CPackDeb.cmake 27 KB

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