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