Post build step for release build only

I am trying to configure the post-build command for CMake, which I did using the ADD_CUSTOM_COMMAND directive, as indicated in the CMake documentation. What I would like to do is only run post-build if I create a release build for my executable.

How to do it?

+3
source share
2 answers

For Makefile-based generators, you can check the variable CMAKE_BUILD_TYPEand act on its value:

if(CMAKE_BUILD_TYPE STREQUAL Debug)
    message(STATUS "Do debug stuff")
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
    message(STATUS "Do release stuff")
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
    message(STATUS "Do release with debug info stuff")
elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
    message(STATUS "Do minimal size release stuff")
endif()

For Visual Studio-based builds, this SO question seems CMAKE_BUILD_TYPEto work with VS 2005+ as well.

+2
source

- , DLL , . , ($<...> ). , ( ), , , , google:

set(no_copy $<NOT:$<CONFIG:Release>>)
add_custom_command(TARGET myDLL POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E
    # do nothing for non-Release build
    $<${no_copy}:echo>    $<${no_copy}:"copy omitted for non-release build, command would have been ">
    # copy file for release build
    copy_if_different $<TARGET_FILE:myDLL> ${DIR_FOR_DLL})

, echo , . , cmake. , , , . , , , if($<CONFIG:Release>) ... endif(), .

+1

Source: https://habr.com/ru/post/1720998/


All Articles