问题
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
回答1:
Per one user here, it may be possible to workaround this behaviour by lying to CPack about what CMake generator you are using.
It seems that CPack only runs the preinstall target for builds using Unix Makefiles as the CMake generator. Setting the variable CPACK_CMAKE_GENERATOR
to a different generator available on your system will change CPack's behaviour, but CMake will still build using whatever generator was specified for it to use.
The user in the linked thread seems to have had luck specifying XCode as the CPack CMake generator, and I've had success specifying Ninja.
For example, you could try adding a line like
set(CPACK_CMAKE_GENERATOR Ninja)
so that CPack won't try to run the preinstall target.
来源:https://stackoverflow.com/questions/36689963/cpack-tries-to-build-all-targets