Skip to content

Commit 0798ebb

Browse files
committed
Merge branch 'devel'
2 parents 2ce1ce3 + 9d2da69 commit 0798ebb

File tree

249 files changed

+23028
-11199
lines changed

Some content is hidden

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

249 files changed

+23028
-11199
lines changed

.travis.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ matrix:
1010
dist: trusty
1111
sudo: required
1212
compiler: gcc
13+
addons:
14+
apt:
15+
sources:
16+
- ubuntu-toolchain-r-test
17+
packages:
18+
- g++-7
19+
env:
20+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
1321
- os: osx
1422
compiler: gcc
1523
allow_failures:
@@ -21,16 +29,20 @@ branches:
2129
- devel
2230

2331
before_install:
32+
- eval "${MATRIX_EVAL}"
2433
- git clone git://git.cryptomilk.org/projects/cmocka.git
2534
- cd cmocka && mkdir build && cd build
2635
- cmake .. && make -j2 && sudo make install
2736
- cd ../..
2837
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
29-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind osc; fi
38+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind osc; sudo dpkg -i ./swig/swig3.0_3.0.8-0ubuntu3_amd64.deb; fi
3039
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
3140

3241
script:
33-
- mkdir build && cd build && cmake .. && make -j2 && ctest --output-on-failure
42+
- mkdir build && cd build
43+
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake ..; fi
44+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON ..; fi
45+
- make -j2 && ctest --output-on-failure
3446
- cd -
3547

3648
after_success:

CMakeLists.txt

Lines changed: 116 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
22
project(libyang C)
33

44
include(GNUInstallDirs)
5+
include(CheckSymbolExists)
56

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

@@ -10,8 +11,8 @@ set(CMAKE_MACOSX_RPATH TRUE)
1011

1112
# set version
1213
set(LIBYANG_MAJOR_VERSION 0)
13-
set(LIBYANG_MINOR_VERSION 14)
14-
set(LIBYANG_MICRO_VERSION 81)
14+
set(LIBYANG_MINOR_VERSION 15)
15+
set(LIBYANG_MICRO_VERSION 119)
1516
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
1617
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION})
1718

@@ -20,7 +21,7 @@ if(NOT CMAKE_BUILD_TYPE)
2021
set(CMAKE_BUILD_TYPE debug)
2122
endif()
2223

23-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
24+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=gnu11")
2425
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
2526
set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
2627
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
@@ -35,7 +36,8 @@ else()
3536
endif()
3637
option(ENABLE_CALLGRIND_TESTS "Build performance tests to be run with callgrind" OFF)
3738
option(ENABLE_LATEST_REVISIONS "Enable reusing of latest revisions of schemas" ON)
38-
option(ENABLE_CACHE "Enable data caching for schemas (time-efficient at the cost of increased space-complexity)" OFF)
39+
option(ENABLE_CACHE "Enable data caching for schemas (time-efficient at the cost of increased space-complexity)" ON)
40+
set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang" CACHE STRING "Directory with libyang plugins (extensions and user types)")
3941

4042
if (ENABLE_LATEST_REVISIONS)
4143
set(ENABLE_LATEST_REVISIONS_MACRO "/**\n * @brief Latest revisions of loaded schemas will be reused.\n */\n#define LY_ENABLED_LATEST_REVISIONS")
@@ -49,15 +51,32 @@ else()
4951
set(ENABLE_CACHE_MACRO "/**\n * @brief Cache of some temporary information will not be used.\n */")
5052
endif()
5153

54+
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
55+
# require at least gcc 4.9
56+
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
57+
message(FATAL_ERROR "GCC version must be at least 4.9!")
58+
endif()
59+
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
60+
set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
61+
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
62+
# require at least clang 3.0
63+
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
64+
message(FATAL_ERROR "Clang version must be at least 3.0!")
65+
endif()
66+
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
67+
set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
68+
else()
69+
message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement.")
70+
set(COMPILER_UNUSED_ATTR "UNUSED_ ## x")
71+
set(COMPILER_PACKED_ATTR "")
72+
endif()
73+
5274
include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src)
5375
configure_file(${PROJECT_SOURCE_DIR}/src/libyang.h.in ${PROJECT_BINARY_DIR}/src/libyang.h @ONLY)
76+
configure_file(${PROJECT_SOURCE_DIR}/src/common.h.in ${PROJECT_BINARY_DIR}/src/common.h @ONLY)
5477

55-
if(PLUGINS_DIR)
56-
set(LIBYANG_EXT_PLUGINS_DIR ${PLUGINS_DIR})
57-
else()
58-
set(LIBYANG_EXT_PLUGINS_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang)
59-
endif()
60-
configure_file(${PROJECT_SOURCE_DIR}/src/extensions_config.h.in ${PROJECT_BINARY_DIR}/src/extensions_config.h)
78+
set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
79+
set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
6180

6281
# include custom Modules
6382
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
@@ -72,9 +91,9 @@ set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.")
7291

7392
find_package(FLEX)
7493
find_package(BISON)
75-
find_program (DEB_BUILDER NAMES debuild)
76-
find_program (RPM_BUILDER NAMES rpmbuild)
77-
find_program (SED_TOOL NAMES sed)
94+
find_program(DEB_BUILDER NAMES debuild)
95+
find_program(RPM_BUILDER NAMES rpmbuild)
96+
find_program(SED_TOOL NAMES sed)
7897

7998
if(NOT BISON_FOUND)
8099
message(WARNING "Missing Bison.\nYou won't be able to generate source codes from changed flex/bison files.\nCompiling libyang should still works fine.")
@@ -115,11 +134,13 @@ endif()
115134

116135
if ($ENV{TRAVIS_BRANCH} STREQUAL "master")
117136
set(PACKAGE_NAME "libyang")
137+
set(PACKAGE_PART_NAME "")
118138
set(BRANCH "master")
119139
set(BUILD_TYPE "Package")
120140
set(CONFLICT_PACKAGE_NAME "libyang-experimental")
121141
else ()
122142
set(PACKAGE_NAME "libyang-experimental")
143+
set(PACKAGE_PART_NAME "-experimental")
123144
set(BRANCH "devel")
124145
set(BUILD_TYPE "debug")
125146
set(CONFLICT_PACKAGE_NAME "libyang")
@@ -153,6 +174,10 @@ else ()
153174
configure_file(${PROJECT_SOURCE_DIR}/packages/local-rpm.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-rpm.sh @ONLY)
154175
endif()
155176

177+
# by default build shared library
178+
# static build requires static libpcre library
179+
option(ENABLE_STATIC "Build static (.a) library" OFF)
180+
156181
# check the supported platform
157182
if(NOT UNIX)
158183
message(FATAL_ERROR "Only *nix like systems are supported.")
@@ -162,7 +187,7 @@ set(libsrc
162187
src/common.c
163188
src/context.c
164189
src/log.c
165-
src/dict.c
190+
src/hash_table.c
166191
src/resolve.c
167192
src/validation.c
168193
src/xml.c
@@ -175,7 +200,7 @@ set(libsrc
175200
src/parser_yang.c
176201
src/tree_schema.c
177202
src/tree_data.c
178-
src/extensions.c
203+
src/plugins.c
179204
src/printer.c
180205
src/xpath.c
181206
src/printer_yang.c
@@ -204,27 +229,49 @@ set(headers
204229
src/tree_schema.h
205230
src/tree_data.h
206231
src/extensions.h
232+
src/user_types.h
207233
src/xml.h
208234
src/dict.h)
209235

210-
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
211-
add_library(yangobj OBJECT ${libsrc})
212-
add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
236+
check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
237+
if(HAVE_VDPRINTF)
238+
add_definitions(-DHAVE_VDPRINTF)
239+
endif(HAVE_VDPRINTF)
240+
241+
# create static libyang library
242+
if(ENABLE_STATIC)
243+
add_definitions(-DSTATIC)
244+
set(CMAKE_EXE_LINKER_FLAGS -static)
245+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
246+
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
247+
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
248+
add_library(yang STATIC ${libsrc})
249+
else()
250+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
251+
add_library(yangobj OBJECT ${libsrc})
252+
add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
253+
254+
#link dl
255+
target_link_libraries(yang ${CMAKE_DL_LIBS})
256+
endif(ENABLE_STATIC)
257+
213258
set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
214259
set_target_properties(yang PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
215260

216261
# link math
217262
target_link_libraries(yang m)
218263

219-
#link dl
220-
target_link_libraries(yang ${CMAKE_DL_LIBS})
221-
222264
# find pthreads
223265
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
224266
find_package(Threads REQUIRED)
225-
target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
267+
if(ENABLE_STATIC)
268+
target_link_libraries(yang -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive)
269+
else()
270+
target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
271+
endif(ENABLE_STATIC)
226272

227273
# find PCRE library
274+
unset(PCRE_LIBRARY CACHE)
228275
find_package(PCRE REQUIRED)
229276
include_directories(${PCRE_INCLUDE_DIRS})
230277
target_link_libraries(yang ${PCRE_LIBRARIES})
@@ -266,7 +313,50 @@ add_custom_target(cclean
266313
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
267314

268315
# YANG extensions plugins
269-
add_subdirectory(src/extensions)
316+
set(EXTENSIONS_LIST "nacm" "metadata" "yangdata")
317+
# if the tests are enabled, build libyang_ext_test
318+
if(ENABLE_BUILD_TESTS)
319+
find_package(CMocka 1.0.0)
320+
if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
321+
list(APPEND EXTENSIONS_LIST "libyang_ext_test")
322+
endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
323+
endif(ENABLE_BUILD_TESTS)
324+
325+
if(ENABLE_STATIC)
326+
set(EXTENSIONS_LIST_SIZE " 0 ")
327+
set(ITEM 0)
328+
foreach(EXTENSION ${EXTENSIONS_LIST})
329+
add_library(${EXTENSION} STATIC "src/extensions/${EXTENSION}.c")
330+
target_link_libraries(yang ${EXTENSION})
331+
set(EXTENSIONS_LIST_SIZE "${EXTENSIONS_LIST_SIZE} + lyext_size(${EXTENSION})")
332+
set(EXTERN_EXTENSIONS_LIST "${EXTERN_EXTENSIONS_LIST}extern struct lyext_plugin_list ${EXTENSION}[];\n")
333+
set(MEMCPY_EXTENSIONS_LIST "${MEMCPY_EXTENSIONS_LIST} lyext_add(plugin, count, ${EXTENSION});\n")
334+
set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${EXTENSION}\",")
335+
MATH(EXPR ITEM "${ITEM}+1")
336+
endforeach()
337+
else()
338+
add_subdirectory(src/extensions)
339+
endif(ENABLE_STATIC)
340+
341+
# YANG user types plugins ("user_ipv4" is just an example, not installed by default)
342+
set(USER_TYPE_LIST "user_date_and_time")
343+
if(ENABLE_STATIC)
344+
set(USER_TYPE_LIST_SIZE " 0 ")
345+
foreach(USER_TYPE ${USER_TYPE_LIST})
346+
add_library(${USER_TYPE} STATIC "src/user_types/${USER_TYPE}.c")
347+
target_link_libraries(yang ${USER_TYPE})
348+
set(USER_TYPE_LIST_SIZE "${USER_TYPE_LIST_SIZE} + lytype_size(${USER_TYPE})")
349+
set(EXTERN_USER_TYPE_LIST "${EXTERN_USER_TYPE_LIST}extern struct lytype_plugin_list ${USER_TYPE}[];\n")
350+
set(MEMCPY_USER_TYPE_LIST "${MEMCPY_USER_TYPE_LIST} lytype_add(plugin, count, ${USER_TYPE});\n")
351+
set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${USER_TYPE}\",")
352+
MATH(EXPR ITEM "${ITEM}+1")
353+
endforeach()
354+
set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}")
355+
else()
356+
add_subdirectory(src/user_types)
357+
endif(ENABLE_STATIC)
358+
359+
configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h)
270360

271361
# yanglint
272362
add_executable(yanglint ${lintsrc})
@@ -287,17 +377,15 @@ if(ENABLE_VALGRIND_TESTS)
287377
endif()
288378

289379
if(ENABLE_BUILD_TESTS)
290-
find_package(CMocka 1.0.0)
291380
if(CMOCKA_FOUND)
292381
enable_testing()
293382
add_subdirectory(tests)
383+
else(CMOCKA_FOUND)
384+
message(STATUS "Disabling tests because of missing CMocka")
385+
set(ENABLE_BUILD_TESTS NO)
294386
endif(CMOCKA_FOUND)
295387
endif(ENABLE_BUILD_TESTS)
296388

297389
if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
298390
add_subdirectory(swig)
299391
endif()
300-
301-
if(GEN_LANGUAGE_BINDINGS AND GEN_JAVASCRIPT_BINDINGS)
302-
include(swig/javascript/CMakeLists.txt)
303-
endif()

Doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ INPUT = @CMAKE_BINARY_DIR@/src/libyang.h \
785785
./src/tree_data.h \
786786
./src/tree_schema.h \
787787
./src/extensions.h \
788+
./src/user_types.h \
788789
./src/xml.h \
789790
./src/dict.h
790791

FAQ.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ __Q: error while loading shared libraries__
55
__A:__ libyang is installed into the directory detected by CMake's GNUInstallDirs
66
function. However, when it is connected with the installation prefix, the
77
target directory is not necessary the path used by the system linker. Check
8-
the linker's paths in `/etc/ld.so.conf.d/`. If the path where libyang is
8+
the linker's paths in `/etc/ld.so.conf.d/`. If the path where libyang is
99
installed is already present, just make `ldconfig` to rebuild its cache:
1010
```
1111
# ldconfig
@@ -15,7 +15,7 @@ __A:__ libyang is installed into the directory detected by CMake's GNUInstallDir
1515
```
1616
$ mkdir build; cd build
1717
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
18-
$ make
18+
$ make
1919
# make install
2020
```
2121
or add the libyang's location to the linker paths in `/etc/ld.so.conf.d` and
@@ -40,4 +40,9 @@ __A:__ To handle complex YANG extensions, libyang (and therefore yanglint(1))
4040
```
4141
$ LIBYANG_EXTENSIONS_PLUGINS_DIR=`pwd`/src/extensions ./yanglint
4242
```
43-
43+
The same issue occurs for user types and the solution is the same except they
44+
are built in `src/user_types/` subdirectory and the path should be set with:
45+
```
46+
$ LIBYANG_USER_TYPES_PLUGINS_DIR=`pwd`/src/user_types
47+
```
48+
However, user types are not required for yanglint(1) to run properly.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ master branch. If you want the latest code from the devel branch, install `libya
3737

3838
### Build Requirements
3939

40-
* C compiler (gcc, clang, ...)
41-
* cmake >= 2.8.9
40+
* C compiler (gcc >= 4.9, clang >= 3.0, ...)
41+
* cmake >= 2.8.12
4242
* libpcre (devel package)
4343
* note, that PCRE is supposed to be compiled with unicode support (configure's options
4444
`--enable-utf` and `--enable-unicode-properties`)

0 commit comments

Comments
 (0)