[CMake] User defined variable not propagating into subdirs

David Cole david.cole at kitware.com
Fri Nov 16 11:29:34 EST 2007


Alan is correct - LIB_TYPE should be available in subdirectories added via
ADD_SUBDIRECTORY.

Are you sure you don't have a typo? -- CMake variable names are case
sensitive.

Maybe you have Lib_TYPE and LIB_TYPE or LIB__TYPE or something like that?


On 11/16/07, Stephen Collyer <scollyer at netspinner.co.uk> wrote:
>
> 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
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071116/2ab32a55/attachment.html


More information about the CMake mailing list