CPackRPM.cmake 108 KB

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