Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 7, 2020
2 parents 1b7d73d + 357fd20 commit b62d0a7
Show file tree
Hide file tree
Showing 47 changed files with 1,517 additions and 824 deletions.
50 changes: 25 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ endif()

project(libyang C)

# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

include(GNUInstallDirs)
include(CheckSymbolExists)
include(UseCompat)

set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.")

Expand All @@ -21,18 +25,23 @@ set(CMAKE_MACOSX_RPATH TRUE)
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
set(LIBYANG_MAJOR_VERSION 1)
set(LIBYANG_MINOR_VERSION 0)
set(LIBYANG_MICRO_VERSION 130)
set(LIBYANG_MICRO_VERSION 167)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})

# Version of the library
# Major version is changed with every backward non-compatible API/ABI change in libyang, minor version changes
# with backward compatible change and micro version is connected with any internal change of the library.
set(LIBYANG_MAJOR_SOVERSION 1)
set(LIBYANG_MINOR_SOVERSION 6)
set(LIBYANG_MICRO_SOVERSION 7)
set(LIBYANG_MINOR_SOVERSION 7)
set(LIBYANG_MICRO_SOVERSION 11)
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})

# check the supported platform
if(NOT UNIX)
message(FATAL_ERROR "Only *nix like systems are supported.")
endif()

# set default build type if not specified by user
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
Expand Down Expand Up @@ -81,7 +90,8 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
else()
message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement or the \"__builtin_types_compatible_p\" built-in function.")
message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement"
" or the \"__builtin_types_compatible_p\" built-in function.")
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x")
set(COMPILER_PACKED_ATTR "")
endif()
Expand All @@ -93,9 +103,6 @@ configure_file(${PROJECT_SOURCE_DIR}/src/common.h.in ${PROJECT_BINARY_DIR}/src/c
set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")

# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

# setup bindings
set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.")
set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
Expand Down Expand Up @@ -132,11 +139,6 @@ endif()
# static build requires static libpcre library
option(ENABLE_STATIC "Build static (.a) library" OFF)

# check the supported platform
if(NOT UNIX)
message(FATAL_ERROR "Only *nix like systems are supported.")
endif()

set(libsrc
src/common.c
src/context.c
Expand Down Expand Up @@ -190,10 +192,8 @@ set(headers
src/xml.h
src/dict.h)

check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF)
if(HAVE_VDPRINTF)
add_definitions(-DHAVE_VDPRINTF)
endif(HAVE_VDPRINTF)
# link compat
use_compat()

# create static libyang library
if(ENABLE_STATIC)
Expand All @@ -202,7 +202,7 @@ if(ENABLE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
add_library(yang STATIC ${libsrc})
add_library(yang STATIC ${libsrc} $<TARGET_OBJECTS:compat>)

# switch off the tests
if(ENABLE_BUILD_TESTS)
Expand All @@ -217,7 +217,7 @@ if(ENABLE_STATIC)
else()
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_library(yangobj OBJECT ${libsrc})
add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
add_library(yang SHARED $<TARGET_OBJECTS:yangobj> $<TARGET_OBJECTS:compat>)

#only for tests with visible internal symbols
add_library(yangobj_tests OBJECT ${libsrc})
Expand All @@ -226,7 +226,7 @@ else()
target_link_libraries(yang ${CMAKE_DL_LIBS})

set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
endif(ENABLE_STATIC)
endif()

set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION})

Expand Down Expand Up @@ -296,7 +296,7 @@ if(ENABLE_BUILD_TESTS)
if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
list(APPEND EXTENSIONS_LIST "libyang_ext_test")
endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
endif(ENABLE_BUILD_TESTS)
endif()

if(ENABLE_STATIC)
set(EXTENSIONS_LIST_SIZE " 0 ")
Expand Down Expand Up @@ -330,18 +330,18 @@ if(ENABLE_STATIC)
set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}")
else()
add_subdirectory(src/user_types)
endif(ENABLE_STATIC)
endif()

configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h)

# yanglint
add_executable(yanglint ${lintsrc})
add_executable(yanglint ${lintsrc} $<TARGET_OBJECTS:compat>)
target_link_libraries(yanglint yang)
install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)

#yangre
add_executable(yangre ${resrc})
add_executable(yangre ${resrc} $<TARGET_OBJECTS:compat>)
target_link_libraries(yangre yang)
install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${PROJECT_SOURCE_DIR}/tools/re/yangre.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
Expand All @@ -367,11 +367,11 @@ if(ENABLE_BUILD_TESTS)
message(STATUS "Disabling tests because of missing CMocka")
set(ENABLE_BUILD_TESTS NO)
endif(CMOCKA_FOUND)
endif(ENABLE_BUILD_TESTS)
endif()

if(ENABLE_BUILD_FUZZ_TARGETS)
add_subdirectory(tests/fuzz)
endif(ENABLE_BUILD_FUZZ_TARGETS)
endif()

if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
add_subdirectory(swig)
Expand Down
25 changes: 25 additions & 0 deletions CMakeModules/UseCompat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 2.8.12)

include(CheckSymbolExists)
include(TestBigEndian)

macro(USE_COMPAT)
# compatibility checks
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF)
check_symbol_exists(asprintf "stdio.h" HAVE_ASPRINTF)
check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF)

check_symbol_exists(get_current_dir_name "unistd.h" HAVE_GET_CURRENT_DIR_NAME)

check_symbol_exists(strndup "string.h" HAVE_STRNDUP)
check_symbol_exists(getline "stdio.h" HAVE_GETLINE)

TEST_BIG_ENDIAN(IS_BIG_ENDIAN)

# header and object file
configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat.h @ONLY)
include_directories(${PROJECT_BINARY_DIR})
add_library(compat OBJECT ${PROJECT_SOURCE_DIR}/compat/compat.c)
endmacro()
11 changes: 11 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ $ LIBYANG_EXTENSIONS_PLUGINS_DIR=`pwd`/src/extensions ./yanglint
$ LIBYANG_USER_TYPES_PLUGINS_DIR=`pwd`/src/user_types
```
However, user types are not required for yanglint(1) to run properly.

__Q: error (or similar) is printed:__
```
Regular expression "<exp>" is not valid ("<exp>": support for \P, \p, and \X has not been compiled).
```

__A:__ libyang uses *PCRE* library (not *PCRE2*) for regular expression parsing
and evaluation. This error is printed because the locally installed *PCRE*
library on your system is missing support for these regex atoms. It must
be explicitly allowed by compiling *PCRE* with `--enable-unicode-properties`
(more in its [README](https://www.pcre.org/original/readme.txt)).
133 changes: 133 additions & 0 deletions FindLibYANG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# - 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
#
# LIBYANG_CPP_FOUND - system has LibYANG C++ bindings
# LIBYANG_CPP_INCLUDE_DIRS - the LibYANG C++ include directory
# LIBYANG_CPP_LIBRARIES - Link these to use LibYANG C++ bindings
#
# Author Radek Krejci <[email protected]>
# Copyright (c) 2015 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_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_HEADER)
string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_HEADER}")
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 SYSREPO_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()

#C++ bindings
if (LIBYANG_CPP_LIBRARIES AND LIBYANG_CPP_INCLUDE_DIRS)
# in cache already
set(LIBYANG_CPP_FOUND TRUE)
else ()
find_path(LIBYANG_CPP_INCLUDE_DIR
NAMES
libyang/Libyang.hpp
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)

find_library(LIBYANG_CPP_LIBRARY
NAMES
yang-cpp
libyang-cpp
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_CPP_INCLUDE_DIR AND LIBYANG_CPP_LIBRARY)
set(LIBYANG_CPP_FOUND TRUE)
else ()
set(LIBYANG_CPP_FOUND FALSE)
endif ()

set(LIBYANG_CPP_INCLUDE_DIRS ${LIBYANG_CPP_INCLUDE_DIR})
set(LIBYANG_CPP_LIBRARIES ${LIBYANG_CPP_LIBRARY})

# show the LIBYANG_CPP_INCLUDE_DIRS and LIBYANG_CPP_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBYANG_CPP_INCLUDE_DIRS LIBYANG_CPP_LIBRARIES)
endif()
Loading

0 comments on commit b62d0a7

Please sign in to comment.