diff --git a/.gitignore b/.gitignore index bf07c16e..7ee20fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Gemfile.lock website/Gemfile.lock *~ +build diff --git a/cmake/my_cmake_cpp_project1/CMakeLists.txt b/cmake/my_cmake_cpp_project1/CMakeLists.txt new file mode 100644 index 00000000..73c3ace8 --- /dev/null +++ b/cmake/my_cmake_cpp_project1/CMakeLists.txt @@ -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) + + + diff --git a/cmake/my_cmake_cpp_project1/apps/CMakeLists.txt b/cmake/my_cmake_cpp_project1/apps/CMakeLists.txt new file mode 100644 index 00000000..aab12cb2 --- /dev/null +++ b/cmake/my_cmake_cpp_project1/apps/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(my_program) diff --git a/cmake/my_cmake_cpp_project1/apps/my_program/CMakeLists.txt b/cmake/my_cmake_cpp_project1/apps/my_program/CMakeLists.txt new file mode 100644 index 00000000..83aa321c --- /dev/null +++ b/cmake/my_cmake_cpp_project1/apps/my_program/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(my_program my_program.cpp) + +target_link_libraries(my_program PRIVATE mylib) diff --git a/cmake/my_cmake_cpp_project1/apps/my_program/my_program.cpp b/cmake/my_cmake_cpp_project1/apps/my_program/my_program.cpp new file mode 100644 index 00000000..ba9be0fa --- /dev/null +++ b/cmake/my_cmake_cpp_project1/apps/my_program/my_program.cpp @@ -0,0 +1,6 @@ +#include + +int main() +{ + file_hello(); +} diff --git a/cmake/my_project/my_prog/include/my_file.hpp b/cmake/my_cmake_cpp_project1/include/mylib/my_file.hpp similarity index 100% rename from cmake/my_project/my_prog/include/my_file.hpp rename to cmake/my_cmake_cpp_project1/include/mylib/my_file.hpp diff --git a/cmake/my_cmake_cpp_project1/src/CMakeLists.txt b/cmake/my_cmake_cpp_project1/src/CMakeLists.txt new file mode 100644 index 00000000..0e506567 --- /dev/null +++ b/cmake/my_cmake_cpp_project1/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(mylib) diff --git a/cmake/my_cmake_cpp_project1/src/mylib/CMakeLists.txt b/cmake/my_cmake_cpp_project1/src/mylib/CMakeLists.txt new file mode 100644 index 00000000..38b04ce5 --- /dev/null +++ b/cmake/my_cmake_cpp_project1/src/mylib/CMakeLists.txt @@ -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) + + diff --git a/cmake/my_project/my_prog/my_file.cpp b/cmake/my_cmake_cpp_project1/src/mylib/my_file.cpp similarity index 100% rename from cmake/my_project/my_prog/my_file.cpp rename to cmake/my_cmake_cpp_project1/src/mylib/my_file.cpp diff --git a/cmake/my_cpp_project/include/my_file.hpp b/cmake/my_cpp_project/include/my_file.hpp new file mode 100644 index 00000000..3bb07bba --- /dev/null +++ b/cmake/my_cpp_project/include/my_file.hpp @@ -0,0 +1,7 @@ +#ifndef __MY_FILE_HPP__ +#define __MY_FILE_HPP__ + +void file_hello(); + +#endif + diff --git a/cmake/my_project/my_prog/main.cpp b/cmake/my_cpp_project/main.cpp similarity index 100% rename from cmake/my_project/my_prog/main.cpp rename to cmake/my_cpp_project/main.cpp diff --git a/cmake/my_cpp_project/my_file.cpp b/cmake/my_cpp_project/my_file.cpp new file mode 100644 index 00000000..f2ab96ff --- /dev/null +++ b/cmake/my_cpp_project/my_file.cpp @@ -0,0 +1,6 @@ +#include + +void file_hello() +{ + std::cout << "Hello from my_file.cpp" << std::endl; +} diff --git a/cmake/notes.txt b/cmake/notes.txt index 2b6f79f6..f39e46a7 100644 --- a/cmake/notes.txt +++ b/cmake/notes.txt @@ -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 @@ -43,14 +43,38 @@ 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! @@ -58,5 +82,24 @@ 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