1 # CPack script for creating RPM package
2 # Author: Eric Noulard with the help of Alexander Neundorf.
3 # All variables used by CPackRPM begins with CPACK_RPM_ prefix
5 # Here comes the list of used variables:
9 MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
10 ENDIF(CMAKE_BINARY_DIR)
13 MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
16 # rpmbuild is the basic command for building RPM package
17 # it may be a simple (symbolic) link to rpmb command.
18 FIND_PROGRAM(RPMBUILD_EXECUTABLE rpmbuild)
20 IF(NOT RPMBUILD_EXECUTABLE)
21 MESSAGE(FATAL_ERROR "RPM package requires rpmbuild executable")
22 ENDIF(NOT RPMBUILD_EXECUTABLE)
24 IF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
25 MESSAGE(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
26 ENDIF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
28 # If rpmbuild is found
29 # we try to discover alien since we may be on non RPM distro like Debian.
30 # In this case we may try to to use more advanced features
31 # like generating RPM directly from DEB using alien.
32 # FIXME feature not finished (yet)
33 FIND_PROGRAM(ALIEN_EXECUTABLE alien)
35 MESSAGE(STATUS "alien found, we may be on a Debian based distro.")
36 ENDIF(ALIEN_EXECUTABLE)
39 # Use user-defined RPM specific variables value
40 # or generate reasonable default value from
41 # CPACK_xxx generic values.
42 # The variables comes from the needed (mandatory or not)
43 # values found in the RPM specification file aka ".spec" file.
44 # The variables which may/should be defined are:
47 # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
48 IF(NOT CPACK_RPM_PACKAGE_SUMMARY)
49 # if neither var is defined lets use the name as summary
50 IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
51 STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
52 ELSE(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
53 SET(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
54 ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
55 ENDIF(NOT CPACK_RPM_PACKAGE_SUMMARY)
57 # CPACK_RPM_PACKAGE_NAME (mandatory)
58 IF(NOT CPACK_RPM_PACKAGE_NAME)
59 STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
60 ENDIF(NOT CPACK_RPM_PACKAGE_NAME)
62 # CPACK_RPM_PACKAGE_VERSION (mandatory)
63 IF(NOT CPACK_RPM_PACKAGE_VERSION)
64 IF(NOT CPACK_PACKAGE_VERSION)
65 MESSAGE(FATAL_ERROR "RPM package requires a package version")
66 ENDIF(NOT CPACK_PACKAGE_VERSION)
67 SET(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
68 ENDIF(NOT CPACK_RPM_PACKAGE_VERSION)
70 # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
71 IF(CPACK_RPM_PACKAGE_ARCHITECTURE)
72 SET(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
73 IF(CPACK_RPM_PACKAGE_DEBUG)
74 MESSAGE("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
75 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
76 ELSE(CPACK_RPM_PACKAGE_ARCHITECTURE)
77 SET(TMP_RPM_BUILDARCH "")
78 ENDIF(CPACK_RPM_PACKAGE_ARCHITECTURE)
80 # CPACK_RPM_PACKAGE_RELEASE
81 # The RPM release is the numbering of the RPM package ITSELF
82 # this is the version of the PACKAGING and NOT the version
83 # of the CONTENT of the package.
84 # You may well need to generate a new RPM package release
85 # without changing the version of the packaged software.
86 # This is the case when the packaging is buggy (not) the software :=)
87 # If not set, 1 is a good candidate
88 IF(NOT CPACK_RPM_PACKAGE_RELEASE)
89 SET(CPACK_RPM_PACKAGE_RELEASE 1)
90 ENDIF(NOT CPACK_RPM_PACKAGE_RELEASE)
92 # CPACK_RPM_PACKAGE_LICENSE
93 IF(NOT CPACK_RPM_PACKAGE_LICENSE)
94 SET(CPACK_RPM_PACKAGE_LICENSE "unknown")
95 ENDIF(NOT CPACK_RPM_PACKAGE_LICENSE)
97 # CPACK_RPM_PACKAGE_GROUP
98 IF(NOT CPACK_RPM_PACKAGE_GROUP)
99 SET(CPACK_RPM_PACKAGE_GROUP "unknown")
100 ENDIF(NOT CPACK_RPM_PACKAGE_GROUP)
102 # CPACK_RPM_PACKAGE_VENDOR
103 IF(NOT CPACK_RPM_PACKAGE_VENDOR)
104 IF(CPACK_PACKAGE_VENDOR)
105 SET(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
106 ELSE(CPACK_PACKAGE_VENDOR)
107 SET(CPACK_RPM_PACKAGE_VENDOR "unknown")
108 ENDIF(CPACK_PACKAGE_VENDOR)
109 ENDIF(NOT CPACK_RPM_PACKAGE_VENDOR)
111 # CPACK_RPM_PACKAGE_SOURCE
112 # The name of the source tarball in case we generate a source RPM
114 # CPACK_RPM_PACKAGE_DESCRIPTION
115 # The variable content may be either
116 # - explicitely given by tthe user or
117 # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
119 # - set to a default value
121 IF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
122 IF (CPACK_PACKAGE_DESCRIPTION_FILE)
123 FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
124 ELSE (CPACK_PACKAGE_DESCRIPTION_FILE)
125 SET(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
126 ENDIF (CPACK_PACKAGE_DESCRIPTION_FILE)
127 ENDIF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
129 # CPACK_RPM_PACKAGE_REQUIRES
130 # Placeholder used to specify binary RPM dependencies (if any)
131 # see http://www.rpm.org/max-rpm/s1-rpm-depend-manual-dependencies.html
132 IF(CPACK_RPM_PACKAGE_REQUIRES)
133 IF(CPACK_RPM_PACKAGE_DEBUG)
134 MESSAGE("CPackRPM:Debug: User defined Requires:\n ${CPACK_RPM_PACKAGE_REQUIRES}")
135 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
136 SET(TMP_RPM_REQUIRES "Requires: ${CPACK_RPM_PACKAGE_REQUIRES}")
137 ENDIF(CPACK_RPM_PACKAGE_REQUIRES)
139 # CPACK_RPM_SPEC_INSTALL_POST
140 # May be used to define a RPM post intallation script
141 # for example setting it to "/bin/true" may prevent
142 # rpmbuild from stripping binaries.
143 IF(CPACK_RPM_SPEC_INSTALL_POST)
144 IF(CPACK_RPM_PACKAGE_DEBUG)
145 MESSAGE("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
146 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
147 SET(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
148 ENDIF(CPACK_RPM_SPEC_INSTALL_POST)
150 # CPACK_RPM_SPEC_MORE_DEFINE
151 # This is a generated spec rpm file spaceholder
152 IF(CPACK_RPM_SPEC_MORE_DEFINE)
153 IF(CPACK_RPM_PACKAGE_DEBUG)
154 MESSAGE("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
155 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
156 ENDIF(CPACK_RPM_SPEC_MORE_DEFINE)
158 # CPACK_RPM_USER_BINARY_SPECFILE
159 # FIXME when this is set then CPack should us the
160 # user provided file.
162 # Now we may create the RPM build tree structure
163 SET(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
164 MESSAGE(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
165 # Prepare RPM build tree
166 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
167 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
168 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
169 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
170 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
171 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
172 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
174 #SET(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
175 SET(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
176 # it seems rpmbuild can't handle spaces in the path
177 # neither escaping (as below) nor putting quotes around the path seem to help
178 #STRING(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
179 SET(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
182 SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
183 IF(CPACK_RPM_USER_BINARY_SPECFILE)
184 # User may have specified SPECFILE just use it
185 MESSAGE("CPackRPM: Will use user specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
186 # Note that user provided file is processed for @var replacement
187 CONFIGURE_FILE(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
188 ELSE(CPACK_RPM_USER_BINARY_SPECFILE)
189 # No User specified spec file generate a valid one using var values
190 IF(CPACK_RPM_PACKAGE_DEBUG)
191 MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
192 MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
193 MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
194 MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
195 MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
196 MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
197 MESSAGE("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
198 MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
199 MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
200 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
201 FILE(WRITE ${CPACK_RPM_BINARY_SPECFILE}
203 Buildroot: ${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}
204 Summary: ${CPACK_RPM_PACKAGE_SUMMARY}
205 Name: ${CPACK_RPM_PACKAGE_NAME}
206 Version: ${CPACK_RPM_PACKAGE_VERSION}
207 Release: ${CPACK_RPM_PACKAGE_RELEASE}
208 License: ${CPACK_RPM_PACKAGE_LICENSE}
209 Group: ${CPACK_RPM_PACKAGE_GROUP}
210 Vendor: ${CPACK_RPM_PACKAGE_VENDOR}
214 #%define prefix ${CMAKE_INSTALL_PREFIX}
215 %define _rpmdir ${CPACK_RPM_DIRECTORY}
216 %define _rpmfilename ${CPACK_RPM_FILE_NAME}
217 %define _unpackaged_files_terminate_build 0
218 %define _topdir ${CPACK_RPM_DIRECTORY}
219 ${TMP_RPM_SPEC_INSTALL_POST}
220 ${CPACK_RPM_SPEC_MORE_DEFINE}
223 ${CPACK_RPM_PACKAGE_DESCRIPTION}
225 # This is a shortcutted spec file
226 # generated by CMake RPM generator
227 # we skip the _prepn _build and _install
228 # steps because CPack does that for us
238 %defattr(-,root,root,-)
244 * Mon Oct 03 2008 Erk <eric.noulard@gmail.com>
245 Update generator to handle optional dependencies using Requires
246 Update DEBUG output typos.
247 * Mon Aug 25 2008 Erk <eric.noulard@gmail.com>
248 Update generator to handle optional post-install
249 * Tue Aug 16 2007 Erk <eric.noulard@gmail.com>
250 Generated by CPack RPM Generator and associated macros
252 ENDIF(CPACK_RPM_USER_BINARY_SPECFILE)
255 IF(RPMBUILD_EXECUTABLE)
256 # Now call rpmbuild using the SPECFILE
258 COMMAND "${RPMBUILD_EXECUTABLE}" -bb "${CPACK_RPM_BINARY_SPECFILE}"
259 WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
260 ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err"
261 OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
262 IF(CPACK_RPM_PACKAGE_DEBUG)
263 MESSAGE("CPackRPM:Debug: You may consult rpmbuild logs in: ")
264 MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err")
265 MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
266 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
267 ELSE(RPMBUILD_EXECUTABLE)
269 MESSAGE(FATAL_ERROR "RPM packaging through alien not done (yet)")
270 ENDIF(ALIEN_EXECUTABLE)
271 ENDIF(RPMBUILD_EXECUTABLE)