[CMake] Separate object directories on Linux?
KSpam
keesling_spam at cox.net
Wed Apr 2 14:17:52 EDT 2008
On Wednesday 02 April 2008 10:20:18 Bill Hoffman wrote:
> However, there are some variables that can help with this.
>
> CMAKE_BUILD_TYPE is only used by makefile generators and is the specific
> build for that tree.
>
> CMAKE_CONFIGURATION_TYPES is set to the list of active configurations
> (Debug, Release, etc). It is empty for makefile builds. So, you can
> iterate over this and construct paths etc.
I like to build multiple build types and library types in the same build
directory. I have BOOL configuration options for enabling STLport and shared
libraries. To keep the configurations from stomping on each other, I just
have to make sure that my target names are unique. Here is a macro that I
use to create a unique target name:
MACRO(MARKET_TARGET_NAME name _targetName)
SET(${_targetName} ${name})
# Append static or shared
IF (BUILD_SHARED_LIBS)
SET(${_targetName} "${${_targetName}}-shared")
ELSE (BUILD_SHARED_LIBS)
SET(${_targetName} "${${_targetName}}-static")
ENDIF (BUILD_SHARED_LIBS)
# Append stlport
IF (MARKET_USE_STLPORT)
SET(${_targetName} "${${_targetName}}-stlport")
ENDIF (MARKET_USE_STLPORT)
# Append the build type
IF (NOT CMAKE_CONFIGURATION_TYPES)
SET(${_targetName} "${${_targetName}}-${CMAKE_BUILD_TYPE}")
ENDIF (NOT CMAKE_CONFIGURATION_TYPES)
ENDMACRO(MARKET_TARGET_NAME)
When I create a library, for instance, I use the unique target name:
MARKET_TARGET_NAME(libname targetName)
ADD_LIBRARY(${targetName} ...)
Now I can build libname-shared, libname-shared-stlport, libname-static, and
libname-static-stlport in the same build directory. On Makefile
systems,libname-shared becomes libname-shared-${CMAKE_BUILD_TYPE}, so I can
build Debug and Release in the same build directory.
The only annoyance I have with this system is that the target names in the
Makefile (make help) are long. To alleviate this, I simply add aliases as
so:
ADD_CUSTOM_TARGET(libname)
ADD_DEPENDENCIES(libname ${targetName})
Unfortunately, each target ends up with two listings in "make help"
(i.e. "libname" and "libname-static-stlport-Debug"); however, I personally do
not mind the extra noise.
Hope This Helps,
Justin
More information about the CMake
mailing list