1 # - The builtin (binary) CPack RPM generator (Unix only)
2 # CPackRPM may be used to create RPM package using CPack.
3 # CPackRPM is a CPack generator thus it uses the CPACK_XXX variables
4 # used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
6 # However CPackRPM has specific features which are controlled by
7 # the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
9 # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29
10 # However as a handy reminder here comes the list of specific variables:
12 # CPACK_RPM_PACKAGE_SUMMARY
14 # Default : CPACK_PACKAGE_DESCRIPTION
15 # The RPM package summary
16 # CPACK_RPM_PACKAGE_NAME
18 # Default : CPACK_PACKAGE_NAME
19 # The RPM package name
20 # CPACK_RPM_PACKAGE_VERSION
22 # Default : CPACK_PACKAGE_VERSION
23 # The RPM package version
24 # CPACK_RPM_PACKAGE_ARCHITECTURE
27 # The RPM package architecture. This may be set to "noarch" if you
28 # know you are building a noarch package.
29 # CPACK_RPM_PACKAGE_RELEASE
32 # The RPM package release. This is the numbering of the RPM package
33 # itself, i.e. the version of the packaging and not the version of the
34 # content (see CPACK_RPM_PACKAGE_VERSION). One may change the default
35 # value if the previous packaging was buggy and/or you want to put here
36 # a fancy Linux distro specific numbering.
37 # CPACK_RPM_PACKAGE_LICENSE
40 # The RPM package license policy.
41 # CPACK_RPM_PACKAGE_GROUP
44 # The RPM package group.
45 # CPACK_RPM_PACKAGE_VENDOR
47 # Default : CPACK_PACKAGE_VENDOR if set or"unknown"
48 # The RPM package group.
49 # CPACK_RPM_PACKAGE_DESCRIPTION
51 # Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available"
52 # CPACK_RPM_PACKAGE_REQUIRES
55 # May be used to set RPM dependencies.
56 # CPACK_RPM_SPEC_INSTALL_POST
59 # May be used to set an RPM post-install command inside the spec file.
60 # For example setting it to "/bin/true" may be used to prevent
61 # rpmbuild to strip binaries.
62 # CPACK_RPM_SPEC_MORE_DEFINE
65 # May be used to add any %define lines to the generated spec file.
66 # CPACK_RPM_PACKAGE_DEBUG
69 # May be set when invoking cpack in order to trace debug informations
70 # during CPack RPM run. For example you may launch CPack like this
71 # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
73 # Author: Eric Noulard with the help of Alexander Neundorf.
76 MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
77 ENDIF(CMAKE_BINARY_DIR)
80 MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
83 # rpmbuild is the basic command for building RPM package
84 # it may be a simple (symbolic) link to rpmb command.
85 FIND_PROGRAM(RPMBUILD_EXECUTABLE rpmbuild)
87 # Check version of the rpmbuild tool this would be easier to
88 # track bugs with users and CPackRPM debug mode.
89 # We may use RPM version in order to check for available version dependent features
90 IF(RPMBUILD_EXECUTABLE)
91 execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
92 OUTPUT_VARIABLE _TMP_VERSION
94 OUTPUT_STRIP_TRAILING_WHITESPACE)
95 string(REGEX REPLACE "^.*\ " ""
96 RPMBUILD_EXECUTABLE_VERSION
98 IF(CPACK_RPM_PACKAGE_DEBUG)
99 MESSAGE("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
100 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
101 ENDIF(RPMBUILD_EXECUTABLE)
103 IF(NOT RPMBUILD_EXECUTABLE)
104 MESSAGE(FATAL_ERROR "RPM package requires rpmbuild executable")
105 ENDIF(NOT RPMBUILD_EXECUTABLE)
107 # We may use RPM version in the future in order
108 # to shut down warning about space in buildtree
109 # some recent RPM version should support space in different places.
111 IF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
112 MESSAGE(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
113 ENDIF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
115 # If rpmbuild is found
116 # we try to discover alien since we may be on non RPM distro like Debian.
117 # In this case we may try to to use more advanced features
118 # like generating RPM directly from DEB using alien.
119 # FIXME feature not finished (yet)
120 FIND_PROGRAM(ALIEN_EXECUTABLE alien)
122 MESSAGE(STATUS "alien found, we may be on a Debian based distro.")
123 ENDIF(ALIEN_EXECUTABLE)
126 # Use user-defined RPM specific variables value
127 # or generate reasonable default value from
128 # CPACK_xxx generic values.
129 # The variables comes from the needed (mandatory or not)
130 # values found in the RPM specification file aka ".spec" file.
131 # The variables which may/should be defined are:
134 # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
135 IF(NOT CPACK_RPM_PACKAGE_SUMMARY)
136 # if neither var is defined lets use the name as summary
137 IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
138 STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
139 ELSE(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
140 SET(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
141 ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
142 ENDIF(NOT CPACK_RPM_PACKAGE_SUMMARY)
144 # CPACK_RPM_PACKAGE_NAME (mandatory)
145 IF(NOT CPACK_RPM_PACKAGE_NAME)
146 STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
147 ENDIF(NOT CPACK_RPM_PACKAGE_NAME)
149 # CPACK_RPM_PACKAGE_VERSION (mandatory)
150 IF(NOT CPACK_RPM_PACKAGE_VERSION)
151 IF(NOT CPACK_PACKAGE_VERSION)
152 MESSAGE(FATAL_ERROR "RPM package requires a package version")
153 ENDIF(NOT CPACK_PACKAGE_VERSION)
154 SET(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
155 ENDIF(NOT CPACK_RPM_PACKAGE_VERSION)
157 # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
158 IF(CPACK_RPM_PACKAGE_ARCHITECTURE)
159 SET(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
160 IF(CPACK_RPM_PACKAGE_DEBUG)
161 MESSAGE("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
162 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
163 ELSE(CPACK_RPM_PACKAGE_ARCHITECTURE)
164 SET(TMP_RPM_BUILDARCH "")
165 ENDIF(CPACK_RPM_PACKAGE_ARCHITECTURE)
167 # CPACK_RPM_PACKAGE_RELEASE
168 # The RPM release is the numbering of the RPM package ITSELF
169 # this is the version of the PACKAGING and NOT the version
170 # of the CONTENT of the package.
171 # You may well need to generate a new RPM package release
172 # without changing the version of the packaged software.
173 # This is the case when the packaging is buggy (not) the software :=)
174 # If not set, 1 is a good candidate
175 IF(NOT CPACK_RPM_PACKAGE_RELEASE)
176 SET(CPACK_RPM_PACKAGE_RELEASE 1)
177 ENDIF(NOT CPACK_RPM_PACKAGE_RELEASE)
179 # CPACK_RPM_PACKAGE_LICENSE
180 IF(NOT CPACK_RPM_PACKAGE_LICENSE)
181 SET(CPACK_RPM_PACKAGE_LICENSE "unknown")
182 ENDIF(NOT CPACK_RPM_PACKAGE_LICENSE)
184 # CPACK_RPM_PACKAGE_GROUP
185 IF(NOT CPACK_RPM_PACKAGE_GROUP)
186 SET(CPACK_RPM_PACKAGE_GROUP "unknown")
187 ENDIF(NOT CPACK_RPM_PACKAGE_GROUP)
189 # CPACK_RPM_PACKAGE_VENDOR
190 IF(NOT CPACK_RPM_PACKAGE_VENDOR)
191 IF(CPACK_PACKAGE_VENDOR)
192 SET(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
193 ELSE(CPACK_PACKAGE_VENDOR)
194 SET(CPACK_RPM_PACKAGE_VENDOR "unknown")
195 ENDIF(CPACK_PACKAGE_VENDOR)
196 ENDIF(NOT CPACK_RPM_PACKAGE_VENDOR)
198 # CPACK_RPM_PACKAGE_SOURCE
199 # The name of the source tarball in case we generate a source RPM
201 # CPACK_RPM_PACKAGE_DESCRIPTION
202 # The variable content may be either
203 # - explicitely given by tthe user or
204 # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
206 # - set to a default value
208 IF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
209 IF (CPACK_PACKAGE_DESCRIPTION_FILE)
210 FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
211 ELSE (CPACK_PACKAGE_DESCRIPTION_FILE)
212 SET(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
213 ENDIF (CPACK_PACKAGE_DESCRIPTION_FILE)
214 ENDIF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
216 # CPACK_RPM_PACKAGE_REQUIRES
217 # Placeholder used to specify binary RPM dependencies (if any)
218 # see http://www.rpm.org/max-rpm/s1-rpm-depend-manual-dependencies.html
219 IF(CPACK_RPM_PACKAGE_REQUIRES)
220 IF(CPACK_RPM_PACKAGE_DEBUG)
221 MESSAGE("CPackRPM:Debug: User defined Requires:\n ${CPACK_RPM_PACKAGE_REQUIRES}")
222 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
223 SET(TMP_RPM_REQUIRES "Requires: ${CPACK_RPM_PACKAGE_REQUIRES}")
224 ENDIF(CPACK_RPM_PACKAGE_REQUIRES)
226 # CPACK_RPM_SPEC_INSTALL_POST
227 # May be used to define a RPM post intallation script
228 # for example setting it to "/bin/true" may prevent
229 # rpmbuild from stripping binaries.
230 IF(CPACK_RPM_SPEC_INSTALL_POST)
231 IF(CPACK_RPM_PACKAGE_DEBUG)
232 MESSAGE("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
233 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
234 SET(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
235 ENDIF(CPACK_RPM_SPEC_INSTALL_POST)
237 # CPACK_RPM_SPEC_MORE_DEFINE
238 # This is a generated spec rpm file spaceholder
239 IF(CPACK_RPM_SPEC_MORE_DEFINE)
240 IF(CPACK_RPM_PACKAGE_DEBUG)
241 MESSAGE("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
242 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
243 ENDIF(CPACK_RPM_SPEC_MORE_DEFINE)
245 # CPACK_RPM_USER_BINARY_SPECFILE
246 # FIXME when this is set then CPack should us the
247 # user provided file.
249 # Now we may create the RPM build tree structure
250 SET(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
251 MESSAGE(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
252 # Prepare RPM build tree
253 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
254 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
255 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
256 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
257 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
258 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
259 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
261 #SET(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
262 SET(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
263 # it seems rpmbuild can't handle spaces in the path
264 # neither escaping (as below) nor putting quotes around the path seem to help
265 #STRING(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
266 SET(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
269 SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
270 IF(CPACK_RPM_USER_BINARY_SPECFILE)
271 # User may have specified SPECFILE just use it
272 MESSAGE("CPackRPM: Will use user specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
273 # Note that user provided file is processed for @var replacement
274 CONFIGURE_FILE(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
275 ELSE(CPACK_RPM_USER_BINARY_SPECFILE)
276 # No User specified spec file generate a valid one using var values
277 IF(CPACK_RPM_PACKAGE_DEBUG)
278 MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
279 MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
280 MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
281 MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
282 MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
283 MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
284 MESSAGE("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
285 MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
286 MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
287 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
288 FILE(WRITE ${CPACK_RPM_BINARY_SPECFILE}
290 Buildroot: ${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}
291 Summary: ${CPACK_RPM_PACKAGE_SUMMARY}
292 Name: ${CPACK_RPM_PACKAGE_NAME}
293 Version: ${CPACK_RPM_PACKAGE_VERSION}
294 Release: ${CPACK_RPM_PACKAGE_RELEASE}
295 License: ${CPACK_RPM_PACKAGE_LICENSE}
296 Group: ${CPACK_RPM_PACKAGE_GROUP}
297 Vendor: ${CPACK_RPM_PACKAGE_VENDOR}
301 #p define prefix ${CMAKE_INSTALL_PREFIX}
302 %define _rpmdir ${CPACK_RPM_DIRECTORY}
303 %define _rpmfilename ${CPACK_RPM_FILE_NAME}
304 %define _unpackaged_files_terminate_build 0
305 %define _topdir ${CPACK_RPM_DIRECTORY}
306 ${TMP_RPM_SPEC_INSTALL_POST}
307 ${CPACK_RPM_SPEC_MORE_DEFINE}
310 ${CPACK_RPM_PACKAGE_DESCRIPTION}
312 # This is a shortcutted spec file
313 # generated by CMake RPM generator
314 # we skip the _prepn _build and _install
315 # steps because CPack does that for us
325 %defattr(-,root,root,-)
331 * Mon Oct 03 2008 Erk <eric.noulard@gmail.com>
332 Update generator to handle optional dependencies using Requires
333 Update DEBUG output typos.
334 * Mon Aug 25 2008 Erk <eric.noulard@gmail.com>
335 Update generator to handle optional post-install
336 * Tue Aug 16 2007 Erk <eric.noulard@gmail.com>
337 Generated by CPack RPM Generator and associated macros
339 ENDIF(CPACK_RPM_USER_BINARY_SPECFILE)
342 IF(RPMBUILD_EXECUTABLE)
343 # Now call rpmbuild using the SPECFILE
345 COMMAND "${RPMBUILD_EXECUTABLE}" -bb
346 --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
347 "${CPACK_RPM_BINARY_SPECFILE}"
348 WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
349 ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err"
350 OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
351 IF(CPACK_RPM_PACKAGE_DEBUG)
352 MESSAGE("CPackRPM:Debug: You may consult rpmbuild logs in: ")
353 MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err")
354 MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
355 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
356 ELSE(RPMBUILD_EXECUTABLE)
358 MESSAGE(FATAL_ERROR "RPM packaging through alien not done (yet)")
359 ENDIF(ALIEN_EXECUTABLE)
360 ENDIF(RPMBUILD_EXECUTABLE)