CPackRPM.cmake 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694
  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. # .. note::
  724. #
  725. # Currently multiple debuginfo packages are generated if component based
  726. # packaging is used - one debuginfo package per component. This duplicates
  727. # sources if multiple binaries are using them. This is a side effect of
  728. # how CPackRPM currently generates component packages and will be addressed
  729. # in later versions of the generator.
  730. #
  731. # Debuginfo RPM packaging has it's own set of variables:
  732. #
  733. # .. variable:: CPACK_RPM_DEBUGINFO_PACKAGE
  734. # CPACK_RPM_<component>_DEBUGINFO_PACKAGE
  735. #
  736. # Enable generation of debuginfo RPM package(s).
  737. #
  738. # * Mandatory : NO
  739. # * Default : OFF
  740. #
  741. # .. note::
  742. #
  743. # Binaries must contain debug symbols before packaging so use either ``Debug``
  744. # or ``RelWithDebInfo`` for :variable:`CMAKE_BUILD_TYPE` variable value.
  745. #
  746. # .. note::
  747. #
  748. # Packages generated from packages without binary files, with binary files but
  749. # without execute permissions or without debug symbols will be empty.
  750. #
  751. # .. variable:: CPACK_BUILD_SOURCE_DIRS
  752. #
  753. # Provides locations of root directories of source files from which binaries
  754. # were built.
  755. #
  756. # * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set
  757. # * Default : -
  758. #
  759. # .. note::
  760. #
  761. # For CMake project :variable:`CPACK_BUILD_SOURCE_DIRS` is set by default to
  762. # point to :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR` paths.
  763. #
  764. # .. note::
  765. #
  766. # Sources with path prefixes that do not fall under any location provided with
  767. # :variable:`CPACK_BUILD_SOURCE_DIRS` will not be present in debuginfo package.
  768. #
  769. # .. variable:: CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX
  770. # CPACK_RPM_<component>_BUILD_SOURCE_DIRS_PREFIX
  771. #
  772. # Prefix of location where sources will be placed during package installation.
  773. #
  774. # * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set
  775. # * Default : "/usr/src/debug/<CPACK_PACKAGE_FILE_NAME>" and
  776. # for component packaging "/usr/src/debug/<CPACK_PACKAGE_FILE_NAME>-<component>"
  777. #
  778. # .. note::
  779. #
  780. # Each source path prefix is additionaly suffixed by ``src_<index>`` where
  781. # index is index of the path used from :variable:`CPACK_BUILD_SOURCE_DIRS`
  782. # variable. This produces ``<CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX>/src_<index>``
  783. # replacement path.
  784. # Limitation is that replaced path part must be shorter or of equal
  785. # length than the length of its replacement. If that is not the case either
  786. # :variable:`CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX` variable has to be set to
  787. # a shorter path or source directories must be placed on a longer path.
  788. #
  789. # .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS
  790. #
  791. # Directories containing sources that should be excluded from debuginfo packages.
  792. #
  793. # * Mandatory : NO
  794. # * Default : "/usr /usr/src /usr/src/debug"
  795. #
  796. # Listed paths are owned by other RPM packages and should therefore not be
  797. # deleted on debuginfo package uninstallation.
  798. #
  799. # .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION
  800. #
  801. # Paths that should be appended to :variable:`CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS`
  802. # for exclusion.
  803. #
  804. # * Mandatory : NO
  805. # * Default : -
  806. #
  807. # .. variable:: CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE
  808. #
  809. # Create a single debuginfo package even if components packaging is set.
  810. #
  811. # * Mandatory : NO
  812. # * Default : OFF
  813. #
  814. # When this variable is enabled it produces a single debuginfo package even if
  815. # component packaging is enabled.
  816. #
  817. # When using this feature in combination with components packaging and there is
  818. # more than one component this variable requires :variable:`CPACK_RPM_MAIN_COMPONENT`
  819. # to be set.
  820. #
  821. # .. note::
  822. #
  823. # If none of the :variable:`CPACK_RPM_<component>_DEBUGINFO_PACKAGE` variables
  824. # is set then :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is automatically set to
  825. # ``ON`` when :variable:`CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE` is set.
  826. #
  827. # Packaging of sources (SRPM)
  828. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  829. #
  830. # SRPM packaging is enabled by setting :variable:`CPACK_RPM_PACKAGE_SOURCES`
  831. # variable while usually using :variable:`CPACK_INSTALLED_DIRECTORIES` variable
  832. # to provide directory containing CMakeLists.txt and source files.
  833. #
  834. # For CMake projects SRPM package would be product by executing:
  835. #
  836. # ``cpack -G RPM --config ./CPackSourceConfig.cmake``
  837. #
  838. # .. note::
  839. #
  840. # Produced SRPM package is expected to be built with :manual:`cmake(1)` executable
  841. # and packaged with :manual:`cpack(1)` executable so CMakeLists.txt has to be
  842. # located in root source directory and must be able to generate binary rpm
  843. # packages by executing ``cpack -G`` command. The two executables as well as
  844. # rpmbuild must also be present when generating binary rpm packages from the
  845. # produced SRPM package.
  846. #
  847. # Once the SRPM package is generated it can be used to generate binary packages
  848. # by creating a directory structure for rpm generation and executing rpmbuild
  849. # tool:
  850. #
  851. # ``mkdir -p build_dir/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}``
  852. # ``rpmbuild --define "_topdir <path_to_build_dir>" --rebuild <SRPM_file_name>``
  853. #
  854. # Generated packages will be located in build_dir/RPMS directory or its sub
  855. # directories.
  856. #
  857. # .. note::
  858. #
  859. # SRPM package internally uses CPack/RPM generator to generate binary packages
  860. # so CMakeScripts.txt can decide during the SRPM to binary rpm generation step
  861. # what content the package(s) should have as well as how they should be packaged
  862. # (monolithic or components). CMake can decide this for e.g. by reading environment
  863. # variables set by the package manager before starting the process of generating
  864. # binary rpm packages. This way a single SRPM package can be used to produce
  865. # different binary rpm packages on different platforms depending on the platform's
  866. # packaging rules.
  867. #
  868. # Source RPM packaging has it's own set of variables:
  869. #
  870. # .. variable:: CPACK_RPM_PACKAGE_SOURCES
  871. #
  872. # Should the content be packaged as a source rpm (default is binary rpm).
  873. #
  874. # * Mandatory : NO
  875. # * Default : OFF
  876. #
  877. # .. note::
  878. #
  879. # For cmake projects :variable:`CPACK_RPM_PACKAGE_SOURCES` variable is set
  880. # to ``OFF`` in CPackConfig.cmake and ``ON`` in CPackSourceConfig.cmake
  881. # generated files.
  882. #
  883. # .. variable:: CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
  884. #
  885. # Additional command-line parameters provided to :manual:`cmake(1)` executable.
  886. #
  887. # * Mandatory : NO
  888. # * Default : -
  889. #
  890. # .. variable:: CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX
  891. #
  892. # Packaging install prefix that would be provided in :variable:`CPACK_PACKAGING_INSTALL_PREFIX`
  893. # variable for producing binary RPM packages.
  894. #
  895. # * Mandatory : YES
  896. # * Default : "/"
  897. # Author: Eric Noulard with the help of Alexander Neundorf.
  898. function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR)
  899. set(PERMISSIONS ${${PERMISSIONS_VAR}})
  900. list(LENGTH PERMISSIONS PERM_LEN_PRE)
  901. list(REMOVE_DUPLICATES PERMISSIONS)
  902. list(LENGTH PERMISSIONS PERM_LEN_POST)
  903. if(NOT ${PERM_LEN_PRE} EQUAL ${PERM_LEN_POST})
  904. message(FATAL_ERROR "${PERMISSIONS_VAR} contains duplicate values.")
  905. endif()
  906. foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD")
  907. set(${PERMISSION_TYPE}_PERMISSIONS 0)
  908. foreach(PERMISSION ${PERMISSIONS})
  909. if("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_READ")
  910. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 4")
  911. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_WRITE")
  912. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 2")
  913. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_EXECUTE")
  914. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 1")
  915. elseif(PERMISSION MATCHES "${PERMISSION_TYPE}.*")
  916. message(FATAL_ERROR "${PERMISSIONS_VAR} contains invalid values.")
  917. endif()
  918. endforeach()
  919. endforeach()
  920. set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE)
  921. endfunction()
  922. function(cpack_rpm_prepare_relocation_paths)
  923. # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes
  924. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX)
  925. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX}" PATH_PREFIX)
  926. elseif(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX)
  927. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX}" PATH_PREFIX)
  928. else()
  929. file(TO_CMAKE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}" PATH_PREFIX)
  930. endif()
  931. set(RPM_RELOCATION_PATHS "${CPACK_RPM_RELOCATION_PATHS}")
  932. list(REMOVE_DUPLICATES RPM_RELOCATION_PATHS)
  933. # set base path prefix
  934. if(EXISTS "${WDIR}/${PATH_PREFIX}")
  935. if(NOT CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION AND
  936. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT}_INSTALL_PREFIX_RELOCATION AND
  937. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_INSTALL_PREFIX_RELOCATION)
  938. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PATH_PREFIX}\n")
  939. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PATH_PREFIX}")
  940. if(CPACK_RPM_PACKAGE_DEBUG)
  941. message("CPackRPM:Debug: removing '${PATH_PREFIX}' from relocation paths")
  942. endif()
  943. endif()
  944. endif()
  945. # set other path prefixes
  946. foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS})
  947. if(IS_ABSOLUTE "${RELOCATION_PATH}")
  948. set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}")
  949. elseif(PATH_PREFIX STREQUAL "/")
  950. # don't prefix path with a second slash as "//" is treated as network path
  951. # by get_filename_component() so it remains in path even inside rpm
  952. # package where it may cause problems with relocation
  953. set(PREPARED_RELOCATION_PATH "/${RELOCATION_PATH}")
  954. else()
  955. set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}")
  956. endif()
  957. # handle cases where path contains extra slashes (e.g. /a//b/ instead of
  958. # /a/b)
  959. get_filename_component(PREPARED_RELOCATION_PATH
  960. "${PREPARED_RELOCATION_PATH}" ABSOLUTE)
  961. if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}")
  962. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n")
  963. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}")
  964. endif()
  965. endforeach()
  966. # warn about all the paths that are not relocatable
  967. cmake_policy(PUSH)
  968. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  969. # even if the project does not set this policy to NEW.
  970. cmake_policy(SET CMP0009 NEW)
  971. file(GLOB_RECURSE FILE_PATHS_ "${WDIR}/*")
  972. cmake_policy(POP)
  973. foreach(TMP_PATH ${FILE_PATHS_})
  974. string(LENGTH "${WDIR}" WDIR_LEN)
  975. string(SUBSTRING "${TMP_PATH}" ${WDIR_LEN} -1 TMP_PATH)
  976. unset(TMP_PATH_FOUND_)
  977. foreach(RELOCATION_PATH ${RPM_USED_PACKAGE_PREFIXES})
  978. file(RELATIVE_PATH REL_PATH_ "${RELOCATION_PATH}" "${TMP_PATH}")
  979. string(SUBSTRING "${REL_PATH_}" 0 2 PREFIX_)
  980. if(NOT "${PREFIX_}" STREQUAL "..")
  981. set(TPM_PATH_FOUND_ TRUE)
  982. break()
  983. endif()
  984. endforeach()
  985. if(NOT TPM_PATH_FOUND_)
  986. message(AUTHOR_WARNING "CPackRPM:Warning: Path ${TMP_PATH} is not on one of the relocatable paths! Package will be partially relocatable.")
  987. endif()
  988. endforeach()
  989. set(RPM_USED_PACKAGE_PREFIXES "${RPM_USED_PACKAGE_PREFIXES}" PARENT_SCOPE)
  990. set(TMP_RPM_PREFIXES "${TMP_RPM_PREFIXES}" PARENT_SCOPE)
  991. endfunction()
  992. function(cpack_rpm_prepare_content_list)
  993. # get files list
  994. cmake_policy(PUSH)
  995. cmake_policy(SET CMP0009 NEW)
  996. file(GLOB_RECURSE CPACK_RPM_INSTALL_FILES LIST_DIRECTORIES true RELATIVE "${WDIR}" "${WDIR}/*")
  997. cmake_policy(POP)
  998. set(CPACK_RPM_INSTALL_FILES "/${CPACK_RPM_INSTALL_FILES}")
  999. string(REPLACE ";" ";/" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}")
  1000. # if we are creating a relocatable package, omit parent directories of
  1001. # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
  1002. # which is passed to the find command that generates the content-list
  1003. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  1004. # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are
  1005. # destinct parent paths of other relocation paths and remove the
  1006. # final element (so the install-prefix dir itself is not omitted
  1007. # from the RPM's content-list)
  1008. list(SORT RPM_USED_PACKAGE_PREFIXES)
  1009. set(_DISTINCT_PATH "NOT_SET")
  1010. foreach(_RPM_RELOCATION_PREFIX ${RPM_USED_PACKAGE_PREFIXES})
  1011. if(NOT "${_RPM_RELOCATION_PREFIX}" MATCHES "${_DISTINCT_PATH}/.*")
  1012. set(_DISTINCT_PATH "${_RPM_RELOCATION_PREFIX}")
  1013. string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS " ${_RPM_RELOCATION_PREFIX}")
  1014. cmake_policy(PUSH)
  1015. cmake_policy(SET CMP0007 NEW)
  1016. list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
  1017. cmake_policy(POP)
  1018. unset(_TMP_LIST)
  1019. # Now generate all of the parent dirs of the relocation path
  1020. foreach(_PREFIX_PATH_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
  1021. list(APPEND _TMP_LIST "${_PREFIX_PATH_ELEM}")
  1022. string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
  1023. separate_arguments(_OMIT_DIR)
  1024. list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
  1025. endforeach()
  1026. endif()
  1027. endforeach()
  1028. endif()
  1029. if(CPACK_RPM_PACKAGE_DEBUG)
  1030. message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  1031. endif()
  1032. if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  1033. set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/libx32 /usr/include)
  1034. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
  1035. if(CPACK_RPM_PACKAGE_DEBUG)
  1036. message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
  1037. endif()
  1038. list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
  1039. endif()
  1040. endif()
  1041. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  1042. if(CPACK_RPM_PACKAGE_DEBUG)
  1043. message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
  1044. endif()
  1045. list(APPEND _RPM_DIRS_TO_OMIT ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
  1046. endif()
  1047. if(CPACK_RPM_PACKAGE_DEBUG)
  1048. message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  1049. endif()
  1050. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES ${_RPM_DIRS_TO_OMIT})
  1051. # add man paths that will be compressed
  1052. # (copied from /usr/lib/rpm/brp-compress - script that does the actual
  1053. # compressing)
  1054. list(APPEND MAN_LOCATIONS "/usr/man/man.*" "/usr/man/.*/man.*" "/usr/info.*"
  1055. "/usr/share/man/man.*" "/usr/share/man/.*/man.*" "/usr/share/info.*"
  1056. "/usr/kerberos/man.*" "/usr/X11R6/man/man.*" "/usr/lib/perl5/man/man.*"
  1057. "/usr/share/doc/.*/man/man.*" "/usr/lib/.*/man/man.*")
  1058. if(CPACK_RPM_ADDITIONAL_MAN_DIRS)
  1059. if(CPACK_RPM_PACKAGE_DEBUG)
  1060. message("CPackRPM:Debug: CPACK_RPM_ADDITIONAL_MAN_DIRS= ${CPACK_RPM_ADDITIONAL_MAN_DIRS}")
  1061. endif()
  1062. list(APPEND MAN_LOCATIONS ${CPACK_RPM_ADDITIONAL_MAN_DIRS})
  1063. endif()
  1064. foreach(PACK_LOCATION IN LISTS CPACK_RPM_INSTALL_FILES)
  1065. foreach(MAN_LOCATION IN LISTS MAN_LOCATIONS)
  1066. # man pages are files inside a certain location
  1067. if(PACK_LOCATION MATCHES "${MAN_LOCATION}/"
  1068. AND NOT IS_DIRECTORY "${WDIR}${PACK_LOCATION}"
  1069. AND NOT IS_SYMLINK "${WDIR}${PACK_LOCATION}")
  1070. list(FIND CPACK_RPM_INSTALL_FILES "${PACK_LOCATION}" INDEX)
  1071. # insert file location that covers compressed man pages
  1072. # even if using a wildcard causes duplicates as those are
  1073. # handled by RPM and we still keep the same file list
  1074. # in spec file - wildcard only represents file type (e.g. .gz)
  1075. list(INSERT CPACK_RPM_INSTALL_FILES ${INDEX} "${PACK_LOCATION}*")
  1076. # remove file location that doesn't cover compressed man pages
  1077. math(EXPR INDEX ${INDEX}+1)
  1078. list(REMOVE_AT CPACK_RPM_INSTALL_FILES ${INDEX})
  1079. break()
  1080. endif()
  1081. endforeach()
  1082. endforeach()
  1083. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}" PARENT_SCOPE)
  1084. endfunction()
  1085. function(cpack_rpm_symlink_get_relocation_prefixes LOCATION PACKAGE_PREFIXES RETURN_VARIABLE)
  1086. foreach(PKG_PREFIX IN LISTS PACKAGE_PREFIXES)
  1087. string(REGEX MATCH "^${PKG_PREFIX}/.*" FOUND_ "${LOCATION}")
  1088. if(FOUND_)
  1089. list(APPEND TMP_PREFIXES "${PKG_PREFIX}")
  1090. endif()
  1091. endforeach()
  1092. set(${RETURN_VARIABLE} "${TMP_PREFIXES}" PARENT_SCOPE)
  1093. endfunction()
  1094. function(cpack_rpm_symlink_create_relocation_script PACKAGE_PREFIXES)
  1095. list(LENGTH PACKAGE_PREFIXES LAST_INDEX)
  1096. set(SORTED_PACKAGE_PREFIXES "${PACKAGE_PREFIXES}")
  1097. list(SORT SORTED_PACKAGE_PREFIXES)
  1098. list(REVERSE SORTED_PACKAGE_PREFIXES)
  1099. math(EXPR LAST_INDEX ${LAST_INDEX}-1)
  1100. foreach(SYMLINK_INDEX RANGE ${LAST_INDEX})
  1101. list(GET SORTED_PACKAGE_PREFIXES ${SYMLINK_INDEX} SRC_PATH)
  1102. list(FIND PACKAGE_PREFIXES "${SRC_PATH}" SYMLINK_INDEX) # reverse magic
  1103. string(LENGTH "${SRC_PATH}" SRC_PATH_LEN)
  1104. set(PARTS_CNT 0)
  1105. set(SCRIPT_PART "if [ \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}\" != \"${SRC_PATH}\" ]; then\n")
  1106. # both paths relocated
  1107. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  1108. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  1109. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  1110. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  1111. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  1112. if("${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  1113. set(INDENT "")
  1114. else()
  1115. string(APPEND SCRIPT_PART " if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  1116. set(INDENT " ")
  1117. endif()
  1118. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  1119. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  1120. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1121. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1122. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1123. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  1124. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  1125. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN})
  1126. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1127. string(APPEND SCRIPT_PART " ${INDENT}if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1128. string(APPEND SCRIPT_PART " ${INDENT}ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  1129. string(APPEND SCRIPT_PART " ${INDENT}CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1130. string(APPEND SCRIPT_PART " ${INDENT}fi\n")
  1131. endforeach()
  1132. if(NOT "${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  1133. string(APPEND SCRIPT_PART " fi\n")
  1134. endif()
  1135. endif()
  1136. endforeach()
  1137. # source path relocated
  1138. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  1139. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  1140. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  1141. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1142. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1143. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1144. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  1145. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  1146. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  1147. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1148. string(APPEND SCRIPT_PART " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1149. string(APPEND SCRIPT_PART " ln -s \"${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  1150. string(APPEND SCRIPT_PART " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1151. string(APPEND SCRIPT_PART " fi\n")
  1152. endforeach()
  1153. endif()
  1154. if(PARTS_CNT)
  1155. set(SCRIPT "${SCRIPT_PART}")
  1156. string(APPEND SCRIPT "fi\n")
  1157. endif()
  1158. endforeach()
  1159. # point path relocated
  1160. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  1161. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  1162. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  1163. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  1164. if(_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  1165. string(APPEND SCRIPT "if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  1166. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  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+${POINT_PATH_LEN})
  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 \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"${SYMLINK_}\"\n")
  1175. string(APPEND SCRIPT " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  1176. string(APPEND SCRIPT " fi\n")
  1177. endforeach()
  1178. string(APPEND SCRIPT "fi\n")
  1179. endif()
  1180. endforeach()
  1181. # no path relocated
  1182. if(_RPM_RELOCATION_SCRIPT_X_X)
  1183. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_X)
  1184. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  1185. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  1186. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  1187. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_)
  1188. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  1189. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  1190. string(APPEND SCRIPT "if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  1191. string(APPEND SCRIPT " ln -s \"${POINT_}\" \"${SYMLINK_}\"\n")
  1192. string(APPEND SCRIPT "fi\n")
  1193. endforeach()
  1194. endif()
  1195. set(RPM_SYMLINK_POSTINSTALL "${SCRIPT}" PARENT_SCOPE)
  1196. endfunction()
  1197. function(cpack_rpm_symlink_add_for_relocation_script PACKAGE_PREFIXES SYMLINK SYMLINK_RELOCATION_PATHS POINT POINT_RELOCATION_PATHS)
  1198. list(LENGTH SYMLINK_RELOCATION_PATHS SYMLINK_PATHS_COUTN)
  1199. list(LENGTH POINT_RELOCATION_PATHS POINT_PATHS_COUNT)
  1200. list(APPEND _RPM_RELOCATION_SCRIPT_PAIRS "${SYMLINK}:${POINT}")
  1201. list(LENGTH _RPM_RELOCATION_SCRIPT_PAIRS PAIR_NO)
  1202. if(SYMLINK_PATHS_COUTN)
  1203. foreach(SYMLINK_RELOC_PATH IN LISTS SYMLINK_RELOCATION_PATHS)
  1204. list(FIND PACKAGE_PREFIXES "${SYMLINK_RELOC_PATH}" SYMLINK_INDEX)
  1205. # source path relocated
  1206. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X "${PAIR_NO}")
  1207. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X")
  1208. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  1209. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  1210. # both paths relocated
  1211. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX} "${PAIR_NO}")
  1212. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}")
  1213. # point path relocated
  1214. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  1215. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  1216. endforeach()
  1217. endforeach()
  1218. elseif(POINT_PATHS_COUNT)
  1219. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  1220. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  1221. # point path relocated
  1222. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  1223. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  1224. endforeach()
  1225. endif()
  1226. # no path relocated
  1227. list(APPEND _RPM_RELOCATION_SCRIPT_X_X "${PAIR_NO}")
  1228. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_X")
  1229. # place variables into parent scope
  1230. foreach(VAR IN LISTS RELOCATION_VARS)
  1231. set(${VAR} "${${VAR}}" PARENT_SCOPE)
  1232. endforeach()
  1233. set(_RPM_RELOCATION_SCRIPT_PAIRS "${_RPM_RELOCATION_SCRIPT_PAIRS}" PARENT_SCOPE)
  1234. set(REQUIRES_SYMLINK_RELOCATION_SCRIPT "true" PARENT_SCOPE)
  1235. set(DIRECTIVE "%ghost " PARENT_SCOPE)
  1236. endfunction()
  1237. function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXES IS_RELOCATABLE)
  1238. # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
  1239. # This is necessary to avoid duplicate files since rpmbuild does
  1240. # recursion on its own when encountering a pathname which is a directory
  1241. # which is not flagged as %dir
  1242. string(STRIP "${INSTALL_FILES_LIST}" INSTALL_FILES_LIST)
  1243. string(REPLACE "\n" ";" INSTALL_FILES_LIST
  1244. "${INSTALL_FILES_LIST}")
  1245. string(REPLACE "\"" "" INSTALL_FILES_LIST
  1246. "${INSTALL_FILES_LIST}")
  1247. string(LENGTH "${WDIR}" WDR_LEN_)
  1248. list(SORT INSTALL_FILES_LIST) # make file order consistent on all platforms
  1249. foreach(F IN LISTS INSTALL_FILES_LIST)
  1250. unset(DIRECTIVE)
  1251. if(IS_SYMLINK "${WDIR}/${F}")
  1252. if(IS_RELOCATABLE)
  1253. # check that symlink has relocatable format
  1254. get_filename_component(SYMLINK_LOCATION_ "${WDIR}/${F}" DIRECTORY)
  1255. execute_process(COMMAND ls -la "${WDIR}/${F}"
  1256. WORKING_DIRECTORY "${WDIR}"
  1257. OUTPUT_VARIABLE SYMLINK_POINT_
  1258. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1259. string(FIND "${SYMLINK_POINT_}" "->" SYMLINK_POINT_INDEX_ REVERSE)
  1260. math(EXPR SYMLINK_POINT_INDEX_ ${SYMLINK_POINT_INDEX_}+3)
  1261. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  1262. # get destination path
  1263. string(SUBSTRING "${SYMLINK_POINT_}" ${SYMLINK_POINT_INDEX_} ${SYMLINK_POINT_LENGTH_} SYMLINK_POINT_)
  1264. # check if path is relative or absolute
  1265. string(SUBSTRING "${SYMLINK_POINT_}" 0 1 SYMLINK_IS_ABSOLUTE_)
  1266. if(${SYMLINK_IS_ABSOLUTE_} STREQUAL "/")
  1267. # prevent absolute paths from having /../ or /./ section inside of them
  1268. get_filename_component(SYMLINK_POINT_ "${SYMLINK_POINT_}" ABSOLUTE)
  1269. else()
  1270. # handle relative path
  1271. get_filename_component(SYMLINK_POINT_ "${SYMLINK_LOCATION_}/${SYMLINK_POINT_}" ABSOLUTE)
  1272. endif()
  1273. # recalculate path length after conversion to canonical form
  1274. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  1275. if(SYMLINK_POINT_ MATCHES "${WDIR}/.*")
  1276. # only symlinks that are pointing inside the packaging structure should be checked for relocation
  1277. string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_)
  1278. cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS")
  1279. cpack_rpm_symlink_get_relocation_prefixes("${SYMLINK_POINT_WD_}" "${PACKAGE_PREFIXES}" "POINT_RELOCATIONS")
  1280. list(LENGTH SYMLINK_RELOCATIONS SYMLINK_RELOCATIONS_COUNT)
  1281. list(LENGTH POINT_RELOCATIONS POINT_RELOCATIONS_COUNT)
  1282. else()
  1283. # location pointed to is ouside WDR so it should be treated as a permanent symlink
  1284. set(SYMLINK_POINT_WD_ "${SYMLINK_POINT_}")
  1285. unset(SYMLINK_RELOCATIONS)
  1286. unset(POINT_RELOCATIONS)
  1287. unset(SYMLINK_RELOCATIONS_COUNT)
  1288. unset(POINT_RELOCATIONS_COUNT)
  1289. message(AUTHOR_WARNING "CPackRPM:Warning: Symbolic link '${F}' points to location that is outside packaging path! Link will possibly not be relocatable.")
  1290. endif()
  1291. if(SYMLINK_RELOCATIONS_COUNT AND POINT_RELOCATIONS_COUNT)
  1292. # find matching
  1293. foreach(SYMLINK_RELOCATION_PREFIX IN LISTS SYMLINK_RELOCATIONS)
  1294. list(FIND POINT_RELOCATIONS "${SYMLINK_RELOCATION_PREFIX}" FOUND_INDEX)
  1295. if(NOT ${FOUND_INDEX} EQUAL -1)
  1296. break()
  1297. endif()
  1298. endforeach()
  1299. if(NOT ${FOUND_INDEX} EQUAL -1)
  1300. # symlinks have the same subpath
  1301. if(${SYMLINK_RELOCATIONS_COUNT} EQUAL 1 AND ${POINT_RELOCATIONS_COUNT} EQUAL 1)
  1302. # permanent symlink
  1303. get_filename_component(SYMLINK_LOCATION_ "${F}" DIRECTORY)
  1304. file(RELATIVE_PATH FINAL_PATH_ ${SYMLINK_LOCATION_} ${SYMLINK_POINT_WD_})
  1305. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${FINAL_PATH_}" "${WDIR}/${F}")
  1306. else()
  1307. # relocation subpaths
  1308. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1309. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1310. endif()
  1311. else()
  1312. # not on the same relocation path
  1313. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1314. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1315. endif()
  1316. elseif(POINT_RELOCATIONS_COUNT)
  1317. # point is relocatable
  1318. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  1319. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  1320. else()
  1321. # is not relocatable or points to non relocatable path - permanent symlink
  1322. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${SYMLINK_POINT_WD_}" "${WDIR}/${F}")
  1323. endif()
  1324. endif()
  1325. elseif(IS_DIRECTORY "${WDIR}/${F}")
  1326. set(DIRECTIVE "%dir ")
  1327. endif()
  1328. string(APPEND INSTALL_FILES "${DIRECTIVE}\"${F}\"\n")
  1329. endforeach()
  1330. if(REQUIRES_SYMLINK_RELOCATION_SCRIPT)
  1331. cpack_rpm_symlink_create_relocation_script("${PACKAGE_PREFIXES}")
  1332. endif()
  1333. set(RPM_SYMLINK_POSTINSTALL "${RPM_SYMLINK_POSTINSTALL}" PARENT_SCOPE)
  1334. set(CPACK_RPM_INSTALL_FILES "${INSTALL_FILES}" PARENT_SCOPE)
  1335. endfunction()
  1336. if(CMAKE_BINARY_DIR)
  1337. message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  1338. endif()
  1339. if(NOT UNIX)
  1340. message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  1341. endif()
  1342. # We need to check if the binaries were compiled with debug symbols
  1343. # because without them the package will be useless
  1344. function(cpack_rpm_debugsymbol_check INSTALL_FILES WORKING_DIR)
  1345. if(NOT CPACK_BUILD_SOURCE_DIRS)
  1346. message(FATAL_ERROR "CPackRPM: CPACK_BUILD_SOURCE_DIRS variable is not set!"
  1347. " Required for debuginfo packaging. See documentation of"
  1348. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1349. endif()
  1350. # With objdump we should check the debug symbols
  1351. find_program(OBJDUMP_EXECUTABLE objdump)
  1352. if(NOT OBJDUMP_EXECUTABLE)
  1353. message(FATAL_ERROR "CPackRPM: objdump binary could not be found!"
  1354. " Required for debuginfo packaging. See documentation of"
  1355. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1356. endif()
  1357. # With debugedit we prepare source files list
  1358. find_program(DEBUGEDIT_EXECUTABLE debugedit "/usr/lib/rpm/")
  1359. if(NOT DEBUGEDIT_EXECUTABLE)
  1360. message(FATAL_ERROR "CPackRPM: debugedit binary could not be found!"
  1361. " Required for debuginfo packaging. See documentation of"
  1362. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1363. endif()
  1364. unset(mkdir_list_)
  1365. unset(cp_list_)
  1366. unset(additional_sources_)
  1367. foreach(F IN LISTS INSTALL_FILES)
  1368. if(IS_DIRECTORY "${WORKING_DIR}/${F}" OR IS_SYMLINK "${WORKING_DIR}/${F}")
  1369. continue()
  1370. endif()
  1371. execute_process(COMMAND "${OBJDUMP_EXECUTABLE}" -h ${WORKING_DIR}/${F}
  1372. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}"
  1373. RESULT_VARIABLE OBJDUMP_EXEC_RESULT
  1374. OUTPUT_VARIABLE OBJDUMP_OUT
  1375. ERROR_QUIET)
  1376. # Check that if the given file was executable or not
  1377. if(NOT OBJDUMP_EXEC_RESULT)
  1378. string(FIND "${OBJDUMP_OUT}" "debug" FIND_RESULT)
  1379. if(FIND_RESULT GREATER -1)
  1380. set(index_ 0)
  1381. foreach(source_dir_ IN LISTS CPACK_BUILD_SOURCE_DIRS)
  1382. string(LENGTH "${source_dir_}" source_dir_len_)
  1383. string(LENGTH "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" debuginfo_dir_len)
  1384. if(source_dir_len_ LESS debuginfo_dir_len)
  1385. message(FATAL_ERROR "CPackRPM: source dir path '${source_dir_}' is"
  1386. " longer than debuginfo sources dir path '${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}'!"
  1387. " Source dir path must be shorter than debuginfo sources dir path."
  1388. " Set CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX variable to a shorter value"
  1389. " or make source dir path longer."
  1390. " Required for debuginfo packaging. See documentation of"
  1391. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  1392. endif()
  1393. file(REMOVE "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list")
  1394. 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}"
  1395. RESULT_VARIABLE res_
  1396. OUTPUT_VARIABLE opt_
  1397. ERROR_VARIABLE err_
  1398. )
  1399. file(STRINGS
  1400. "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list"
  1401. sources_)
  1402. list(REMOVE_DUPLICATES sources_)
  1403. foreach(source_ IN LISTS sources_)
  1404. if(EXISTS "${source_dir_}/${source_}" AND NOT IS_DIRECTORY "${source_dir_}/${source_}")
  1405. get_filename_component(path_part_ "${source_}" DIRECTORY)
  1406. list(APPEND mkdir_list_ "%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}")
  1407. list(APPEND cp_list_ "cp \"${source_dir_}/${source_}\" \"%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}\"")
  1408. list(APPEND additional_sources_ "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${source_}")
  1409. endif()
  1410. endforeach()
  1411. math(EXPR index_ "${index_} + 1")
  1412. endforeach()
  1413. else()
  1414. message(WARNING "CPackRPM: File: ${F} does not contain debug symbols. They will possibly be missing from debuginfo package!")
  1415. endif()
  1416. endif()
  1417. endforeach()
  1418. list(LENGTH mkdir_list_ len_)
  1419. if(len_)
  1420. list(REMOVE_DUPLICATES mkdir_list_)
  1421. unset(TMP_RPM_DEBUGINFO_INSTALL)
  1422. foreach(part_ IN LISTS mkdir_list_)
  1423. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "mkdir -p \"${part_}\"\n")
  1424. endforeach()
  1425. endif()
  1426. list(LENGTH cp_list_ len_)
  1427. if(len_)
  1428. list(REMOVE_DUPLICATES cp_list_)
  1429. foreach(part_ IN LISTS cp_list_)
  1430. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "${part_}\n")
  1431. endforeach()
  1432. endif()
  1433. if(NOT DEFINED CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS)
  1434. set(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS /usr /usr/src /usr/src/debug)
  1435. if(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION)
  1436. if(CPACK_RPM_PACKAGE_DEBUG)
  1437. message("CPackRPM:Debug: Adding ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION} to builtin omit list.")
  1438. endif()
  1439. list(APPEND CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS "${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION}")
  1440. endif()
  1441. endif()
  1442. if(CPACK_RPM_PACKAGE_DEBUG)
  1443. message("CPackRPM:Debug: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS= ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}")
  1444. endif()
  1445. list(LENGTH additional_sources_ len_)
  1446. if(len_)
  1447. list(REMOVE_DUPLICATES additional_sources_)
  1448. unset(additional_sources_all_)
  1449. foreach(source_ IN LISTS additional_sources_)
  1450. string(REPLACE "/" ";" split_source_ " ${source_}")
  1451. list(REMOVE_AT split_source_ 0)
  1452. unset(tmp_path_)
  1453. # Now generate all segments of the path
  1454. foreach(segment_ IN LISTS split_source_)
  1455. string(APPEND tmp_path_ "/${segment_}")
  1456. list(APPEND additional_sources_all_ "${tmp_path_}")
  1457. endforeach()
  1458. endforeach()
  1459. list(REMOVE_DUPLICATES additional_sources_all_)
  1460. list(REMOVE_ITEM additional_sources_all_
  1461. ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS})
  1462. unset(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  1463. foreach(source_ IN LISTS additional_sources_all_)
  1464. string(APPEND TMP_DEBUGINFO_ADDITIONAL_SOURCES "${source_}\n")
  1465. endforeach()
  1466. endif()
  1467. set(TMP_RPM_DEBUGINFO_INSTALL "${TMP_RPM_DEBUGINFO_INSTALL}" PARENT_SCOPE)
  1468. set(TMP_DEBUGINFO_ADDITIONAL_SOURCES "${TMP_DEBUGINFO_ADDITIONAL_SOURCES}"
  1469. PARENT_SCOPE)
  1470. endfunction()
  1471. function(cpack_rpm_variable_fallback OUTPUT_VAR_NAME)
  1472. set(FALLBACK_VAR_NAMES ${ARGN})
  1473. foreach(variable_name IN LISTS FALLBACK_VAR_NAMES)
  1474. if(${variable_name})
  1475. set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE)
  1476. break()
  1477. endif()
  1478. endforeach()
  1479. endfunction()
  1480. function(cpack_rpm_generate_package)
  1481. # rpmbuild is the basic command for building RPM package
  1482. # it may be a simple (symbolic) link to rpm command.
  1483. find_program(RPMBUILD_EXECUTABLE rpmbuild)
  1484. # Check version of the rpmbuild tool this would be easier to
  1485. # track bugs with users and CPackRPM debug mode.
  1486. # We may use RPM version in order to check for available version dependent features
  1487. if(RPMBUILD_EXECUTABLE)
  1488. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  1489. OUTPUT_VARIABLE _TMP_VERSION
  1490. ERROR_QUIET
  1491. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1492. string(REGEX REPLACE "^.* " ""
  1493. RPMBUILD_EXECUTABLE_VERSION
  1494. ${_TMP_VERSION})
  1495. if(CPACK_RPM_PACKAGE_DEBUG)
  1496. message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  1497. endif()
  1498. endif()
  1499. if(NOT RPMBUILD_EXECUTABLE)
  1500. message(FATAL_ERROR "RPM package requires rpmbuild executable")
  1501. endif()
  1502. # Display lsb_release output if DEBUG mode enable
  1503. # This will help to diagnose problem with CPackRPM
  1504. # because we will know on which kind of Linux we are
  1505. if(CPACK_RPM_PACKAGE_DEBUG)
  1506. find_program(LSB_RELEASE_EXECUTABLE lsb_release)
  1507. if(LSB_RELEASE_EXECUTABLE)
  1508. execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
  1509. OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
  1510. ERROR_QUIET
  1511. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1512. string(REGEX REPLACE "\n" ", "
  1513. LSB_RELEASE_OUTPUT
  1514. ${_TMP_LSB_RELEASE_OUTPUT})
  1515. else ()
  1516. set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
  1517. endif()
  1518. message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
  1519. endif()
  1520. # We may use RPM version in the future in order
  1521. # to shut down warning about space in buildtree
  1522. # some recent RPM version should support space in different places.
  1523. # not checked [yet].
  1524. if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  1525. message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  1526. endif()
  1527. # If rpmbuild is found
  1528. # we try to discover alien since we may be on non RPM distro like Debian.
  1529. # In this case we may try to to use more advanced features
  1530. # like generating RPM directly from DEB using alien.
  1531. # FIXME feature not finished (yet)
  1532. find_program(ALIEN_EXECUTABLE alien)
  1533. if(ALIEN_EXECUTABLE)
  1534. message(STATUS "alien found, we may be on a Debian based distro.")
  1535. endif()
  1536. # Are we packaging components ?
  1537. if(CPACK_RPM_PACKAGE_COMPONENT)
  1538. string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1539. endif()
  1540. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  1541. #
  1542. # Use user-defined RPM specific variables value
  1543. # or generate reasonable default value from
  1544. # CPACK_xxx generic values.
  1545. # The variables comes from the needed (mandatory or not)
  1546. # values found in the RPM specification file aka ".spec" file.
  1547. # The variables which may/should be defined are:
  1548. #
  1549. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  1550. if(CPACK_RPM_PACKAGE_COMPONENT)
  1551. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_SUMMARY"
  1552. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY"
  1553. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_SUMMARY")
  1554. endif()
  1555. if(NOT CPACK_RPM_PACKAGE_SUMMARY)
  1556. if(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  1557. set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  1558. else()
  1559. # if neither var is defined lets use the name as summary
  1560. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  1561. endif()
  1562. endif()
  1563. # CPACK_RPM_PACKAGE_NAME (mandatory)
  1564. if(NOT CPACK_RPM_PACKAGE_NAME)
  1565. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  1566. endif()
  1567. if(CPACK_RPM_PACKAGE_COMPONENT)
  1568. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  1569. CPACK_RPM_MAIN_COMPONENT_UPPER)
  1570. if(NOT CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1571. string(APPEND CPACK_RPM_PACKAGE_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
  1572. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_NAME"
  1573. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME"
  1574. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME")
  1575. endif()
  1576. endif()
  1577. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  1578. if(NOT CPACK_RPM_PACKAGE_VERSION)
  1579. if(NOT CPACK_PACKAGE_VERSION)
  1580. message(FATAL_ERROR "RPM package requires a package version")
  1581. endif()
  1582. set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  1583. endif()
  1584. # Replace '-' in version with '_'
  1585. # '-' character is an Illegal RPM version character
  1586. # it is illegal because it is used to separate
  1587. # RPM "Version" from RPM "Release"
  1588. string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
  1589. # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory)
  1590. if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
  1591. execute_process(COMMAND uname "-m"
  1592. OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
  1593. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1594. else()
  1595. if(CPACK_RPM_PACKAGE_DEBUG)
  1596. message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1597. endif()
  1598. endif()
  1599. if(CPACK_RPM_PACKAGE_COMPONENT)
  1600. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_ARCHITECTURE"
  1601. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE"
  1602. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_ARCHITECTURE")
  1603. if(CPACK_RPM_PACKAGE_DEBUG)
  1604. message("CPackRPM:Debug: using component build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1605. endif()
  1606. endif()
  1607. if(${CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch")
  1608. set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  1609. else()
  1610. set(TMP_RPM_BUILDARCH "")
  1611. endif()
  1612. # CPACK_RPM_PACKAGE_RELEASE
  1613. # The RPM release is the numbering of the RPM package ITSELF
  1614. # this is the version of the PACKAGING and NOT the version
  1615. # of the CONTENT of the package.
  1616. # You may well need to generate a new RPM package release
  1617. # without changing the version of the packaged software.
  1618. # This is the case when the packaging is buggy (not) the software :=)
  1619. # If not set, 1 is a good candidate
  1620. if(NOT CPACK_RPM_PACKAGE_RELEASE)
  1621. set(CPACK_RPM_PACKAGE_RELEASE "1")
  1622. endif()
  1623. if(CPACK_RPM_PACKAGE_RELEASE_DIST)
  1624. string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}")
  1625. endif()
  1626. # CPACK_RPM_PACKAGE_LICENSE
  1627. if(NOT CPACK_RPM_PACKAGE_LICENSE)
  1628. set(CPACK_RPM_PACKAGE_LICENSE "unknown")
  1629. endif()
  1630. # CPACK_RPM_PACKAGE_GROUP
  1631. if(CPACK_RPM_PACKAGE_COMPONENT)
  1632. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_GROUP"
  1633. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP"
  1634. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_GROUP")
  1635. endif()
  1636. if(NOT CPACK_RPM_PACKAGE_GROUP)
  1637. set(CPACK_RPM_PACKAGE_GROUP "unknown")
  1638. endif()
  1639. # CPACK_RPM_PACKAGE_VENDOR
  1640. if(NOT CPACK_RPM_PACKAGE_VENDOR)
  1641. if(CPACK_PACKAGE_VENDOR)
  1642. set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  1643. else()
  1644. set(CPACK_RPM_PACKAGE_VENDOR "unknown")
  1645. endif()
  1646. endif()
  1647. # CPACK_RPM_PACKAGE_SOURCE
  1648. # The name of the source tarball in case we generate a source RPM
  1649. # CPACK_RPM_PACKAGE_DESCRIPTION
  1650. # The variable content may be either
  1651. # - explicitly given by the user or
  1652. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  1653. # if it is defined
  1654. # - set to a default value
  1655. #
  1656. if(CPACK_RPM_PACKAGE_COMPONENT)
  1657. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_DESCRIPTION"
  1658. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION"
  1659. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_DESCRIPTION"
  1660. "CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION")
  1661. endif()
  1662. if(NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  1663. if(CPACK_PACKAGE_DESCRIPTION_FILE)
  1664. file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  1665. else ()
  1666. set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  1667. endif ()
  1668. endif ()
  1669. # CPACK_RPM_COMPRESSION_TYPE
  1670. #
  1671. if (CPACK_RPM_COMPRESSION_TYPE)
  1672. if(CPACK_RPM_PACKAGE_DEBUG)
  1673. message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
  1674. endif()
  1675. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  1676. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
  1677. endif()
  1678. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  1679. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
  1680. endif()
  1681. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  1682. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
  1683. endif()
  1684. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  1685. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
  1686. endif()
  1687. else()
  1688. set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
  1689. endif()
  1690. if(NOT CPACK_RPM_PACKAGE_SOURCES)
  1691. if(CPACK_PACKAGE_RELOCATABLE OR CPACK_RPM_PACKAGE_RELOCATABLE)
  1692. if(CPACK_RPM_PACKAGE_DEBUG)
  1693. message("CPackRPM:Debug: Trying to build a relocatable package")
  1694. endif()
  1695. if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  1696. 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.")
  1697. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE)
  1698. else()
  1699. set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files)
  1700. cpack_rpm_prepare_relocation_paths()
  1701. set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
  1702. endif()
  1703. endif()
  1704. else()
  1705. if(CPACK_RPM_PACKAGE_COMPONENT)
  1706. message(FATAL_ERROR "CPACK_RPM_PACKAGE_SOURCES parameter can not be used"
  1707. " in combination with CPACK_RPM_PACKAGE_COMPONENT parameter!")
  1708. endif()
  1709. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) # disable relocatable option if building source RPM
  1710. endif()
  1711. execute_process(
  1712. COMMAND "${RPMBUILD_EXECUTABLE}" --querytags
  1713. OUTPUT_VARIABLE RPMBUILD_TAG_LIST
  1714. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1715. string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}")
  1716. # Check if additional fields for RPM spec header are given
  1717. # There may be some COMPONENT specific variables as well
  1718. # If component specific var is not provided we use the global one
  1719. # for each component
  1720. foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  1721. if(CPACK_RPM_PACKAGE_DEBUG)
  1722. message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
  1723. endif()
  1724. if(CPACK_RPM_PACKAGE_COMPONENT)
  1725. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}"
  1726. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}"
  1727. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_${_RPM_SPEC_HEADER}")
  1728. endif()
  1729. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  1730. cmake_policy(PUSH)
  1731. cmake_policy(SET CMP0057 NEW)
  1732. # Prefix can be replaced by Prefixes but the old version stil works so we'll ignore it for now
  1733. # Requires* is a special case because it gets transformed to Requires(pre/post/preun/postun)
  1734. # Auto* is a special case because the tags can not be queried by querytags rpmbuild flag
  1735. set(special_case_tags_ PREFIX REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN AUTOPROV AUTOREQ AUTOREQPROV)
  1736. if(NOT _RPM_SPEC_HEADER IN_LIST RPMBUILD_TAG_LIST AND NOT _RPM_SPEC_HEADER IN_LIST special_case_tags_)
  1737. cmake_policy(POP)
  1738. message(AUTHOR_WARNING "CPackRPM:Warning: ${_RPM_SPEC_HEADER} not "
  1739. "supported in provided rpmbuild. Tag will not be used.")
  1740. continue()
  1741. endif()
  1742. cmake_policy(POP)
  1743. if(CPACK_RPM_PACKAGE_DEBUG)
  1744. message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
  1745. endif()
  1746. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
  1747. endif()
  1748. # Treat the RPM Spec keyword iff it has been properly defined
  1749. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  1750. # Transform NAME --> Name e.g. PROVIDES --> Provides
  1751. # The Upper-case first letter and lowercase tail is the
  1752. # appropriate value required in the final RPM spec file.
  1753. string(SUBSTRING ${_RPM_SPEC_HEADER} 1 -1 _PACKAGE_HEADER_TAIL)
  1754. string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
  1755. string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
  1756. string(APPEND _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_TAIL}")
  1757. # The following keywords require parentheses around the "pre" or "post" suffix in the final RPM spec file.
  1758. set(SCRIPTS_REQUIREMENTS_LIST REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  1759. list(FIND SCRIPTS_REQUIREMENTS_LIST ${_RPM_SPEC_HEADER} IS_SCRIPTS_REQUIREMENT_FOUND)
  1760. if(NOT ${IS_SCRIPTS_REQUIREMENT_FOUND} EQUAL -1)
  1761. string(REPLACE "_" "(" _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}")
  1762. string(APPEND _PACKAGE_HEADER_NAME ")")
  1763. endif()
  1764. if(CPACK_RPM_PACKAGE_DEBUG)
  1765. message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  1766. endif()
  1767. set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  1768. unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  1769. endif()
  1770. endforeach()
  1771. # CPACK_RPM_SPEC_INSTALL_POST
  1772. # May be used to define a RPM post intallation script
  1773. # for example setting it to "/bin/true" may prevent
  1774. # rpmbuild from stripping binaries.
  1775. if(CPACK_RPM_SPEC_INSTALL_POST)
  1776. if(CPACK_RPM_PACKAGE_DEBUG)
  1777. message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  1778. endif()
  1779. set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  1780. endif()
  1781. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
  1782. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
  1783. # May be used to embed a post (un)installation script in the spec file.
  1784. # The refered script file(s) will be read and directly
  1785. # put after the %post or %postun section
  1786. # ----------------------------------------------------------------
  1787. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
  1788. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
  1789. # May be used to embed a pre (un)installation script in the spec file.
  1790. # The refered script file(s) will be read and directly
  1791. # put after the %pre or %preun section
  1792. foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL")
  1793. foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST")
  1794. set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  1795. "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}")
  1796. if(CPACK_RPM_PACKAGE_COMPONENT)
  1797. cpack_rpm_variable_fallback("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  1798. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE"
  1799. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE")
  1800. endif()
  1801. # Handle file if it has been specified
  1802. if(CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE)
  1803. if(EXISTS ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE})
  1804. file(READ ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}
  1805. "CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}")
  1806. else()
  1807. 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")
  1808. endif()
  1809. else()
  1810. # reset SPEC var value if no file has been specified
  1811. # (either globally or component-wise)
  1812. set("CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}" "")
  1813. endif()
  1814. endforeach()
  1815. endforeach()
  1816. # CPACK_RPM_CHANGELOG_FILE
  1817. # May be used to embed a changelog in the spec file.
  1818. # The refered file will be read and directly put after the %changelog section
  1819. if(CPACK_RPM_CHANGELOG_FILE)
  1820. if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  1821. file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
  1822. else()
  1823. message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
  1824. endif()
  1825. else()
  1826. 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)")
  1827. endif()
  1828. # CPACK_RPM_SPEC_MORE_DEFINE
  1829. # This is a generated spec rpm file spaceholder
  1830. if(CPACK_RPM_SPEC_MORE_DEFINE)
  1831. if(CPACK_RPM_PACKAGE_DEBUG)
  1832. message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  1833. endif()
  1834. endif()
  1835. # Now we may create the RPM build tree structure
  1836. set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  1837. message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  1838. # Prepare RPM build tree
  1839. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  1840. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  1841. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  1842. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  1843. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  1844. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  1845. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  1846. # it seems rpmbuild can't handle spaces in the path
  1847. # neither escaping (as below) nor putting quotes around the path seem to help
  1848. #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1849. set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1850. cpack_rpm_prepare_content_list()
  1851. # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
  1852. # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1853. # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
  1854. # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
  1855. if(CPACK_RPM_PACKAGE_COMPONENT)
  1856. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1857. cpack_rpm_variable_fallback("COMPONENT_FILES_TAG"
  1858. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}"
  1859. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}")
  1860. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
  1861. if(CPACK_RPM_PACKAGE_DEBUG)
  1862. message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
  1863. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1864. endif()
  1865. endif()
  1866. else()
  1867. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1868. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
  1869. endif()
  1870. endif()
  1871. # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
  1872. set(CPACK_RPM_USER_FILELIST_INTERNAL "")
  1873. if(CPACK_RPM_PACKAGE_COMPONENT)
  1874. cpack_rpm_variable_fallback("CPACK_RPM_USER_FILELIST_INTERNAL"
  1875. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST"
  1876. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_FILELIST")
  1877. if(CPACK_RPM_PACKAGE_DEBUG AND CPACK_RPM_USER_FILELIST_INTERNAL)
  1878. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1879. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1880. endif()
  1881. elseif(CPACK_RPM_USER_FILELIST)
  1882. set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
  1883. endif()
  1884. # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
  1885. # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1886. # or CPACK_RPM_INSTALL_FILES,
  1887. # hence it must be done before these auto-generated lists are processed.
  1888. if(CPACK_RPM_USER_FILELIST_INTERNAL)
  1889. if(CPACK_RPM_PACKAGE_DEBUG)
  1890. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1891. endif()
  1892. # Create CMake list from CPACK_RPM_INSTALL_FILES
  1893. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1894. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
  1895. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1896. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
  1897. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1898. set(CPACK_RPM_USER_INSTALL_FILES "")
  1899. foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
  1900. string(REGEX REPLACE "%[A-Za-z]+(\\([^()]*\\))? " "" F_PATH ${F})
  1901. string(REGEX MATCH "(%[A-Za-z]+(\\([^()]*\\))? )*" F_PREFIX ${F})
  1902. string(STRIP ${F_PREFIX} F_PREFIX)
  1903. if(CPACK_RPM_PACKAGE_DEBUG)
  1904. message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
  1905. endif()
  1906. if(F_PREFIX)
  1907. string(APPEND F_PREFIX " ")
  1908. endif()
  1909. # Rebuild the user list file
  1910. string(APPEND CPACK_RPM_USER_INSTALL_FILES "${F_PREFIX}\"${F_PATH}\"\n")
  1911. # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1912. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
  1913. # ABSOLUTE destination files list may not exists at all
  1914. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1915. list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
  1916. endif()
  1917. endforeach()
  1918. # Rebuild CPACK_RPM_INSTALL_FILES
  1919. set(CPACK_RPM_INSTALL_FILES "")
  1920. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1921. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1922. endforeach()
  1923. else()
  1924. set(CPACK_RPM_USER_INSTALL_FILES "")
  1925. endif()
  1926. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1927. if(CPACK_RPM_PACKAGE_DEBUG)
  1928. message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
  1929. endif()
  1930. # Remove trailing space
  1931. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1932. # Transform endline separated - string into CMake List
  1933. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1934. # Remove unecessary quotes
  1935. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1936. # Remove ABSOLUTE install file from INSTALL FILE LIST
  1937. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
  1938. # Rebuild INSTALL_FILES
  1939. set(CPACK_RPM_INSTALL_FILES "")
  1940. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1941. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1942. endforeach()
  1943. # Build ABSOLUTE_INSTALL_FILES
  1944. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1945. foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1946. string(APPEND CPACK_RPM_ABSOLUTE_INSTALL_FILES "%config \"${F}\"\n")
  1947. endforeach()
  1948. if(CPACK_RPM_PACKAGE_DEBUG)
  1949. message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
  1950. message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
  1951. endif()
  1952. else()
  1953. # reset vars in order to avoid leakage of value(s) from one component to another
  1954. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1955. endif()
  1956. cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_PACKAGE"
  1957. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_PACKAGE"
  1958. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_PACKAGE"
  1959. "CPACK_RPM_DEBUGINFO_PACKAGE")
  1960. if(CPACK_RPM_DEBUGINFO_PACKAGE OR (CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND NOT GENERATE_SPEC_PARTS))
  1961. cpack_rpm_variable_fallback("CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX"
  1962. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_BUILD_SOURCE_DIRS_PREFIX"
  1963. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_BUILD_SOURCE_DIRS_PREFIX"
  1964. "CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX")
  1965. if(NOT CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX)
  1966. set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  1967. endif()
  1968. # handle cases where path contains extra slashes (e.g. /a//b/ instead of
  1969. # /a/b)
  1970. get_filename_component(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX
  1971. "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}" ABSOLUTE)
  1972. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  1973. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files"
  1974. "${CPACK_RPM_INSTALL_FILES}")
  1975. else()
  1976. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND CPACK_RPM_PACKAGE_COMPONENT)
  1977. # this part is only required by components packaging - with monolithic
  1978. # packages we can be certain that there are no other components present
  1979. # so CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is a noop
  1980. if(CPACK_RPM_DEBUGINFO_PACKAGE)
  1981. # only add current package files to debuginfo list if debuginfo
  1982. # generation is enabled for current package
  1983. set(install_files_ "${CPACK_RPM_INSTALL_FILES}")
  1984. else()
  1985. unset(install_files_)
  1986. endif()
  1987. file(GLOB files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.files")
  1988. foreach(f_ IN LISTS files_)
  1989. file(READ "${f_}" tmp_)
  1990. string(APPEND install_files_ ";${tmp_}")
  1991. endforeach()
  1992. # if there were other components/groups so we need to move files from them
  1993. # to current component otherwise those files won't be found
  1994. file(GLOB components_ LIST_DIRECTORIES true RELATIVE
  1995. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  1996. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/*")
  1997. foreach(component_ IN LISTS components_)
  1998. string(TOUPPER "${component_}" component_dir_upper_)
  1999. if(component_dir_upper_ STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  2000. # skip current component
  2001. continue()
  2002. endif()
  2003. cmake_policy(PUSH)
  2004. cmake_policy(SET CMP0009 NEW)
  2005. file(GLOB_RECURSE files_for_move_ LIST_DIRECTORIES false RELATIVE
  2006. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}"
  2007. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/*")
  2008. cmake_policy(POP)
  2009. foreach(f_ IN LISTS files_for_move_)
  2010. get_filename_component(dir_path_ "${f_}" DIRECTORY)
  2011. set(src_file_
  2012. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/${f_}")
  2013. # check that we are not overriding an existing file that doesn't
  2014. # match the file that we want to copy
  2015. if(EXISTS "${src_file_}" AND EXISTS "${WDIR}/${f_}")
  2016. execute_process(
  2017. COMMAND ${CMAKE_COMMAND} -E compare_files "${src_file_}" "${WDIR}/${f_}"
  2018. RESULT_VARIABLE res_
  2019. )
  2020. if(res_)
  2021. message(FATAL_ERROR "CPackRPM:Error: File on path '${WDIR}/${f_}'"
  2022. " already exists but is a different than the one in component"
  2023. " '${component_}'! Packages will not be generated.")
  2024. endif()
  2025. endif()
  2026. file(MAKE_DIRECTORY "${WDIR}/${dir_path_}")
  2027. file(RENAME "${src_file_}"
  2028. "${WDIR}/${f_}")
  2029. endforeach()
  2030. endforeach()
  2031. cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}")
  2032. else()
  2033. cpack_rpm_debugsymbol_check("${CPACK_RPM_INSTALL_FILES}" "${WDIR}")
  2034. endif()
  2035. if(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  2036. set(TMP_RPM_DEBUGINFO "
  2037. # Modified version of %%debug_package macro
  2038. # defined in /usr/lib/rpm/macros as that one
  2039. # can't handle injection of extra source files.
  2040. %ifnarch noarch
  2041. %global __debug_package 1
  2042. %package debuginfo
  2043. Summary: Debug information for package %{name}
  2044. Group: Development/Debug
  2045. AutoReqProv: 0
  2046. %description debuginfo
  2047. This package provides debug information for package %{name}.
  2048. Debug information is useful when developing applications that use this
  2049. package or when debugging this package.
  2050. %files debuginfo -f debugfiles.list
  2051. %defattr(-,root,root)
  2052. ${TMP_DEBUGINFO_ADDITIONAL_SOURCES}
  2053. %endif
  2054. ")
  2055. elseif(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  2056. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  2057. " but will not be generated as no source files were found!")
  2058. else()
  2059. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  2060. " but will not be generated as no source files were found! Component: '"
  2061. "${CPACK_RPM_PACKAGE_COMPONENT}'.")
  2062. endif()
  2063. endif()
  2064. endif()
  2065. # Prepare install files
  2066. cpack_rpm_prepare_install_files(
  2067. "${CPACK_RPM_INSTALL_FILES}"
  2068. "${WDIR}"
  2069. "${RPM_USED_PACKAGE_PREFIXES}"
  2070. "${CPACK_RPM_PACKAGE_RELOCATABLE}"
  2071. )
  2072. # set default user and group
  2073. foreach(_PERM_TYPE "USER" "GROUP")
  2074. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE})
  2075. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}}")
  2076. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE})
  2077. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_DEFAULT_${_PERM_TYPE}}")
  2078. else()
  2079. set(TMP_DEFAULT_${_PERM_TYPE} "root")
  2080. endif()
  2081. endforeach()
  2082. # set default file and dir permissions
  2083. foreach(_PERM_TYPE "FILE" "DIR")
  2084. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  2085. get_unix_permissions_octal_notation("CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2086. set(_PERMISSIONS_VAR "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2087. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  2088. get_unix_permissions_octal_notation("CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2089. set(_PERMISSIONS_VAR "CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  2090. else()
  2091. set(TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS "-")
  2092. endif()
  2093. endforeach()
  2094. # The name of the final spec file to be used by rpmbuild
  2095. set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
  2096. # Print out some debug information if we were asked for that
  2097. if(CPACK_RPM_PACKAGE_DEBUG)
  2098. message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  2099. message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  2100. message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  2101. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  2102. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  2103. message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  2104. message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  2105. message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  2106. message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  2107. endif()
  2108. #
  2109. # USER generated/provided spec file handling.
  2110. #
  2111. # We can have a component specific spec file.
  2112. if(CPACK_RPM_PACKAGE_COMPONENT)
  2113. cpack_rpm_variable_fallback("CPACK_RPM_USER_BINARY_SPECFILE"
  2114. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE"
  2115. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_BINARY_SPECFILE")
  2116. endif()
  2117. cpack_rpm_variable_fallback("CPACK_RPM_FILE_NAME"
  2118. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_FILE_NAME"
  2119. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_FILE_NAME"
  2120. "CPACK_RPM_FILE_NAME")
  2121. if(NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  2122. if(CPACK_RPM_FILE_NAME)
  2123. cmake_policy(PUSH)
  2124. cmake_policy(SET CMP0010 NEW)
  2125. if(NOT CPACK_RPM_FILE_NAME MATCHES ".*\\.rpm")
  2126. cmake_policy(POP)
  2127. message(FATAL_ERROR "'${CPACK_RPM_FILE_NAME}' is not a valid RPM package file name as it must end with '.rpm'!")
  2128. endif()
  2129. cmake_policy(POP)
  2130. else()
  2131. # old file name format for back compatibility
  2132. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  2133. CPACK_RPM_MAIN_COMPONENT_UPPER)
  2134. if(CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  2135. # this is the main component so ignore the component filename part
  2136. set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.rpm")
  2137. else()
  2138. set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  2139. endif()
  2140. endif()
  2141. # else example:
  2142. #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  2143. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  2144. string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" expected_filename_)
  2145. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.rpm_name"
  2146. "${expected_filename_};${CPACK_RPM_FILE_NAME}")
  2147. elseif(NOT CPACK_RPM_DEBUGINFO_PACKAGE)
  2148. set(FILE_NAME_DEFINE "%define _rpmfilename ${CPACK_RPM_FILE_NAME}")
  2149. endif()
  2150. endif()
  2151. if(CPACK_RPM_PACKAGE_SOURCES) # source rpm
  2152. set(archive_name_ "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}")
  2153. execute_process(
  2154. COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${CPACK_RPM_DIRECTORY}/SOURCES/${archive_name_}.tar.gz" "${CPACK_PACKAGE_FILE_NAME}"
  2155. WORKING_DIRECTORY ${CPACK_RPM_DIRECTORY}
  2156. )
  2157. set(TMP_RPM_SOURCE "Source: ${archive_name_}.tar.gz")
  2158. if(CPACK_RPM_BUILDREQUIRES)
  2159. set(TMP_RPM_BUILD_REQUIRES "BuildRequires: ${CPACK_RPM_BUILDREQUIRES}")
  2160. endif()
  2161. # Disable debuginfo packages - srpm generates invalid packages due to
  2162. # releasing controll to cpack to generate binary packages.
  2163. # Note however that this doesn't prevent cpack to generate debuginfo
  2164. # packages when run from srpm with --rebuild.
  2165. set(TMP_RPM_DISABLE_DEBUGINFO "%define debug_package %{nil}")
  2166. if(NOT CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX)
  2167. set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/")
  2168. endif()
  2169. set(TMP_RPM_BUILD
  2170. "
  2171. %build
  2172. mkdir cpack_rpm_build_dir
  2173. cd cpack_rpm_build_dir
  2174. cmake ${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCPACK_PACKAGING_INSTALL_PREFIX=${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX} ../${CPACK_PACKAGE_FILE_NAME}
  2175. make %{?_smp_mflags}" # %{?_smp_mflags} -> -j option
  2176. )
  2177. set(TMP_RPM_INSTALL
  2178. "
  2179. cd cpack_rpm_build_dir
  2180. cpack -G RPM
  2181. mv *.rpm %_rpmdir"
  2182. )
  2183. set(TMP_RPM_PREP "%setup -c")
  2184. set(RPMBUILD_FLAGS "-bs")
  2185. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2186. "# -*- rpm-spec -*-
  2187. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@
  2188. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2189. Name: \@CPACK_RPM_PACKAGE_NAME\@
  2190. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2191. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2192. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2193. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2194. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2195. \@TMP_RPM_SOURCE\@
  2196. \@TMP_RPM_BUILD_REQUIRES\@
  2197. \@TMP_RPM_BUILDARCH\@
  2198. \@TMP_RPM_PREFIXES\@
  2199. \@TMP_RPM_DISABLE_DEBUGINFO\@
  2200. %define _rpmdir %_topdir/RPMS
  2201. %define _srcrpmdir %_topdir/SRPMS
  2202. \@FILE_NAME_DEFINE\@
  2203. %define _unpackaged_files_terminate_build 0
  2204. \@TMP_RPM_SPEC_INSTALL_POST\@
  2205. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  2206. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  2207. %description
  2208. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2209. # This is a shortcutted spec file generated by CMake RPM generator
  2210. # we skip _install step because CPack does that for us.
  2211. # We do only save CPack installed tree in _prepr
  2212. # and then restore it in build.
  2213. %prep
  2214. \@TMP_RPM_PREP\@
  2215. \@TMP_RPM_BUILD\@
  2216. #p build
  2217. %install
  2218. \@TMP_RPM_INSTALL\@
  2219. %clean
  2220. %changelog
  2221. \@CPACK_RPM_SPEC_CHANGELOG\@
  2222. "
  2223. )
  2224. elseif(GENERATE_SPEC_PARTS) # binary rpm with single debuginfo package
  2225. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2226. "# -*- rpm-spec -*-
  2227. %package -n \@CPACK_RPM_PACKAGE_NAME\@
  2228. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2229. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2230. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2231. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2232. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2233. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2234. \@TMP_RPM_URL\@
  2235. \@TMP_RPM_REQUIRES\@
  2236. \@TMP_RPM_REQUIRES_PRE\@
  2237. \@TMP_RPM_REQUIRES_POST\@
  2238. \@TMP_RPM_REQUIRES_PREUN\@
  2239. \@TMP_RPM_REQUIRES_POSTUN\@
  2240. \@TMP_RPM_PROVIDES\@
  2241. \@TMP_RPM_OBSOLETES\@
  2242. \@TMP_RPM_CONFLICTS\@
  2243. \@TMP_RPM_SUGGESTS\@
  2244. \@TMP_RPM_AUTOPROV\@
  2245. \@TMP_RPM_AUTOREQ\@
  2246. \@TMP_RPM_AUTOREQPROV\@
  2247. \@TMP_RPM_BUILDARCH\@
  2248. \@TMP_RPM_PREFIXES\@
  2249. %description -n \@CPACK_RPM_PACKAGE_NAME\@
  2250. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2251. %files -n \@CPACK_RPM_PACKAGE_NAME\@
  2252. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  2253. \@CPACK_RPM_INSTALL_FILES\@
  2254. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  2255. \@CPACK_RPM_USER_INSTALL_FILES\@
  2256. "
  2257. )
  2258. else() # binary rpm
  2259. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  2260. # find generated spec file and take its name
  2261. file(GLOB spec_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.spec")
  2262. foreach(f_ IN LISTS spec_files_)
  2263. file(READ "${f_}" tmp_)
  2264. string(APPEND TMP_OTHER_COMPONENTS "\n${tmp_}\n")
  2265. endforeach()
  2266. endif()
  2267. # We should generate a USER spec file template:
  2268. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  2269. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  2270. set(RPMBUILD_FLAGS "-bb")
  2271. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  2272. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  2273. "# -*- rpm-spec -*-
  2274. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
  2275. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  2276. Name: \@CPACK_RPM_PACKAGE_NAME\@
  2277. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  2278. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  2279. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  2280. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  2281. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  2282. \@TMP_RPM_URL\@
  2283. \@TMP_RPM_REQUIRES\@
  2284. \@TMP_RPM_REQUIRES_PRE\@
  2285. \@TMP_RPM_REQUIRES_POST\@
  2286. \@TMP_RPM_REQUIRES_PREUN\@
  2287. \@TMP_RPM_REQUIRES_POSTUN\@
  2288. \@TMP_RPM_PROVIDES\@
  2289. \@TMP_RPM_OBSOLETES\@
  2290. \@TMP_RPM_CONFLICTS\@
  2291. \@TMP_RPM_SUGGESTS\@
  2292. \@TMP_RPM_AUTOPROV\@
  2293. \@TMP_RPM_AUTOREQ\@
  2294. \@TMP_RPM_AUTOREQPROV\@
  2295. \@TMP_RPM_BUILDARCH\@
  2296. \@TMP_RPM_PREFIXES\@
  2297. \@TMP_RPM_DEBUGINFO\@
  2298. %define _rpmdir %_topdir/RPMS
  2299. %define _srcrpmdir %_topdir/SRPMS
  2300. \@FILE_NAME_DEFINE\@
  2301. %define _unpackaged_files_terminate_build 0
  2302. \@TMP_RPM_SPEC_INSTALL_POST\@
  2303. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  2304. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  2305. %description
  2306. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  2307. # This is a shortcutted spec file generated by CMake RPM generator
  2308. # we skip _install step because CPack does that for us.
  2309. # We do only save CPack installed tree in _prepr
  2310. # and then restore it in build.
  2311. %prep
  2312. mv $RPM_BUILD_ROOT %_topdir/tmpBBroot
  2313. %install
  2314. if [ -e $RPM_BUILD_ROOT ];
  2315. then
  2316. rm -rf $RPM_BUILD_ROOT
  2317. fi
  2318. mv %_topdir/tmpBBroot $RPM_BUILD_ROOT
  2319. \@TMP_RPM_DEBUGINFO_INSTALL\@
  2320. %clean
  2321. %post
  2322. \@RPM_SYMLINK_POSTINSTALL\@
  2323. \@CPACK_RPM_SPEC_POSTINSTALL\@
  2324. %postun
  2325. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  2326. %pre
  2327. \@CPACK_RPM_SPEC_PREINSTALL\@
  2328. %preun
  2329. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  2330. %files
  2331. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  2332. \@CPACK_RPM_INSTALL_FILES\@
  2333. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  2334. \@CPACK_RPM_USER_INSTALL_FILES\@
  2335. %changelog
  2336. \@CPACK_RPM_SPEC_CHANGELOG\@
  2337. \@TMP_OTHER_COMPONENTS\@
  2338. "
  2339. )
  2340. endif()
  2341. # Stop here if we were asked to only generate a template USER spec file
  2342. # The generated file may then be used as a template by user who wants
  2343. # to customize their own spec file.
  2344. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  2345. message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file template is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  2346. endif()
  2347. endif()
  2348. # After that we may either use a user provided spec file
  2349. # or generate one using appropriate variables value.
  2350. if(CPACK_RPM_USER_BINARY_SPECFILE)
  2351. # User may have specified SPECFILE just use it
  2352. message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  2353. # The user provided file is processed for @var replacement
  2354. configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  2355. else()
  2356. # No User specified spec file, will use the generated spec file
  2357. message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  2358. # Note the just created file is processed for @var replacement
  2359. configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  2360. endif()
  2361. if(NOT GENERATE_SPEC_PARTS) # generate package
  2362. if(RPMBUILD_EXECUTABLE)
  2363. # Now call rpmbuild using the SPECFILE
  2364. execute_process(
  2365. COMMAND "${RPMBUILD_EXECUTABLE}" ${RPMBUILD_FLAGS}
  2366. --define "_topdir ${CPACK_RPM_DIRECTORY}"
  2367. --buildroot "%_topdir/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  2368. --target "${CPACK_RPM_PACKAGE_ARCHITECTURE}"
  2369. "${CPACK_RPM_BINARY_SPECFILE}"
  2370. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  2371. RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
  2372. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err"
  2373. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  2374. if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  2375. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR)
  2376. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT)
  2377. message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  2378. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err")
  2379. message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  2380. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  2381. message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***")
  2382. endif()
  2383. else()
  2384. if(ALIEN_EXECUTABLE)
  2385. message(FATAL_ERROR "RPM packaging through alien not done (yet)")
  2386. endif()
  2387. endif()
  2388. # find generated rpm files and take their names
  2389. cmake_policy(PUSH)
  2390. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  2391. # even if the project does not set this policy to NEW.
  2392. cmake_policy(SET CMP0009 NEW)
  2393. file(GLOB_RECURSE GENERATED_FILES "${CPACK_RPM_DIRECTORY}/RPMS/*.rpm"
  2394. "${CPACK_RPM_DIRECTORY}/SRPMS/*.rpm")
  2395. cmake_policy(POP)
  2396. if(NOT GENERATED_FILES)
  2397. message(FATAL_ERROR "RPM package was not generated! ${CPACK_RPM_DIRECTORY}")
  2398. endif()
  2399. unset(expected_filenames_)
  2400. unset(filenames_)
  2401. if(CPACK_RPM_DEBUGINFO_PACKAGE AND NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  2402. string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" efn_)
  2403. list(APPEND expected_filenames_ "${efn_}")
  2404. list(APPEND filenames_ "${CPACK_RPM_FILE_NAME}")
  2405. endif()
  2406. # check if other files have to be renamed
  2407. file(GLOB rename_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.rpm_name")
  2408. if(rename_files_)
  2409. foreach(f_ IN LISTS rename_files_)
  2410. file(READ "${f_}" tmp_)
  2411. list(GET tmp_ 0 efn_)
  2412. list(APPEND expected_filenames_ "${efn_}")
  2413. list(GET tmp_ 1 fn_)
  2414. list(APPEND filenames_ "${fn_}")
  2415. endforeach()
  2416. endif()
  2417. if(expected_filenames_)
  2418. foreach(F IN LISTS GENERATED_FILES)
  2419. unset(matched_)
  2420. foreach(expected_ IN LISTS expected_filenames_)
  2421. if(F MATCHES ".*/${expected_}")
  2422. list(FIND expected_filenames_ "${expected_}" idx_)
  2423. list(GET filenames_ ${idx_} filename_)
  2424. get_filename_component(FILE_PATH "${F}" DIRECTORY)
  2425. file(RENAME "${F}" "${FILE_PATH}/${filename_}")
  2426. list(APPEND new_files_list_ "${FILE_PATH}/${filename_}")
  2427. set(matched_ "YES")
  2428. break()
  2429. endif()
  2430. endforeach()
  2431. if(NOT matched_)
  2432. list(APPEND new_files_list_ "${F}")
  2433. endif()
  2434. endforeach()
  2435. set(GENERATED_FILES "${new_files_list_}")
  2436. endif()
  2437. endif()
  2438. set(GEN_CPACK_OUTPUT_FILES "${GENERATED_FILES}" PARENT_SCOPE)
  2439. if(CPACK_RPM_PACKAGE_DEBUG)
  2440. message("CPackRPM:Debug: GEN_CPACK_OUTPUT_FILES = ${GENERATED_FILES}")
  2441. endif()
  2442. endfunction()
  2443. cpack_rpm_generate_package()