I'm trying to put together a CMake project where I have different packages that I need to build. This is my desired structure:
package1 src file.cpp test file_test.cpp package2 src file2.cpp test file2_test.cpp CMakeLists.txt main.cpp // this will be removed later This is my current CMakeLists.txt file:
cmake_minimum_required(VERSION 3.10) # set the project name project(cppApp) # specify the C++ standard set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) include_directories(${PROJECT_SOURCE_DIR}) # add the executable add_executable(cppApp main.cpp ./package1/src/file.cpp ./package2/src/file2.cpp) So the question is firstly, is a library considered a package in CMake? This question comes from someone who have done a lot of Java where I would typically call that a package and not a library. But does it in CMake?
Also, how do I in CMake include all files in the "packages" to be built instead of hard coding in the files as an executable? If I create many .cpp/.h files I want to automate this as much as possible.
I have seen that some other projects use a CMakeLists.txt file inside each "package", is this ideal? And is this good practice?
If you have a better suggestion according to some standard I should use to structure my project I would like to know a good one as well.
add_library(lib)and is those kinds of directories considered a library? Can something nudge me in the right direction or show some kind of example how that differs and how to add that to a CMake file for it to build?cmake --install ...,cpackwhich work based on theinstallcmake command among other things but to me it seems like that's not what you're hoping to achieve right now.file(GLOB SRC_FILES dir/*.cpp)to automate listing of source files but there are performance issues, partially solved byCONFIGURE_DEPENDSkeyword, not mentioning that you may list files which you do not actually want as part of