CPackDeb.cmake 16 KB

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