[CMake] Compiler definitions for shared and static builds

Eric Noulard eric.noulard at gmail.com
Mon Jan 31 11:33:40 EST 2011


2011/1/31 Andreas Pakulat <apaku at gmx.de>:
> 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.

and you can adjust OUTPUT names for each unique target:

set_target_properties(${fox_default_libname}-static
                               PROPERTIES OUTPUT_NAME ${fox_default_libname})

set_target_properties(${fox_default_libname}-dynamic
                               PROPERTIES OUTPUT_NAME ${fox_default_libname})

that way you CMake target are unique but they output with the same name.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list