Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Partial cmake tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
jmangelson committed Apr 29, 2021
1 parent e832bc7 commit e2cee4b
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Gemfile.lock
website/Gemfile.lock
*~
build
21 changes: 21 additions & 0 deletions cmake/my_cmake_cpp_project1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Example pulled in part from Henery Schreiner at:
# https://gitlab.com/CLIUtils/modern-cmake
cmake_minimum_required(VERSION 3.11...3.20)

# Project Name
project(
MyCmakeProject
VERSION 1.0
DESCRIPTION "Example CMake Project"
LANGUAGES CXX)

#ORDER HERE MATTERS!

# Explore the source file directory for library code
add_subdirectory(src)

# Explore the exectuble file directory for exec. code
add_subdirectory(apps)



1 change: 1 addition & 0 deletions cmake/my_cmake_cpp_project1/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(my_program)
3 changes: 3 additions & 0 deletions cmake/my_cmake_cpp_project1/apps/my_program/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(my_program my_program.cpp)

target_link_libraries(my_program PRIVATE mylib)
6 changes: 6 additions & 0 deletions cmake/my_cmake_cpp_project1/apps/my_program/my_program.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <mylib/my_file.hpp>

int main()
{
file_hello();
}
1 change: 1 addition & 0 deletions cmake/my_cmake_cpp_project1/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(mylib)
8 changes: 8 additions & 0 deletions cmake/my_cmake_cpp_project1/src/mylib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Create Header file list, though not needed to create the library, it is needed for IDEs
set(HEADER_LIST "${MyCmakeProject_SOURCE_DIR}/include/mylib/my_file.hpp")

add_library(mylib SHARED my_file.cpp ${HEADER_LIST})

target_include_directories(mylib PUBLIC ../../include)


7 changes: 7 additions & 0 deletions cmake/my_cpp_project/include/my_file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __MY_FILE_HPP__
#define __MY_FILE_HPP__

void file_hello();

#endif

File renamed without changes.
6 changes: 6 additions & 0 deletions cmake/my_cpp_project/my_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

void file_hello()
{
std::cout << "Hello from my_file.cpp" << std::endl;
}
51 changes: 47 additions & 4 deletions cmake/notes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CMake Tutorial

1. Pre-processing, linking, and compiling of alone
1. Pre-processing, linking, and compiling of alone (In my_cpp_project)

/////////////////////////////
// Pre-processor
Expand Down Expand Up @@ -43,20 +43,63 @@ g++ -o my_program main.c my_file.c

You could run this command every time you change a file to re-build.
What does a Makefile buy you?
Any reasons why we wouldn't want to always do this manually?

When working large code bases?
With respect to efficiency?

2. Why CMake?
2. Make my_file.cpp into a library (mylib)

////////////////////////////////////////////
// Static Library with g++/gcc








////////////////////////////////////////////
// Dynamic Library with g++/gcc







3. Why CMake?

- Generating a Makefile for large projects is tedious, time consuming, and brital.
- What if your compiler changes?
- What if you move to another machine with a different operating system?
- What if you want to do something more complex (dynamicly linked libraries)?
- What if you want to do something more complex (dynamically linked libraries)?
- What if your large library has many different versions of libraries it could link against and you want to configure those things at compile time?

CMAKE!

Luckily, this general process is similar for almost every program/project.
CMake lets us specify the dependencies of a project and then it will automatically generate the make file for us.

3. CMake Example
4. Simple CMake Library Example

Go through CMake Library Code

SHARED vs STATIC



Installing?


Finding and using a dependency
- Make available
- Find

Exporting

Testing


Pods2

0 comments on commit e2cee4b

Please sign in to comment.