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