CMake creating shared and static library with different defines -


i want create static , shared library using cmake create build environment. furthermore should create ansi , unicode version.

i found posting: is possible cmake build both static , shared version of same library?

which told me can use multiple add_library statements achieve this. when tried it, creates libraries fine, posting doesn't tell me how set different -d options depending on version built.

my cmakelists.txt looks this:

list(append support_source     dll_main.cpp )  add_definitions(-dbuild_support_dll)  add_library(support shared ${support_source} ) add_library(support_s static ${support_source} ) add_library(support_u shared ${support_source} ) add_library(support_su static ${support_source} ) 

after all, when build dll, functions needs __declspec(dllexport) declaration should not have in static versions. furthermore build unicode variant need pass -dunicode.

so need know version built , use appropriate build flags for various targets.

another thing don't understand is, how can create debug builds different name. use pattern libname.lib , libname_d.lib can have possible versions in single directory link against.

you can set compiler flags per-target using target_compile_definitions command. example:

target_compile_definitions(support private my_shared_definition) target_compile_definitions(support_s private my_static_definition) 

as adding postfix debug libraries, can achieve setting cmake variable cmake_debug_postfix:

set(cmake_debug_postfix _d) 

this cause non-executable targets have _d appended when built in debug. if need more fine-grained control, can set debug_postfix property individual targets:

set_target_properties(support support_s properties debug_postfix -dbg) 

this override global cmake_debug_postfix value these 2 targets , give them -dbg postfix instead.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -