[CMake] User defined variable not propagating into subdirs
Bill Hoffman
bill.hoffman at kitware.com
Fri Nov 16 09:18:31 EST 2007
Stephen Collyer wrote:
> I have a top-level cmake list file with this in it:
>
> OPTION (MDP_BUILD_SHARED_LIBS "Build Shared Libraries" ON)
> SET (LIB_TYPE STATIC)
> IF (MDP_BUILD_SHARED_LIBS)
> SET (LIB_TYPE SHARED)
> IF (WIN32)
> ADD_DEFINITIONS("-DMDP_BUILD_SHARED_LIBS")
> ENDIF (WIN32)
> ENDIF (MDP_BUILD_SHARED_LIBS)
>
> In a lower subdirectory, I have this to build a library:
>
> ADD_LIBRARY(Test ${LIB_TYPE} Test.cpp)
>
> the idea being that I can drive the generation of shared/static
> libraries via the setting of the MDP_BUILD_SHARED_LIBS setting
> which defaults to ON. However if I run cmake in an out-of-source
> build from scratch and run a "make all", it seems that LIB_TYPE
> is'nt being seen inside the lower subdirs - I've tested this by
> adding "SET (LIB_TYPE SHARED)" explicitly to the library cmake
> list file, then it build a shared library.
>
> Can someone explain what's going on here. I'm beginning to
> tear my hair out.
>
> And for added bonus: is there a cmake log file generated anywhere
> so I can see what it thinks it doing ? I can't find one anywhere.
>
If you want to change all the libraries in your project to shared, you
can use the global variable BUILD_SHARED_LIBS, and use add_library
without specifying shared or static.
$ cmake --help-command add_library
cmake version 2.4-patch 7
ADD_LIBRARY
Add a library to the project using the specified source files.
ADD_LIBRARY(libname [SHARED | STATIC | MODULE]
..... If no keywords appear as the
second argument, the type defaults to the current value of
BUILD_SHARED_LIBS. If this variable is not set, the type
defaults to STATIC.
Log files are found in CMakeFiles directory.
-Bill
More information about the CMake
mailing list