diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19789b3bc8..7d0f08640d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,21 +10,6 @@ on: - devel jobs: - git-branch: - name: Get git branch - runs-on: ubuntu-latest - outputs: - branch-name: ${{ steps.get-git-branch.outputs.branch-name }} - steps: - - id: get-git-branch - run: | - if ${{ github.event_name == 'push' }} - then export GIT_BRANCH=`echo ${{ github.ref }} | cut -d'/' -f 3` - else - export GIT_BRANCH=${{ github.base_ref }} - fi - echo "branch-name=$GIT_BRANCH" >> $GITHUB_OUTPUT - build-unix: name: ${{ matrix.config.name }} runs-on: ${{ matrix.config.os }} @@ -266,9 +251,10 @@ jobs: - name: Build in 32-bit container run: | docker run --rm \ + --platform linux/386 \ -v ${{ github.workspace }}:${{ github.workspace }} \ -w ${{ github.workspace }} \ - i386/ubuntu \ + debian:13 \ /bin/bash -c " \ apt-get update -q && \ apt-get install -y -q git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev libcbor-dev && \ @@ -315,7 +301,6 @@ jobs: build-packages: name: ${{ matrix.config.name }} runs-on: ubuntu-latest - needs: git-branch strategy: fail-fast: false matrix: @@ -333,7 +318,7 @@ jobs: image: "debian:13", pkg-setup: "apt-get update -q", pkg-cmd: "apt-get install -yq", - pkg-packages: "pipx cmake git debhelper pkg-config libcmocka-dev libpcre2-dev libcbor-dev libxxhash-dev", + pkg-packages: "pipx cmake git debhelper libcmocka-dev libpcre2-dev libcbor-dev libxxhash-dev", pipx-install: "" } container: @@ -349,9 +334,11 @@ jobs: pipx install apkg $HOME/.local/bin/apkg system-setup + - uses: actions/checkout@main + - name: Build-and-install-package run: | - git clone -b ${{ needs.git-branch.outputs.branch-name }} https://github.com/CESNET/libyang.git - cd libyang + # the container runs as root, the checked out workspace belongs to the runner user + git config --global --add safe.directory $GITHUB_WORKSPACE $HOME/.local/bin/apkg build $HOME/.local/bin/apkg install diff --git a/CMakeLists.txt b/CMakeLists.txt index f45fd92287..f15d1a49a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ if(WIN32) cmake_minimum_required(VERSION 3.22.0) else() - cmake_minimum_required(VERSION 2.8.12...3.28.1) + cmake_minimum_required(VERSION 3.12...3.28.1) endif() # force out-of-source build @@ -20,6 +20,7 @@ include(ABICheck) include(SourceFormat) include(GenDoc) include(GenCoverage) +include(GenConfigPackage) include(CheckIncludeFile) # set default build type if not specified by user @@ -80,7 +81,9 @@ else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -std=c11") endif() -include_directories(${PROJECT_BINARY_DIR} ${PROJECT_BINARY_DIR}/libyang ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/plugins_exts) +include_directories(${PROJECT_BINARY_DIR} + ${PROJECT_BINARY_DIR}/include ${PROJECT_BINARY_DIR}/include/libyang + ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/plugins_exts) # type plugins are separate because they have their documentation generated set(type_plugins @@ -205,6 +208,7 @@ set(internal_headers src/hash_table_internal.h src/in_internal.h src/json.h + src/lcbor.h src/lyb.h src/out_internal.h src/parser_internal.h @@ -235,7 +239,7 @@ set(doxy_files doc/transition_3_4.dox doc/transition_4_5.dox ${headers} - ${PROJECT_BINARY_DIR}/libyang/version.h + ${PROJECT_BINARY_DIR}/include/libyang/version.h ${type_plugins}) # project (doxygen) logo @@ -342,11 +346,11 @@ endif() find_package(CBOR) if(CBOR_FOUND) - set(LY_HAVE_CBOR 1) + set(LY_HAVE_CBOR TRUE) list(APPEND libsrc src/parser_cbor.c src/lcbor.c src/printer_cbor.c) - list(APPEND headers src/lcbor.h) list(APPEND format_sources src/parser_cbor.c src/lcbor.h src/lcbor.c src/printer_cbor.c) else() + set(LY_HAVE_CBOR FALSE) message(STATUS "libcbor not found, CBOR support disabled") endif() @@ -372,9 +376,12 @@ if(LY_HAVE_REGEX_H) endif() # generate and copy all public header files -configure_file(${PROJECT_SOURCE_DIR}/src/ly_config.h.in ${PROJECT_BINARY_DIR}/libyang/ly_config.h @ONLY) -configure_file(${PROJECT_SOURCE_DIR}/src/version.h.in ${PROJECT_BINARY_DIR}/libyang/version.h @ONLY) -file(COPY ${headers} DESTINATION ${PROJECT_BINARY_DIR}/libyang) +configure_file(${PROJECT_SOURCE_DIR}/src/ly_config.h.in ${PROJECT_BINARY_DIR}/include/libyang/ly_config.h @ONLY) +configure_file(${PROJECT_SOURCE_DIR}/src/version.h.in ${PROJECT_BINARY_DIR}/include/libyang/version.h @ONLY) +foreach(h IN LISTS headers) + get_filename_component(h_name ${h} NAME) + configure_file(${PROJECT_SOURCE_DIR}/${h} ${PROJECT_BINARY_DIR}/include/libyang/${h_name} COPYONLY) +endforeach() # DOC-only target with no extra dependencies if("${BUILD_TYPE_UPPER}" STREQUAL "DOCONLY") @@ -424,7 +431,7 @@ else() endif() #link dl - target_link_libraries(yang ${CMAKE_DL_LIBS}) + target_link_libraries(yang PRIVATE ${CMAKE_DL_LIBS}) endif() if(WIN32) @@ -443,26 +450,28 @@ if(WIN32) find_package(pthreads REQUIRED) set(COMPAT_WIN_LIBRARIES PThreads4W::PThreads4W shlwapi.lib ws2_32) - target_link_libraries(yang ${COMPAT_WIN_LIBRARIES}) + # ws2_32 is public, ly_config.h includes winsock2.h + target_link_libraries(yang PRIVATE PThreads4W::PThreads4W shlwapi.lib PUBLIC ws2_32) endif() set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION}) +target_include_directories(yang PUBLIC $ $) # link math if(NOT WIN32) - target_link_libraries(yang m) + target_link_libraries(yang PRIVATE m) endif() # find pthreads set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads REQUIRED) -target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(yang PRIVATE ${CMAKE_THREAD_LIBS_INIT}) # find PCRE2 library unset(PCRE2_LIBRARY CACHE) find_package(PCRE2 10.21 REQUIRED) include_directories(${PCRE2_INCLUDE_DIRS}) -target_link_libraries(yang ${PCRE2_LIBRARIES}) +target_link_libraries(yang PRIVATE ${PCRE2_LIBRARIES}) # link libcbor if found if(CBOR_FOUND) @@ -470,16 +479,15 @@ if(CBOR_FOUND) target_include_directories(yangobj PRIVATE ${CBOR_INCLUDE_DIR}) endif() target_include_directories(yang PRIVATE ${CBOR_INCLUDE_DIR}) - target_link_libraries(yang ${CBOR_LIBRARY}) + target_link_libraries(yang PRIVATE ${CBOR_LIBRARY}) endif() # XXHash include and library find_package(XXHash) if(XXHASH_FOUND) add_definitions(-DLY_XXHASH_SUPPORT) - set(PC_XXHASH_LIB libxxhash) include_directories(${XXHASH_INCLUDE_DIR}) - target_link_libraries(yang ${XXHASH_LIBRARY}) + target_link_libraries(yang PRIVATE ${XXHASH_LIBRARY}) message(STATUS "Hash algorithm: xxhash") if (HAVE_XXH3_64BITS_WITHSEED) # for 32-bit system compatibility, this may not be available there, so use XXH32 instead @@ -491,33 +499,58 @@ endif() # generated header list foreach(h IN LISTS gen_headers) - list(APPEND g_headers ${PROJECT_BINARY_DIR}/libyang/${h}) + list(APPEND g_headers ${PROJECT_BINARY_DIR}/include/libyang/${h}) endforeach() # install the modules install(DIRECTORY "${PROJECT_SOURCE_DIR}/modules/" DESTINATION ${YANG_MODULE_DIR} FILES_MATCHING PATTERN "*.yang") -# install all library files -install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR}) +# install all library files, a Windows DLL is RUNTIME and belongs to bin/ +install(TARGETS yang EXPORT LibYANGTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${headers} ${g_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang) -find_package(PkgConfig) -if(PKG_CONFIG_FOUND) - # generate and install pkg-config file - configure_file("libyang.pc.in" "libyang.pc" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - # check that pkg-config includes the used path - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) - if(RETURN EQUAL 0) - string(STRIP "${PC_PATH}" PC_PATH) - set(PC_PATH "${PC_PATH}:$ENV{PKG_CONFIG_PATH}") - string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}") - string(LENGTH "${SUBSTR}" SUBSTR_LEN) - if(SUBSTR_LEN EQUAL 0) - message(WARNING "pkg-config will not detect the new package after installation, adjust PKG_CONFIG_PATH using \"export PKG_CONFIG_PATH=\${PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig\".") - endif() +# CMake config package, for the build tree and the installation +if(BUILD_SHARED_LIBS) + # the package version is the SO version, which all the dependent projects check + gen_config_package(LibYANG ${LIBYANG_SOVERSION_FULL}) +else() + message(STATUS "Static build, CMake config package is not installed") +endif() + +# generate and install pkg-config file +if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(PC_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") +else() + set(PC_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +endif() +if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}") +else() + set(PC_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +endif() +# dependencies only in Libs.private, Requires.private would need their .pc files even for dynamic linking +set(PC_LIBS_PRIVATE "-lpcre2-8") +if(XXHASH_FOUND) + string(APPEND PC_LIBS_PRIVATE " -lxxhash") +endif() +if(CBOR_FOUND) + string(APPEND PC_LIBS_PRIVATE " -lcbor") +endif() +if(NOT WIN32) + string(APPEND PC_LIBS_PRIVATE " -lm") + # only the shared library loads plugins + if(BUILD_SHARED_LIBS AND CMAKE_DL_LIBS) + string(APPEND PC_LIBS_PRIVATE " -l${CMAKE_DL_LIBS}") endif() endif() +if(CMAKE_THREAD_LIBS_INIT) + string(APPEND PC_LIBS_PRIVATE " ${CMAKE_THREAD_LIBS_INIT}") +endif() +configure_file("libyang.pc.in" "libyang.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # tests if(ENABLE_TESTS) diff --git a/CMakeModules/GenConfigPackage.cmake b/CMakeModules/GenConfigPackage.cmake new file mode 100644 index 0000000000..7e1368362c --- /dev/null +++ b/CMakeModules/GenConfigPackage.cmake @@ -0,0 +1,42 @@ +# Generate the CMake config package of a library for the build tree and the installation +# +# gen_config_package(LIB_NAME LIB_SOVERSION_FULL [EXPORTS ...] [PATH_VARS ...]) +# LIB_NAME package name, the template is Config.cmake.in in the source root +# LIB_SOVERSION_FULL package version, the full SO version of the library +# EXPORTS optional, export sets installed besides Targets +# PATH_VARS optional, template variables with installed paths, _BUILD holds the build tree path +# +# The template reads its other variables from the scope of the caller. +include(CMakePackageConfigHelpers) + +function(gen_config_package LIB_NAME LIB_SOVERSION_FULL) + # the optional arguments into LIB_EXPORTS and LIB_PATH_VARS + cmake_parse_arguments(PARSE_ARGV 2 LIB "" "" "EXPORTS;PATH_VARS") + set(LIB_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME}) + set(LIB_TEMPLATE ${PROJECT_SOURCE_DIR}/${LIB_NAME}Config.cmake.in) + + # create the version file + write_basic_package_version_file(${PROJECT_BINARY_DIR}/${LIB_NAME}ConfigVersion.cmake + VERSION ${LIB_SOVERSION_FULL} COMPATIBILITY SameMajorVersion) + install(FILES ${PROJECT_BINARY_DIR}/${LIB_NAME}ConfigVersion.cmake DESTINATION ${LIB_CONFIG_DIR}) + + # the targets file of each export set, for the build tree and the installation + foreach(LIB_EXPORT IN ITEMS ${LIB_NAME}Targets ${LIB_EXPORTS}) + export(EXPORT ${LIB_EXPORT} NAMESPACE ${LIB_NAME}:: FILE ${PROJECT_BINARY_DIR}/${LIB_EXPORT}.cmake) + install(EXPORT ${LIB_EXPORT} NAMESPACE ${LIB_NAME}:: DESTINATION ${LIB_CONFIG_DIR}) + endforeach() + + # the installed config, generated aside so that it does not replace the build tree one + configure_package_config_file(${LIB_TEMPLATE} ${PROJECT_BINARY_DIR}/CMakeFiles/${LIB_NAME}Config.cmake + INSTALL_DESTINATION ${LIB_CONFIG_DIR} PATH_VARS ${LIB_PATH_VARS}) + install(FILES ${PROJECT_BINARY_DIR}/CMakeFiles/${LIB_NAME}Config.cmake DESTINATION ${LIB_CONFIG_DIR}) + + # each path variable set to its _BUILD value + foreach(LIB_VAR IN LISTS LIB_PATH_VARS) + set(${LIB_VAR} ${${LIB_VAR}_BUILD}) + endforeach() + + # the build tree config, the build directory is both its location and its prefix + configure_package_config_file(${LIB_TEMPLATE} ${PROJECT_BINARY_DIR}/${LIB_NAME}Config.cmake + INSTALL_DESTINATION ${PROJECT_BINARY_DIR} INSTALL_PREFIX ${PROJECT_BINARY_DIR} PATH_VARS ${LIB_PATH_VARS}) +endfunction() diff --git a/CMakeModules/UseCompat.cmake b/CMakeModules/UseCompat.cmake index 53bb0236e7..48c588d226 100644 --- a/CMakeModules/UseCompat.cmake +++ b/CMakeModules/UseCompat.cmake @@ -44,9 +44,13 @@ macro(USE_COMPAT) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads) - list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + if(CMAKE_THREAD_LIBS_INIT) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + endif() check_function_exists(pthread_mutex_timedlock HAVE_PTHREAD_MUTEX_TIMEDLOCK) - list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} "") # cmake <= 3.19 needs at least one item + if(CMAKE_THREAD_LIBS_INIT) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + endif() test_big_endian(IS_BIG_ENDIAN) diff --git a/FindLibYANG.cmake b/FindLibYANG.cmake deleted file mode 100644 index 89cd93ad50..0000000000 --- a/FindLibYANG.cmake +++ /dev/null @@ -1,89 +0,0 @@ -# - Try to find LibYANG -# Once done this will define -# -# LIBYANG_FOUND - system has LibYANG -# LIBYANG_INCLUDE_DIRS - the LibYANG include directory -# LIBYANG_LIBRARIES - Link these to use LibYANG -# LIBYANG_VERSION - SO version of the found libyang library -# -# Author Michal Vasko -# Copyright (c) 2021 CESNET, z.s.p.o. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -include(FindPackageHandleStandardArgs) - -if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS) - # in cache already - set(LIBYANG_FOUND TRUE) -else() - find_path(LIBYANG_INCLUDE_DIR - NAMES - libyang/libyang.h - PATHS - /usr/include - /usr/local/include - /opt/local/include - /sw/include - ${CMAKE_INCLUDE_PATH} - ${CMAKE_INSTALL_PREFIX}/include - ) - - find_library(LIBYANG_LIBRARY - NAMES - yang - libyang - PATHS - /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/local/lib - /sw/lib - ${CMAKE_LIBRARY_PATH} - ${CMAKE_INSTALL_PREFIX}/lib - ) - - if(LIBYANG_INCLUDE_DIR) - find_path(LY_VERSION_PATH "libyang/version.h" HINTS ${LIBYANG_INCLUDE_DIR}) - if(LY_VERSION_PATH) - file(READ "${LY_VERSION_PATH}/libyang/version.h" LY_VERSION_FILE) - else() - find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR}) - file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_VERSION_FILE) - endif() - string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_VERSION_FILE}") - string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}") - endif() - - set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR}) - set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY}) - mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES) - - # handle the QUIETLY and REQUIRED arguments and set LIBYANG_FOUND to TRUE - # if all listed variables are TRUE - find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND - REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR - VERSION_VAR LIBYANG_VERSION) -endif() diff --git a/LibYANGConfig.cmake.in b/LibYANGConfig.cmake.in new file mode 100644 index 0000000000..791e08b259 --- /dev/null +++ b/LibYANGConfig.cmake.in @@ -0,0 +1,18 @@ +# CMake config package of libyang +# +# Imported target: +# LibYANG::yang the libyang library +# +# Variables: +# LibYANG_VERSION SO version of the library, compared by find_package() +# LibYANG_PROJECT_VERSION version of the libyang project +# LibYANG_HAVE_CBOR libyang supports the CBOR data format (LY_HAVE_CBOR) + +@PACKAGE_INIT@ + +set(LibYANG_PROJECT_VERSION "@LIBYANG_VERSION@") +set(LibYANG_HAVE_CBOR @LY_HAVE_CBOR@) + +# the LibYANG::yang target, generated by CMake next to this file +include("${CMAKE_CURRENT_LIST_DIR}/LibYANGTargets.cmake") +check_required_components(LibYANG) diff --git a/README.md b/README.md index 036318a0b7..4b8c5ad7ff 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ libyang & yanglint can be installed using [homebrew](https://brew.sh/) with ```b ### Unix Build Requirements * C compiler -* cmake >= 2.8.12 +* cmake >= 3.12 * libpcre2 >= 10.21 (including devel package) #### Optional @@ -188,8 +188,21 @@ library was installed into a non-standard path, the path to libyang must be spec linker. To help with setting all the compiler's options, there is `libyang.pc` file for `pkg-config(1)` available in the source tree. The file is installed with the library. -If you are using `cmake` in you project, it is also possible to use the provided -`FindLibYANG.cmake` file to detect presence of the libyang library in the system. +A CMake project finds libyang by its CMake package, installed into `LIBDIR/cmake/LibYANG` +(`LIBDIR` is the library directory under the install prefix, e.g. `/usr/local/lib`): +``` +find_package(LibYANG 5 CONFIG REQUIRED) +target_link_libraries(myapp PRIVATE LibYANG::yang) +``` + +The version passed to `find_package()` is the SO version of the library. The package also +defines the following variables: + +* `LibYANG_PROJECT_VERSION` - project version of libyang, +* `LibYANG_HAVE_CBOR` - whether libyang supports the CBOR data format. + +To use libyang from its build directory, pass `-DLibYANG_DIR=`. +Static builds and older libyang releases provide no CMake package, use `pkg-config` with them. ## Bindings diff --git a/distro/pkg/deb/control b/distro/pkg/deb/control index cd967faf34..0f17fd61ac 100644 --- a/distro/pkg/deb/control +++ b/distro/pkg/deb/control @@ -9,8 +9,7 @@ Build-Depends: cmake, libcmocka-dev , libpcre2-dev, libcbor-dev, - libxxhash-dev, - pkg-config + libxxhash-dev Vcs-Browser: https://github.com/CESNET/libyang/tree/master Vcs-Git: https://github.com/CESNET/libyang.git diff --git a/distro/pkg/deb/libyang-dev.install b/distro/pkg/deb/libyang-dev.install index 452d7e0142..ba59834e0c 100644 --- a/distro/pkg/deb/libyang-dev.install +++ b/distro/pkg/deb/libyang-dev.install @@ -1,3 +1,4 @@ usr/include/libyang/*.h usr/lib/*/*.so usr/lib/*/pkgconfig/*.pc +usr/lib/*/cmake/LibYANG diff --git a/distro/pkg/deb/rules b/distro/pkg/deb/rules index 58f845de82..5339ca9ed3 100755 --- a/distro/pkg/deb/rules +++ b/distro/pkg/deb/rules @@ -10,3 +10,7 @@ include /usr/share/dpkg/default.mk override_dh_auto_configure: dh_auto_configure -- \ -DCMAKE_BUILD_TYPE:String="Release" + +# fail on installed files that no package lists +override_dh_missing: + dh_missing --fail-missing diff --git a/distro/pkg/rpm/libyang.spec b/distro/pkg/rpm/libyang.spec index 6322c5022a..c291b7eeb7 100644 --- a/distro/pkg/rpm/libyang.spec +++ b/distro/pkg/rpm/libyang.spec @@ -87,6 +87,7 @@ cp -a doc/html %{buildroot}/%{_docdir}/libyang/html %files devel %{_libdir}/libyang.so %{_libdir}/pkgconfig/libyang.pc +%{_libdir}/cmake/LibYANG/ %{_includedir}/libyang/*.h %dir %{_includedir}/libyang/ diff --git a/distro/tests/control b/distro/tests/control deleted file mode 100644 index 61b906099e..0000000000 --- a/distro/tests/control +++ /dev/null @@ -1 +0,0 @@ -Tests: test-pkg-config.sh test-yanglint.sh diff --git a/distro/tests/test-pkg-config.sh b/distro/tests/test-pkg-config.sh deleted file mode 100755 index 581e4d61f8..0000000000 --- a/distro/tests/test-pkg-config.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -ex - -version=`pkg-config --modversion libyang` -echo "$version" | grep '2\.[0-9.]\+' diff --git a/distro/tests/test-yanglint.sh b/distro/tests/test-yanglint.sh deleted file mode 100755 index 70bf4b9b47..0000000000 --- a/distro/tests/test-yanglint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -ex - -version=`yanglint --version` -echo "$version" | grep '2\.[0-9.]\+' diff --git a/libyang.pc.in b/libyang.pc.in index 63de935029..69712be6ed 100644 --- a/libyang.pc.in +++ b/libyang.pc.in @@ -1,11 +1,10 @@ prefix=@CMAKE_INSTALL_PREFIX@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=@PC_INCLUDEDIR@ +libdir=@PC_LIBDIR@ Name: @PROJECT_NAME@ Description: @LIBYANG_DESCRIPTION@ Version: @LIBYANG_VERSION@ -Requires.private: libpcre2-8 @PC_XXHASH_LIB@ Libs: -L${libdir} -lyang -Libs.private: -lpcre2-8 +Libs.private: @PC_LIBS_PRIVATE@ Cflags: -I${includedir} diff --git a/tests/yangupdate/CMakeLists.txt b/tests/yangupdate/CMakeLists.txt index 17b08d9325..f5d9e8199b 100644 --- a/tests/yangupdate/CMakeLists.txt +++ b/tests/yangupdate/CMakeLists.txt @@ -11,7 +11,7 @@ function(lyu_add_test) set(TEST_NAME yangupdate_${ARGV0}) add_executable(${TEST_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${ARGV0}/test.c) - target_include_directories(${TEST_NAME} PRIVATE ${PROJECT_BINARY_DIR}/libyang ${PROJECT_SOURCE_DIR}/tools/update) + target_include_directories(${TEST_NAME} PRIVATE ${PROJECT_BINARY_DIR}/include/libyang ${PROJECT_SOURCE_DIR}/tools/update) target_link_libraries(${TEST_NAME} ${YANGUPDATE_TEST_LIB} ${CMOCKA_LIBRARIES}) set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests) diff --git a/tools/lint/CMakeLists.txt b/tools/lint/CMakeLists.txt index 8e83e24b2b..3fd23f40f4 100644 --- a/tools/lint/CMakeLists.txt +++ b/tools/lint/CMakeLists.txt @@ -42,7 +42,8 @@ set(format_sources PARENT_SCOPE) add_executable(yanglint ${lintsrc} ${compatsrc}) -target_link_libraries(yanglint yang) +# the compat sources may call pthread functions +target_link_libraries(yanglint yang ${CMAKE_THREAD_LIBS_INIT}) install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}) diff --git a/tools/re/CMakeLists.txt b/tools/re/CMakeLists.txt index 7b6de226f1..f0fe050c5e 100644 --- a/tools/re/CMakeLists.txt +++ b/tools/re/CMakeLists.txt @@ -9,7 +9,8 @@ set(format_sources PARENT_SCOPE) add_executable(yangre ${resrc} ${compatsrc}) -target_link_libraries(yangre yang) +# the compat sources may call pthread functions +target_link_libraries(yangre yang ${CMAKE_THREAD_LIBS_INIT}) install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${PROJECT_SOURCE_DIR}/tools/re/yangre.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) target_include_directories(yangre BEFORE PRIVATE ${PROJECT_BINARY_DIR}) diff --git a/tools/update/CMakeLists.txt b/tools/update/CMakeLists.txt index 49bdf2cd64..c0aff02631 100644 --- a/tools/update/CMakeLists.txt +++ b/tools/update/CMakeLists.txt @@ -40,12 +40,17 @@ else() set(LIB_NAME yang_update) endif() -# yang update library -add_library(${LIB_NAME} STATIC ${lib_src}) +# yang update library, uses also internal libyang functions +if(TARGET yangobj) + add_library(${LIB_NAME} STATIC ${lib_src} $) + get_target_property(yang_linked_libraries yang LINK_LIBRARIES) + target_link_libraries(${LIB_NAME} ${yang_linked_libraries}) +else() + add_library(${LIB_NAME} STATIC ${lib_src}) + target_link_libraries(${LIB_NAME} yang) +endif() target_compile_definitions(${LIB_NAME} PUBLIC LIBYANG_BUILD) target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_BINARY_DIR}) -get_target_property(yang_linked_libraries yang LINK_LIBRARIES) -target_link_libraries(${LIB_NAME} $ ${yang_linked_libraries}) if(NOT YANGUPDATE_TEST_LIB) # yangupdate