[CMake] Correct way to add definitions

Mike Jackson imikejackson at gmail.com
Fri Nov 16 18:17:23 EST 2007


On Nov 16, 2007 6:11 PM, Brandon Van Every <bvanevery at gmail.com> wrote:
> On Nov 16, 2007 5:19 PM, Mike Jackson <imikejackson at gmail.com> wrote:
> > I am trying to create a cmake build system for a 3rd party library.
> > The trouble I am having is that I need a definition for the dynamic
> > library ONLY, but when I build the ensuing test executables I need to
> > have a _different_ definition defined.
> >
> > At first I did the usual:
> >
> > IF(BUILD_SHARED_LIBS)
> >     IF (WIN32)
> >        ADD_DEFINITION(-D_BUILD_DLL_)
> >     ENDIF(WIN32)
> > ENDIF (BUILD_SHARED_LIBS)
> >
> > Then in I have ADD_SUBDIRECTORY(test)
> > and in the test/CMakeLists.txt file I have
> >
> > IF(BUILD_SHARED_LIBS)
> >     IF (WIN32)
> >        ADD_DEFINITION(-D_USE_DLL_)
> >     ENDIF(WIN32)
> > ENDIF (BUILD_SHARED_LIBS)
> >
> > but when I create my VS2003.net project from CMake (2.4.6) I get BOTH
> > definitions in the testing targets.
>
> Why wouldn't you?  Variables are propagated to subdirectories, and I
> imagine definitions are also.  Perhaps you want to put your
> ADD_SUBDIRECTORY statement earlier, to prevent propagation of
> -D_BUILD_DLL.
>
> Perhaps you want the REMOVE_DEFINITIONS command?
>
>
> Cheers,
> Brandon Van Every

(turning slightly red.. ) .. I did not thing to look for
REMOVE_DEFINITIONS and I did not understand the sequence really DOES
matter in a cmake file.

Both are things I'm going to jot down in my book of cmake notes..

Thanks
-- 
Mike Jackson
imikejackson _at_ gee-mail dot com


More information about the CMake mailing list