I am using cmake 2.8.12.2. I have set CMAKE_DEBUG_POSTFIX
, and it is automatically used with the add_library
command. But it is not automatically used with add_executable
command. I have discovered that I can set the DEBUG_POSTFIX
target property to get a debug postfix into the executable name, but this requires using an additional command.
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
Is the second command explicitly setting the DEBUG_POSTFIX
target property required or is there an easier way?
The current cmake documentation for set_target_properties states
There is also a
<CONFIG>_OUTPUT_NAME
that can set the output name on a per-configuration basis.<CONFIG>_POSTFIX
sets a postfix for the real name of the target when it is built under the configuration named by (in upper-case, such as “DEBUG_POSTFIX”). The value of this property is initialized when the target is created to the value of the variableCMAKE_<CONFIG>_POSTFIX
(except for executable targets because earlier CMake versions which did not use this variable for executables).
So it seems to highlight the fact that cmake does not use the value of CMAKE_DEBUG_POSTFIX
in the name of executables. Therefore
add_executable(myexe ${SOURCE_FILES})
set_target_properties(myexe PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
will use the value of the global variable ${CMAKE_DEBUG_POSTFIX}
when building the myexe
target for the DEBUG
configuration.
Note that one of the commenters to this question was confused by the use of the variable ${PROJECT_NAME}
. This variable is automatically set to myexe
when using project(myexe)
. Using ${PROJECT_NAME}
is equivalent to myexe
and it makes it easier to copy/paste to new CMakeLists.txt.
Just to mention that, if you have in your project many sub-executables, it is worth having a look on CMAKE_EXECUTABLE_SUFFIX. The variable in this case would need to be changed when running CMake for a specific build (Release/Debug), but this suffix is auto-attached to every ADD_EXECUTABLE(...)-call executable name. Tested and verified with CMake 2.8.12.2 and 3.0.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With