[CMake] Re: Preprocessor Definition for a single Target

Matthew Woehlke mw_triad at users.sourceforge.net
Fri Apr 13 18:56:10 EDT 2007


Mike Jackson wrote:
> I have a CMakeLists.txt file with multiple targets in it. A single 
> library and multiple apps that depend on the library. When I build the 
> library I need to define a preprocessor but when I build the other 
> targets I Don't want it defined. Does that make sense?
> 
> psuedo cmake file:
> 
> ADD_DEFINITION("_DLLEXPORT") //but I only want this to be applied to the 
> library?
> ADD_LIBRARY(BaseLib ${Base_Sources} )
> 
> ADD_DEFINITION("_DLLIMPORT") //and this only for the executable?
> ADD_EXECUTABLE(BaseTest ${Base_Test_sources} )
> TARGET_LINK_LIBRARIES(BaseTest BaseLib)
> 
> 
> How would I do this? Use Target_Properties? Which I know little about..

That seems to be the answer. I do this:
SET_SOURCE_FILES_PROPERTIES(foo.c PROPERTIES COMPILE_FLAGS -Wno-all)

...which isn't what you want, but based on that, I think you want:

SET_TARGET_PROPERTIES(BaseText PROPERTIES COMPILE_FLAGS -D_DLLIMPORT)

Also note that 'ADD_DEFINITION("_DLLEXPORT")' is wrong, it should start 
with '-D' (also you don't need the quotes; I think those are only needed 
if you want to pass a string with spaces as a single argument).

-- 
Matthew
Current geek index: 62%



More information about the CMake mailing list