Hello,
I am very new to packaging targets and files using components.
My goal was that I want 2 different packages, that contain the same binary each and different files and based on which package is installed, the binary will read the file that is available to it.
I found the solution below that works and does what I need and what I expect.
cmake_minimum_required(VERSION 3.11.0)
project(TestApp VERSION 1.0.0 LANGUAGES CXX)
add_executable(${PROJECT_NAME} main.cpp)
install(TARGETS ${PROJECT_NAME}
RUNTIME
DESTINATION bin/dev
COMPONENT DEV
)
install(FILES
${CMAKE_SOURCE_DIR}/numbers_dev.txt
DESTINATION bin/dev
COMPONENT DEV
)
install(TARGETS ${PROJECT_NAME}
RUNTIME
DESTINATION bin/default
COMPONENT DEFAULT
)
install(FILES
${CMAKE_SOURCE_DIR}/numbers_default.txt
DESTINATION bin/default
COMPONENT DEFAULT
)
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_GENERATOR "TGZ")
set(CPACK_ARCHIVE_DEV_FILE_NAME "dev")
set(CPACK_ARCHIVE_DEFAULT_FILE_NAME "default")
set(CPACK_COMPONENTS_ALL "")
list(APPEND CPACK_COMPONENTS_ALL "DEV" "DEFAULT")
include(CPack)
I would like to ask if there could be better/another solution in CMake to what I want to do ?
As far as I know I cannot assign 2 component names like this:
install(TARGETS ${PROJECT_NAME}
RUNTIME
DESTINATION bin/dev
COMPONENT DEV DEFAULT # cmake error
)
I also know that something like this would not work either:
install(TARGETS ${PROJECT_NAME}
RUNTIME
DESTINATION bin/dev
COMPONENT DEV
RUNTIME
DESTINATION bin/default
COMPONENT DEFAULT # this one makes the first one obsolete
)