Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CPackComponents/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 that allows
5
# users to select which pieces will be installed: the example
6
# application, the library binaries, and/or the header file.
7
cmake_minimum_required(VERSION 3.10)
8
project(CPackComponents)
9
10
# Create the mylib library
11
add_library(mylib mylib.cpp)
12
13
# Create the mylibapp application
14
add_executable(mylibapp mylibapp.cpp)
15
target_link_libraries(mylibapp mylib)
16
17
# On Linux, enable using an absolute install path to verify that
18
# CMAKE_INSTALL_PREFIX and CPACK_SET_DESTDIR interact properly.
19
#
20
# But only use absolute paths if not targeting an NSIS installer
21
# as indicated by CPACK_BINARY_NSIS. (If we allow this, the test
22
# fails on Linux machines with makensis installed when we are not
23
# cross-compiling...)
24
#
25
if(UNIX AND NOT APPLE)
26
if(NOT CPACK_BINARY_NSIS)
27
set(mylib_install_to_absolute_path ON)
28
endif()
29
endif()
30
31
if(mylib_install_to_absolute_path)
32
set(CMAKE_INSTALL_PREFIX "/opt/mylib")
33
set(CPACK_SET_DESTDIR ON)
34
endif()
35
36
# Create installation targets. Note that we put each kind of file
37
# into a different component via COMPONENT. These components will
38
# be used to create the installation components.
39
install(TARGETS mylib
40
ARCHIVE
41
DESTINATION lib
42
COMPONENT libraries)
43
install(TARGETS mylibapp
44
RUNTIME
45
DESTINATION bin
46
COMPONENT applications)
47
install(FILES mylib.h
48
DESTINATION include
49
COMPONENT headers)
50
install(FILES "Issue 7470.html"
51
DESTINATION docs
52
COMPONENT documentation)
53
54
if(mylib_install_to_absolute_path)
55
install(FILES mylib.cpp
56
DESTINATION /opt/mylib-source
57
COMPONENT source)
58
endif()
59
60
# CPack boilerplate for this project
61
set(CPACK_PACKAGE_NAME "MyLib")
62
set(CPACK_PACKAGE_VENDOR "CMake.org")
63
set(CPACK_PACKAGE_CONTACT "[email protected]")
64
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
65
set(CPACK_PACKAGE_VERSION "1.0.0")
66
set(CPACK_PACKAGE_VERSION_MAJOR "1")
67
set(CPACK_PACKAGE_VERSION_MINOR "0")
68
set(CPACK_PACKAGE_VERSION_PATCH "0")
69
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
70
71
# Settings used when building NSIS installers
72
set(CPACK_NSIS_MENU_LINKS
73
"ftp://ftpserver" "Test Ftp Link"
74
"ftps://ftpsserver" "Test Ftps Link"
75
"https://cmake.org" "CMake Web Site"
76
"https://github.com/" "Test Https Link"
77
"mailto:[email protected]" "Test MailTo Link"
78
"news://newsserver" "Test News Link"
79
)
80
81
# Suggested default root for end users of the installer:
82
set(CPACK_NSIS_INSTALL_ROOT "C:/Program Files/CMake Tests Install Root")
83
84
# Include CPack to introduce the appropriate targets
85
include(CPack)
86
87
# Installation types
88
cpack_add_install_type(Full
89
DISPLAY_NAME "Everything")
90
cpack_add_install_type(Developer)
91
92
# Component groups
93
cpack_add_component_group(Runtime)
94
cpack_add_component_group(Development
95
EXPANDED
96
DESCRIPTION "All of the tools you'll ever need to develop software")
97
98
# Components
99
cpack_add_component(applications
100
DISPLAY_NAME "MyLib Application"
101
DESCRIPTION "An extremely useful application that makes use of MyLib"
102
GROUP Runtime
103
INSTALL_TYPES Full)
104
cpack_add_component(documentation
105
DISPLAY_NAME "MyLib Documentation"
106
DESCRIPTION "The extensive suite of MyLib Application documentation files"
107
GROUP Runtime
108
INSTALL_TYPES Full)
109
cpack_add_component(libraries
110
DISPLAY_NAME "Libraries"
111
DESCRIPTION "Static libraries used to build programs with MyLib"
112
GROUP Development
113
INSTALL_TYPES Developer Full)
114
cpack_add_component(headers
115
DISPLAY_NAME "C++ Headers"
116
DESCRIPTION "C/C++ header files for use with MyLib"
117
GROUP Development
118
DEPENDS libraries
119
INSTALL_TYPES Developer Full)
120
121
if(mylib_install_to_absolute_path)
122
cpack_add_component(source
123
DISPLAY_NAME "C++ Source Files"
124
DESCRIPTION "C/C++ source files to build MyLib"
125
GROUP Development
126
DEPENDS libraries
127
INSTALL_TYPES Developer Full)
128
endif()
129
130