CPackRPM.cmake 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # Author: Eric Noulard with the help of Alexander Neundorf.
  4. cmake_policy(PUSH)
  5. cmake_policy(SET CMP0057 NEW) # if IN_LIST
  6. function(get_file_permissions FILE RETURN_VAR)
  7. execute_process(COMMAND ls -l ${FILE}
  8. OUTPUT_VARIABLE permissions_
  9. ERROR_QUIET
  10. OUTPUT_STRIP_TRAILING_WHITESPACE)
  11. string(REPLACE " " ";" permissions_ "${permissions_}")
  12. list(GET permissions_ 0 permissions_)
  13. unset(text_notation_)
  14. set(any_chars_ ".")
  15. foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD")
  16. if(permissions_ MATCHES "${any_chars_}r.*")
  17. list(APPEND text_notation_ "${PERMISSION_TYPE}_READ")
  18. endif()
  19. string(APPEND any_chars_ ".")
  20. if(permissions_ MATCHES "${any_chars_}w.*")
  21. list(APPEND text_notation_ "${PERMISSION_TYPE}_WRITE")
  22. endif()
  23. string(APPEND any_chars_ ".")
  24. if(permissions_ MATCHES "${any_chars_}x.*")
  25. list(APPEND text_notation_ "${PERMISSION_TYPE}_EXECUTE")
  26. endif()
  27. endforeach()
  28. set(${RETURN_VAR} "${text_notation_}" PARENT_SCOPE)
  29. endfunction()
  30. function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR)
  31. set(PERMISSIONS ${${PERMISSIONS_VAR}})
  32. list(LENGTH PERMISSIONS PERM_LEN_PRE)
  33. list(REMOVE_DUPLICATES PERMISSIONS)
  34. list(LENGTH PERMISSIONS PERM_LEN_POST)
  35. if(NOT ${PERM_LEN_PRE} EQUAL ${PERM_LEN_POST})
  36. message(FATAL_ERROR "${PERMISSIONS_VAR} contains duplicate values.")
  37. endif()
  38. foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD")
  39. set(${PERMISSION_TYPE}_PERMISSIONS 0)
  40. foreach(PERMISSION ${PERMISSIONS})
  41. if("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_READ")
  42. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 4")
  43. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_WRITE")
  44. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 2")
  45. elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_EXECUTE")
  46. math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 1")
  47. elseif(PERMISSION MATCHES "${PERMISSION_TYPE}.*")
  48. message(FATAL_ERROR "${PERMISSIONS_VAR} contains invalid values.")
  49. endif()
  50. endforeach()
  51. endforeach()
  52. set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE)
  53. endfunction()
  54. function(cpack_rpm_exact_regex regex_var string)
  55. string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" regex "${string}")
  56. set("${regex_var}" "${regex}" PARENT_SCOPE)
  57. endfunction()
  58. function(cpack_rpm_prepare_relocation_paths)
  59. # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes
  60. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX)
  61. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX}" PATH_PREFIX)
  62. elseif(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX)
  63. file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX}" PATH_PREFIX)
  64. else()
  65. file(TO_CMAKE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}" PATH_PREFIX)
  66. endif()
  67. set(RPM_RELOCATION_PATHS "${CPACK_RPM_RELOCATION_PATHS}")
  68. list(REMOVE_DUPLICATES RPM_RELOCATION_PATHS)
  69. # set base path prefix
  70. if(EXISTS "${WDIR}/${PATH_PREFIX}")
  71. if(NOT CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION AND
  72. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT}_INSTALL_PREFIX_RELOCATION AND
  73. NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_INSTALL_PREFIX_RELOCATION)
  74. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PATH_PREFIX}\n")
  75. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PATH_PREFIX}")
  76. if(CPACK_RPM_PACKAGE_DEBUG)
  77. message("CPackRPM:Debug: removing '${PATH_PREFIX}' from relocation paths")
  78. endif()
  79. endif()
  80. endif()
  81. # set other path prefixes
  82. foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS})
  83. if(IS_ABSOLUTE "${RELOCATION_PATH}")
  84. set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}")
  85. elseif(PATH_PREFIX STREQUAL "/")
  86. # don't prefix path with a second slash as "//" is treated as network path
  87. # by get_filename_component() so it remains in path even inside rpm
  88. # package where it may cause problems with relocation
  89. set(PREPARED_RELOCATION_PATH "/${RELOCATION_PATH}")
  90. else()
  91. set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}")
  92. endif()
  93. # handle cases where path contains extra slashes (e.g. /a//b/ instead of
  94. # /a/b)
  95. get_filename_component(PREPARED_RELOCATION_PATH
  96. "${PREPARED_RELOCATION_PATH}" ABSOLUTE)
  97. if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}")
  98. string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n")
  99. list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}")
  100. endif()
  101. endforeach()
  102. # warn about all the paths that are not relocatable
  103. file(GLOB_RECURSE FILE_PATHS_ "${WDIR}/*")
  104. foreach(TMP_PATH ${FILE_PATHS_})
  105. string(LENGTH "${WDIR}" WDIR_LEN)
  106. string(SUBSTRING "${TMP_PATH}" ${WDIR_LEN} -1 TMP_PATH)
  107. unset(TMP_PATH_FOUND_)
  108. foreach(RELOCATION_PATH ${RPM_USED_PACKAGE_PREFIXES})
  109. file(RELATIVE_PATH REL_PATH_ "${RELOCATION_PATH}" "${TMP_PATH}")
  110. string(SUBSTRING "${REL_PATH_}" 0 2 PREFIX_)
  111. if(NOT "${PREFIX_}" STREQUAL "..")
  112. set(TPM_PATH_FOUND_ TRUE)
  113. break()
  114. endif()
  115. endforeach()
  116. if(NOT TPM_PATH_FOUND_)
  117. message(AUTHOR_WARNING "CPackRPM:Warning: Path ${TMP_PATH} is not on one of the relocatable paths! Package will be partially relocatable.")
  118. endif()
  119. endforeach()
  120. set(RPM_USED_PACKAGE_PREFIXES "${RPM_USED_PACKAGE_PREFIXES}" PARENT_SCOPE)
  121. set(TMP_RPM_PREFIXES "${TMP_RPM_PREFIXES}" PARENT_SCOPE)
  122. endfunction()
  123. function(cpack_rpm_prepare_content_list)
  124. # get files list
  125. file(GLOB_RECURSE CPACK_RPM_INSTALL_FILES LIST_DIRECTORIES true RELATIVE "${WDIR}" "${WDIR}/*")
  126. set(CPACK_RPM_INSTALL_FILES "/${CPACK_RPM_INSTALL_FILES}")
  127. string(REPLACE ";" ";/" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}")
  128. # if we are creating a relocatable package, omit parent directories of
  129. # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
  130. # which is passed to the find command that generates the content-list
  131. if(CPACK_RPM_PACKAGE_RELOCATABLE)
  132. # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are
  133. # destinct parent paths of other relocation paths and remove the
  134. # final element (so the install-prefix dir itself is not omitted
  135. # from the RPM's content-list)
  136. list(SORT RPM_USED_PACKAGE_PREFIXES)
  137. set(_DISTINCT_PATH "NOT_SET")
  138. foreach(_RPM_RELOCATION_PREFIX ${RPM_USED_PACKAGE_PREFIXES})
  139. if(NOT "${_RPM_RELOCATION_PREFIX}" MATCHES "${_DISTINCT_PATH}/.*")
  140. set(_DISTINCT_PATH "${_RPM_RELOCATION_PREFIX}")
  141. string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS " ${_RPM_RELOCATION_PREFIX}")
  142. list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
  143. unset(_TMP_LIST)
  144. # Now generate all of the parent dirs of the relocation path
  145. foreach(_PREFIX_PATH_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
  146. list(APPEND _TMP_LIST "${_PREFIX_PATH_ELEM}")
  147. string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
  148. separate_arguments(_OMIT_DIR)
  149. list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
  150. endforeach()
  151. endif()
  152. endforeach()
  153. endif()
  154. if(CPACK_RPM_PACKAGE_DEBUG)
  155. message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  156. endif()
  157. if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  158. set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/bin
  159. /usr/include /usr/lib /usr/libx32 /usr/lib64
  160. /usr/share /usr/share/aclocal /usr/share/doc )
  161. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
  162. if(CPACK_RPM_PACKAGE_DEBUG)
  163. message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
  164. endif()
  165. list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
  166. endif()
  167. endif()
  168. if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
  169. if(CPACK_RPM_PACKAGE_DEBUG)
  170. message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
  171. endif()
  172. list(APPEND _RPM_DIRS_TO_OMIT ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
  173. endif()
  174. if(CPACK_RPM_PACKAGE_DEBUG)
  175. message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
  176. endif()
  177. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES ${_RPM_DIRS_TO_OMIT})
  178. # add man paths that will be compressed
  179. # (copied from /usr/lib/rpm/brp-compress - script that does the actual
  180. # compressing)
  181. list(APPEND MAN_LOCATIONS "/usr/man/man.*" "/usr/man/.*/man.*" "/usr/info.*"
  182. "/usr/share/man/man.*" "/usr/share/man/.*/man.*" "/usr/share/info.*"
  183. "/usr/kerberos/man.*" "/usr/X11R6/man/man.*" "/usr/lib/perl5/man/man.*"
  184. "/usr/share/doc/.*/man/man.*" "/usr/lib/.*/man/man.*")
  185. if(CPACK_RPM_ADDITIONAL_MAN_DIRS)
  186. if(CPACK_RPM_PACKAGE_DEBUG)
  187. message("CPackRPM:Debug: CPACK_RPM_ADDITIONAL_MAN_DIRS= ${CPACK_RPM_ADDITIONAL_MAN_DIRS}")
  188. endif()
  189. list(APPEND MAN_LOCATIONS ${CPACK_RPM_ADDITIONAL_MAN_DIRS})
  190. endif()
  191. foreach(PACK_LOCATION IN LISTS CPACK_RPM_INSTALL_FILES)
  192. foreach(MAN_LOCATION IN LISTS MAN_LOCATIONS)
  193. # man pages are files inside a certain location
  194. if(PACK_LOCATION MATCHES "${MAN_LOCATION}/"
  195. AND NOT IS_DIRECTORY "${WDIR}${PACK_LOCATION}"
  196. AND NOT IS_SYMLINK "${WDIR}${PACK_LOCATION}")
  197. list(FIND CPACK_RPM_INSTALL_FILES "${PACK_LOCATION}" INDEX)
  198. # insert file location that covers compressed man pages
  199. # even if using a wildcard causes duplicates as those are
  200. # handled by RPM and we still keep the same file list
  201. # in spec file - wildcard only represents file type (e.g. .gz)
  202. list(INSERT CPACK_RPM_INSTALL_FILES ${INDEX} "${PACK_LOCATION}*")
  203. # remove file location that doesn't cover compressed man pages
  204. math(EXPR INDEX ${INDEX}+1)
  205. list(REMOVE_AT CPACK_RPM_INSTALL_FILES ${INDEX})
  206. break()
  207. endif()
  208. endforeach()
  209. endforeach()
  210. set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}" PARENT_SCOPE)
  211. endfunction()
  212. function(cpack_rpm_symlink_get_relocation_prefixes LOCATION PACKAGE_PREFIXES RETURN_VARIABLE)
  213. foreach(PKG_PREFIX IN LISTS PACKAGE_PREFIXES)
  214. string(REGEX MATCH "^${PKG_PREFIX}/.*" FOUND_ "${LOCATION}")
  215. if(FOUND_)
  216. list(APPEND TMP_PREFIXES "${PKG_PREFIX}")
  217. endif()
  218. endforeach()
  219. set(${RETURN_VARIABLE} "${TMP_PREFIXES}" PARENT_SCOPE)
  220. endfunction()
  221. function(cpack_rpm_symlink_create_relocation_script PACKAGE_PREFIXES)
  222. list(LENGTH PACKAGE_PREFIXES LAST_INDEX)
  223. set(SORTED_PACKAGE_PREFIXES "${PACKAGE_PREFIXES}")
  224. list(SORT SORTED_PACKAGE_PREFIXES)
  225. list(REVERSE SORTED_PACKAGE_PREFIXES)
  226. math(EXPR LAST_INDEX ${LAST_INDEX}-1)
  227. foreach(SYMLINK_INDEX RANGE ${LAST_INDEX})
  228. list(GET SORTED_PACKAGE_PREFIXES ${SYMLINK_INDEX} SRC_PATH)
  229. list(FIND PACKAGE_PREFIXES "${SRC_PATH}" SYMLINK_INDEX) # reverse magic
  230. string(LENGTH "${SRC_PATH}" SRC_PATH_LEN)
  231. set(PARTS_CNT 0)
  232. set(SCRIPT_PART "if [ \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}\" != \"${SRC_PATH}\" ]; then\n")
  233. # both paths relocated
  234. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  235. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  236. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  237. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  238. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  239. if("${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  240. set(INDENT "")
  241. else()
  242. string(APPEND SCRIPT_PART " if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  243. set(INDENT " ")
  244. endif()
  245. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX})
  246. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  247. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  248. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  249. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  250. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  251. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  252. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN})
  253. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  254. string(APPEND SCRIPT_PART " ${INDENT}if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  255. string(APPEND SCRIPT_PART " ${INDENT}ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  256. string(APPEND SCRIPT_PART " ${INDENT}CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  257. string(APPEND SCRIPT_PART " ${INDENT}fi\n")
  258. endforeach()
  259. if(NOT "${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}")
  260. string(APPEND SCRIPT_PART " fi\n")
  261. endif()
  262. endif()
  263. endforeach()
  264. # source path relocated
  265. if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  266. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X)
  267. math(EXPR PARTS_CNT ${PARTS_CNT}+1)
  268. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  269. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  270. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  271. math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN})
  272. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_)
  273. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  274. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  275. string(APPEND SCRIPT_PART " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  276. string(APPEND SCRIPT_PART " ln -s \"${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n")
  277. string(APPEND SCRIPT_PART " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  278. string(APPEND SCRIPT_PART " fi\n")
  279. endforeach()
  280. endif()
  281. if(PARTS_CNT)
  282. set(SCRIPT "${SCRIPT_PART}")
  283. string(APPEND SCRIPT "fi\n")
  284. endif()
  285. endforeach()
  286. # point path relocated
  287. foreach(POINT_INDEX RANGE ${LAST_INDEX})
  288. list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH)
  289. list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic
  290. string(LENGTH "${POINT_PATH}" POINT_PATH_LEN)
  291. if(_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  292. string(APPEND SCRIPT "if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n")
  293. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX})
  294. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  295. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  296. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  297. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_)
  298. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN})
  299. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  300. string(APPEND SCRIPT " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  301. string(APPEND SCRIPT " ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"${SYMLINK_}\"\n")
  302. string(APPEND SCRIPT " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n")
  303. string(APPEND SCRIPT " fi\n")
  304. endforeach()
  305. string(APPEND SCRIPT "fi\n")
  306. endif()
  307. endforeach()
  308. # no path relocated
  309. if(_RPM_RELOCATION_SCRIPT_X_X)
  310. foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_X)
  311. math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1)
  312. list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR)
  313. string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX)
  314. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_)
  315. math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1)
  316. string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_)
  317. string(APPEND SCRIPT "if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n")
  318. string(APPEND SCRIPT " ln -s \"${POINT_}\" \"${SYMLINK_}\"\n")
  319. string(APPEND SCRIPT "fi\n")
  320. endforeach()
  321. endif()
  322. set(RPM_SYMLINK_POSTINSTALL "${SCRIPT}" PARENT_SCOPE)
  323. endfunction()
  324. function(cpack_rpm_symlink_add_for_relocation_script PACKAGE_PREFIXES SYMLINK SYMLINK_RELOCATION_PATHS POINT POINT_RELOCATION_PATHS)
  325. list(LENGTH SYMLINK_RELOCATION_PATHS SYMLINK_PATHS_COUTN)
  326. list(LENGTH POINT_RELOCATION_PATHS POINT_PATHS_COUNT)
  327. list(APPEND _RPM_RELOCATION_SCRIPT_PAIRS "${SYMLINK}:${POINT}")
  328. list(LENGTH _RPM_RELOCATION_SCRIPT_PAIRS PAIR_NO)
  329. if(SYMLINK_PATHS_COUTN)
  330. foreach(SYMLINK_RELOC_PATH IN LISTS SYMLINK_RELOCATION_PATHS)
  331. list(FIND PACKAGE_PREFIXES "${SYMLINK_RELOC_PATH}" SYMLINK_INDEX)
  332. # source path relocated
  333. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X "${PAIR_NO}")
  334. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X")
  335. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  336. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  337. # both paths relocated
  338. list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX} "${PAIR_NO}")
  339. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}")
  340. # point path relocated
  341. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  342. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  343. endforeach()
  344. endforeach()
  345. elseif(POINT_PATHS_COUNT)
  346. foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS)
  347. list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX)
  348. # point path relocated
  349. list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}")
  350. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}")
  351. endforeach()
  352. endif()
  353. # no path relocated
  354. list(APPEND _RPM_RELOCATION_SCRIPT_X_X "${PAIR_NO}")
  355. list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_X")
  356. # place variables into parent scope
  357. foreach(VAR IN LISTS RELOCATION_VARS)
  358. set(${VAR} "${${VAR}}" PARENT_SCOPE)
  359. endforeach()
  360. set(_RPM_RELOCATION_SCRIPT_PAIRS "${_RPM_RELOCATION_SCRIPT_PAIRS}" PARENT_SCOPE)
  361. set(REQUIRES_SYMLINK_RELOCATION_SCRIPT "true" PARENT_SCOPE)
  362. set(DIRECTIVE "%ghost " PARENT_SCOPE)
  363. endfunction()
  364. function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXES IS_RELOCATABLE)
  365. # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
  366. # This is necessary to avoid duplicate files since rpmbuild does
  367. # recursion on its own when encountering a pathname which is a directory
  368. # which is not flagged as %dir
  369. string(STRIP "${INSTALL_FILES_LIST}" INSTALL_FILES_LIST)
  370. string(REPLACE "\n" ";" INSTALL_FILES_LIST
  371. "${INSTALL_FILES_LIST}")
  372. string(REPLACE "\"" "" INSTALL_FILES_LIST
  373. "${INSTALL_FILES_LIST}")
  374. string(LENGTH "${WDIR}" WDR_LEN_)
  375. list(SORT INSTALL_FILES_LIST) # make file order consistent on all platforms
  376. foreach(F IN LISTS INSTALL_FILES_LIST)
  377. unset(DIRECTIVE)
  378. if(IS_SYMLINK "${WDIR}/${F}")
  379. if(IS_RELOCATABLE)
  380. # check that symlink has relocatable format
  381. get_filename_component(SYMLINK_LOCATION_ "${WDIR}/${F}" DIRECTORY)
  382. execute_process(COMMAND ls -la "${WDIR}/${F}"
  383. WORKING_DIRECTORY "${WDIR}"
  384. OUTPUT_VARIABLE SYMLINK_POINT_
  385. OUTPUT_STRIP_TRAILING_WHITESPACE)
  386. string(FIND "${SYMLINK_POINT_}" "->" SYMLINK_POINT_INDEX_ REVERSE)
  387. math(EXPR SYMLINK_POINT_INDEX_ ${SYMLINK_POINT_INDEX_}+3)
  388. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  389. # get destination path
  390. string(SUBSTRING "${SYMLINK_POINT_}" ${SYMLINK_POINT_INDEX_} ${SYMLINK_POINT_LENGTH_} SYMLINK_POINT_)
  391. # check if path is relative or absolute
  392. string(SUBSTRING "${SYMLINK_POINT_}" 0 1 SYMLINK_IS_ABSOLUTE_)
  393. if(${SYMLINK_IS_ABSOLUTE_} STREQUAL "/")
  394. # prevent absolute paths from having /../ or /./ section inside of them
  395. get_filename_component(SYMLINK_POINT_ "${SYMLINK_POINT_}" ABSOLUTE)
  396. else()
  397. # handle relative path
  398. get_filename_component(SYMLINK_POINT_ "${SYMLINK_LOCATION_}/${SYMLINK_POINT_}" ABSOLUTE)
  399. endif()
  400. # recalculate path length after conversion to canonical form
  401. string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_)
  402. cpack_rpm_exact_regex(IN_SYMLINK_POINT_REGEX "${WDIR}")
  403. string(APPEND IN_SYMLINK_POINT_REGEX "/.*")
  404. if(SYMLINK_POINT_ MATCHES "${IN_SYMLINK_POINT_REGEX}")
  405. # only symlinks that are pointing inside the packaging structure should be checked for relocation
  406. string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_)
  407. cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS")
  408. cpack_rpm_symlink_get_relocation_prefixes("${SYMLINK_POINT_WD_}" "${PACKAGE_PREFIXES}" "POINT_RELOCATIONS")
  409. list(LENGTH SYMLINK_RELOCATIONS SYMLINK_RELOCATIONS_COUNT)
  410. list(LENGTH POINT_RELOCATIONS POINT_RELOCATIONS_COUNT)
  411. else()
  412. # location pointed to is outside WDR so it should be treated as a permanent symlink
  413. set(SYMLINK_POINT_WD_ "${SYMLINK_POINT_}")
  414. unset(SYMLINK_RELOCATIONS)
  415. unset(POINT_RELOCATIONS)
  416. unset(SYMLINK_RELOCATIONS_COUNT)
  417. unset(POINT_RELOCATIONS_COUNT)
  418. message(AUTHOR_WARNING "CPackRPM:Warning: Symbolic link '${F}' points to location that is outside packaging path! Link will possibly not be relocatable.")
  419. endif()
  420. if(SYMLINK_RELOCATIONS_COUNT AND POINT_RELOCATIONS_COUNT)
  421. # find matching
  422. foreach(SYMLINK_RELOCATION_PREFIX IN LISTS SYMLINK_RELOCATIONS)
  423. list(FIND POINT_RELOCATIONS "${SYMLINK_RELOCATION_PREFIX}" FOUND_INDEX)
  424. if(NOT ${FOUND_INDEX} EQUAL -1)
  425. break()
  426. endif()
  427. endforeach()
  428. if(NOT ${FOUND_INDEX} EQUAL -1)
  429. # symlinks have the same subpath
  430. if(${SYMLINK_RELOCATIONS_COUNT} EQUAL 1 AND ${POINT_RELOCATIONS_COUNT} EQUAL 1)
  431. # permanent symlink
  432. get_filename_component(SYMLINK_LOCATION_ "${F}" DIRECTORY)
  433. file(RELATIVE_PATH FINAL_PATH_ ${SYMLINK_LOCATION_} ${SYMLINK_POINT_WD_})
  434. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${FINAL_PATH_}" "${WDIR}/${F}")
  435. else()
  436. # relocation subpaths
  437. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  438. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  439. endif()
  440. else()
  441. # not on the same relocation path
  442. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  443. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  444. endif()
  445. elseif(POINT_RELOCATIONS_COUNT)
  446. # point is relocatable
  447. cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}"
  448. "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}")
  449. else()
  450. # is not relocatable or points to non relocatable path - permanent symlink
  451. execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${SYMLINK_POINT_WD_}" "${WDIR}/${F}")
  452. endif()
  453. endif()
  454. elseif(IS_DIRECTORY "${WDIR}/${F}")
  455. set(DIRECTIVE "%dir ")
  456. endif()
  457. string(APPEND INSTALL_FILES "${DIRECTIVE}\"${F}\"\n")
  458. endforeach()
  459. if(REQUIRES_SYMLINK_RELOCATION_SCRIPT)
  460. cpack_rpm_symlink_create_relocation_script("${PACKAGE_PREFIXES}")
  461. endif()
  462. set(RPM_SYMLINK_POSTINSTALL "${RPM_SYMLINK_POSTINSTALL}" PARENT_SCOPE)
  463. set(CPACK_RPM_INSTALL_FILES "${INSTALL_FILES}" PARENT_SCOPE)
  464. endfunction()
  465. if(CMAKE_BINARY_DIR)
  466. message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
  467. endif()
  468. if(NOT UNIX)
  469. message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
  470. endif()
  471. # We need to check if the binaries were compiled with debug symbols
  472. # because without them the package will be useless
  473. function(cpack_rpm_debugsymbol_check INSTALL_FILES WORKING_DIR)
  474. if(NOT CPACK_BUILD_SOURCE_DIRS)
  475. message(FATAL_ERROR "CPackRPM: CPACK_BUILD_SOURCE_DIRS variable is not set!"
  476. " Required for debuginfo packaging. See documentation of"
  477. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  478. endif()
  479. # With objdump we should check the debug symbols
  480. find_program(OBJDUMP_EXECUTABLE objdump)
  481. if(NOT OBJDUMP_EXECUTABLE)
  482. message(FATAL_ERROR "CPackRPM: objdump binary could not be found!"
  483. " Required for debuginfo packaging. See documentation of"
  484. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  485. endif()
  486. # With debugedit we prepare source files list
  487. find_program(DEBUGEDIT_EXECUTABLE debugedit "/usr/lib/rpm/")
  488. if(NOT DEBUGEDIT_EXECUTABLE)
  489. message(FATAL_ERROR "CPackRPM: debugedit binary could not be found!"
  490. " Required for debuginfo packaging. See documentation of"
  491. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  492. endif()
  493. unset(mkdir_list_)
  494. unset(cp_list_)
  495. unset(additional_sources_)
  496. foreach(F IN LISTS INSTALL_FILES)
  497. if(IS_DIRECTORY "${WORKING_DIR}/${F}" OR IS_SYMLINK "${WORKING_DIR}/${F}")
  498. continue()
  499. endif()
  500. execute_process(COMMAND "${OBJDUMP_EXECUTABLE}" -h ${WORKING_DIR}/${F}
  501. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}"
  502. RESULT_VARIABLE OBJDUMP_EXEC_RESULT
  503. OUTPUT_VARIABLE OBJDUMP_OUT
  504. ERROR_QUIET)
  505. # Check if the given file is an executable or not
  506. if(NOT OBJDUMP_EXEC_RESULT)
  507. string(FIND "${OBJDUMP_OUT}" "debug" FIND_RESULT)
  508. if(FIND_RESULT GREATER -1)
  509. set(index_ 0)
  510. foreach(source_dir_ IN LISTS CPACK_BUILD_SOURCE_DIRS)
  511. string(LENGTH "${source_dir_}" source_dir_len_)
  512. string(LENGTH "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" debuginfo_dir_len)
  513. if(source_dir_len_ LESS debuginfo_dir_len)
  514. message(FATAL_ERROR "CPackRPM: source dir path '${source_dir_}' is"
  515. " shorter than debuginfo sources dir path '${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}'!"
  516. " Source dir path must be longer than debuginfo sources dir path."
  517. " Set CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX variable to a shorter value"
  518. " or make source dir path longer."
  519. " Required for debuginfo packaging. See documentation of"
  520. " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.")
  521. endif()
  522. file(REMOVE "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list")
  523. 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}"
  524. RESULT_VARIABLE res_
  525. OUTPUT_VARIABLE opt_
  526. ERROR_VARIABLE err_
  527. )
  528. file(STRINGS
  529. "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list"
  530. sources_)
  531. list(REMOVE_DUPLICATES sources_)
  532. foreach(source_ IN LISTS sources_)
  533. if(EXISTS "${source_dir_}/${source_}" AND NOT IS_DIRECTORY "${source_dir_}/${source_}")
  534. get_filename_component(path_part_ "${source_}" DIRECTORY)
  535. list(APPEND mkdir_list_ "%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}")
  536. list(APPEND cp_list_ "cp \"${source_dir_}/${source_}\" \"%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}\"")
  537. list(APPEND additional_sources_ "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${source_}")
  538. endif()
  539. endforeach()
  540. math(EXPR index_ "${index_} + 1")
  541. endforeach()
  542. else()
  543. message(WARNING "CPackRPM: File: ${F} does not contain debug symbols. They will possibly be missing from debuginfo package!")
  544. endif()
  545. get_file_permissions("${WORKING_DIR}/${F}" permissions_)
  546. if(NOT "USER_EXECUTE" IN_LIST permissions_ AND
  547. NOT "GROUP_EXECUTE" IN_LIST permissions_ AND
  548. NOT "WORLD_EXECUTE" IN_LIST permissions_)
  549. if(CPACK_RPM_INSTALL_WITH_EXEC)
  550. execute_process(COMMAND chmod a+x ${WORKING_DIR}/${F}
  551. RESULT_VARIABLE res_
  552. ERROR_VARIABLE err_
  553. OUTPUT_QUIET)
  554. if(res_)
  555. message(FATAL_ERROR "CPackRPM: could not apply execute permissions "
  556. "requested by CPACK_RPM_INSTALL_WITH_EXEC variable on "
  557. "'${WORKING_DIR}/${F}'! Reason: '${err_}'")
  558. endif()
  559. else()
  560. message(AUTHOR_WARNING "CPackRPM: File: ${WORKING_DIR}/${F} does not "
  561. "have execute permissions. Debuginfo symbols will not be extracted"
  562. "! Missing debuginfo may cause packaging failure. Consider setting "
  563. "execute permissions or setting 'CPACK_RPM_INSTALL_WITH_EXEC' "
  564. "variable.")
  565. endif()
  566. endif()
  567. endif()
  568. endforeach()
  569. list(LENGTH mkdir_list_ len_)
  570. if(len_)
  571. list(REMOVE_DUPLICATES mkdir_list_)
  572. unset(TMP_RPM_DEBUGINFO_INSTALL)
  573. foreach(part_ IN LISTS mkdir_list_)
  574. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "mkdir -p \"${part_}\"\n")
  575. endforeach()
  576. endif()
  577. list(LENGTH cp_list_ len_)
  578. if(len_)
  579. list(REMOVE_DUPLICATES cp_list_)
  580. foreach(part_ IN LISTS cp_list_)
  581. string(APPEND TMP_RPM_DEBUGINFO_INSTALL "${part_}\n")
  582. endforeach()
  583. endif()
  584. if(NOT DEFINED CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS)
  585. set(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS /usr /usr/src /usr/src/debug)
  586. if(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION)
  587. if(CPACK_RPM_PACKAGE_DEBUG)
  588. message("CPackRPM:Debug: Adding ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION} to builtin omit list.")
  589. endif()
  590. list(APPEND CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS "${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION}")
  591. endif()
  592. endif()
  593. if(CPACK_RPM_PACKAGE_DEBUG)
  594. message("CPackRPM:Debug: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS= ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}")
  595. endif()
  596. list(LENGTH additional_sources_ len_)
  597. if(len_)
  598. list(REMOVE_DUPLICATES additional_sources_)
  599. unset(additional_sources_all_)
  600. foreach(source_ IN LISTS additional_sources_)
  601. string(REPLACE "/" ";" split_source_ " ${source_}")
  602. list(REMOVE_AT split_source_ 0)
  603. unset(tmp_path_)
  604. # Now generate all segments of the path
  605. foreach(segment_ IN LISTS split_source_)
  606. string(APPEND tmp_path_ "/${segment_}")
  607. list(APPEND additional_sources_all_ "${tmp_path_}")
  608. endforeach()
  609. endforeach()
  610. list(REMOVE_DUPLICATES additional_sources_all_)
  611. list(REMOVE_ITEM additional_sources_all_
  612. ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS})
  613. unset(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  614. foreach(source_ IN LISTS additional_sources_all_)
  615. string(APPEND TMP_DEBUGINFO_ADDITIONAL_SOURCES "${source_}\n")
  616. endforeach()
  617. endif()
  618. set(TMP_RPM_DEBUGINFO_INSTALL "${TMP_RPM_DEBUGINFO_INSTALL}" PARENT_SCOPE)
  619. set(TMP_DEBUGINFO_ADDITIONAL_SOURCES "${TMP_DEBUGINFO_ADDITIONAL_SOURCES}"
  620. PARENT_SCOPE)
  621. endfunction()
  622. function(cpack_rpm_variable_fallback OUTPUT_VAR_NAME)
  623. set(FALLBACK_VAR_NAMES ${ARGN})
  624. foreach(variable_name IN LISTS FALLBACK_VAR_NAMES)
  625. if(${variable_name})
  626. set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE)
  627. break()
  628. endif()
  629. endforeach()
  630. endfunction()
  631. function(cpack_rpm_generate_package)
  632. # rpmbuild is the basic command for building RPM package
  633. # it may be a simple (symbolic) link to rpm command.
  634. find_program(RPMBUILD_EXECUTABLE rpmbuild)
  635. # Check version of the rpmbuild tool this would be easier to
  636. # track bugs with users and CPackRPM debug mode.
  637. # We may use RPM version in order to check for available version dependent features
  638. if(RPMBUILD_EXECUTABLE)
  639. execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
  640. OUTPUT_VARIABLE _TMP_VERSION
  641. ERROR_QUIET
  642. OUTPUT_STRIP_TRAILING_WHITESPACE)
  643. string(REGEX REPLACE "^.* " ""
  644. RPMBUILD_EXECUTABLE_VERSION
  645. ${_TMP_VERSION})
  646. if(CPACK_RPM_PACKAGE_DEBUG)
  647. message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
  648. endif()
  649. endif()
  650. if(NOT RPMBUILD_EXECUTABLE)
  651. message(FATAL_ERROR "RPM package requires rpmbuild executable")
  652. endif()
  653. # Display lsb_release output if DEBUG mode enable
  654. # This will help to diagnose problem with CPackRPM
  655. # because we will know on which kind of Linux we are
  656. if(CPACK_RPM_PACKAGE_DEBUG)
  657. find_program(LSB_RELEASE_EXECUTABLE lsb_release)
  658. if(LSB_RELEASE_EXECUTABLE)
  659. execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
  660. OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
  661. ERROR_QUIET
  662. OUTPUT_STRIP_TRAILING_WHITESPACE)
  663. string(REGEX REPLACE "\n" ", "
  664. LSB_RELEASE_OUTPUT
  665. ${_TMP_LSB_RELEASE_OUTPUT})
  666. else ()
  667. set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
  668. endif()
  669. message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
  670. endif()
  671. # We may use RPM version in the future in order
  672. # to shut down warning about space in buildtree
  673. # some recent RPM version should support space in different places.
  674. # not checked [yet].
  675. if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
  676. message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
  677. endif()
  678. # If rpmbuild is found
  679. # we try to discover alien since we may be on non RPM distro like Debian.
  680. # In this case we may try to to use more advanced features
  681. # like generating RPM directly from DEB using alien.
  682. # FIXME feature not finished (yet)
  683. find_program(ALIEN_EXECUTABLE alien)
  684. if(ALIEN_EXECUTABLE)
  685. message(STATUS "alien found, we may be on a Debian based distro.")
  686. endif()
  687. # Are we packaging components ?
  688. if(CPACK_RPM_PACKAGE_COMPONENT)
  689. string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  690. endif()
  691. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  692. #
  693. # Use user-defined RPM specific variables value
  694. # or generate reasonable default value from
  695. # CPACK_xxx generic values.
  696. # The variables comes from the needed (mandatory or not)
  697. # values found in the RPM specification file aka ".spec" file.
  698. # The variables which may/should be defined are:
  699. #
  700. # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
  701. if(CPACK_RPM_PACKAGE_COMPONENT)
  702. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_SUMMARY"
  703. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY"
  704. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_SUMMARY")
  705. endif()
  706. if(NOT CPACK_RPM_PACKAGE_SUMMARY)
  707. if(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  708. set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  709. else()
  710. # if neither var is defined lets use the name as summary
  711. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
  712. endif()
  713. endif()
  714. if(NOT CPACK_RPM_PACKAGE_URL AND CMAKE_PROJECT_HOMEPAGE_URL)
  715. set(CPACK_RPM_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}")
  716. endif()
  717. # CPACK_RPM_PACKAGE_NAME (mandatory)
  718. if(NOT CPACK_RPM_PACKAGE_NAME)
  719. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
  720. endif()
  721. if(CPACK_RPM_PACKAGE_COMPONENT)
  722. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  723. CPACK_RPM_MAIN_COMPONENT_UPPER)
  724. if(NOT CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  725. string(APPEND CPACK_RPM_PACKAGE_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
  726. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_NAME"
  727. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME"
  728. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME")
  729. endif()
  730. endif()
  731. # CPACK_RPM_PACKAGE_VERSION (mandatory)
  732. if(NOT CPACK_RPM_PACKAGE_VERSION)
  733. if(NOT CPACK_PACKAGE_VERSION)
  734. message(FATAL_ERROR "RPM package requires a package version")
  735. endif()
  736. set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  737. endif()
  738. # Replace '-' in version with '_'
  739. # '-' character is an Illegal RPM version character
  740. # it is illegal because it is used to separate
  741. # RPM "Version" from RPM "Release"
  742. string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
  743. # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory)
  744. if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
  745. execute_process(COMMAND uname "-m"
  746. OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
  747. OUTPUT_STRIP_TRAILING_WHITESPACE)
  748. else()
  749. if(CPACK_RPM_PACKAGE_DEBUG)
  750. message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  751. endif()
  752. endif()
  753. if(CPACK_RPM_PACKAGE_COMPONENT)
  754. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_ARCHITECTURE"
  755. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE"
  756. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_ARCHITECTURE")
  757. if(CPACK_RPM_PACKAGE_DEBUG)
  758. message("CPackRPM:Debug: using component build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  759. endif()
  760. endif()
  761. if(${CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch")
  762. set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
  763. else()
  764. set(TMP_RPM_BUILDARCH "")
  765. endif()
  766. # CPACK_RPM_PACKAGE_RELEASE
  767. # The RPM release is the numbering of the RPM package ITSELF
  768. # this is the version of the PACKAGING and NOT the version
  769. # of the CONTENT of the package.
  770. # You may well need to generate a new RPM package release
  771. # without changing the version of the packaged software.
  772. # This is the case when the packaging is buggy (not) the software :=)
  773. # If not set, 1 is a good candidate
  774. if(NOT CPACK_RPM_PACKAGE_RELEASE)
  775. set(CPACK_RPM_PACKAGE_RELEASE "1")
  776. endif()
  777. if(CPACK_RPM_PACKAGE_RELEASE_DIST)
  778. string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}")
  779. endif()
  780. # CPACK_RPM_PACKAGE_LICENSE
  781. if(NOT CPACK_RPM_PACKAGE_LICENSE)
  782. set(CPACK_RPM_PACKAGE_LICENSE "unknown")
  783. endif()
  784. # CPACK_RPM_PACKAGE_GROUP
  785. if(CPACK_RPM_PACKAGE_COMPONENT)
  786. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_GROUP"
  787. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP"
  788. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_GROUP")
  789. endif()
  790. if(NOT CPACK_RPM_PACKAGE_GROUP)
  791. set(CPACK_RPM_PACKAGE_GROUP "unknown")
  792. endif()
  793. # CPACK_RPM_PACKAGE_VENDOR
  794. if(NOT CPACK_RPM_PACKAGE_VENDOR)
  795. if(CPACK_PACKAGE_VENDOR)
  796. set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
  797. else()
  798. set(CPACK_RPM_PACKAGE_VENDOR "unknown")
  799. endif()
  800. endif()
  801. # CPACK_RPM_PACKAGE_SOURCE
  802. # The name of the source tarball in case we generate a source RPM
  803. # CPACK_RPM_PACKAGE_DESCRIPTION
  804. # The variable content may be either
  805. # - explicitly given by the user or
  806. # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
  807. # if it is defined
  808. # - set to a default value
  809. #
  810. if(CPACK_RPM_PACKAGE_COMPONENT)
  811. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_DESCRIPTION"
  812. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION"
  813. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_DESCRIPTION"
  814. "CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION")
  815. endif()
  816. if(NOT CPACK_RPM_PACKAGE_DESCRIPTION)
  817. if(CPACK_PACKAGE_DESCRIPTION_FILE)
  818. file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
  819. else ()
  820. set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
  821. endif ()
  822. endif ()
  823. # CPACK_RPM_COMPRESSION_TYPE
  824. #
  825. if (CPACK_RPM_COMPRESSION_TYPE)
  826. if(CPACK_RPM_PACKAGE_DEBUG)
  827. message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
  828. endif()
  829. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
  830. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
  831. endif()
  832. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
  833. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
  834. endif()
  835. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
  836. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
  837. endif()
  838. if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
  839. set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
  840. endif()
  841. else()
  842. set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
  843. endif()
  844. if(NOT CPACK_RPM_PACKAGE_SOURCES)
  845. if(CPACK_PACKAGE_RELOCATABLE OR CPACK_RPM_PACKAGE_RELOCATABLE)
  846. if(CPACK_RPM_PACKAGE_DEBUG)
  847. message("CPackRPM:Debug: Trying to build a relocatable package")
  848. endif()
  849. if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
  850. 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.")
  851. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE)
  852. else()
  853. set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files)
  854. cpack_rpm_prepare_relocation_paths()
  855. set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
  856. endif()
  857. endif()
  858. else()
  859. if(CPACK_RPM_PACKAGE_COMPONENT)
  860. message(FATAL_ERROR "CPACK_RPM_PACKAGE_SOURCES parameter can not be used"
  861. " in combination with CPACK_RPM_PACKAGE_COMPONENT parameter!")
  862. endif()
  863. set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) # disable relocatable option if building source RPM
  864. endif()
  865. execute_process(
  866. COMMAND "${RPMBUILD_EXECUTABLE}" --querytags
  867. OUTPUT_VARIABLE RPMBUILD_TAG_LIST
  868. OUTPUT_STRIP_TRAILING_WHITESPACE)
  869. string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}")
  870. if(CPACK_RPM_PACKAGE_EPOCH)
  871. set(TMP_RPM_EPOCH "Epoch: ${CPACK_RPM_PACKAGE_EPOCH}")
  872. endif()
  873. # Check if additional fields for RPM spec header are given
  874. # There may be some COMPONENT specific variables as well
  875. # If component specific var is not provided we use the global one
  876. # for each component
  877. foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  878. if(CPACK_RPM_PACKAGE_DEBUG)
  879. message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
  880. endif()
  881. if(CPACK_RPM_PACKAGE_COMPONENT)
  882. cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}"
  883. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}"
  884. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_${_RPM_SPEC_HEADER}")
  885. endif()
  886. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
  887. # Prefix can be replaced by Prefixes but the old version still works so we'll ignore it for now
  888. # Requires* is a special case because it gets transformed to Requires(pre/post/preun/postun)
  889. # Auto* is a special case because the tags can not be queried by querytags rpmbuild flag
  890. set(special_case_tags_ PREFIX REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN AUTOPROV AUTOREQ AUTOREQPROV)
  891. if(NOT _RPM_SPEC_HEADER IN_LIST RPMBUILD_TAG_LIST AND NOT _RPM_SPEC_HEADER IN_LIST special_case_tags_)
  892. message(AUTHOR_WARNING "CPackRPM:Warning: ${_RPM_SPEC_HEADER} not "
  893. "supported in provided rpmbuild. Tag will not be used.")
  894. continue()
  895. endif()
  896. if(CPACK_RPM_PACKAGE_DEBUG)
  897. message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
  898. endif()
  899. set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
  900. endif()
  901. # Treat the RPM Spec keyword iff it has been properly defined
  902. if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  903. # Transform NAME --> Name e.g. PROVIDES --> Provides
  904. # The Upper-case first letter and lowercase tail is the
  905. # appropriate value required in the final RPM spec file.
  906. string(SUBSTRING ${_RPM_SPEC_HEADER} 1 -1 _PACKAGE_HEADER_TAIL)
  907. string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
  908. string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
  909. string(APPEND _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_TAIL}")
  910. # The following keywords require parentheses around the "pre" or "post" suffix in the final RPM spec file.
  911. set(SCRIPTS_REQUIREMENTS_LIST REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
  912. list(FIND SCRIPTS_REQUIREMENTS_LIST ${_RPM_SPEC_HEADER} IS_SCRIPTS_REQUIREMENT_FOUND)
  913. if(NOT ${IS_SCRIPTS_REQUIREMENT_FOUND} EQUAL -1)
  914. string(REPLACE "_" "(" _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}")
  915. string(APPEND _PACKAGE_HEADER_NAME ")")
  916. endif()
  917. if(CPACK_RPM_PACKAGE_DEBUG)
  918. message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  919. endif()
  920. set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
  921. unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
  922. endif()
  923. endforeach()
  924. # CPACK_RPM_SPEC_INSTALL_POST
  925. # May be used to define a RPM post intallation script
  926. # for example setting it to "/bin/true" may prevent
  927. # rpmbuild from stripping binaries.
  928. if(CPACK_RPM_SPEC_INSTALL_POST)
  929. if(CPACK_RPM_PACKAGE_DEBUG)
  930. message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
  931. endif()
  932. set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
  933. endif()
  934. # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
  935. # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
  936. # May be used to embed a post (un)installation script in the spec file.
  937. # The referred script file(s) will be read and directly
  938. # put after the %post or %postun section
  939. # ----------------------------------------------------------------
  940. # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
  941. # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
  942. # May be used to embed a pre (un)installation script in the spec file.
  943. # The referred script file(s) will be read and directly
  944. # put after the %pre or %preun section
  945. foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL")
  946. foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST")
  947. set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  948. "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}")
  949. if(CPACK_RPM_PACKAGE_COMPONENT)
  950. cpack_rpm_variable_fallback("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE"
  951. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE"
  952. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE")
  953. endif()
  954. # Handle file if it has been specified
  955. if(CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE)
  956. if(EXISTS ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE})
  957. file(READ ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}
  958. "CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}")
  959. else()
  960. 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")
  961. endif()
  962. else()
  963. # reset SPEC var value if no file has been specified
  964. # (either globally or component-wise)
  965. set("CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}" "")
  966. endif()
  967. endforeach()
  968. endforeach()
  969. # CPACK_RPM_CHANGELOG_FILE
  970. # May be used to embed a changelog in the spec file.
  971. # The referred file will be read and directly put after the %changelog section
  972. if(CPACK_RPM_CHANGELOG_FILE)
  973. if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
  974. file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
  975. else()
  976. message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
  977. endif()
  978. else()
  979. 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)")
  980. endif()
  981. # CPACK_RPM_SPEC_MORE_DEFINE
  982. # This is a generated spec rpm file spaceholder
  983. if(CPACK_RPM_SPEC_MORE_DEFINE)
  984. if(CPACK_RPM_PACKAGE_DEBUG)
  985. message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
  986. endif()
  987. endif()
  988. # Now we may create the RPM build tree structure
  989. set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
  990. if(CPACK_RPM_PACKAGE_DEBUG)
  991. message("CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
  992. endif()
  993. # Prepare RPM build tree
  994. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
  995. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
  996. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
  997. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
  998. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
  999. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
  1000. file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
  1001. # it seems rpmbuild can't handle spaces in the path
  1002. # neither escaping (as below) nor putting quotes around the path seem to help
  1003. #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1004. set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
  1005. cpack_rpm_prepare_content_list()
  1006. # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
  1007. # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1008. # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
  1009. # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
  1010. if(CPACK_RPM_PACKAGE_COMPONENT)
  1011. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1012. cpack_rpm_variable_fallback("COMPONENT_FILES_TAG"
  1013. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}"
  1014. "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}")
  1015. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
  1016. if(CPACK_RPM_PACKAGE_DEBUG)
  1017. message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
  1018. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1019. endif()
  1020. endif()
  1021. else()
  1022. if(CPACK_ABSOLUTE_DESTINATION_FILES)
  1023. set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
  1024. endif()
  1025. endif()
  1026. # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
  1027. set(CPACK_RPM_USER_FILELIST_INTERNAL "")
  1028. if(CPACK_RPM_PACKAGE_COMPONENT)
  1029. cpack_rpm_variable_fallback("CPACK_RPM_USER_FILELIST_INTERNAL"
  1030. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST"
  1031. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_FILELIST")
  1032. if(CPACK_RPM_PACKAGE_DEBUG AND CPACK_RPM_USER_FILELIST_INTERNAL)
  1033. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1034. message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
  1035. endif()
  1036. elseif(CPACK_RPM_USER_FILELIST)
  1037. set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
  1038. endif()
  1039. # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
  1040. # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1041. # or CPACK_RPM_INSTALL_FILES,
  1042. # hence it must be done before these auto-generated lists are processed.
  1043. if(CPACK_RPM_USER_FILELIST_INTERNAL)
  1044. if(CPACK_RPM_PACKAGE_DEBUG)
  1045. message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
  1046. endif()
  1047. # Create CMake list from CPACK_RPM_INSTALL_FILES
  1048. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1049. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
  1050. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1051. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
  1052. "${CPACK_RPM_INSTALL_FILES_LIST}")
  1053. set(CPACK_RPM_USER_INSTALL_FILES "")
  1054. foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
  1055. string(REGEX REPLACE "%[A-Za-z]+(\\([^()]*\\))? " "" F_PATH ${F})
  1056. string(REGEX MATCH "(%[A-Za-z]+(\\([^()]*\\))? )*" F_PREFIX ${F})
  1057. string(STRIP ${F_PREFIX} F_PREFIX)
  1058. if(CPACK_RPM_PACKAGE_DEBUG)
  1059. message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
  1060. endif()
  1061. if(F_PREFIX)
  1062. string(APPEND F_PREFIX " ")
  1063. endif()
  1064. # Rebuild the user list file
  1065. string(APPEND CPACK_RPM_USER_INSTALL_FILES "${F_PREFIX}\"${F_PATH}\"\n")
  1066. # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
  1067. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
  1068. # ABSOLUTE destination files list may not exists at all
  1069. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1070. list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
  1071. endif()
  1072. endforeach()
  1073. # Rebuild CPACK_RPM_INSTALL_FILES
  1074. set(CPACK_RPM_INSTALL_FILES "")
  1075. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1076. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1077. endforeach()
  1078. else()
  1079. set(CPACK_RPM_USER_INSTALL_FILES "")
  1080. endif()
  1081. if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1082. if(CPACK_RPM_PACKAGE_DEBUG)
  1083. message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
  1084. endif()
  1085. # Remove trailing space
  1086. string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
  1087. # Transform endline separated - string into CMake List
  1088. string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1089. # Remove unnecessary quotes
  1090. string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
  1091. # Remove ABSOLUTE install file from INSTALL FILE LIST
  1092. list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
  1093. # Rebuild INSTALL_FILES
  1094. set(CPACK_RPM_INSTALL_FILES "")
  1095. foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
  1096. string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n")
  1097. endforeach()
  1098. # Build ABSOLUTE_INSTALL_FILES
  1099. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1100. foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
  1101. string(APPEND CPACK_RPM_ABSOLUTE_INSTALL_FILES "%config \"${F}\"\n")
  1102. endforeach()
  1103. if(CPACK_RPM_PACKAGE_DEBUG)
  1104. message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
  1105. message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
  1106. endif()
  1107. else()
  1108. # reset vars in order to avoid leakage of value(s) from one component to another
  1109. set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
  1110. endif()
  1111. cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_PACKAGE"
  1112. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_PACKAGE"
  1113. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_PACKAGE"
  1114. "CPACK_RPM_DEBUGINFO_PACKAGE")
  1115. if(CPACK_RPM_DEBUGINFO_PACKAGE OR (CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND NOT GENERATE_SPEC_PARTS))
  1116. cpack_rpm_variable_fallback("CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX"
  1117. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_BUILD_SOURCE_DIRS_PREFIX"
  1118. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_BUILD_SOURCE_DIRS_PREFIX"
  1119. "CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX")
  1120. if(NOT CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX)
  1121. set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
  1122. endif()
  1123. # handle cases where path contains extra slashes (e.g. /a//b/ instead of
  1124. # /a/b)
  1125. get_filename_component(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX
  1126. "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}" ABSOLUTE)
  1127. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  1128. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files"
  1129. "${CPACK_RPM_INSTALL_FILES}")
  1130. else()
  1131. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND CPACK_RPM_PACKAGE_COMPONENT)
  1132. # this part is only required by components packaging - with monolithic
  1133. # packages we can be certain that there are no other components present
  1134. # so CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is a noop
  1135. if(CPACK_RPM_DEBUGINFO_PACKAGE)
  1136. # only add current package files to debuginfo list if debuginfo
  1137. # generation is enabled for current package
  1138. string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_)
  1139. string(REPLACE "\n" ";" install_files_ "${install_files_}")
  1140. string(REPLACE "\"" "" install_files_ "${install_files_}")
  1141. else()
  1142. unset(install_files_)
  1143. endif()
  1144. file(GLOB files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.files")
  1145. foreach(f_ IN LISTS files_)
  1146. file(READ "${f_}" tmp_)
  1147. string(APPEND install_files_ ";${tmp_}")
  1148. endforeach()
  1149. # if there were other components/groups so we need to move files from them
  1150. # to current component otherwise those files won't be found
  1151. file(GLOB components_ LIST_DIRECTORIES true RELATIVE
  1152. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}"
  1153. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/*")
  1154. foreach(component_ IN LISTS components_)
  1155. string(TOUPPER "${component_}" component_dir_upper_)
  1156. if(component_dir_upper_ STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1157. # skip current component
  1158. continue()
  1159. endif()
  1160. file(GLOB_RECURSE files_for_move_ LIST_DIRECTORIES false RELATIVE
  1161. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}"
  1162. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/*")
  1163. foreach(f_ IN LISTS files_for_move_)
  1164. get_filename_component(dir_path_ "${f_}" DIRECTORY)
  1165. set(src_file_
  1166. "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/${f_}")
  1167. # check that we are not overriding an existing file that doesn't
  1168. # match the file that we want to copy
  1169. if(EXISTS "${src_file_}" AND EXISTS "${WDIR}/${f_}")
  1170. execute_process(
  1171. COMMAND ${CMAKE_COMMAND} -E compare_files "${src_file_}" "${WDIR}/${f_}"
  1172. RESULT_VARIABLE res_
  1173. )
  1174. if(res_)
  1175. message(FATAL_ERROR "CPackRPM:Error: File on path '${WDIR}/${f_}'"
  1176. " already exists but is a different than the one in component"
  1177. " '${component_}'! Packages will not be generated.")
  1178. endif()
  1179. endif()
  1180. file(MAKE_DIRECTORY "${WDIR}/${dir_path_}")
  1181. file(RENAME "${src_file_}"
  1182. "${WDIR}/${f_}")
  1183. endforeach()
  1184. endforeach()
  1185. cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}")
  1186. else()
  1187. string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_)
  1188. string(REPLACE "\n" ";" install_files_ "${install_files_}")
  1189. string(REPLACE "\"" "" install_files_ "${install_files_}")
  1190. cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}")
  1191. endif()
  1192. if(TMP_DEBUGINFO_ADDITIONAL_SOURCES)
  1193. set(TMP_RPM_DEBUGINFO "
  1194. # Modified version of %%debug_package macro
  1195. # defined in /usr/lib/rpm/macros as that one
  1196. # can't handle injection of extra source files.
  1197. %ifnarch noarch
  1198. %global __debug_package 1
  1199. %package debuginfo
  1200. Summary: Debug information for package %{name}
  1201. Group: Development/Debug
  1202. AutoReqProv: 0
  1203. %description debuginfo
  1204. This package provides debug information for package %{name}.
  1205. Debug information is useful when developing applications that use this
  1206. package or when debugging this package.
  1207. %files debuginfo -f debugfiles.list
  1208. %defattr(-,root,root)
  1209. ${TMP_DEBUGINFO_ADDITIONAL_SOURCES}
  1210. %endif
  1211. ")
  1212. elseif(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  1213. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  1214. " but will not be generated as no source files were found!")
  1215. else()
  1216. message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested"
  1217. " but will not be generated as no source files were found! Component: '"
  1218. "${CPACK_RPM_PACKAGE_COMPONENT}'.")
  1219. endif()
  1220. endif()
  1221. endif()
  1222. # Prepare install files
  1223. cpack_rpm_prepare_install_files(
  1224. "${CPACK_RPM_INSTALL_FILES}"
  1225. "${WDIR}"
  1226. "${RPM_USED_PACKAGE_PREFIXES}"
  1227. "${CPACK_RPM_PACKAGE_RELOCATABLE}"
  1228. )
  1229. # set default user and group
  1230. foreach(_PERM_TYPE "USER" "GROUP")
  1231. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE})
  1232. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}}")
  1233. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE})
  1234. set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_DEFAULT_${_PERM_TYPE}}")
  1235. else()
  1236. set(TMP_DEFAULT_${_PERM_TYPE} "root")
  1237. endif()
  1238. endforeach()
  1239. # set default file and dir permissions
  1240. foreach(_PERM_TYPE "FILE" "DIR")
  1241. if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  1242. get_unix_permissions_octal_notation("CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  1243. set(_PERMISSIONS_VAR "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  1244. elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS)
  1245. get_unix_permissions_octal_notation("CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  1246. set(_PERMISSIONS_VAR "CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS")
  1247. else()
  1248. set(TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS "-")
  1249. endif()
  1250. endforeach()
  1251. # The name of the final spec file to be used by rpmbuild
  1252. set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
  1253. # Print out some debug information if we were asked for that
  1254. if(CPACK_RPM_PACKAGE_DEBUG)
  1255. message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  1256. message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  1257. message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  1258. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  1259. message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  1260. message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  1261. message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
  1262. message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  1263. message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  1264. endif()
  1265. #
  1266. # USER generated/provided spec file handling.
  1267. #
  1268. # We can have a component specific spec file.
  1269. if(CPACK_RPM_PACKAGE_COMPONENT)
  1270. cpack_rpm_variable_fallback("CPACK_RPM_USER_BINARY_SPECFILE"
  1271. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE"
  1272. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_BINARY_SPECFILE")
  1273. endif()
  1274. cpack_rpm_variable_fallback("CPACK_RPM_FILE_NAME"
  1275. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_FILE_NAME"
  1276. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_FILE_NAME"
  1277. "CPACK_RPM_FILE_NAME")
  1278. if(NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  1279. if(CPACK_RPM_FILE_NAME)
  1280. if(NOT CPACK_RPM_FILE_NAME MATCHES ".*\\.rpm")
  1281. message(FATAL_ERROR "'${CPACK_RPM_FILE_NAME}' is not a valid RPM package file name as it must end with '.rpm'!")
  1282. endif()
  1283. else()
  1284. # old file name format for back compatibility
  1285. string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}"
  1286. CPACK_RPM_MAIN_COMPONENT_UPPER)
  1287. if(CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER)
  1288. # this is the main component so ignore the component filename part
  1289. set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.rpm")
  1290. else()
  1291. set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
  1292. endif()
  1293. endif()
  1294. # else example:
  1295. #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
  1296. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS)
  1297. string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" expected_filename_)
  1298. file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.rpm_name"
  1299. "${expected_filename_};${CPACK_RPM_FILE_NAME}")
  1300. elseif(NOT CPACK_RPM_DEBUGINFO_PACKAGE)
  1301. set(FILE_NAME_DEFINE "%define _rpmfilename ${CPACK_RPM_FILE_NAME}")
  1302. endif()
  1303. endif()
  1304. if(CPACK_RPM_PACKAGE_SOURCES) # source rpm
  1305. set(archive_name_ "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}")
  1306. execute_process(
  1307. COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${CPACK_RPM_DIRECTORY}/SOURCES/${archive_name_}.tar.gz" "${CPACK_PACKAGE_FILE_NAME}"
  1308. WORKING_DIRECTORY ${CPACK_RPM_DIRECTORY}
  1309. )
  1310. set(TMP_RPM_SOURCE "Source: ${archive_name_}.tar.gz")
  1311. if(CPACK_RPM_BUILDREQUIRES)
  1312. set(TMP_RPM_BUILD_REQUIRES "BuildRequires: ${CPACK_RPM_BUILDREQUIRES}")
  1313. endif()
  1314. # Disable debuginfo packages - srpm generates invalid packages due to
  1315. # releasing control to cpack to generate binary packages.
  1316. # Note however that this doesn't prevent cpack to generate debuginfo
  1317. # packages when run from srpm with --rebuild.
  1318. set(TMP_RPM_DISABLE_DEBUGINFO "%define debug_package %{nil}")
  1319. if(NOT CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX)
  1320. set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/")
  1321. endif()
  1322. set(TMP_RPM_BUILD
  1323. "
  1324. %build
  1325. mkdir cpack_rpm_build_dir
  1326. cd cpack_rpm_build_dir
  1327. '${CMAKE_COMMAND}' ${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCPACK_PACKAGING_INSTALL_PREFIX=${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX} ../${CPACK_PACKAGE_FILE_NAME}
  1328. make %{?_smp_mflags}" # %{?_smp_mflags} -> -j option
  1329. )
  1330. set(TMP_RPM_INSTALL
  1331. "
  1332. cd cpack_rpm_build_dir
  1333. cpack -G RPM
  1334. mv *.rpm %_rpmdir"
  1335. )
  1336. set(TMP_RPM_PREP "%setup -c")
  1337. set(RPMBUILD_FLAGS "-bs")
  1338. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  1339. "# Restore old style debuginfo creation for rpm >= 4.14.
  1340. %undefine _debugsource_packages
  1341. %undefine _debuginfo_subpackages
  1342. # -*- rpm-spec -*-
  1343. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@
  1344. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  1345. Name: \@CPACK_RPM_PACKAGE_NAME\@
  1346. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  1347. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  1348. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  1349. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  1350. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  1351. \@TMP_RPM_SOURCE\@
  1352. \@TMP_RPM_BUILD_REQUIRES\@
  1353. \@TMP_RPM_BUILDARCH\@
  1354. \@TMP_RPM_PREFIXES\@
  1355. \@TMP_RPM_DISABLE_DEBUGINFO\@
  1356. %define _rpmdir %_topdir/RPMS
  1357. %define _srcrpmdir %_topdir/SRPMS
  1358. \@FILE_NAME_DEFINE\@
  1359. %define _unpackaged_files_terminate_build 0
  1360. \@TMP_RPM_SPEC_INSTALL_POST\@
  1361. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  1362. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  1363. %description
  1364. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  1365. # This is a shortcutted spec file generated by CMake RPM generator
  1366. # we skip _install step because CPack does that for us.
  1367. # We do only save CPack installed tree in _prepr
  1368. # and then restore it in build.
  1369. %prep
  1370. \@TMP_RPM_PREP\@
  1371. \@TMP_RPM_BUILD\@
  1372. #p build
  1373. %install
  1374. \@TMP_RPM_INSTALL\@
  1375. %clean
  1376. %changelog
  1377. \@CPACK_RPM_SPEC_CHANGELOG\@
  1378. "
  1379. )
  1380. elseif(GENERATE_SPEC_PARTS) # binary rpm with single debuginfo package
  1381. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  1382. "# -*- rpm-spec -*-
  1383. %package -n \@CPACK_RPM_PACKAGE_NAME\@
  1384. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  1385. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  1386. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  1387. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  1388. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  1389. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  1390. \@TMP_RPM_URL\@
  1391. \@TMP_RPM_REQUIRES\@
  1392. \@TMP_RPM_REQUIRES_PRE\@
  1393. \@TMP_RPM_REQUIRES_POST\@
  1394. \@TMP_RPM_REQUIRES_PREUN\@
  1395. \@TMP_RPM_REQUIRES_POSTUN\@
  1396. \@TMP_RPM_PROVIDES\@
  1397. \@TMP_RPM_OBSOLETES\@
  1398. \@TMP_RPM_CONFLICTS\@
  1399. \@TMP_RPM_SUGGESTS\@
  1400. \@TMP_RPM_AUTOPROV\@
  1401. \@TMP_RPM_AUTOREQ\@
  1402. \@TMP_RPM_AUTOREQPROV\@
  1403. \@TMP_RPM_BUILDARCH\@
  1404. \@TMP_RPM_PREFIXES\@
  1405. \@TMP_RPM_EPOCH\@
  1406. %description -n \@CPACK_RPM_PACKAGE_NAME\@
  1407. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  1408. %files -n \@CPACK_RPM_PACKAGE_NAME\@
  1409. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  1410. \@CPACK_RPM_INSTALL_FILES\@
  1411. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  1412. \@CPACK_RPM_USER_INSTALL_FILES\@
  1413. "
  1414. )
  1415. else() # binary rpm
  1416. if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE)
  1417. # find generated spec file and take its name
  1418. file(GLOB spec_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.spec")
  1419. foreach(f_ IN LISTS spec_files_)
  1420. file(READ "${f_}" tmp_)
  1421. string(APPEND TMP_OTHER_COMPONENTS "\n${tmp_}\n")
  1422. endforeach()
  1423. endif()
  1424. # We should generate a USER spec file template:
  1425. # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
  1426. # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
  1427. set(RPMBUILD_FLAGS "-bb")
  1428. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
  1429. file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
  1430. "# Restore old style debuginfo creation for rpm >= 4.14.
  1431. %undefine _debugsource_packages
  1432. %undefine _debuginfo_subpackages
  1433. # -*- rpm-spec -*-
  1434. BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
  1435. Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@
  1436. Name: \@CPACK_RPM_PACKAGE_NAME\@
  1437. Version: \@CPACK_RPM_PACKAGE_VERSION\@
  1438. Release: \@CPACK_RPM_PACKAGE_RELEASE\@
  1439. License: \@CPACK_RPM_PACKAGE_LICENSE\@
  1440. Group: \@CPACK_RPM_PACKAGE_GROUP\@
  1441. Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
  1442. \@TMP_RPM_URL\@
  1443. \@TMP_RPM_REQUIRES\@
  1444. \@TMP_RPM_REQUIRES_PRE\@
  1445. \@TMP_RPM_REQUIRES_POST\@
  1446. \@TMP_RPM_REQUIRES_PREUN\@
  1447. \@TMP_RPM_REQUIRES_POSTUN\@
  1448. \@TMP_RPM_PROVIDES\@
  1449. \@TMP_RPM_OBSOLETES\@
  1450. \@TMP_RPM_CONFLICTS\@
  1451. \@TMP_RPM_SUGGESTS\@
  1452. \@TMP_RPM_AUTOPROV\@
  1453. \@TMP_RPM_AUTOREQ\@
  1454. \@TMP_RPM_AUTOREQPROV\@
  1455. \@TMP_RPM_BUILDARCH\@
  1456. \@TMP_RPM_PREFIXES\@
  1457. \@TMP_RPM_EPOCH\@
  1458. \@TMP_RPM_DEBUGINFO\@
  1459. %define _rpmdir %_topdir/RPMS
  1460. %define _srcrpmdir %_topdir/SRPMS
  1461. \@FILE_NAME_DEFINE\@
  1462. %define _unpackaged_files_terminate_build 0
  1463. \@TMP_RPM_SPEC_INSTALL_POST\@
  1464. \@CPACK_RPM_SPEC_MORE_DEFINE\@
  1465. \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
  1466. %description
  1467. \@CPACK_RPM_PACKAGE_DESCRIPTION\@
  1468. # This is a shortcutted spec file generated by CMake RPM generator
  1469. # we skip _install step because CPack does that for us.
  1470. # We do only save CPack installed tree in _prepr
  1471. # and then restore it in build.
  1472. %prep
  1473. mv $RPM_BUILD_ROOT %_topdir/tmpBBroot
  1474. %install
  1475. if [ -e $RPM_BUILD_ROOT ];
  1476. then
  1477. rm -rf $RPM_BUILD_ROOT
  1478. fi
  1479. mv %_topdir/tmpBBroot $RPM_BUILD_ROOT
  1480. \@TMP_RPM_DEBUGINFO_INSTALL\@
  1481. %clean
  1482. %post
  1483. \@RPM_SYMLINK_POSTINSTALL\@
  1484. \@CPACK_RPM_SPEC_POSTINSTALL\@
  1485. %postun
  1486. \@CPACK_RPM_SPEC_POSTUNINSTALL\@
  1487. %pre
  1488. \@CPACK_RPM_SPEC_PREINSTALL\@
  1489. %preun
  1490. \@CPACK_RPM_SPEC_PREUNINSTALL\@
  1491. %files
  1492. %defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@)
  1493. \@CPACK_RPM_INSTALL_FILES\@
  1494. \@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
  1495. \@CPACK_RPM_USER_INSTALL_FILES\@
  1496. %changelog
  1497. \@CPACK_RPM_SPEC_CHANGELOG\@
  1498. \@TMP_OTHER_COMPONENTS\@
  1499. "
  1500. )
  1501. endif()
  1502. # Stop here if we were asked to only generate a template USER spec file
  1503. # The generated file may then be used as a template by user who wants
  1504. # to customize their own spec file.
  1505. if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
  1506. message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file template is: ${CPACK_RPM_BINARY_SPECFILE}.in")
  1507. endif()
  1508. endif()
  1509. # After that we may either use a user provided spec file
  1510. # or generate one using appropriate variables value.
  1511. if(CPACK_RPM_USER_BINARY_SPECFILE)
  1512. # User may have specified SPECFILE just use it
  1513. message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
  1514. # The user provided file is processed for @var replacement
  1515. configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  1516. else()
  1517. # No User specified spec file, will use the generated spec file
  1518. message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
  1519. # Note the just created file is processed for @var replacement
  1520. configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
  1521. endif()
  1522. if(NOT GENERATE_SPEC_PARTS) # generate package
  1523. if(RPMBUILD_EXECUTABLE)
  1524. # Now call rpmbuild using the SPECFILE
  1525. execute_process(
  1526. COMMAND "${RPMBUILD_EXECUTABLE}" ${RPMBUILD_FLAGS}
  1527. --define "_topdir ${CPACK_RPM_DIRECTORY}"
  1528. --buildroot "%_topdir/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  1529. --target "${CPACK_RPM_PACKAGE_ARCHITECTURE}"
  1530. "${CPACK_RPM_BINARY_SPECFILE}"
  1531. WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
  1532. RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
  1533. ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err"
  1534. OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  1535. if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
  1536. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR)
  1537. file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT)
  1538. message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
  1539. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err")
  1540. message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
  1541. message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
  1542. message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***")
  1543. endif()
  1544. else()
  1545. if(ALIEN_EXECUTABLE)
  1546. message(FATAL_ERROR "RPM packaging through alien not done (yet)")
  1547. endif()
  1548. endif()
  1549. # find generated rpm files and take their names
  1550. file(GLOB_RECURSE GENERATED_FILES "${CPACK_RPM_DIRECTORY}/RPMS/*.rpm"
  1551. "${CPACK_RPM_DIRECTORY}/SRPMS/*.rpm")
  1552. if(NOT GENERATED_FILES)
  1553. message(FATAL_ERROR "RPM package was not generated! ${CPACK_RPM_DIRECTORY}")
  1554. endif()
  1555. unset(expected_filenames_)
  1556. unset(filenames_)
  1557. if(CPACK_RPM_DEBUGINFO_PACKAGE AND NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT")
  1558. list(APPEND expected_filenames_
  1559. "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm")
  1560. list(APPEND filenames_ "${CPACK_RPM_FILE_NAME}")
  1561. endif()
  1562. if(CPACK_RPM_DEBUGINFO_PACKAGE)
  1563. cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_FILE_NAME"
  1564. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_FILE_NAME"
  1565. "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_FILE_NAME"
  1566. "CPACK_RPM_DEBUGINFO_FILE_NAME")
  1567. if(CPACK_RPM_DEBUGINFO_FILE_NAME AND
  1568. NOT CPACK_RPM_DEBUGINFO_FILE_NAME STREQUAL "RPM-DEFAULT")
  1569. list(APPEND expected_filenames_
  1570. "${CPACK_RPM_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}.*\\.rpm")
  1571. string(REPLACE "@cpack_component@" "${CPACK_RPM_PACKAGE_COMPONENT}"
  1572. CPACK_RPM_DEBUGINFO_FILE_NAME "${CPACK_RPM_DEBUGINFO_FILE_NAME}")
  1573. list(APPEND filenames_ "${CPACK_RPM_DEBUGINFO_FILE_NAME}")
  1574. endif()
  1575. endif()
  1576. # check if other files have to be renamed
  1577. file(GLOB rename_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.rpm_name")
  1578. if(rename_files_)
  1579. foreach(f_ IN LISTS rename_files_)
  1580. file(READ "${f_}" tmp_)
  1581. list(GET tmp_ 0 efn_)
  1582. list(APPEND expected_filenames_ "${efn_}")
  1583. list(GET tmp_ 1 fn_)
  1584. list(APPEND filenames_ "${fn_}")
  1585. endforeach()
  1586. endif()
  1587. if(expected_filenames_)
  1588. foreach(F IN LISTS GENERATED_FILES)
  1589. unset(matched_)
  1590. foreach(expected_ IN LISTS expected_filenames_)
  1591. if(F MATCHES ".*/${expected_}")
  1592. list(FIND expected_filenames_ "${expected_}" idx_)
  1593. list(GET filenames_ ${idx_} filename_)
  1594. get_filename_component(FILE_PATH "${F}" DIRECTORY)
  1595. file(RENAME "${F}" "${FILE_PATH}/${filename_}")
  1596. list(APPEND new_files_list_ "${FILE_PATH}/${filename_}")
  1597. set(matched_ "YES")
  1598. break()
  1599. endif()
  1600. endforeach()
  1601. if(NOT matched_)
  1602. list(APPEND new_files_list_ "${F}")
  1603. endif()
  1604. endforeach()
  1605. set(GENERATED_FILES "${new_files_list_}")
  1606. endif()
  1607. endif()
  1608. set(GEN_CPACK_OUTPUT_FILES "${GENERATED_FILES}" PARENT_SCOPE)
  1609. if(CPACK_RPM_PACKAGE_DEBUG)
  1610. message("CPackRPM:Debug: GEN_CPACK_OUTPUT_FILES = ${GENERATED_FILES}")
  1611. endif()
  1612. endfunction()
  1613. cpack_rpm_generate_package()
  1614. cmake_policy(POP)