I have a CMake project composed of one root CMakeLists and multiple sub-CMakeLists (one for each project).
I am trying to use CPack to generate a .deb file for one of these projects (APP_client).
Yet, when I try to run CPack, it first runs a 'preinstall' and try to build all targets.
I want to build only the required targets and their dependencies.
Here is what I added to one of my CMakeLists:
if(UNIX)
INSTALL(
TARGETS ${PROJECT_NAME}
COMPONENT ${PROJECT_NAME}
DESTINATION ${PROJECT_INSTALL_PATH}
)
SET(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/../deb)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
SET(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_version})
SET(CPACK_DEBIAN_PACKAGE_NAME ${PROJECT_NAME})
SET(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_version})
INCLUDE(CPack)
endif()
Here is what I get when I try tu run cpack -V
CPack: Enable Verbose
CPack Verbose: Read CPack config file:
CPack Verbose: Read CPack configuration file: [...]/CPackConfig.cmake
CPack Verbose: Specified generator: DEB
CPack Verbose: Use generator: cmCPackDebGenerator
CPack Verbose: For project: APP_client
CPack: Create package using DEB
CPack Verbose: Read description file: [...]/CPack.GenericDescription.txt
CPack Verbose: [DEB] requested component grouping = ONE_PER_GROUP
CPack Verbose: Remove toplevel directory: [...]/../deb/APP_client/_CPack_Packages/Linux/DEB
CPack: Install projects
CPack: - Run preinstall target for: ROOT
CPack Error: Problem running install command: /home/gitlab-runner/cmake/bin/cmake --build . --target "preinstall"
Please check [...]/../deb/APP_client/_CPack_Packages/Linux/DEB/PreinstallOutput.log for errors
CPack Error: Error when generating package: APP_client
The preinstall fails because it is trying to build another target and fails to link it.
I am using CMake 3.5
install()targets of CMake doesn't carry make-like dependencies fromadd_executable/add_librarycalls. So, even when CPack needs to prepare only part of prerequesites, it unconditionally builds all targets. You should tune (e,g., with option variables) your CMake project for build lesser number of targets. - Tsyvarev