summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-03-20 14:03:15 -0400
committerGitHub <noreply@github.com>2024-03-20 14:03:15 -0400
commit8128af5210538780af89c87f9d87c246baa0b043 (patch)
tree839225b1b7dda284a0afc89553a5a6383f8cd165
parent11cf7564d5e3cdf524c38c6b29141932e5cfcbde (diff)
Move bundling of libyaml to CMake. (#17190)
-rw-r--r--CMakeLists.txt28
-rwxr-xr-xnetdata-installer.sh67
-rw-r--r--packaging/cmake/Modules/NetdataYAML.cmake65
-rw-r--r--packaging/installer/functions.sh1
-rw-r--r--packaging/yaml.checksums1
-rw-r--r--packaging/yaml.version1
6 files changed, 78 insertions, 85 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d72320bc4c..8bd91c8d82 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -269,6 +269,18 @@ if(NOT HAVE_LOG10)
endif()
#
+# Custom modules
+#
+
+include(NetdataYAML)
+
+#
+# Checks from custom modules
+#
+
+netdata_detect_libyaml()
+
+#
# check include files
#
@@ -1525,21 +1537,7 @@ endif()
# message(FATAL_ERROR "jsonc libraries: ${JSONC_LIBRARIES}")
# message(FATAL_ERROR "jsonc ldflags: ${JSONC_LDFLAGS}")
-# yaml
-set(HAVE_LIBYAML True)
-if(ENABLE_BUNDLED_YAML)
- add_library(yaml STATIC IMPORTED)
- set_property(TARGET yaml PROPERTY
- IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/externaldeps/libyaml/libyaml.a")
-
- target_include_directories(libnetdata BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/externaldeps/libyaml")
- target_link_libraries(libnetdata PUBLIC yaml)
-else()
- pkg_check_modules(YAML REQUIRED yaml-0.1)
- target_include_directories(libnetdata BEFORE PUBLIC ${YAML_INCLUDE_DIRS})
- target_compile_definitions(libnetdata PUBLIC ${YAML_CFLAGS_OTHER})
- target_link_libraries(libnetdata PUBLIC ${YAML_LDFLAGS})
-endif()
+netdata_add_libyaml_to_target(libnetdata)
# zlib
pkg_check_modules(ZLIB REQUIRED zlib)
diff --git a/netdata-installer.sh b/netdata-installer.sh
index 50bfa30fae..b8a598dc69 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -624,73 +624,6 @@ bundle_jsonc() {
bundle_jsonc
# -----------------------------------------------------------------------------
-build_yaml() {
- env_cmd=''
-
- if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
- env_cmd="env CFLAGS='-fPIC -pipe -Wno-unused-value' CXXFLAGS='-fPIC -pipe' LDFLAGS="
- fi
-
- cd "${1}" > /dev/null || return 1
- run eval "${env_cmd} ./configure --disable-shared --disable-dependency-tracking --with-pic"
- run eval "${env_cmd} ${make} ${MAKEOPTS}"
- cd - > /dev/null || return 1
-}
-
-copy_yaml() {
- target_dir="${PWD}/externaldeps/libyaml"
-
- run mkdir -p "${target_dir}" || return 1
-
- run cp "${1}/src/.libs/libyaml.a" "${target_dir}/libyaml.a" || return 1
- run cp "${1}/include/yaml.h" "${target_dir}/" || return 1
-}
-
-bundle_yaml() {
- if pkg-config yaml-0.1; then
- BUNDLE_YAML=0
- return 0
- fi
-
- if [ -z "${make}" ]; then
- fatal "Need to bundle libyaml but cannot find a copy of Make to build it with. Either install development files for libyaml, or install a usable copy fo Make." I0016
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling YAML."
-
- progress "Prepare YAML"
-
- YAML_PACKAGE_VERSION="$(cat packaging/yaml.version)"
-
- tmp="$(mktemp -d -t netdata-yaml-XXXXXX)"
- YAML_PACKAGE_BASENAME="yaml-${YAML_PACKAGE_VERSION}.tar.gz"
-
- if fetch_and_verify "yaml" \
- "https://github.com/yaml/libyaml/releases/download/${YAML_PACKAGE_VERSION}/${YAML_PACKAGE_BASENAME}" \
- "${YAML_PACKAGE_BASENAME}" \
- "${tmp}" \
- "${NETDATA_LOCAL_TARBALL_OVERRIDE_YAML}"; then
- if run tar --no-same-owner -xf "${tmp}/${YAML_PACKAGE_BASENAME}" -C "${tmp}" &&
- build_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
- copy_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
- rm -rf "${tmp}"; then
- run_ok "YAML built and prepared."
- BUNDLE_YAML=1
- else
- run_failed "Failed to build YAML, critical error."
- BUNDLE_YAML=0
- fi
- else
- run_failed "Unable to fetch sources for YAML, critical error."
- BUNDLE_YAML=0
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
-}
-
-bundle_yaml
-
-# -----------------------------------------------------------------------------
get_kernel_version() {
r="$(uname -r | cut -f 1 -d '-')"
diff --git a/packaging/cmake/Modules/NetdataYAML.cmake b/packaging/cmake/Modules/NetdataYAML.cmake
new file mode 100644
index 0000000000..73af55167d
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataYAML.cmake
@@ -0,0 +1,65 @@
+# Functions and macros for handling of libYAML
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Handle bundling of libyaml.
+#
+# This pulls it in as a sub-project using FetchContent functionality.
+#
+# This needs to be a function and not a macro for variable scoping
+# reasons. All the things we care about from the sub-project are exposed
+# as targets, which are globally scoped and not function scoped.
+function(netdata_bundle_libyaml)
+ include(FetchContent)
+ include(NetdataFetchContentExtra)
+
+ if(ENABLE_BUNDLED_LIBYAML)
+ set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
+ endif()
+
+ set(FETCHCONTENT_FULLY_DISCONNECTED Off)
+
+ FetchContent_Declare(yaml
+ GIT_REPOSITORY https://github.com/yaml/libyaml
+ GIT_TAG 2c891fc7a770e8ba2fec34fc6b545c672beb37e6 # v0.2.5
+ )
+
+ FetchContent_MakeAvailable_NoInstall(yaml)
+endfunction()
+
+# Handle setup of libyaml for the build.
+#
+# This will attempt to find libyaml using pkg_check_modules. If it finds
+# a usable copy, that will be used. If not, it will bundle a vendored copy
+# as a sub-project.
+#
+# Irrespective of how libyaml is to be included, library names,
+# include directories, and compile definitions will be specified in the
+# NETDATA_YAML_* variables for later use.
+macro(netdata_detect_libyaml)
+ set(HAVE_LIBYAML True)
+
+ pkg_check_modules(YAML yaml-0.1)
+
+ if(ENABLE_BUNDLED_LIBYAML OR NOT YAML_FOUND)
+ netdata_bundle_libyaml()
+ set(NETDATA_YAML_LDFLAGS yaml)
+ get_target_property(NETDATA_YAML_INCLUDE_DIRS yaml INTERFACE_INCLUDE_DIRECTORIES)
+ get_target_property(NETDATA_YAML_CFLAGS_OTHER yaml INTERFACE_COMPILE_DEFINITIONS)
+ else()
+ set(NETDATA_YAML_LDFLAGS ${YAML_LDFLAGS})
+ set(NETDATA_YAML_CFLAGS_OTHER ${YAML_CFLAGS_OTHER})
+ set(NETDATA_YAML_INCLUDE_DIRS ${YAML_INCLUDE_DIRS})
+ endif()
+endmacro()
+
+# Add libyaml as a public link dependency of the specified target.
+#
+# The specified target must already exist, and the netdata_detect_libyaml
+# macro must have already been run at least once for this to work correctly.
+function(netdata_add_libyaml_to_target _target)
+ target_include_directories(${_target} PUBLIC ${NETDATA_YAML_INCLUDE_DIRS})
+ target_compile_definitions(${_target} PUBLIC ${NETDATA_YAML_CFLAGS_OTHER})
+ target_link_libraries(${_target} PUBLIC ${NETDATA_YAML_LDFLAGS})
+endfunction()
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh
index c05382492b..9060930ce2 100644
--- a/packaging/installer/functions.sh
+++ b/packaging/installer/functions.sh
@@ -306,7 +306,6 @@ prepare_cmake_options() {
enable_feature ACLK "${ENABLE_CLOUD:-1}"
enable_feature CLOUD "${ENABLE_CLOUD:-1}"
enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C:-0}"
- enable_feature BUNDLED_YAML "${BUNDLE_YAML:-0}"
enable_feature DBENGINE "${ENABLE_DBENGINE:-1}"
enable_feature H2O "${ENABLE_H2O:-1}"
enable_feature ML "${NETDATA_ENABLE_ML:-1}"
diff --git a/packaging/yaml.checksums b/packaging/yaml.checksums
deleted file mode 100644
index 563c273d45..0000000000
--- a/packaging/yaml.checksums
+++ /dev/null
@@ -1 +0,0 @@
-c642ae9b75fee120b2d96c712538bd2cf283228d2337df2cf2988e3c02678ef4 yaml-0.2.5.tar.gz
diff --git a/packaging/yaml.version b/packaging/yaml.version
deleted file mode 100644
index 3a4036fb45..0000000000
--- a/packaging/yaml.version
+++ /dev/null
@@ -1 +0,0 @@
-0.2.5