[CMake] Working with targets

Tyler Roscoe tyler at cryptio.net
Wed Oct 28 11:17:50 EDT 2009


On Wed, Oct 28, 2009 at 09:02:52AM +0100, Dietmar Hummel wrote:
> What I would like to handle are targets like
> release
> debug
> demo release (additionals defines)
> first customer oem release (other additional defines)
> second customer oem release (again different set of defines)
> ... and so on ...
> 
> Additionally I would like to be able to build all libraries
> in a static and a shared variant.
> 
> I couldnt figure out how to do this in general and I am wondering how
> to do this if I would like to have the same targets set on windows and
> unixes because of the differences multi-configuration generator on
> windows side vs. single-configuration generator on unix side.

Not sure where there's a good tutorial on all these topics but a few
hints to get you started.

You probably don't want to try and make targets for each of your build
configurations. You probably want them to be build configurations
instead.

Look at the various COMPILE_DEFINITIONS_<CONFIG> and
CMAKE_CXX_FLAGS_<CONFIG> properties and variables. This will get you
started with setting different compile definitions and compiler flags
and etc. for your different build configurations. 

Debug and Release exist by default, but you can create arbitrary
configurations to support your customer oem configurations. There's a
page in the wiki about this somewhere.

I think most people control shared vs static libs by wrapping
add_library() and add_executable() with a macro that passes the correct
arguments based on a cache variable.

Also, look at others' CMakeLists files on the internets. VTK, Boost,
KDE, Mike Jackson's projects and other projects posted in the list
archives -- all of these have examples of various ways to tackle these
types of problems.

good luck,
tyler


More information about the CMake mailing list