[CMake] Correct way to add definitions
Brandon Van Every
bvanevery at gmail.com
Fri Nov 16 18:11:58 EST 2007
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
More information about the CMake
mailing list