[CMake] Re: Preprocessor Definition for a single Target

Mike Jackson imikejackson at gmail.com
Fri Apr 13 19:37:59 EDT 2007


Turns out the CMake guys have already put some of the plumbing into  
CMake that I needed. For those playing along at home, I had the rude  
awakening to Windows DLL Export fun. So I was looking at other  
projects to see how they were doing things. When I built shared  
libraries I noticed that CMake was adding a "-DMXADataModel_EXPORTS"  
for me, just for the shared library target. Thanks guys. That  
simplified my code and CMakeLists.txt a bunch.. Almost like someone  
had gone through this before ;-)

Thanks
-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services


On Apr 13, 2007, at 6:56 PM, Matthew Woehlke wrote:

> 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%
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list