[CMake] Marking libraries (yes: maRking)
Brad King
brad.king at kitware.com
Wed Mar 1 22:57:58 EST 2006
Brandon J. Van Every wrote:
> Rodrigo Madera wrote:
>
>> I have a project that build a lot of different libraries (like Boost
>> does, but it's not Boost) with configuration markings and build
>> options.
>>
>> I want to build:
>>
>> MyLib.lib: the release library
>> MyLib-D.lib debug library
>> MyLib-A.lib non unicode version
>> MyLib-AD.lib nin unicode debug library.
>>
>> How can I do this _efficiently_?
>>
>
> The CVS version of CMake lets you do things like building SHARED vs.
> STATIC libraries and also provide target-specific flags. You're still
> going to have to create entries for each and every library you want to
> build though. There's no "take care of all of my minor variation
> decisions" for me. You have to make those decisions yourself.
The CMake development version from CVS has several features that make
this easier. Using it you should be able to do:
--------------------------------------------------------------------
# Macro to create both an ASCII and UNICODE version of a library.
MACRO(MY_ADD_LIBRARY name)
# Build UNICODE version.
ADD_LIBRARY(${name} ${ARGN})
SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX -D)
SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "-D_UNICODE")
# Build ASCII version.
ADD_LIBRARY(${name}-A ${ARGN})
SET_TARGET_PROPERTIES(${name}-A PROPERTIES DEBUG_POSTFIX D)
ENDMACRO(MY_ADD_LIBRARY)
# Add library MyLib.
MY_ADD_LIBRARY(MyLib src1.c src2.c)
--------------------------------------------------------------------
When the user selects the "Debug" configuration this will build
"MyLib-D" and "MyLib-AD". When the user selects the "Release"
configuration this will build "MyLib" and "MyLib-A".
See the documentation of the SET_TARGET_PROPERTY command for details.
-Brad
More information about the CMake
mailing list