-
Notifications
You must be signed in to change notification settings - Fork 11
/
BasisPack.cmake
341 lines (295 loc) · 11.9 KB
/
BasisPack.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# ============================================================================
# Copyright (c) 2011-2012 University of Pennsylvania
# Copyright (c) 2013-2014 Andreas Schuh
# All rights reserved.
#
# See COPYING file for license information or visit
# http://opensource.andreasschuh.com/cmake-basis/download.html#license
# ============================================================================
##############################################################################
# @file BasisPack.cmake
# @brief CPack configuration. Include this module instead of CPack.
#
# @note This module is included by basis_project_finalize().
#
# This module implements the packaging of BASIS projects.
#
# Overwrite the package information set by this module either in a file
# Package.cmake or a file Package.cmake.in located in the directory
# specified by PROJECT_CONFIG_DIR. The latter is configured and copied to the
# binary tree before included by this module. Further, to enable a
# component-based installation, provide either a file Components.cmake or
# Components.cmake.in again in the directory specified by PROJECT_CONFIG_DIR.
# Also in this case, the latter is configured via CMake's configure_file()
# before use. This file is referred to as components definition (file).
#
# Components can be added in the components definition using the command
# basis_add_component(). Several components can be grouped together and a
# group description be added using the command basis_add_component_group().
# Different pre-configured install types which define a certain selection of
# components to install can be added using basis_add_install_type().
# Note that all these BASIS functions are wrappers around the corresponding
# CPack functions.
#
# @sa CPack.cmake
# @sa http://www.vtk.org/Wiki/CMake:Component_Install_With_CPack#Component-Based_Installers_with_CPack
#
# @ingroup CMakeAPI
##############################################################################
# ============================================================================
# local variables
# ============================================================================
basis_get_relative_path (_TEST_DIR "${PROJECT_SOURCE_DIR}" "${PROJECT_TESTING_DIR}")
basis_get_relative_path (_MODULES_DIR "${PROJECT_SOURCE_DIR}" "${PROJECT_MODULES_DIR}")
# ============================================================================
# system libraries
# ============================================================================
# find required runtime libraries
set (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
include (InstallRequiredSystemLibraries)
# include system runtime libraries in the installation
if (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
if (WIN32)
install (
PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
DESTINATION ${INSTALL_RUNTIME_DIR}
)
else ()
install (
PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
DESTINATION ${INSTALL_LIBRARY_DIR}
)
endif ()
endif ()
# ============================================================================
# package information
# ============================================================================
# general information
set (CPACK_PACKAGE_NAME "${PROJECT_PACKAGE_NAME}")
set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set (CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set (CPACK_PACKAGE_CONTACT "${PROJECT_CONTACT}")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
if (PROJECT_README_FILE)
set (CPACK_RESOURCE_FILE_README "${PROJECT_README_FILE}")
endif ()
if (PROJECT_COPYING_FILE)
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_COPYING_FILE}")
endif ()
if (PROJECT_PROVIDER_NAME AND PROJECT_DIVISION_NAME)
set (CPACK_PACKAGE_VENDOR "${PROJECT_DIVISION_NAME}, ${PROJECT_PROVIDER_NAME}")
elseif (PROJECT_PROVIDER_NAME)
set (CPACK_PACKAGE_VENDOR "${PROJECT_PROVIDER_NAME}")
elseif (PROJECT_DIVISION_NAME)
set (CPACK_PACKAGE_VENDOR "${PROJECT_DIVISION_NAME}")
elseif (PROJECT_PACKAGE_VENDOR)
set (CPACK_PACKAGE_VENDOR "${PROJECT_PACKAGE_VENDOR}")
else ()
set (CPACK_PACKAGE_VENDOR "")
endif ()
if (PROJECT_INSTALL_FILE)
set (CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_INSTALL_FILE}")
endif ()
if (PROJECT_WELCOME_FILE)
set (CPACK_RESOURCE_FILE_WELCOME "${PROJECT_WELCOME_FILE}")
endif ()
set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set (CPACK_PACKAGE_RELOCATABLE "true")
# system name
string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
if (${CPACK_SYSTEM_NAME} MATCHES "windows")
if (CMAKE_CL_64)
set (CPACK_SYSTEM_NAME "win64")
else ()
set (CPACK_SYSTEM_NAME "win32")
endif ()
endif ()
# binary package
set (CPACK_GENERATOR "TGZ")
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY "1")
set (CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
set (CPACK_PACKAGE_FILE_NAME "${PROJECT_PACKAGE_NAME_L}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}")
if (CMAKE_SYSTEM_PROCESSOR)
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
endif ()
# source package
set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-source")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_PACKAGE_NAME_L}-${PROJECT_VERSION}-source")
# ----------------------------------------------------------------------------
# TODO The proper values for the following options still need to be
# figured. For the moment, just ignore these settings. NSIS might
# anyways not be supported in the near future.
# ----------------------------------------------------------------------------
if (WIN32 AND NOT UNIX)
# There is a bug in NSI that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
# set (CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
# set (CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\MyExecutable.exe")
# set (CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
# set (CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.my-project-home-page.org")
# set (CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.my-personal-home-page.com")
set (CPACK_NSIS_CONTACT "${PROJECT_CONTACT}")
set (CPACK_NSIS_MODIFY_PATH "ON")
else ()
# set (CPACK_STRIP_FILES "bin/MyExecutable")
# set (CPACK_SOURCE_STRIP_FILES "")
endif ()
# ============================================================================
# source package
# ============================================================================
## @brief Patterns to be ignored when creating source package.
# @ingroup BasisSettings
list (APPEND CPACK_SOURCE_IGNORE_FILES
"/CVS/"
"/\\\\.svn/"
"/\\\\.git/"
"\\\\.swp$"
"\\\\.#"
"/#"
"\\\\.*~"
"cscope\\\\.*"
"/${_TEST_DIR}/internal/"
)
# exclude disabled modules from source package
if (PROJECT_MODULES_DISABLED)
foreach (_M ${PROJECT_MODULES_DISABLED})
list (APPEND CPACK_SOURCE_IGNORE_FILES "/${_MODULES_DIR}/${_M}/")
endforeach ()
endif ()
# ============================================================================
# include project package information
# ============================================================================
if (EXISTS "${PROJECT_CONFIG_DIR}/Package.cmake.in")
configure_file ("${PROJECT_CONFIG_DIR}/Package.cmake.in"
"${PROJECT_BINARY_DIR}/Package.cmake" @ONLY)
include ("${PROJECT_BINARY_DIR}/Package.cmake")
elseif (EXISTS "${PROJECT_CONFIG_DIR}/Package.cmake")
include ("${PROJECT_CONFIG_DIR}/Package.cmake")
endif ()
# ============================================================================
# build package
# ============================================================================
include (CPack)
# ============================================================================
# components
# ============================================================================
# ----------------------------------------------------------------------------
# utilities
# ----------------------------------------------------------------------------
## @addtogroup CMakeAPI
# @{
# ----------------------------------------------------------------------------
## @brief Add component group.
#
# @attention This functionality is not yet entirely implemented.
# @todo Come up and implement components concept which fits into superproject concept.
#
# @param [in] GRPNAME Name of the component group.
# @param [in] ARGN Further arguments passed to cpack_add_component_group().
#
# @returns Adds the component group @p GRPNAME.
#
# @sa http://www.cmake.org/pipermail/cmake/2008-August/023336.html
# @sa cpack_add_component_group()
function (basis_add_component_group GRPNAME)
set (OPTION_NAME)
set (PARENT_GROUP)
foreach (ARG ${ARGN})
if (OPTION_NAME)
set (${OPTION_NAME} "${ARG}")
set (OPTION_NAME)
break ()
else ()
if (ARG MATCHES "^PARENT_GROUP$")
set (OPTION_NAME "PARENT_GROUP")
endif ()
endif ()
endforeach ()
cpack_add_component_group (${GRPNAME} ${ARGN})
add_custom_target (install_${GRPNAME})
if (PARENT_GROUP)
add_dependencies (install_${PARENT_GROUP} install_${GRPNAME})
endif ()
endfunction ()
# ----------------------------------------------------------------------------
## @brief Add component.
#
# @attention This functionality is not yet entirely implemented.
# @todo Come up and implement components concept which fits into superproject concept.
#
# @param [in] COMPNAME Name of the component.
# @param [in] ARGN Further arguments passed to cpack_add_component().
#
# @returns Adds the component named @p COMPNAME.
#
# @sa http://www.cmake.org/pipermail/cmake/2008-August/023336.html
# @sa cpack_add_component()
function (basis_add_component COMPNAME)
set (OPTION_NAME)
set (GROUP)
foreach (ARG ${ARGN})
if (OPTION_NAME)
set (${OPTION_NAME} "${ARG}")
set (OPTION_NAME)
break ()
else ()
if (ARG MATCHES "^GROUP$")
set (OPTION_NAME "GROUP")
endif ()
endif ()
endforeach ()
cpack_add_component (${COMPNAME} ${ARGN})
add_custom_target (
install_${COMPNAME}
COMMAND "${CMAKE_COMMAND}" -DCOMPONENT=${COMPNAME}
-P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
)
if (GROUP)
add_dependencies (install_${GROUP} install_${COMPNAME})
endif ()
endfunction ()
# ----------------------------------------------------------------------------
## @brief Add pre-configured install type.
#
# @param [in] ARGN Arguments for cpack_add_install_type().
#
# @returns Adds a pre-configured installation type.
#
# @sa CPack.cmake
# @sa cpack_add_install_type ()
function (basis_add_install_type)
cpack_add_install_type (${ARGN})
endfunction ()
# ----------------------------------------------------------------------------
## @brief Configure installation-time downloads of selected components.
#
# @param [in] ARGN Arguments for cpack_configure_downloads().
#
# @returns Nothing.
#
# @sa CPack.cmake
# @sa cpack_configure_downloads()
function (basis_configure_downloads)
cpack_configure_downloads (${ARGN})
endfunction ()
## @}
# end of Doxygen group
# ----------------------------------------------------------------------------
# include components definition
# ----------------------------------------------------------------------------
if (EXISTS "${PROJECT_CONFIG_DIR}/Components.cmake.in")
configure_file ("${PROJECT_CONFIG_DIR}/Components.cmake.in"
"${PROJECT_BINARY_DIR}/Components.cmake" @ONLY)
include ("${PROJECT_BINARY_DIR}/Components.cmake")
elseif (EXISTS "${PROJECT_CONFIG_DIR}/Components.cmake")
include ("${PROJECT_CONFIG_DIR}/Components.cmake")
endif ()
# ============================================================================
# clean up
# ============================================================================
unset (_M)
unset (_TEST_DIR)
unset (_MODULES_DIR)