blob: 9db72419e0659e3218aed52042d587018ce3f9cc [file] [log] [blame]
Radek Krejci2c22f122018-09-05 15:08:03 +02001cmake_minimum_required(VERSION 2.8.12)
Radek Krejcif8482c72019-04-04 10:10:47 +02002
3# force out-of-source build
4if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
5 message(FATAL_ERROR "In-source build is not allowed. Please make a standalone build directory and run CMake from there. You may need to remove CMakeCache.txt.")
6endif()
7
Radek Krejci2c22f122018-09-05 15:08:03 +02008project(libyang C)
9
10include(GNUInstallDirs)
11include(CheckSymbolExists)
12
13set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.")
14
15# Correct RPATH usage on OS X
16set(CMAKE_MACOSX_RPATH TRUE)
17
Radek Krejcia43d69d2019-04-04 10:34:46 +020018# set version of the project
19set(LIBYANG_MAJOR_VERSION 2)
Radek Krejci2c22f122018-09-05 15:08:03 +020020set(LIBYANG_MINOR_VERSION 0)
21set(LIBYANG_MICRO_VERSION 0)
22set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
Radek Krejcia43d69d2019-04-04 10:34:46 +020023# set version of the library
24set(LIBYANG_MAJOR_SOVERSION 2)
25set(LIBYANG_MINOR_SOVERSION 0)
26set(LIBYANG_MICRO_SOVERSION 0)
27set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
28set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})
Radek Krejci2c22f122018-09-05 15:08:03 +020029
30# set default build type if not specified by user
31if(NOT CMAKE_BUILD_TYPE)
32 set(CMAKE_BUILD_TYPE debug)
33endif()
34
Radek Krejci2c22f122018-09-05 15:08:03 +020035# options
Radek Krejcie84f12f2018-09-18 14:11:50 +020036if((CMAKE_BUILD_TYPE STREQUAL debug) OR (CMAKE_BUILD_TYPE STREQUAL Package))
37 option(ENABLE_BUILD_TESTS "Build tests" ON)
38 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
Radek Krejci290a6a52019-09-12 17:13:17 +020039 set(INTERNAL_DOCS YES)
Radek Krejcie84f12f2018-09-18 14:11:50 +020040else()
41 option(ENABLE_BUILD_TESTS "Build tests" OFF)
42 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
Radek Krejci290a6a52019-09-12 17:13:17 +020043 set(INTERNAL_DOCS NO)
Radek Krejcie84f12f2018-09-18 14:11:50 +020044endif()
Radek Krejcif3156102019-09-06 13:07:10 +020045option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +020046
47option(ENABLE_FUZZ_TARGETS "Build target programs suitable for fuzzing with AFL" OFF)
Radek Krejci2c22f122018-09-05 15:08:03 +020048#option(ENABLE_CALLGRIND_TESTS "Build performance tests to be run with callgrind" OFF)
49
50#option(ENABLE_CACHE "Enable data caching for schemas and hash tables for data (time-efficient at the cost of increased space-complexity)" ON)
51#option(ENABLE_LATEST_REVISIONS "Enable reusing of latest revisions of schemas" ON)
52#option(ENABLE_LYD_PRIV "Add a private pointer also to struct lyd_node (data node structure), just like in struct lys_node, for arbitrary user data" OFF)
53#set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang" CACHE STRING "Directory with libyang plugins (extensions and user types)")
54
55#if(ENABLE_CACHE)
56# set(LY_ENABLED_CACHE 1)
57#endif()
58#if(ENABLE_LATEST_REVISIONS)
59# set(LY_ENABLED_LATEST_REVISIONS 1)
60#endif()
61#if(ENABLE_LYD_PRIV)
62# set(LY_ENABLED_LYD_PRIV 1)
63#endif()
64
65if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
66 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
67 set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
68elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
69 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
70 set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
71else()
72 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x")
73 set(COMPILER_PACKED_ATTR "")
74endif()
75
Radek Krejci8c1054b2019-05-17 10:18:54 +020076if(ENABLE_COVERAGE)
77 find_program(PATH_GCOV NAMES gcov)
78 if(NOT PATH_GCOV)
79 message(WARNING "'gcov' executable not found! Disabling building code coverage report.")
80 set(ENABLE_COVERAGE OFF)
81 endif()
82
83 find_program(PATH_LCOV NAMES lcov)
84 if(NOT PATH_GCOV)
85 message(WARNING "'lcov' executable not found! Disabling building code coverage report.")
86 set(ENABLE_COVERAGE OFF)
87 endif()
88
89 find_program(PATH_GENHTML NAMES genhtml)
90 if(NOT PATH_GCOV)
91 message(WARNING "'genhtml' executable not found! Disabling building code coverage report.")
92 set(ENABLE_COVERAGE OFF)
93 endif()
94
95 if(NOT CMAKE_COMPILER_IS_GNUCC)
96 message(WARNING "Compiler is not gcc! Coverage may break the tests!")
97 endif()
98
99 if(ENABLE_COVERAGE)
100 set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
101 endif()
102endif()
103
104set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_COVERAGE} -Wall -Wextra -Wno-missing-field-initializers -std=c99")
105set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
106set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
107set(CMAKE_C_FLAGS_DEBUG "-g -O0")
108
Radek Krejcia9dc4ab2019-05-16 11:13:17 +0200109list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
110check_symbol_exists(get_current_dir_name unistd.h HAVE_GET_CURRENT_DIR_NAME)
111check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
112check_symbol_exists(strnstr string.h HAVE_STRNSTR)
113
Radek Krejci2c22f122018-09-05 15:08:03 +0200114include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src)
115configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY)
116
117#set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
118#set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
119
120# include custom Modules
121set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
122
123# setup bindings
124#set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.")
125#set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
126# Python bindings depend on C++ bindings because of SWIG
127#set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.")
128#set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version")
129#set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.")
130
131#find_program(DEB_BUILDER NAMES debuild)
132#find_program(RPM_BUILDER NAMES rpmbuild)
133
134#if (NOT DEFINED ENV{TRAVIS_BRANCH})
135# execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD"
136# OUTPUT_VARIABLE GIT_BRANCH
137# OUTPUT_STRIP_TRAILING_WHITESPACE
138# ERROR_QUIET
139# )
140# if (NOT GIT_BRANCH)
141# set(ENV{TRAVIS_BRANCH} "master")
142# else()
143# if (GIT_BRANCH MATCHES "master|devel")
144# set(ENV{TRAVIS_BRANCH} ${GIT_BRANCH})
145# else()
146# set(ENV{TRAVIS_BRANCH} "master")
147# endif()
148# endif()
149# set(GIT_BRANCH $ENV{TRAVIS_BRANCH})
150#endif()
151#
152#if ($ENV{TRAVIS_BRANCH} STREQUAL "master")
153# set(PACKAGE_NAME "libyang")
154# set(PACKAGE_PART_NAME "")
155# set(BRANCH "master")
156# set(BUILD_TYPE "Package")
157# set(CONFLICT_PACKAGE_NAME "libyang-experimental")
158#else ()
159# set(PACKAGE_NAME "libyang-experimental")
160# set(PACKAGE_PART_NAME "-experimental")
161# set(BRANCH "devel")
162# set(BUILD_TYPE "debug")
163# set(CONFLICT_PACKAGE_NAME "libyang")
164#endif()
165# change version in config files
166#configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.spec.in ${PROJECT_BINARY_DIR}/build-packages/libyang.spec)
167#configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.dsc.in ${PROJECT_BINARY_DIR}/build-packages/libyang.dsc)
168#configure_file(${PROJECT_SOURCE_DIR}/packages/debian.control.in ${PROJECT_BINARY_DIR}/build-packages/debian.control @ONLY)
169#configure_file(${PROJECT_SOURCE_DIR}/packages/debian.rules.in ${PROJECT_BINARY_DIR}/build-packages/debian.rules)
170
171#if (NOT DEB_BUILDER)
172# message(WARNING "Missing tools (devscripts, debhelper package) for building deb package.\nYou won't be able to generate deb package from source code.\nCompiling libyang should still works fine.")
173#else ()
174# # target for local build deb package
175# add_custom_target(build-deb
176# WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
177# COMMAND build-packages/local-deb.sh
178# )
179# configure_file(${PROJECT_SOURCE_DIR}/packages/local-deb.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-deb.sh @ONLY)
180#endif()
181
182#if (NOT RPM_BUILDER)
183# message(WARNING "Missing tools (rpm package) for building rpm package. \nYou won't be able to generate rpm package from source code.\nCompiling libyang should still works fine.")
184#else ()
185# # target for local build rpm package
186# string(REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR})
187# add_custom_target(build-rpm
188# WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
189# COMMAND build-packages/local-rpm.sh
190# )
191# configure_file(${PROJECT_SOURCE_DIR}/packages/local-rpm.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-rpm.sh @ONLY)
192#endif()
193
194# by default build shared library
Radek Krejci54579462019-04-30 12:47:06 +0200195# static build requires static libpcre2 library
Radek Krejci2c22f122018-09-05 15:08:03 +0200196option(ENABLE_STATIC "Build static (.a) library" OFF)
197
198# check the supported platform
199if(NOT UNIX)
200 message(FATAL_ERROR "Only *nix like systems are supported.")
201endif()
202
203set(libsrc
Michal Vasko1324b6c2018-09-07 11:16:23 +0200204 src/common.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200205 src/compat.c
Radek Krejci2c22f122018-09-05 15:08:03 +0200206 src/log.c
207 src/hash_table.c
Radek Krejciad573502018-09-07 15:26:55 +0200208 src/set.c
Michal Vasko004d3152020-06-11 19:59:22 +0200209 src/path.c
Radek Krejcid4557c62018-09-17 11:42:09 +0200210 src/context.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200211 src/tree_data.c
212 src/tree_data_free.c
213 src/tree_data_helpers.c
214 src/tree_data_hash.c
215 src/parser_xml.c
Michal Vasko90932a92020-02-12 14:33:03 +0100216 src/parser_json.c
Radek Krejcia5bba312020-01-09 15:41:20 +0100217 src/printer.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200218 src/printer_data.c
219 src/printer_xml.c
Radek Krejci13a57b62019-07-19 13:04:09 +0200220 src/printer_json.c
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200221 src/tree_schema.c
Radek Krejci19a96102018-11-15 13:38:09 +0100222 src/tree_schema_free.c
223 src/tree_schema_compile.c
Radek Krejci86d106e2018-10-18 09:53:19 +0200224 src/tree_schema_helpers.c
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200225 src/parser.c
Radek Krejcid91dbaf2018-09-21 15:51:39 +0200226 src/parser_yang.c
David Sedlák3b4db242018-10-19 16:11:01 +0200227 src/parser_yin.c
Radek Krejci335332a2019-09-05 13:03:35 +0200228 src/parser_stmt.c
Radek Krejcid3ca0632019-04-16 16:54:54 +0200229 src/printer.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200230 src/printer_schema.c
Radek Krejcid3ca0632019-04-16 16:54:54 +0200231 src/printer_yang.c
FredGand944bdc2019-11-05 21:57:07 +0800232 src/printer_yin.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200233 src/plugins_types.c
Radek Krejci0935f412019-08-20 16:15:18 +0200234 src/plugins_exts.c
Radek Krejcib1646a92018-11-02 16:08:26 +0100235 src/xml.c
Michal Vaskocde73ac2019-11-14 16:10:27 +0100236 src/xpath.c
237 src/validation.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200238
Radek Krejcied5acc52019-04-25 15:57:04 +0200239set(lintsrc
240 tools/lint/main.c
241 tools/lint/main_ni.c
242 tools/lint/commands.c
243 tools/lint/completion.c
244 tools/lint/configuration.c
245 tools/lint/linenoise/linenoise.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200246
Radek Krejci5819f7c2019-05-31 14:53:29 +0200247set(resrc
248 tools/re/main.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200249
Radek Krejci2c22f122018-09-05 15:08:03 +0200250set(headers
251 src/libyang.h
Radek Krejci6caa6ab2018-10-24 10:04:48 +0200252 src/context.h
Radek Krejcie7b95092019-05-15 11:03:07 +0200253 src/tree.h
254 src/tree_data.h
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200255 src/parser.h
256 src/parser_schema.h
257 src/plugins_exts.h
258 src/plugins_types.h
Radek Krejcia5bba312020-01-09 15:41:20 +0100259 src/printer.h
Radek Krejcie7b95092019-05-15 11:03:07 +0200260 src/printer_data.h
Radek Krejci2c22f122018-09-05 15:08:03 +0200261 src/tree_schema.h
Radek Krejcid3ca0632019-04-16 16:54:54 +0200262 src/printer_schema.h
Radek Krejci0935f412019-08-20 16:15:18 +0200263 src/plugins_exts.h
Radek Krejcie7b95092019-05-15 11:03:07 +0200264 src/plugins_types.h
Radek Krejci2c22f122018-09-05 15:08:03 +0200265 src/dict.h
266 src/log.h
Michal Vasko1324b6c2018-09-07 11:16:23 +0200267 src/set.h)
Radek Krejci2c22f122018-09-05 15:08:03 +0200268
Radek Krejci2c22f122018-09-05 15:08:03 +0200269# create static libyang library
270if(ENABLE_STATIC)
271 add_definitions(-DSTATIC)
272 set(CMAKE_EXE_LINKER_FLAGS -static)
273 set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
274 set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
275 set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
276 add_library(yang STATIC ${libsrc})
277else()
278 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
279 add_library(yangobj OBJECT ${libsrc})
280 add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
281
282 #link dl
283 target_link_libraries(yang ${CMAKE_DL_LIBS})
Michal Vasko90932a92020-02-12 14:33:03 +0100284
Juraj Vijtiukdd53e662019-11-15 13:35:33 +0100285 set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
Radek Krejci2c22f122018-09-05 15:08:03 +0200286endif(ENABLE_STATIC)
287
Radek Krejcia43d69d2019-04-04 10:34:46 +0200288set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION})
Radek Krejci2c22f122018-09-05 15:08:03 +0200289
290# link math
291target_link_libraries(yang m)
292
293# find pthreads
294set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
295find_package(Threads REQUIRED)
296if(ENABLE_STATIC)
297 target_link_libraries(yang -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive)
298else()
299 target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
300endif(ENABLE_STATIC)
301
Radek Krejci54579462019-04-30 12:47:06 +0200302# find PCRE2 library
303unset(PCRE2_LIBRARY CACHE)
Radek Krejcid9e68c42019-05-31 16:26:26 +0200304find_package(PCRE2 10.30 REQUIRED)
Radek Krejci54579462019-04-30 12:47:06 +0200305include_directories(${PCRE2_INCLUDE_DIRS})
306target_link_libraries(yang ${PCRE2_LIBRARIES})
Radek Krejci2c22f122018-09-05 15:08:03 +0200307
308install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR})
309install(FILES ${headers} ${PROJECT_BINARY_DIR}/src/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang)
310
311find_package(PkgConfig)
312if(PKG_CONFIG_FOUND)
313 # generate and install pkg-config file
314 configure_file("libyang.pc.in" "libyang.pc" @ONLY)
315 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
316 # check that pkg-config includes the used path
317 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET)
318 if(RETURN EQUAL 0)
319 string(STRIP "${PC_PATH}" PC_PATH)
320 set(PC_PATH "${PC_PATH}:$ENV{PKG_CONFIG_PATH}")
321 string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}")
322 string(LENGTH "${SUBSTR}" SUBSTR_LEN)
323 if(SUBSTR_LEN EQUAL 0)
324 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\".")
325 endif()
326 endif()
327endif()
328
329# generate doxygen documentation for libyang API
330find_package(Doxygen)
331if(DOXYGEN_FOUND)
332 find_program(DOT_PATH dot PATH_SUFFIXES graphviz2.38/bin graphviz/bin)
333 if(DOT_PATH)
334 set(HAVE_DOT "YES")
335 else()
336 set(HAVE_DOT "NO")
337 message(AUTHOR_WARNING "Doxygen: to generate UML diagrams please install graphviz")
338 endif()
339 add_custom_target(doc
340 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
341 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Radek Krejci2ff0d572020-05-21 15:27:28 +0200342 string(REPLACE ";" " " DOXY_HEADERS "${headers}")
Radek Krejci2c22f122018-09-05 15:08:03 +0200343 configure_file(Doxyfile.in Doxyfile)
344endif()
345
346# clean cmake cache
347add_custom_target(cclean
348 COMMAND make clean
349 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
350 COMMAND rm -rf Makefile Doxyfile
351 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
352
353# YANG extensions plugins
354#set(EXTENSIONS_LIST "nacm" "metadata" "yangdata")
355# if the tests are enabled, build libyang_ext_test
Radek Krejcie84f12f2018-09-18 14:11:50 +0200356if(ENABLE_BUILD_TESTS)
357 find_package(CMocka 1.0.0)
Radek Krejci2c22f122018-09-05 15:08:03 +0200358# if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
359# list(APPEND EXTENSIONS_LIST "libyang_ext_test")
360# endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
Radek Krejcie84f12f2018-09-18 14:11:50 +0200361endif(ENABLE_BUILD_TESTS)
Radek Krejci2c22f122018-09-05 15:08:03 +0200362
363#if(ENABLE_STATIC)
364# set(EXTENSIONS_LIST_SIZE " 0 ")
365# set(ITEM 0)
366# foreach(EXTENSION ${EXTENSIONS_LIST})
367# add_library(${EXTENSION} STATIC "src/extensions/${EXTENSION}.c")
368# target_link_libraries(yang ${EXTENSION})
369# set(EXTENSIONS_LIST_SIZE "${EXTENSIONS_LIST_SIZE} + lyext_size(${EXTENSION})")
370# set(EXTERN_EXTENSIONS_LIST "${EXTERN_EXTENSIONS_LIST}extern struct lyext_plugin_list ${EXTENSION}[];\n")
371# set(MEMCPY_EXTENSIONS_LIST "${MEMCPY_EXTENSIONS_LIST} lyext_add(plugin, count, ${EXTENSION});\n")
372# set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${EXTENSION}\",")
373# MATH(EXPR ITEM "${ITEM}+1")
374# endforeach()
375#else()
376# add_subdirectory(src/extensions)
377#endif(ENABLE_STATIC)
378
379# YANG user types plugins ("user_ipv4" is just an example, not installed by default)
380#set(USER_TYPE_LIST "user_date_and_time")
381#if(ENABLE_STATIC)
382# set(USER_TYPE_LIST_SIZE " 0 ")
383# foreach(USER_TYPE ${USER_TYPE_LIST})
384# add_library(${USER_TYPE} STATIC "src/user_types/${USER_TYPE}.c")
385# target_link_libraries(yang ${USER_TYPE})
386# set(USER_TYPE_LIST_SIZE "${USER_TYPE_LIST_SIZE} + lytype_size(${USER_TYPE})")
387# set(EXTERN_USER_TYPE_LIST "${EXTERN_USER_TYPE_LIST}extern struct lytype_plugin_list ${USER_TYPE}[];\n")
388# set(MEMCPY_USER_TYPE_LIST "${MEMCPY_USER_TYPE_LIST} lytype_add(plugin, count, ${USER_TYPE});\n")
389# set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${USER_TYPE}\",")
390# MATH(EXPR ITEM "${ITEM}+1")
391# endforeach()
392# set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}")
393#else()
394# add_subdirectory(src/user_types)
395#endif(ENABLE_STATIC)
396#
397#configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h)
398
Radek Krejcied5acc52019-04-25 15:57:04 +0200399# config file for tools
400configure_file(${PROJECT_SOURCE_DIR}/tools/config.h.in ${PROJECT_BINARY_DIR}/tools/config.h @ONLY)
401
Radek Krejci2c22f122018-09-05 15:08:03 +0200402# yanglint
Radek Krejcied5acc52019-04-25 15:57:04 +0200403add_executable(yanglint ${lintsrc})
404target_link_libraries(yanglint yang)
405install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
406install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
Radek Krejci535ea9f2020-05-29 16:01:05 +0200407target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR})
Radek Krejci2c22f122018-09-05 15:08:03 +0200408
Radek Krejci5819f7c2019-05-31 14:53:29 +0200409# yangre
410add_executable(yangre ${resrc})
411target_link_libraries(yangre yang)
412install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR})
Radek Krejci535ea9f2020-05-29 16:01:05 +0200413target_include_directories(yangre BEFORE PRIVATE ${PROJECT_BINARY_DIR})
Radek Krejci2c22f122018-09-05 15:08:03 +0200414
Radek Krejcie84f12f2018-09-18 14:11:50 +0200415if(ENABLE_VALGRIND_TESTS)
416 set(ENABLE_BUILD_TESTS ON)
417endif()
Radek Krejci2c22f122018-09-05 15:08:03 +0200418
Radek Krejcie84f12f2018-09-18 14:11:50 +0200419if(ENABLE_BUILD_TESTS)
420 if(CMOCKA_FOUND)
421 enable_testing()
422 add_subdirectory(tests)
423 else(CMOCKA_FOUND)
424 message(STATUS "Disabling tests because of missing CMocka")
425 set(ENABLE_BUILD_TESTS NO)
426 endif(CMOCKA_FOUND)
427endif(ENABLE_BUILD_TESTS)
Radek Krejci2c22f122018-09-05 15:08:03 +0200428
Juraj Vijtiuk04f71272019-08-07 06:49:00 -0400429if(ENABLE_FUZZ_TARGETS)
Juraj Vijtiuk260407e2020-03-18 10:32:13 +0100430 set(FUZZER "AFL" CACHE STRING "fuzzer type")
431 if(FUZZER STREQUAL "LibFuzzer")
432 if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
433 message(FATAL_ERROR "LibFuzzer works only with clang")
434 endif()
Radek Krejciab6b8ed2020-05-13 20:44:22 +0200435 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
Juraj Vijtiuk260407e2020-03-18 10:32:13 +0100436 endif()
Juraj Vijtiukf3939c92019-05-14 13:07:38 +0200437 add_subdirectory(tests/fuzz)
Juraj Vijtiuk04f71272019-08-07 06:49:00 -0400438endif(ENABLE_FUZZ_TARGETS)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +0200439
Radek Krejci2c22f122018-09-05 15:08:03 +0200440#if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
441# add_subdirectory(swig)
442#endif()
443