CPackRPM.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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
  5. #
  6. # However CPackRPM has specific features which are controlled by
  7. # the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
  8. # the wiki:
  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:
  11. #
  12. # CPACK_RPM_PACKAGE_SUMMARY
  13. # Mandatory : YES
  14. # Default : CPACK_PACKAGE_DESCRIPTION
  15. # The RPM package summary
  16. # CPACK_RPM_PACKAGE_NAME
  17. # Mandatory : YES
  18. # Default : CPACK_PACKAGE_NAME
  19. # The RPM package name
  20. # CPACK_RPM_PACKAGE_VERSION
  21. # Mandatory : YES
  22. # Default : CPACK_PACKAGE_VERSION
  23. # The RPM package version
  24. # CPACK_RPM_PACKAGE_ARCHITECTURE
  25. # Mandatory : NO
  26. # Default : -
  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
  30. # Mandatory : YES
  31. # Default : 1
  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
  38. # Mandatory : YES
  39. # Default : "unknown"
  40. # The RPM package license policy.
  41. # CPACK_RPM_PACKAGE_GROUP
  42. # Mandatory : YES
  43. # Default : "unknown"
  44. # The RPM package group.
  45. # CPACK_RPM_PACKAGE_VENDOR
  46. # Mandatory : YES
  47. # Default : CPACK_PACKAGE_VENDOR if set or "unknown"
  48. # The RPM package group.
  49. # CPACK_RPM_PACKAGE_DESCRIPTION
  50. # Mandatory : YES
  51. # Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available"
  52. # CPACK_RPM_PACKAGE_REQUIRES
  53. # Mandatory : NO
  54. # Default : -
  55. # May be used to set RPM dependencies (requires).
  56. # CPACK_RPM_PACKAGES_PROVIDES
  57. # Mandatory : NO
  58. # Default : -
  59. # May be used to set RPM dependencies (provides).
  60. # CPACK_RPM_SPEC_INSTALL_POST
  61. # Mandatory : NO
  62. # Default : -
  63. # May be used to set an RPM post-install command inside the spec file.
  64. # For example setting it to "/bin/true" may be used to prevent
  65. # rpmbuild to strip binaries.
  66. # CPACK_RPM_SPEC_MORE_DEFINE
  67. # Mandatory : NO
  68. # Default : -
  69. # May be used to add any %define lines to the generated spec file.
  70. # CPACK_RPM_PACKAGE_DEBUG
  71. # Mandatory : NO
  72. # Default : -
  73. # May be set when invoking cpack in order to trace debug informations
  74. # during CPack RPM run. For example you may launch CPack like this
  75. # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
  76. # CPACK_RPM_USER_BINARY_SPECFILE
  77. # Mandatory : NO
  78. # Default : -
  79. # May be set by the user in order to specify a USER binary spec file
  80. # to be used by CPackRPM instead of generating the file.
  81. # The specified file will be processed by CONFIGURE_FILE( @ONLY).
  82. # CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  83. # Mandatory : NO
  84. # Default : -
  85. # If set CPack will generate a template for USER specified binary
  86. # spec file and stop with an error. For example launch CPack like this
  87. # cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
  88. # The user may then use this file in order to hand-craft is own
  89. # binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE.
  90. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  91. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  92. # Mandatory : NO
  93. # Default : -
  94. # May be used to embbed a pre (un)installation script in the spec file.
  95. # The refered script file(s) will be read and directly
  96. # put after the %pre or %preun section
  97. # One may verify which scriptlet has been included with
  98. # rpm -qp --scripts package.rpm
  99. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  100. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  101. # Mandatory : NO
  102. # Default : -
  103. # May be used to embbed a post (un)installation script in the spec file.
  104. # The refered script file(s) will be read and directly
  105. # put after the %post or %postun section
  106. # One may verify which scriptlet has been included with
  107. # rpm -qp --scripts package.rpm
  108. #=============================================================================
  109. # Copyright 2007-2009 Kitware, Inc.
  110. #
  111. # Distributed under the OSI-approved BSD License (the "License");
  112. # see accompanying file Copyright.txt for details.
  113. #
  114. # This software is distributed WITHOUT ANY WARRANTY; without even the
  115. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  116. # See the License for more information.
  117. #=============================================================================
  118. # (To distributed this file outside of CMake, substitute the full
  119. # License text for the above reference.)
  120. # Author: Eric Noulard with the help of Alexander Neundorf.
  121. IF(CMAKE_BINARY_DIR)
  122. MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  123. ENDIF(CMAKE_BINARY_DIR)
  124. IF(NOT UNIX)
  125. MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  126. ENDIF(NOT UNIX)
  127. # rpmbuild is the basic command for building RPM package
  128. # it may be a simple (symbolic) link to rpmb command.
  129. FIND_PROGRAM(RPMBUILD_EXECUTABLE rpmbuild)
  130. # Check version of the rpmbuild tool this would be easier to
  131. # track bugs with users and CPackRPM debug mode.
  132. # We may use RPM version in order to check for available version dependent features
  133. IF(RPMBUILD_EXECUTABLE)
  134. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  135. OUTPUT_VARIABLE _TMP_VERSION
  136. ERROR_QUIET
  137. OUTPUT_STRIP_TRAILING_WHITESPACE)
  138. string(REGEX REPLACE "^.*\ " ""
  139. RPMBUILD_EXECUTABLE_VERSION
  140. ${_TMP_VERSION})
  141. IF(CPACK_RPM_PACKAGE_DEBUG)
  142. MESSAGE("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  143. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  144. ENDIF(RPMBUILD_EXECUTABLE)
  145. IF(NOT RPMBUILD_EXECUTABLE)
  146. MESSAGE(FATAL_ERROR "RPM package requires rpmbuild executable")
  147. ENDIF(NOT RPMBUILD_EXECUTABLE)
  148. # We may use RPM version in the future in order
  149. # to shut down warning about space in buildtree
  150. # some recent RPM version should support space in different places.
  151. # not checked [yet].
  152. IF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  153. MESSAGE(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  154. ENDIF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  155. # If rpmbuild is found
  156. # we try to discover alien since we may be on non RPM distro like Debian.
  157. # In this case we may try to to use more advanced features
  158. # like generating RPM directly from DEB using alien.
  159. # FIXME feature not finished (yet)
  160. FIND_PROGRAM(ALIEN_EXECUTABLE alien)
  161. IF(ALIEN_EXECUTABLE)
  162. MESSAGE(STATUS "alien found, we may be on a Debian based distro.")
  163. ENDIF(ALIEN_EXECUTABLE)
  164. #
  165. # Use user-defined RPM specific variables value
  166. # or generate reasonable default value from
  167. # CPACK_xxx generic values.
  168. # The variables comes from the needed (mandatory or not)
  169. # values found in the RPM specification file aka ".spec" file.
  170. # The variables which may/should be defined are:
  171. #
  172. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  173. IF(NOT CPACK_RPM_PACKAGE_SUMMARY)
  174. # if neither var is defined lets use the name as summary
  175. IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  176. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  177. ELSE(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  178. SET(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  179. ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  180. ENDIF(NOT CPACK_RPM_PACKAGE_SUMMARY)
  181. # CPACK_RPM_PACKAGE_NAME (mandatory)
  182. IF(NOT CPACK_RPM_PACKAGE_NAME)
  183. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  184. ENDIF(NOT CPACK_RPM_PACKAGE_NAME)
  185. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  186. IF(NOT CPACK_RPM_PACKAGE_VERSION)
  187. IF(NOT CPACK_PACKAGE_VERSION)
  188. MESSAGE(FATAL_ERROR "RPM package requires a package version")
  189. ENDIF(NOT CPACK_PACKAGE_VERSION)
  190. SET(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  191. ENDIF(NOT CPACK_RPM_PACKAGE_VERSION)
  192. # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
  193. IF(CPACK_RPM_PACKAGE_ARCHITECTURE)
  194. SET(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  195. IF(CPACK_RPM_PACKAGE_DEBUG)
  196. MESSAGE("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  197. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  198. ELSE(CPACK_RPM_PACKAGE_ARCHITECTURE)
  199. SET(TMP_RPM_BUILDARCH "")
  200. ENDIF(CPACK_RPM_PACKAGE_ARCHITECTURE)
  201. # CPACK_RPM_PACKAGE_RELEASE
  202. # The RPM release is the numbering of the RPM package ITSELF
  203. # this is the version of the PACKAGING and NOT the version
  204. # of the CONTENT of the package.
  205. # You may well need to generate a new RPM package release
  206. # without changing the version of the packaged software.
  207. # This is the case when the packaging is buggy (not) the software :=)
  208. # If not set, 1 is a good candidate
  209. IF(NOT CPACK_RPM_PACKAGE_RELEASE)
  210. SET(CPACK_RPM_PACKAGE_RELEASE 1)
  211. ENDIF(NOT CPACK_RPM_PACKAGE_RELEASE)
  212. # CPACK_RPM_PACKAGE_LICENSE
  213. IF(NOT CPACK_RPM_PACKAGE_LICENSE)
  214. SET(CPACK_RPM_PACKAGE_LICENSE "unknown")
  215. ENDIF(NOT CPACK_RPM_PACKAGE_LICENSE)
  216. # CPACK_RPM_PACKAGE_GROUP
  217. IF(NOT CPACK_RPM_PACKAGE_GROUP)
  218. SET(CPACK_RPM_PACKAGE_GROUP "unknown")
  219. ENDIF(NOT CPACK_RPM_PACKAGE_GROUP)
  220. # CPACK_RPM_PACKAGE_VENDOR
  221. IF(NOT CPACK_RPM_PACKAGE_VENDOR)
  222. IF(CPACK_PACKAGE_VENDOR)
  223. SET(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  224. ELSE(CPACK_PACKAGE_VENDOR)
  225. SET(CPACK_RPM_PACKAGE_VENDOR "unknown")
  226. ENDIF(CPACK_PACKAGE_VENDOR)
  227. ENDIF(NOT CPACK_RPM_PACKAGE_VENDOR)
  228. # CPACK_RPM_PACKAGE_SOURCE
  229. # The name of the source tarball in case we generate a source RPM
  230. # CPACK_RPM_PACKAGE_DESCRIPTION
  231. # The variable content may be either
  232. # - explicitely given by tthe user or
  233. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  234. # if it is defined
  235. # - set to a default value
  236. #
  237. IF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  238. IF (CPACK_PACKAGE_DESCRIPTION_FILE)
  239. FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  240. ELSE (CPACK_PACKAGE_DESCRIPTION_FILE)
  241. SET(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  242. ENDIF (CPACK_PACKAGE_DESCRIPTION_FILE)
  243. ENDIF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  244. # CPACK_RPM_PACKAGE_REQUIRES
  245. # Placeholder used to specify binary RPM dependencies (if any)
  246. # see http://www.rpm.org/max-rpm/s1-rpm-depend-manual-dependencies.html
  247. IF(CPACK_RPM_PACKAGE_REQUIRES)
  248. IF(CPACK_RPM_PACKAGE_DEBUG)
  249. MESSAGE("CPackRPM:Debug: User defined Requires:\n ${CPACK_RPM_PACKAGE_REQUIRES}")
  250. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  251. SET(TMP_RPM_REQUIRES "Requires: ${CPACK_RPM_PACKAGE_REQUIRES}")
  252. ENDIF(CPACK_RPM_PACKAGE_REQUIRES)
  253. # CPACK_RPM_PACKAGE_PROVIDES
  254. # Placeholder used to specify binary RPM dependencies (if any)
  255. # see http://www.rpm.org/max-rpm/s1-rpm-depend-manual-dependencies.html
  256. IF(CPACK_RPM_PACKAGE_PROVIDES)
  257. IF(CPACK_RPM_PACKAGE_DEBUG)
  258. MESSAGE("CPackRPM:Debug: User defined Provides:\n ${CPACK_RPM_PACKAGE_PROVIDES}")
  259. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  260. SET(TMP_RPM_PROVIDES "Provides: ${CPACK_RPM_PACKAGE_PROVIDES}")
  261. ENDIF(CPACK_RPM_PACKAGE_PROVIDES)
  262. # CPACK_RPM_SPEC_INSTALL_POST
  263. # May be used to define a RPM post intallation script
  264. # for example setting it to "/bin/true" may prevent
  265. # rpmbuild from stripping binaries.
  266. IF(CPACK_RPM_SPEC_INSTALL_POST)
  267. IF(CPACK_RPM_PACKAGE_DEBUG)
  268. MESSAGE("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  269. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  270. SET(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  271. ENDIF(CPACK_RPM_SPEC_INSTALL_POST)
  272. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  273. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  274. # May be used to embbed a post (un)installation script in the spec file.
  275. # The refered script file(s) will be read and directly
  276. # put after the %post or %postun section
  277. if(CPACK_RPM_POST_INSTALL_SCRIPT_FILE)
  278. if(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  279. file(READ ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_POSTINSTALL)
  280. else(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  281. message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_SCRIPT_FILE}> does not exists - ignoring")
  282. endif(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  283. endif(CPACK_RPM_POST_INSTALL_SCRIPT_FILE)
  284. if(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE)
  285. if(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  286. file(READ ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
  287. else(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  288. message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE}> does not exists - ignoring")
  289. endif(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  290. endif(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE)
  291. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  292. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  293. # May be used to embbed a pre (un)installation script in the spec file.
  294. # The refered script file(s) will be read and directly
  295. # put after the %pre or %preun section
  296. if(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE)
  297. if(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  298. file(READ ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_PREINSTALL)
  299. else(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  300. message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE}> does not exists - ignoring")
  301. endif(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  302. endif(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE)
  303. if(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE)
  304. if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  305. file(READ ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
  306. else(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  307. message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE}> does not exists - ignoring")
  308. endif(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  309. endif(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE)
  310. # CPACK_RPM_SPEC_MORE_DEFINE
  311. # This is a generated spec rpm file spaceholder
  312. IF(CPACK_RPM_SPEC_MORE_DEFINE)
  313. IF(CPACK_RPM_PACKAGE_DEBUG)
  314. MESSAGE("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  315. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  316. ENDIF(CPACK_RPM_SPEC_MORE_DEFINE)
  317. # Now we may create the RPM build tree structure
  318. SET(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  319. MESSAGE(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  320. # Prepare RPM build tree
  321. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  322. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  323. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  324. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  325. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  326. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  327. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  328. #SET(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  329. SET(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  330. # it seems rpmbuild can't handle spaces in the path
  331. # neither escaping (as below) nor putting quotes around the path seem to help
  332. #STRING(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  333. SET(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  334. # Use files tree to construct files command (spec file)
  335. EXECUTE_PROCESS(COMMAND find -type f
  336. COMMAND sed {s/\\.//}
  337. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  338. OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
  339. # The name of the final spec file to be used by rpmbuild
  340. SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
  341. # Print out some debug information if we were asked for that
  342. IF(CPACK_RPM_PACKAGE_DEBUG)
  343. MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  344. MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  345. MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  346. MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  347. MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  348. MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  349. MESSAGE("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  350. MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  351. MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  352. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  353. # USER generated spec file handling.
  354. # We should generate a spec file template:
  355. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  356. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  357. #
  358. IF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  359. FILE(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  360. "# -*- rpm-spec -*-
  361. Buildroot: \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@
  362. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  363. Name: \@CPACK_RPM_PACKAGE_NAME\@
  364. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  365. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  366. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  367. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  368. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  369. \@TMP_RPM_REQUIRES\@
  370. \@TMP_RPM_PROVIDES\@
  371. \@TMP_RPM_BUILDARCH\@
  372. #p define prefix \@CMAKE_INSTALL_PREFIX\@
  373. %define _rpmdir \@CPACK_RPM_DIRECTORY\@
  374. %define _rpmfilename \@CPACK_RPM_FILE_NAME\@
  375. %define _unpackaged_files_terminate_build 0
  376. %define _topdir \@CPACK_RPM_DIRECTORY\@
  377. \@TMP_RPM_SPEC_INSTALL_POST\@
  378. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  379. %description
  380. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  381. # This is a shortcutted spec file
  382. # generated by CMake RPM generator
  383. # we skip the _prepn _build and _install
  384. # steps because CPack does that for us
  385. # WE MUST NOT DO ANYTHING in those steps because they
  386. # may fail for non-privileged user
  387. #p prep
  388. #p build
  389. #p install
  390. %clean
  391. %post
  392. \@CPACK_RPM_SPEC_POSTINSTALL\@
  393. %postun
  394. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  395. %pre
  396. \@CPACK_RPM_SPEC_PREINSTALL\@
  397. %preun
  398. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  399. %files
  400. %defattr(-,root,root,-)
  401. #p dir %{prefix}
  402. #p {prefix}/*
  403. ${CPACK_RPM_INSTALL_FILES}
  404. %changelog
  405. * Wed Oct 07 2009 Erk <[email protected]>
  406. Add user custom spec file support
  407. * Sat Oct 03 2009 Kami <[email protected]>
  408. Update to handle more precisely the files section
  409. * Mon Oct 03 2008 Erk <[email protected]>
  410. Update generator to handle optional dependencies using Requires
  411. Update DEBUG output typos.
  412. * Mon Aug 25 2008 Erk <[email protected]>
  413. Update generator to handle optional post-install
  414. * Tue Aug 16 2007 Erk <[email protected]>
  415. Generated by CPack RPM Generator and associated macros
  416. ")
  417. # Stop here if we were asked to only generate a template USER spec file
  418. # The generated file may then be used as a template by user who wants
  419. # to customize their own spec file.
  420. IF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  421. MESSAGE(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  422. ENDIF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  423. ENDIF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  424. # After that we may either use a user provided spec file
  425. # or generate one using appropriate variables value.
  426. IF(CPACK_RPM_USER_BINARY_SPECFILE)
  427. # User may have specified SPECFILE just use it
  428. MESSAGE("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  429. # The user provided file is processed for @var replacement
  430. CONFIGURE_FILE(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  431. ELSE(CPACK_RPM_USER_BINARY_SPECFILE)
  432. # No User specified spec file, will use the generated spec file
  433. MESSAGE("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  434. # Note the just created file is processed for @var replacement
  435. CONFIGURE_FILE(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  436. ENDIF(CPACK_RPM_USER_BINARY_SPECFILE)
  437. IF(RPMBUILD_EXECUTABLE)
  438. # Now call rpmbuild using the SPECFILE
  439. EXECUTE_PROCESS(
  440. COMMAND "${RPMBUILD_EXECUTABLE}" -bb
  441. --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  442. "${CPACK_RPM_BINARY_SPECFILE}"
  443. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  444. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err"
  445. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
  446. IF(CPACK_RPM_PACKAGE_DEBUG)
  447. MESSAGE("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  448. MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.err")
  449. MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild.out")
  450. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  451. ELSE(RPMBUILD_EXECUTABLE)
  452. IF(ALIEN_EXECUTABLE)
  453. MESSAGE(FATAL_ERROR "RPM packaging through alien not done (yet)")
  454. ENDIF(ALIEN_EXECUTABLE)
  455. ENDIF(RPMBUILD_EXECUTABLE)