如何在可执行文件名称中获取调试后缀
How to get debug postfix in executable name
我正在使用 cmake 2.8.12.2。我已经设置了CMAKE_DEBUG_POSTFIX
,它会自动与add_library
命令一起使用。但它不会自动与 add_executable
命令一起使用。我发现我可以设置 DEBUG_POSTFIX
目标 属性 来将调试后缀添加到可执行文件名称中,但这需要使用额外的命令。
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
第二个命令是否需要明确设置 DEBUG_POSTFIX
目标 属性 还是有更简单的方法?
set_target_properties 的当前 cmake 文档指出
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 variable CMAKE_<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})
在为 DEBUG
配置构建 myexe
目标时将使用全局变量 ${CMAKE_DEBUG_POSTFIX}
的值。
请注意,此问题的一位评论者对变量 ${PROJECT_NAME}
的使用感到困惑。使用 project(myexe)
时,此变量会自动设置为 myexe
。使用 ${PROJECT_NAME}
等同于 myexe
,它使 copy/paste 到新的 CMakeLists.txt 更容易。
顺便提一下,如果您的项目中有许多子可执行文件,那么 CMAKE_EXECUTABLE_SUFFIX 值得一看。当 运行 CMake 用于特定构建 (Release/Debug) 时,需要更改这种情况下的变量,但此后缀会自动附加到每个 ADD_EXECUTABLE(...)-调用可执行名称。使用 CMake 2.8.12.2 和 3.0.2
进行测试和验证
我正在使用 cmake 2.8.12.2。我已经设置了CMAKE_DEBUG_POSTFIX
,它会自动与add_library
命令一起使用。但它不会自动与 add_executable
命令一起使用。我发现我可以设置 DEBUG_POSTFIX
目标 属性 来将调试后缀添加到可执行文件名称中,但这需要使用额外的命令。
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
第二个命令是否需要明确设置 DEBUG_POSTFIX
目标 属性 还是有更简单的方法?
set_target_properties 的当前 cmake 文档指出
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})
在为 DEBUG
配置构建 myexe
目标时将使用全局变量 ${CMAKE_DEBUG_POSTFIX}
的值。
请注意,此问题的一位评论者对变量 ${PROJECT_NAME}
的使用感到困惑。使用 project(myexe)
时,此变量会自动设置为 myexe
。使用 ${PROJECT_NAME}
等同于 myexe
,它使 copy/paste 到新的 CMakeLists.txt 更容易。
顺便提一下,如果您的项目中有许多子可执行文件,那么 CMAKE_EXECUTABLE_SUFFIX 值得一看。当 运行 CMake 用于特定构建 (Release/Debug) 时,需要更改这种情况下的变量,但此后缀会自动附加到每个 ADD_EXECUTABLE(...)-调用可执行名称。使用 CMake 2.8.12.2 和 3.0.2
进行测试和验证