Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CPackComponentsForAll/CMakeLists.txt
3150 views
1
# CPack Example: User-selectable Installation Components
2
#
3
# In this example, we have a simple library (mylib) with an example
4
# application (mylibapp). We create a binary installer (a CPack Generator)
5
# which supports CPack components.
6
#
7
# Depending on the CPack generator and on some CPACK_xxx var values
8
# the generator may produce a single (NSIS, productbuild)
9
# or several package files (Archive Generators, RPM, DEB)
10
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
11
project(CPackComponentsForAll)
12
13
# Use GNUInstallDirs in order to enforce lib64 if needed
14
include(GNUInstallDirs)
15
16
# Create the mylib library
17
add_library(mylib mylib.cpp)
18
19
# Create the mylibapp application
20
add_executable(mylibapp mylibapp.cpp)
21
target_link_libraries(mylibapp mylib)
22
23
# Duplicate of mylibapp application
24
# which won't be put in any component (?mistake?)
25
add_executable(mylibapp2 mylibapp.cpp)
26
target_link_libraries(mylibapp2 mylib)
27
28
# Create installation targets. Note that we put each kind of file
29
# into a different component via COMPONENT. These components will
30
# be used to create the installation components.
31
install(TARGETS mylib
32
ARCHIVE
33
DESTINATION ${CMAKE_INSTALL_LIBDIR}
34
COMPONENT libraries)
35
install(TARGETS mylibapp
36
RUNTIME
37
DESTINATION bin
38
COMPONENT applications)
39
40
# This application does not belong to any component
41
# thus (as of cmake 2.8.2) it will be left "uninstalled"
42
# by a component-aware installer unless a
43
# CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
44
install(TARGETS mylibapp2
45
RUNTIME
46
DESTINATION bin/@in@_@path@@with\\@and\\@/\@in_path\@) # test @ char in path
47
48
install(FILES mylib.h
49
DESTINATION include
50
COMPONENT headers)
51
52
if("${CPACK_GENERATOR}" MATCHES "RPM")
53
############## test man pages
54
install(FILES mylib
55
DESTINATION share/man/mylib/man3/mylib.1)
56
install(FILES mylib
57
DESTINATION share/man/mylib/man3/mylib.1 RENAME mylib2)
58
59
############## test symlinks
60
# Package symbolic links
61
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
62
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable/bar COMPONENT libraries)
63
install(DIRECTORY DESTINATION other_relocatable/depth_two COMPONENT libraries)
64
install(DIRECTORY DESTINATION non_relocatable/depth_two COMPONENT libraries)
65
# test symbolic links to same dir
66
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink depth_three symlink_samedir_path)
67
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
68
# test symbolic links to same dir with current dir ./ prefix
69
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./depth_three symlink_samedir_path_current_dir)
70
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_current_dir DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
71
# test symbolic links to same dir with longer relative path
72
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)
73
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_longer DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
74
# test symbolic links to sub dir
75
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three symlink_subdir_path)
76
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_subdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one COMPONENT libraries)
77
# test symbolic links to parent dir
78
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two symlink_parentdir_path)
79
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_parentdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
80
# test symbolic link to another relocatable path
81
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././.././../other_relocatable/./depth_two symlink_other_relocatable_path)
82
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_other_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
83
# test symbolic link to non relocatable path
84
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../non_relocatable/./depth_two symlink_to_non_relocatable_path)
85
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
86
# test symbolic link from non relocatable path
87
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two symlink_from_non_relocatable_path)
88
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_from_non_relocatable_path DESTINATION non_relocatable/depth_two COMPONENT libraries)
89
# test symbolic link relocatable path to its relocatable subpath
90
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../inside_relocatable_two/depth_two/different_relocatable/bar symlink_relocatable_subpath)
91
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_relocatable_subpath DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
92
# test symbolic link to location outside package
93
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./outside_package symlink_outside_package)
94
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_package DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
95
# test symbolic link to location outside wdr (packaging directory)
96
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink /outside_package_wdr symlink_outside_wdr)
97
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_wdr DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
98
endif()
99
100
# CPack boilerplate for this project
101
set(CPACK_PACKAGE_NAME "MyLib")
102
set(CPACK_PACKAGE_CONTACT "None")
103
set(CPACK_PACKAGE_VENDOR "CMake.org")
104
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
105
set(CPACK_PACKAGE_VERSION "1.0.2")
106
set(CPACK_PACKAGE_VERSION_MAJOR "1")
107
set(CPACK_PACKAGE_VERSION_MINOR "0")
108
set(CPACK_PACKAGE_VERSION_PATCH "2")
109
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
110
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
111
112
# Tell CPack all of the components to install. The "ALL"
113
# refers to the fact that this is the set of components that
114
# will be included when CPack is instructed to put everything
115
# into the binary installer (the default behavior).
116
set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
117
118
# Set the displayed names for each of the components to install.
119
# These will be displayed in the list of components inside the installer.
120
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
121
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
122
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
123
124
# Provide descriptions for each of the components to install.
125
# When the user hovers the mouse over the name of a component,
126
# the description will be shown in the "Description" box in the
127
# installer. If no descriptions are provided, the "Description"
128
# box will be removed.
129
set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
130
"An extremely useful application that makes use of MyLib")
131
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
132
"Static libraries used to build programs with MyLib")
133
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
134
"C/C++ header files for use with MyLib")
135
136
# Put the components into two different groups: "Runtime" and "Development"
137
set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
138
set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
139
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
140
141
# Expand the "Development" group by default, since we have so few components.
142
# Also, provide this group with a description.
143
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
144
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
145
"All of the tools you'll ever need to develop software")
146
147
# It doesn't make sense to install the headers without the libraries
148
# (because you could never use the headers!), so make the headers component
149
# depend on the libraries component.
150
set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
151
152
# Create two installation types with pre-selected components.
153
# The "Developer" installation has just the library and headers,
154
# while the "Full" installation has everything.
155
set(CPACK_ALL_INSTALL_TYPES Full Developer)
156
set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
157
set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
158
set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
159
set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
160
161
# set CPACK_RPM_RELOCATION_PATHS here as GNUInstallDirs script
162
# can not be used in CPack scripts due to CMAKE_SIZEOF_VOID_P
163
# variable not being set
164
set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
165
"${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable"
166
"${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable")
167
168
# set CPACK_DEBIAN_FILE_NAME to use default package name format
169
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
170
171
# set some tags for NuGet packages
172
# 1. all in one package
173
set(CPACK_NUGET_PACKAGE_TAGS "nuget" "unit" "test" "all-in-one")
174
# 2. per component packages
175
set(CPACK_NUGET_APPLICATIONS_PACKAGE_TAGS "nuget" "unit" "test" "applications")
176
set(CPACK_NUGET_LIBRARIES_PACKAGE_TAGS "nuget" "unit" "test" "libraries")
177
set(CPACK_NUGET_HEADERS_PACKAGE_TAGS "nuget" "unit" "test" "headers")
178
set(CPACK_NUGET_UNSPECIFIED_PACKAGE_TAGS "nuget" "unit" "test" "uNsP3c1FiEd")
179
# 3. per group packages
180
set(CPACK_NUGET_RUNTIME_PACKAGE_TAGS "nuget" "unit" "test" "run-time")
181
set(CPACK_NUGET_DEVELOPMENT_PACKAGE_TAGS "nuget" "unit" "test" "development")
182
183
# We may use the CPack specific config file in order
184
# to tailor CPack behavior on a CPack generator specific way
185
# (Behavior would be different for RPM or TGZ or DEB ...)
186
if (NOT ("${CPackComponentWay}" STREQUAL "default"))
187
# Setup project specific CPack-time CPack Config file.
188
configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in
189
${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake
190
@ONLY)
191
set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)
192
endif ()
193
# Include CPack to introduce the appropriate targets
194
include(CPack)
195
196