CPackDeb.cmake 29 KB

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