在中CMake
add_custom_command
可以执行构建后命令,例如strip
。该PROJECT_NAME
变量定义为目标二进制文件,例如
# Set the project name
set(PROJECT_NAME "MyProject")
project(${PROJECT_NAME})
Run Code Online (Sandbox Code Playgroud)
将以下代码add_executable
放在您的之后CMakeLists.txt
:
# Strip binary for release builds
if (CMAKE_BUILD_TYPE STREQUAL Release)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP} ${PROJECT_NAME})
endif ()
Run Code Online (Sandbox Code Playgroud)
该CMAKE_BUILD_TYPE
指示生成类型像Debug
或Release
。CMAKE_STRIP
是文件路径平台的strip
实用程序(如/usr/bin/strip
上Linux
)。