CPackFreeBSD.cmake 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CPackFreeBSD
  5. ------------
  6. The built in (binary) CPack FreeBSD (pkg) generator (Unix only)
  7. Variables specific to CPack FreeBSD (pkg) generator
  8. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9. CPackFreeBSD may be used to create pkg(8) packages -- these may be used
  10. on FreeBSD, DragonflyBSD, NetBSD, OpenBSD, but also on Linux or OSX,
  11. depending on the installed package-management tools -- using :module:`CPack`.
  12. CPackFreeBSD is a :module:`CPack` generator and uses the ``CPACK_XXX``
  13. variables used by :module:`CPack`. It tries to re-use packaging information
  14. that may already be specified for Debian packages for the :module:`CPackDeb`
  15. generator. it also tries to re-use RPM packaging information when Debian
  16. does not specify.
  17. CPackFreeBSD generator should work on any host with libpkg installed. The
  18. packages it produces are specific to the host architecture and ABI.
  19. CPackFreeBSD sets package-metadata through :code:`CPACK_FREEBSD_XXX` variables.
  20. CPackFreeBSD, unlike CPackDeb, does not specially support componentized
  21. packages; a single package is created from all the software artifacts
  22. created through CMake.
  23. All of the variables can be set specifically for FreeBSD packaging in
  24. the CPackConfig file or in CMakeLists.txt, but most of them have defaults
  25. that use general settings (e.g. CMAKE_PROJECT_NAME) or Debian-specific
  26. variables when those make sense (e.g. the homepage of an upstream project
  27. is usually unchanged by the flavor of packaging). When there is no Debian
  28. information to fall back on, but the RPM packaging has it, fall back to
  29. the RPM information (e.g. package license).
  30. .. variable:: CPACK_FREEBSD_PACKAGE_NAME
  31. Sets the package name (in the package manifest, but also affects the
  32. output filename).
  33. * Mandatory: YES
  34. * Default:
  35. - :variable:`CPACK_PACKAGE_NAME` (this is always set by CPack itself,
  36. based on CMAKE_PROJECT_NAME).
  37. .. variable:: CPACK_FREEBSD_PACKAGE_COMMENT
  38. Sets the package comment. This is the short description displayed by
  39. pkg(8) in standard "pkg info" output.
  40. * Mandatory: YES
  41. * Default:
  42. - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` (this is always set
  43. by CPack itself, if nothing else sets it explicitly).
  44. - :variable:`PROJECT_DESCRIPTION` (this can be set with the DESCRIPTION
  45. parameter for :command:`project`).
  46. .. variable:: CPACK_FREEBSD_PACKAGE_DESCRIPTION
  47. Sets the package description. This is the long description of the package,
  48. given by "pkg info" with a specific package as argument.
  49. * Mandatory: YES
  50. * Default:
  51. - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` (this may be set already
  52. for Debian packaging, so we may as well re-use it).
  53. .. variable:: CPACK_FREEBSD_PACKAGE_WWW
  54. The URL of the web site for this package, preferably (when applicable) the
  55. site from which the original source can be obtained and any additional
  56. upstream documentation or information may be found.
  57. * Mandatory: YES
  58. * Default:
  59. - :variable:`CPACK_DEBIAN_PACKAGE_HOMEPAGE` (this may be set already
  60. for Debian packaging, so we may as well re-use it).
  61. .. variable:: CPACK_FREEBSD_PACKAGE_LICENSE
  62. The license, or licenses, which apply to this software package. This must
  63. be one or more license-identifiers that pkg recognizes as acceptable license
  64. identifiers (e.g. "GPLv2").
  65. * Mandatory: YES
  66. * Default:
  67. - :variable:`CPACK_RPM_PACKAGE_LICENSE`
  68. .. variable:: CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC
  69. This variable is only of importance if there is more than one license.
  70. The default is "single", which is only applicable to a single license.
  71. Other acceptable values are determined by pkg -- those are "dual" or "multi" --
  72. meaning choice (OR) or simultaneous (AND) application of the licenses.
  73. * Mandatory: NO
  74. * Default: single
  75. .. variable:: CPACK_FREEBSD_PACKAGE_MAINTAINER
  76. The FreeBSD maintainer (e.g. kde@freebsd.org) of this package.
  77. * Mandatory: YES
  78. * Default: none
  79. .. variable:: CPACK_FREEBSD_PACKAGE_ORIGIN
  80. The origin (ports label) of this package; for packages built by CPack
  81. outside of the ports system this is of less importance. The default
  82. puts the package somewhere under misc/, as a stopgap.
  83. * Mandatory: YES
  84. * Default: misc/<package name>
  85. .. variable:: CPACK_FREEBSD_PACKAGE_CATEGORIES
  86. The ports categories where this package lives (if it were to be built
  87. from ports). If none is set a single category is determined based on
  88. the package origin.
  89. * Mandatory: YES
  90. * Default: derived from ORIGIN
  91. .. variable:: CPACK_FREEBSD_PACKAGE_DEPS
  92. A list of package origins that should be added as package dependencies.
  93. These are in the form <category>/<packagename>, e.g. x11/libkonq.
  94. No version information needs to be provided (this is not included
  95. in the manifest).
  96. * Mandatory: NO
  97. * Default: empty
  98. #]=======================================================================]
  99. if(CMAKE_BINARY_DIR)
  100. message(FATAL_ERROR "CPackFreeBSD.cmake may only be used by CPack internally.")
  101. endif()
  102. if(NOT UNIX)
  103. message(FATAL_ERROR "CPackFreeBSD.cmake may only be used under UNIX.")
  104. endif()
  105. ###
  106. #
  107. # These bits are copied from the Debian packaging file; slightly modified.
  108. # They are used for filling in FreeBSD-packaging variables that can take
  109. # on values from elsewhere -- e.g. the package description may as well be
  110. # copied from Debian.
  111. #
  112. function(_cpack_freebsd_fallback_var OUTPUT_VAR_NAME)
  113. set(FALLBACK_VAR_NAMES ${ARGN})
  114. set(VALUE "${${OUTPUT_VAR_NAME}}")
  115. if(VALUE)
  116. return()
  117. endif()
  118. foreach(variable_name IN LISTS FALLBACK_VAR_NAMES)
  119. if(${variable_name})
  120. set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE)
  121. set(VALUE "${${variable_name}}")
  122. break()
  123. endif()
  124. endforeach()
  125. if(NOT VALUE)
  126. message(WARNING "Variable ${OUTPUT_VAR_NAME} could not be given a fallback value from any variable ${FALLBACK_VAR_NAMES}.")
  127. endif()
  128. endfunction()
  129. function(check_required_var VAR_NAME)
  130. if(NOT ${VAR_NAME})
  131. message(FATAL_ERROR "Variable ${VAR_NAME} is not set.")
  132. endif()
  133. endfunction()
  134. set(_cpack_freebsd_fallback_origin "misc/bogus")
  135. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_NAME"
  136. "CPACK_PACKAGE_NAME"
  137. "CMAKE_PROJECT_NAME"
  138. )
  139. set(_cpack_freebsd_fallback_www "http://example.com/?pkg=${CPACK_FREEBSD_PACKAGE_NAME}")
  140. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_COMMENT"
  141. "CPACK_PACKAGE_DESCRIPTION_SUMMARY"
  142. )
  143. # TODO: maybe read the PACKAGE_DESCRIPTION file for the longer
  144. # FreeBSD pkg-descr?
  145. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION"
  146. "CPACK_DEBIAN_PACKAGE_DESCRIPTION"
  147. "CPACK_PACKAGE_DESCRIPTION_SUMMARY"
  148. "PACKAGE_DESCRIPTION"
  149. )
  150. # There's really only one homepage for a project, so
  151. # re-use the Debian setting if it's there.
  152. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_WWW"
  153. "CPACK_DEBIAN_PACKAGE_HOMEPAGE"
  154. "_cpack_freebsd_fallback_www"
  155. )
  156. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_VERSION"
  157. "CMAKE_PROJECT_VERSION"
  158. "${CMAKE_PROJECT_NAME}_VERSION"
  159. "PROJECT_VERSION"
  160. "CPACK_PACKAGE_VERSION"
  161. "CPACK_PACKAGE_VERSION"
  162. )
  163. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_MAINTAINER"
  164. "CPACK_PACKAGE_CONTACT"
  165. )
  166. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_LICENSE"
  167. "CPACK_RPM_PACKAGE_LICENSE"
  168. )
  169. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_ORIGIN"
  170. "_cpack_freebsd_fallback_origin"
  171. )
  172. if(NOT CPACK_FREEBSD_PACKAGE_CATEGORIES)
  173. string(REGEX REPLACE "/.*" "" CPACK_FREEBSD_PACKAGE_CATEGORIES ${CPACK_FREEBSD_PACKAGE_ORIGIN})
  174. endif()
  175. check_required_var("CPACK_FREEBSD_PACKAGE_NAME")
  176. check_required_var("CPACK_FREEBSD_PACKAGE_ORIGIN")
  177. check_required_var("CPACK_FREEBSD_PACKAGE_VERSION")
  178. check_required_var("CPACK_FREEBSD_PACKAGE_MAINTAINER")
  179. check_required_var("CPACK_FREEBSD_PACKAGE_COMMENT")
  180. check_required_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION")
  181. check_required_var("CPACK_FREEBSD_PACKAGE_WWW")
  182. check_required_var("CPACK_FREEBSD_PACKAGE_LICENSE")