Keeping file hierarchy across subdirectories in CMake

前端 未结 3 1262
北恋
北恋 2020-12-06 12:57

Till date I still do not really understand what the \'best practice\' is for doing this for a CMake project with many subdirectories.

Say I have a project hierarchy

3条回答
  •  无人及你
    2020-12-06 13:34

    In your case there's no need to use add_subdirectory since you have only one target which is created in the root CMakeLists.txt. You can simply write this:

    add_executable(myProg
        SubD1/Source.cpp
        SubD1/SubSubD1/Source2.cpp)
    

    Use add_subdirectory for subdirectories creating their own targets so there's no information to pass upwards.

提交回复
热议问题