Building the "package" target fails if CPACK_INSTALL_CMAKE_CONFIGURATIONS contains more than one config
!3533 (merged) introduced the new CPACK_INSTALL_CMAKE_CONFIGURATIONS
variable. If it is set to more than one configuration, then building the package
target from a clean build directory will fail. Here's a minimal project used to reproduce the problem:
cmake_minimum_required(VERSION 3.15)
project(MultiConfigInstall)
add_executable(barry main.cpp)
install(TARGETS barry RUNTIME DESTINATION bin/$<CONFIG>)
set(CPACK_GENERATOR ZIP)
set(CPACK_INSTALL_CMAKE_CONFIGURATIONS Debug Release)
include(CPack)
Issue the following commands to reproduce the build error using Xcode (MSVC has the same behavior too):
# Assuming the build directory doesn't exist yet
mkdir build
cd build
cmake -G Xcode ..
cmake --build . --target package
Building the package
target fails because it only tries to build one configuration (Debug), but then when it invokes cpack
, the build for the other configuration is missing. If you manually build both targets first, then the package is built successfully and contains both configurations. The package
target will need to learn to recognise that multiple configurations are needed and build all of the ones listed in CPACK_INSTALL_CMAKE_CONFIGURATIONS
before it runs cpack
.
There is also a similar situation for the clean
target as well which will become more important once the above issue is addressed.
Ignore the rest of the description below, it is incorrect (kept here only so that the comment history makes sense)
Doing the same thing with the Visual Studio generator gives no error, but only the Debug configuration is included in the package, even if you manually build both the Debug and Release configurations first. Even if you invoke cpack -C "Debug;Release"
directly, the package includes either just the Debug configuration or nothing at all (again, even if you manually build both configurations first). Which result I get seems to depend on things I may have done beforehand.
Continuing with Visual Studio, if you run cpack
without the -C
option, you get an empty package if you haven't built the Release configuration, or you get just the Release configuration if you've built that configuration. In either case, no errors are raised. The Debug configuration gets completely ignored, despite it being listed in CPACK_INSTALL_CMAKE_CONFIGURATIONS
. It's possible that there might be different results depending on what steps you've done beforehand.