CPackDeb.cmake 30 KB

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