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(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
72 # FIXME This should be obtained through 'arch' command
73 # but is it --really necessary-- ?
74 SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386)
75 ENDIF(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
77 # CPACK_RPM_PACKAGE_RELEASE
78 # The RPM release is the numbering of the RPM package ITSELF
79 # this is the version of the PACKAGING and NOT the version
80 # of the CONTENT of the package.
81 # You may well need to generate a new RPM package release
82 # without changing the version of the packaged software.
83 # This is the case when the packaging is buggy (not) the software :=)
84 # If not set, 1 is a good candidate
85 IF(NOT CPACK_RPM_PACKAGE_RELEASE)
86 SET(CPACK_RPM_PACKAGE_RELEASE 1)
87 ENDIF(NOT CPACK_RPM_PACKAGE_RELEASE)
89 # CPACK_RPM_PACKAGE_LICENSE
90 IF(NOT CPACK_RPM_PACKAGE_LICENSE)
91 SET(CPACK_RPM_PACKAGE_LICENSE "unknown")
92 ENDIF(NOT CPACK_RPM_PACKAGE_LICENSE)
94 # CPACK_RPM_PACKAGE_GROUP
95 IF(NOT CPACK_RPM_PACKAGE_GROUP)
96 SET(CPACK_RPM_PACKAGE_GROUP "unknown")
97 ENDIF(NOT CPACK_RPM_PACKAGE_GROUP)
99 # CPACK_RPM_PACKAGE_VENDOR
100 IF(NOT CPACK_RPM_PACKAGE_VENDOR)
101 IF(CPACK_PACKAGE_VENDOR)
102 SET(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
103 ELSE(CPACK_PACKAGE_VENDOR)
104 SET(CPACK_RPM_PACKAGE_VENDOR "unknown")
105 ENDIF(CPACK_PACKAGE_VENDOR)
106 ENDIF(NOT CPACK_RPM_PACKAGE_VENDOR)
108 # CPACK_RPM_PACKAGE_SOURCE
109 # The name of the source tarball in case we generate
112 # CPACK_RPM_PACKAGE_DESCRIPTION
113 # The variable content may be either
114 # - explicitely given by tthe user or
115 # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
117 # - set to a default value
119 IF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
120 IF (CPACK_PACKAGE_DESCRIPTION_FILE)
121 FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
122 ELSE (CPACK_PACKAGE_DESCRIPTION_FILE)
123 SET(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
124 ENDIF (CPACK_PACKAGE_DESCRIPTION_FILE)
125 ENDIF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
127 # CPACK_RPM_USER_BINARY_SPECFILE
128 # FIXME when this is set then CPack should us the
129 # user provided file.
131 # Now we may create the RPM build tree structure
132 SET(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
133 MESSAGE(STATUS "CPackRPM:: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
134 # Prepare RPM build tree
135 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
136 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
137 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
138 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
139 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
140 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
141 FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
143 #SET(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
144 SET(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
145 # it seems rpmbuild can't handle spaces in the path
146 # neither escaping (as below) nor putting quotes around the path seem to help
147 #STRING(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
148 SET(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
151 SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
152 IF(CPACK_RPM_USER_BINARY_SPECFILE)
153 # User may have specified SPECFILE just use it
154 MESSAGE("CPackRPM: Will use user specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
155 # Note that user provided file is processed for @var replacement
156 CONFIGURE_FILE(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
157 ELSE(CPACK_RPM_USER_BINARY_SPECFILE)
158 # No User specified spec file generate a valid one using var values
159 IF(CPACK_RPM_PACKAGE_DEBUG)
160 MESSAGE("CPackRPM:: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
161 MESSAGE("CPackRPM:: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
162 MESSAGE("CPackRPM:: CPACK_TEMPORARY_DIRECTORY= ${PACK_TEMPORARY_DIRECTORY}")
163 MESSAGE("CPackRPM:: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
164 MESSAGE("CPackRPM:: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
165 MESSAGE("CPackRPM:: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
166 MESSAGE("CPackRPM:: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
167 MESSAGE("CPackRPM:: CPACK_PACKAGE_INSTALL_DIRECTORY = ${PACK_PACKAGE_INSTALL_DIRECTORY}")
168 MESSAGE("CPackRPM ::CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
169 ENDIF(CPACK_RPM_PACKAGE_DEBUG)
170 FILE(WRITE ${CPACK_RPM_BINARY_SPECFILE}
172 Buildroot: ${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}
173 Summary: ${CPACK_RPM_PACKAGE_SUMMARY}
174 Name: ${CPACK_RPM_PACKAGE_NAME}
175 Version: ${CPACK_RPM_PACKAGE_VERSION}
176 Release: ${CPACK_RPM_PACKAGE_RELEASE}
177 License: ${CPACK_RPM_PACKAGE_LICENSE}
178 Group: ${CPACK_RPM_PACKAGE_GROUP}
179 Vendor: ${CPACK_RPM_PACKAGE_VENDOR}
181 #%define prefix ${CMAKE_INSTALL_PREFIX}
182 %define _rpmdir ${CPACK_RPM_DIRECTORY}
183 %define _rpmfilename ${CPACK_RPM_FILE_NAME}
184 %define _unpackaged_files_terminate_build 0
185 %define _topdir ${CPACK_RPM_DIRECTORY}
188 ${CPACK_RPM_PACKAGE_DESCRIPTION}
190 # This is a shortcutted spec file
191 # generated by CMake RPM generator
192 # we skip the %prepn %build and %install
193 # steps because CPack does that for us
203 %defattr(-,root,root,-)
209 * Tue Aug 16 2007 Erk <eric.noulard@gmail.com>
210 Generated by CPack RPM Generator and associated macros
213 ENDIF(CPACK_RPM_USER_BINARY_SPECFILE)
216 IF(RPMBUILD_EXECUTABLE)
217 # Now call rpmbuild using the SPECFILE
219 COMMAND "${RPMBUILD_EXECUTABLE}" -bb "${CPACK_RPM_BINARY_SPECFILE}"
220 WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
221 ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err"
222 OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
223 ELSE(RPMBUILD_EXECUTABLE)
225 MESSAGE(FATAL_ERROR "RPM packaging through alien not done (yet)")
226 ENDIF(ALIEN_EXECUTABLE)
227 ENDIF(RPMBUILD_EXECUTABLE)