forked from Eyescale/CMake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonCPack.cmake
201 lines (167 loc) · 6.62 KB
/
CommonCPack.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
# Copyright (c) 2012-2013 Stefan Eilemann <eile@eyescale.ch>
# Info: http://www.itk.org/Wiki/CMake:Component_Install_With_CPack
# No support for subproject packaging
if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
include(CommonPackageConfig)
return()
endif()
if(NOT CPACK_PROJECT_NAME)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
endif()
if(NOT CPACK_PACKAGE_NAME)
set(CPACK_PACKAGE_NAME ${CPACK_PROJECT_NAME})
endif()
if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${${UPPER_PROJECT_NAME}_DESCRIPTION})
endif()
if(NOT CPACK_PACKAGE_LICENSE)
set(CPACK_PACKAGE_LICENSE ${${UPPER_PROJECT_NAME}_LICENSE})
endif()
if(NOT CPACK_PACKAGE_LICENSE)
message(FATAL_ERROR "Missing CPACK_PACKAGE_LICENSE")
endif()
if(NOT CPACK_PACKAGE_CONTACT)
set(CPACK_PACKAGE_CONTACT ${${UPPER_PROJECT_NAME}_MAINTAINER})
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(EXISTS ${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}.in.spec)
configure_file(${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}.in.spec
${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}.spec @ONLY)
endif()
string(TOLOWER ${CPACK_PACKAGE_NAME} LOWER_PACKAGE_NAME_PREFIX)
set(CPACK_PACKAGE_NAME "${LOWER_PACKAGE_NAME_PREFIX}")
set(OLD_PACKAGES)
if(VERSION_ABI)
set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}${VERSION_ABI}")
math(EXPR NUM_OLD_PACKAGES "${VERSION_ABI} - 1")
foreach(i RANGE ${NUM_OLD_PACKAGES})
list(APPEND OLD_PACKAGES "${LOWER_PACKAGE_NAME_PREFIX}${i},")
endforeach()
list(APPEND OLD_PACKAGES "${LOWER_PACKAGE_NAME_PREFIX}")
string(REGEX REPLACE ";" " " OLD_PACKAGES ${OLD_PACKAGES})
endif()
endif()
if(NOT APPLE)
# deb lintian insists on URL
set(CPACK_PACKAGE_VENDOR "http://${CPACK_PACKAGE_VENDOR}")
endif()
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE.txt)
if(NOT CPACK_DEBIAN_BUILD_DEPENDS)
# setup'd by Buildyard config, same as for travis CI
set(CPACK_DEBIAN_BUILD_DEPENDS ${${UPPER_PROJECT_NAME}_BUILD_DEBS})
endif()
# Default component definition
if(NOT CPACK_COMPONENTS_ALL)
set(CPACK_COMPONENTS_ALL unspecified lib dev doc apps examples)
set(CPACK_COMPONENT_UNSPECIFIED_DISPLAY_NAME "Unspecified")
set(CPACK_COMPONENT_UNSPECIFIED_DESCRIPTION
"Unspecified Component - set COMPONENT in CMake install() command")
set(CPACK_COMPONENT_LIB_DISPLAY_NAME "${CPACK_PROJECT_NAME} Libraries")
set(CPACK_COMPONENT_LIB_DESCRIPTION "${CPACK_PROJECT_NAME} Runtime Libraries")
set(CPACK_COMPONENT_DEV_DISPLAY_NAME
"${CPACK_PROJECT_NAME} Development Files")
set(CPACK_COMPONENT_DEV_DESCRIPTION
"Header and Library Files for ${CPACK_PROJECT_NAME} Development")
set(CPACK_COMPONENT_DEV_DEPENDS lib)
set(CPACK_COMPONENT_DOC_DISPLAY_NAME "${CPACK_PROJECT_NAME} Documentation")
set(CPACK_COMPONENT_DOC_DESCRIPTION "${CPACK_PROJECT_NAME} Documentation")
set(CPACK_COMPONENT_DOC_DEPENDS lib)
set(CPACK_COMPONENT_APPS_DISPLAY_NAME "${CPACK_PROJECT_NAME} Applications")
set(CPACK_COMPONENT_APPS_DESCRIPTION "${CPACK_PROJECT_NAME} Applications")
set(CPACK_COMPONENT_APPS_DEPENDS lib)
set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "${CPACK_PROJECT_NAME} Examples")
set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION
"${CPACK_PROJECT_NAME} Example Source Code")
set(CPACK_COMPONENT_EXAMPLES_DEPENDS dev)
elseif(CPACK_COMPONENTS_ALL STREQUAL "none")
set(CPACK_COMPONENTS_ALL)
endif()
include(LSBInfo)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
find_program(RPM_EXE rpmbuild)
find_program(DEB_EXE debuild)
endif()
# Auto-package-version magic
include(GitInfo)
set(CMAKE_PACKAGE_VERSION "" CACHE
STRING "Additional build version for packages")
mark_as_advanced(CMAKE_PACKAGE_VERSION)
if(GIT_REVISION)
if(NOT PACKAGE_VERSION_REVISION STREQUAL GIT_REVISION)
if(PACKAGE_VERSION_REVISION)
if(CMAKE_PACKAGE_VERSION)
math(EXPR CMAKE_PACKAGE_VERSION "${CMAKE_PACKAGE_VERSION} + 1")
else()
set(CMAKE_PACKAGE_VERSION "1")
endif()
else()
set(CMAKE_PACKAGE_VERSION "")
endif()
set(CMAKE_PACKAGE_VERSION ${CMAKE_PACKAGE_VERSION} CACHE STRING
"Additional build version for packages" FORCE)
endif()
set(PACKAGE_VERSION_REVISION ${GIT_REVISION} CACHE INTERNAL "" FORCE)
endif()
# Heuristics to figure out cpack generator
if(MSVC)
set(CPACK_GENERATOR "NSIS")
set(CPACK_NSIS_MODIFY_PATH ON)
elseif(APPLE)
set(CPACK_GENERATOR "PackageMaker")
set(CPACK_OSX_PACKAGE_VERSION "${${UPPER_PROJECT_NAME}_OSX_VERSION}")
elseif(LSB_DISTRIBUTOR_ID MATCHES "Ubuntu")
set(CPACK_GENERATOR "DEB")
elseif(LSB_DISTRIBUTOR_ID MATCHES "RedHatEnterpriseServer")
set(CPACK_GENERATOR "RPM")
elseif(DEB_EXE)
set(CPACK_GENERATOR "DEB")
elseif(RPM_EXE)
set(CPACK_GENERATOR "RPM")
else()
set(CPACK_GENERATOR "TGZ")
endif()
if(CPACK_GENERATOR STREQUAL "RPM")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_LICENSE ${CPACK_PACKAGE_LICENSE})
set(CPACK_RPM_PACKAGE_RELEASE ${CMAKE_PACKAGE_VERSION})
set(CPACK_RPM_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
if(NOT CPACK_RPM_POST_INSTALL_SCRIPT_FILE)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_LIST_DIR}/rpmPostInstall.sh")
endif()
set(CPACK_RPM_PACKAGE_OBSOLETES ${OLD_PACKAGES})
set(PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME}.rpm)
else()
if(CMAKE_PACKAGE_VERSION)
set(CPACK_PACKAGE_VERSION
${CPACK_PACKAGE_VERSION}-${CMAKE_PACKAGE_VERSION})
endif()
if(CPACK_GENERATOR STREQUAL "DEB")
# dpkg requires lowercase package names
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
if(NOT CPACK_DEBIAN_PACKAGE_VERSION)
set(CPACK_DEBIAN_PACKAGE_VERSION
"${CPACK_PACKAGE_VERSION}~${CPACK_PACKAGE_NAME_EXTRA}${LSB_RELEASE}")
endif()
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_DEBIAN_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
if(NOT CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "/sbin/ldconfig")
endif()
if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_CONTACT}")
endif()
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${OLD_PACKAGES})
set(PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME}.deb)
endif()
endif()
set(CPACK_STRIP_FILES TRUE)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_FILE_NAME_BACKUP "${CPACK_PACKAGE_FILE_NAME}")
include(CPack)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME_BACKUP}")
include(CommonPackageConfig)