cmake - 如何在可执行文件名称中获取调试后缀

标签 cmake

我正在使用 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 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})

将使用全局变量 ${CMAKE_DEBUG_POSTFIX} 的值构建 myexeDEBUG 的目标配置。

请注意,该问题的一位评论者对变量 ${PROJECT_NAME} 的使用感到困惑。 .此变量自动设置为 myexe使用时 project(myexe) .使用 ${PROJECT_NAME}相当于 myexe它可以更轻松地复制/粘贴到新的 CMakeLists.txt。

关于cmake - 如何在可执行文件名称中获取调试后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893450/

相关文章:

c++ - cmake 不断重新生成缓存 [cmake + visual studio 打开文件夹 + ninja + clang-cl]

cmake - 为什么 CMake 检查 C++ 编译器?

c++ - 将库添加到 Cmake 项目

c++ - Visual Studio 2017 与 boost 1.64.0/1.63.0 的兼容性问题

c++ - CMake 和 Flex/Bison

c - 我如何告诉我的 IDE 以特定方式编译我的 CMake 项目?

c++ - 未添加 CMake 包含目录

qt - cmake如何包含shaders.qrc

android - 在 OpenCV 上。 C++ 编译器无法编译简单的测试程序。使用 Clang++

c++ - 如何在 biicode 中使用 Emscripten 工具链?