CPack/Archive: Not setting CPACK_ARCHIVE_COMPONENT_INSTALL=ON results in error message
my zip file creation function:
function(package_zip NAME SUFFIX CONFIG)
unset(options)
unset(oneValueArgs)
set(multiValueArgs TARGETS)
cmake_parse_arguments(FUNC_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(FUNC_ARGS_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments to package_zip; ${FUNC_ARGS_UNPARSED_ARGUMENTS}")
endif()
# Get the entire list of targets, including the top-level ones.
get_recursive_dependency_list(FULL_TARGET_LIST ${FUNC_ARGS_TARGETS})
list(PREPEND FULL_TARGET_LIST ${FUNC_ARGS_TARGETS})
list(REMOVE_DUPLICATES FULL_TARGET_LIST)
filter_target_type(FULL_TARGET_LIST STATIC_LIBRARY)
filter_target_type(FULL_TARGET_LIST INTERFACE_LIBRARY)
split_out_imported_targets(FULL_TARGET_LIST IMPORTED_TARGET_LIST)
# Install each target into the folder created for cpack to pack into a zip.
#
# TODO: If we omit the CONFIGURATIONS, or omit the ${CONFIG} from the COMPONENT part
# Then we get release artifacts in the debug zip.
install(TARGETS ${FULL_TARGET_LIST}
RUNTIME EXCLUDE_FROM_ALL COMPONENT ${NAME} DESTINATION .
LIBRARY EXCLUDE_FROM_ALL COMPONENT ${NAME} DESTINATION .
# Install any additional installation files to the destination.
# the actual destination directory is relative to the base-dir for each such file set
# and controlled by the target...
FILE_SET ininbuild_additional_install_files EXCLUDE_FROM_ALL COMPONENT ${NAME} DESTINATION .
)
install(IMPORTED_RUNTIME_ARTIFACTS ${IMPORTED_TARGET_LIST}
RUNTIME EXCLUDE_FROM_ALL COMPONENT ${NAME} DESTINATION .
LIBRARY EXCLUDE_FROM_ALL COMPONENT ${NAME} DESTINATION .
)
if(CONFIG STREQUAL "Debug")
set(CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY TRUE)
endif()
# Install "system" runtime libraries.
#set(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT ${NAME})
#include(InstallRequiredSystemLibraries)
# See example of how to use the requested config in the output filename.
# might be we can use this to unify all configs into a single config.
# https://gitlab.kitware.com/cmake/cmake/-/issues/10940
#string(TOUPPER ${NAME} UPPER_COMP_NAME)
#set(CPACK_ARCHIVE_${UPPER_COMP_NAME}_FILE_NAME ${NAME}-${SUFFIX})
set(CPACK_PACKAGE_NAME ${NAME})
set(CPACK_PACKAGE_FILE_NAME ${NAME}-${SUFFIX})
# We don't bother trying to set CPACK_ARCHIVE_FILE_NAME
# https://gitlab.kitware.com/cmake/cmake/-/issues/20419
cmake_path(SET CPACK_OUTPUT_CONFIG_FILE NORMALIZE "${CMAKE_BINARY_DIR}/BuildCPackConfigs/${NAME}-${CONFIG}.cmake")
cmake_path(SET CPACK_OUTPUT_FILE_PREFIX NORMALIZE "${TIER_ROOT_CURRENT}/pub/gen/distrib")
cmake_path(SET OUTPUT_FILE_DESTINATION NORMALIZE "${CPACK_OUTPUT_FILE_PREFIX}/${NAME}-${SUFFIX}.zip")
set(CPACK_GENERATOR "ZIP")
set(CPACK_SOURCE_ZIP OFF)
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_ARCHIVE_FILE_NAME "")
set(CPACK_PACKAGE_VENDOR "Genesys")
set(CPACK_COMPONENTS_ALL ${NAME})
# Parallel archiving
set(CPACK_THREADS 0)
set(CPACK_ARCHIVE_THREADS 0)
set(CPACK_INSTALL_PREFIX "")
include(CPack)
# https://gitlab.kitware.com/cmake/cmake/-/issues/8438
if(NOT TARGET distrib)
add_custom_target(distrib)
endif()
add_custom_command(OUTPUT "${OUTPUT_FILE_DESTINATION}"
MAIN_DEPENDENCY "${CPACK_OUTPUT_CONFIG_FILE}"
DEPENDS ${FUNC_ARGS_TARGETS}
COMMAND ${CMAKE_CPACK_COMMAND} -C ${CONFIG} --config ${CPACK_OUTPUT_CONFIG_FILE})
# Give the packaging target a friendly name that doesn't have a timestamp in it.
set(PACKAGE_TARGET_NAME "package_${NAME}_${CONFIG}_zip")
add_custom_target(${PACKAGE_TARGET_NAME} DEPENDS "${OUTPUT_FILE_DESTINATION}")
# Unfortunately, we cannot depend only on the version of "package_...zip" for the currently built config(s).
# see https://gitlab.kitware.com/cmake/cmake/-/issues/19467
# As such, any callers of this package_zips function must only ask for build configurations that will actually be built.
add_dependencies(distrib ${PACKAGE_TARGET_NAME})
endfunction()
This function is called multiple times with different package names, suffixes, and configs.
Each time it's called, the list of targets to install into the zip changes, but for the most part, the lower level dependencies are duplicated across each zip file.
Each target is also configured to install (when the install target is built, instead of the distrib target) to various places on the filesystem as well.
If I comment out the line set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
I get this error.
CMake Error at D:/builds/cmake-team-cmake-build-l64f/blahblahblah/cmake_install.cmake:54 (file):
file INSTALL cannot find
"D:/builds/cmake-team-cmake-build-l64f/artifacts/my-build-artifact-here":
File exists.
Call Stack (most recent call first):
.... blahblah ....
D:/builds/cmake-team-cmake-build-l64f/cmake_install.cmake:82 (include)
This error message is useless. Can't find the file because the file exists?
If I do not comment the line out, things work as expected (aside from the bugs in the comments in the code snippet)
Edited by Craig Scott