Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 && \
Expand Down Expand Up @@ -315,7 +301,6 @@ jobs:
build-packages:
name: ${{ matrix.config.name }}
runs-on: ubuntu-latest
needs: git-branch
strategy:
fail-fast: false
matrix:
Expand All @@ -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:
Expand All @@ -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
123 changes: 71 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Comment thread
michalvasko marked this conversation as resolved.
Resolved

# type plugins are separate because they have their documentation generated
set(type_plugins
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -371,10 +375,13 @@ if(LY_HAVE_REGEX_H)
check_symbol_exists(REG_STARTEND "regex.h" HAVE_REG_STARTEND)
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)
# generate and copy all public header files, configure_file() refreshes the copies whenever they change
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")
Expand All @@ -395,6 +402,10 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
add_compile_definitions(__EXTENSIONS__)
endif()

# private dependencies of a static build, for Libs.private of libyang.pc,
# Requires.private would need their .pc files even for dynamic linking
set(PC_LIBS_PRIVATE "")

# create static libyang library
if(NOT BUILD_SHARED_LIBS)
add_definitions(-DSTATIC)
Expand All @@ -408,10 +419,10 @@ if(NOT BUILD_SHARED_LIBS)

set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
add_library(yang STATIC ${libsrc} ${compatsrc})
add_library(yang STATIC ${libsrc})
else()
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_library(yang SHARED ${libsrc} ${compatsrc})
add_library(yang SHARED ${libsrc})
if(NOT WIN32)
set_target_properties(yang PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
endif()
Expand All @@ -422,56 +433,59 @@ else()
set(CMAKE_DL_LIBS dlfcn-win32::dl)
endif()

#link dl
target_link_libraries(yang ${CMAKE_DL_LIBS})
#link dl, only the shared library loads plugins
target_link_libraries(yang PRIVATE ${CMAKE_DL_LIBS})
if(NOT WIN32 AND CMAKE_DL_LIBS)
string(APPEND PC_LIBS_PRIVATE " -l${CMAKE_DL_LIBS}")
endif()
endif()

if(WIN32)
find_path(DIRENT_INCLUDE_DIR NAMES dirent.h REQUIRED)
message(STATUS "Found <dirent.h> at ${DIRENT_INCLUDE_DIR}")
# compat functions, hidden in the shared library
target_link_libraries(yang PRIVATE yangcompat)

set(COMPAT_POSIX_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/compat/posix-shims
${DIRENT_INCLUDE_DIR})

target_include_directories(yang PRIVATE ${COMPAT_POSIX_INCLUDES})
include_directories(${COMPAT_POSIX_INCLUDES})

find_package(pthreads REQUIRED)
set(COMPAT_WIN_LIBRARIES PThreads4W::PThreads4W shlwapi.lib ws2_32)
target_link_libraries(yang ${COMPAT_WIN_LIBRARIES})
if(WIN32)
# ws2_32 is public, ly_config.h includes winsock2.h
target_link_libraries(yang PUBLIC ws2_32)
endif()

set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION})
target_include_directories(yang PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

# link math
if(NOT WIN32)
target_link_libraries(yang m)
target_link_libraries(yang PRIVATE m)
string(APPEND PC_LIBS_PRIVATE " -lm")
endif()

# find pthreads
# link pthreads
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(yang PRIVATE Threads::Threads)
if(CMAKE_THREAD_LIBS_INIT)
# the thread library flag for the .pc file
string(APPEND PC_LIBS_PRIVATE " ${CMAKE_THREAD_LIBS_INIT}")
endif()

# find PCRE2 library
find_package(PCRE2 10.21 REQUIRED)
include_directories(${PCRE2_INCLUDE_DIRS})
target_link_libraries(yang ${PCRE2_LIBRARIES})
target_link_libraries(yang PRIVATE ${PCRE2_LIBRARIES})
string(APPEND PC_LIBS_PRIVATE " -lpcre2-8")

# link libcbor if found
if(CBOR_FOUND)
target_include_directories(yang PRIVATE ${CBOR_INCLUDE_DIR})
target_link_libraries(yang ${CBOR_LIBRARY})
target_link_libraries(yang PRIVATE ${CBOR_LIBRARY})
string(APPEND PC_LIBS_PRIVATE " -lcbor")
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})
string(APPEND PC_LIBS_PRIVATE " -lxxhash")
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
Expand All @@ -483,34 +497,39 @@ 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()
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}
VARS
"PROJECT_VERSION" "${LIBYANG_VERSION}"
"HAVE_CBOR" "${LY_HAVE_CBOR}"
"YANG_MODULE_DIR" "${YANG_MODULE_DIR}"
"PLUGINS_DIR_EXTENSIONS" "${PLUGINS_DIR_EXTENSIONS}"
"PLUGINS_DIR_TYPES" "${PLUGINS_DIR_TYPES}")
else()
message(STATUS "Static build, CMake config package is not installed")
endif()

string(STRIP "${PC_LIBS_PRIVATE}" PC_LIBS_PRIVATE)

# 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")

# tests
if(ENABLE_TESTS)
enable_testing()
Expand Down
3 changes: 3 additions & 0 deletions CMakeModules/FindCBOR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ find_library(CBOR_LIBRARY

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CBOR FOUND_VAR CBOR_FOUND REQUIRED_VARS CBOR_INCLUDE_DIR CBOR_LIBRARY)

# show the CBOR_INCLUDE_DIR and CBOR_LIBRARY variables only in the advanced view
mark_as_advanced(CBOR_INCLUDE_DIR CBOR_LIBRARY)
4 changes: 2 additions & 2 deletions CMakeModules/FindCMocka.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ endif (CMOCKA_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR)

# show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view
mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES)
# show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARY variables only in the advanced view
mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARY)
2 changes: 1 addition & 1 deletion CMakeModules/FindPCRE2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ else()

set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
mark_as_advanced(PCRE2_INCLUDE_DIR PCRE2_LIBRARY)

# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
find_package_handle_standard_args(PCRE2 FOUND_VAR PCRE2_FOUND
Expand Down
3 changes: 3 additions & 0 deletions CMakeModules/FindXXHash.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ check_symbol_exists(XXH3_64bits_withSeed ${XXHASH_INCLUDE_DIR}/xxhash.h HAVE_XXH

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XXHash FOUND_VAR XXHASH_FOUND REQUIRED_VARS XXHASH_INCLUDE_DIR XXHASH_LIBRARY)

# show the XXHASH_INCLUDE_DIR and XXHASH_LIBRARY variables only in the advanced view
mark_as_advanced(XXHASH_INCLUDE_DIR XXHASH_LIBRARY)
Loading
Loading