CPackRPM.cmake 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. ##section Variables specific to CPack RPM generator
  2. ##end
  3. ##module
  4. # - The builtin (binary) CPack RPM generator (Unix only)
  5. # CPackRPM may be used to create RPM package using CPack.
  6. # CPackRPM is a CPack generator thus it uses the CPACK_XXX variables
  7. # used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
  8. #
  9. # However CPackRPM has specific features which are controlled by
  10. # the specifics CPACK_RPM_XXX variables. CPackRPM is a component aware
  11. # generator so when CPACK_RPM_COMPONENT_INSTALL is ON some more
  12. # CPACK_RPM_<ComponentName>_XXXX variables may be used in order
  13. # to have component specific values. Note however that <componentName>
  14. # refers to the **grouping name**. This may be either a component name
  15. # or a component GROUP name.
  16. # Usually those vars correspond to RPM spec file entities, one may find
  17. # information about spec files here http://www.rpm.org/wiki/Docs.
  18. # You'll find a detailed usage of CPackRPM on the wiki:
  19. # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29
  20. # However as a handy reminder here comes the list of specific variables:
  21. ##end
  22. #
  23. ##variable
  24. # CPACK_RPM_PACKAGE_SUMMARY - The RPM package summary.
  25. # Mandatory : YES
  26. # Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
  27. ##end
  28. ##variable
  29. # CPACK_RPM_PACKAGE_NAME - The RPM package name.
  30. # Mandatory : YES
  31. # Default : CPACK_PACKAGE_NAME
  32. ##end
  33. ##variable
  34. # CPACK_RPM_PACKAGE_VERSION - The RPM package version.
  35. # Mandatory : YES
  36. # Default : CPACK_PACKAGE_VERSION
  37. ##end
  38. ##variable
  39. # CPACK_RPM_PACKAGE_ARCHITECTURE - The RPM package architecture.
  40. # Mandatory : NO
  41. # Default : -
  42. # This may be set to "noarch" if you
  43. # know you are building a noarch package.
  44. ##end
  45. ##variable
  46. # CPACK_RPM_PACKAGE_RELEASE - The RPM package release.
  47. # Mandatory : YES
  48. # Default : 1
  49. # This is the numbering of the RPM package
  50. # itself, i.e. the version of the packaging and not the version of the
  51. # content (see CPACK_RPM_PACKAGE_VERSION). One may change the default
  52. # value if the previous packaging was buggy and/or you want to put here
  53. # a fancy Linux distro specific numbering.
  54. ##end
  55. ##variable
  56. # CPACK_RPM_PACKAGE_LICENSE - The RPM package license policy.
  57. # Mandatory : YES
  58. # Default : "unknown"
  59. ##end
  60. ##variable
  61. # CPACK_RPM_PACKAGE_GROUP - The RPM package group.
  62. # Mandatory : YES
  63. # Default : "unknown"
  64. ##end
  65. ##variable
  66. # CPACK_RPM_PACKAGE_VENDOR - The RPM package vendor.
  67. # Mandatory : YES
  68. # Default : CPACK_PACKAGE_VENDOR if set or "unknown"
  69. ##end
  70. ##variable
  71. # CPACK_RPM_PACKAGE_URL - The projects URL.
  72. # Mandatory : NO
  73. # Default : -
  74. ##end
  75. ##variable
  76. # CPACK_RPM_PACKAGE_DESCRIPTION - RPM package description.
  77. # Mandatory : YES
  78. # Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available"
  79. ##end
  80. ##variable
  81. # CPACK_RPM_COMPRESSION_TYPE - RPM compression type.
  82. # Mandatory : NO
  83. # Default : -
  84. # May be used to override RPM compression type to be used
  85. # to build the RPM. For example some Linux distribution now default
  86. # to lzma or xz compression whereas older cannot use such RPM.
  87. # Using this one can enforce compression type to be used.
  88. # Possible value are: lzma, xz, bzip2 and gzip.
  89. ##end
  90. ##variable
  91. # CPACK_RPM_PACKAGE_REQUIRES - RPM spec requires field.
  92. # Mandatory : NO
  93. # Default : -
  94. # May be used to set RPM dependencies (requires).
  95. # Note that you must enclose the complete requires string between quotes,
  96. # for example:
  97. # set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")
  98. # The required package list of an RPM file could be printed with
  99. # rpm -qp --requires file.rpm
  100. ##end
  101. ##variable
  102. # CPACK_RPM_PACKAGE_SUGGESTS - RPM spec suggest field.
  103. # Mandatory : NO
  104. # Default : -
  105. # May be used to set weak RPM dependencies (suggests).
  106. # Note that you must enclose the complete requires string between quotes.
  107. ##end
  108. ##variable
  109. # CPACK_RPM_PACKAGE_PROVIDES - RPM spec provides field.
  110. # Mandatory : NO
  111. # Default : -
  112. # May be used to set RPM dependencies (provides).
  113. # The provided package list of an RPM file could be printed with
  114. # rpm -qp --provides file.rpm
  115. ##end
  116. ##variable
  117. # CPACK_RPM_PACKAGE_OBSOLETES - RPM spec obsoletes field.
  118. # Mandatory : NO
  119. # Default : -
  120. # May be used to set RPM packages that are obsoleted by this one.
  121. ##end
  122. ##variable
  123. # CPACK_RPM_PACKAGE_RELOCATABLE - build a relocatable RPM.
  124. # Mandatory : NO
  125. # Default : CPACK_PACKAGE_RELOCATABLE
  126. # If this variable is set to TRUE or ON CPackRPM will try
  127. # to build a relocatable RPM package. A relocatable RPM may
  128. # be installed using rpm --prefix or --relocate in order to
  129. # install it at an alternate place see rpm(8).
  130. # Note that currently this may fail if CPACK_SET_DESTDIR is set to ON.
  131. # If CPACK_SET_DESTDIR is set then you will get a warning message
  132. # but if there is file installed with absolute path you'll get
  133. # unexpected behavior.
  134. ##end
  135. ##variable
  136. # CPACK_RPM_SPEC_INSTALL_POST - [deprecated].
  137. # Mandatory : NO
  138. # Default : -
  139. # This way of specifying post-install script is deprecated use
  140. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  141. # May be used to set an RPM post-install command inside the spec file.
  142. # For example setting it to "/bin/true" may be used to prevent
  143. # rpmbuild to strip binaries.
  144. ##end
  145. ##variable
  146. # CPACK_RPM_SPEC_MORE_DEFINE - RPM extended spec definitions lines.
  147. # Mandatory : NO
  148. # Default : -
  149. # May be used to add any %define lines to the generated spec file.
  150. ##end
  151. ##variable
  152. # CPACK_RPM_PACKAGE_DEBUG - Toggle CPackRPM debug output.
  153. # Mandatory : NO
  154. # Default : -
  155. # May be set when invoking cpack in order to trace debug information
  156. # during CPack RPM run. For example you may launch CPack like this
  157. # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
  158. ##end
  159. ##variable
  160. # CPACK_RPM_USER_BINARY_SPECFILE - A user provided spec file.
  161. # Mandatory : NO
  162. # Default : -
  163. # May be set by the user in order to specify a USER binary spec file
  164. # to be used by CPackRPM instead of generating the file.
  165. # The specified file will be processed by configure_file( @ONLY).
  166. # One can provide a component specific file by setting
  167. # CPACK_RPM_<componentName>_USER_BINARY_SPECFILE.
  168. ##end
  169. ##variable
  170. # CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE - Spec file template.
  171. # Mandatory : NO
  172. # Default : -
  173. # If set CPack will generate a template for USER specified binary
  174. # spec file and stop with an error. For example launch CPack like this
  175. # cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
  176. # The user may then use this file in order to hand-craft is own
  177. # binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE.
  178. ##end
  179. ##variable
  180. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  181. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  182. # Mandatory : NO
  183. # Default : -
  184. # May be used to embed a pre (un)installation script in the spec file.
  185. # The refered script file(s) will be read and directly
  186. # put after the %pre or %preun section
  187. # If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
  188. # each component can be overridden with
  189. # CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE and
  190. # CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE
  191. # One may verify which scriptlet has been included with
  192. # rpm -qp --scripts package.rpm
  193. ##end
  194. ##variable
  195. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  196. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  197. # Mandatory : NO
  198. # Default : -
  199. # May be used to embed a post (un)installation script in the spec file.
  200. # The refered script file(s) will be read and directly
  201. # put after the %post or %postun section
  202. # If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
  203. # each component can be overridden with
  204. # CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE and
  205. # CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE
  206. # One may verify which scriptlet has been included with
  207. # rpm -qp --scripts package.rpm
  208. ##end
  209. ##variable
  210. # CPACK_RPM_USER_FILELIST
  211. # CPACK_RPM_<COMPONENT>_USER_FILELIST
  212. # Mandatory : NO
  213. # Default : -
  214. # May be used to explicitly specify %(<directive>) file line
  215. # in the spec file. Like %config(noreplace) or any other directive
  216. # that be found in the %files section. Since CPackRPM is generating
  217. # the list of files (and directories) the user specified files of
  218. # the CPACK_RPM_<COMPONENT>_USER_FILELIST list will be removed from the generated list.
  219. ##end
  220. ##variable
  221. # CPACK_RPM_CHANGELOG_FILE - RPM changelog file.
  222. # Mandatory : NO
  223. # Default : -
  224. # May be used to embed a changelog in the spec file.
  225. # The refered file will be read and directly put after the %changelog
  226. # section.
  227. ##end
  228. ##variable
  229. # CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST - list of path to be excluded.
  230. # Mandatory : NO
  231. # Default : /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include
  232. # May be used to exclude path (directories or files) from the auto-generated
  233. # list of paths discovered by CPack RPM. The defaut value contains a reasonable
  234. # set of values if the variable is not defined by the user. If the variable
  235. # is defined by the user then CPackRPM will NOT any of the default path.
  236. # If you want to add some path to the default list then you can use
  237. # CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION variable.
  238. ##end
  239. ##variable
  240. # CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION - additional list of path to be excluded.
  241. # Mandatory : NO
  242. # Default : -
  243. # May be used to add more exclude path (directories or files) from the initial
  244. # default list of excluded paths. See CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST.
  245. ##end
  246. #=============================================================================
  247. # Copyright 2007-2009 Kitware, Inc.
  248. #
  249. # Distributed under the OSI-approved BSD License (the "License");
  250. # see accompanying file Copyright.txt for details.
  251. #
  252. # This software is distributed WITHOUT ANY WARRANTY; without even the
  253. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  254. # See the License for more information.
  255. #=============================================================================
  256. # (To distribute this file outside of CMake, substitute the full
  257. # License text for the above reference.)
  258. # Author: Eric Noulard with the help of Alexander Neundorf.
  259. if(CMAKE_BINARY_DIR)
  260. message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  261. endif()
  262. if(NOT UNIX)
  263. message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  264. endif()
  265. # rpmbuild is the basic command for building RPM package
  266. # it may be a simple (symbolic) link to rpm command.
  267. find_program(RPMBUILD_EXECUTABLE rpmbuild)
  268. # Check version of the rpmbuild tool this would be easier to
  269. # track bugs with users and CPackRPM debug mode.
  270. # We may use RPM version in order to check for available version dependent features
  271. if(RPMBUILD_EXECUTABLE)
  272. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  273. OUTPUT_VARIABLE _TMP_VERSION
  274. ERROR_QUIET
  275. OUTPUT_STRIP_TRAILING_WHITESPACE)
  276. string(REGEX REPLACE "^.* " ""
  277. RPMBUILD_EXECUTABLE_VERSION
  278. ${_TMP_VERSION})
  279. if(CPACK_RPM_PACKAGE_DEBUG)
  280. message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  281. endif()
  282. endif()
  283. if(NOT RPMBUILD_EXECUTABLE)
  284. message(FATAL_ERROR "RPM package requires rpmbuild executable")
  285. endif()
  286. # Display lsb_release output if DEBUG mode enable
  287. # This will help to diagnose problem with CPackRPM
  288. # because we will know on which kind of Linux we are
  289. if(CPACK_RPM_PACKAGE_DEBUG)
  290. find_program(LSB_RELEASE_EXECUTABLE lsb_release)
  291. if(LSB_RELEASE_EXECUTABLE)
  292. execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
  293. OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
  294. ERROR_QUIET
  295. OUTPUT_STRIP_TRAILING_WHITESPACE)
  296. string(REGEX REPLACE "\n" ", "
  297. LSB_RELEASE_OUTPUT
  298. ${_TMP_LSB_RELEASE_OUTPUT})
  299. else ()
  300. set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
  301. endif()
  302. message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
  303. endif()
  304. # We may use RPM version in the future in order
  305. # to shut down warning about space in buildtree
  306. # some recent RPM version should support space in different places.
  307. # not checked [yet].
  308. if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  309. message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  310. endif()
  311. # If rpmbuild is found
  312. # we try to discover alien since we may be on non RPM distro like Debian.
  313. # In this case we may try to to use more advanced features
  314. # like generating RPM directly from DEB using alien.
  315. # FIXME feature not finished (yet)
  316. find_program(ALIEN_EXECUTABLE alien)
  317. if(ALIEN_EXECUTABLE)
  318. message(STATUS "alien found, we may be on a Debian based distro.")
  319. endif()
  320. # Are we packaging components ?
  321. if(CPACK_RPM_PACKAGE_COMPONENT)
  322. set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
  323. else()
  324. set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
  325. endif()
  326. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  327. #
  328. # Use user-defined RPM specific variables value
  329. # or generate reasonable default value from
  330. # CPACK_xxx generic values.
  331. # The variables comes from the needed (mandatory or not)
  332. # values found in the RPM specification file aka ".spec" file.
  333. # The variables which may/should be defined are:
  334. #
  335. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  336. if(NOT CPACK_RPM_PACKAGE_SUMMARY)
  337. # if neither var is defined lets use the name as summary
  338. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  339. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  340. else()
  341. set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  342. endif()
  343. endif()
  344. # CPACK_RPM_PACKAGE_NAME (mandatory)
  345. if(NOT CPACK_RPM_PACKAGE_NAME)
  346. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  347. endif()
  348. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  349. if(NOT CPACK_RPM_PACKAGE_VERSION)
  350. if(NOT CPACK_PACKAGE_VERSION)
  351. message(FATAL_ERROR "RPM package requires a package version")
  352. endif()
  353. set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  354. endif()
  355. # Replace '-' in version with '_'
  356. # '-' character is an Illegal RPM version character
  357. # it is illegal because it is used to separate
  358. # RPM "Version" from RPM "Release"
  359. string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
  360. # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
  361. if(CPACK_RPM_PACKAGE_ARCHITECTURE)
  362. set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  363. if(CPACK_RPM_PACKAGE_DEBUG)
  364. message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  365. endif()
  366. else()
  367. set(TMP_RPM_BUILDARCH "")
  368. endif()
  369. # CPACK_RPM_PACKAGE_RELEASE
  370. # The RPM release is the numbering of the RPM package ITSELF
  371. # this is the version of the PACKAGING and NOT the version
  372. # of the CONTENT of the package.
  373. # You may well need to generate a new RPM package release
  374. # without changing the version of the packaged software.
  375. # This is the case when the packaging is buggy (not) the software :=)
  376. # If not set, 1 is a good candidate
  377. if(NOT CPACK_RPM_PACKAGE_RELEASE)
  378. set(CPACK_RPM_PACKAGE_RELEASE 1)
  379. endif()
  380. # CPACK_RPM_PACKAGE_LICENSE
  381. if(NOT CPACK_RPM_PACKAGE_LICENSE)
  382. set(CPACK_RPM_PACKAGE_LICENSE "unknown")
  383. endif()
  384. # CPACK_RPM_PACKAGE_GROUP
  385. if(NOT CPACK_RPM_PACKAGE_GROUP)
  386. set(CPACK_RPM_PACKAGE_GROUP "unknown")
  387. endif()
  388. # CPACK_RPM_PACKAGE_VENDOR
  389. if(NOT CPACK_RPM_PACKAGE_VENDOR)
  390. if(CPACK_PACKAGE_VENDOR)
  391. set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  392. else()
  393. set(CPACK_RPM_PACKAGE_VENDOR "unknown")
  394. endif()
  395. endif()
  396. # CPACK_RPM_PACKAGE_SOURCE
  397. # The name of the source tarball in case we generate a source RPM
  398. # CPACK_RPM_PACKAGE_DESCRIPTION
  399. # The variable content may be either
  400. # - explicitly given by the user or
  401. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  402. # if it is defined
  403. # - set to a default value
  404. #
  405. if (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  406. if (CPACK_PACKAGE_DESCRIPTION_FILE)
  407. file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  408. else ()
  409. set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  410. endif ()
  411. endif ()
  412. # CPACK_RPM_COMPRESSION_TYPE
  413. #
  414. if (CPACK_RPM_COMPRESSION_TYPE)
  415. if(CPACK_RPM_PACKAGE_DEBUG)
  416. message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
  417. endif()
  418. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  419. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
  420. endif()
  421. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  422. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
  423. endif()
  424. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  425. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
  426. endif()
  427. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  428. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
  429. endif()
  430. else()
  431. set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
  432. endif()
  433. if(CPACK_PACKAGE_RELOCATABLE)
  434. set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
  435. endif()
  436. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  437. if(CPACK_RPM_PACKAGE_DEBUG)
  438. message("CPackRPM:Debug: Trying to build a relocatable package")
  439. endif()
  440. if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  441. 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.")
  442. else()
  443. set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX})
  444. endif()
  445. endif()
  446. # Check if additional fields for RPM spec header are given
  447. # There may be some COMPONENT specific variables as well
  448. # If component specific var is not provided we use the global one
  449. # for each component
  450. foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV)
  451. if(CPACK_RPM_PACKAGE_DEBUG)
  452. message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
  453. endif()
  454. if(CPACK_RPM_PACKAGE_COMPONENT)
  455. if(DEFINED CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER})
  456. if(CPACK_RPM_PACKAGE_DEBUG)
  457. message("CPackRPM:Debug: using CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}")
  458. endif()
  459. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}})
  460. else()
  461. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  462. if(CPACK_RPM_PACKAGE_DEBUG)
  463. message("CPackRPM:Debug: CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER} not defined")
  464. message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
  465. endif()
  466. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
  467. endif()
  468. endif()
  469. else()
  470. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  471. if(CPACK_RPM_PACKAGE_DEBUG)
  472. message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
  473. endif()
  474. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
  475. endif()
  476. endif()
  477. # Treat the RPM Spec keyword iff it has been properly defined
  478. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  479. # Transform NAME --> Name e.g. PROVIDES --> Provides
  480. # The Upper-case first letter and lowercase tail is the
  481. # appropriate value required in the final RPM spec file.
  482. string(LENGTH ${_RPM_SPEC_HEADER} _PACKAGE_HEADER_STRLENGTH)
  483. math(EXPR _PACKAGE_HEADER_STRLENGTH "${_PACKAGE_HEADER_STRLENGTH} - 1")
  484. string(SUBSTRING ${_RPM_SPEC_HEADER} 1 ${_PACKAGE_HEADER_STRLENGTH} _PACKAGE_HEADER_TAIL)
  485. string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
  486. string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
  487. set(_PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}${_PACKAGE_HEADER_TAIL}")
  488. if(CPACK_RPM_PACKAGE_DEBUG)
  489. message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  490. endif()
  491. set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  492. else()
  493. # Do not forget to unset previously set header (from previous component)
  494. unset(TMP_RPM_${_RPM_SPEC_HEADER})
  495. endif()
  496. endforeach()
  497. # CPACK_RPM_SPEC_INSTALL_POST
  498. # May be used to define a RPM post intallation script
  499. # for example setting it to "/bin/true" may prevent
  500. # rpmbuild from stripping binaries.
  501. if(CPACK_RPM_SPEC_INSTALL_POST)
  502. if(CPACK_RPM_PACKAGE_DEBUG)
  503. message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  504. endif()
  505. set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  506. endif()
  507. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
  508. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
  509. # May be used to embed a post (un)installation script in the spec file.
  510. # The refered script file(s) will be read and directly
  511. # put after the %post or %postun section
  512. if(CPACK_RPM_PACKAGE_COMPONENT)
  513. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE)
  514. set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE})
  515. else()
  516. set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  517. endif()
  518. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE)
  519. set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE})
  520. else()
  521. set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  522. endif()
  523. else()
  524. set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
  525. set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
  526. endif()
  527. # Handle post-install file if it has been specified
  528. if(CPACK_RPM_POST_INSTALL_READ_FILE)
  529. if(EXISTS ${CPACK_RPM_POST_INSTALL_READ_FILE})
  530. file(READ ${CPACK_RPM_POST_INSTALL_READ_FILE} CPACK_RPM_SPEC_POSTINSTALL)
  531. else()
  532. message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_READ_FILE}> does not exists - ignoring")
  533. endif()
  534. else()
  535. # reset SPEC var value if no post install file has been specified
  536. # (either globally or component-wise)
  537. set(CPACK_RPM_SPEC_POSTINSTALL "")
  538. endif()
  539. # Handle post-uninstall file if it has been specified
  540. if(CPACK_RPM_POST_UNINSTALL_READ_FILE)
  541. if(EXISTS ${CPACK_RPM_POST_UNINSTALL_READ_FILE})
  542. file(READ ${CPACK_RPM_POST_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
  543. else()
  544. message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_READ_FILE}> does not exists - ignoring")
  545. endif()
  546. else()
  547. # reset SPEC var value if no post uninstall file has been specified
  548. # (either globally or component-wise)
  549. set(CPACK_RPM_SPEC_POSTUNINSTALL "")
  550. endif()
  551. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
  552. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
  553. # May be used to embed a pre (un)installation script in the spec file.
  554. # The refered script file(s) will be read and directly
  555. # put after the %pre or %preun section
  556. if(CPACK_RPM_PACKAGE_COMPONENT)
  557. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE)
  558. set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE})
  559. else()
  560. set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  561. endif()
  562. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE)
  563. set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE})
  564. else()
  565. set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  566. endif()
  567. else()
  568. set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
  569. set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
  570. endif()
  571. # Handle pre-install file if it has been specified
  572. if(CPACK_RPM_PRE_INSTALL_READ_FILE)
  573. if(EXISTS ${CPACK_RPM_PRE_INSTALL_READ_FILE})
  574. file(READ ${CPACK_RPM_PRE_INSTALL_READ_FILE} CPACK_RPM_SPEC_PREINSTALL)
  575. else()
  576. message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_READ_FILE}> does not exists - ignoring")
  577. endif()
  578. else()
  579. # reset SPEC var value if no pre-install file has been specified
  580. # (either globally or component-wise)
  581. set(CPACK_RPM_SPEC_PREINSTALL "")
  582. endif()
  583. # Handle pre-uninstall file if it has been specified
  584. if(CPACK_RPM_PRE_UNINSTALL_READ_FILE)
  585. if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_READ_FILE})
  586. file(READ ${CPACK_RPM_PRE_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
  587. else()
  588. message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_READ_FILE}> does not exists - ignoring")
  589. endif()
  590. else()
  591. # reset SPEC var value if no pre-uninstall file has been specified
  592. # (either globally or component-wise)
  593. set(CPACK_RPM_SPEC_PREUNINSTALL "")
  594. endif()
  595. # CPACK_RPM_CHANGELOG_FILE
  596. # May be used to embed a changelog in the spec file.
  597. # The refered file will be read and directly put after the %changelog section
  598. if(CPACK_RPM_CHANGELOG_FILE)
  599. if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  600. file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
  601. else()
  602. message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
  603. endif()
  604. else()
  605. set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Erk <[email protected]>\n Generated by CPack RPM (no Changelog file were provided)")
  606. endif()
  607. # CPACK_RPM_SPEC_MORE_DEFINE
  608. # This is a generated spec rpm file spaceholder
  609. if(CPACK_RPM_SPEC_MORE_DEFINE)
  610. if(CPACK_RPM_PACKAGE_DEBUG)
  611. message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  612. endif()
  613. endif()
  614. # Now we may create the RPM build tree structure
  615. set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  616. message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  617. # Prepare RPM build tree
  618. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  619. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  620. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  621. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  622. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  623. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  624. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  625. #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  626. set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  627. # it seems rpmbuild can't handle spaces in the path
  628. # neither escaping (as below) nor putting quotes around the path seem to help
  629. #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  630. set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  631. # if we are creating a relocatable package, omit parent directories of
  632. # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
  633. # which is passed to the find command that generates the content-list
  634. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  635. # get a list of the elements in CPACK_RPM_PACKAGE_PREFIX and remove
  636. # the final element (so the install-prefix dir itself is not omitted
  637. # from the RPM's content-list)
  638. string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS ".${CPACK_RPM_PACKAGE_PREFIX}")
  639. list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
  640. # Now generate all of the parent dirs of CPACK_RPM_PACKAGE_PREFIX
  641. foreach(_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
  642. list(APPEND _TMP_LIST "${_ELEM}")
  643. string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
  644. set(_OMIT_DIR "-o -path ${_OMIT_DIR}")
  645. separate_arguments(_OMIT_DIR)
  646. list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
  647. endforeach()
  648. endif()
  649. if (CPACK_RPM_PACKAGE_DEBUG)
  650. message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  651. endif()
  652. if (NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  653. set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include)
  654. if (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
  655. message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
  656. list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
  657. endif()
  658. endif()
  659. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  660. if (CPACK_RPM_PACKAGE_DEBUG)
  661. message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
  662. endif()
  663. foreach(_DIR ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
  664. list(APPEND _RPM_DIRS_TO_OMIT "-o;-path;.${_DIR}")
  665. endforeach()
  666. endif()
  667. if (CPACK_RPM_PACKAGE_DEBUG)
  668. message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  669. endif()
  670. # Use files tree to construct files command (spec file)
  671. # We should not forget to include symlinks (thus -o -type l)
  672. # We should include directory as well (thus -type d)
  673. # but not the main local dir "." (thus -a -not -name ".")
  674. # We must remove the './' due to the local search and escape the
  675. # file name by enclosing it between double quotes (thus the sed)
  676. # Then we must authorize any man pages extension (adding * at the end)
  677. # because rpmbuild may automatically compress those files
  678. execute_process(COMMAND find . -type f -o -type l -o (-type d -a -not ( -name "." ${_RPM_DIRS_TO_OMIT} ) )
  679. COMMAND sed s:.*/man.*/.*:&*:
  680. COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/
  681. WORKING_DIRECTORY "${WDIR}"
  682. OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
  683. # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
  684. # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  685. # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
  686. # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
  687. if(CPACK_RPM_PACKAGE_COMPONENT)
  688. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  689. set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}")
  690. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
  691. if(CPACK_RPM_PACKAGE_DEBUG)
  692. message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
  693. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  694. endif()
  695. endif()
  696. else()
  697. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  698. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
  699. endif()
  700. endif()
  701. # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
  702. if(CPACK_RPM_PACKAGE_COMPONENT)
  703. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST)
  704. set(CPACK_RPM_USER_FILELIST_INTERNAL ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST})
  705. if(CPACK_RPM_PACKAGE_DEBUG)
  706. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  707. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  708. endif()
  709. else()
  710. set(CPACK_RPM_USER_FILELIST_INTERNAL "")
  711. endif()
  712. else()
  713. if(CPACK_RPM_USER_FILELIST)
  714. set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
  715. else()
  716. set(CPACK_RPM_USER_FILELIST_INTERNAL "")
  717. endif()
  718. endif()
  719. # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
  720. # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  721. # or CPACK_RPM_INSTALL_FILES,
  722. # hence it must be done before these auto-generated lists are processed.
  723. if(CPACK_RPM_USER_FILELIST_INTERNAL)
  724. if(CPACK_RPM_PACKAGE_DEBUG)
  725. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  726. endif()
  727. # Create CMake list from CPACK_RPM_INSTALL_FILES
  728. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  729. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
  730. "${CPACK_RPM_INSTALL_FILES_LIST}")
  731. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
  732. "${CPACK_RPM_INSTALL_FILES_LIST}")
  733. set(CPACK_RPM_USER_INSTALL_FILES "")
  734. foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
  735. string(REGEX REPLACE "%[A-Za-z0-9\(\),-]* " "" F_PATH ${F})
  736. string(REGEX MATCH "%[A-Za-z0-9\(\),-]*" F_PREFIX ${F})
  737. if(CPACK_RPM_PACKAGE_DEBUG)
  738. message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
  739. endif()
  740. if(F_PREFIX)
  741. set(F_PREFIX "${F_PREFIX} ")
  742. endif()
  743. # Rebuild the user list file
  744. set(CPACK_RPM_USER_INSTALL_FILES "${CPACK_RPM_USER_INSTALL_FILES}${F_PREFIX}\"${F_PATH}\"\n")
  745. # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  746. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
  747. # ABSOLUTE destination files list may not exists at all
  748. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  749. list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
  750. endif()
  751. endforeach()
  752. # Rebuild CPACK_RPM_INSTALL_FILES
  753. set(CPACK_RPM_INSTALL_FILES "")
  754. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  755. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
  756. endforeach()
  757. else()
  758. set(CPACK_RPM_USER_INSTALL_FILES "")
  759. endif()
  760. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  761. if(CPACK_RPM_PACKAGE_DEBUG)
  762. message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
  763. endif()
  764. # Remove trailing space
  765. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  766. # Transform endline separated - string into CMake List
  767. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  768. # Remove unecessary quotes
  769. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  770. # Remove ABSOLUTE install file from INSTALL FILE LIST
  771. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
  772. # Rebuild INSTALL_FILES
  773. set(CPACK_RPM_INSTALL_FILES "")
  774. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  775. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
  776. endforeach()
  777. # Build ABSOLUTE_INSTALL_FILES
  778. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  779. foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  780. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "${CPACK_RPM_ABSOLUTE_INSTALL_FILES}%config \"${F}\"\n")
  781. endforeach()
  782. if(CPACK_RPM_PACKAGE_DEBUG)
  783. message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
  784. message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
  785. endif()
  786. else()
  787. # reset vars in order to avoid leakage of value(s) from one component to another
  788. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  789. endif()
  790. # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
  791. # This is necessary to avoid duplicate files since rpmbuild do
  792. # recursion on its own when encountering a pathname which is a directory
  793. # which is not flagged as %dir
  794. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  795. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
  796. "${CPACK_RPM_INSTALL_FILES_LIST}")
  797. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
  798. "${CPACK_RPM_INSTALL_FILES_LIST}")
  799. set(CPACK_RPM_INSTALL_FILES "")
  800. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  801. if(IS_DIRECTORY "${WDIR}/${F}")
  802. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n")
  803. else()
  804. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
  805. endif()
  806. endforeach()
  807. set(CPACK_RPM_INSTALL_FILES_LIST "")
  808. # The name of the final spec file to be used by rpmbuild
  809. set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec")
  810. # Print out some debug information if we were asked for that
  811. if(CPACK_RPM_PACKAGE_DEBUG)
  812. message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  813. message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  814. message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  815. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  816. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  817. message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  818. message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  819. message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  820. message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  821. endif()
  822. #
  823. # USER generated/provided spec file handling.
  824. #
  825. # We can have a component specific spec file.
  826. if(CPACK_RPM_PACKAGE_COMPONENT AND CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE)
  827. set(CPACK_RPM_USER_BINARY_SPECFILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE})
  828. endif()
  829. # We should generate a USER spec file template:
  830. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  831. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  832. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  833. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  834. "# -*- rpm-spec -*-
  835. BuildRoot: \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
  836. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  837. Name: \@CPACK_RPM_PACKAGE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_NAME\@
  838. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  839. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  840. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  841. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  842. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  843. \@TMP_RPM_URL\@
  844. \@TMP_RPM_REQUIRES\@
  845. \@TMP_RPM_PROVIDES\@
  846. \@TMP_RPM_OBSOLETES\@
  847. \@TMP_RPM_CONFLICTS\@
  848. \@TMP_RPM_AUTOPROV\@
  849. \@TMP_RPM_AUTOREQ\@
  850. \@TMP_RPM_AUTOREQPROV\@
  851. \@TMP_RPM_BUILDARCH\@
  852. \@TMP_RPM_PREFIX\@
  853. %define _rpmdir \@CPACK_RPM_DIRECTORY\@
  854. %define _rpmfilename \@CPACK_RPM_FILE_NAME\@
  855. %define _unpackaged_files_terminate_build 0
  856. %define _topdir \@CPACK_RPM_DIRECTORY\@
  857. \@TMP_RPM_SPEC_INSTALL_POST\@
  858. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  859. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  860. %description
  861. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  862. # This is a shortcutted spec file generated by CMake RPM generator
  863. # we skip _install step because CPack does that for us.
  864. # We do only save CPack installed tree in _prepr
  865. # and then restore it in build.
  866. %prep
  867. mv $RPM_BUILD_ROOT \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\"
  868. #p build
  869. %install
  870. if [ -e $RPM_BUILD_ROOT ];
  871. then
  872. rm -rf $RPM_BUILD_ROOT
  873. fi
  874. mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
  875. %clean
  876. %post
  877. \@CPACK_RPM_SPEC_POSTINSTALL\@
  878. %postun
  879. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  880. %pre
  881. \@CPACK_RPM_SPEC_PREINSTALL\@
  882. %preun
  883. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  884. %files
  885. %defattr(-,root,root,-)
  886. \@CPACK_RPM_INSTALL_FILES\@
  887. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  888. \@CPACK_RPM_USER_INSTALL_FILES\@
  889. %changelog
  890. \@CPACK_RPM_SPEC_CHANGELOG\@
  891. ")
  892. # Stop here if we were asked to only generate a template USER spec file
  893. # The generated file may then be used as a template by user who wants
  894. # to customize their own spec file.
  895. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  896. message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  897. endif()
  898. endif()
  899. # After that we may either use a user provided spec file
  900. # or generate one using appropriate variables value.
  901. if(CPACK_RPM_USER_BINARY_SPECFILE)
  902. # User may have specified SPECFILE just use it
  903. message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  904. # The user provided file is processed for @var replacement
  905. configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  906. else()
  907. # No User specified spec file, will use the generated spec file
  908. message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  909. # Note the just created file is processed for @var replacement
  910. configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  911. endif()
  912. if(RPMBUILD_EXECUTABLE)
  913. # Now call rpmbuild using the SPECFILE
  914. execute_process(
  915. COMMAND "${RPMBUILD_EXECUTABLE}" -bb
  916. --define "_topdir ${CPACK_RPM_DIRECTORY}"
  917. --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  918. "${CPACK_RPM_BINARY_SPECFILE}"
  919. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  920. RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
  921. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err"
  922. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
  923. if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  924. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err RPMBUILDERR)
  925. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out RPMBUILDOUT)
  926. message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  927. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err")
  928. message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  929. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
  930. message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  931. endif()
  932. else()
  933. if(ALIEN_EXECUTABLE)
  934. message(FATAL_ERROR "RPM packaging through alien not done (yet)")
  935. endif()
  936. endif()