Multiple source directories for one executable with CMake

前端 未结 3 766
[愿得一人]
[愿得一人] 2020-12-19 15:29

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

3条回答
  •  [愿得一人]
    2020-12-19 15:59

    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

提交回复
热议问题