[CMake] trying to modify preprocessor statements on same source file (probs with SET_SOURCE_FILES_PROPERTIES & ADD_DEFINITIONS)

Philip Lowman philip at yhbt.com
Tue Mar 20 18:22:25 EST 2007


Hi,

I'm trying to facilitate compiling the same source file once with a 
STATIC_BUILD preprocessor statement defined to 1 and once with it 
defined to 0.  I can't seem to figure out a way to do this, however.

It appears that the only options I have which are ADD_DEFINITIONS and 
SET_SOURCE_FILES_PROPERTIES are gathered together and
processed at the end of the file and are not interpreted atomically 
during an ADD_EXECUTABLE() call like I believe they should.

==========

Example 1:  This fails because whichever calls 
SET_SOURCE_FILES_PROPERTIES last will win.

IF(STATIC_BUILD)
    SET_SOURCE_FILES_PROPERTIES(foo.cc
	PROPERTIES COMPILE_FLAGS "-DSTATIC_BUILD=1")

    ADD_EXECUTABLE(foo-static foo.cc)

ELSE()
    SET_SOURCE_FILES_PROPERTIES(foo.cc
	PROPERTIES COMPILE_FLAGS "")

    ADD_EXECUTABLE(foo-shared foo.cc)
ENDIF()

==========

Example 2:  I can't do this either as the compiler simply appends 
-DSTATIC_BUILD=1 -DSTATIC_BUILD=0 for both builds

IF(STATIC_BUILD)
    ADD_DEFINITIONS(-DSTATIC_BUILD=1)
    ADD_EXECUTABLE(foo-static foo.cc)

ELSE()
    ADD_DEFINITIONS(-DSTATIC_BUILD=0)
    ADD_EXECUTABLE(foo-shared foo.cc)
ENDIF()

I'm running CMake 2.4.6.  Any advice would be appreciated.  Aside from 
forking the source file I'm out of ideas.

-- 
Philip Lowman
Simulation Development Engineer, Modeling and Simulation Technology
General Dynamics Land Systems
http://www.gdls.com


More information about the CMake mailing list