CPackDeb.cmake 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. # Copyright 2007-2009 Kitware, Inc.
  331. # Copyright 2007-2009 Mathieu Malaterre <[email protected]>
  332. #
  333. # Distributed under the OSI-approved BSD License (the "License");
  334. # see accompanying file Copyright.txt for details.
  335. #
  336. # This software is distributed WITHOUT ANY WARRANTY; without even the
  337. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  338. # See the License for more information.
  339. #=============================================================================
  340. # (To distribute this file outside of CMake, substitute the full
  341. # License text for the above reference.)
  342. # CPack script for creating Debian package
  343. # Author: Mathieu Malaterre
  344. #
  345. # http://wiki.debian.org/HowToPackageForDebian
  346. if(CMAKE_BINARY_DIR)
  347. message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
  348. endif()
  349. if(NOT UNIX)
  350. message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
  351. endif()
  352. function(cpack_deb_prepare_package_vars)
  353. # CPACK_DEBIAN_PACKAGE_SHLIBDEPS
  354. # If specify OFF, only user depends are used
  355. if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  356. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
  357. endif()
  358. find_program(FAKEROOT_EXECUTABLE fakeroot)
  359. if(FAKEROOT_EXECUTABLE)
  360. set(CPACK_DEBIAN_FAKEROOT_EXECUTABLE ${FAKEROOT_EXECUTABLE})
  361. endif()
  362. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}")
  363. # per component automatic discover: some of the component might not have
  364. # binaries.
  365. if(CPACK_DEB_PACKAGE_COMPONENT)
  366. string(TOUPPER "${CPACK_DEB_PACKAGE_COMPONENT}" _local_component_name)
  367. set(_component_shlibdeps_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_SHLIBDEPS")
  368. # if set, overrides the global configuration
  369. if(DEFINED ${_component_shlibdeps_var})
  370. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "${${_component_shlibdeps_var}}")
  371. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  372. message("CPackDeb Debug: component '${CPACK_DEB_PACKAGE_COMPONENT}' dpkg-shlibdeps set to ${CPACK_DEBIAN_PACKAGE_SHLIBDEPS}")
  373. endif()
  374. endif()
  375. endif()
  376. if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  377. # dpkg-shlibdeps is a Debian utility for generating dependency list
  378. find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps)
  379. if(SHLIBDEPS_EXECUTABLE)
  380. # Check version of the dpkg-shlibdeps tool using CPackRPM method
  381. execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version
  382. OUTPUT_VARIABLE _TMP_VERSION
  383. ERROR_QUIET
  384. OUTPUT_STRIP_TRAILING_WHITESPACE)
  385. if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)")
  386. set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
  387. else()
  388. set(SHLIBDEPS_EXECUTABLE_VERSION "")
  389. endif()
  390. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  391. message("CPackDeb Debug: dpkg-shlibdeps --version output is '${_TMP_VERSION}'")
  392. message("CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>")
  393. endif()
  394. # Generating binary list - Get type of all install files
  395. cmake_policy(PUSH)
  396. # Tell file(GLOB_RECURSE) not to follow directory symlinks
  397. # even if the project does not set this policy to NEW.
  398. cmake_policy(SET CMP0009 NEW)
  399. file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false RELATIVE "${WDIR}" "${WDIR}/*")
  400. cmake_policy(POP)
  401. # get file info so that we can determine if file is executable or not
  402. unset(CPACK_DEB_INSTALL_FILES)
  403. foreach(FILE_ IN LISTS FILE_PATHS_)
  404. execute_process(COMMAND file "./${FILE_}"
  405. WORKING_DIRECTORY "${WDIR}"
  406. OUTPUT_VARIABLE INSTALL_FILE_)
  407. list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}")
  408. endforeach()
  409. # Only dynamically linked ELF files are included
  410. # Extract only file name infront of ":"
  411. foreach(_FILE ${CPACK_DEB_INSTALL_FILES})
  412. if( ${_FILE} MATCHES "ELF.*dynamically linked")
  413. string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}")
  414. list(APPEND CPACK_DEB_BINARY_FILES "${CMAKE_MATCH_1}")
  415. set(CONTAINS_EXECUTABLE_FILES_ TRUE)
  416. endif()
  417. endforeach()
  418. if(CONTAINS_EXECUTABLE_FILES_)
  419. message("CPackDeb: - Generating dependency list")
  420. # Create blank control file for running dpkg-shlibdeps
  421. # There might be some other way to invoke dpkg-shlibdeps without creating this file
  422. # but standard debian package should not have anything that can collide with this file or directory
  423. file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian)
  424. file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "")
  425. # Add --ignore-missing-info if the tool supports it
  426. execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help
  427. OUTPUT_VARIABLE _TMP_HELP
  428. ERROR_QUIET
  429. OUTPUT_STRIP_TRAILING_WHITESPACE)
  430. if(_TMP_HELP MATCHES "--ignore-missing-info")
  431. set(IGNORE_MISSING_INFO_FLAG "--ignore-missing-info")
  432. endif()
  433. # Execute dpkg-shlibdeps
  434. # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package
  435. # -O : print to STDOUT
  436. execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}
  437. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  438. OUTPUT_VARIABLE SHLIBDEPS_OUTPUT
  439. RESULT_VARIABLE SHLIBDEPS_RESULT
  440. ERROR_VARIABLE SHLIBDEPS_ERROR
  441. OUTPUT_STRIP_TRAILING_WHITESPACE )
  442. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  443. # dpkg-shlibdeps will throw some warnings if some input files are not binary
  444. message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}")
  445. endif()
  446. if(NOT SHLIBDEPS_RESULT EQUAL 0)
  447. message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n"
  448. "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n"
  449. "found files: '${INSTALL_FILE_}';\n"
  450. "files info: '${CPACK_DEB_INSTALL_FILES}';\n"
  451. "binary files: '${CPACK_DEB_BINARY_FILES}'")
  452. endif()
  453. #Get rid of prefix generated by dpkg-shlibdeps
  454. string(REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS "${SHLIBDEPS_OUTPUT}")
  455. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  456. message("CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS} from output ${SHLIBDEPS_OUTPUT}")
  457. endif()
  458. # Remove blank control file
  459. # Might not be safe if package actual contain file or directory named debian
  460. file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian")
  461. else()
  462. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  463. message(AUTHOR_WARNING "CPackDeb Debug: Using only user-provided depends because package does not contain executable files that link to shared libraries.")
  464. endif()
  465. endif()
  466. else()
  467. message("CPackDeb: Using only user-provided dependencies because dpkg-shlibdeps is not found.")
  468. endif()
  469. else()
  470. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  471. message("CPackDeb Debug: Using only user-provided dependencies")
  472. endif()
  473. endif()
  474. # Let's define the control file found in debian package:
  475. # Binary package:
  476. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
  477. # DEBIAN/control
  478. # debian policy enforce lower case for package name
  479. # Package: (mandatory)
  480. if(NOT CPACK_DEBIAN_PACKAGE_NAME)
  481. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  482. endif()
  483. # Version: (mandatory)
  484. if(NOT CPACK_DEBIAN_PACKAGE_VERSION)
  485. if(NOT CPACK_PACKAGE_VERSION)
  486. message(FATAL_ERROR "CPackDeb: Debian package requires a package version")
  487. endif()
  488. set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  489. endif()
  490. # Architecture: (mandatory)
  491. if(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  492. # There is no such thing as i686 architecture on debian, you should use i386 instead
  493. # $ dpkg --print-architecture
  494. find_program(DPKG_CMD dpkg)
  495. if(NOT DPKG_CMD)
  496. message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.")
  497. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  498. endif()
  499. execute_process(COMMAND "${DPKG_CMD}" --print-architecture
  500. OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  501. OUTPUT_STRIP_TRAILING_WHITESPACE
  502. )
  503. endif()
  504. # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES),
  505. # this returns the successful find_package() calls, maybe this can help
  506. # Depends:
  507. # You should set: DEBIAN_PACKAGE_DEPENDS
  508. # TODO: automate 'objdump -p | grep NEEDED'
  509. # if per-component dependency, overrides the global CPACK_DEBIAN_PACKAGE_${dependency_type_}
  510. # automatic dependency discovery will be performed afterwards.
  511. if(CPACK_DEB_PACKAGE_COMPONENT)
  512. foreach(dependency_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES)
  513. set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${dependency_type_}")
  514. # if set, overrides the global dependency
  515. if(DEFINED ${_component_var})
  516. set(CPACK_DEBIAN_PACKAGE_${dependency_type_} "${${_component_var}}")
  517. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  518. message("CPackDeb Debug: component '${_local_component_name}' ${dependency_type_}"
  519. "dependencies set to '${CPACK_DEBIAN_PACKAGE_${dependency_}}'")
  520. endif()
  521. endif()
  522. endforeach()
  523. endif()
  524. # at this point, the CPACK_DEBIAN_PACKAGE_DEPENDS is properly set
  525. # to the minimal dependency of the package
  526. # Append automatically discovered dependencies .
  527. if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "")
  528. if (CPACK_DEBIAN_PACKAGE_DEPENDS)
  529. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}")
  530. else ()
  531. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
  532. endif ()
  533. endif()
  534. if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
  535. message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
  536. endif()
  537. # Maintainer: (mandatory)
  538. if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
  539. if(NOT CPACK_PACKAGE_CONTACT)
  540. message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
  541. endif()
  542. set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
  543. endif()
  544. # Description: (mandatory)
  545. if(NOT CPACK_DEB_PACKAGE_COMPONENT)
  546. if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  547. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  548. message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
  549. endif()
  550. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  551. endif()
  552. else()
  553. set(component_description_var CPACK_COMPONENT_${_local_component_name}_DESCRIPTION)
  554. # component description overrides package description
  555. if(${component_description_var})
  556. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${${component_description_var}})
  557. elseif(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  558. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  559. 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}")
  560. endif()
  561. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  562. endif()
  563. endif()
  564. # Section: (recommended)
  565. if(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  566. set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
  567. endif()
  568. # Priority: (recommended)
  569. if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  570. set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  571. endif()
  572. # Compression: (recommended)
  573. if(NOT CPACK_DEBIAN_COMPRESSION_TYPE)
  574. set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
  575. endif()
  576. # Recommends:
  577. # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  578. # Suggests:
  579. # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
  580. # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  581. # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
  582. # Typical examples are:
  583. # - conffiles
  584. # - postinst
  585. # - postrm
  586. # - prerm
  587. # Usage:
  588. # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  589. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  590. # Are we packaging components ?
  591. if(CPACK_DEB_PACKAGE_COMPONENT)
  592. # override values with per component version if set
  593. foreach(VAR_NAME_ "PACKAGE_CONTROL_EXTRA")
  594. if(CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_})
  595. set(CPACK_DEBIAN_${VAR_NAME_} "${CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}}")
  596. endif()
  597. endforeach()
  598. set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "-${CPACK_DEB_PACKAGE_COMPONENT}")
  599. string(TOLOWER "${CPACK_PACKAGE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  600. else()
  601. set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "")
  602. endif()
  603. # Print out some debug information if we were asked for that
  604. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  605. message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  606. message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  607. message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  608. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  609. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  610. message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  611. message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  612. message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  613. endif()
  614. # For debian source packages:
  615. # debian/control
  616. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
  617. # .dsc
  618. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
  619. # Builds-Depends:
  620. #if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
  621. # set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
  622. # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
  623. # )
  624. #endif()
  625. # move variables to parent scope so that they may be used to create debian package
  626. set(GEN_CPACK_DEBIAN_PACKAGE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}" PARENT_SCOPE)
  627. set(GEN_CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_DEBIAN_PACKAGE_VERSION}" PARENT_SCOPE)
  628. set(GEN_CPACK_DEBIAN_PACKAGE_SECTION "${CPACK_DEBIAN_PACKAGE_SECTION}" PARENT_SCOPE)
  629. set(GEN_CPACK_DEBIAN_PACKAGE_PRIORITY "${CPACK_DEBIAN_PACKAGE_PRIORITY}" PARENT_SCOPE)
  630. set(GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" PARENT_SCOPE)
  631. set(GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_DEBIAN_PACKAGE_MAINTAINER}" PARENT_SCOPE)
  632. set(GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_DEBIAN_PACKAGE_DESCRIPTION}" PARENT_SCOPE)
  633. set(GEN_CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
  634. set(GEN_CPACK_DEBIAN_FAKEROOT_EXECUTABLE "${CPACK_DEBIAN_FAKEROOT_EXECUTABLE}" PARENT_SCOPE)
  635. set(GEN_CPACK_DEBIAN_COMPRESSION_TYPE "${CPACK_DEBIAN_COMPRESSION_TYPE}" PARENT_SCOPE)
  636. set(GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS "${CPACK_DEBIAN_PACKAGE_RECOMMENDS}" PARENT_SCOPE)
  637. set(GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}" PARENT_SCOPE)
  638. set(GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_DEBIAN_PACKAGE_HOMEPAGE}" PARENT_SCOPE)
  639. set(GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS "${CPACK_DEBIAN_PACKAGE_PREDEPENDS}" PARENT_SCOPE)
  640. set(GEN_CPACK_DEBIAN_PACKAGE_ENHANCES "${CPACK_DEBIAN_PACKAGE_ENHANCES}" PARENT_SCOPE)
  641. set(GEN_CPACK_DEBIAN_PACKAGE_BREAKS "${CPACK_DEBIAN_PACKAGE_BREAKS}" PARENT_SCOPE)
  642. set(GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS "${CPACK_DEBIAN_PACKAGE_CONFLICTS}" PARENT_SCOPE)
  643. set(GEN_CPACK_DEBIAN_PACKAGE_PROVIDES "${CPACK_DEBIAN_PACKAGE_PROVIDES}" PARENT_SCOPE)
  644. set(GEN_CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_REPLACES}" PARENT_SCOPE)
  645. set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" PARENT_SCOPE)
  646. set(GEN_WDIR "${WDIR}" PARENT_SCOPE)
  647. endfunction()
  648. cpack_deb_prepare_package_vars()