No Description

CPackDeb.cmake 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # - The builtin (binary) CPack Deb generator (Unix only)
  2. # CPackDeb may be used to create Deb package using CPack.
  3. # CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
  4. # used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
  5. #
  6. # However CPackRPM has specific features which are controlled by
  7. # the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
  8. # the wiki:
  9. # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
  10. # However as a handy reminder here comes the list of specific variables:
  11. #
  12. # CPACK_DEBIAN_PACKAGE_NAME
  13. # Mandatory : YES
  14. # Default : CPACK_PACKAGE_NAME (lower case)
  15. # The debian package summary
  16. # CPACK_DEBIAN_PACKAGE_VERSION
  17. # Mandatory : YES
  18. # Default : CPACK_PACKAGE_VERSION
  19. # The debian package version
  20. # CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  21. # Mandatory : YES
  22. # Default : Output of dpkg --print-architecture or i386
  23. # The debian package architecture
  24. # CPACK_DEBIAN_PACKAGE_DEPENDS
  25. # Mandatory : NO
  26. # Default : -
  27. # May be used to set deb dependencies.
  28. # CPACK_DEBIAN_PACKAGE_MAINTAINER
  29. # Mandatory : YES
  30. # Default : CPACK_PACKAGE_CONTACT
  31. # The debian package maintainer
  32. # CPACK_DEBIAN_PACKAGE_DESCRIPTION
  33. # Mandatory : YES
  34. # Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
  35. # The debian package description
  36. # CPACK_DEBIAN_PACKAGE_SECTION
  37. # Mandatory : YES
  38. # Default : 'devel'
  39. # The debian package section
  40. # CPACK_DEBIAN_PACKAGE_PRIORITY
  41. # Mandatory : YES
  42. # Default : 'optional'
  43. # The debian package priority
  44. #=============================================================================
  45. # Copyright 2007-2009 Kitware, Inc.
  46. # Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
  47. #
  48. # Distributed under the OSI-approved BSD License (the "License");
  49. # see accompanying file Copyright.txt for details.
  50. #
  51. # This software is distributed WITHOUT ANY WARRANTY; without even the
  52. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  53. # See the License for more information.
  54. #=============================================================================
  55. # (To distributed this file outside of CMake, substitute the full
  56. # License text for the above reference.)
  57. # CPack script for creating Debian package
  58. # Author: Mathieu Malaterre
  59. #
  60. # http://wiki.debian.org/HowToPackageForDebian
  61. IF(CMAKE_BINARY_DIR)
  62. MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
  63. ENDIF(CMAKE_BINARY_DIR)
  64. IF(NOT UNIX)
  65. MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
  66. ENDIF(NOT UNIX)
  67. # Let's define the control file found in debian package:
  68. # Binary package:
  69. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
  70. # DEBIAN/control
  71. # debian policy enforce lower case for package name
  72. # Package: (mandatory)
  73. IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
  74. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  75. ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)
  76. # Version: (mandatory)
  77. IF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
  78. IF(NOT CPACK_PACKAGE_VERSION)
  79. MESSAGE(FATAL_ERROR "Debian package requires a package version")
  80. ENDIF(NOT CPACK_PACKAGE_VERSION)
  81. SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
  82. ENDIF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
  83. # Architecture: (mandatory)
  84. IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  85. # There is no such thing as i686 architecture on debian, you should use i386 instead
  86. # $ dpkg --print-architecture
  87. FIND_PROGRAM(DPKG_CMD dpkg)
  88. IF(NOT DPKG_CMD)
  89. MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
  90. SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  91. ENDIF(NOT DPKG_CMD)
  92. EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
  93. OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  94. OUTPUT_STRIP_TRAILING_WHITESPACE
  95. )
  96. ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
  97. # have a look at GET_PROPERTY(result GLOBAL PROPERTY ENABLED_FEATURES),
  98. # this returns the successful FIND_PACKAGE() calls, maybe this can help
  99. # Depends:
  100. # You should set: DEBIAN_PACKAGE_DEPENDS
  101. # TODO: automate 'objdump -p | grep NEEDED'
  102. IF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
  103. MESSAGE(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
  104. ENDIF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
  105. # Maintainer: (mandatory)
  106. IF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
  107. IF(NOT CPACK_PACKAGE_CONTACT)
  108. MESSAGE(FATAL_ERROR "Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
  109. ENDIF(NOT CPACK_PACKAGE_CONTACT)
  110. SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
  111. ENDIF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
  112. # Description: (mandatory)
  113. IF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  114. IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  115. MESSAGE(FATAL_ERROR "Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
  116. ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
  117. SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
  118. ENDIF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
  119. # Section: (recommended)
  120. IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  121. SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
  122. ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  123. # Priority: (recommended)
  124. IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  125. SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  126. ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
  127. # Recommends:
  128. # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
  129. # Suggests:
  130. # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
  131. # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  132. # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
  133. # Typical examples are:
  134. # - conffiles
  135. # - postinst
  136. # - postrm
  137. # - prerm"
  138. # Usage:
  139. # SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
  140. # "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
  141. # For debian source packages:
  142. # debian/control
  143. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
  144. # .dsc
  145. # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
  146. # Builds-Depends:
  147. #IF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
  148. # SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
  149. # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
  150. # )
  151. #ENDIF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
  152. # Description: (mandatory)
  153. #if(NOT CPACK_SECTION)
  154. # message(FATAL_ERROR "opkg package requires a package section")
  155. #endif(NOT CPACK_SECTION)
  156. # Package for opkg
  157. FIND_PROGRAM(OPKG_CMD opkg-build)
  158. if( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
  159. message("CPack: opkg-build not found. Skipping packaging")
  160. else( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
  161. SET(CPACK_OPKG_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
  162. FILE(MAKE_DIRECTORY ${CPACK_OPKG_ROOTDIR}/CONTROL)
  163. set(CPACK_OPKG_CONTROL_FILE "${CPACK_OPKG_ROOTDIR}/CONTROL/control")
  164. # Write controlfile
  165. FILE(WRITE ${CPACK_OPKG_CONTROL_FILE}
  166. "Package: ${CPACK_PACKAGE_NAME}
  167. Version: ${CPACK_PACKAGE_VERSION}
  168. Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
  169. Architecture: ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}
  170. Section: ${CPACK_DEBIAN_PACKAGE_SECTION}
  171. Priority: optional
  172. Maintainer: ${CPACK_DEBIAN_PACKAGE_MAINTAINER}
  173. Depends: ${CPACK_DEBIAN_PACKAGE_DEPENDS}
  174. Provides: ${CPACK_DEBIAN_PACKAGE_PROVIDES}
  175. Replaces: ${CPACK_DEBIAN_PACKAGE_REPLACES}
  176. Conflicts: ${CPACK_DEBIAN_PACKAGE_CONFLICTS}
  177. Source: https://github.com/intel-iot-devkit/upm
  178. #Essential: no
  179. ")
  180. set(OPKG_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
  181. execute_process(
  182. COMMAND "${OPKG_CMD}" "-o" "0" "${CPACK_PACKAGE_FILE_NAME}" "."
  183. RESULT_VARIABLE _result
  184. OUTPUT_VARIABLE _res_output
  185. ERROR_VARIABLE _res_error
  186. WORKING_DIRECTORY ${CPACK_TOPLEVEL_DIRECTORY}
  187. )
  188. if(${_result})
  189. message("Result '${_result}'")
  190. message("Output '${_res_output}'")
  191. message("Error '${_res_error}'")
  192. else(${_result})
  193. message("CPack: Package ${OPKG_FILE_NAME}.ipk generated.")
  194. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
  195. file(RENAME ${CPACK_TOPLEVEL_DIRECTORY}/${OPKG_FILE_NAME}.ipk ${CPACK_BINARY_DIR}/${OPKG_FILE_NAME}.ipk)
  196. endif(${_result})
  197. endif( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )