2010-12-03 00:56:26 +03:00
|
|
|
# CPack Example: User-selectable Installation Components
|
|
|
|
#
|
|
|
|
# In this example, we have a simple library (mylib) with an example
|
|
|
|
# application (mylibapp). We create a binary installer (a CPack Generator)
|
|
|
|
# which supports CPack components.
|
|
|
|
#
|
|
|
|
# Depending on the CPack generator and on some CPACK_xxx var values
|
|
|
|
# the generator may produce a single (NSIS, PackageMaker)
|
|
|
|
# or several package files (Archive Generators, RPM, DEB)
|
2010-12-11 13:59:02 +03:00
|
|
|
cmake_minimum_required(VERSION 2.8.3.20101130 FATAL_ERROR)
|
2010-12-03 00:56:26 +03:00
|
|
|
project(CPackComponentsForAll)
|
|
|
|
|
2011-03-28 23:10:52 +04:00
|
|
|
# Use GNUInstallDirs in order to enforce lib64 if needed
|
|
|
|
include(GNUInstallDirs)
|
2011-03-13 23:15:49 +03:00
|
|
|
|
2010-12-03 00:56:26 +03:00
|
|
|
# Create the mylib library
|
|
|
|
add_library(mylib mylib.cpp)
|
|
|
|
|
|
|
|
# Create the mylibapp application
|
|
|
|
add_executable(mylibapp mylibapp.cpp)
|
|
|
|
target_link_libraries(mylibapp mylib)
|
|
|
|
|
|
|
|
# Duplicate of mylibapp application
|
|
|
|
# which won't be put in any component (?mistake?)
|
|
|
|
add_executable(mylibapp2 mylibapp.cpp)
|
|
|
|
target_link_libraries(mylibapp2 mylib)
|
|
|
|
|
|
|
|
# Create installation targets. Note that we put each kind of file
|
|
|
|
# into a different component via COMPONENT. These components will
|
|
|
|
# be used to create the installation components.
|
|
|
|
install(TARGETS mylib
|
|
|
|
ARCHIVE
|
2011-03-28 23:10:52 +04:00
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2010-12-03 00:56:26 +03:00
|
|
|
COMPONENT libraries)
|
|
|
|
install(TARGETS mylibapp
|
|
|
|
RUNTIME
|
|
|
|
DESTINATION bin
|
|
|
|
COMPONENT applications)
|
|
|
|
|
|
|
|
# This application does not belong to any component
|
|
|
|
# thus (as of cmake 2.8.2) it will be left "uninstalled"
|
|
|
|
# by a component-aware installer unless a
|
|
|
|
# CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
|
|
|
|
install(TARGETS mylibapp2
|
|
|
|
RUNTIME
|
2015-01-07 22:33:27 +03:00
|
|
|
DESTINATION bin/@in@_@path@@with\\@and\\@/\@in_path\@) # test @ char in path
|
2010-12-03 00:56:26 +03:00
|
|
|
|
|
|
|
install(FILES mylib.h
|
|
|
|
DESTINATION include
|
|
|
|
COMPONENT headers)
|
|
|
|
|
2015-03-29 21:55:20 +03:00
|
|
|
if("${CPACK_GENERATOR}" MATCHES "RPM")
|
2015-04-19 19:22:18 +03:00
|
|
|
############## test man pages
|
|
|
|
install(FILES mylib
|
|
|
|
DESTINATION share/man/mylib/man3/mylib.1)
|
|
|
|
install(FILES mylib
|
|
|
|
DESTINATION share/man/mylib/man3/mylib.1 RENAME mylib2)
|
|
|
|
|
|
|
|
############## test symlinks
|
2015-03-29 21:55:20 +03:00
|
|
|
# Package symbolic links
|
|
|
|
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
|
|
|
|
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable/bar COMPONENT libraries)
|
|
|
|
install(DIRECTORY DESTINATION other_relocatable/depth_two COMPONENT libraries)
|
|
|
|
install(DIRECTORY DESTINATION non_relocatable/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic links to same dir
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink depth_three symlink_samedir_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic links to same dir with current dir ./ prefix
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./depth_three symlink_samedir_path_current_dir)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_current_dir DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic links to same dir with longer relative path
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../${CMAKE_INSTALL_LIBDIR}/.././${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two/depth_three symlink_samedir_path_longer)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_longer DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic links to sub dir
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three symlink_subdir_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_subdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one COMPONENT libraries)
|
|
|
|
# test symbolic links to parent dir
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two symlink_parentdir_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_parentdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
|
|
|
|
# test symbolic link to another relocatable path
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././.././../other_relocatable/./depth_two symlink_other_relocatable_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_other_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic link to non relocatable path
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../non_relocatable/./depth_two symlink_to_non_relocatable_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic link from non relocatable path
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two symlink_from_non_relocatable_path)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_from_non_relocatable_path DESTINATION non_relocatable/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic link relocatable path to its relocatable subpath
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../inside_relocatable_two/depth_two/different_relocatable/bar symlink_relocatable_subpath)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_relocatable_subpath DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
|
|
|
# test symbolic link to location outside package
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./outside_package symlink_outside_package)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_package DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
2016-03-31 08:48:38 +03:00
|
|
|
# test symbolic link to location outside wdr (packaging directory)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink /outside_package_wdr symlink_outside_wdr)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_wdr DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
|
2015-03-29 21:55:20 +03:00
|
|
|
endif()
|
|
|
|
|
2010-12-03 00:56:26 +03:00
|
|
|
# CPack boilerplate for this project
|
|
|
|
set(CPACK_PACKAGE_NAME "MyLib")
|
|
|
|
set(CPACK_PACKAGE_CONTACT "None")
|
|
|
|
set(CPACK_PACKAGE_VENDOR "CMake.org")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
|
|
|
|
set(CPACK_PACKAGE_VERSION "1.0.2")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR "1")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR "0")
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH "2")
|
|
|
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
|
2013-11-01 06:14:58 +04:00
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
|
2010-12-03 00:56:26 +03:00
|
|
|
|
|
|
|
# Tell CPack all of the components to install. The "ALL"
|
|
|
|
# refers to the fact that this is the set of components that
|
|
|
|
# will be included when CPack is instructed to put everything
|
|
|
|
# into the binary installer (the default behavior).
|
|
|
|
set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
|
|
|
|
|
|
|
|
# Set the displayed names for each of the components to install.
|
|
|
|
# These will be displayed in the list of components inside the installer.
|
|
|
|
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
|
|
|
|
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
|
|
|
|
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
|
|
|
|
|
|
|
|
# Provide descriptions for each of the components to install.
|
|
|
|
# When the user hovers the mouse over the name of a component,
|
|
|
|
# the description will be shown in the "Description" box in the
|
|
|
|
# installer. If no descriptions are provided, the "Description"
|
|
|
|
# box will be removed.
|
|
|
|
set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
|
|
|
|
"An extremely useful application that makes use of MyLib")
|
|
|
|
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
|
|
|
|
"Static libraries used to build programs with MyLib")
|
|
|
|
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
|
|
|
|
"C/C++ header files for use with MyLib")
|
|
|
|
|
|
|
|
# Put the components into two different groups: "Runtime" and "Development"
|
|
|
|
set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
|
|
|
|
set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
|
|
|
|
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
|
|
|
|
|
|
|
|
# Expand the "Development" group by default, since we have so few components.
|
|
|
|
# Also, provide this group with a description.
|
|
|
|
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
|
|
|
|
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
|
|
|
|
"All of the tools you'll ever need to develop software")
|
|
|
|
|
|
|
|
# It doesn't make sense to install the headers without the libraries
|
|
|
|
# (because you could never use the headers!), so make the headers component
|
|
|
|
# depend on the libraries component.
|
|
|
|
set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
|
|
|
|
|
|
|
|
# Create two installation types with pre-selected components.
|
|
|
|
# The "Developer" installation has just the library and headers,
|
|
|
|
# while the "Full" installation has everything.
|
|
|
|
set(CPACK_ALL_INSTALL_TYPES Full Developer)
|
|
|
|
set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
|
|
|
|
set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
|
|
|
|
set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
|
|
|
|
set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
|
|
|
|
|
2015-01-21 02:29:46 +03:00
|
|
|
# set CPACK_RPM_RELOCATION_PATHS here as GNUInstallDirs script
|
|
|
|
# can not be used in CPack scripts due to CMAKE_SIZEOF_VOID_P
|
|
|
|
# variable not being set
|
|
|
|
set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
|
2015-03-29 21:55:20 +03:00
|
|
|
"${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable"
|
|
|
|
"${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable")
|
2015-01-21 02:29:46 +03:00
|
|
|
|
2010-12-03 00:56:26 +03:00
|
|
|
# We may use the CPack specific config file in order
|
2011-01-30 15:11:25 +03:00
|
|
|
# to tailor CPack behavior on a CPack generator specific way
|
2010-12-03 00:56:26 +03:00
|
|
|
# (Behavior would be different for RPM or TGZ or DEB ...)
|
2011-01-30 15:11:25 +03:00
|
|
|
if (NOT ("${CPackComponentWay}" STREQUAL "default"))
|
2010-12-03 00:56:26 +03:00
|
|
|
# Setup project specific CPack-time CPack Config file.
|
2011-01-30 15:11:25 +03:00
|
|
|
configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in
|
|
|
|
${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake
|
2010-12-03 00:56:26 +03:00
|
|
|
@ONLY)
|
2011-01-30 15:11:25 +03:00
|
|
|
set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2010-12-03 00:56:26 +03:00
|
|
|
# Include CPack to introduce the appropriate targets
|
2013-11-01 06:14:58 +04:00
|
|
|
include(CPack)
|