[CMake] Compiler definitions for shared and static builds

Andreas Pakulat apaku at gmx.de
Mon Jan 31 11:29:41 EST 2011


On 31.01.11 17:18:58, Louis Hoefler wrote:
> Hello everyone,
> I try to generate a cmake project and want to
> build shared and dynamic libraries in one step.
>
> I therefore added two targets:
> ADD_LIBRARY(${fox_default_libname} STATIC ${fox_cpp_files}  
> ${fox_h_files} icons.h icons.cpp)
> ADD_LIBRARY(${fox_default_libname} SHARED ${fox_cpp_files}  
> ${fox_h_files} icons.h icons.cpp)
>
> Booth of them should have different compiler definitions.
> How to set them explicitly for shared and static targets?
>
> I tried something like this:
> SET_PROPERTY(TARGET ${fox_default_libname}
>                            PROPERTY COMPILE_DEFINITIONS  
> ${fox_default_defines_static}
> )
>
> But the targets for shared and static builds need to have different names
> (becouse the need different build directories though).
>
> Is there an elegant way to achive what I want?

No, target names in cmake need to be unique within the same CMakeLists.txt
at least (not sure if they need to be unique globally) and hence using 2
different names for the shared and static lib are necessary. Once you have
that you can use set_target_properties with COMPILE_DEFINITIONS without any
problem.

Andreas

-- 
Future looks spotty.  You will spill soup in late evening.


More information about the CMake mailing list