Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "$<$<CONFIG:Debug>:Release>" mean in cmake?

Tags:

In buildem_cmake_recipe.cmake, I saw an expression:

    externalproject_add_step(${_name} BuildOtherConfig
                        COMMAND ${CMAKE_COMMAND} --build ${BINARY_DIR} --config "$<$<CONFIG:Debug>:Release>$<$<CONFIG:Release>:Debug>" --target INSTALL
                        DEPENDEES install
                        )

What does the $<$<CONFIG:Debug>:Release>$<$<CONFIG:Release>:Debug> mean here?

like image 830
David S. Avatar asked Dec 28 '15 08:12

David S.


People also ask

What is the default CMake build type?

Build typesDebug (the default build type) Release. RelWithDebInfo (Release with debugging information) MinSizeRel (Release optimized for size)

What is Cmake_build_type?

Specifies the build type on single-configuration generators (e.g. Makefile Generators or Ninja ). Typical values include Debug , Release , RelWithDebInfo and MinSizeRel , but custom build types can also be defined.

What is CMake generator?

A CMake Generator is responsible for writing the input files for a native build system. Exactly one of the CMake Generators must be selected for a build tree to determine what native build system is to be used.


2 Answers

That's a CMake generator expression. You can follow the link for a full discussion of what these are and what they can do. In short, it's a piece of text which CMake will evaluate at generate time (when it's done parsing all CMakeLists and is generating the buildsystem); it can evaluate to a different value for each configuration.

The one you have there means roughly this (pseudo-code):

if current_configuration == "Debug"
  output "Release"
if current_configuration == "Release"
  output "Debug"

So, if the current configuration is Debug, the whole expression will evaluate to Release. If the current configuration's Release, it will evaluate to Debug. Notice that the step being added is called "BuildOtherConfig," so this inverted logic makes sense.


How it works, in a little more detail:

$<CONFIG:Debug>

This will evaluate to a 1 if the current config is Debug, and to a 0 otherwise.

$<1:X>

Evaluates to X.

$<0:X>

Evaluates to an empty string (no value).

Putting it together, we have $<$<CONFIG:Debug>:Release>. When the current config is Debug, it evaluates like this:

$<$<CONFIG:Debug>:Release>
$<1:Release>
Release

When the current config is not Debug, it evaluates like this:

$<$<CONFIG:Debug>:Release>
$<0:Release>
like image 83
Angew is no longer proud of SO Avatar answered Oct 07 '22 16:10

Angew is no longer proud of SO


Expressions like $<...> are generator exressions, introduced in CMake 2.8. The main feature of these expressions is that they are evaluated at build time, not at configuration time, like normal CMake variables.

Your particular expression

$<$<CONFIG:Debug>:Release>

expands to "Release" if Debug configuration is in use.

like image 32
Tsyvarev Avatar answered Oct 07 '22 17:10

Tsyvarev