[CMake] Different targets for different configurations

Eric Noulard eric.noulard at gmail.com
Fri Mar 23 02:53:07 EDT 2012


2012/3/23 Mike Krus <mike at mve.com>:
> Hi
>
> I would like run a script with different options for debug and release
> builds. I can do this easily for Makefiles but am struggling to get it to
> work for Visual Studio.
>
> I basically:
> - add a custom command the output of which depends on the configuration
> - add a custom target for that command
> - add that target as a dependency of my other targets (I want the
>  script to run first)

Why can't you use the "PRE_BUILD" options of add_custom_command
with TARGET target signature?

It is not possible because this script should be run before any target?


>
> Here's the CMake code below...
>
>
> My problem is that for Visual Studio ${CMAKE_BUILD_TYPE} is not set (normal)
> and CMake doesn't know about $(CONFIGURATION) since it's a build time thing
> (again, normal).
> So as it stands, the scripts always runs at every build because it's not
> picking up the correct output file.

Did have a look at "generator expressions" they are meant to be used
in your precise case,
i.e. they are evaluated at "build time" and not at CMake time.

Valid expressions are:

         $<CONFIGURATION>          = configuration name
         $<TARGET_FILE:tgt>        = main file (.exe, .so.1.2, .a)
         $<TARGET_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)
         $<TARGET_SONAME_FILE:tgt> = file with soname (.so.3)

more doc in:
cmake --help-command add_custom_command


-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list