CMakeLists.txt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # SPDX-License-Identifier: GPL-3.0-or-later
  2. cmake_minimum_required(VERSION 3.16.0...3.30)
  3. list(APPEND RHEL_DISTROS centos centos-stream rocky almalinux cloudlinux)
  4. list(APPEND SUSE_DISTROS opensuse-leap opensuse-tumbleweed)
  5. list(APPEND RPM_DISTROS rhel opensuse ol amzn fedora)
  6. list(APPEND DEB_DISTROS debian ubuntu)
  7. set(DEB_GPG_KEY_SOURCE "https://repo.netdata.cloud/netdatabot.gpg.key")
  8. set(PACKAGE_VERSION 4)
  9. set(PACKAGE_RELEASE 1)
  10. set(CPACK_THREADS 0)
  11. set(CPACK_STRIP_FILES NO)
  12. set(CPACK_PACKAGE_INSTALL_DIRECTORY "netdata")
  13. set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages")
  14. set(CPACK_PACKAGING_INSTALL_PREFIX "/")
  15. set(CPACK_PACKAGE_VENDOR "Netdata Inc.")
  16. set(CPACK_COMPONENT_NETDATA-REPO_PACKAGE_DESCRIPTION "Configuration for the official Netdata Stable package repository.")
  17. set(CPACK_COMPONENT_NETDATA-REPO-EDGE_PACKAGE_DESCRIPTION "Configuration for the official Netdata Edge package repository.")
  18. project(netdata-repoconfig VERSION "${PACKAGE_VERSION}.${PACKAGE_RELEASE}"
  19. DESCRIPTION "Repository configuration for Netdata’s official native packages."
  20. HOMEPAGE_URL "https://www.netdata.cloud/"
  21. LANGUAGES NONE)
  22. function(extract_release_item _variable _item)
  23. if(DEFINED "${_variable}")
  24. return()
  25. endif()
  26. if(DEFINED OS_RELEASE_FILE)
  27. else()
  28. message(CHECK_START "Searching for os-release file")
  29. find_file(OS_RELEASE_FILE os-release PATHS /etc /lib /usr/lib NO_DEFAULT_PATH)
  30. if(${OS_RELEASE_FILE} STREQUAL "OS_RELEASE_FILE-NOTFOUND")
  31. message(CHECK_FAIL "failed")
  32. message(FATAL_ERROR "Could not find os-release file")
  33. endif()
  34. message(CHECK_PASS "${OS_RELEASE_FILE}")
  35. endif()
  36. message(CHECK_START "Extracting ${_item} from ${OS_RELEASE_FILE}")
  37. execute_process(COMMAND sh -c ". ${OS_RELEASE_FILE} && printf %s $${_item}"
  38. RESULT_VARIABLE _result
  39. OUTPUT_VARIABLE _output)
  40. if(NOT ${_result} EQUAL 0)
  41. message(CHECK_FAIL "failed to parse ${OS_RELEASE_FILE}")
  42. return()
  43. elseif(${_output} STREQUAL "")
  44. message(CHECK_FAIL "variable ${_item} not defined in ${OS_RELEASE_FILE}")
  45. return()
  46. endif()
  47. message(CHECK_PASS ${_output})
  48. set(${_variable} ${_output} PARENT_SCOPE)
  49. endfunction()
  50. function(require_command _variable _cmd)
  51. if(DEFINED ${_variable})
  52. return()
  53. endif()
  54. message(CHECK_START "Looking for ${_cmd}")
  55. find_program(_result_${_cmd} ${_cmd})
  56. if(${_result_${_cmd}} STREQUAL "_result_${_cmd}-NOTFOUND")
  57. message(CHECK_FAIL "failed")
  58. message(FATAL_ERROR "Unable to find required command: ${_cmd}")
  59. endif()
  60. message(CHECK_PASS "${_result_${_cmd}}")
  61. set(${_variable} ${_result_${_cmd}} PARENT_SCOPE)
  62. endfunction()
  63. if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  64. extract_release_item("DISTRO" ID)
  65. if(NOT DEFINED DISTRO)
  66. message(FATAL_ERROR "Failed to auto-detect distro ID")
  67. endif()
  68. extract_release_item(DISTRO_VERSION VERSION_ID)
  69. if(NOT DEFINED DISTRO_VERSION)
  70. message(FATAL_ERROR "Failed to auto-detect distro version ID.")
  71. endif()
  72. else()
  73. message(FATAL_ERROR "Repository configuration packages can only be built on Linux")
  74. endif()
  75. if(${DISTRO} IN_LIST RHEL_DISTROS)
  76. set(DISTRO "rhel")
  77. elseif(${DISTRO} STREQUAL "opensuse-leap")
  78. set(DISTRO "opensuse")
  79. elseif(${DISTRO} STREQUAL "opensuse-tumbleweed")
  80. set(DISTRO "opensuse")
  81. set(DISTRO_VERSION "tumbleweed")
  82. endif()
  83. if(${DISTRO} IN_LIST DEB_DISTROS)
  84. extract_release_item(SUITE VERSION_CODENAME)
  85. if(NOT DEFINED SUITE)
  86. message(FATAL_ERROR "Failed to determine version codename")
  87. endif()
  88. require_command(DPKG dpkg)
  89. require_command(CURL curl)
  90. require_command(GPG gpg)
  91. set(DIST_NAME ${DISTRO})
  92. message(STATUS "Generating stable repository configuration for ${DISTRO} ${SUITE}")
  93. set(VARIANT stable)
  94. configure_file(netdata.sources.in netdata.sources @ONLY)
  95. message(STATUS "Generating edge repository configuration for ${DISTRO} ${SUITE}")
  96. set(VARIANT edge)
  97. configure_file(netdata.sources.in netdata-edge.sources @ONLY)
  98. message(STATUS "Preparing changelogs")
  99. set(PKG_NAME netdata-repo)
  100. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/netdata-repo)
  101. configure_file(deb.changelog netdata-repo/changelog @ONLY)
  102. set(PKG_NAME netdata-repo-edge)
  103. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/netdata-repo-edge)
  104. configure_file(deb.changelog netdata-repo-edge/changelog @ONLY)
  105. install(FILES ${CMAKE_BINARY_DIR}/netdata.sources
  106. DESTINATION etc/apt/sources.list.d
  107. COMPONENT netdata-repo)
  108. install(FILES ${CMAKE_BINARY_DIR}/netdata-edge.sources
  109. DESTINATION etc/apt/sources.list.d
  110. COMPONENT netdata-repo-edge)
  111. add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/netdatabot.gpg.key
  112. COMMENT "Fetch GPG key from ${DEB_GPG_KEY_SOURCE}"
  113. COMMAND ${CURL} -f -L -o ${CMAKE_BINARY_DIR}/netdatabot.gpg.key ${DEB_GPG_KEY_SOURCE})
  114. add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/netdata.gpg
  115. COMMENT "Dearmor ${CMAKE_BINARY_DIR}/netdatabot.gpg.key"
  116. DEPENDS ${CMAKE_BINARY_DIR}/netdatabot.gpg.key
  117. COMMAND ${GPG} --dearmor --output ${CMAKE_BINARY_DIR}/netdata.gpg ${CMAKE_BINARY_DIR}/netdatabot.gpg.key)
  118. add_custom_target(dearmor_gpg_key
  119. ALL
  120. COMMENT "Dearmor ${CMAKE_BINARY_DIR}/netdatabot.gpg.key"
  121. DEPENDS ${CMAKE_BINARY_DIR}/netdata.gpg)
  122. install(FILES ${CMAKE_BINARY_DIR}/netdata.gpg
  123. DESTINATION usr/share/keyrings
  124. RENAME netdata-archive-keyring.gpg
  125. PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
  126. COMPONENT netdata-repo)
  127. install(FILES ${CMAKE_BINARY_DIR}/netdata.gpg
  128. DESTINATION usr/share/keyrings
  129. RENAME netdata-archive-keyring.gpg
  130. PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
  131. COMPONENT netdata-repo-edge)
  132. set(CPACK_DEB_COMPONENT_INSTALL YES)
  133. set(CPACK_DEBIAN_DEBUGINFO_PACKAGE NO)
  134. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS NO)
  135. set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS YES)
  136. set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
  137. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Netdata Builder <bot@netdata.cloud>")
  138. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")
  139. set(CPACK_DEBIAN_PACKAGE_DEPENDS "debian-keyring, gnupg")
  140. set(CPACK_DEBIAN_PACKAGE_SECTION "net")
  141. set(CPACK_DEBIAN_PACKAGE_VERSION "${PACKAGE_VERSION}")
  142. set(CPACK_DEBIAN_PACKAGE_RELEASE "${PACKAGE_RELEASE}")
  143. set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_NAME "netdata-repo")
  144. set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_NAME "netdata-repo-edge")
  145. set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_CONFLICTS "netdata-repo-edge")
  146. set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_CONFLICTS "netdata-repo")
  147. set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/netdata-repo/changelog")
  148. set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/netdata-repo-edge/changelog")
  149. elseif(${DISTRO} IN_LIST RPM_DISTROS)
  150. require_command(RPM rpm)
  151. if(${RPM} STREQUAL "RPM-NOTFOUND")
  152. message(FATAL_ERROR "Unable to find rpm, which is required for RPM package builds.")
  153. endif()
  154. set(REPO_CFG_PATH "yum.repos.d")
  155. set(REPO_ID "dnf")
  156. set(DIST_NAME "${DISTRO}")
  157. set(DIST_VERSION "$releasever")
  158. if(${DISTRO} STREQUAL "amzn")
  159. set(DIST_NAME "amazonlinux")
  160. if(${DISTRO_VERSION} VERSION_EQUAL 2)
  161. # Nothing to do in this case, defaults work here.
  162. elseif(${DISTRO_VERSION} VERSION_EQUAL 2023)
  163. set(DIST_VERSION "2023")
  164. else()
  165. message(FATAL_ERROR "Unsupported version of Amazon Linux: ${DISTRO_VERSION}")
  166. endif()
  167. elseif(${DISTRO} STREQUAL "opensuse")
  168. set(REPO_CFG_PATH "zypp/repos.d")
  169. set(REPO_ID "zypp")
  170. set(DIST_NAME "opensuse")
  171. elseif(${DISTRO} STREQUAL "rhel")
  172. set(DIST_NAME "el")
  173. if(${DISTRO_VERSION} VERSION_LESS_EQUAL 8)
  174. set(CPACK_RPM_PACKAGE_REQUIRES "yum-plugin-priorities, epel-release")
  175. else()
  176. set(CPACK_RPM_PACKAGE_REQUIRES "epel-release")
  177. endif()
  178. endif()
  179. message(STATUS "Generating stable repository configuration for ${DISTRO} ${DISTRO_VERSION}")
  180. set(VARIANT stable)
  181. configure_file(netdata.repo.${REPO_ID} netdata.repo @ONLY)
  182. message(STATUS "Generating edge repository configuration for ${DISTRO} ${DISTRO_VERSION}")
  183. set(VARIANT edge)
  184. configure_file(netdata.repo.${REPO_ID} netdata-edge.repo @ONLY)
  185. install(FILES ${CMAKE_BINARY_DIR}/netdata.repo
  186. COMPONENT netdata-repo
  187. DESTINATION etc/${REPO_CFG_PATH})
  188. install(FILES ${CMAKE_BINARY_DIR}/netdata-edge.repo
  189. COMPONENT netdata-repo-edge
  190. DESTINATION etc/${REPO_CFG_PATH})
  191. set(CPACK_RPM_COMPONENT_INSTALL ON)
  192. set(CPACK_RPM_PACAKGE_AUTOREQPROV OFF)
  193. set(CPACK_RPM_DEBUGINFO_PACKAGE OFF)
  194. set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
  195. set(CPACK_RPM_PACKAGE_GROUP "System Environment/Base")
  196. set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "")
  197. set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
  198. set(CPACK_RPM_PACKAGE_VERSION "${PACKAGE_VERSION}")
  199. set(CPACK_RPM_PACKAGE_RELEASE "${PACKAGE_RELEASE}")
  200. set(CPACK_RPM_PACKAGE_CHANGELOG "${CMAKE_SOURCE_DIR}/rpm.changelog")
  201. set(CPACK_RPM_NETDATA-REPO_FILE_NAME "netdata-repo-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.noarch.rpm")
  202. set(CPACK_RPM_NETDATA-REPO_PACKAGE_NAME "netdata-repo")
  203. set(CPACK_RPM_NETDATA-REPO_PACAKGE_CONFLICTS "netdata-repo-edge")
  204. set(CPACK_RPM_NETDATA-REPO-EDGE_FILE_NAME "netdata-repo-edge-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.noarch.rpm")
  205. set(CPACK_RPM_NETDATA-REPO-EDGE_PACKAGE_NAME "netdata-repo-edge")
  206. set(CPACK_RPM_NETDATA-REPO-EDGE_PACKAGE_CONFLICTS "netdata-repo")
  207. else()
  208. message(FATAL_ERROR "Unsupported distribution ${DISTRO} ${DISTRO_VERSION}")
  209. endif()
  210. include(CPack)