CPackDeb.cmake 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. #.rst:
  2. # CPackDeb
  3. # --------
  4. #
  5. # The builtin (binary) CPack Deb generator (Unix only)
  6. #
  7. # Variables specific to CPack Debian (DEB) generator
  8. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9. #
  10. # CPackDeb may be used to create Deb package using CPack.
  11. # CPackDeb is a CPack generator thus it uses the ``CPACK_XXX`` variables
  12. # used by CPack : https://cmake.org/Wiki/CMake:CPackConfiguration.
  13. # CPackDeb generator should work on any linux host but it will produce
  14. # better deb package when Debian specific tools 'dpkg-xxx' are usable on
  15. # the build system.
  16. #
  17. # CPackDeb has specific features which are controlled by the specifics
  18. # :code:`CPACK_DEBIAN_XXX` variables.
  19. #
  20. # :code:`CPACK_DEBIAN_<COMPONENT>_XXXX` variables may be used in order to have
  21. # **component** specific values. Note however that ``<COMPONENT>`` refers to the
  22. # **grouping name** written in upper case. It may be either a component name or
  23. # a component GROUP name.
  24. #
  25. # You'll find a detailed usage on the wiki:
  26. # https://cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29 .
  27. # However as a handy reminder here comes the list of specific variables:
  28. #
  29. # .. variable:: CPACK_DEBIAN_PACKAGE_NAME
  30. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_NAME
  31. #
  32. # The Debian package summary
  33. #
  34. # * Mandatory : YES
  35. # * Default : :variable:`CPACK_PACKAGE_NAME` (lower case)
  36. #
  37. #
  38. # .. variable:: CPACK_DEBIAN_PACKAGE_VERSION
  39. #
  40. # The Debian package version
  41. #
  42. # * Mandatory : YES
  43. # * Default : :variable:`CPACK_PACKAGE_VERSION`
  44. #
  45. #
  46. # .. variable:: CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  47. #
  48. # The Debian package architecture
  49. #
  50. # * Mandatory : YES
  51. # * Default : Output of :code:`dpkg --print-architecture` (or :code:`i386`
  52. # if :code:`dpkg` is not found)
  53. #
  54. #
  55. # .. variable:: CPACK_DEBIAN_PACKAGE_DEPENDS
  56. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_DEPENDS
  57. #
  58. # Sets the Debian dependencies of this package.
  59. #
  60. # * Mandatory : NO
  61. # * Default :
  62. #
  63. # - An empty string for non-component based installations
  64. # - :variable:`CPACK_DEBIAN_PACKAGE_DEPENDS` for component-based
  65. # installations.
  66. #
  67. # .. note::
  68. #
  69. # If :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS` or
  70. # more specifically :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_SHLIBDEPS`
  71. # is set for this component, the discovered dependencies will be appended
  72. # to :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_DEPENDS` instead of
  73. # :variable:`CPACK_DEBIAN_PACKAGE_DEPENDS`. If
  74. # :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_DEPENDS` is an empty string,
  75. # only the automatically discovered dependencies will be set for this
  76. # component.
  77. #
  78. # Example::
  79. #
  80. # set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libc6 (< 2.4)")
  81. #
  82. #
  83. # .. variable:: CPACK_DEBIAN_PACKAGE_MAINTAINER
  84. #
  85. # The Debian package maintainer
  86. #
  87. # * Mandatory : YES
  88. # * Default : :code:`CPACK_PACKAGE_CONTACT`
  89. #
  90. #
  91. # .. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION
  92. # CPACK_COMPONENT_<COMPONENT>_DESCRIPTION
  93. #
  94. # The Debian package description
  95. #
  96. # * Mandatory : YES
  97. # * Default :
  98. #
  99. # - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set or
  100. # - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
  101. #
  102. #
  103. # .. variable:: CPACK_DEBIAN_PACKAGE_SECTION
  104. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_SECTION
  105. #
  106. # Set Section control field e.g. admin, devel, doc, ...
  107. #
  108. # * Mandatory : YES
  109. # * Default : 'devel'
  110. #
  111. # See https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
  112. #
  113. #
  114. # .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE
  115. #
  116. # The compression used for creating the Debian package.
  117. # Possible values are: lzma, xz, bzip2 and gzip.
  118. #
  119. # * Mandatory : YES
  120. # * Default : 'gzip'
  121. #
  122. #
  123. # .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
  124. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY
  125. #
  126. # Set Priority control field e.g. required, important, standard, optional,
  127. # extra
  128. #
  129. # * Mandatory : YES
  130. # * Default : 'optional'
  131. #
  132. # See https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
  133. #
  134. #
  135. # .. variable:: CPACK_DEBIAN_PACKAGE_HOMEPAGE
  136. #
  137. # The URL of the web site for this package, preferably (when applicable) the
  138. # site from which the original source can be obtained and any additional
  139. # upstream documentation or information may be found.
  140. #
  141. # * Mandatory : NO
  142. # * Default : -
  143. #
  144. # .. note::
  145. #
  146. # The content of this field is a simple URL without any surrounding
  147. # characters such as <>.
  148. #
  149. #
  150. # .. variable:: CPACK_DEBIAN_PACKAGE_SHLIBDEPS
  151. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_SHLIBDEPS
  152. #
  153. # May be set to ON in order to use :code:`dpkg-shlibdeps` to generate
  154. # better package dependency list.
  155. #
  156. # * Mandatory : NO
  157. # * Default :
  158. #
  159. # - :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS` if set or
  160. # - OFF
  161. #
  162. # .. note::
  163. #
  164. # You may need set :variable:`CMAKE_INSTALL_RPATH` to an appropriate value
  165. # if you use this feature, because if you don't :code:`dpkg-shlibdeps`
  166. # may fail to find your own shared libs.
  167. # See https://cmake.org/Wiki/CMake_RPATH_handling.
  168. #
  169. #
  170. # .. variable:: CPACK_DEBIAN_PACKAGE_DEBUG
  171. #
  172. # May be set when invoking cpack in order to trace debug information
  173. # during CPackDeb run.
  174. #
  175. # * Mandatory : NO
  176. # * Default : -
  177. #
  178. # .. variable:: CPACK_DEBIAN_PACKAGE_PREDEPENDS
  179. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_PREDEPENDS
  180. #
  181. # Sets the `Pre-Depends` field of the Debian package.
  182. # Like :variable:`Depends <CPACK_DEBIAN_PACKAGE_DEPENDS>`, except that it
  183. # also forces :code:`dpkg` to complete installation of the packages named
  184. # before even starting the installation of the package which declares the
  185. # pre-dependency.
  186. #
  187. # * Mandatory : NO
  188. # * Default :
  189. #
  190. # - An empty string for non-component based installations
  191. # - :variable:`CPACK_DEBIAN_PACKAGE_PREDEPENDS` for component-based
  192. # installations.
  193. #
  194. # See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  195. #
  196. # .. variable:: CPACK_DEBIAN_PACKAGE_ENHANCES
  197. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_ENHANCES
  198. #
  199. # Sets the `Enhances` field of the Debian package.
  200. # Similar to :variable:`Suggests <CPACK_DEBIAN_PACKAGE_SUGGESTS>` but works
  201. # in the opposite direction: declares that a package can enhance the
  202. # functionality of another package.
  203. #
  204. # * Mandatory : NO
  205. # * Default :
  206. #
  207. # - An empty string for non-component based installations
  208. # - :variable:`CPACK_DEBIAN_PACKAGE_ENHANCES` for component-based
  209. # installations.
  210. #
  211. # See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  212. #
  213. # .. variable:: CPACK_DEBIAN_PACKAGE_BREAKS
  214. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_BREAKS
  215. #
  216. # Sets the `Breaks` field of the Debian package.
  217. # When a binary package (P) declares that it breaks other packages (B),
  218. # :code:`dpkg` will not allow the package (P) which declares `Breaks` be
  219. # **unpacked** unless the packages that will be broken (B) are deconfigured
  220. # first.
  221. # As long as the package (P) is configured, the previously deconfigured
  222. # packages (B) cannot be reconfigured again.
  223. #
  224. # * Mandatory : NO
  225. # * Default :
  226. #
  227. # - An empty string for non-component based installations
  228. # - :variable:`CPACK_DEBIAN_PACKAGE_BREAKS` for component-based
  229. # installations.
  230. #
  231. # See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-breaks
  232. #
  233. #
  234. # .. variable:: CPACK_DEBIAN_PACKAGE_CONFLICTS
  235. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_CONFLICTS
  236. #
  237. # Sets the `Conflicts` field of the Debian package.
  238. # When one binary package declares a conflict with another using a `Conflicts`
  239. # field, :code:`dpkg` will not allow them to be unpacked on the system at
  240. # the same time.
  241. #
  242. # * Mandatory : NO
  243. # * Default :
  244. #
  245. # - An empty string for non-component based installations
  246. # - :variable:`CPACK_DEBIAN_PACKAGE_CONFLICTS` for component-based
  247. # installations.
  248. #
  249. # See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts
  250. #
  251. # .. note::
  252. #
  253. # This is a stronger restriction than
  254. # :variable:`Breaks <CPACK_DEBIAN_PACKAGE_BREAKS>`, which prevents the
  255. # broken package from being configured while the breaking package is in
  256. # the "Unpacked" state but allows both packages to be unpacked at the same
  257. # time.
  258. #
  259. # .. variable:: CPACK_DEBIAN_PACKAGE_PROVIDES
  260. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_PROVIDES
  261. #
  262. # Sets the `Provides` field of the Debian package.
  263. # A virtual package is one which appears in the `Provides` control field of
  264. # another package.
  265. #
  266. # * Mandatory : NO
  267. # * Default :
  268. #
  269. # - An empty string for non-component based installations
  270. # - :variable:`CPACK_DEBIAN_PACKAGE_PROVIDES` for component-based
  271. # installations.
  272. #
  273. # See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-virtual
  274. #
  275. #
  276. # .. variable:: CPACK_DEBIAN_PACKAGE_REPLACES
  277. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_REPLACES
  278. #
  279. # Sets the `Replaces` field of the Debian package.
  280. # Packages can declare in their control file that they should overwrite
  281. # files in certain other packages, or completely replace other packages.
  282. #
  283. # * Mandatory : NO
  284. # * Default :
  285. #
  286. # - An empty string for non-component based installations
  287. # - :variable:`CPACK_DEBIAN_PACKAGE_REPLACES` for component-based
  288. # installations.
  289. #
  290. # See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  291. #
  292. #
  293. # .. variable:: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  294. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_RECOMMENDS
  295. #
  296. # Sets the `Recommends` field of the Debian package.
  297. # Allows packages to declare a strong, but not absolute, dependency on other
  298. # packages.
  299. #
  300. # * Mandatory : NO
  301. # * Default :
  302. #
  303. # - An empty string for non-component based installations
  304. # - :variable:`CPACK_DEBIAN_PACKAGE_RECOMMENDS` for component-based
  305. # installations.
  306. #
  307. # See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  308. #
  309. #
  310. # .. variable:: CPACK_DEBIAN_PACKAGE_SUGGESTS
  311. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_SUGGESTS
  312. #
  313. # Sets the `Suggests` field of the Debian package.
  314. # Allows packages to declare a suggested package install grouping.
  315. #
  316. # * Mandatory : NO
  317. # * Default :
  318. #
  319. # - An empty string for non-component based installations
  320. # - :variable:`CPACK_DEBIAN_PACKAGE_SUGGESTS` for component-based
  321. # installations.
  322. #
  323. # See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  324. #
  325. #
  326. # .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  327. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_CONTROL_EXTRA
  328. #
  329. # This variable allow advanced user to add custom script to the
  330. # control.tar.gz.
  331. # Typical usage is for conffiles, postinst, postrm, prerm.
  332. #
  333. # * Mandatory : NO
  334. # * Default : -
  335. #
  336. # Usage::
  337. #
  338. # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  339. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  340. #
  341. # .. note::
  342. #
  343. # The original permissions of the files will be used in the final
  344. # package unless the variable
  345. # :variable:`CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION` is set.
  346. # In particular, the scripts should have the proper executable
  347. # flag prior to the generation of the package.
  348. #
  349. # .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION
  350. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_CONTROL_STRICT_PERMISSION
  351. #
  352. # This variable indicates if the Debian policy on control files should be
  353. # strictly followed.
  354. #
  355. # * Mandatory : NO
  356. # * Default : FALSE
  357. #
  358. # Usage::
  359. #
  360. # set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
  361. #
  362. # .. note::
  363. #
  364. # This overrides the permissions on the original files, following the rules
  365. # set by Debian policy
  366. # https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners
  367. #
  368. # .. variable:: CPACK_DEBIAN_PACKAGE_SOURCE
  369. # CPACK_DEBIAN_<COMPONENT>_PACKAGE_SOURCE
  370. #
  371. # Sets the ``Source`` field of the binary Debian package.
  372. # When the binary package name is not the same as the source package name
  373. # (in particular when several components/binaries are generated from one
  374. # source) the source from which the binary has been generated should be
  375. # indicated with the field ``Source``.
  376. #
  377. # * Mandatory : NO
  378. # * Default :
  379. #
  380. # - An empty string for non-component based installations
  381. # - :variable:`CPACK_DEBIAN_PACKAGE_SOURCE` for component-based
  382. # installations.
  383. #
  384. # See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
  385. #
  386. # .. note::
  387. #
  388. # This value is not interpreted. It is possible to pass an optional
  389. # revision number of the referenced source package as well.
  390. #=============================================================================
  391. # Copyright 2007-2009 Kitware, Inc.
  392. # Copyright 2007-2009 Mathieu Malaterre <[email protected]>
  393. #
  394. # Distributed under the OSI-approved BSD License (the "License");
  395. # see accompanying file Copyright.txt for details.
  396. #
  397. # This software is distributed WITHOUT ANY WARRANTY; without even the
  398. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  399. # See the License for more information.
  400. #=============================================================================
  401. # (To distribute this file outside of CMake, substitute the full
  402. # License text for the above reference.)
  403. # CPack script for creating Debian package
  404. # Author: Mathieu Malaterre
  405. #
  406. # http://wiki.debian.org/HowToPackageForDebian
  407. if(CMAKE_BINARY_DIR)
  408. message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
  409. endif()
  410. if(NOT UNIX)
  411. message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
  412. endif()
  413. function(cpack_deb_prepare_package_vars)
  414. # CPACK_DEBIAN_PACKAGE_SHLIBDEPS
  415. # If specify OFF, only user depends are used
  416. if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  417. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
  418. endif()
  419. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}")
  420. # per component automatic discover: some of the component might not have
  421. # binaries.
  422. if(CPACK_DEB_PACKAGE_COMPONENT)
  423. string(TOUPPER "${CPACK_DEB_PACKAGE_COMPONENT}" _local_component_name)
  424. set(_component_shlibdeps_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_SHLIBDEPS")
  425. # if set, overrides the global configuration
  426. if(DEFINED ${_component_shlibdeps_var})
  427. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "${${_component_shlibdeps_var}}")
  428. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  429. message("CPackDeb Debug: component '${CPACK_DEB_PACKAGE_COMPONENT}' dpkg-shlibdeps set to ${CPACK_DEBIAN_PACKAGE_SHLIBDEPS}")
  430. endif()
  431. endif()
  432. endif()
  433. if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  434. # dpkg-shlibdeps is a Debian utility for generating dependency list
  435. find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps)
  436. if(SHLIBDEPS_EXECUTABLE)
  437. # Check version of the dpkg-shlibdeps tool using CPackRPM method
  438. execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version
  439. OUTPUT_VARIABLE _TMP_VERSION
  440. ERROR_QUIET
  441. OUTPUT_STRIP_TRAILING_WHITESPACE)
  442. if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)")
  443. set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
  444. else()
  445. set(SHLIBDEPS_EXECUTABLE_VERSION "")
  446. endif()
  447. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  448. message("CPackDeb Debug: dpkg-shlibdeps --version output is '${_TMP_VERSION}'")
  449. message("CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>")
  450. endif()
  451. # Generating binary list - Get type of all install files
  452. cmake_policy(PUSH)
  453. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  454. # even if the project does not set this policy to NEW.
  455. cmake_policy(SET CMP0009 NEW)
  456. file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false RELATIVE "${WDIR}" "${WDIR}/*")
  457. cmake_policy(POP)
  458. # get file info so that we can determine if file is executable or not
  459. unset(CPACK_DEB_INSTALL_FILES)
  460. foreach(FILE_ IN LISTS FILE_PATHS_)
  461. execute_process(COMMAND file "./${FILE_}"
  462. WORKING_DIRECTORY "${WDIR}"
  463. OUTPUT_VARIABLE INSTALL_FILE_)
  464. list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}")
  465. endforeach()
  466. # Only dynamically linked ELF files are included
  467. # Extract only file name infront of ":"
  468. foreach(_FILE ${CPACK_DEB_INSTALL_FILES})
  469. if( ${_FILE} MATCHES "ELF.*dynamically linked")
  470. string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}")
  471. list(APPEND CPACK_DEB_BINARY_FILES "${CMAKE_MATCH_1}")
  472. set(CONTAINS_EXECUTABLE_FILES_ TRUE)
  473. endif()
  474. endforeach()
  475. if(CONTAINS_EXECUTABLE_FILES_)
  476. message("CPackDeb: - Generating dependency list")
  477. # Create blank control file for running dpkg-shlibdeps
  478. # There might be some other way to invoke dpkg-shlibdeps without creating this file
  479. # but standard debian package should not have anything that can collide with this file or directory
  480. file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian)
  481. file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "")
  482. # Add --ignore-missing-info if the tool supports it
  483. execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help
  484. OUTPUT_VARIABLE _TMP_HELP
  485. ERROR_QUIET
  486. OUTPUT_STRIP_TRAILING_WHITESPACE)
  487. if(_TMP_HELP MATCHES "--ignore-missing-info")
  488. set(IGNORE_MISSING_INFO_FLAG "--ignore-missing-info")
  489. endif()
  490. # Execute dpkg-shlibdeps
  491. # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package
  492. # -O : print to STDOUT
  493. execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}
  494. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  495. OUTPUT_VARIABLE SHLIBDEPS_OUTPUT
  496. RESULT_VARIABLE SHLIBDEPS_RESULT
  497. ERROR_VARIABLE SHLIBDEPS_ERROR
  498. OUTPUT_STRIP_TRAILING_WHITESPACE )
  499. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  500. # dpkg-shlibdeps will throw some warnings if some input files are not binary
  501. message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}")
  502. endif()
  503. if(NOT SHLIBDEPS_RESULT EQUAL 0)
  504. message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n"
  505. "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n"
  506. "found files: '${INSTALL_FILE_}';\n"
  507. "files info: '${CPACK_DEB_INSTALL_FILES}';\n"
  508. "binary files: '${CPACK_DEB_BINARY_FILES}'")
  509. endif()
  510. #Get rid of prefix generated by dpkg-shlibdeps
  511. string(REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS "${SHLIBDEPS_OUTPUT}")
  512. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  513. message("CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS} from output ${SHLIBDEPS_OUTPUT}")
  514. endif()
  515. # Remove blank control file
  516. # Might not be safe if package actual contain file or directory named debian
  517. file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian")
  518. else()
  519. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  520. message(AUTHOR_WARNING "CPackDeb Debug: Using only user-provided depends because package does not contain executable files that link to shared libraries.")
  521. endif()
  522. endif()
  523. else()
  524. message("CPackDeb: Using only user-provided dependencies because dpkg-shlibdeps is not found.")
  525. endif()
  526. else()
  527. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  528. message("CPackDeb Debug: Using only user-provided dependencies")
  529. endif()
  530. endif()
  531. # Let's define the control file found in debian package:
  532. # Binary package:
  533. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
  534. # DEBIAN/control
  535. # debian policy enforce lower case for package name
  536. # Package: (mandatory)
  537. if(NOT CPACK_DEBIAN_PACKAGE_NAME)
  538. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  539. endif()
  540. # Version: (mandatory)
  541. if(NOT CPACK_DEBIAN_PACKAGE_VERSION)
  542. if(NOT CPACK_PACKAGE_VERSION)
  543. message(FATAL_ERROR "CPackDeb: Debian package requires a package version")
  544. endif()
  545. set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  546. endif()
  547. # Architecture: (mandatory)
  548. if(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  549. # There is no such thing as i686 architecture on debian, you should use i386 instead
  550. # $ dpkg --print-architecture
  551. find_program(DPKG_CMD dpkg)
  552. if(NOT DPKG_CMD)
  553. message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.")
  554. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  555. endif()
  556. execute_process(COMMAND "${DPKG_CMD}" --print-architecture
  557. OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  558. OUTPUT_STRIP_TRAILING_WHITESPACE
  559. )
  560. endif()
  561. # Source: (optional)
  562. # in case several packages are constructed from a unique source
  563. # (multipackaging), the source may be indicated as well.
  564. # The source might contain a version if the generated package
  565. # version is different from the source version
  566. if(NOT CPACK_DEBIAN_PACKAGE_SOURCE)
  567. set(CPACK_DEBIAN_PACKAGE_SOURCE "")
  568. endif()
  569. # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES),
  570. # this returns the successful find_package() calls, maybe this can help
  571. # Depends:
  572. # You should set: DEBIAN_PACKAGE_DEPENDS
  573. # TODO: automate 'objdump -p | grep NEEDED'
  574. # if per-component variable, overrides the global CPACK_DEBIAN_PACKAGE_${variable_type_}
  575. # automatic dependency discovery will be performed afterwards.
  576. if(CPACK_DEB_PACKAGE_COMPONENT)
  577. foreach(value_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME)
  578. set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${value_type_}")
  579. # if set, overrides the global variable
  580. if(DEFINED ${_component_var})
  581. set(CPACK_DEBIAN_PACKAGE_${value_type_} "${${_component_var}}")
  582. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  583. message("CPackDeb Debug: component '${_local_component_name}' ${value_type_} "
  584. "value set to '${CPACK_DEBIAN_PACKAGE_${value_type_}}'")
  585. endif()
  586. endif()
  587. endforeach()
  588. endif()
  589. # at this point, the CPACK_DEBIAN_PACKAGE_DEPENDS is properly set
  590. # to the minimal dependency of the package
  591. # Append automatically discovered dependencies .
  592. if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "")
  593. if (CPACK_DEBIAN_PACKAGE_DEPENDS)
  594. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}")
  595. else ()
  596. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
  597. endif ()
  598. endif()
  599. if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
  600. message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
  601. endif()
  602. # Maintainer: (mandatory)
  603. if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
  604. if(NOT CPACK_PACKAGE_CONTACT)
  605. message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
  606. endif()
  607. set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
  608. endif()
  609. # Description: (mandatory)
  610. if(NOT CPACK_DEB_PACKAGE_COMPONENT)
  611. if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  612. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  613. message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
  614. endif()
  615. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  616. endif()
  617. else()
  618. set(component_description_var CPACK_COMPONENT_${_local_component_name}_DESCRIPTION)
  619. # component description overrides package description
  620. if(${component_description_var})
  621. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${${component_description_var}})
  622. elseif(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  623. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  624. message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION or ${component_description_var}")
  625. endif()
  626. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  627. endif()
  628. endif()
  629. # Section: (recommended)
  630. if(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  631. set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
  632. endif()
  633. # Priority: (recommended)
  634. if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  635. set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  636. endif()
  637. # Compression: (recommended)
  638. if(NOT CPACK_DEBIAN_COMPRESSION_TYPE)
  639. set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
  640. endif()
  641. # Recommends:
  642. # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  643. # Suggests:
  644. # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
  645. # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  646. # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
  647. # Typical examples are:
  648. # - conffiles
  649. # - postinst
  650. # - postrm
  651. # - prerm
  652. # Usage:
  653. # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  654. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  655. # Are we packaging components ?
  656. if(CPACK_DEB_PACKAGE_COMPONENT)
  657. # override values with per component version if set
  658. foreach(VAR_NAME_ "PACKAGE_CONTROL_EXTRA" "PACKAGE_CONTROL_STRICT_PERMISSION")
  659. if(CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_})
  660. set(CPACK_DEBIAN_${VAR_NAME_} "${CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}}")
  661. endif()
  662. endforeach()
  663. if(CPACK_DEBIAN_${_local_component_name}_PACKAGE_NAME)
  664. string(TOLOWER "${CPACK_DEBIAN_${_local_component_name}_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  665. else()
  666. string(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_DEB_PACKAGE_COMPONENT}" CPACK_DEBIAN_PACKAGE_NAME)
  667. endif()
  668. endif()
  669. # Print out some debug information if we were asked for that
  670. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  671. message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = '${CPACK_TOPLEVEL_DIRECTORY}'")
  672. message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG = '${CPACK_TOPLEVEL_TAG}'")
  673. message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY = '${CPACK_TEMPORARY_DIRECTORY}'")
  674. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME = '${CPACK_OUTPUT_FILE_NAME}'")
  675. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH = '${CPACK_OUTPUT_FILE_PATH}'")
  676. message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME = '${CPACK_PACKAGE_FILE_NAME}'")
  677. message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = '${CPACK_PACKAGE_INSTALL_DIRECTORY}'")
  678. message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = '${CPACK_TEMPORARY_PACKAGE_FILE_NAME}'")
  679. message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = '${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}'")
  680. message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_SOURCE = '${CPACK_DEBIAN_PACKAGE_SOURCE}'")
  681. endif()
  682. # For debian source packages:
  683. # debian/control
  684. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
  685. # .dsc
  686. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
  687. # Builds-Depends:
  688. #if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
  689. # set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
  690. # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
  691. # )
  692. #endif()
  693. # move variables to parent scope so that they may be used to create debian package
  694. set(GEN_CPACK_DEBIAN_PACKAGE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}" PARENT_SCOPE)
  695. set(GEN_CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_DEBIAN_PACKAGE_VERSION}" PARENT_SCOPE)
  696. set(GEN_CPACK_DEBIAN_PACKAGE_SECTION "${CPACK_DEBIAN_PACKAGE_SECTION}" PARENT_SCOPE)
  697. set(GEN_CPACK_DEBIAN_PACKAGE_PRIORITY "${CPACK_DEBIAN_PACKAGE_PRIORITY}" PARENT_SCOPE)
  698. set(GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" PARENT_SCOPE)
  699. set(GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_DEBIAN_PACKAGE_MAINTAINER}" PARENT_SCOPE)
  700. set(GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_DEBIAN_PACKAGE_DESCRIPTION}" PARENT_SCOPE)
  701. set(GEN_CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
  702. set(GEN_CPACK_DEBIAN_COMPRESSION_TYPE "${CPACK_DEBIAN_COMPRESSION_TYPE}" PARENT_SCOPE)
  703. set(GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS "${CPACK_DEBIAN_PACKAGE_RECOMMENDS}" PARENT_SCOPE)
  704. set(GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}" PARENT_SCOPE)
  705. set(GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_DEBIAN_PACKAGE_HOMEPAGE}" PARENT_SCOPE)
  706. set(GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS "${CPACK_DEBIAN_PACKAGE_PREDEPENDS}" PARENT_SCOPE)
  707. set(GEN_CPACK_DEBIAN_PACKAGE_ENHANCES "${CPACK_DEBIAN_PACKAGE_ENHANCES}" PARENT_SCOPE)
  708. set(GEN_CPACK_DEBIAN_PACKAGE_BREAKS "${CPACK_DEBIAN_PACKAGE_BREAKS}" PARENT_SCOPE)
  709. set(GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS "${CPACK_DEBIAN_PACKAGE_CONFLICTS}" PARENT_SCOPE)
  710. set(GEN_CPACK_DEBIAN_PACKAGE_PROVIDES "${CPACK_DEBIAN_PACKAGE_PROVIDES}" PARENT_SCOPE)
  711. set(GEN_CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_REPLACES}" PARENT_SCOPE)
  712. set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" PARENT_SCOPE)
  713. set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION
  714. "${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}" PARENT_SCOPE)
  715. set(GEN_CPACK_DEBIAN_PACKAGE_SOURCE
  716. "${CPACK_DEBIAN_PACKAGE_SOURCE}" PARENT_SCOPE)
  717. set(GEN_WDIR "${WDIR}" PARENT_SCOPE)
  718. endfunction()
  719. cpack_deb_prepare_package_vars()