Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cmake

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

Something like

A    CMakeLists.txt  B   CMakeLists.txt 

and B includes A as sub-directory ?

like image 293
Vivek Goel Avatar asked Nov 02 '11 13:11

Vivek Goel


2 Answers

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.

like image 171
DLRdave Avatar answered Sep 22 '22 14:09

DLRdave


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

like image 25
arrowd Avatar answered Sep 20 '22 14:09

arrowd