CPackDeb.cmake 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. # CPACK_DEBIAN_XXX variables.You'll find a detailed usage on the wiki:
  19. # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
  20. #
  21. # However as a handy reminder here comes the list of specific variables:
  22. #
  23. # .. variable:: CPACK_DEBIAN_PACKAGE_NAME
  24. #
  25. # * Mandatory : YES
  26. # * Default : CPACK_PACKAGE_NAME (lower case)
  27. #
  28. # The debian package summary
  29. #
  30. # .. variable:: CPACK_DEBIAN_PACKAGE_VERSION
  31. #
  32. # * Mandatory : YES
  33. # * Default : CPACK_PACKAGE_VERSION
  34. #
  35. # The debian package version
  36. #
  37. # .. variable:: CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  38. #
  39. # * Mandatory : YES
  40. # * Default : Output of dpkg --print-architecture (or i386 if dpkg is not found)
  41. #
  42. # The debian package architecture
  43. #
  44. # .. variable:: CPACK_DEBIAN_PACKAGE_DEPENDS
  45. #
  46. # * Mandatory : NO
  47. # * Default : -
  48. #
  49. # May be used to set deb dependencies.
  50. #
  51. # .. variable:: CPACK_DEBIAN_PACKAGE_MAINTAINER
  52. #
  53. # * Mandatory : YES
  54. # * Default : CPACK_PACKAGE_CONTACT
  55. #
  56. # The debian package maintainer
  57. #
  58. # .. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION
  59. #
  60. # * Mandatory : YES
  61. # * Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
  62. #
  63. # The debian package description
  64. #
  65. # .. variable:: CPACK_DEBIAN_PACKAGE_SECTION
  66. #
  67. # * Mandatory : YES
  68. # * Default : 'devel'
  69. #
  70. # .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE
  71. #
  72. # * Mandatory : YES
  73. # * Default : 'gzip'
  74. #
  75. # Possible values are: lzma, xz, bzip2 and gzip.
  76. #
  77. # .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
  78. #
  79. # * Mandatory : YES
  80. # * Default : 'optional'
  81. #
  82. # The debian package priority
  83. #
  84. # .. variable:: CPACK_DEBIAN_PACKAGE_HOMEPAGE
  85. #
  86. # * Mandatory : NO
  87. # * Default : -
  88. #
  89. # The URL of the web site for this package, preferably (when applicable) the
  90. # site from which the original source can be obtained and any additional
  91. # upstream documentation or information may be found.
  92. # The content of this field is a simple URL without any surrounding
  93. # characters such as <>.
  94. #
  95. # .. variable:: CPACK_DEBIAN_PACKAGE_SHLIBDEPS
  96. #
  97. # * Mandatory : NO
  98. # * Default : OFF
  99. #
  100. # May be set to ON in order to use dpkg-shlibdeps to generate
  101. # better package dependency list.
  102. # You may need set CMAKE_INSTALL_RPATH toi appropriate value
  103. # if you use this feature, because if you don't dpkg-shlibdeps
  104. # may fail to find your own shared libs.
  105. # See http://www.cmake.org/Wiki/CMake_RPATH_handling.
  106. #
  107. # .. variable:: CPACK_DEBIAN_PACKAGE_DEBUG
  108. #
  109. # * Mandatory : NO
  110. # * Default : -
  111. #
  112. # May be set when invoking cpack in order to trace debug information
  113. # during CPackDeb run.
  114. #
  115. # .. variable:: CPACK_DEBIAN_PACKAGE_PREDEPENDS
  116. #
  117. # * Mandatory : NO
  118. # * Default : -
  119. #
  120. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  121. # This field is like Depends, except that it also forces dpkg to complete installation of
  122. # the packages named before even starting the installation of the package which declares
  123. # the pre-dependency.
  124. #
  125. # .. variable:: CPACK_DEBIAN_PACKAGE_ENHANCES
  126. #
  127. # * Mandatory : NO
  128. # * Default : -
  129. #
  130. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  131. # This field is similar to Suggests but works in the opposite direction.
  132. # It is used to declare that a package can enhance the functionality of another package.
  133. #
  134. # .. variable:: CPACK_DEBIAN_PACKAGE_BREAKS
  135. #
  136. # * Mandatory : NO
  137. # * Default : -
  138. #
  139. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  140. # When one binary package declares that it breaks another, dpkg will refuse to allow the
  141. # package which declares Breaks be installed unless the broken package is deconfigured first,
  142. # and it will refuse to allow the broken package to be reconfigured.
  143. #
  144. # .. variable:: CPACK_DEBIAN_PACKAGE_CONFLICTS
  145. #
  146. # * Mandatory : NO
  147. # * Default : -
  148. #
  149. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  150. # When one binary package declares a conflict with another using a Conflicts field,
  151. # dpkg will refuse to allow them to be installed on the system at the same time.
  152. #
  153. # .. variable:: CPACK_DEBIAN_PACKAGE_PROVIDES
  154. #
  155. # * Mandatory : NO
  156. # * Default : -
  157. #
  158. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  159. # A virtual package is one which appears in the Provides control field of another package.
  160. #
  161. # .. variable:: CPACK_DEBIAN_PACKAGE_REPLACES
  162. #
  163. # * Mandatory : NO
  164. # * Default : -
  165. #
  166. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  167. # Packages can declare in their control file that they should overwrite
  168. # files in certain other packages, or completely replace other packages.
  169. #
  170. # .. variable:: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  171. #
  172. # * Mandatory : NO
  173. # * Default : -
  174. #
  175. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  176. # Allows packages to declare a strong, but not absolute, dependency on other packages.
  177. #
  178. # .. variable:: CPACK_DEBIAN_PACKAGE_SUGGESTS
  179. #
  180. # * Mandatory : NO
  181. # * Default : -
  182. #
  183. # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
  184. # Allows packages to declare a suggested package install grouping.
  185. #
  186. # .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  187. #
  188. # * Mandatory : NO
  189. # * Default : -
  190. #
  191. # This variable allow advanced user to add custom script to the
  192. # control.tar.gz Typical usage is for conffiles, postinst, postrm, prerm.
  193. # Usage::
  194. #
  195. # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  196. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  197. #=============================================================================
  198. # Copyright 2007-2009 Kitware, Inc.
  199. # Copyright 2007-2009 Mathieu Malaterre <[email protected]>
  200. #
  201. # Distributed under the OSI-approved BSD License (the "License");
  202. # see accompanying file Copyright.txt for details.
  203. #
  204. # This software is distributed WITHOUT ANY WARRANTY; without even the
  205. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  206. # See the License for more information.
  207. #=============================================================================
  208. # (To distribute this file outside of CMake, substitute the full
  209. # License text for the above reference.)
  210. # CPack script for creating Debian package
  211. # Author: Mathieu Malaterre
  212. #
  213. # http://wiki.debian.org/HowToPackageForDebian
  214. if(CMAKE_BINARY_DIR)
  215. message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
  216. endif()
  217. if(NOT UNIX)
  218. message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
  219. endif()
  220. # CPACK_DEBIAN_PACKAGE_SHLIBDEPS
  221. # If specify OFF, only user depends are used
  222. if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  223. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
  224. endif()
  225. find_program(FAKEROOT_EXECUTABLE fakeroot)
  226. if(FAKEROOT_EXECUTABLE)
  227. set(CPACK_DEBIAN_FAKEROOT_EXECUTABLE ${FAKEROOT_EXECUTABLE})
  228. endif()
  229. if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
  230. # dpkg-shlibdeps is a Debian utility for generating dependency list
  231. find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps)
  232. # Check version of the dpkg-shlibdeps tool using CPackRPM method
  233. if(SHLIBDEPS_EXECUTABLE)
  234. execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} --version
  235. OUTPUT_VARIABLE _TMP_VERSION
  236. ERROR_QUIET
  237. OUTPUT_STRIP_TRAILING_WHITESPACE)
  238. string(REGEX MATCH "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)"
  239. SHLIBDEPS_EXECUTABLE_VERSION
  240. ${_TMP_VERSION})
  241. set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
  242. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  243. message( "CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>")
  244. endif()
  245. # Generating binary list - Get type of all install files
  246. execute_process(COMMAND find -type f
  247. COMMAND xargs file
  248. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  249. OUTPUT_VARIABLE CPACK_DEB_INSTALL_FILES)
  250. # Convert to CMake list
  251. string(REPLACE "\n" ";" CPACK_DEB_INSTALL_FILES ${CPACK_DEB_INSTALL_FILES})
  252. # Only dynamically linked ELF files are included
  253. # Extract only file name infront of ":"
  254. foreach ( _FILE ${CPACK_DEB_INSTALL_FILES})
  255. if ( ${_FILE} MATCHES "ELF.*dynamically linked")
  256. string(REGEX MATCH "(^.*):" _FILE_NAME ${_FILE})
  257. list(APPEND CPACK_DEB_BINARY_FILES ${CMAKE_MATCH_1})
  258. endif()
  259. endforeach()
  260. message( "CPackDeb: - Generating dependency list")
  261. # Create blank control file for running dpkg-shlibdeps
  262. # There might be some other way to invoke dpkg-shlibdeps without creating this file
  263. # but standard debian package should not have anything that can collide with this file or directory
  264. file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian)
  265. file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "")
  266. # Execute dpkg-shlibdeps
  267. # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package
  268. # -O : print to STDOUT
  269. execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} --ignore-missing-info -O ${CPACK_DEB_BINARY_FILES}
  270. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  271. OUTPUT_VARIABLE SHLIBDEPS_OUTPUT
  272. RESULT_VARIABLE SHLIBDEPS_RESULT
  273. ERROR_VARIABLE SHLIBDEPS_ERROR
  274. OUTPUT_STRIP_TRAILING_WHITESPACE )
  275. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  276. # dpkg-shlibdeps will throw some warnings if some input files are not binary
  277. message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}")
  278. endif()
  279. if (NOT SHLIBDEPS_RESULT EQUAL 0)
  280. message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: ${SHLIBDEPS_ERROR}")
  281. endif ()
  282. #Get rid of prefix generated by dpkg-shlibdeps
  283. string (REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS ${SHLIBDEPS_OUTPUT})
  284. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  285. message( "CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
  286. endif()
  287. # Remove blank control file
  288. # Might not be safe if package actual contain file or directory named debian
  289. file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian")
  290. # Append user depend if set
  291. if (CPACK_DEBIAN_PACKAGE_DEPENDS)
  292. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}")
  293. else ()
  294. set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
  295. endif ()
  296. else ()
  297. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  298. message( "CPackDeb Debug: Using only user-provided depends because dpkg-shlibdeps is not found.")
  299. endif()
  300. endif()
  301. else ()
  302. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  303. message( "CPackDeb Debug: Using only user-provided depends")
  304. endif()
  305. endif()
  306. # Let's define the control file found in debian package:
  307. # Binary package:
  308. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
  309. # DEBIAN/control
  310. # debian policy enforce lower case for package name
  311. # Package: (mandatory)
  312. if(NOT CPACK_DEBIAN_PACKAGE_NAME)
  313. string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  314. endif()
  315. # Version: (mandatory)
  316. if(NOT CPACK_DEBIAN_PACKAGE_VERSION)
  317. if(NOT CPACK_PACKAGE_VERSION)
  318. message(FATAL_ERROR "CPackDeb: Debian package requires a package version")
  319. endif()
  320. set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  321. endif()
  322. # Architecture: (mandatory)
  323. if(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  324. # There is no such thing as i686 architecture on debian, you should use i386 instead
  325. # $ dpkg --print-architecture
  326. find_program(DPKG_CMD dpkg)
  327. if(NOT DPKG_CMD)
  328. message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.")
  329. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  330. endif()
  331. execute_process(COMMAND "${DPKG_CMD}" --print-architecture
  332. OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  333. OUTPUT_STRIP_TRAILING_WHITESPACE
  334. )
  335. endif()
  336. # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES),
  337. # this returns the successful find_package() calls, maybe this can help
  338. # Depends:
  339. # You should set: DEBIAN_PACKAGE_DEPENDS
  340. # TODO: automate 'objdump -p | grep NEEDED'
  341. if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
  342. message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
  343. endif()
  344. # Maintainer: (mandatory)
  345. if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
  346. if(NOT CPACK_PACKAGE_CONTACT)
  347. message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
  348. endif()
  349. set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
  350. endif()
  351. # Description: (mandatory)
  352. if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  353. if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  354. message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
  355. endif()
  356. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  357. endif()
  358. # Section: (recommended)
  359. if(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  360. set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
  361. endif()
  362. # Priority: (recommended)
  363. if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  364. set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  365. endif()
  366. # Compression: (recommended)
  367. if(NOT CPACK_DEBIAN_COMPRESSION_TYPE)
  368. set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
  369. endif()
  370. # Recommends:
  371. # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  372. # Suggests:
  373. # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
  374. # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  375. # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
  376. # Typical examples are:
  377. # - conffiles
  378. # - postinst
  379. # - postrm
  380. # - prerm"
  381. # Usage:
  382. # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  383. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  384. # Are we packaging components ?
  385. if(CPACK_DEB_PACKAGE_COMPONENT)
  386. set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "-${CPACK_DEB_PACKAGE_COMPONENT}")
  387. string(TOLOWER "${CPACK_PACKAGE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  388. else()
  389. set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "")
  390. endif()
  391. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}")
  392. # Print out some debug information if we were asked for that
  393. if(CPACK_DEBIAN_PACKAGE_DEBUG)
  394. message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
  395. message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
  396. message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
  397. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
  398. message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
  399. message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
  400. message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  401. message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
  402. endif()
  403. # For debian source packages:
  404. # debian/control
  405. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
  406. # .dsc
  407. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
  408. # Builds-Depends:
  409. #if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
  410. # set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
  411. # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
  412. # )
  413. #endif()