Path: blob/master/Tests/CPackComponentsForAll/CMakeLists.txt
3150 views
# CPack Example: User-selectable Installation Components1#2# In this example, we have a simple library (mylib) with an example3# application (mylibapp). We create a binary installer (a CPack Generator)4# which supports CPack components.5#6# Depending on the CPack generator and on some CPACK_xxx var values7# the generator may produce a single (NSIS, productbuild)8# or several package files (Archive Generators, RPM, DEB)9cmake_minimum_required(VERSION 3.10 FATAL_ERROR)10project(CPackComponentsForAll)1112# Use GNUInstallDirs in order to enforce lib64 if needed13include(GNUInstallDirs)1415# Create the mylib library16add_library(mylib mylib.cpp)1718# Create the mylibapp application19add_executable(mylibapp mylibapp.cpp)20target_link_libraries(mylibapp mylib)2122# Duplicate of mylibapp application23# which won't be put in any component (?mistake?)24add_executable(mylibapp2 mylibapp.cpp)25target_link_libraries(mylibapp2 mylib)2627# Create installation targets. Note that we put each kind of file28# into a different component via COMPONENT. These components will29# be used to create the installation components.30install(TARGETS mylib31ARCHIVE32DESTINATION ${CMAKE_INSTALL_LIBDIR}33COMPONENT libraries)34install(TARGETS mylibapp35RUNTIME36DESTINATION bin37COMPONENT applications)3839# This application does not belong to any component40# thus (as of cmake 2.8.2) it will be left "uninstalled"41# by a component-aware installer unless a42# CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).43install(TARGETS mylibapp244RUNTIME45DESTINATION bin/@in@_@path@@with\\@and\\@/\@in_path\@) # test @ char in path4647install(FILES mylib.h48DESTINATION include49COMPONENT headers)5051if("${CPACK_GENERATOR}" MATCHES "RPM")52############## test man pages53install(FILES mylib54DESTINATION share/man/mylib/man3/mylib.1)55install(FILES mylib56DESTINATION share/man/mylib/man3/mylib.1 RENAME mylib2)5758############## test symlinks59# Package symbolic links60install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)61install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable/bar COMPONENT libraries)62install(DIRECTORY DESTINATION other_relocatable/depth_two COMPONENT libraries)63install(DIRECTORY DESTINATION non_relocatable/depth_two COMPONENT libraries)64# test symbolic links to same dir65execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink depth_three symlink_samedir_path)66install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)67# test symbolic links to same dir with current dir ./ prefix68execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./depth_three symlink_samedir_path_current_dir)69install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_current_dir DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)70# test symbolic links to same dir with longer relative path71execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../${CMAKE_INSTALL_LIBDIR}/.././${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two/depth_three symlink_samedir_path_longer)72install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_longer DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)73# test symbolic links to sub dir74execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three symlink_subdir_path)75install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_subdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one COMPONENT libraries)76# test symbolic links to parent dir77execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two symlink_parentdir_path)78install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_parentdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)79# test symbolic link to another relocatable path80execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././.././../other_relocatable/./depth_two symlink_other_relocatable_path)81install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_other_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)82# test symbolic link to non relocatable path83execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../non_relocatable/./depth_two symlink_to_non_relocatable_path)84install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)85# test symbolic link from non relocatable path86execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two symlink_from_non_relocatable_path)87install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_from_non_relocatable_path DESTINATION non_relocatable/depth_two COMPONENT libraries)88# test symbolic link relocatable path to its relocatable subpath89execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../inside_relocatable_two/depth_two/different_relocatable/bar symlink_relocatable_subpath)90install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_relocatable_subpath DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)91# test symbolic link to location outside package92execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./outside_package symlink_outside_package)93install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_package DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)94# test symbolic link to location outside wdr (packaging directory)95execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink /outside_package_wdr symlink_outside_wdr)96install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_wdr DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)97endif()9899# CPack boilerplate for this project100set(CPACK_PACKAGE_NAME "MyLib")101set(CPACK_PACKAGE_CONTACT "None")102set(CPACK_PACKAGE_VENDOR "CMake.org")103set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")104set(CPACK_PACKAGE_VERSION "1.0.2")105set(CPACK_PACKAGE_VERSION_MAJOR "1")106set(CPACK_PACKAGE_VERSION_MINOR "0")107set(CPACK_PACKAGE_VERSION_PATCH "2")108set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")109set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)110111# Tell CPack all of the components to install. The "ALL"112# refers to the fact that this is the set of components that113# will be included when CPack is instructed to put everything114# into the binary installer (the default behavior).115set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)116117# Set the displayed names for each of the components to install.118# These will be displayed in the list of components inside the installer.119set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")120set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")121set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")122123# Provide descriptions for each of the components to install.124# When the user hovers the mouse over the name of a component,125# the description will be shown in the "Description" box in the126# installer. If no descriptions are provided, the "Description"127# box will be removed.128set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION129"An extremely useful application that makes use of MyLib")130set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION131"Static libraries used to build programs with MyLib")132set(CPACK_COMPONENT_HEADERS_DESCRIPTION133"C/C++ header files for use with MyLib")134135# Put the components into two different groups: "Runtime" and "Development"136set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")137set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")138set(CPACK_COMPONENT_HEADERS_GROUP "Development")139140# Expand the "Development" group by default, since we have so few components.141# Also, provide this group with a description.142set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)143set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION144"All of the tools you'll ever need to develop software")145146# It doesn't make sense to install the headers without the libraries147# (because you could never use the headers!), so make the headers component148# depend on the libraries component.149set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)150151# Create two installation types with pre-selected components.152# The "Developer" installation has just the library and headers,153# while the "Full" installation has everything.154set(CPACK_ALL_INSTALL_TYPES Full Developer)155set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")156set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)157set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)158set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)159160# set CPACK_RPM_RELOCATION_PATHS here as GNUInstallDirs script161# can not be used in CPack scripts due to CMAKE_SIZEOF_VOID_P162# variable not being set163set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"164"${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable"165"${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable")166167# set CPACK_DEBIAN_FILE_NAME to use default package name format168set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")169170# set some tags for NuGet packages171# 1. all in one package172set(CPACK_NUGET_PACKAGE_TAGS "nuget" "unit" "test" "all-in-one")173# 2. per component packages174set(CPACK_NUGET_APPLICATIONS_PACKAGE_TAGS "nuget" "unit" "test" "applications")175set(CPACK_NUGET_LIBRARIES_PACKAGE_TAGS "nuget" "unit" "test" "libraries")176set(CPACK_NUGET_HEADERS_PACKAGE_TAGS "nuget" "unit" "test" "headers")177set(CPACK_NUGET_UNSPECIFIED_PACKAGE_TAGS "nuget" "unit" "test" "uNsP3c1FiEd")178# 3. per group packages179set(CPACK_NUGET_RUNTIME_PACKAGE_TAGS "nuget" "unit" "test" "run-time")180set(CPACK_NUGET_DEVELOPMENT_PACKAGE_TAGS "nuget" "unit" "test" "development")181182# We may use the CPack specific config file in order183# to tailor CPack behavior on a CPack generator specific way184# (Behavior would be different for RPM or TGZ or DEB ...)185if (NOT ("${CPackComponentWay}" STREQUAL "default"))186# Setup project specific CPack-time CPack Config file.187configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in188${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake189@ONLY)190set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)191endif ()192# Include CPack to introduce the appropriate targets193include(CPack)194195196