Renaming cpack automatic target
Question
When you INCLUDE(CPack)
in a CMakeLists.txt
file, it adds a target named package
to the generated build files. You can configure a lot of things about that generated target and how it operates, but I can't seem to find a way to change the name of the target itself; i.e., instead of a generated Makefile
containing a target named package
, I'd like it to contain one named (for example) bundle
instead. Is there any way to do this?
Solution
CMake only adds the default package
target if a package config file named CPackConfig.cmake
exists in the outermost binary build directory. By forcing the CPack module to generate the package file under a different name, you can prevent the package
target from being created:
set (CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/BundleConfig.cmake")
include(CPack)
You can manually add a bundle
target then:
add_custom_target(bundle
COMMAND "${CMAKE_CPACK_COMMAND}"
"-C" "$<CONFIGURATION>" "--config" "${CMAKE_BINARY_DIR}/BundleConfig.cmake")
This is also true for the default package_source
target. Use the variable CPACK_SOURCE_OUTPUT_CONFIG_FILE
to override the default package configuration file name CPackSourceConfig.cmake
.