blob: 83dfafa6a72aa571bb1cb64d6308d01d37ccfe3b [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)
39else()
40 option(ENABLE_BUILD_TESTS "Build tests" OFF)
41 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
42endif()
Radek Krejcif3156102019-09-06 13:07:10 +020043option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +020044
45option(ENABLE_FUZZ_TARGETS "Build target programs suitable for fuzzing with AFL" OFF)
Radek Krejci2c22f122018-09-05 15:08:03 +020046#option(ENABLE_CALLGRIND_TESTS "Build performance tests to be run with callgrind" OFF)
47
48#option(ENABLE_CACHE "Enable data caching for schemas and hash tables for data (time-efficient at the cost of increased space-complexity)" ON)
49#option(ENABLE_LATEST_REVISIONS "Enable reusing of latest revisions of schemas" ON)
50#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)
51#set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang" CACHE STRING "Directory with libyang plugins (extensions and user types)")
52
53#if(ENABLE_CACHE)
54# set(LY_ENABLED_CACHE 1)
55#endif()
56#if(ENABLE_LATEST_REVISIONS)
57# set(LY_ENABLED_LATEST_REVISIONS 1)
58#endif()
59#if(ENABLE_LYD_PRIV)
60# set(LY_ENABLED_LYD_PRIV 1)
61#endif()
62
63if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
64 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
65 set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
66elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
67 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))")
68 set(COMPILER_PACKED_ATTR "__attribute__((__packed__))")
69else()
70 set(COMPILER_UNUSED_ATTR "UNUSED_ ## x")
71 set(COMPILER_PACKED_ATTR "")
72endif()
73
Radek Krejci8c1054b2019-05-17 10:18:54 +020074if(ENABLE_COVERAGE)
75 find_program(PATH_GCOV NAMES gcov)
76 if(NOT PATH_GCOV)
77 message(WARNING "'gcov' executable not found! Disabling building code coverage report.")
78 set(ENABLE_COVERAGE OFF)
79 endif()
80
81 find_program(PATH_LCOV NAMES lcov)
82 if(NOT PATH_GCOV)
83 message(WARNING "'lcov' executable not found! Disabling building code coverage report.")
84 set(ENABLE_COVERAGE OFF)
85 endif()
86
87 find_program(PATH_GENHTML NAMES genhtml)
88 if(NOT PATH_GCOV)
89 message(WARNING "'genhtml' executable not found! Disabling building code coverage report.")
90 set(ENABLE_COVERAGE OFF)
91 endif()
92
93 if(NOT CMAKE_COMPILER_IS_GNUCC)
94 message(WARNING "Compiler is not gcc! Coverage may break the tests!")
95 endif()
96
97 if(ENABLE_COVERAGE)
98 set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
99 endif()
100endif()
101
102set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_COVERAGE} -Wall -Wextra -Wno-missing-field-initializers -std=c99")
103set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
104set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
105set(CMAKE_C_FLAGS_DEBUG "-g -O0")
106
Radek Krejcia9dc4ab2019-05-16 11:13:17 +0200107list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
108check_symbol_exists(get_current_dir_name unistd.h HAVE_GET_CURRENT_DIR_NAME)
109check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
110check_symbol_exists(strnstr string.h HAVE_STRNSTR)
111
Radek Krejci2c22f122018-09-05 15:08:03 +0200112include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src)
113configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY)
114
115#set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
116#set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
117
118# include custom Modules
119set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
120
121# setup bindings
122#set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.")
123#set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
124# Python bindings depend on C++ bindings because of SWIG
125#set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.")
126#set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version")
127#set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.")
128
129#find_program(DEB_BUILDER NAMES debuild)
130#find_program(RPM_BUILDER NAMES rpmbuild)
131
132#if (NOT DEFINED ENV{TRAVIS_BRANCH})
133# execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD"
134# OUTPUT_VARIABLE GIT_BRANCH
135# OUTPUT_STRIP_TRAILING_WHITESPACE
136# ERROR_QUIET
137# )
138# if (NOT GIT_BRANCH)
139# set(ENV{TRAVIS_BRANCH} "master")
140# else()
141# if (GIT_BRANCH MATCHES "master|devel")
142# set(ENV{TRAVIS_BRANCH} ${GIT_BRANCH})
143# else()
144# set(ENV{TRAVIS_BRANCH} "master")
145# endif()
146# endif()
147# set(GIT_BRANCH $ENV{TRAVIS_BRANCH})
148#endif()
149#
150#if ($ENV{TRAVIS_BRANCH} STREQUAL "master")
151# set(PACKAGE_NAME "libyang")
152# set(PACKAGE_PART_NAME "")
153# set(BRANCH "master")
154# set(BUILD_TYPE "Package")
155# set(CONFLICT_PACKAGE_NAME "libyang-experimental")
156#else ()
157# set(PACKAGE_NAME "libyang-experimental")
158# set(PACKAGE_PART_NAME "-experimental")
159# set(BRANCH "devel")
160# set(BUILD_TYPE "debug")
161# set(CONFLICT_PACKAGE_NAME "libyang")
162#endif()
163# change version in config files
164#configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.spec.in ${PROJECT_BINARY_DIR}/build-packages/libyang.spec)
165#configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.dsc.in ${PROJECT_BINARY_DIR}/build-packages/libyang.dsc)
166#configure_file(${PROJECT_SOURCE_DIR}/packages/debian.control.in ${PROJECT_BINARY_DIR}/build-packages/debian.control @ONLY)
167#configure_file(${PROJECT_SOURCE_DIR}/packages/debian.rules.in ${PROJECT_BINARY_DIR}/build-packages/debian.rules)
168
169#if (NOT DEB_BUILDER)
170# 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.")
171#else ()
172# # target for local build deb package
173# add_custom_target(build-deb
174# WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
175# COMMAND build-packages/local-deb.sh
176# )
177# configure_file(${PROJECT_SOURCE_DIR}/packages/local-deb.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-deb.sh @ONLY)
178#endif()
179
180#if (NOT RPM_BUILDER)
181# 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.")
182#else ()
183# # target for local build rpm package
184# string(REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR})
185# add_custom_target(build-rpm
186# WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
187# COMMAND build-packages/local-rpm.sh
188# )
189# configure_file(${PROJECT_SOURCE_DIR}/packages/local-rpm.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-rpm.sh @ONLY)
190#endif()
191
192# by default build shared library
Radek Krejci54579462019-04-30 12:47:06 +0200193# static build requires static libpcre2 library
Radek Krejci2c22f122018-09-05 15:08:03 +0200194option(ENABLE_STATIC "Build static (.a) library" OFF)
195
196# check the supported platform
197if(NOT UNIX)
198 message(FATAL_ERROR "Only *nix like systems are supported.")
199endif()
200
201set(libsrc
Michal Vasko1324b6c2018-09-07 11:16:23 +0200202 src/common.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200203 src/compat.c
Radek Krejci2c22f122018-09-05 15:08:03 +0200204 src/log.c
205 src/hash_table.c
Radek Krejciad573502018-09-07 15:26:55 +0200206 src/set.c
Radek Krejcid4557c62018-09-17 11:42:09 +0200207 src/context.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200208 src/tree_data.c
209 src/tree_data_free.c
210 src/tree_data_helpers.c
211 src/tree_data_hash.c
212 src/parser_xml.c
213 src/printer_data.c
214 src/printer_xml.c
Radek Krejci13a57b62019-07-19 13:04:09 +0200215 src/printer_json.c
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200216 src/tree_schema.c
Radek Krejci19a96102018-11-15 13:38:09 +0100217 src/tree_schema_free.c
218 src/tree_schema_compile.c
Radek Krejci86d106e2018-10-18 09:53:19 +0200219 src/tree_schema_helpers.c
Radek Krejcid91dbaf2018-09-21 15:51:39 +0200220 src/parser_yang.c
David Sedlák3b4db242018-10-19 16:11:01 +0200221 src/parser_yin.c
Radek Krejci335332a2019-09-05 13:03:35 +0200222 src/parser_stmt.c
Radek Krejcid3ca0632019-04-16 16:54:54 +0200223 src/printer.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200224 src/printer_schema.c
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225 src/printer_yang.c
Radek Krejcie7b95092019-05-15 11:03:07 +0200226 src/plugins_types.c
Radek Krejci0935f412019-08-20 16:15:18 +0200227 src/plugins_exts.c
Radek Krejcib1646a92018-11-02 16:08:26 +0100228 src/xml.c
229 src/xpath.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200230
Radek Krejcied5acc52019-04-25 15:57:04 +0200231set(lintsrc
232 tools/lint/main.c
233 tools/lint/main_ni.c
234 tools/lint/commands.c
235 tools/lint/completion.c
236 tools/lint/configuration.c
237 tools/lint/linenoise/linenoise.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200238
Radek Krejci5819f7c2019-05-31 14:53:29 +0200239set(resrc
240 tools/re/main.c)
Radek Krejci2c22f122018-09-05 15:08:03 +0200241
Radek Krejci2c22f122018-09-05 15:08:03 +0200242set(headers
243 src/libyang.h
Radek Krejci6caa6ab2018-10-24 10:04:48 +0200244 src/context.h
Radek Krejcie7b95092019-05-15 11:03:07 +0200245 src/tree.h
246 src/tree_data.h
247 src/printer_data.h
Radek Krejci2c22f122018-09-05 15:08:03 +0200248 src/tree_schema.h
Radek Krejcid3ca0632019-04-16 16:54:54 +0200249 src/printer_schema.h
Radek Krejci0935f412019-08-20 16:15:18 +0200250 src/plugins_exts.h
Radek Krejcie7b95092019-05-15 11:03:07 +0200251 src/plugins_types.h
Radek Krejci2c22f122018-09-05 15:08:03 +0200252 src/dict.h
253 src/log.h
Michal Vasko1324b6c2018-09-07 11:16:23 +0200254 src/set.h)
Radek Krejci2c22f122018-09-05 15:08:03 +0200255
Radek Krejci2c22f122018-09-05 15:08:03 +0200256# create static libyang library
257if(ENABLE_STATIC)
258 add_definitions(-DSTATIC)
259 set(CMAKE_EXE_LINKER_FLAGS -static)
260 set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
261 set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
262 set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
263 add_library(yang STATIC ${libsrc})
264else()
265 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
266 add_library(yangobj OBJECT ${libsrc})
267 add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
268
269 #link dl
270 target_link_libraries(yang ${CMAKE_DL_LIBS})
271endif(ENABLE_STATIC)
272
Radek Krejcia43d69d2019-04-04 10:34:46 +0200273set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION})
Radek Krejcif3f47842018-11-15 11:22:15 +0100274set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
Radek Krejci2c22f122018-09-05 15:08:03 +0200275
276# link math
277target_link_libraries(yang m)
278
279# find pthreads
280set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
281find_package(Threads REQUIRED)
282if(ENABLE_STATIC)
283 target_link_libraries(yang -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive)
284else()
285 target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
286endif(ENABLE_STATIC)
287
Radek Krejci54579462019-04-30 12:47:06 +0200288# find PCRE2 library
289unset(PCRE2_LIBRARY CACHE)
Radek Krejcid9e68c42019-05-31 16:26:26 +0200290find_package(PCRE2 10.30 REQUIRED)
Radek Krejci54579462019-04-30 12:47:06 +0200291include_directories(${PCRE2_INCLUDE_DIRS})
292target_link_libraries(yang ${PCRE2_LIBRARIES})
Radek Krejci2c22f122018-09-05 15:08:03 +0200293
294install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR})
295install(FILES ${headers} ${PROJECT_BINARY_DIR}/src/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang)
296
297find_package(PkgConfig)
298if(PKG_CONFIG_FOUND)
299 # generate and install pkg-config file
300 configure_file("libyang.pc.in" "libyang.pc" @ONLY)
301 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
302 # check that pkg-config includes the used path
303 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET)
304 if(RETURN EQUAL 0)
305 string(STRIP "${PC_PATH}" PC_PATH)
306 set(PC_PATH "${PC_PATH}:$ENV{PKG_CONFIG_PATH}")
307 string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}")
308 string(LENGTH "${SUBSTR}" SUBSTR_LEN)
309 if(SUBSTR_LEN EQUAL 0)
310 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\".")
311 endif()
312 endif()
313endif()
314
315# generate doxygen documentation for libyang API
316find_package(Doxygen)
317if(DOXYGEN_FOUND)
318 find_program(DOT_PATH dot PATH_SUFFIXES graphviz2.38/bin graphviz/bin)
319 if(DOT_PATH)
320 set(HAVE_DOT "YES")
321 else()
322 set(HAVE_DOT "NO")
323 message(AUTHOR_WARNING "Doxygen: to generate UML diagrams please install graphviz")
324 endif()
325 add_custom_target(doc
326 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
327 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
328 configure_file(Doxyfile.in Doxyfile)
329endif()
330
331# clean cmake cache
332add_custom_target(cclean
333 COMMAND make clean
334 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
335 COMMAND rm -rf Makefile Doxyfile
336 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
337
338# YANG extensions plugins
339#set(EXTENSIONS_LIST "nacm" "metadata" "yangdata")
340# if the tests are enabled, build libyang_ext_test
Radek Krejcie84f12f2018-09-18 14:11:50 +0200341if(ENABLE_BUILD_TESTS)
342 find_package(CMocka 1.0.0)
Radek Krejci2c22f122018-09-05 15:08:03 +0200343# if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
344# list(APPEND EXTENSIONS_LIST "libyang_ext_test")
345# endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug)
Radek Krejcie84f12f2018-09-18 14:11:50 +0200346endif(ENABLE_BUILD_TESTS)
Radek Krejci2c22f122018-09-05 15:08:03 +0200347
348#if(ENABLE_STATIC)
349# set(EXTENSIONS_LIST_SIZE " 0 ")
350# set(ITEM 0)
351# foreach(EXTENSION ${EXTENSIONS_LIST})
352# add_library(${EXTENSION} STATIC "src/extensions/${EXTENSION}.c")
353# target_link_libraries(yang ${EXTENSION})
354# set(EXTENSIONS_LIST_SIZE "${EXTENSIONS_LIST_SIZE} + lyext_size(${EXTENSION})")
355# set(EXTERN_EXTENSIONS_LIST "${EXTERN_EXTENSIONS_LIST}extern struct lyext_plugin_list ${EXTENSION}[];\n")
356# set(MEMCPY_EXTENSIONS_LIST "${MEMCPY_EXTENSIONS_LIST} lyext_add(plugin, count, ${EXTENSION});\n")
357# set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${EXTENSION}\",")
358# MATH(EXPR ITEM "${ITEM}+1")
359# endforeach()
360#else()
361# add_subdirectory(src/extensions)
362#endif(ENABLE_STATIC)
363
364# YANG user types plugins ("user_ipv4" is just an example, not installed by default)
365#set(USER_TYPE_LIST "user_date_and_time")
366#if(ENABLE_STATIC)
367# set(USER_TYPE_LIST_SIZE " 0 ")
368# foreach(USER_TYPE ${USER_TYPE_LIST})
369# add_library(${USER_TYPE} STATIC "src/user_types/${USER_TYPE}.c")
370# target_link_libraries(yang ${USER_TYPE})
371# set(USER_TYPE_LIST_SIZE "${USER_TYPE_LIST_SIZE} + lytype_size(${USER_TYPE})")
372# set(EXTERN_USER_TYPE_LIST "${EXTERN_USER_TYPE_LIST}extern struct lytype_plugin_list ${USER_TYPE}[];\n")
373# set(MEMCPY_USER_TYPE_LIST "${MEMCPY_USER_TYPE_LIST} lytype_add(plugin, count, ${USER_TYPE});\n")
374# set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${USER_TYPE}\",")
375# MATH(EXPR ITEM "${ITEM}+1")
376# endforeach()
377# set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}")
378#else()
379# add_subdirectory(src/user_types)
380#endif(ENABLE_STATIC)
381#
382#configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h)
383
Radek Krejcied5acc52019-04-25 15:57:04 +0200384# config file for tools
385configure_file(${PROJECT_SOURCE_DIR}/tools/config.h.in ${PROJECT_BINARY_DIR}/tools/config.h @ONLY)
386
Radek Krejci2c22f122018-09-05 15:08:03 +0200387# yanglint
Radek Krejcied5acc52019-04-25 15:57:04 +0200388add_executable(yanglint ${lintsrc})
389target_link_libraries(yanglint yang)
390install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
391install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
392target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}/tools)
Radek Krejci2c22f122018-09-05 15:08:03 +0200393
Radek Krejci5819f7c2019-05-31 14:53:29 +0200394# yangre
395add_executable(yangre ${resrc})
396target_link_libraries(yangre yang)
397install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR})
398target_include_directories(yangre BEFORE PRIVATE ${PROJECT_BINARY_DIR}/tools)
Radek Krejci2c22f122018-09-05 15:08:03 +0200399
Radek Krejcie84f12f2018-09-18 14:11:50 +0200400if(ENABLE_VALGRIND_TESTS)
401 set(ENABLE_BUILD_TESTS ON)
402endif()
Radek Krejci2c22f122018-09-05 15:08:03 +0200403
Radek Krejcie84f12f2018-09-18 14:11:50 +0200404if(ENABLE_BUILD_TESTS)
405 if(CMOCKA_FOUND)
406 enable_testing()
407 add_subdirectory(tests)
408 else(CMOCKA_FOUND)
409 message(STATUS "Disabling tests because of missing CMocka")
410 set(ENABLE_BUILD_TESTS NO)
411 endif(CMOCKA_FOUND)
412endif(ENABLE_BUILD_TESTS)
Radek Krejci2c22f122018-09-05 15:08:03 +0200413
Juraj Vijtiuk04f71272019-08-07 06:49:00 -0400414if(ENABLE_FUZZ_TARGETS)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +0200415 add_subdirectory(tests/fuzz)
Juraj Vijtiuk04f71272019-08-07 06:49:00 -0400416endif(ENABLE_FUZZ_TARGETS)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +0200417
Radek Krejci2c22f122018-09-05 15:08:03 +0200418#if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
419# add_subdirectory(swig)
420#endif()
421