I want my source organised in a number of subdirectories but be able to create a single executable without having to build a library for each subdirectory. Can CMake do this
Another (arguably better for big code bases) variant is to use a separate CMakeLists.txt
for each sub-directory where you isolate adding sources of the directory to a target using target_sources
and maybe some particular configuration settings \ include conditions for those sources:
target_sources( SomeExeOrLib PRIVATE source1.h source1.cpp )
here you also have more control of the scope by specifying PRIVATE
, other options are INTERFACE
or PUBLIC
. See details here: https://cmake.org/cmake/help/v3.3/command/target_sources.html