我正在使用 cmake 2.8.12.2。我已经设置了CMAKE_DEBUG_POSTFIX
,它会自动与 add_library
一起使用命令。但它不会自动与 add_executable
一起使用命令。我发现我可以设置 DEBUG_POSTFIX
target 属性将调试后缀添加到可执行文件名称中,但这需要使用额外的命令。
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
第二个命令是否明确设置
DEBUG_POSTFIX
需要目标属性还是有更简单的方法?
最佳答案
当前的 cmake 文档 set_target_properties状态
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).
所以似乎强调了 cmake 不使用
CMAKE_DEBUG_POSTFIX
的值这一事实。以可执行文件的名义。所以add_executable(myexe ${SOURCE_FILES})
set_target_properties(myexe PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
将使用全局变量
${CMAKE_DEBUG_POSTFIX}
的值构建 myexe
时DEBUG
的目标配置。请注意,该问题的一位评论者对变量
${PROJECT_NAME}
的使用感到困惑。 .此变量自动设置为 myexe
使用时 project(myexe)
.使用 ${PROJECT_NAME}
相当于 myexe
它可以更轻松地复制/粘贴到新的 CMakeLists.txt。
关于cmake - 如何在可执行文件名称中获取调试后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893450/