@cryptotaxi247 / netdata-1 / commits / 8128af521

Move bundling of libyaml to CMake. (#17190)

Austin S. Hemmelgarn committed Mar 20, 2024 at 14:03 UTC 8128af5210538780af89c87f9d87c246baa0b043
6 files changed +78 -85
CMakeLists.txt
+13 -15
@@ -268,6 +268,18 @@ if(NOT HAVE_LOG10)
268 endif()
269 endif()
270
271 +#
272 +# Custom modules
273 +#
274 +
275 +include(NetdataYAML)
276 +
277 +#
278 +# Checks from custom modules
279 +#
280 +
281 +netdata_detect_libyaml()
282 +
283 #
284 # check include files
285 #
@@ -1525,21 +1537,7 @@ endif()
1537 # message(FATAL_ERROR "jsonc libraries: ${JSONC_LIBRARIES}")
1538 # message(FATAL_ERROR "jsonc ldflags: ${JSONC_LDFLAGS}")
1539
1528 -# yaml
1529 -set(HAVE_LIBYAML True)
1530 -if(ENABLE_BUNDLED_YAML)
1531 - add_library(yaml STATIC IMPORTED)
1532 - set_property(TARGET yaml PROPERTY
1533 - IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/externaldeps/libyaml/libyaml.a")
1534 -
1535 - target_include_directories(libnetdata BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/externaldeps/libyaml")
1536 - target_link_libraries(libnetdata PUBLIC yaml)
1537 -else()
1538 - pkg_check_modules(YAML REQUIRED yaml-0.1)
1539 - target_include_directories(libnetdata BEFORE PUBLIC ${YAML_INCLUDE_DIRS})
1540 - target_compile_definitions(libnetdata PUBLIC ${YAML_CFLAGS_OTHER})
1541 - target_link_libraries(libnetdata PUBLIC ${YAML_LDFLAGS})
1542 -endif()
1540 +netdata_add_libyaml_to_target(libnetdata)
1541
1542 # zlib
1543 pkg_check_modules(ZLIB REQUIRED zlib)
netdata-installer.sh
-67
@@ -623,73 +623,6 @@ bundle_jsonc() {
623
624 bundle_jsonc
625
626 -# -----------------------------------------------------------------------------
627 -build_yaml() {
628 - env_cmd=''
629 -
630 - if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
631 - env_cmd="env CFLAGS='-fPIC -pipe -Wno-unused-value' CXXFLAGS='-fPIC -pipe' LDFLAGS="
632 - fi
633 -
634 - cd "${1}" > /dev/null || return 1
635 - run eval "${env_cmd} ./configure --disable-shared --disable-dependency-tracking --with-pic"
636 - run eval "${env_cmd} ${make} ${MAKEOPTS}"
637 - cd - > /dev/null || return 1
638 -}
639 -
640 -copy_yaml() {
641 - target_dir="${PWD}/externaldeps/libyaml"
642 -
643 - run mkdir -p "${target_dir}" || return 1
644 -
645 - run cp "${1}/src/.libs/libyaml.a" "${target_dir}/libyaml.a" || return 1
646 - run cp "${1}/include/yaml.h" "${target_dir}/" || return 1
647 -}
648 -
649 -bundle_yaml() {
650 - if pkg-config yaml-0.1; then
651 - BUNDLE_YAML=0
652 - return 0
653 - fi
654 -
655 - if [ -z "${make}" ]; then
656 - 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
657 - fi
658 -
659 - [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling YAML."
660 -
661 - progress "Prepare YAML"
662 -
663 - YAML_PACKAGE_VERSION="$(cat packaging/yaml.version)"
664 -
665 - tmp="$(mktemp -d -t netdata-yaml-XXXXXX)"
666 - YAML_PACKAGE_BASENAME="yaml-${YAML_PACKAGE_VERSION}.tar.gz"
667 -
668 - if fetch_and_verify "yaml" \
669 - "https://github.com/yaml/libyaml/releases/download/${YAML_PACKAGE_VERSION}/${YAML_PACKAGE_BASENAME}" \
670 - "${YAML_PACKAGE_BASENAME}" \
671 - "${tmp}" \
672 - "${NETDATA_LOCAL_TARBALL_OVERRIDE_YAML}"; then
673 - if run tar --no-same-owner -xf "${tmp}/${YAML_PACKAGE_BASENAME}" -C "${tmp}" &&
674 - build_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
675 - copy_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
676 - rm -rf "${tmp}"; then
677 - run_ok "YAML built and prepared."
678 - BUNDLE_YAML=1
679 - else
680 - run_failed "Failed to build YAML, critical error."
681 - BUNDLE_YAML=0
682 - fi
683 - else
684 - run_failed "Unable to fetch sources for YAML, critical error."
685 - BUNDLE_YAML=0
686 - fi
687 -
688 - [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
689 -}
690 -
691 -bundle_yaml
692 -
626 # -----------------------------------------------------------------------------
627
628 get_kernel_version() {
packaging/cmake/Modules/NetdataYAML.cmake new
+65
@@ -0,0 +1,65 @@
1 +# Functions and macros for handling of libYAML
2 +#
3 +# Copyright (c) 2024 Netdata Inc.
4 +# SPDX-License-Identifier: GPL-3.0-or-later
5 +
6 +# Handle bundling of libyaml.
7 +#
8 +# This pulls it in as a sub-project using FetchContent functionality.
9 +#
10 +# This needs to be a function and not a macro for variable scoping
11 +# reasons. All the things we care about from the sub-project are exposed
12 +# as targets, which are globally scoped and not function scoped.
13 +function(netdata_bundle_libyaml)
14 + include(FetchContent)
15 + include(NetdataFetchContentExtra)
16 +
17 + if(ENABLE_BUNDLED_LIBYAML)
18 + set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
19 + endif()
20 +
21 + set(FETCHCONTENT_FULLY_DISCONNECTED Off)
22 +
23 + FetchContent_Declare(yaml
24 + GIT_REPOSITORY https://github.com/yaml/libyaml
25 + GIT_TAG 2c891fc7a770e8ba2fec34fc6b545c672beb37e6 # v0.2.5
26 + )
27 +
28 + FetchContent_MakeAvailable_NoInstall(yaml)
29 +endfunction()
30 +
31 +# Handle setup of libyaml for the build.
32 +#
33 +# This will attempt to find libyaml using pkg_check_modules. If it finds
34 +# a usable copy, that will be used. If not, it will bundle a vendored copy
35 +# as a sub-project.
36 +#
37 +# Irrespective of how libyaml is to be included, library names,
38 +# include directories, and compile definitions will be specified in the
39 +# NETDATA_YAML_* variables for later use.
40 +macro(netdata_detect_libyaml)
41 + set(HAVE_LIBYAML True)
42 +
43 + pkg_check_modules(YAML yaml-0.1)
44 +
45 + if(ENABLE_BUNDLED_LIBYAML OR NOT YAML_FOUND)
46 + netdata_bundle_libyaml()
47 + set(NETDATA_YAML_LDFLAGS yaml)
48 + get_target_property(NETDATA_YAML_INCLUDE_DIRS yaml INTERFACE_INCLUDE_DIRECTORIES)
49 + get_target_property(NETDATA_YAML_CFLAGS_OTHER yaml INTERFACE_COMPILE_DEFINITIONS)
50 + else()
51 + set(NETDATA_YAML_LDFLAGS ${YAML_LDFLAGS})
52 + set(NETDATA_YAML_CFLAGS_OTHER ${YAML_CFLAGS_OTHER})
53 + set(NETDATA_YAML_INCLUDE_DIRS ${YAML_INCLUDE_DIRS})
54 + endif()
55 +endmacro()
56 +
57 +# Add libyaml as a public link dependency of the specified target.
58 +#
59 +# The specified target must already exist, and the netdata_detect_libyaml
60 +# macro must have already been run at least once for this to work correctly.
61 +function(netdata_add_libyaml_to_target _target)
62 + target_include_directories(${_target} PUBLIC ${NETDATA_YAML_INCLUDE_DIRS})
63 + target_compile_definitions(${_target} PUBLIC ${NETDATA_YAML_CFLAGS_OTHER})
64 + target_link_libraries(${_target} PUBLIC ${NETDATA_YAML_LDFLAGS})
65 +endfunction()
packaging/installer/functions.sh
-1
@@ -306,7 +306,6 @@ prepare_cmake_options() {
306 enable_feature ACLK "${ENABLE_CLOUD:-1}"
307 enable_feature CLOUD "${ENABLE_CLOUD:-1}"
308 enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C:-0}"
309 - enable_feature BUNDLED_YAML "${BUNDLE_YAML:-0}"
309 enable_feature DBENGINE "${ENABLE_DBENGINE:-1}"
310 enable_feature H2O "${ENABLE_H2O:-1}"
311 enable_feature ML "${NETDATA_ENABLE_ML:-1}"
packaging/yaml.checksums deleted
-1
@@ -1 +0,0 @@
1 -c642ae9b75fee120b2d96c712538bd2cf283228d2337df2cf2988e3c02678ef4 yaml-0.2.5.tar.gz
packaging/yaml.version deleted
-1
@@ -1 +0,0 @@
1 -0.2.5