Reputation: 3184
Let's suppose I have a project organized as follows:
Proj/src
Proj/src/library_a
Proj/src/library_b
Proj/src/executable
What I would like to do is to collect the names of the libraries contained in src/library_a
and src/library_b
in a variable Proj_LIBS to be propagated up to the root of the CMake tree.
In the file src/library_a/CMakeLists.txt
, I add all of the names of the targets to the variable Proj_LIBS, then I use this variable in the CMakeLists.txt file in folder src/executable
.
The Proj/src/library_a/CMakeLists.txt
is
add_library(A1 A1.cpp)
add_library(A2 A2.cpp)
SET(Curr_LIBS "${Proj_LIBS} A1 A2")
SET(Proj_LIBS ${Curr_LIBS} PARENT_SCOPE)
When I try to produce the executable with Proj/src/executable/CMakeLists.txt
:
add_executable(exe1 exe1.cpp)
target_link_libraries(exe1 ${Proj_LIBS})
the names in Proj_LIBS are interpreted as library names, i.e, the compilation command prepared by CMake is:
gcc exe1.cpp -l A1 -l A2 -o exe1
and are not considered as dependencies as they are if I write the following lines in Proj/src/executable/CMakeLists.txt
:
add_executable(exe1 exe1.cpp)
target_link_libraries(exe1 A1 A2)
Any suggestion?
Upvotes: 0
Views: 116
Reputation: 34421
I bet the problem is using string instead of a list. Try this:
SET(Curr_LIBS "${Proj_LIBS};A1;A2")
SET(Proj_LIBS ${Curr_LIBS} PARENT_SCOPE)
Upvotes: 1