Skip to content

Commit b62d0a7

Browse files
committed
Merge branch 'devel'
2 parents 1b7d73d + 357fd20 commit b62d0a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1517
-824
lines changed

CMakeLists.txt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ endif()
77

88
project(libyang C)
99

10+
# include custom Modules
11+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
12+
1013
include(GNUInstallDirs)
1114
include(CheckSymbolExists)
15+
include(UseCompat)
1216

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

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

2731
# Version of the library
2832
# Major version is changed with every backward non-compatible API/ABI change in libyang, minor version changes
2933
# with backward compatible change and micro version is connected with any internal change of the library.
3034
set(LIBYANG_MAJOR_SOVERSION 1)
31-
set(LIBYANG_MINOR_SOVERSION 6)
32-
set(LIBYANG_MICRO_SOVERSION 7)
35+
set(LIBYANG_MINOR_SOVERSION 7)
36+
set(LIBYANG_MICRO_SOVERSION 11)
3337
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
3438
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})
3539

40+
# check the supported platform
41+
if(NOT UNIX)
42+
message(FATAL_ERROR "Only *nix like systems are supported.")
43+
endif()
44+
3645
# set default build type if not specified by user
3746
if(NOT CMAKE_BUILD_TYPE)
3847
set(CMAKE_BUILD_TYPE debug)
@@ -81,7 +90,8 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
8190
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
8291
set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
8392
else()
84-
message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement or the \"__builtin_types_compatible_p\" built-in function.")
93+
message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement"
94+
" or the \"__builtin_types_compatible_p\" built-in function.")
8595
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x")
8696
set(COMPILER_PACKED_ATTR "")
8797
endif()
@@ -93,9 +103,6 @@ configure_file(${PROJECT_SOURCE_DIR}/src/common.h.in ${PROJECT_BINARY_DIR}/src/c
93103
set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
94104
set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
95105

96-
# include custom Modules
97-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
98-
99106
# setup bindings
100107
set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.")
101108
set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
@@ -132,11 +139,6 @@ endif()
132139
# static build requires static libpcre library
133140
option(ENABLE_STATIC "Build static (.a) library" OFF)
134141

135-
# check the supported platform
136-
if(NOT UNIX)
137-
message(FATAL_ERROR "Only *nix like systems are supported.")
138-
endif()
139-
140142
set(libsrc
141143
src/common.c
142144
src/context.c
@@ -190,10 +192,8 @@ set(headers
190192
src/xml.h
191193
src/dict.h)
192194

193-
check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF)
194-
if(HAVE_VDPRINTF)
195-
add_definitions(-DHAVE_VDPRINTF)
196-
endif(HAVE_VDPRINTF)
195+
# link compat
196+
use_compat()
197197

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

207207
# switch off the tests
208208
if(ENABLE_BUILD_TESTS)
@@ -217,7 +217,7 @@ if(ENABLE_STATIC)
217217
else()
218218
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
219219
add_library(yangobj OBJECT ${libsrc})
220-
add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
220+
add_library(yang SHARED $<TARGET_OBJECTS:yangobj> $<TARGET_OBJECTS:compat>)
221221

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

228228
set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
229-
endif(ENABLE_STATIC)
229+
endif()
230230

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

@@ -296,7 +296,7 @@ if(ENABLE_BUILD_TESTS)
296296
if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
297297
list(APPEND EXTENSIONS_LIST "libyang_ext_test")
298298
endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
299-
endif(ENABLE_BUILD_TESTS)
299+
endif()
300300

301301
if(ENABLE_STATIC)
302302
set(EXTENSIONS_LIST_SIZE " 0 ")
@@ -330,18 +330,18 @@ if(ENABLE_STATIC)
330330
set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}")
331331
else()
332332
add_subdirectory(src/user_types)
333-
endif(ENABLE_STATIC)
333+
endif()
334334

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

337337
# yanglint
338-
add_executable(yanglint ${lintsrc})
338+
add_executable(yanglint ${lintsrc} $<TARGET_OBJECTS:compat>)
339339
target_link_libraries(yanglint yang)
340340
install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
341341
install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
342342

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

372372
if(ENABLE_BUILD_FUZZ_TARGETS)
373373
add_subdirectory(tests/fuzz)
374-
endif(ENABLE_BUILD_FUZZ_TARGETS)
374+
endif()
375375

376376
if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
377377
add_subdirectory(swig)

CMakeModules/UseCompat.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
3+
include(CheckSymbolExists)
4+
include(TestBigEndian)
5+
6+
macro(USE_COMPAT)
7+
# compatibility checks
8+
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
9+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
10+
check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF)
11+
check_symbol_exists(asprintf "stdio.h" HAVE_ASPRINTF)
12+
check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF)
13+
14+
check_symbol_exists(get_current_dir_name "unistd.h" HAVE_GET_CURRENT_DIR_NAME)
15+
16+
check_symbol_exists(strndup "string.h" HAVE_STRNDUP)
17+
check_symbol_exists(getline "stdio.h" HAVE_GETLINE)
18+
19+
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
20+
21+
# header and object file
22+
configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat.h @ONLY)
23+
include_directories(${PROJECT_BINARY_DIR})
24+
add_library(compat OBJECT ${PROJECT_SOURCE_DIR}/compat/compat.c)
25+
endmacro()

FAQ.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ $ LIBYANG_EXTENSIONS_PLUGINS_DIR=`pwd`/src/extensions ./yanglint
4646
$ LIBYANG_USER_TYPES_PLUGINS_DIR=`pwd`/src/user_types
4747
```
4848
However, user types are not required for yanglint(1) to run properly.
49+
50+
__Q: error (or similar) is printed:__
51+
```
52+
Regular expression "<exp>" is not valid ("<exp>": support for \P, \p, and \X has not been compiled).
53+
```
54+
55+
__A:__ libyang uses *PCRE* library (not *PCRE2*) for regular expression parsing
56+
and evaluation. This error is printed because the locally installed *PCRE*
57+
library on your system is missing support for these regex atoms. It must
58+
be explicitly allowed by compiling *PCRE* with `--enable-unicode-properties`
59+
(more in its [README](https://www.pcre.org/original/readme.txt)).

FindLibYANG.cmake

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# - Try to find LibYANG
2+
# Once done this will define
3+
#
4+
# LIBYANG_FOUND - system has LibYANG
5+
# LIBYANG_INCLUDE_DIRS - the LibYANG include directory
6+
# LIBYANG_LIBRARIES - Link these to use LibYANG
7+
# LIBYANG_VERSION - SO version of the found libyang library
8+
#
9+
# LIBYANG_CPP_FOUND - system has LibYANG C++ bindings
10+
# LIBYANG_CPP_INCLUDE_DIRS - the LibYANG C++ include directory
11+
# LIBYANG_CPP_LIBRARIES - Link these to use LibYANG C++ bindings
12+
#
13+
# Author Radek Krejci <[email protected]>
14+
# Copyright (c) 2015 CESNET, z.s.p.o.
15+
#
16+
# Redistribution and use in source and binary forms, with or without
17+
# modification, are permitted provided that the following conditions
18+
# are met:
19+
#
20+
# 1. Redistributions of source code must retain the copyright
21+
# notice, this list of conditions and the following disclaimer.
22+
# 2. Redistributions in binary form must reproduce the copyright
23+
# notice, this list of conditions and the following disclaimer in the
24+
# documentation and/or other materials provided with the distribution.
25+
# 3. The name of the author may not be used to endorse or promote products
26+
# derived from this software without specific prior written permission.
27+
#
28+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
#
39+
include(FindPackageHandleStandardArgs)
40+
41+
if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
42+
# in cache already
43+
set(LIBYANG_FOUND TRUE)
44+
else()
45+
find_path(LIBYANG_INCLUDE_DIR
46+
NAMES
47+
libyang/libyang.h
48+
PATHS
49+
/usr/include
50+
/usr/local/include
51+
/opt/local/include
52+
/sw/include
53+
${CMAKE_INCLUDE_PATH}
54+
${CMAKE_INSTALL_PREFIX}/include
55+
)
56+
57+
find_library(LIBYANG_LIBRARY
58+
NAMES
59+
yang
60+
libyang
61+
PATHS
62+
/usr/lib
63+
/usr/lib64
64+
/usr/local/lib
65+
/usr/local/lib64
66+
/opt/local/lib
67+
/sw/lib
68+
${CMAKE_LIBRARY_PATH}
69+
${CMAKE_INSTALL_PREFIX}/lib
70+
)
71+
72+
if(LIBYANG_INCLUDE_DIR)
73+
find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
74+
file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_HEADER)
75+
string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_HEADER}")
76+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
77+
endif()
78+
79+
set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
80+
set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
81+
mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
82+
83+
# handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE
84+
# if all listed variables are TRUE
85+
find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND
86+
REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR
87+
VERSION_VAR LIBYANG_VERSION)
88+
endif()
89+
90+
#C++ bindings
91+
if (LIBYANG_CPP_LIBRARIES AND LIBYANG_CPP_INCLUDE_DIRS)
92+
# in cache already
93+
set(LIBYANG_CPP_FOUND TRUE)
94+
else ()
95+
find_path(LIBYANG_CPP_INCLUDE_DIR
96+
NAMES
97+
libyang/Libyang.hpp
98+
PATHS
99+
/usr/include
100+
/usr/local/include
101+
/opt/local/include
102+
/sw/include
103+
${CMAKE_INCLUDE_PATH}
104+
${CMAKE_INSTALL_PREFIX}/include
105+
)
106+
107+
find_library(LIBYANG_CPP_LIBRARY
108+
NAMES
109+
yang-cpp
110+
libyang-cpp
111+
PATHS
112+
/usr/lib
113+
/usr/lib64
114+
/usr/local/lib
115+
/usr/local/lib64
116+
/opt/local/lib
117+
/sw/lib
118+
${CMAKE_LIBRARY_PATH}
119+
${CMAKE_INSTALL_PREFIX}/lib
120+
)
121+
122+
if (LIBYANG_CPP_INCLUDE_DIR AND LIBYANG_CPP_LIBRARY)
123+
set(LIBYANG_CPP_FOUND TRUE)
124+
else ()
125+
set(LIBYANG_CPP_FOUND FALSE)
126+
endif ()
127+
128+
set(LIBYANG_CPP_INCLUDE_DIRS ${LIBYANG_CPP_INCLUDE_DIR})
129+
set(LIBYANG_CPP_LIBRARIES ${LIBYANG_CPP_LIBRARY})
130+
131+
# show the LIBYANG_CPP_INCLUDE_DIRS and LIBYANG_CPP_LIBRARIES variables only in the advanced view
132+
mark_as_advanced(LIBYANG_CPP_INCLUDE_DIRS LIBYANG_CPP_LIBRARIES)
133+
endif()

0 commit comments

Comments
 (0)