How to change CPack package file name based on configuration?

Viewed 2572

In CMake, using CPack I want CPACK_PACKAGE_FILE_NAME to include -debug suffix in case the package is produced from Debug configuration. For single-configuration CMake generators this is probably doable by checking CMAKE_BUILD_TYPE, but this does not work for multi-configuration generators like Visual Studio.

2 Answers

I had the same issue which I fixed using file(GENERATE). It's a somewhat shorter solution than the previous one :

set(BUILD_TYPE <IF:$<OR:$<CONFIG:RelWithDebInfo>,$<CONFIG:Debug>>,debug,release>)
set(CPACK_PROPERTIES_FILE "${CMAKE_BINARY_DIR}/YOURPACKAGECPackProperties.cmake")
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/YOURPACKAGECPackProperties.cmake" #allows use of generator expression to retrieve CONFIG
        CONTENT "set(CPACK_PACKAGE_FILE_NAME \"yourpackagename_${BUILD_TYPE}\")\n")
Related