[CMake] User defined variable not propagating into subdirs

Stephen Collyer scollyer at netspinner.co.uk
Fri Nov 16 11:17:18 EST 2007


Alan W. Irwin wrote:
> On 2007-11-16 11:49-0000 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)
> 
> Bill has already given you a global way to set static or shared libraries,
> but what caught my eye here is that your LIB_TYPE was not propagating to
> lower directories as it should.

Right. I'd actually forgotten that that was my original problem.

> I successfully use such propagation of variables all the time with
> ADD_SUBDIRECTORY. Are you using SUBDIRS instead? 

No, I'm using ADD_SUBDIRECTORY. However, I'm now using an
ADD_DEFINITIONS("-DBUILD_SHARED_LIBS") to control the
preprocessor code lower down the tree, and that is working,
so my original problem has disappeared. But, yes, I'm concerned
that something odd is happening with the LIB_TYPE variable as
I expected it to be available lower down the tree. As I know
next to nothing about cmake, I can't really offer an explanation
though.

-- 
Regards

Steve Collyer
Netspinner Ltd


More information about the CMake mailing list