CPackRPM.cmake 22 KB

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