CMAKE add sub-directory which is not sub-directory on real directory

前端 未结 2 1345
花落未央
花落未央 2020-12-13 03:46

Is It possible to include sibling directory as Sub-Directory inside cmake ?

Something like

A 
  CMakeLists.txt

B
  CMakeLists.txt

相关标签:
2条回答
  • 2020-12-13 04:12

    Unfortunately, no.

    As solution i may suggest you to add_subdirectory(A) and add_subdirectory(B) at the top level and set vars you want to export from A with PARENT_SCOPE. This would allow B/CMakeLists.txt to access varibles defined in A/CMakeLists.txt

    0 讨论(0)
  • 2020-12-13 04:17

    It is possible, although perhaps not recommended...

    You can use the two-argument form of the add_subdirectory command to add any directory you want as a "sub" directory:

    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../A ${CMAKE_CURRENT_BINARY_DIR}/A)
    

    The second argument of the two-argument form specifies where to put the binary directory for the added subdirectory.

    You just have to be careful that there's not also another real sub-directory of B that is also named "A" and that is also add_subdirectory'd... Because if you do, then that would be an error, as CMake cannot have two different source directories mapping into the same build directory.

    0 讨论(0)
提交回复
热议问题