CPackRPM.cmake 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # CPackRPM
  5. # --------
  6. #
  7. # The built in (binary) CPack RPM generator (Unix only)
  8. #
  9. # Variables specific to CPack RPM generator
  10. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11. #
  12. # CPackRPM may be used to create RPM packages using :module:`CPack`.
  13. # CPackRPM is a :module:`CPack` generator thus it uses the ``CPACK_XXX``
  14. # variables used by :module:`CPack`.
  15. #
  16. # CPackRPM has specific features which are controlled by the specifics
  17. # :code:`CPACK_RPM_XXX` variables.
  18. #
  19. # :code:`CPACK_RPM_<COMPONENT>_XXXX` variables may be used in order to have
  20. # **component** specific values. Note however that ``<COMPONENT>`` refers to the
  21. # **grouping name** written in upper case. It may be either a component name or
  22. # a component GROUP name. Usually those variables correspond to RPM spec file
  23. # entities. One may find information about spec files here
  24. # http://www.rpm.org/wiki/Docs
  25. #
  26. # .. note::
  27. #
  28. # `<COMPONENT>` part of variables is preferred to be in upper case (for e.g. if
  29. # component is named `foo` then use `CPACK_RPM_FOO_XXXX` variable name format)
  30. # as is with other `CPACK_<COMPONENT>_XXXX` variables.
  31. # For the purposes of back compatibility (CMake/CPack version 3.5 and lower)
  32. # support for same cased component (e.g. `fOo` would be used as
  33. # `CPACK_RPM_fOo_XXXX`) is still supported for variables defined in older
  34. # versions of CMake/CPack but is not guaranteed for variables that
  35. # will be added in the future. For the sake of back compatibility same cased
  36. # component variables also override upper cased versions where both are
  37. # present.
  38. #
  39. # Here are some CPackRPM wiki resources that are here for historic reasons and
  40. # are no longer maintained but may still prove useful:
  41. #
  42. # - https://cmake.org/Wiki/CMake:CPackConfiguration
  43. # - https://cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29
  44. #
  45. # List of CPackRPM specific variables:
  46. #
  47. # .. variable:: CPACK_RPM_COMPONENT_INSTALL
  48. #
  49. # Enable component packaging for CPackRPM
  50. #
  51. # * Mandatory : NO
  52. # * Default : OFF
  53. #
  54. # If enabled (ON) multiple packages are generated. By default a single package
  55. # containing files of all components is generated.
  56. #
  57. # .. variable:: CPACK_RPM_PACKAGE_SUMMARY
  58. # CPACK_RPM_<component>_PACKAGE_SUMMARY
  59. #
  60. # The RPM package summary.
  61. #
  62. # * Mandatory : YES
  63. # * Default : :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
  64. #
  65. # .. variable:: CPACK_RPM_PACKAGE_NAME
  66. # CPACK_RPM_<component>_PACKAGE_NAME
  67. #
  68. # The RPM package name.
  69. #
  70. # * Mandatory : YES
  71. # * Default : :variable:`CPACK_PACKAGE_NAME`
  72. #
  73. # .. variable:: CPACK_RPM_FILE_NAME
  74. # CPACK_RPM_<component>_FILE_NAME
  75. #
  76. # Package file name.
  77. #
  78. # * Mandatory : YES
  79. # * Default : ``<CPACK_PACKAGE_FILE_NAME>[-<component>].rpm`` with spaces
  80. # replaced by '-'
  81. #
  82. # This may be set to ``RPM-DEFAULT`` to allow rpmbuild tool to generate package
  83. # file name by itself.
  84. # Alternatively provided package file name must end with ``.rpm`` suffix.
  85. #
  86. # .. note::
  87. #
  88. # By using user provided spec file, rpm macro extensions such as for
  89. # generating debuginfo packages or by simply using multiple components more
  90. # than one rpm file may be generated, either from a single spec file or from
  91. # multiple spec files (each component execution produces it's own spec file).
  92. # In such cases duplicate file names may occur as a result of this variable
  93. # setting or spec file content structure. Duplicate files get overwritten
  94. # and it is up to the packager to set the variables in a manner that will
  95. # prevent such errors.
  96. #
  97. # .. variable:: CPACK_RPM_MAIN_COMPONENT
  98. #
  99. # Main component that is packaged without component suffix.
  100. #
  101. # * Mandatory : NO
  102. # * Default : -
  103. #
  104. # This variable can be set to any component or group name so that component or
  105. # group rpm package is generated without component suffix in filename and
  106. # package name.
  107. #
  108. # .. variable:: CPACK_RPM_PACKAGE_VERSION
  109. #
  110. # The RPM package version.
  111. #
  112. # * Mandatory : YES
  113. # * Default : :variable:`CPACK_PACKAGE_VERSION`
  114. #
  115. # .. variable:: CPACK_RPM_PACKAGE_ARCHITECTURE
  116. # CPACK_RPM_<component>_PACKAGE_ARCHITECTURE
  117. #
  118. # The RPM package architecture.
  119. #
  120. # * Mandatory : YES
  121. # * Default : Native architecture output by ``uname -m``
  122. #
  123. # This may be set to ``noarch`` if you know you are building a noarch package.
  124. #
  125. # .. variable:: CPACK_RPM_PACKAGE_RELEASE
  126. #
  127. # The RPM package release.
  128. #
  129. # * Mandatory : YES
  130. # * Default : 1
  131. #
  132. # This is the numbering of the RPM package itself, i.e. the version of the
  133. # packaging and not the version of the content (see
  134. # :variable:`CPACK_RPM_PACKAGE_VERSION`). One may change the default value if
  135. # the previous packaging was buggy and/or you want to put here a fancy Linux
  136. # distro specific numbering.
  137. #
  138. # .. note::
  139. #
  140. # This is the string that goes into the RPM ``Release:`` field. Some distros
  141. # (e.g. Fedora, CentOS) require ``1%{?dist}`` format and not just a number.
  142. # ``%{?dist}`` part can be added by setting :variable:`CPACK_RPM_PACKAGE_RELEASE_DIST`.
  143. #
  144. # .. variable:: CPACK_RPM_PACKAGE_RELEASE_DIST
  145. #
  146. # The dist tag that is added RPM ``Release:`` field.
  147. #
  148. # * Mandatory : NO
  149. # * Default : OFF
  150. #
  151. # This is the reported ``%{dist}`` tag from the current distribution or empty
  152. # ``%{dist}`` if RPM macro is not set. If this variable is set then RPM
  153. # ``Release:`` field value is set to ``${CPACK_RPM_PACKAGE_RELEASE}%{?dist}``.
  154. #
  155. # .. variable:: CPACK_RPM_PACKAGE_LICENSE
  156. #
  157. # The RPM package license policy.
  158. #
  159. # * Mandatory : YES
  160. # * Default : "unknown"
  161. #
  162. # .. variable:: CPACK_RPM_PACKAGE_GROUP
  163. # CPACK_RPM_<component>_PACKAGE_GROUP
  164. #
  165. # The RPM package group.
  166. #
  167. # * Mandatory : YES
  168. # * Default : "unknown"
  169. #
  170. # .. variable:: CPACK_RPM_PACKAGE_VENDOR
  171. #
  172. # The RPM package vendor.
  173. #
  174. # * Mandatory : YES
  175. # * Default : CPACK_PACKAGE_VENDOR if set or "unknown"
  176. #
  177. # .. variable:: CPACK_RPM_PACKAGE_URL
  178. # CPACK_RPM_<component>_PACKAGE_URL
  179. #
  180. # The projects URL.
  181. #
  182. # * Mandatory : NO
  183. # * Default : -
  184. #
  185. # .. variable:: CPACK_RPM_PACKAGE_DESCRIPTION
  186. # CPACK_RPM_<component>_PACKAGE_DESCRIPTION
  187. #
  188. # RPM package description.
  189. #
  190. # * Mandatory : YES
  191. # * Default : :variable:`CPACK_COMPONENT_<compName>_DESCRIPTION` (component
  192. # based installers only) if set, :variable:`CPACK_PACKAGE_DESCRIPTION_FILE`
  193. # if set or "no package description available"
  194. #
  195. # .. variable:: CPACK_RPM_COMPRESSION_TYPE
  196. #
  197. # RPM compression type.
  198. #
  199. # * Mandatory : NO
  200. # * Default : -
  201. #
  202. # May be used to override RPM compression type to be used to build the
  203. # RPM. For example some Linux distribution now default to lzma or xz
  204. # compression whereas older cannot use such RPM. Using this one can enforce
  205. # compression type to be used.
  206. #
  207. # Possible values are:
  208. #
  209. # - lzma
  210. # - xz
  211. # - bzip2
  212. # - gzip
  213. #
  214. # .. variable:: CPACK_RPM_PACKAGE_AUTOREQ
  215. # CPACK_RPM_<component>_PACKAGE_AUTOREQ
  216. #
  217. # RPM spec autoreq field.
  218. #
  219. # * Mandatory : NO
  220. # * Default : -
  221. #
  222. # May be used to enable (1, yes) or disable (0, no) automatic shared libraries
  223. # dependency detection. Dependencies are added to requires list.
  224. #
  225. # .. note::
  226. #
  227. # By default automatic dependency detection is enabled by rpm generator.
  228. #
  229. # .. variable:: CPACK_RPM_PACKAGE_AUTOPROV
  230. # CPACK_RPM_<component>_PACKAGE_AUTOPROV
  231. #
  232. # RPM spec autoprov field.
  233. #
  234. # * Mandatory : NO
  235. # * Default : -
  236. #
  237. # May be used to enable (1, yes) or disable (0, no) automatic listing of shared
  238. # libraries that are provided by the package. Shared libraries are added to
  239. # provides list.
  240. #
  241. # .. note::
  242. #
  243. # By default automatic provides detection is enabled by rpm generator.
  244. #
  245. # .. variable:: CPACK_RPM_PACKAGE_AUTOREQPROV
  246. # CPACK_RPM_<component>_PACKAGE_AUTOREQPROV
  247. #
  248. # RPM spec autoreqprov field.
  249. #
  250. # * Mandatory : NO
  251. # * Default : -
  252. #
  253. # Variable enables/disables autoreq and autoprov at the same time.
  254. # See :variable:`CPACK_RPM_PACKAGE_AUTOREQ` and :variable:`CPACK_RPM_PACKAGE_AUTOPROV`
  255. # for more details.
  256. #
  257. # .. note::
  258. #
  259. # By default automatic detection feature is enabled by rpm.
  260. #
  261. # .. variable:: CPACK_RPM_PACKAGE_REQUIRES
  262. # CPACK_RPM_<component>_PACKAGE_REQUIRES
  263. #
  264. # RPM spec requires field.
  265. #
  266. # * Mandatory : NO
  267. # * Default : -
  268. #
  269. # May be used to set RPM dependencies (requires). Note that you must enclose
  270. # the complete requires string between quotes, for example::
  271. #
  272. # set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")
  273. #
  274. # The required package list of an RPM file could be printed with::
  275. #
  276. # rpm -qp --requires file.rpm
  277. #
  278. # .. variable:: CPACK_RPM_PACKAGE_CONFLICTS
  279. # CPACK_RPM_<component>_PACKAGE_CONFLICTS
  280. #
  281. # RPM spec conflicts field.
  282. #
  283. # * Mandatory : NO
  284. # * Default : -
  285. #
  286. # May be used to set negative RPM dependencies (conflicts). Note that you must
  287. # enclose the complete requires string between quotes, for example::
  288. #
  289. # set(CPACK_RPM_PACKAGE_CONFLICTS "libxml2")
  290. #
  291. # The conflicting package list of an RPM file could be printed with::
  292. #
  293. # rpm -qp --conflicts file.rpm
  294. #
  295. # .. variable:: CPACK_RPM_PACKAGE_REQUIRES_PRE
  296. # CPACK_RPM_<component>_PACKAGE_REQUIRES_PRE
  297. #
  298. # RPM spec requires(pre) field.
  299. #
  300. # * Mandatory : NO
  301. # * Default : -
  302. #
  303. # May be used to set RPM preinstall dependencies (requires(pre)). Note that
  304. # you must enclose the complete requires string between quotes, for example::
  305. #
  306. # set(CPACK_RPM_PACKAGE_REQUIRES_PRE "shadow-utils, initscripts")
  307. #
  308. # .. variable:: CPACK_RPM_PACKAGE_REQUIRES_POST
  309. # CPACK_RPM_<component>_PACKAGE_REQUIRES_POST
  310. #
  311. # RPM spec requires(post) field.
  312. #
  313. # * Mandatory : NO
  314. # * Default : -
  315. #
  316. # May be used to set RPM postinstall dependencies (requires(post)). Note that
  317. # you must enclose the complete requires string between quotes, for example::
  318. #
  319. # set(CPACK_RPM_PACKAGE_REQUIRES_POST "shadow-utils, initscripts")
  320. #
  321. # .. variable:: CPACK_RPM_PACKAGE_REQUIRES_POSTUN
  322. # CPACK_RPM_<component>_PACKAGE_REQUIRES_POSTUN
  323. #
  324. # RPM spec requires(postun) field.
  325. #
  326. # * Mandatory : NO
  327. # * Default : -
  328. #
  329. # May be used to set RPM postuninstall dependencies (requires(postun)). Note
  330. # that you must enclose the complete requires string between quotes, for
  331. # example::
  332. #
  333. # set(CPACK_RPM_PACKAGE_REQUIRES_POSTUN "shadow-utils, initscripts")
  334. #
  335. # .. variable:: CPACK_RPM_PACKAGE_REQUIRES_PREUN
  336. # CPACK_RPM_<component>_PACKAGE_REQUIRES_PREUN
  337. #
  338. # RPM spec requires(preun) field.
  339. #
  340. # * Mandatory : NO
  341. # * Default : -
  342. #
  343. # May be used to set RPM preuninstall dependencies (requires(preun)). Note that
  344. # you must enclose the complete requires string between quotes, for example::
  345. #
  346. # set(CPACK_RPM_PACKAGE_REQUIRES_PREUN "shadow-utils, initscripts")
  347. #
  348. # .. variable:: CPACK_RPM_PACKAGE_SUGGESTS
  349. # CPACK_RPM_<component>_PACKAGE_SUGGESTS
  350. #
  351. # RPM spec suggest field.
  352. #
  353. # * Mandatory : NO
  354. # * Default : -
  355. #
  356. # May be used to set weak RPM dependencies (suggests). Note that you must
  357. # enclose the complete requires string between quotes.
  358. #
  359. # .. variable:: CPACK_RPM_PACKAGE_PROVIDES
  360. # CPACK_RPM_<component>_PACKAGE_PROVIDES
  361. #
  362. # RPM spec provides field.
  363. #
  364. # * Mandatory : NO
  365. # * Default : -
  366. #
  367. # May be used to set RPM dependencies (provides). The provided package list
  368. # of an RPM file could be printed with::
  369. #
  370. # rpm -qp --provides file.rpm
  371. #
  372. # .. variable:: CPACK_RPM_PACKAGE_OBSOLETES
  373. # CPACK_RPM_<component>_PACKAGE_OBSOLETES
  374. #
  375. # RPM spec obsoletes field.
  376. #
  377. # * Mandatory : NO
  378. # * Default : -
  379. #
  380. # May be used to set RPM packages that are obsoleted by this one.
  381. #
  382. # .. variable:: CPACK_RPM_PACKAGE_RELOCATABLE
  383. #
  384. # build a relocatable RPM.
  385. #
  386. # * Mandatory : NO
  387. # * Default : CPACK_PACKAGE_RELOCATABLE
  388. #
  389. # If this variable is set to TRUE or ON CPackRPM will try
  390. # to build a relocatable RPM package. A relocatable RPM may
  391. # be installed using::
  392. #
  393. # rpm --prefix or --relocate
  394. #
  395. # in order to install it at an alternate place see rpm(8). Note that
  396. # currently this may fail if :variable:`CPACK_SET_DESTDIR` is set to ``ON``. If
  397. # :variable:`CPACK_SET_DESTDIR` is set then you will get a warning message but
  398. # if there is file installed with absolute path you'll get unexpected behavior.
  399. #
  400. # .. variable:: CPACK_RPM_SPEC_INSTALL_POST
  401. #
  402. # Deprecated - use :variable:`CPACK_RPM_POST_INSTALL_SCRIPT_FILE` instead.
  403. #
  404. # * Mandatory : NO
  405. # * Default : -
  406. # * Deprecated: YES
  407. #
  408. # This way of specifying post-install script is deprecated, use
  409. # :variable:`CPACK_RPM_POST_INSTALL_SCRIPT_FILE`.
  410. # May be used to set an RPM post-install command inside the spec file.
  411. # For example setting it to ``/bin/true`` may be used to prevent
  412. # rpmbuild to strip binaries.
  413. #
  414. # .. variable:: CPACK_RPM_SPEC_MORE_DEFINE
  415. #
  416. # RPM extended spec definitions lines.
  417. #
  418. # * Mandatory : NO
  419. # * Default : -
  420. #
  421. # May be used to add any ``%define`` lines to the generated spec file.
  422. #
  423. # .. variable:: CPACK_RPM_PACKAGE_DEBUG
  424. #
  425. # Toggle CPackRPM debug output.
  426. #
  427. # * Mandatory : NO
  428. # * Default : -
  429. #
  430. # May be set when invoking cpack in order to trace debug information
  431. # during CPack RPM run. For example you may launch CPack like this::
  432. #
  433. # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
  434. #
  435. # .. variable:: CPACK_RPM_USER_BINARY_SPECFILE
  436. # CPACK_RPM_<componentName>_USER_BINARY_SPECFILE
  437. #
  438. # A user provided spec file.
  439. #
  440. # * Mandatory : NO
  441. # * Default : -
  442. #
  443. # May be set by the user in order to specify a USER binary spec file
  444. # to be used by CPackRPM instead of generating the file.
  445. # The specified file will be processed by configure_file( @ONLY).
  446. #
  447. # .. variable:: CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  448. #
  449. # Spec file template.
  450. #
  451. # * Mandatory : NO
  452. # * Default : -
  453. #
  454. # If set CPack will generate a template for USER specified binary
  455. # spec file and stop with an error. For example launch CPack like this::
  456. #
  457. # cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
  458. #
  459. # The user may then use this file in order to hand-craft is own
  460. # binary spec file which may be used with
  461. # :variable:`CPACK_RPM_USER_BINARY_SPECFILE`.
  462. #
  463. # .. variable:: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
  464. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
  465. #
  466. # Path to file containing pre (un)install script.
  467. #
  468. # * Mandatory : NO
  469. # * Default : -
  470. #
  471. # May be used to embed a pre (un)installation script in the spec file.
  472. # The referred script file (or both) will be read and directly
  473. # put after the ``%pre`` or ``%preun`` section
  474. # If :variable:`CPACK_RPM_COMPONENT_INSTALL` is set to ON the (un)install
  475. # script for each component can be overridden with
  476. # ``CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE`` and
  477. # ``CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE``.
  478. # One may verify which scriptlet has been included with::
  479. #
  480. # rpm -qp --scripts package.rpm
  481. #
  482. # .. variable:: CPACK_RPM_POST_INSTALL_SCRIPT_FILE
  483. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
  484. #
  485. # Path to file containing post (un)install script.
  486. #
  487. # * Mandatory : NO
  488. # * Default : -
  489. #
  490. # May be used to embed a post (un)installation script in the spec file.
  491. # The referred script file (or both) will be read and directly
  492. # put after the ``%post`` or ``%postun`` section.
  493. # If :variable:`CPACK_RPM_COMPONENT_INSTALL` is set to ON the (un)install
  494. # script for each component can be overridden with
  495. # ``CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE`` and
  496. # ``CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE``.
  497. # One may verify which scriptlet has been included with::
  498. #
  499. # rpm -qp --scripts package.rpm
  500. #
  501. # .. variable:: CPACK_RPM_USER_FILELIST
  502. # CPACK_RPM_<COMPONENT>_USER_FILELIST
  503. #
  504. # * Mandatory : NO
  505. # * Default : -
  506. #
  507. # May be used to explicitly specify ``%(<directive>)`` file line
  508. # in the spec file. Like ``%config(noreplace)`` or any other directive
  509. # that be found in the ``%files`` section. You can have multiple directives
  510. # per line, as in ``%attr(600,root,root) %config(noreplace)``. Since
  511. # CPackRPM is generating the list of files (and directories) the user
  512. # specified files of the ``CPACK_RPM_<COMPONENT>_USER_FILELIST`` list will
  513. # be removed from the generated list. If referring to directories do
  514. # not add a trailing slash.
  515. #
  516. # .. variable:: CPACK_RPM_CHANGELOG_FILE
  517. #
  518. # RPM changelog file.
  519. #
  520. # * Mandatory : NO
  521. # * Default : -
  522. #
  523. # May be used to embed a changelog in the spec file.
  524. # The referred file will be read and directly put after the ``%changelog``
  525. # section.
  526. #
  527. # .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
  528. #
  529. # list of path to be excluded.
  530. #
  531. # * Mandatory : NO
  532. # * Default : /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include
  533. #
  534. # May be used to exclude path (directories or files) from the auto-generated
  535. # list of paths discovered by CPack RPM. The defaut value contains a
  536. # reasonable set of values if the variable is not defined by the user. If the
  537. # variable is defined by the user then CPackRPM will NOT any of the default
  538. # path. If you want to add some path to the default list then you can use
  539. # :variable:`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION` variable.
  540. #
  541. # .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
  542. #
  543. # additional list of path to be excluded.
  544. #
  545. # * Mandatory : NO
  546. # * Default : -
  547. #
  548. # May be used to add more exclude path (directories or files) from the initial
  549. # default list of excluded paths. See
  550. # :variable:`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST`.
  551. #
  552. # .. variable:: CPACK_RPM_RELOCATION_PATHS
  553. #
  554. # Packages relocation paths list.
  555. #
  556. # * Mandatory : NO
  557. # * Default : -
  558. #
  559. # May be used to specify more than one relocation path per relocatable RPM.
  560. # Variable contains a list of relocation paths that if relative are prefixed
  561. # by the value of :variable:`CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX` or by the
  562. # value of :variable:`CPACK_PACKAGING_INSTALL_PREFIX` if the component version
  563. # is not provided.
  564. # Variable is not component based as its content can be used to set a different
  565. # path prefix for e.g. binary dir and documentation dir at the same time.
  566. # Only prefixes that are required by a certain component are added to that
  567. # component - component must contain at least one file/directory/symbolic link
  568. # with :variable:`CPACK_RPM_RELOCATION_PATHS` prefix for a certain relocation
  569. # path to be added. Package will not contain any relocation paths if there are
  570. # no files/directories/symbolic links on any of the provided prefix locations.
  571. # Packages that either do not contain any relocation paths or contain
  572. # files/directories/symbolic links that are outside relocation paths print
  573. # out an ``AUTHOR_WARNING`` that RPM will be partially relocatable.
  574. #
  575. # .. variable:: CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX
  576. #
  577. # Per component relocation path install prefix.
  578. #
  579. # * Mandatory : NO
  580. # * Default : CPACK_PACKAGING_INSTALL_PREFIX
  581. #
  582. # May be used to set per component :variable:`CPACK_PACKAGING_INSTALL_PREFIX`
  583. # for relocatable RPM packages.
  584. #
  585. # .. variable:: CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION
  586. # CPACK_RPM_NO_<COMPONENT>_INSTALL_PREFIX_RELOCATION
  587. #
  588. # Removal of default install prefix from relocation paths list.
  589. #
  590. # * Mandatory : NO
  591. # * Default : CPACK_PACKAGING_INSTALL_PREFIX or CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX
  592. # are treated as one of relocation paths
  593. #
  594. # May be used to remove CPACK_PACKAGING_INSTALL_PREFIX and CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX
  595. # from relocatable RPM prefix paths.
  596. #
  597. # .. variable:: CPACK_RPM_ADDITIONAL_MAN_DIRS
  598. #
  599. # * Mandatory : NO
  600. # * Default : -
  601. #
  602. # May be used to set additional man dirs that could potentially be compressed
  603. # by brp-compress RPM macro. Variable content must be a list of regular
  604. # expressions that point to directories containing man files or to man files
  605. # directly. Note that in order to compress man pages a path must also be
  606. # present in brp-compress RPM script and that brp-compress script must be
  607. # added to RPM configuration by the operating system.
  608. #
  609. # Regular expressions that are added by default were taken from brp-compress
  610. # RPM macro:
  611. #
  612. # - /usr/man/man.*
  613. # - /usr/man/.*/man.*
  614. # - /usr/info.*
  615. # - /usr/share/man/man.*
  616. # - /usr/share/man/.*/man.*
  617. # - /usr/share/info.*
  618. # - /usr/kerberos/man.*
  619. # - /usr/X11R6/man/man.*
  620. # - /usr/lib/perl5/man/man.*
  621. # - /usr/share/doc/.*/man/man.*
  622. # - /usr/lib/.*/man/man.*
  623. #
  624. # .. variable:: CPACK_RPM_DEFAULT_USER
  625. # CPACK_RPM_<compName>_DEFAULT_USER
  626. #
  627. # default user ownership of RPM content
  628. #
  629. # * Mandatory : NO
  630. # * Default : root
  631. #
  632. # Value should be user name and not UID.
  633. # Note that <compName> must be in upper-case.
  634. #
  635. # .. variable:: CPACK_RPM_DEFAULT_GROUP
  636. # CPACK_RPM_<compName>_DEFAULT_GROUP
  637. #
  638. # default group ownership of RPM content
  639. #
  640. # * Mandatory : NO
  641. # * Default : root
  642. #
  643. # Value should be group name and not GID.
  644. # Note that <compName> must be in upper-case.
  645. #
  646. # .. variable:: CPACK_RPM_DEFAULT_FILE_PERMISSIONS
  647. # CPACK_RPM_<compName>_DEFAULT_FILE_PERMISSIONS
  648. #
  649. # default permissions used for packaged files
  650. #
  651. # * Mandatory : NO
  652. # * Default : - (system default)
  653. #
  654. # Accepted values are lists with ``PERMISSIONS``. Valid permissions
  655. # are:
  656. #
  657. # - OWNER_READ
  658. # - OWNER_WRITE
  659. # - OWNER_EXECUTE
  660. # - GROUP_READ
  661. # - GROUP_WRITE
  662. # - GROUP_EXECUTE
  663. # - WORLD_READ
  664. # - WORLD_WRITE
  665. # - WORLD_EXECUTE
  666. #
  667. # Note that <compName> must be in upper-case.
  668. #
  669. # .. variable:: CPACK_RPM_DEFAULT_DIR_PERMISSIONS
  670. # CPACK_RPM_<compName>_DEFAULT_DIR_PERMISSIONS
  671. #
  672. # default permissions used for packaged directories
  673. #
  674. # * Mandatory : NO
  675. # * Default : - (system default)
  676. #
  677. # Accepted values are lists with PERMISSIONS. Valid permissions
  678. # are the same as for :variable:`CPACK_RPM_DEFAULT_FILE_PERMISSIONS`.
  679. # Note that <compName> must be in upper-case.
  680. #
  681. # Packaging of Symbolic Links
  682. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  683. #
  684. # CPackRPM supports packaging of symbolic links::
  685. #
  686. # execute_process(COMMAND ${CMAKE_COMMAND}
  687. # -E create_symlink <relative_path_location> <symlink_name>)
  688. # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<symlink_name>
  689. # DESTINATION <symlink_location> COMPONENT libraries)
  690. #
  691. # Symbolic links will be optimized (paths will be shortened if possible)
  692. # before being added to the package or if multiple relocation paths are
  693. # detected, a post install symlink relocation script will be generated.
  694. #
  695. # Symbolic links may point to locations that are not packaged by the same
  696. # package (either a different component or even not packaged at all) but
  697. # those locations will be treated as if they were a part of the package
  698. # while determining if symlink should be either created or present in a
  699. # post install script - depending on relocation paths.
  700. #
  701. # Symbolic links that point to locations outside packaging path produce a
  702. # warning and are treated as non relocatable permanent symbolic links.
  703. #
  704. # Currently there are a few limitations though:
  705. #
  706. # * For component based packaging component interdependency is not checked
  707. # when processing symbolic links. Symbolic links pointing to content of
  708. # a different component are treated the same way as if pointing to location
  709. # that will not be packaged.
  710. #
  711. # * Symbolic links pointing to a location through one or more intermediate
  712. # symbolic links will not be handled differently - if the intermediate
  713. # symbolic link(s) is also on a relocatable path, relocating it during
  714. # package installation may cause initial symbolic link to point to an
  715. # invalid location.
  716. #
  717. # Packaging of debug information
  718. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  719. #
  720. # Debuginfo packages contain debug symbols and sources for debugging packaged
  721. # binaries.
  722. #
  723. # Debuginfo RPM packaging has it's own set of variables:
  724. #
  725. # .. variable:: CPACK_RPM_DEBUGINFO_PACKAGE
  726. # CPACK_RPM_<component>_DEBUGINFO_PACKAGE
  727. #
  728. # Enable generation of debuginfo RPM package(s).
  729. #
  730. # * Mandatory : NO
  731. # * Default : OFF
  732. #
  733. # .. note::
  734. #
  735. # Binaries must contain debug symbols before packaging so use either ``Debug``
  736. # or ``RelWithDebInfo`` for :variable:`CMAKE_BUILD_TYPE` variable value.
  737. #
  738. # .. note::
  739. #
  740. # Packages generated from packages without binary files, with binary files but
  741. # without execute permissions or without debug symbols will be empty.
  742. #
  743. # .. variable:: CPACK_BUILD_SOURCE_DIRS
  744. #
  745. # Provides locations of root directories of source files from which binaries
  746. # were built.
  747. #
  748. # * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set
  749. # * Default : -
  750. #
  751. # .. note::
  752. #
  753. # For CMake project :variable:`CPACK_BUILD_SOURCE_DIRS` is set by default to
  754. # point to :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR` paths.
  755. #
  756. # .. note::
  757. #
  758. # Sources with path prefixes that do not fall under any location provided with
  759. # :variable:`CPACK_BUILD_SOURCE_DIRS` will not be present in debuginfo package.
  760. #
  761. # .. variable:: CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX
  762. # CPACK_RPM_<component>_BUILD_SOURCE_DIRS_PREFIX
  763. #
  764. # Prefix of location where sources will be placed during package installation.
  765. #
  766. # * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set
  767. # * Default : "/usr/src/debug/<CPACK_PACKAGE_FILE_NAME>" and
  768. # for component packaging "/usr/src/debug/<CPACK_PACKAGE_FILE_NAME>-<component>"
  769. #
  770. # .. note::
  771. #
  772. # Each source path prefix is additionaly suffixed by ``src_<index>`` where
  773. # index is index of the path used from :variable:`CPACK_BUILD_SOURCE_DIRS`
  774. # variable. This produces ``<CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX>/src_<index>``
  775. # replacement path.
  776. # Limitation is that replaced path part must be shorter or of equal
  777. # length than the length of its replacement. If that is not the case either
  778. # :variable:`CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX` variable has to be set to
  779. # a shorter path or source directories must be placed on a longer path.
  780. #
  781. # .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS
  782. #
  783. # Directories containing sources that should be excluded from debuginfo packages.
  784. #
  785. # * Mandatory : NO
  786. # * Default : "/usr /usr/src /usr/src/debug"
  787. #
  788. # Listed paths are owned by other RPM packages and should therefore not be
  789. # deleted on debuginfo package uninstallation.
  790. #
  791. # .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION
  792. #
  793. # Paths that should be appended to :variable:`CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS`
  794. # for exclusion.
  795. #
  796. # * Mandatory : NO
  797. # * Default : -
  798. #
  799. # .. variable:: CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE
  800. #
  801. # Create a single debuginfo package even if components packaging is set.
  802. #
  803. # * Mandatory : NO
  804. # * Default : OFF
  805. #
  806. # When this variable is enabled it produces a single debuginfo package even if
  807. # component packaging is enabled.
  808. #
  809. # When using this feature in combination with components packaging and there is
  810. # more than one component this variable requires :variable:`CPACK_RPM_MAIN_COMPONENT`
  811. # to be set.
  812. #
  813. # .. note::
  814. #
  815. # If none of the :variable:`CPACK_RPM_<component>_DEBUGINFO_PACKAGE` variables
  816. # is set then :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is automatically set to
  817. # ``ON`` when :variable:`CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE` is set.
  818. #
  819. # Packaging of sources (SRPM)
  820. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  821. #
  822. # SRPM packaging is enabled by setting :variable:`CPACK_RPM_PACKAGE_SOURCES`
  823. # variable while usually using :variable:`CPACK_INSTALLED_DIRECTORIES` variable
  824. # to provide directory containing CMakeLists.txt and source files.
  825. #
  826. # For CMake projects SRPM package would be product by executing:
  827. #
  828. # ``cpack -G RPM --config ./CPackSourceConfig.cmake``
  829. #
  830. # .. note::
  831. #
  832. # Produced SRPM package is expected to be built with :manual:`cmake(1)` executable
  833. # and packaged with :manual:`cpack(1)` executable so CMakeLists.txt has to be
  834. # located in root source directory and must be able to generate binary rpm
  835. # packages by executing ``cpack -G`` command. The two executables as well as
  836. # rpmbuild must also be present when generating binary rpm packages from the
  837. # produced SRPM package.
  838. #
  839. # Once the SRPM package is generated it can be used to generate binary packages
  840. # by creating a directory structure for rpm generation and executing rpmbuild
  841. # tool:
  842. #
  843. # ``mkdir -p build_dir/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}``
  844. # ``rpmbuild --define "_topdir <path_to_build_dir>" --rebuild <SRPM_file_name>``
  845. #
  846. # Generated packages will be located in build_dir/RPMS directory or its sub
  847. # directories.
  848. #
  849. # .. note::
  850. #
  851. # SRPM package internally uses CPack/RPM generator to generate binary packages
  852. # so CMakeScripts.txt can decide during the SRPM to binary rpm generation step
  853. # what content the package(s) should have as well as how they should be packaged
  854. # (monolithic or components). CMake can decide this for e.g. by reading environment
  855. # variables set by the package manager before starting the process of generating
  856. # binary rpm packages. This way a single SRPM package can be used to produce
  857. # different binary rpm packages on different platforms depending on the platform's
  858. # packaging rules.
  859. #
  860. # Source RPM packaging has it's own set of variables:
  861. #
  862. # .. variable:: CPACK_RPM_PACKAGE_SOURCES
  863. #
  864. # Should the content be packaged as a source rpm (default is binary rpm).
  865. #
  866. # * Mandatory : NO
  867. # * Default : OFF
  868. #
  869. # .. note::
  870. #
  871. # For cmake projects :variable:`CPACK_RPM_PACKAGE_SOURCES` variable is set
  872. # to ``OFF`` in CPackConfig.cmake and ``ON`` in CPackSourceConfig.cmake
  873. # generated files.
  874. #
  875. # .. variable:: CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
  876. #
  877. # Additional command-line parameters provided to :manual:`cmake(1)` executable.
  878. #
  879. # * Mandatory : NO
  880. # * Default : -
  881. #
  882. # .. variable:: CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX
  883. #
  884. # Packaging install prefix that would be provided in :variable:`CPACK_PACKAGING_INSTALL_PREFIX`
  885. # variable for producing binary RPM packages.
  886. #
  887. # * Mandatory : YES
  888. # * Default : "/"
  889. # Author: Eric Noulard with the help of Alexander Neundorf.
  890. function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR)
  891. set(PERMISSIONS ${${PERMISSIONS_VAR}})
  892. list(LENGTH PERMISSIONS PERM_LEN_PRE)
  893. list(REMOVE_DUPLICATES PERMISSIONS)
  894. list(LENGTH PERMISSIONS PERM_LEN_POST)
  895. if(NOT ${PERM_LEN_PRE} EQUAL ${PERM_LEN_POST})
  896. message(FATAL_ERROR "${PERMISSIONS_VAR} contains duplicate values.")
  897. endif()
  898. foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD")
  899. set(${PERMISSION_TYPE}_PERMISSIONS 0)
  900. foreach(PERMISSION ${PERMISSIONS})
  901. if("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_READ")
  902. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 4")
  903. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_WRITE")
  904. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 2")
  905. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_EXECUTE")
  906. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 1")
  907. elseif(PERMISSION MATCHES "${PERMISSION_TYPE}.*")
  908. message(FATAL_ERROR "${PERMISSIONS_VAR} contains invalid values.")
  909. endif()
  910. endforeach()
  911. endforeach()
  912. set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE)
  913. endfunction()
  914. function(cpack_rpm_prepare_relocation_paths)
  915. # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes
  916. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX)
  917. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX}" PATH_PREFIX)
  918. elseif(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX)
  919. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX}" PATH_PREFIX)
  920. else()
  921. file(TO_CMAKE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}" PATH_PREFIX)
  922. endif()
  923. set(RPM_RELOCATION_PATHS "${CPACK_RPM_RELOCATION_PATHS}")
  924. list(REMOVE_DUPLICATES RPM_RELOCATION_PATHS)
  925. # set base path prefix
  926. if(EXISTS "${WDIR}/${PATH_PREFIX}")
  927. if(NOT CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION AND
  928. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT}_INSTALL_PREFIX_RELOCATION AND
  929. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_INSTALL_PREFIX_RELOCATION)
  930. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PATH_PREFIX}\n")
  931. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PATH_PREFIX}")
  932. if(CPACK_RPM_PACKAGE_DEBUG)
  933. message("CPackRPM:Debug: removing '${PATH_PREFIX}' from relocation paths")
  934. endif()
  935. endif()
  936. endif()
  937. # set other path prefixes
  938. foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS})
  939. if(IS_ABSOLUTE "${RELOCATION_PATH}")
  940. set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}")
  941. else()
  942. set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}")
  943. endif()
  944. if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}")
  945. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n")
  946. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}")
  947. endif()
  948. endforeach()
  949. # warn about all the paths that are not relocatable
  950. cmake_policy(PUSH)
  951. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  952. # even if the project does not set this policy to NEW.
  953. cmake_policy(SET CMP0009 NEW)
  954. file(GLOB_RECURSE FILE_PATHS_ "${WDIR}/*")
  955. cmake_policy(POP)
  956. foreach(TMP_PATH ${FILE_PATHS_})
  957. string(LENGTH "${WDIR}" WDIR_LEN)
  958. string(SUBSTRING "${TMP_PATH}" ${WDIR_LEN} -1 TMP_PATH)
  959. unset(TMP_PATH_FOUND_)
  960. foreach(RELOCATION_PATH ${RPM_USED_PACKAGE_PREFIXES})
  961. file(RELATIVE_PATH REL_PATH_ "${RELOCATION_PATH}" "${TMP_PATH}")
  962. string(SUBSTRING "${REL_PATH_}" 0 2 PREFIX_)
  963. if(NOT "${PREFIX_}" STREQUAL "..")
  964. set(TPM_PATH_FOUND_ TRUE)
  965. break()
  966. endif()
  967. endforeach()
  968. if(NOT TPM_PATH_FOUND_)
  969. message(AUTHOR_WARNING "CPackRPM:Warning: Path ${TMP_PATH} is not on one of the relocatable paths! Package will be partially relocatable.")
  970. endif()
  971. endforeach()
  972. set(RPM_USED_PACKAGE_PREFIXES "${RPM_USED_PACKAGE_PREFIXES}" PARENT_SCOPE)
  973. set(TMP_RPM_PREFIXES "${TMP_RPM_PREFIXES}" PARENT_SCOPE)
  974. endfunction()
  975. function(cpack_rpm_prepare_content_list)
  976. # get files list
  977. cmake_policy(PUSH)
  978. cmake_policy(SET CMP0009 NEW)
  979. file(GLOB_RECURSE CPACK_RPM_INSTALL_FILES LIST_DIRECTORIES true RELATIVE "${WDIR}" "${WDIR}/*")
  980. cmake_policy(POP)
  981. set(CPACK_RPM_INSTALL_FILES "/${CPACK_RPM_INSTALL_FILES}")
  982. string(REPLACE ";" ";/" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}")
  983. # if we are creating a relocatable package, omit parent directories of
  984. # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
  985. # which is passed to the find command that generates the content-list
  986. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  987. # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are
  988. # destinct parent paths of other relocation paths and remove the
  989. # final element (so the install-prefix dir itself is not omitted
  990. # from the RPM's content-list)
  991. list(SORT RPM_USED_PACKAGE_PREFIXES)
  992. set(_DISTINCT_PATH "NOT_SET")
  993. foreach(_RPM_RELOCATION_PREFIX ${RPM_USED_PACKAGE_PREFIXES})
  994. if(NOT "${_RPM_RELOCATION_PREFIX}" MATCHES "${_DISTINCT_PATH}/.*")
  995. set(_DISTINCT_PATH "${_RPM_RELOCATION_PREFIX}")
  996. string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS " ${_RPM_RELOCATION_PREFIX}")
  997. cmake_policy(PUSH)
  998. cmake_policy(SET CMP0007 NEW)
  999. list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
  1000. cmake_policy(POP)
  1001. unset(_TMP_LIST)
  1002. # Now generate all of the parent dirs of the relocation path
  1003. foreach(_PREFIX_PATH_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
  1004. list(APPEND _TMP_LIST "${_PREFIX_PATH_ELEM}")
  1005. string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
  1006. separate_arguments(_OMIT_DIR)
  1007. list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
  1008. endforeach()
  1009. endif()
  1010. endforeach()
  1011. endif()
  1012. if(CPACK_RPM_PACKAGE_DEBUG)
  1013. message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  1014. endif()
  1015. if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  1016. 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)
  1017. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
  1018. if(CPACK_RPM_PACKAGE_DEBUG)
  1019. message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
  1020. endif()
  1021. list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
  1022. endif()
  1023. endif()
  1024. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  1025. if(CPACK_RPM_PACKAGE_DEBUG)
  1026. message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
  1027. endif()
  1028. list(APPEND _RPM_DIRS_TO_OMIT ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
  1029. endif()
  1030. if(CPACK_RPM_PACKAGE_DEBUG)
  1031. message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  1032. endif()
  1033. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES ${_RPM_DIRS_TO_OMIT})
  1034. # add man paths that will be compressed
  1035. # (copied from /usr/lib/rpm/brp-compress - script that does the actual
  1036. # compressing)
  1037. list(APPEND MAN_LOCATIONS "/usr/man/man.*" "/usr/man/.*/man.*" "/usr/info.*"
  1038. "/usr/share/man/man.*" "/usr/share/man/.*/man.*" "/usr/share/info.*"
  1039. "/usr/kerberos/man.*" "/usr/X11R6/man/man.*" "/usr/lib/perl5/man/man.*"
  1040. "/usr/share/doc/.*/man/man.*" "/usr/lib/.*/man/man.*")
  1041. if(CPACK_RPM_ADDITIONAL_MAN_DIRS)
  1042. if(CPACK_RPM_PACKAGE_DEBUG)
  1043. message("CPackRPM:Debug: CPACK_RPM_ADDITIONAL_MAN_DIRS= ${CPACK_RPM_ADDITIONAL_MAN_DIRS}")
  1044. endif()
  1045. list(APPEND MAN_LOCATIONS ${CPACK_RPM_ADDITIONAL_MAN_DIRS})
  1046. endif()
  1047. foreach(PACK_LOCATION IN LISTS CPACK_RPM_INSTALL_FILES)
  1048. foreach(MAN_LOCATION IN LISTS MAN_LOCATIONS)
  1049. # man pages are files inside a certain location
  1050. if(PACK_LOCATION MATCHES "${MAN_LOCATION}/"
  1051. AND NOT IS_DIRECTORY "${WDIR}${PACK_LOCATION}"
  1052. AND NOT IS_SYMLINK "${WDIR}${PACK_LOCATION}")
  1053. list(FIND CPACK_RPM_INSTALL_FILES "${PACK_LOCATION}" INDEX)
  1054. # insert file location that covers compressed man pages
  1055. # even if using a wildcard causes duplicates as those are
  1056. # handled by RPM and we still keep the same file list
  1057. # in spec file - wildcard only represents file type (e.g. .gz)
  1058. list(INSERT CPACK_RPM_INSTALL_FILES ${INDEX} "${PACK_LOCATION}*")
  1059. # remove file location that doesn't cover compressed man pages
  1060. math(EXPR INDEX ${INDEX}+1)
  1061. list(REMOVE_AT CPACK_RPM_INSTALL_FILES ${INDEX})
  1062. break()
  1063. endif()
  1064. endforeach()
  1065. endforeach()
  1066. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}" PARENT_SCOPE)
  1067. endfunction()
  1068. function(cpack_rpm_symlink_get_relocation_prefixes LOCATION PACKAGE_PREFIXES RETURN_VARIABLE)
  1069. foreach(PKG_PREFIX IN LISTS PACKAGE_PREFIXES)
  1070. string(REGEX MATCH "^${PKG_PREFIX}/.*" FOUND_ "${LOCATION}")
  1071. if(FOUND_)
  1072. list(APPEND TMP_PREFIXES "${PKG_PREFIX}")
  1073. endif()
  1074. endforeach()
  1075. set(${RETURN_VARIABLE} "${TMP_PREFIXES}" PARENT_SCOPE)
  1076. endfunction()
  1077. function(cpack_rpm_symlink_create_relocation_script PACKAGE_PREFIXES)
  1078. list(LENGTH PACKAGE_PREFIXES LAST_INDEX)
  1079. set(SORTED_PACKAGE_PREFIXES "${PACKAGE_PREFIXES}")
  1080. list(SORT SORTED_PACKAGE_PREFIXES)
  1081. list(REVERSE SORTED_PACKAGE_PREFIXES)
  1082. math(EXPR LAST_INDEX ${LAST_INDEX}-1)
  1083. foreach(SYMLINK_INDEX RANGE ${LAST_INDEX})
  1084. list(GET SORTED_PACKAGE_PREFIXES ${SYMLINK_INDEX} SRC_PATH)
  1085. list(FIND PACKAGE_PREFIXES "${SRC_PATH}" SYMLINK_INDEX) # reverse magic
  1086. string(LENGTH "${SRC_PATH}" SRC_PATH_LEN)
  1087. set(PARTS_CNT 0)
  1088. set(SCRIPT_PART "if [ \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}\" != \"${SRC_PATH}\" ]; then\n")
  1089. # both paths relocated
  1090. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  1091. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  1092. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  1093. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  1094. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  1095. if("${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  1096. set(INDENT "")
  1097. else()
  1098. string(APPEND SCRIPT_PART " if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  1099. set(INDENT " ")
  1100. endif()
  1101. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  1102. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  1103. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1104. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1105. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1106. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  1107. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  1108. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN})
  1109. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1110. string(APPEND SCRIPT_PART " ${INDENT}if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1111. string(APPEND SCRIPT_PART " ${INDENT}ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  1112. string(APPEND SCRIPT_PART " ${INDENT}CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1113. string(APPEND SCRIPT_PART " ${INDENT}fi\n")
  1114. endforeach()
  1115. if(NOT "${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  1116. string(APPEND SCRIPT_PART " fi\n")
  1117. endif()
  1118. endif()
  1119. endforeach()
  1120. # source path relocated
  1121. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  1122. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  1123. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  1124. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1125. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1126. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1127. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  1128. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  1129. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  1130. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1131. string(APPEND SCRIPT_PART " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1132. string(APPEND SCRIPT_PART " ln -s \"${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  1133. string(APPEND SCRIPT_PART " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1134. string(APPEND SCRIPT_PART " fi\n")
  1135. endforeach()
  1136. endif()
  1137. if(PARTS_CNT)
  1138. set(SCRIPT "${SCRIPT_PART}")
  1139. string(APPEND SCRIPT "fi\n")
  1140. endif()
  1141. endforeach()
  1142. # point path relocated
  1143. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  1144. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  1145. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  1146. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  1147. if(_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  1148. string(APPEND SCRIPT "if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  1149. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  1150. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1151. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1152. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1153. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_)
  1154. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN})
  1155. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1156. string(APPEND SCRIPT " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1157. string(APPEND SCRIPT " ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"${SYMLINK_}\"\n")
  1158. string(APPEND SCRIPT " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1159. string(APPEND SCRIPT " fi\n")
  1160. endforeach()
  1161. string(APPEND SCRIPT "fi\n")
  1162. endif()
  1163. endforeach()
  1164. # no path relocated
  1165. if(_RPM_RELOCATION_SCRIPT_X_X)
  1166. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_X)
  1167. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1168. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1169. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1170. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_)
  1171. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  1172. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1173. string(APPEND SCRIPT "if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1174. string(APPEND SCRIPT " ln -s \"${POINT_}\" \"${SYMLINK_}\"\n")
  1175. string(APPEND SCRIPT "fi\n")
  1176. endforeach()
  1177. endif()
  1178. set(RPM_SYMLINK_POSTINSTALL "${SCRIPT}" PARENT_SCOPE)
  1179. endfunction()
  1180. function(cpack_rpm_symlink_add_for_relocation_script PACKAGE_PREFIXES SYMLINK SYMLINK_RELOCATION_PATHS POINT POINT_RELOCATION_PATHS)
  1181. list(LENGTH SYMLINK_RELOCATION_PATHS SYMLINK_PATHS_COUTN)
  1182. list(LENGTH POINT_RELOCATION_PATHS POINT_PATHS_COUNT)
  1183. list(APPEND _RPM_RELOCATION_SCRIPT_PAIRS "${SYMLINK}:${POINT}")
  1184. list(LENGTH _RPM_RELOCATION_SCRIPT_PAIRS PAIR_NO)
  1185. if(SYMLINK_PATHS_COUTN)
  1186. foreach(SYMLINK_RELOC_PATH IN LISTS SYMLINK_RELOCATION_PATHS)
  1187. list(FIND PACKAGE_PREFIXES "${SYMLINK_RELOC_PATH}" SYMLINK_INDEX)
  1188. # source path relocated
  1189. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X "${PAIR_NO}")
  1190. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X")
  1191. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  1192. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  1193. # both paths relocated
  1194. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX} "${PAIR_NO}")
  1195. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}")
  1196. # point path relocated
  1197. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  1198. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  1199. endforeach()
  1200. endforeach()
  1201. elseif(POINT_PATHS_COUNT)
  1202. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  1203. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  1204. # point path relocated
  1205. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  1206. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  1207. endforeach()
  1208. endif()
  1209. # no path relocated
  1210. list(APPEND _RPM_RELOCATION_SCRIPT_X_X "${PAIR_NO}")
  1211. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_X")
  1212. # place variables into parent scope
  1213. foreach(VAR IN LISTS RELOCATION_VARS)
  1214. set(${VAR} "${${VAR}}" PARENT_SCOPE)
  1215. endforeach()
  1216. set(_RPM_RELOCATION_SCRIPT_PAIRS "${_RPM_RELOCATION_SCRIPT_PAIRS}" PARENT_SCOPE)
  1217. set(REQUIRES_SYMLINK_RELOCATION_SCRIPT "true" PARENT_SCOPE)
  1218. set(DIRECTIVE "%ghost " PARENT_SCOPE)
  1219. endfunction()
  1220. function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXES IS_RELOCATABLE)
  1221. # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
  1222. # This is necessary to avoid duplicate files since rpmbuild does
  1223. # recursion on its own when encountering a pathname which is a directory
  1224. # which is not flagged as %dir
  1225. string(STRIP "${INSTALL_FILES_LIST}" INSTALL_FILES_LIST)
  1226. string(REPLACE "\n" ";" INSTALL_FILES_LIST
  1227. "${INSTALL_FILES_LIST}")
  1228. string(REPLACE "\"" "" INSTALL_FILES_LIST
  1229. "${INSTALL_FILES_LIST}")
  1230. string(LENGTH "${WDIR}" WDR_LEN_)
  1231. list(SORT INSTALL_FILES_LIST) # make file order consistent on all platforms
  1232. foreach(F IN LISTS INSTALL_FILES_LIST)
  1233. unset(DIRECTIVE)
  1234. if(IS_SYMLINK "${WDIR}/${F}")
  1235. if(IS_RELOCATABLE)
  1236. # check that symlink has relocatable format
  1237. get_filename_component(SYMLINK_LOCATION_ "${WDIR}/${F}" DIRECTORY)
  1238. execute_process(COMMAND ls -la "${WDIR}/${F}"
  1239. WORKING_DIRECTORY "${WDIR}"
  1240. OUTPUT_VARIABLE SYMLINK_POINT_
  1241. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1242. string(FIND "${SYMLINK_POINT_}" "->" SYMLINK_POINT_INDEX_ REVERSE)
  1243. math(EXPR SYMLINK_POINT_INDEX_ ${SYMLINK_POINT_INDEX_}+3)
  1244. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  1245. # get destination path
  1246. string(SUBSTRING "${SYMLINK_POINT_}" ${SYMLINK_POINT_INDEX_} ${SYMLINK_POINT_LENGTH_} SYMLINK_POINT_)
  1247. # check if path is relative or absolute
  1248. string(SUBSTRING "${SYMLINK_POINT_}" 0 1 SYMLINK_IS_ABSOLUTE_)
  1249. if(${SYMLINK_IS_ABSOLUTE_} STREQUAL "/")
  1250. # prevent absolute paths from having /../ or /./ section inside of them
  1251. get_filename_component(SYMLINK_POINT_ "${SYMLINK_POINT_}" ABSOLUTE)
  1252. else()
  1253. # handle relative path
  1254. get_filename_component(SYMLINK_POINT_ "${SYMLINK_LOCATION_}/${SYMLINK_POINT_}" ABSOLUTE)
  1255. endif()
  1256. # recalculate path length after conversion to canonical form
  1257. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  1258. if(SYMLINK_POINT_ MATCHES "${WDIR}/.*")
  1259. # only symlinks that are pointing inside the packaging structure should be checked for relocation
  1260. string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_)
  1261. cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS")
  1262. cpack_rpm_symlink_get_relocation_prefixes("${SYMLINK_POINT_WD_}" "${PACKAGE_PREFIXES}" "POINT_RELOCATIONS")
  1263. list(LENGTH SYMLINK_RELOCATIONS SYMLINK_RELOCATIONS_COUNT)
  1264. list(LENGTH POINT_RELOCATIONS POINT_RELOCATIONS_COUNT)
  1265. else()
  1266. # location pointed to is ouside WDR so it should be treated as a permanent symlink
  1267. set(SYMLINK_POINT_WD_ "${SYMLINK_POINT_}")
  1268. unset(SYMLINK_RELOCATIONS)
  1269. unset(POINT_RELOCATIONS)
  1270. unset(SYMLINK_RELOCATIONS_COUNT)
  1271. unset(POINT_RELOCATIONS_COUNT)
  1272. message(AUTHOR_WARNING "CPackRPM:Warning: Symbolic link '${F}' points to location that is outside packaging path! Link will possibly not be relocatable.")
  1273. endif()
  1274. if(SYMLINK_RELOCATIONS_COUNT AND POINT_RELOCATIONS_COUNT)
  1275. # find matching
  1276. foreach(SYMLINK_RELOCATION_PREFIX IN LISTS SYMLINK_RELOCATIONS)
  1277. list(FIND POINT_RELOCATIONS "${SYMLINK_RELOCATION_PREFIX}" FOUND_INDEX)
  1278. if(NOT ${FOUND_INDEX} EQUAL -1)
  1279. break()
  1280. endif()
  1281. endforeach()
  1282. if(NOT ${FOUND_INDEX} EQUAL -1)
  1283. # symlinks have the same subpath
  1284. if(${SYMLINK_RELOCATIONS_COUNT} EQUAL 1 AND ${POINT_RELOCATIONS_COUNT} EQUAL 1)
  1285. # permanent symlink
  1286. get_filename_component(SYMLINK_LOCATION_ "${F}" DIRECTORY)
  1287. file(RELATIVE_PATH FINAL_PATH_ ${SYMLINK_LOCATION_} ${SYMLINK_POINT_WD_})
  1288. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${FINAL_PATH_}" "${WDIR}/${F}")
  1289. else()
  1290. # relocation subpaths
  1291. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1292. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1293. endif()
  1294. else()
  1295. # not on the same relocation path
  1296. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1297. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1298. endif()
  1299. elseif(POINT_RELOCATIONS_COUNT)
  1300. # point is relocatable
  1301. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1302. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1303. else()
  1304. # is not relocatable or points to non relocatable path - permanent symlink
  1305. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${SYMLINK_POINT_WD_}" "${WDIR}/${F}")
  1306. endif()
  1307. endif()
  1308. elseif(IS_DIRECTORY "${WDIR}/${F}")
  1309. set(DIRECTIVE "%dir ")
  1310. endif()
  1311. string(APPEND INSTALL_FILES "${DIRECTIVE}\"${F}\"\n")
  1312. endforeach()
  1313. if(REQUIRES_SYMLINK_RELOCATION_SCRIPT)
  1314. cpack_rpm_symlink_create_relocation_script("${PACKAGE_PREFIXES}")
  1315. endif()
  1316. set(RPM_SYMLINK_POSTINSTALL "${RPM_SYMLINK_POSTINSTALL}" PARENT_SCOPE)
  1317. set(CPACK_RPM_INSTALL_FILES "${INSTALL_FILES}" PARENT_SCOPE)
  1318. endfunction()
  1319. if(CMAKE_BINARY_DIR)
  1320. message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  1321. endif()
  1322. if(NOT UNIX)
  1323. message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  1324. endif()
  1325. # We need to check if the binaries were compiled with debug symbols
  1326. # because without them the package will be useless
  1327. function(cpack_rpm_debugsymbol_check INSTALL_FILES WORKING_DIR)
  1328. if(NOT CPACK_BUILD_SOURCE_DIRS)
  1329. message(FATAL_ERROR "CPackRPM: CPACK_BUILD_SOURCE_DIRS variable is not set!"
  1330. " Required for debuginfo packaging. See documentation of"
  1331. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1332. endif()
  1333. # With objdump we should check the debug symbols
  1334. find_program(OBJDUMP_EXECUTABLE objdump)
  1335. if(NOT OBJDUMP_EXECUTABLE)
  1336. message(FATAL_ERROR "CPackRPM: objdump binary could not be found!"
  1337. " Required for debuginfo packaging. See documentation of"
  1338. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1339. endif()
  1340. # With debugedit we prepare source files list
  1341. find_program(DEBUGEDIT_EXECUTABLE debugedit "/usr/lib/rpm/")
  1342. if(NOT DEBUGEDIT_EXECUTABLE)
  1343. message(FATAL_ERROR "CPackRPM: debugedit binary could not be found!"
  1344. " Required for debuginfo packaging. See documentation of"
  1345. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1346. endif()
  1347. unset(mkdir_list_)
  1348. unset(cp_list_)
  1349. unset(additional_sources_)
  1350. foreach(F IN LISTS INSTALL_FILES)
  1351. if(IS_DIRECTORY "${WORKING_DIR}/${F}" OR IS_SYMLINK "${WORKING_DIR}/${F}")
  1352. continue()
  1353. endif()
  1354. execute_process(COMMAND "${OBJDUMP_EXECUTABLE}" -h ${WORKING_DIR}/${F}
  1355. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}"
  1356. RESULT_VARIABLE OBJDUMP_EXEC_RESULT
  1357. OUTPUT_VARIABLE OBJDUMP_OUT
  1358. ERROR_QUIET)
  1359. # Check that if the given file was executable or not
  1360. if(NOT OBJDUMP_EXEC_RESULT)
  1361. string(FIND "${OBJDUMP_OUT}" "debug" FIND_RESULT)
  1362. if(FIND_RESULT GREATER -1)
  1363. set(index_ 0)
  1364. foreach(source_dir_ IN LISTS CPACK_BUILD_SOURCE_DIRS)
  1365. string(LENGTH "${source_dir_}" source_dir_len_)
  1366. string(LENGTH "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" debuginfo_dir_len)
  1367. if(source_dir_len_ LESS debuginfo_dir_len)
  1368. message(FATAL_ERROR "CPackRPM: source dir path '${source_dir_}' is"
  1369. " shorter than debuginfo sources dir path '${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}'!"
  1370. " Source dir path must be longer than debuginfo sources dir path."
  1371. " Set CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX variable to a shorter value"
  1372. " or make source dir path longer."
  1373. " Required for debuginfo packaging. See documentation of"
  1374. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1375. endif()
  1376. file(REMOVE "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list")
  1377. execute_process(COMMAND "${DEBUGEDIT_EXECUTABLE}" -b "${source_dir_}" -d "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" -i -l "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list" "${WORKING_DIR}/${F}"
  1378. RESULT_VARIABLE res_
  1379. OUTPUT_VARIABLE opt_
  1380. ERROR_VARIABLE err_
  1381. )
  1382. file(STRINGS
  1383. "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list"
  1384. sources_)
  1385. list(REMOVE_DUPLICATES sources_)
  1386. foreach(source_ IN LISTS sources_)
  1387. if(EXISTS "${source_dir_}/${source_}" AND NOT IS_DIRECTORY "${source_dir_}/${source_}")
  1388. get_filename_component(path_part_ "${source_}" DIRECTORY)
  1389. list(APPEND mkdir_list_ "%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}")
  1390. list(APPEND cp_list_ "cp \"${source_dir_}/${source_}\" \"%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}\"")
  1391. list(APPEND additional_sources_ "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${source_}")
  1392. endif()
  1393. endforeach()
  1394. math(EXPR index_ "${index_} + 1")
  1395. endforeach()
  1396. else()
  1397. message(WARNING "CPackRPM: File: ${F} does not contain debug symbols. They will possibly be missing from debuginfo package!")
  1398. endif()
  1399. endif()
  1400. endforeach()
  1401. list(LENGTH mkdir_list_ len_)
  1402. if(len_)
  1403. list(REMOVE_DUPLICATES mkdir_list_)
  1404. unset(TMP_RPM_DEBUGINFO_INSTALL)
  1405. foreach(part_ IN LISTS mkdir_list_)
  1406. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "mkdir -p \"${part_}\"\n")
  1407. endforeach()
  1408. endif()
  1409. list(LENGTH cp_list_ len_)
  1410. if(len_)
  1411. list(REMOVE_DUPLICATES cp_list_)
  1412. foreach(part_ IN LISTS cp_list_)
  1413. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "${part_}\n")
  1414. endforeach()
  1415. endif()
  1416. if(NOT DEFINED CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS)
  1417. set(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS /usr /usr/src /usr/src/debug)
  1418. if(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION)
  1419. if(CPACK_RPM_PACKAGE_DEBUG)
  1420. message("CPackRPM:Debug: Adding ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION} to builtin omit list.")
  1421. endif()
  1422. list(APPEND CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS "${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION}")
  1423. endif()
  1424. endif()
  1425. if(CPACK_RPM_PACKAGE_DEBUG)
  1426. message("CPackRPM:Debug: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS= ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}")
  1427. endif()
  1428. list(LENGTH additional_sources_ len_)
  1429. if(len_)
  1430. list(REMOVE_DUPLICATES additional_sources_)
  1431. unset(additional_sources_all_)
  1432. foreach(source_ IN LISTS additional_sources_)
  1433. string(REPLACE "/" ";" split_source_ " ${source_}")
  1434. list(REMOVE_AT split_source_ 0)
  1435. unset(tmp_path_)
  1436. # Now generate all segments of the path
  1437. foreach(segment_ IN LISTS split_source_)
  1438. string(APPEND tmp_path_ "/${segment_}")
  1439. list(APPEND additional_sources_all_ "${tmp_path_}")
  1440. endforeach()
  1441. endforeach()
  1442. list(REMOVE_DUPLICATES additional_sources_all_)
  1443. list(REMOVE_ITEM additional_sources_all_
  1444. ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS})
  1445. unset(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  1446. foreach(source_ IN LISTS additional_sources_all_)
  1447. string(APPEND TMP_DEBUGINFO_ADDITIONAL_SOURCES "${source_}\n")
  1448. endforeach()
  1449. endif()
  1450. set(TMP_RPM_DEBUGINFO_INSTALL "${TMP_RPM_DEBUGINFO_INSTALL}" PARENT_SCOPE)
  1451. set(TMP_DEBUGINFO_ADDITIONAL_SOURCES "${TMP_DEBUGINFO_ADDITIONAL_SOURCES}"
  1452. PARENT_SCOPE)
  1453. endfunction()
  1454. function(cpack_rpm_variable_fallback OUTPUT_VAR_NAME)
  1455. set(FALLBACK_VAR_NAMES ${ARGN})
  1456. foreach(variable_name IN LISTS FALLBACK_VAR_NAMES)
  1457. if(${variable_name})
  1458. set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE)
  1459. break()
  1460. endif()
  1461. endforeach()
  1462. endfunction()
  1463. function(cpack_rpm_generate_package)
  1464. # rpmbuild is the basic command for building RPM package
  1465. # it may be a simple (symbolic) link to rpm command.
  1466. find_program(RPMBUILD_EXECUTABLE rpmbuild)
  1467. # Check version of the rpmbuild tool this would be easier to
  1468. # track bugs with users and CPackRPM debug mode.
  1469. # We may use RPM version in order to check for available version dependent features
  1470. if(RPMBUILD_EXECUTABLE)
  1471. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  1472. OUTPUT_VARIABLE _TMP_VERSION
  1473. ERROR_QUIET
  1474. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1475. string(REGEX REPLACE "^.* " ""
  1476. RPMBUILD_EXECUTABLE_VERSION
  1477. ${_TMP_VERSION})
  1478. if(CPACK_RPM_PACKAGE_DEBUG)
  1479. message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  1480. endif()
  1481. endif()
  1482. if(NOT RPMBUILD_EXECUTABLE)
  1483. message(FATAL_ERROR "RPM package requires rpmbuild executable")
  1484. endif()
  1485. # Display lsb_release output if DEBUG mode enable
  1486. # This will help to diagnose problem with CPackRPM
  1487. # because we will know on which kind of Linux we are
  1488. if(CPACK_RPM_PACKAGE_DEBUG)
  1489. find_program(LSB_RELEASE_EXECUTABLE lsb_release)
  1490. if(LSB_RELEASE_EXECUTABLE)
  1491. execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
  1492. OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
  1493. ERROR_QUIET
  1494. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1495. string(REGEX REPLACE "\n" ", "
  1496. LSB_RELEASE_OUTPUT
  1497. ${_TMP_LSB_RELEASE_OUTPUT})
  1498. else ()
  1499. set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
  1500. endif()
  1501. message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
  1502. endif()
  1503. # We may use RPM version in the future in order
  1504. # to shut down warning about space in buildtree
  1505. # some recent RPM version should support space in different places.
  1506. # not checked [yet].
  1507. if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  1508. message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  1509. endif()
  1510. # If rpmbuild is found
  1511. # we try to discover alien since we may be on non RPM distro like Debian.
  1512. # In this case we may try to to use more advanced features
  1513. # like generating RPM directly from DEB using alien.
  1514. # FIXME feature not finished (yet)
  1515. find_program(ALIEN_EXECUTABLE alien)
  1516. if(ALIEN_EXECUTABLE)
  1517. message(STATUS "alien found, we may be on a Debian based distro.")
  1518. endif()
  1519. # Are we packaging components ?
  1520. if(CPACK_RPM_PACKAGE_COMPONENT)
  1521. string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1522. endif()
  1523. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  1524. #
  1525. # Use user-defined RPM specific variables value
  1526. # or generate reasonable default value from
  1527. # CPACK_xxx generic values.
  1528. # The variables comes from the needed (mandatory or not)
  1529. # values found in the RPM specification file aka ".spec" file.
  1530. # The variables which may/should be defined are:
  1531. #
  1532. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  1533. if(CPACK_RPM_PACKAGE_COMPONENT)
  1534. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_SUMMARY"
  1535. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY"
  1536. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_SUMMARY")
  1537. endif()
  1538. if(NOT CPACK_RPM_PACKAGE_SUMMARY)
  1539. if(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  1540. set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  1541. else()
  1542. # if neither var is defined lets use the name as summary
  1543. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  1544. endif()
  1545. endif()
  1546. # CPACK_RPM_PACKAGE_NAME (mandatory)
  1547. if(NOT CPACK_RPM_PACKAGE_NAME)
  1548. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  1549. endif()
  1550. if(CPACK_RPM_PACKAGE_COMPONENT)
  1551. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  1552. CPACK_RPM_MAIN_COMPONENT_UPPER)
  1553. if(NOT CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1554. string(APPEND CPACK_RPM_PACKAGE_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
  1555. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_NAME"
  1556. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME"
  1557. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME")
  1558. endif()
  1559. endif()
  1560. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  1561. if(NOT CPACK_RPM_PACKAGE_VERSION)
  1562. if(NOT CPACK_PACKAGE_VERSION)
  1563. message(FATAL_ERROR "RPM package requires a package version")
  1564. endif()
  1565. set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  1566. endif()
  1567. # Replace '-' in version with '_'
  1568. # '-' character is an Illegal RPM version character
  1569. # it is illegal because it is used to separate
  1570. # RPM "Version" from RPM "Release"
  1571. string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
  1572. # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory)
  1573. if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
  1574. execute_process(COMMAND uname "-m"
  1575. OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
  1576. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1577. else()
  1578. if(CPACK_RPM_PACKAGE_DEBUG)
  1579. message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1580. endif()
  1581. endif()
  1582. if(CPACK_RPM_PACKAGE_COMPONENT)
  1583. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_ARCHITECTURE"
  1584. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE"
  1585. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_ARCHITECTURE")
  1586. if(CPACK_RPM_PACKAGE_DEBUG)
  1587. message("CPackRPM:Debug: using component build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1588. endif()
  1589. endif()
  1590. if(${CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch")
  1591. set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1592. else()
  1593. set(TMP_RPM_BUILDARCH "")
  1594. endif()
  1595. # CPACK_RPM_PACKAGE_RELEASE
  1596. # The RPM release is the numbering of the RPM package ITSELF
  1597. # this is the version of the PACKAGING and NOT the version
  1598. # of the CONTENT of the package.
  1599. # You may well need to generate a new RPM package release
  1600. # without changing the version of the packaged software.
  1601. # This is the case when the packaging is buggy (not) the software :=)
  1602. # If not set, 1 is a good candidate
  1603. if(NOT CPACK_RPM_PACKAGE_RELEASE)
  1604. set(CPACK_RPM_PACKAGE_RELEASE "1")
  1605. endif()
  1606. if(CPACK_RPM_PACKAGE_RELEASE_DIST)
  1607. string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}")
  1608. endif()
  1609. # CPACK_RPM_PACKAGE_LICENSE
  1610. if(NOT CPACK_RPM_PACKAGE_LICENSE)
  1611. set(CPACK_RPM_PACKAGE_LICENSE "unknown")
  1612. endif()
  1613. # CPACK_RPM_PACKAGE_GROUP
  1614. if(CPACK_RPM_PACKAGE_COMPONENT)
  1615. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_GROUP"
  1616. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP"
  1617. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_GROUP")
  1618. endif()
  1619. if(NOT CPACK_RPM_PACKAGE_GROUP)
  1620. set(CPACK_RPM_PACKAGE_GROUP "unknown")
  1621. endif()
  1622. # CPACK_RPM_PACKAGE_VENDOR
  1623. if(NOT CPACK_RPM_PACKAGE_VENDOR)
  1624. if(CPACK_PACKAGE_VENDOR)
  1625. set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  1626. else()
  1627. set(CPACK_RPM_PACKAGE_VENDOR "unknown")
  1628. endif()
  1629. endif()
  1630. # CPACK_RPM_PACKAGE_SOURCE
  1631. # The name of the source tarball in case we generate a source RPM
  1632. # CPACK_RPM_PACKAGE_DESCRIPTION
  1633. # The variable content may be either
  1634. # - explicitly given by the user or
  1635. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  1636. # if it is defined
  1637. # - set to a default value
  1638. #
  1639. if(CPACK_RPM_PACKAGE_COMPONENT)
  1640. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_DESCRIPTION"
  1641. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION"
  1642. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_DESCRIPTION"
  1643. "CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION")
  1644. endif()
  1645. if(NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  1646. if(CPACK_PACKAGE_DESCRIPTION_FILE)
  1647. file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  1648. else ()
  1649. set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  1650. endif ()
  1651. endif ()
  1652. # CPACK_RPM_COMPRESSION_TYPE
  1653. #
  1654. if (CPACK_RPM_COMPRESSION_TYPE)
  1655. if(CPACK_RPM_PACKAGE_DEBUG)
  1656. message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
  1657. endif()
  1658. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  1659. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
  1660. endif()
  1661. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  1662. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
  1663. endif()
  1664. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  1665. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
  1666. endif()
  1667. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  1668. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
  1669. endif()
  1670. else()
  1671. set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
  1672. endif()
  1673. if(NOT CPACK_RPM_PACKAGE_SOURCES)
  1674. if(CPACK_PACKAGE_RELOCATABLE OR CPACK_RPM_PACKAGE_RELOCATABLE)
  1675. if(CPACK_RPM_PACKAGE_DEBUG)
  1676. message("CPackRPM:Debug: Trying to build a relocatable package")
  1677. endif()
  1678. if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  1679. 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.")
  1680. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE)
  1681. else()
  1682. set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files)
  1683. cpack_rpm_prepare_relocation_paths()
  1684. set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
  1685. endif()
  1686. endif()
  1687. else()
  1688. if(CPACK_RPM_PACKAGE_COMPONENT)
  1689. message(FATAL_ERROR "CPACK_RPM_PACKAGE_SOURCES parameter can not be used"
  1690. " in combination with CPACK_RPM_PACKAGE_COMPONENT parameter!")
  1691. endif()
  1692. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) # disable relocatable option if building source RPM
  1693. endif()
  1694. execute_process(
  1695. COMMAND "${RPMBUILD_EXECUTABLE}" --querytags
  1696. OUTPUT_VARIABLE RPMBUILD_TAG_LIST
  1697. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1698. string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}")
  1699. # Check if additional fields for RPM spec header are given
  1700. # There may be some COMPONENT specific variables as well
  1701. # If component specific var is not provided we use the global one
  1702. # for each component
  1703. foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  1704. if(CPACK_RPM_PACKAGE_DEBUG)
  1705. message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
  1706. endif()
  1707. if(CPACK_RPM_PACKAGE_COMPONENT)
  1708. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}"
  1709. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}"
  1710. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_${_RPM_SPEC_HEADER}")
  1711. endif()
  1712. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  1713. cmake_policy(PUSH)
  1714. cmake_policy(SET CMP0057 NEW)
  1715. # Prefix can be replaced by Prefixes but the old version stil works so we'll ignore it for now
  1716. # Requires* is a special case because it gets transformed to Requires(pre/post/preun/postun)
  1717. # Auto* is a special case because the tags can not be queried by querytags rpmbuild flag
  1718. set(special_case_tags_ PREFIX REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN AUTOPROV AUTOREQ AUTOREQPROV)
  1719. if(NOT _RPM_SPEC_HEADER IN_LIST RPMBUILD_TAG_LIST AND NOT _RPM_SPEC_HEADER IN_LIST special_case_tags_)
  1720. cmake_policy(POP)
  1721. message(AUTHOR_WARNING "CPackRPM:Warning: ${_RPM_SPEC_HEADER} not "
  1722. "supported in provided rpmbuild. Tag will not be used.")
  1723. continue()
  1724. endif()
  1725. cmake_policy(POP)
  1726. if(CPACK_RPM_PACKAGE_DEBUG)
  1727. message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
  1728. endif()
  1729. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
  1730. endif()
  1731. # Treat the RPM Spec keyword iff it has been properly defined
  1732. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  1733. # Transform NAME --> Name e.g. PROVIDES --> Provides
  1734. # The Upper-case first letter and lowercase tail is the
  1735. # appropriate value required in the final RPM spec file.
  1736. string(SUBSTRING ${_RPM_SPEC_HEADER} 1 -1 _PACKAGE_HEADER_TAIL)
  1737. string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
  1738. string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
  1739. string(APPEND _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_TAIL}")
  1740. # The following keywords require parentheses around the "pre" or "post" suffix in the final RPM spec file.
  1741. set(SCRIPTS_REQUIREMENTS_LIST REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  1742. list(FIND SCRIPTS_REQUIREMENTS_LIST ${_RPM_SPEC_HEADER} IS_SCRIPTS_REQUIREMENT_FOUND)
  1743. if(NOT ${IS_SCRIPTS_REQUIREMENT_FOUND} EQUAL -1)
  1744. string(REPLACE "_" "(" _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}")
  1745. string(APPEND _PACKAGE_HEADER_NAME ")")
  1746. endif()
  1747. if(CPACK_RPM_PACKAGE_DEBUG)
  1748. message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  1749. endif()
  1750. set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  1751. unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  1752. endif()
  1753. endforeach()
  1754. # CPACK_RPM_SPEC_INSTALL_POST
  1755. # May be used to define a RPM post intallation script
  1756. # for example setting it to "/bin/true" may prevent
  1757. # rpmbuild from stripping binaries.
  1758. if(CPACK_RPM_SPEC_INSTALL_POST)
  1759. if(CPACK_RPM_PACKAGE_DEBUG)
  1760. message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  1761. endif()
  1762. set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  1763. endif()
  1764. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
  1765. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
  1766. # May be used to embed a post (un)installation script in the spec file.
  1767. # The refered script file(s) will be read and directly
  1768. # put after the %post or %postun section
  1769. # ----------------------------------------------------------------
  1770. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
  1771. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
  1772. # May be used to embed a pre (un)installation script in the spec file.
  1773. # The refered script file(s) will be read and directly
  1774. # put after the %pre or %preun section
  1775. foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL")
  1776. foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST")
  1777. set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  1778. "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}")
  1779. if(CPACK_RPM_PACKAGE_COMPONENT)
  1780. cpack_rpm_variable_fallback("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  1781. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE"
  1782. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE")
  1783. endif()
  1784. # Handle file if it has been specified
  1785. if(CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE)
  1786. if(EXISTS ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE})
  1787. file(READ ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}
  1788. "CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}")
  1789. else()
  1790. message("CPackRPM:Warning: CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE <${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}> does not exists - ignoring")
  1791. endif()
  1792. else()
  1793. # reset SPEC var value if no file has been specified
  1794. # (either globally or component-wise)
  1795. set("CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}" "")
  1796. endif()
  1797. endforeach()
  1798. endforeach()
  1799. # CPACK_RPM_CHANGELOG_FILE
  1800. # May be used to embed a changelog in the spec file.
  1801. # The refered file will be read and directly put after the %changelog section
  1802. if(CPACK_RPM_CHANGELOG_FILE)
  1803. if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  1804. file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
  1805. else()
  1806. message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
  1807. endif()
  1808. else()
  1809. set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard <[email protected]> - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)")
  1810. endif()
  1811. # CPACK_RPM_SPEC_MORE_DEFINE
  1812. # This is a generated spec rpm file spaceholder
  1813. if(CPACK_RPM_SPEC_MORE_DEFINE)
  1814. if(CPACK_RPM_PACKAGE_DEBUG)
  1815. message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  1816. endif()
  1817. endif()
  1818. # Now we may create the RPM build tree structure
  1819. set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  1820. message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  1821. # Prepare RPM build tree
  1822. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  1823. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  1824. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  1825. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  1826. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  1827. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  1828. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  1829. # it seems rpmbuild can't handle spaces in the path
  1830. # neither escaping (as below) nor putting quotes around the path seem to help
  1831. #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1832. set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1833. cpack_rpm_prepare_content_list()
  1834. # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
  1835. # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1836. # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
  1837. # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
  1838. if(CPACK_RPM_PACKAGE_COMPONENT)
  1839. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1840. cpack_rpm_variable_fallback("COMPONENT_FILES_TAG"
  1841. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}"
  1842. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}")
  1843. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
  1844. if(CPACK_RPM_PACKAGE_DEBUG)
  1845. message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
  1846. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1847. endif()
  1848. endif()
  1849. else()
  1850. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1851. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
  1852. endif()
  1853. endif()
  1854. # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
  1855. set(CPACK_RPM_USER_FILELIST_INTERNAL "")
  1856. if(CPACK_RPM_PACKAGE_COMPONENT)
  1857. cpack_rpm_variable_fallback("CPACK_RPM_USER_FILELIST_INTERNAL"
  1858. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST"
  1859. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_FILELIST")
  1860. if(CPACK_RPM_PACKAGE_DEBUG AND CPACK_RPM_USER_FILELIST_INTERNAL)
  1861. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1862. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1863. endif()
  1864. elseif(CPACK_RPM_USER_FILELIST)
  1865. set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
  1866. endif()
  1867. # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
  1868. # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1869. # or CPACK_RPM_INSTALL_FILES,
  1870. # hence it must be done before these auto-generated lists are processed.
  1871. if(CPACK_RPM_USER_FILELIST_INTERNAL)
  1872. if(CPACK_RPM_PACKAGE_DEBUG)
  1873. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1874. endif()
  1875. # Create CMake list from CPACK_RPM_INSTALL_FILES
  1876. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1877. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
  1878. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1879. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
  1880. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1881. set(CPACK_RPM_USER_INSTALL_FILES "")
  1882. foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
  1883. string(REGEX REPLACE "%[A-Za-z]+(\\([^()]*\\))? " "" F_PATH ${F})
  1884. string(REGEX MATCH "(%[A-Za-z]+(\\([^()]*\\))? )*" F_PREFIX ${F})
  1885. string(STRIP ${F_PREFIX} F_PREFIX)
  1886. if(CPACK_RPM_PACKAGE_DEBUG)
  1887. message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
  1888. endif()
  1889. if(F_PREFIX)
  1890. string(APPEND F_PREFIX " ")
  1891. endif()
  1892. # Rebuild the user list file
  1893. string(APPEND CPACK_RPM_USER_INSTALL_FILES "${F_PREFIX}\"${F_PATH}\"\n")
  1894. # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1895. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
  1896. # ABSOLUTE destination files list may not exists at all
  1897. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1898. list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
  1899. endif()
  1900. endforeach()
  1901. # Rebuild CPACK_RPM_INSTALL_FILES
  1902. set(CPACK_RPM_INSTALL_FILES "")
  1903. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1904. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1905. endforeach()
  1906. else()
  1907. set(CPACK_RPM_USER_INSTALL_FILES "")
  1908. endif()
  1909. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1910. if(CPACK_RPM_PACKAGE_DEBUG)
  1911. message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
  1912. endif()
  1913. # Remove trailing space
  1914. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1915. # Transform endline separated - string into CMake List
  1916. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1917. # Remove unecessary quotes
  1918. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1919. # Remove ABSOLUTE install file from INSTALL FILE LIST
  1920. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
  1921. # Rebuild INSTALL_FILES
  1922. set(CPACK_RPM_INSTALL_FILES "")
  1923. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1924. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1925. endforeach()
  1926. # Build ABSOLUTE_INSTALL_FILES
  1927. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1928. foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1929. string(APPEND CPACK_RPM_ABSOLUTE_INSTALL_FILES "%config \"${F}\"\n")
  1930. endforeach()
  1931. if(CPACK_RPM_PACKAGE_DEBUG)
  1932. message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
  1933. message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
  1934. endif()
  1935. else()
  1936. # reset vars in order to avoid leakage of value(s) from one component to another
  1937. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1938. endif()
  1939. cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_PACKAGE"
  1940. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_PACKAGE"
  1941. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_PACKAGE"
  1942. "CPACK_RPM_DEBUGINFO_PACKAGE")
  1943. if(CPACK_RPM_DEBUGINFO_PACKAGE OR (CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND NOT GENERATE_SPEC_PARTS))
  1944. cpack_rpm_variable_fallback("CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX"
  1945. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_BUILD_SOURCE_DIRS_PREFIX"
  1946. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_BUILD_SOURCE_DIRS_PREFIX"
  1947. "CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX")
  1948. if(NOT CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX)
  1949. set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  1950. endif()
  1951. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  1952. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files"
  1953. "${CPACK_RPM_INSTALL_FILES}")
  1954. else()
  1955. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND CPACK_RPM_PACKAGE_COMPONENT)
  1956. # this part is only required by components packaging - with monolithic
  1957. # packages we can be certain that there are no other components present
  1958. # so CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is a noop
  1959. if(CPACK_RPM_DEBUGINFO_PACKAGE)
  1960. # only add current package files to debuginfo list if debuginfo
  1961. # generation is enabled for current package
  1962. string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_)
  1963. string(REPLACE "\n" ";" install_files_ "${install_files_}")
  1964. string(REPLACE "\"" "" install_files_ "${install_files_}")
  1965. else()
  1966. unset(install_files_)
  1967. endif()
  1968. file(GLOB files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.files")
  1969. foreach(f_ IN LISTS files_)
  1970. file(READ "${f_}" tmp_)
  1971. string(APPEND install_files_ ";${tmp_}")
  1972. endforeach()
  1973. # if there were other components/groups so we need to move files from them
  1974. # to current component otherwise those files won't be found
  1975. file(GLOB components_ LIST_DIRECTORIES true RELATIVE
  1976. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  1977. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/*")
  1978. foreach(component_ IN LISTS components_)
  1979. string(TOUPPER "${component_}" component_dir_upper_)
  1980. if(component_dir_upper_ STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1981. # skip current component
  1982. continue()
  1983. endif()
  1984. cmake_policy(PUSH)
  1985. cmake_policy(SET CMP0009 NEW)
  1986. file(GLOB_RECURSE files_for_move_ LIST_DIRECTORIES false RELATIVE
  1987. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}"
  1988. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/*")
  1989. cmake_policy(POP)
  1990. foreach(f_ IN LISTS files_for_move_)
  1991. get_filename_component(dir_path_ "${f_}" DIRECTORY)
  1992. set(src_file_
  1993. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/${f_}")
  1994. # check that we are not overriding an existing file that doesn't
  1995. # match the file that we want to copy
  1996. if(EXISTS "${src_file_}" AND EXISTS "${WDIR}/${f_}")
  1997. execute_process(
  1998. COMMAND ${CMAKE_COMMAND} -E compare_files "${src_file_}" "${WDIR}/${f_}"
  1999. RESULT_VARIABLE res_
  2000. )
  2001. if(res_)
  2002. message(FATAL_ERROR "CPackRPM:Error: File on path '${WDIR}/${f_}'"
  2003. " already exists but is a different than the one in component"
  2004. " '${component_}'! Packages will not be generated.")
  2005. endif()
  2006. endif()
  2007. file(MAKE_DIRECTORY "${WDIR}/${dir_path_}")
  2008. file(RENAME "${src_file_}"
  2009. "${WDIR}/${f_}")
  2010. endforeach()
  2011. endforeach()
  2012. cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}")
  2013. else()
  2014. string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_)
  2015. string(REPLACE "\n" ";" install_files_ "${install_files_}")
  2016. string(REPLACE "\"" "" install_files_ "${install_files_}")
  2017. cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}")
  2018. endif()
  2019. if(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  2020. set(TMP_RPM_DEBUGINFO "
  2021. # Modified version of %%debug_package macro
  2022. # defined in /usr/lib/rpm/macros as that one
  2023. # can't handle injection of extra source files.
  2024. %ifnarch noarch
  2025. %global __debug_package 1
  2026. %package debuginfo
  2027. Summary: Debug information for package %{name}
  2028. Group: Development/Debug
  2029. AutoReqProv: 0
  2030. %description debuginfo
  2031. This package provides debug information for package %{name}.
  2032. Debug information is useful when developing applications that use this
  2033. package or when debugging this package.
  2034. %files debuginfo -f debugfiles.list
  2035. %defattr(-,root,root)
  2036. ${TMP_DEBUGINFO_ADDITIONAL_SOURCES}
  2037. %endif
  2038. ")
  2039. elseif(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  2040. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  2041. " but will not be generated as no source files were found!")
  2042. else()
  2043. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  2044. " but will not be generated as no source files were found! Component: '"
  2045. "${CPACK_RPM_PACKAGE_COMPONENT}'.")
  2046. endif()
  2047. endif()
  2048. endif()
  2049. # Prepare install files
  2050. cpack_rpm_prepare_install_files(
  2051. "${CPACK_RPM_INSTALL_FILES}"
  2052. "${WDIR}"
  2053. "${RPM_USED_PACKAGE_PREFIXES}"
  2054. "${CPACK_RPM_PACKAGE_RELOCATABLE}"
  2055. )
  2056. # set default user and group
  2057. foreach(_PERM_TYPE "USER" "GROUP")
  2058. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE})
  2059. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}}")
  2060. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE})
  2061. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_DEFAULT_${_PERM_TYPE}}")
  2062. else()
  2063. set(TMP_DEFAULT_${_PERM_TYPE} "root")
  2064. endif()
  2065. endforeach()
  2066. # set default file and dir permissions
  2067. foreach(_PERM_TYPE "FILE" "DIR")
  2068. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  2069. get_unix_permissions_octal_notation("CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2070. set(_PERMISSIONS_VAR "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2071. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  2072. get_unix_permissions_octal_notation("CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2073. set(_PERMISSIONS_VAR "CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2074. else()
  2075. set(TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS "-")
  2076. endif()
  2077. endforeach()
  2078. # The name of the final spec file to be used by rpmbuild
  2079. set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
  2080. # Print out some debug information if we were asked for that
  2081. if(CPACK_RPM_PACKAGE_DEBUG)
  2082. message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  2083. message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  2084. message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  2085. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  2086. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  2087. message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  2088. message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  2089. message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  2090. message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  2091. endif()
  2092. #
  2093. # USER generated/provided spec file handling.
  2094. #
  2095. # We can have a component specific spec file.
  2096. if(CPACK_RPM_PACKAGE_COMPONENT)
  2097. cpack_rpm_variable_fallback("CPACK_RPM_USER_BINARY_SPECFILE"
  2098. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE"
  2099. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_BINARY_SPECFILE")
  2100. endif()
  2101. cpack_rpm_variable_fallback("CPACK_RPM_FILE_NAME"
  2102. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_FILE_NAME"
  2103. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_FILE_NAME"
  2104. "CPACK_RPM_FILE_NAME")
  2105. if(NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  2106. if(CPACK_RPM_FILE_NAME)
  2107. cmake_policy(PUSH)
  2108. cmake_policy(SET CMP0010 NEW)
  2109. if(NOT CPACK_RPM_FILE_NAME MATCHES ".*\\.rpm")
  2110. cmake_policy(POP)
  2111. message(FATAL_ERROR "'${CPACK_RPM_FILE_NAME}' is not a valid RPM package file name as it must end with '.rpm'!")
  2112. endif()
  2113. cmake_policy(POP)
  2114. else()
  2115. # old file name format for back compatibility
  2116. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  2117. CPACK_RPM_MAIN_COMPONENT_UPPER)
  2118. if(CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  2119. # this is the main component so ignore the component filename part
  2120. set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.rpm")
  2121. else()
  2122. set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  2123. endif()
  2124. endif()
  2125. # else example:
  2126. #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  2127. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  2128. string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" expected_filename_)
  2129. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.rpm_name"
  2130. "${expected_filename_};${CPACK_RPM_FILE_NAME}")
  2131. elseif(NOT CPACK_RPM_DEBUGINFO_PACKAGE)
  2132. set(FILE_NAME_DEFINE "%define _rpmfilename ${CPACK_RPM_FILE_NAME}")
  2133. endif()
  2134. endif()
  2135. if(CPACK_RPM_PACKAGE_SOURCES) # source rpm
  2136. set(archive_name_ "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}")
  2137. execute_process(
  2138. COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${CPACK_RPM_DIRECTORY}/SOURCES/${archive_name_}.tar.gz" "${CPACK_PACKAGE_FILE_NAME}"
  2139. WORKING_DIRECTORY ${CPACK_RPM_DIRECTORY}
  2140. )
  2141. set(TMP_RPM_SOURCE "Source: ${archive_name_}.tar.gz")
  2142. if(CPACK_RPM_BUILDREQUIRES)
  2143. set(TMP_RPM_BUILD_REQUIRES "BuildRequires: ${CPACK_RPM_BUILDREQUIRES}")
  2144. endif()
  2145. # Disable debuginfo packages - srpm generates invalid packages due to
  2146. # releasing controll to cpack to generate binary packages.
  2147. # Note however that this doesn't prevent cpack to generate debuginfo
  2148. # packages when run from srpm with --rebuild.
  2149. set(TMP_RPM_DISABLE_DEBUGINFO "%define debug_package %{nil}")
  2150. if(NOT CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX)
  2151. set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/")
  2152. endif()
  2153. set(TMP_RPM_BUILD
  2154. "
  2155. %build
  2156. mkdir cpack_rpm_build_dir
  2157. cd cpack_rpm_build_dir
  2158. cmake ${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCPACK_PACKAGING_INSTALL_PREFIX=${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX} ../${CPACK_PACKAGE_FILE_NAME}
  2159. make %{?_smp_mflags}" # %{?_smp_mflags} -> -j option
  2160. )
  2161. set(TMP_RPM_INSTALL
  2162. "
  2163. cd cpack_rpm_build_dir
  2164. cpack -G RPM
  2165. mv *.rpm %_rpmdir"
  2166. )
  2167. set(TMP_RPM_PREP "%setup -c")
  2168. set(RPMBUILD_FLAGS "-bs")
  2169. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2170. "# -*- rpm-spec -*-
  2171. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@
  2172. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2173. Name: \@CPACK_RPM_PACKAGE_NAME\@
  2174. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2175. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2176. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2177. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2178. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2179. \@TMP_RPM_SOURCE\@
  2180. \@TMP_RPM_BUILD_REQUIRES\@
  2181. \@TMP_RPM_BUILDARCH\@
  2182. \@TMP_RPM_PREFIXES\@
  2183. \@TMP_RPM_DISABLE_DEBUGINFO\@
  2184. %define _rpmdir %_topdir/RPMS
  2185. %define _srcrpmdir %_topdir/SRPMS
  2186. \@FILE_NAME_DEFINE\@
  2187. %define _unpackaged_files_terminate_build 0
  2188. \@TMP_RPM_SPEC_INSTALL_POST\@
  2189. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  2190. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  2191. %description
  2192. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2193. # This is a shortcutted spec file generated by CMake RPM generator
  2194. # we skip _install step because CPack does that for us.
  2195. # We do only save CPack installed tree in _prepr
  2196. # and then restore it in build.
  2197. %prep
  2198. \@TMP_RPM_PREP\@
  2199. \@TMP_RPM_BUILD\@
  2200. #p build
  2201. %install
  2202. \@TMP_RPM_INSTALL\@
  2203. %clean
  2204. %changelog
  2205. \@CPACK_RPM_SPEC_CHANGELOG\@
  2206. "
  2207. )
  2208. elseif(GENERATE_SPEC_PARTS) # binary rpm with single debuginfo package
  2209. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2210. "# -*- rpm-spec -*-
  2211. %package -n \@CPACK_RPM_PACKAGE_NAME\@
  2212. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2213. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2214. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2215. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2216. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2217. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2218. \@TMP_RPM_URL\@
  2219. \@TMP_RPM_REQUIRES\@
  2220. \@TMP_RPM_REQUIRES_PRE\@
  2221. \@TMP_RPM_REQUIRES_POST\@
  2222. \@TMP_RPM_REQUIRES_PREUN\@
  2223. \@TMP_RPM_REQUIRES_POSTUN\@
  2224. \@TMP_RPM_PROVIDES\@
  2225. \@TMP_RPM_OBSOLETES\@
  2226. \@TMP_RPM_CONFLICTS\@
  2227. \@TMP_RPM_SUGGESTS\@
  2228. \@TMP_RPM_AUTOPROV\@
  2229. \@TMP_RPM_AUTOREQ\@
  2230. \@TMP_RPM_AUTOREQPROV\@
  2231. \@TMP_RPM_BUILDARCH\@
  2232. \@TMP_RPM_PREFIXES\@
  2233. %description -n \@CPACK_RPM_PACKAGE_NAME\@
  2234. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2235. %files -n \@CPACK_RPM_PACKAGE_NAME\@
  2236. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  2237. \@CPACK_RPM_INSTALL_FILES\@
  2238. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  2239. \@CPACK_RPM_USER_INSTALL_FILES\@
  2240. "
  2241. )
  2242. else() # binary rpm
  2243. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  2244. # find generated spec file and take its name
  2245. file(GLOB spec_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.spec")
  2246. foreach(f_ IN LISTS spec_files_)
  2247. file(READ "${f_}" tmp_)
  2248. string(APPEND TMP_OTHER_COMPONENTS "\n${tmp_}\n")
  2249. endforeach()
  2250. endif()
  2251. # We should generate a USER spec file template:
  2252. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  2253. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  2254. set(RPMBUILD_FLAGS "-bb")
  2255. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  2256. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2257. "# -*- rpm-spec -*-
  2258. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
  2259. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2260. Name: \@CPACK_RPM_PACKAGE_NAME\@
  2261. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2262. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2263. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2264. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2265. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2266. \@TMP_RPM_URL\@
  2267. \@TMP_RPM_REQUIRES\@
  2268. \@TMP_RPM_REQUIRES_PRE\@
  2269. \@TMP_RPM_REQUIRES_POST\@
  2270. \@TMP_RPM_REQUIRES_PREUN\@
  2271. \@TMP_RPM_REQUIRES_POSTUN\@
  2272. \@TMP_RPM_PROVIDES\@
  2273. \@TMP_RPM_OBSOLETES\@
  2274. \@TMP_RPM_CONFLICTS\@
  2275. \@TMP_RPM_SUGGESTS\@
  2276. \@TMP_RPM_AUTOPROV\@
  2277. \@TMP_RPM_AUTOREQ\@
  2278. \@TMP_RPM_AUTOREQPROV\@
  2279. \@TMP_RPM_BUILDARCH\@
  2280. \@TMP_RPM_PREFIXES\@
  2281. \@TMP_RPM_DEBUGINFO\@
  2282. %define _rpmdir %_topdir/RPMS
  2283. %define _srcrpmdir %_topdir/SRPMS
  2284. \@FILE_NAME_DEFINE\@
  2285. %define _unpackaged_files_terminate_build 0
  2286. \@TMP_RPM_SPEC_INSTALL_POST\@
  2287. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  2288. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  2289. %description
  2290. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2291. # This is a shortcutted spec file generated by CMake RPM generator
  2292. # we skip _install step because CPack does that for us.
  2293. # We do only save CPack installed tree in _prepr
  2294. # and then restore it in build.
  2295. %prep
  2296. mv $RPM_BUILD_ROOT %_topdir/tmpBBroot
  2297. %install
  2298. if [ -e $RPM_BUILD_ROOT ];
  2299. then
  2300. rm -rf $RPM_BUILD_ROOT
  2301. fi
  2302. mv %_topdir/tmpBBroot $RPM_BUILD_ROOT
  2303. \@TMP_RPM_DEBUGINFO_INSTALL\@
  2304. %clean
  2305. %post
  2306. \@RPM_SYMLINK_POSTINSTALL\@
  2307. \@CPACK_RPM_SPEC_POSTINSTALL\@
  2308. %postun
  2309. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  2310. %pre
  2311. \@CPACK_RPM_SPEC_PREINSTALL\@
  2312. %preun
  2313. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  2314. %files
  2315. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  2316. \@CPACK_RPM_INSTALL_FILES\@
  2317. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  2318. \@CPACK_RPM_USER_INSTALL_FILES\@
  2319. %changelog
  2320. \@CPACK_RPM_SPEC_CHANGELOG\@
  2321. \@TMP_OTHER_COMPONENTS\@
  2322. "
  2323. )
  2324. endif()
  2325. # Stop here if we were asked to only generate a template USER spec file
  2326. # The generated file may then be used as a template by user who wants
  2327. # to customize their own spec file.
  2328. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  2329. message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file template is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  2330. endif()
  2331. endif()
  2332. # After that we may either use a user provided spec file
  2333. # or generate one using appropriate variables value.
  2334. if(CPACK_RPM_USER_BINARY_SPECFILE)
  2335. # User may have specified SPECFILE just use it
  2336. message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  2337. # The user provided file is processed for @var replacement
  2338. configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  2339. else()
  2340. # No User specified spec file, will use the generated spec file
  2341. message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  2342. # Note the just created file is processed for @var replacement
  2343. configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  2344. endif()
  2345. if(NOT GENERATE_SPEC_PARTS) # generate package
  2346. if(RPMBUILD_EXECUTABLE)
  2347. # Now call rpmbuild using the SPECFILE
  2348. execute_process(
  2349. COMMAND "${RPMBUILD_EXECUTABLE}" ${RPMBUILD_FLAGS}
  2350. --define "_topdir ${CPACK_RPM_DIRECTORY}"
  2351. --buildroot "%_topdir/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  2352. --target "${CPACK_RPM_PACKAGE_ARCHITECTURE}"
  2353. "${CPACK_RPM_BINARY_SPECFILE}"
  2354. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  2355. RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
  2356. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err"
  2357. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  2358. if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  2359. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR)
  2360. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT)
  2361. message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  2362. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err")
  2363. message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  2364. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  2365. message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***")
  2366. endif()
  2367. else()
  2368. if(ALIEN_EXECUTABLE)
  2369. message(FATAL_ERROR "RPM packaging through alien not done (yet)")
  2370. endif()
  2371. endif()
  2372. # find generated rpm files and take their names
  2373. cmake_policy(PUSH)
  2374. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  2375. # even if the project does not set this policy to NEW.
  2376. cmake_policy(SET CMP0009 NEW)
  2377. file(GLOB_RECURSE GENERATED_FILES "${CPACK_RPM_DIRECTORY}/RPMS/*.rpm"
  2378. "${CPACK_RPM_DIRECTORY}/SRPMS/*.rpm")
  2379. cmake_policy(POP)
  2380. if(NOT GENERATED_FILES)
  2381. message(FATAL_ERROR "RPM package was not generated! ${CPACK_RPM_DIRECTORY}")
  2382. endif()
  2383. unset(expected_filenames_)
  2384. unset(filenames_)
  2385. if(CPACK_RPM_DEBUGINFO_PACKAGE AND NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  2386. string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" efn_)
  2387. list(APPEND expected_filenames_ "${efn_}")
  2388. list(APPEND filenames_ "${CPACK_RPM_FILE_NAME}")
  2389. endif()
  2390. # check if other files have to be renamed
  2391. file(GLOB rename_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.rpm_name")
  2392. if(rename_files_)
  2393. foreach(f_ IN LISTS rename_files_)
  2394. file(READ "${f_}" tmp_)
  2395. list(GET tmp_ 0 efn_)
  2396. list(APPEND expected_filenames_ "${efn_}")
  2397. list(GET tmp_ 1 fn_)
  2398. list(APPEND filenames_ "${fn_}")
  2399. endforeach()
  2400. endif()
  2401. if(expected_filenames_)
  2402. foreach(F IN LISTS GENERATED_FILES)
  2403. unset(matched_)
  2404. foreach(expected_ IN LISTS expected_filenames_)
  2405. if(F MATCHES ".*/${expected_}")
  2406. list(FIND expected_filenames_ "${expected_}" idx_)
  2407. list(GET filenames_ ${idx_} filename_)
  2408. get_filename_component(FILE_PATH "${F}" DIRECTORY)
  2409. file(RENAME "${F}" "${FILE_PATH}/${filename_}")
  2410. list(APPEND new_files_list_ "${FILE_PATH}/${filename_}")
  2411. set(matched_ "YES")
  2412. break()
  2413. endif()
  2414. endforeach()
  2415. if(NOT matched_)
  2416. list(APPEND new_files_list_ "${F}")
  2417. endif()
  2418. endforeach()
  2419. set(GENERATED_FILES "${new_files_list_}")
  2420. endif()
  2421. endif()
  2422. set(GEN_CPACK_OUTPUT_FILES "${GENERATED_FILES}" PARENT_SCOPE)
  2423. if(CPACK_RPM_PACKAGE_DEBUG)
  2424. message("CPackRPM:Debug: GEN_CPACK_OUTPUT_FILES = ${GENERATED_FILES}")
  2425. endif()
  2426. endfunction()
  2427. cpack_rpm_generate_package()