CPackRPM.cmake 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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_SUMMARY
  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 vendor.
  49. # CPACK_RPM_PACKAGE_URL
  50. # Mandatory : NO
  51. # Default : -
  52. # The projects URL.
  53. # CPACK_RPM_PACKAGE_DESCRIPTION
  54. # Mandatory : YES
  55. # Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available"
  56. # CPACK_RPM_COMPRESSION_TYPE
  57. # Mandatory : NO
  58. # Default : -
  59. # May be used to override RPM compression type to be used
  60. # to build the RPM. For example some Linux distribution now default
  61. # to lzma or xz compression whereas older cannot use such RPM.
  62. # Using this one can enforce compression type to be used.
  63. # Possible value are: lzma, xz, bzip2 and gzip.
  64. # CPACK_RPM_PACKAGE_REQUIRES
  65. # Mandatory : NO
  66. # Default : -
  67. # May be used to set RPM dependencies (requires).
  68. # Note that you must enclose the complete requires string between quotes,
  69. # for example:
  70. # set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")
  71. # CPACK_RPM_PACKAGE_SUGGESTS
  72. # Mandatory : NO
  73. # Default : -
  74. # May be used to set weak RPM dependencies (suggests).
  75. # Note that you must enclose the complete requires string between quotes.
  76. # CPACK_RPM_PACKAGE_PROVIDES
  77. # Mandatory : NO
  78. # Default : -
  79. # May be used to set RPM dependencies (provides).
  80. # CPACK_RPM_PACKAGE_OBSOLETES
  81. # Mandatory : NO
  82. # Default : -
  83. # May be used to set RPM packages that are obsoleted by this one.
  84. # CPACK_RPM_PACKAGE_RELOCATABLE
  85. # Mandatory : NO
  86. # Default : CPACK_PACKAGE_RELOCATABLE
  87. # If this variable is set to TRUE or ON CPackRPM will try
  88. # to build a relocatable RPM package. A relocatable RPM may
  89. # be installed using rpm --prefix or --relocate in order to
  90. # install it at an alternate place see rpm(8).
  91. # Note that currently this may fail if CPACK_SET_DESTDIR is set to ON.
  92. # If CPACK_SET_DESTDIR is set then you will get a warning message
  93. # but if there is file installed with absolute path you'll get
  94. # unexpected behavior.
  95. # CPACK_RPM_SPEC_INSTALL_POST
  96. # Mandatory : NO
  97. # Default : -
  98. # May be used to set an RPM post-install command inside the spec file.
  99. # For example setting it to "/bin/true" may be used to prevent
  100. # rpmbuild to strip binaries.
  101. # CPACK_RPM_SPEC_MORE_DEFINE
  102. # Mandatory : NO
  103. # Default : -
  104. # May be used to add any %define lines to the generated spec file.
  105. # CPACK_RPM_PACKAGE_DEBUG
  106. # Mandatory : NO
  107. # Default : -
  108. # May be set when invoking cpack in order to trace debug information
  109. # during CPack RPM run. For example you may launch CPack like this
  110. # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
  111. # CPACK_RPM_USER_BINARY_SPECFILE
  112. # Mandatory : NO
  113. # Default : -
  114. # May be set by the user in order to specify a USER binary spec file
  115. # to be used by CPackRPM instead of generating the file.
  116. # The specified file will be processed by CONFIGURE_FILE( @ONLY).
  117. # CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  118. # Mandatory : NO
  119. # Default : -
  120. # If set CPack will generate a template for USER specified binary
  121. # spec file and stop with an error. For example launch CPack like this
  122. # cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
  123. # The user may then use this file in order to hand-craft is own
  124. # binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE.
  125. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  126. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  127. # Mandatory : NO
  128. # Default : -
  129. # May be used to embbed a pre (un)installation script in the spec file.
  130. # The refered script file(s) will be read and directly
  131. # put after the %pre or %preun section
  132. # One may verify which scriptlet has been included with
  133. # rpm -qp --scripts package.rpm
  134. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  135. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  136. # Mandatory : NO
  137. # Default : -
  138. # May be used to embbed a post (un)installation script in the spec file.
  139. # The refered script file(s) will be read and directly
  140. # put after the %post or %postun section
  141. # One may verify which scriptlet has been included with
  142. # rpm -qp --scripts package.rpm
  143. # CPACK_RPM_CHANGELOG_FILE
  144. # Mandatory : NO
  145. # Default : -
  146. # May be used to embbed a changelog in the spec file.
  147. # The refered file will be read and directly put after the %changelog
  148. # section.
  149. #=============================================================================
  150. # Copyright 2007-2009 Kitware, Inc.
  151. #
  152. # Distributed under the OSI-approved BSD License (the "License");
  153. # see accompanying file Copyright.txt for details.
  154. #
  155. # This software is distributed WITHOUT ANY WARRANTY; without even the
  156. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  157. # See the License for more information.
  158. #=============================================================================
  159. # (To distribute this file outside of CMake, substitute the full
  160. # License text for the above reference.)
  161. # Author: Eric Noulard with the help of Alexander Neundorf.
  162. IF(CMAKE_BINARY_DIR)
  163. MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  164. ENDIF(CMAKE_BINARY_DIR)
  165. IF(NOT UNIX)
  166. MESSAGE(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  167. ENDIF(NOT UNIX)
  168. # rpmbuild is the basic command for building RPM package
  169. # it may be a simple (symbolic) link to rpm command.
  170. FIND_PROGRAM(RPMBUILD_EXECUTABLE rpmbuild)
  171. # Check version of the rpmbuild tool this would be easier to
  172. # track bugs with users and CPackRPM debug mode.
  173. # We may use RPM version in order to check for available version dependent features
  174. IF(RPMBUILD_EXECUTABLE)
  175. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  176. OUTPUT_VARIABLE _TMP_VERSION
  177. ERROR_QUIET
  178. OUTPUT_STRIP_TRAILING_WHITESPACE)
  179. string(REGEX REPLACE "^.*\ " ""
  180. RPMBUILD_EXECUTABLE_VERSION
  181. ${_TMP_VERSION})
  182. IF(CPACK_RPM_PACKAGE_DEBUG)
  183. MESSAGE("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  184. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  185. ENDIF(RPMBUILD_EXECUTABLE)
  186. IF(NOT RPMBUILD_EXECUTABLE)
  187. MESSAGE(FATAL_ERROR "RPM package requires rpmbuild executable")
  188. ENDIF(NOT RPMBUILD_EXECUTABLE)
  189. # Display lsb_release output if DEBUG mode enable
  190. # This will help to diagnose problem with CPackRPM
  191. # because we will know on which kind of Linux we are
  192. IF(CPACK_RPM_PACKAGE_DEBUG)
  193. find_program(LSB_RELEASE_EXECUTABLE lsb_release)
  194. if(LSB_RELEASE_EXECUTABLE)
  195. execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
  196. OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
  197. ERROR_QUIET
  198. OUTPUT_STRIP_TRAILING_WHITESPACE)
  199. string(REGEX REPLACE "\n" ", "
  200. LSB_RELEASE_OUTPUT
  201. ${_TMP_LSB_RELEASE_OUTPUT})
  202. else (LSB_RELEASE_EXECUTABLE)
  203. set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
  204. endif(LSB_RELEASE_EXECUTABLE)
  205. MESSAGE("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
  206. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  207. # We may use RPM version in the future in order
  208. # to shut down warning about space in buildtree
  209. # some recent RPM version should support space in different places.
  210. # not checked [yet].
  211. IF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  212. MESSAGE(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  213. ENDIF(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  214. # If rpmbuild is found
  215. # we try to discover alien since we may be on non RPM distro like Debian.
  216. # In this case we may try to to use more advanced features
  217. # like generating RPM directly from DEB using alien.
  218. # FIXME feature not finished (yet)
  219. FIND_PROGRAM(ALIEN_EXECUTABLE alien)
  220. IF(ALIEN_EXECUTABLE)
  221. MESSAGE(STATUS "alien found, we may be on a Debian based distro.")
  222. ENDIF(ALIEN_EXECUTABLE)
  223. #
  224. # Use user-defined RPM specific variables value
  225. # or generate reasonable default value from
  226. # CPACK_xxx generic values.
  227. # The variables comes from the needed (mandatory or not)
  228. # values found in the RPM specification file aka ".spec" file.
  229. # The variables which may/should be defined are:
  230. #
  231. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  232. IF(NOT CPACK_RPM_PACKAGE_SUMMARY)
  233. # if neither var is defined lets use the name as summary
  234. IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  235. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  236. ELSE(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  237. SET(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  238. ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  239. ENDIF(NOT CPACK_RPM_PACKAGE_SUMMARY)
  240. # CPACK_RPM_PACKAGE_NAME (mandatory)
  241. IF(NOT CPACK_RPM_PACKAGE_NAME)
  242. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  243. ENDIF(NOT CPACK_RPM_PACKAGE_NAME)
  244. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  245. IF(NOT CPACK_RPM_PACKAGE_VERSION)
  246. IF(NOT CPACK_PACKAGE_VERSION)
  247. MESSAGE(FATAL_ERROR "RPM package requires a package version")
  248. ENDIF(NOT CPACK_PACKAGE_VERSION)
  249. SET(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  250. ENDIF(NOT CPACK_RPM_PACKAGE_VERSION)
  251. # Replace '-' in version with '_'
  252. # '-' character is an Illegal RPM version character
  253. # it is illegal because it is used to separate
  254. # RPM "Version" from RPM "Release"
  255. STRING(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
  256. # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
  257. IF(CPACK_RPM_PACKAGE_ARCHITECTURE)
  258. SET(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  259. IF(CPACK_RPM_PACKAGE_DEBUG)
  260. MESSAGE("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  261. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  262. ELSE(CPACK_RPM_PACKAGE_ARCHITECTURE)
  263. SET(TMP_RPM_BUILDARCH "")
  264. ENDIF(CPACK_RPM_PACKAGE_ARCHITECTURE)
  265. # CPACK_RPM_PACKAGE_RELEASE
  266. # The RPM release is the numbering of the RPM package ITSELF
  267. # this is the version of the PACKAGING and NOT the version
  268. # of the CONTENT of the package.
  269. # You may well need to generate a new RPM package release
  270. # without changing the version of the packaged software.
  271. # This is the case when the packaging is buggy (not) the software :=)
  272. # If not set, 1 is a good candidate
  273. IF(NOT CPACK_RPM_PACKAGE_RELEASE)
  274. SET(CPACK_RPM_PACKAGE_RELEASE 1)
  275. ENDIF(NOT CPACK_RPM_PACKAGE_RELEASE)
  276. # CPACK_RPM_PACKAGE_LICENSE
  277. IF(NOT CPACK_RPM_PACKAGE_LICENSE)
  278. SET(CPACK_RPM_PACKAGE_LICENSE "unknown")
  279. ENDIF(NOT CPACK_RPM_PACKAGE_LICENSE)
  280. # CPACK_RPM_PACKAGE_GROUP
  281. IF(NOT CPACK_RPM_PACKAGE_GROUP)
  282. SET(CPACK_RPM_PACKAGE_GROUP "unknown")
  283. ENDIF(NOT CPACK_RPM_PACKAGE_GROUP)
  284. # CPACK_RPM_PACKAGE_VENDOR
  285. IF(NOT CPACK_RPM_PACKAGE_VENDOR)
  286. IF(CPACK_PACKAGE_VENDOR)
  287. SET(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  288. ELSE(CPACK_PACKAGE_VENDOR)
  289. SET(CPACK_RPM_PACKAGE_VENDOR "unknown")
  290. ENDIF(CPACK_PACKAGE_VENDOR)
  291. ENDIF(NOT CPACK_RPM_PACKAGE_VENDOR)
  292. # CPACK_RPM_PACKAGE_SOURCE
  293. # The name of the source tarball in case we generate a source RPM
  294. # CPACK_RPM_PACKAGE_DESCRIPTION
  295. # The variable content may be either
  296. # - explicitly given by the user or
  297. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  298. # if it is defined
  299. # - set to a default value
  300. #
  301. IF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  302. IF (CPACK_PACKAGE_DESCRIPTION_FILE)
  303. FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  304. ELSE (CPACK_PACKAGE_DESCRIPTION_FILE)
  305. SET(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  306. ENDIF (CPACK_PACKAGE_DESCRIPTION_FILE)
  307. ENDIF (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  308. # CPACK_RPM_COMPRESSION_TYPE
  309. #
  310. IF (CPACK_RPM_COMPRESSION_TYPE)
  311. IF(CPACK_RPM_PACKAGE_DEBUG)
  312. MESSAGE("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
  313. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  314. IF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  315. SET(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
  316. ENDIF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  317. IF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  318. SET(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
  319. ENDIF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  320. IF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  321. SET(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
  322. ENDIF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  323. IF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  324. SET(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
  325. ENDIF(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  326. ELSE(CPACK_RPM_COMPRESSION_TYPE)
  327. SET(CPACK_RPM_COMPRESSION_TYPE_TMP "")
  328. ENDIF(CPACK_RPM_COMPRESSION_TYPE)
  329. if(CPACK_PACKAGE_RELOCATABLE)
  330. set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
  331. endif(CPACK_PACKAGE_RELOCATABLE)
  332. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  333. if(CPACK_RPM_PACKAGE_DEBUG)
  334. message("CPackRPM:Debug: Trying to build a relocatable package")
  335. endif(CPACK_RPM_PACKAGE_DEBUG)
  336. if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  337. message("CPackRPM:Warning: CPACK_SET_DESTDIR is set (=${CPACK_SET_DESTDIR}) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.")
  338. else(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  339. set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX})
  340. endif(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  341. endif(CPACK_RPM_PACKAGE_RELOCATABLE)
  342. # check if additional fields for RPM spec header are given
  343. FOREACH(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX)
  344. IF(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  345. STRING(LENGTH ${_RPM_SPEC_HEADER} _PACKAGE_HEADER_STRLENGTH)
  346. MATH(EXPR _PACKAGE_HEADER_STRLENGTH "${_PACKAGE_HEADER_STRLENGTH} - 1")
  347. STRING(SUBSTRING ${_RPM_SPEC_HEADER} 1 ${_PACKAGE_HEADER_STRLENGTH} _PACKAGE_HEADER_TAIL)
  348. STRING(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
  349. STRING(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
  350. SET(_PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}${_PACKAGE_HEADER_TAIL}")
  351. IF(CPACK_RPM_PACKAGE_DEBUG)
  352. MESSAGE("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}}")
  353. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  354. SET(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}}")
  355. ENDIF(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  356. ENDFOREACH(_RPM_SPEC_HEADER)
  357. # CPACK_RPM_SPEC_INSTALL_POST
  358. # May be used to define a RPM post intallation script
  359. # for example setting it to "/bin/true" may prevent
  360. # rpmbuild from stripping binaries.
  361. IF(CPACK_RPM_SPEC_INSTALL_POST)
  362. IF(CPACK_RPM_PACKAGE_DEBUG)
  363. MESSAGE("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  364. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  365. SET(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  366. ENDIF(CPACK_RPM_SPEC_INSTALL_POST)
  367. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  368. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  369. # May be used to embbed a post (un)installation script in the spec file.
  370. # The refered script file(s) will be read and directly
  371. # put after the %post or %postun section
  372. if(CPACK_RPM_POST_INSTALL_SCRIPT_FILE)
  373. if(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  374. file(READ ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_POSTINSTALL)
  375. else(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  376. message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_SCRIPT_FILE}> does not exists - ignoring")
  377. endif(EXISTS ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  378. endif(CPACK_RPM_POST_INSTALL_SCRIPT_FILE)
  379. if(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE)
  380. if(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  381. file(READ ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
  382. else(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  383. message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE}> does not exists - ignoring")
  384. endif(EXISTS ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  385. endif(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE)
  386. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  387. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  388. # May be used to embed a pre (un)installation script in the spec file.
  389. # The refered script file(s) will be read and directly
  390. # put after the %pre or %preun section
  391. if(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE)
  392. if(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  393. file(READ ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_PREINSTALL)
  394. else(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  395. message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE}> does not exists - ignoring")
  396. endif(EXISTS ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  397. endif(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE)
  398. if(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE)
  399. if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  400. file(READ ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
  401. else(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  402. message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE}> does not exists - ignoring")
  403. endif(EXISTS ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  404. endif(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE)
  405. # CPACK_RPM_CHANGELOG_FILE
  406. # May be used to embed a changelog in the spec file.
  407. # The refered file will be read and directly put after the %changelog section
  408. if(CPACK_RPM_CHANGELOG_FILE)
  409. if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  410. file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
  411. else(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  412. message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
  413. endif(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  414. else(CPACK_RPM_CHANGELOG_FILE)
  415. set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Erk <[email protected]>\n Generated by CPack RPM (no Changelog file were provided)")
  416. endif(CPACK_RPM_CHANGELOG_FILE)
  417. # CPACK_RPM_SPEC_MORE_DEFINE
  418. # This is a generated spec rpm file spaceholder
  419. IF(CPACK_RPM_SPEC_MORE_DEFINE)
  420. IF(CPACK_RPM_PACKAGE_DEBUG)
  421. MESSAGE("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  422. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  423. ENDIF(CPACK_RPM_SPEC_MORE_DEFINE)
  424. # Now we may create the RPM build tree structure
  425. SET(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  426. MESSAGE(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  427. # Prepare RPM build tree
  428. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  429. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  430. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  431. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  432. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  433. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  434. FILE(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  435. #SET(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  436. SET(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  437. # it seems rpmbuild can't handle spaces in the path
  438. # neither escaping (as below) nor putting quotes around the path seem to help
  439. #STRING(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  440. SET(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  441. # Are we packaging components ?
  442. IF(CPACK_RPM_PACKAGE_COMPONENT)
  443. SET(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
  444. SET(CPACK_RPM_PACKAGE_COMPONENT_PART_PATH "/${CPACK_RPM_PACKAGE_COMPONENT}")
  445. SET(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${CPACK_RPM_PACKAGE_COMPONENT}")
  446. ELSE(CPACK_RPM_PACKAGE_COMPONENT)
  447. SET(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
  448. SET(CPACK_RPM_PACKAGE_COMPONENT_PART_PATH "")
  449. SET(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
  450. ENDIF(CPACK_RPM_PACKAGE_COMPONENT)
  451. # Use files tree to construct files command (spec file)
  452. # We should not forget to include symlinks (thus -o -type l)
  453. # We must remove the './' due to the local search and escape the
  454. # file name by enclosing it between double quotes (thus the sed)
  455. # Then we must authorize any man pages extension (adding * at the end)
  456. # because rpmbuild may automatically compress those files
  457. EXECUTE_PROCESS(COMMAND find . -type f -o -type l
  458. COMMAND sed s:.*/man.*/.*:&*:
  459. COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/
  460. WORKING_DIRECTORY "${WDIR}"
  461. OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
  462. # In component case, replace CPACK_ABSOLUTE_DESTINATION_FILES
  463. # with the content of CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
  464. # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES handling
  465. if(CPACK_RPM_PACKAGE_COMPONENT)
  466. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  467. set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}")
  468. set(CPACK_ABSOLUTE_DESTINATION_FILES "${${COMPONENT_FILES_TAG}}")
  469. if(CPACK_RPM_PACKAGE_DEBUG)
  470. message("CPackRPM:Debug: Handling Absolute Destination Files ${CPACK_ABSOLUTE_DESTINATION_FILES}")
  471. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  472. endif(CPACK_RPM_PACKAGE_DEBUG)
  473. endif()
  474. endif()
  475. if (CPACK_ABSOLUTE_DESTINATION_FILES)
  476. IF(CPACK_RPM_PACKAGE_DEBUG)
  477. message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES}")
  478. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  479. # Remove trailing space
  480. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  481. # Transform endline separated - string into CMake List
  482. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  483. # Remove unecessary quotes
  484. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  485. # Remove ABSOLUTE install file from INSTALL FILE LIST
  486. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES})
  487. # Rebuild INSTALL_FILES
  488. set(CPACK_RPM_INSTALL_FILES "")
  489. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  490. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
  491. endforeach(F)
  492. # Build ABSOLUTE_INSTALL_FILES
  493. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  494. foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES)
  495. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "${CPACK_RPM_ABSOLUTE_INSTALL_FILES}%config \"${F}\"\n")
  496. endforeach(F)
  497. IF(CPACK_RPM_PACKAGE_DEBUG)
  498. message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
  499. message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
  500. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  501. endif(CPACK_ABSOLUTE_DESTINATION_FILES)
  502. # The name of the final spec file to be used by rpmbuild
  503. SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec")
  504. # Print out some debug information if we were asked for that
  505. IF(CPACK_RPM_PACKAGE_DEBUG)
  506. MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  507. MESSAGE("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  508. MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  509. MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  510. MESSAGE("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  511. MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  512. MESSAGE("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  513. MESSAGE("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  514. MESSAGE("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  515. ENDIF(CPACK_RPM_PACKAGE_DEBUG)
  516. # USER generated spec file handling.
  517. # We should generate a spec file template:
  518. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  519. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  520. #
  521. IF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  522. FILE(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  523. "# -*- rpm-spec -*-
  524. BuildRoot: \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
  525. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  526. Name: \@CPACK_RPM_PACKAGE_NAME\@
  527. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  528. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  529. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  530. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  531. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  532. \@TMP_RPM_URL\@
  533. \@TMP_RPM_REQUIRES\@
  534. \@TMP_RPM_PROVIDES\@
  535. \@TMP_RPM_OBSOLETES\@
  536. \@TMP_RPM_BUILDARCH\@
  537. \@TMP_RPM_PREFIX\@
  538. %define _rpmdir \@CPACK_RPM_DIRECTORY\@
  539. %define _rpmfilename \@CPACK_RPM_FILE_NAME\@
  540. %define _unpackaged_files_terminate_build 0
  541. %define _topdir \@CPACK_RPM_DIRECTORY\@
  542. \@TMP_RPM_SPEC_INSTALL_POST\@
  543. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  544. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  545. %description
  546. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  547. # This is a shortcutted spec file generated by CMake RPM generator
  548. # we skip _install step because CPack does that for us.
  549. # We do only save CPack installed tree in _prepr
  550. # and then restore it in build.
  551. %prep
  552. mv $RPM_BUILD_ROOT \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\"
  553. #p build
  554. %install
  555. if [ -e $RPM_BUILD_ROOT ];
  556. then
  557. rm -rf $RPM_BUILD_ROOT
  558. fi
  559. mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
  560. %clean
  561. %post
  562. \@CPACK_RPM_SPEC_POSTINSTALL\@
  563. %postun
  564. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  565. %pre
  566. \@CPACK_RPM_SPEC_PREINSTALL\@
  567. %preun
  568. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  569. %files
  570. %defattr(-,root,root,-)
  571. ${CPACK_RPM_INSTALL_FILES}
  572. ${CPACK_RPM_ABSOLUTE_INSTALL_FILES}
  573. %changelog
  574. \@CPACK_RPM_SPEC_CHANGELOG\@
  575. ")
  576. # Stop here if we were asked to only generate a template USER spec file
  577. # The generated file may then be used as a template by user who wants
  578. # to customize their own spec file.
  579. IF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  580. MESSAGE(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  581. ENDIF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  582. ENDIF(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  583. # After that we may either use a user provided spec file
  584. # or generate one using appropriate variables value.
  585. IF(CPACK_RPM_USER_BINARY_SPECFILE)
  586. # User may have specified SPECFILE just use it
  587. MESSAGE("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  588. # The user provided file is processed for @var replacement
  589. CONFIGURE_FILE(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  590. ELSE(CPACK_RPM_USER_BINARY_SPECFILE)
  591. # No User specified spec file, will use the generated spec file
  592. MESSAGE("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  593. # Note the just created file is processed for @var replacement
  594. CONFIGURE_FILE(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  595. ENDIF(CPACK_RPM_USER_BINARY_SPECFILE)
  596. IF(RPMBUILD_EXECUTABLE)
  597. # Now call rpmbuild using the SPECFILE
  598. EXECUTE_PROCESS(
  599. COMMAND "${RPMBUILD_EXECUTABLE}" -bb
  600. --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  601. "${CPACK_RPM_BINARY_SPECFILE}"
  602. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  603. RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
  604. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err"
  605. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
  606. IF(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  607. FILE(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err RPMBUILDERR)
  608. FILE(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out RPMBUILDOUT)
  609. MESSAGE("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  610. MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err")
  611. MESSAGE("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  612. MESSAGE("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
  613. MESSAGE("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  614. ENDIF(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  615. ELSE(RPMBUILD_EXECUTABLE)
  616. IF(ALIEN_EXECUTABLE)
  617. MESSAGE(FATAL_ERROR "RPM packaging through alien not done (yet)")
  618. ENDIF(ALIEN_EXECUTABLE)
  619. ENDIF(RPMBUILD_EXECUTABLE)