[CMake] Avoiding convenience libs

Pascal Fleury fleury at users.sourceforge.net
Tue Apr 17 17:43:54 EDT 2007


In a move to avoid convenience libraries, I have tried to store a list of 
files into a variable ("utils_SRCS"), and reuse this var in each target that 
would normally link to the convenience lib (potentially compiling these 
source files multiple times, but that is not the issue here).

My files are as follows:
src/CMakeLists.txt
src/utils/CMakeLists.txt
src/utils/a.cpp
src/utils/b.cpp
src/mylib/CMakeLists.txt
src/mylib/l1.cpp
src/mylib/l2.cpp
src/mylib/main.cpp


---src/CMakeLists.txt---------
ADD_SUBDIRECTORY( utils )
ADD_SUBDIRECTORY( mylib )

---src/utils/CMakeLists.txt---------
SET(utils_SRCS a.cpp b.cpp)

---src/mylib/CMakeLists.txt---------
ADD_LIBRARY(mylib l1.cpp l2.cpp main.cpp ${utils_SRCS} )


But now, in src/mylib/CMakeLists.txt, the ${utils_SRCS} is always empty, 
resulting in missing symbols when linking. I have tried to print some STATUS 
messages, and the control flow between the cmake scripts is what I expect, 
but the variable is defined only in the src/utils/CMakeLists.txt, after that, 
it's gone. What is the logic behind this ?

If I set a  FILE(GLOB tils_SRCS "utils/*.cpp" ) in src/CMakeLists.txt, then 
the variable is defined... Is this explained somewhere on the wiki/doc/book ?

Thanks,
--paf


More information about the CMake mailing list