Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
Radek Krejci | f8482c7 | 2019-04-04 10:10:47 +0200 | [diff] [blame] | 2 | |
| 3 | # force out-of-source build |
| 4 | if(${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.") |
| 6 | endif() |
| 7 | |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 8 | project(libyang C) |
| 9 | |
| 10 | include(GNUInstallDirs) |
| 11 | include(CheckSymbolExists) |
| 12 | |
| 13 | set(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 |
| 16 | set(CMAKE_MACOSX_RPATH TRUE) |
| 17 | |
Radek Krejci | a43d69d | 2019-04-04 10:34:46 +0200 | [diff] [blame] | 18 | # set version of the project |
| 19 | set(LIBYANG_MAJOR_VERSION 2) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 20 | set(LIBYANG_MINOR_VERSION 0) |
| 21 | set(LIBYANG_MICRO_VERSION 0) |
| 22 | set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION}) |
Radek Krejci | a43d69d | 2019-04-04 10:34:46 +0200 | [diff] [blame] | 23 | # set version of the library |
| 24 | set(LIBYANG_MAJOR_SOVERSION 2) |
| 25 | set(LIBYANG_MINOR_SOVERSION 0) |
| 26 | set(LIBYANG_MICRO_SOVERSION 0) |
| 27 | set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION}) |
| 28 | set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION}) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 29 | |
| 30 | # set default build type if not specified by user |
| 31 | if(NOT CMAKE_BUILD_TYPE) |
| 32 | set(CMAKE_BUILD_TYPE debug) |
| 33 | endif() |
| 34 | |
Radek Krejci | cad716e | 2018-11-26 15:18:27 +0100 | [diff] [blame] | 35 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers -std=c99") |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 36 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
| 37 | set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG") |
| 38 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 39 | |
| 40 | # options |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 41 | if((CMAKE_BUILD_TYPE STREQUAL debug) OR (CMAKE_BUILD_TYPE STREQUAL Package)) |
| 42 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 43 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
Radek Krejci | e8fb7dd | 2019-03-08 15:14:38 +0100 | [diff] [blame] | 44 | |
| 45 | if(CMAKE_COMPILER_IS_GNUCC) |
| 46 | option(ENABLE_COVERAGE "Build code coverage report from tests" ON) |
| 47 | else() |
| 48 | option(ENABLE_COVERAGE "Build code coverage report from tests" OFF) |
| 49 | endif() |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 50 | else() |
| 51 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 52 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
Radek Krejci | 6208cfa | 2019-03-08 14:43:58 +0100 | [diff] [blame] | 53 | option(ENABLE_COVERAGE "Build code coverage report from tests" OFF) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 54 | endif() |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 55 | #option(ENABLE_CALLGRIND_TESTS "Build performance tests to be run with callgrind" OFF) |
| 56 | |
| 57 | #option(ENABLE_CACHE "Enable data caching for schemas and hash tables for data (time-efficient at the cost of increased space-complexity)" ON) |
| 58 | #option(ENABLE_LATEST_REVISIONS "Enable reusing of latest revisions of schemas" ON) |
| 59 | #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) |
| 60 | #set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang" CACHE STRING "Directory with libyang plugins (extensions and user types)") |
| 61 | |
| 62 | #if(ENABLE_CACHE) |
| 63 | # set(LY_ENABLED_CACHE 1) |
| 64 | #endif() |
| 65 | #if(ENABLE_LATEST_REVISIONS) |
| 66 | # set(LY_ENABLED_LATEST_REVISIONS 1) |
| 67 | #endif() |
| 68 | #if(ENABLE_LYD_PRIV) |
| 69 | # set(LY_ENABLED_LYD_PRIV 1) |
| 70 | #endif() |
| 71 | |
| 72 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 73 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))") |
| 74 | set(COMPILER_PACKED_ATTR "__attribute__((__packed__))") |
| 75 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 76 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))") |
| 77 | set(COMPILER_PACKED_ATTR "__attribute__((__packed__))") |
| 78 | else() |
| 79 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x") |
| 80 | set(COMPILER_PACKED_ATTR "") |
| 81 | endif() |
| 82 | |
| 83 | include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src) |
| 84 | configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY) |
| 85 | |
| 86 | #set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions") |
| 87 | #set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types") |
| 88 | |
| 89 | # include custom Modules |
| 90 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
| 91 | |
| 92 | # setup bindings |
| 93 | #set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.") |
| 94 | #set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.") |
| 95 | # Python bindings depend on C++ bindings because of SWIG |
| 96 | #set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.") |
| 97 | #set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version") |
| 98 | #set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.") |
| 99 | |
| 100 | #find_program(DEB_BUILDER NAMES debuild) |
| 101 | #find_program(RPM_BUILDER NAMES rpmbuild) |
| 102 | |
| 103 | #if (NOT DEFINED ENV{TRAVIS_BRANCH}) |
| 104 | # execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" |
| 105 | # OUTPUT_VARIABLE GIT_BRANCH |
| 106 | # OUTPUT_STRIP_TRAILING_WHITESPACE |
| 107 | # ERROR_QUIET |
| 108 | # ) |
| 109 | # if (NOT GIT_BRANCH) |
| 110 | # set(ENV{TRAVIS_BRANCH} "master") |
| 111 | # else() |
| 112 | # if (GIT_BRANCH MATCHES "master|devel") |
| 113 | # set(ENV{TRAVIS_BRANCH} ${GIT_BRANCH}) |
| 114 | # else() |
| 115 | # set(ENV{TRAVIS_BRANCH} "master") |
| 116 | # endif() |
| 117 | # endif() |
| 118 | # set(GIT_BRANCH $ENV{TRAVIS_BRANCH}) |
| 119 | #endif() |
| 120 | # |
| 121 | #if ($ENV{TRAVIS_BRANCH} STREQUAL "master") |
| 122 | # set(PACKAGE_NAME "libyang") |
| 123 | # set(PACKAGE_PART_NAME "") |
| 124 | # set(BRANCH "master") |
| 125 | # set(BUILD_TYPE "Package") |
| 126 | # set(CONFLICT_PACKAGE_NAME "libyang-experimental") |
| 127 | #else () |
| 128 | # set(PACKAGE_NAME "libyang-experimental") |
| 129 | # set(PACKAGE_PART_NAME "-experimental") |
| 130 | # set(BRANCH "devel") |
| 131 | # set(BUILD_TYPE "debug") |
| 132 | # set(CONFLICT_PACKAGE_NAME "libyang") |
| 133 | #endif() |
| 134 | # change version in config files |
| 135 | #configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.spec.in ${PROJECT_BINARY_DIR}/build-packages/libyang.spec) |
| 136 | #configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.dsc.in ${PROJECT_BINARY_DIR}/build-packages/libyang.dsc) |
| 137 | #configure_file(${PROJECT_SOURCE_DIR}/packages/debian.control.in ${PROJECT_BINARY_DIR}/build-packages/debian.control @ONLY) |
| 138 | #configure_file(${PROJECT_SOURCE_DIR}/packages/debian.rules.in ${PROJECT_BINARY_DIR}/build-packages/debian.rules) |
| 139 | |
| 140 | #if (NOT DEB_BUILDER) |
| 141 | # 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.") |
| 142 | #else () |
| 143 | # # target for local build deb package |
| 144 | # add_custom_target(build-deb |
| 145 | # WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 146 | # COMMAND build-packages/local-deb.sh |
| 147 | # ) |
| 148 | # configure_file(${PROJECT_SOURCE_DIR}/packages/local-deb.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-deb.sh @ONLY) |
| 149 | #endif() |
| 150 | |
| 151 | #if (NOT RPM_BUILDER) |
| 152 | # 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.") |
| 153 | #else () |
| 154 | # # target for local build rpm package |
| 155 | # string(REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR}) |
| 156 | # add_custom_target(build-rpm |
| 157 | # WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 158 | # COMMAND build-packages/local-rpm.sh |
| 159 | # ) |
| 160 | # configure_file(${PROJECT_SOURCE_DIR}/packages/local-rpm.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-rpm.sh @ONLY) |
| 161 | #endif() |
| 162 | |
| 163 | # by default build shared library |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 164 | # static build requires static libpcre2 library |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 165 | option(ENABLE_STATIC "Build static (.a) library" OFF) |
| 166 | |
| 167 | # check the supported platform |
| 168 | if(NOT UNIX) |
| 169 | message(FATAL_ERROR "Only *nix like systems are supported.") |
| 170 | endif() |
| 171 | |
| 172 | set(libsrc |
Michal Vasko | 1324b6c | 2018-09-07 11:16:23 +0200 | [diff] [blame] | 173 | src/common.c |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 174 | src/compat.c |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 175 | src/log.c |
| 176 | src/hash_table.c |
Radek Krejci | ad57350 | 2018-09-07 15:26:55 +0200 | [diff] [blame] | 177 | src/set.c |
Radek Krejci | d4557c6 | 2018-09-17 11:42:09 +0200 | [diff] [blame] | 178 | src/context.c |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 179 | src/tree_data.c |
| 180 | src/tree_data_free.c |
| 181 | src/tree_data_helpers.c |
| 182 | src/tree_data_hash.c |
| 183 | src/parser_xml.c |
| 184 | src/printer_data.c |
| 185 | src/printer_xml.c |
Radek Krejci | 3f5e3db | 2018-10-11 15:57:47 +0200 | [diff] [blame] | 186 | src/tree_schema.c |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 187 | src/tree_schema_free.c |
| 188 | src/tree_schema_compile.c |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 189 | src/tree_schema_helpers.c |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 190 | src/parser_yang.c |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 191 | src/printer.c |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 192 | src/printer_schema.c |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 193 | src/printer_yang.c |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 194 | src/plugins_types.c |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 195 | src/xml.c |
| 196 | src/xpath.c) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 197 | |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 198 | set(lintsrc |
| 199 | tools/lint/main.c |
| 200 | tools/lint/main_ni.c |
| 201 | tools/lint/commands.c |
| 202 | tools/lint/completion.c |
| 203 | tools/lint/configuration.c |
| 204 | tools/lint/linenoise/linenoise.c) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 205 | |
| 206 | #set(resrc |
| 207 | # tools/re/main.c) |
| 208 | |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 209 | set(headers |
| 210 | src/libyang.h |
Radek Krejci | 6caa6ab | 2018-10-24 10:04:48 +0200 | [diff] [blame] | 211 | src/context.h |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 212 | src/tree.h |
| 213 | src/tree_data.h |
| 214 | src/printer_data.h |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 215 | src/tree_schema.h |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 216 | src/printer_schema.h |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 217 | src/extensions.h |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 218 | src/plugins_types.h |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 219 | src/dict.h |
| 220 | src/log.h |
Michal Vasko | 1324b6c | 2018-09-07 11:16:23 +0200 | [diff] [blame] | 221 | src/set.h) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 222 | |
Radek Krejci | 665489b | 2019-04-18 15:07:58 +0200 | [diff] [blame] | 223 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 224 | check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF) |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 225 | check_symbol_exists(strnstr string.h HAVE_STRNSTR) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 226 | |
| 227 | # create static libyang library |
| 228 | if(ENABLE_STATIC) |
| 229 | add_definitions(-DSTATIC) |
| 230 | set(CMAKE_EXE_LINKER_FLAGS -static) |
| 231 | set(CMAKE_FIND_LIBRARY_SUFFIXES .a) |
| 232 | set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic |
| 233 | set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) |
| 234 | add_library(yang STATIC ${libsrc}) |
| 235 | else() |
| 236 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 237 | add_library(yangobj OBJECT ${libsrc}) |
| 238 | add_library(yang SHARED $<TARGET_OBJECTS:yangobj>) |
| 239 | |
| 240 | #link dl |
| 241 | target_link_libraries(yang ${CMAKE_DL_LIBS}) |
| 242 | endif(ENABLE_STATIC) |
| 243 | |
Radek Krejci | a43d69d | 2019-04-04 10:34:46 +0200 | [diff] [blame] | 244 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION}) |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 245 | set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 246 | |
| 247 | # link math |
| 248 | target_link_libraries(yang m) |
| 249 | |
| 250 | # find pthreads |
| 251 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 252 | find_package(Threads REQUIRED) |
| 253 | if(ENABLE_STATIC) |
| 254 | target_link_libraries(yang -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive) |
| 255 | else() |
| 256 | target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) |
| 257 | endif(ENABLE_STATIC) |
| 258 | |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 259 | # find PCRE2 library |
| 260 | unset(PCRE2_LIBRARY CACHE) |
| 261 | find_package(PCRE2 REQUIRED) |
| 262 | include_directories(${PCRE2_INCLUDE_DIRS}) |
| 263 | target_link_libraries(yang ${PCRE2_LIBRARIES}) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 264 | |
| 265 | install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 266 | install(FILES ${headers} ${PROJECT_BINARY_DIR}/src/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang) |
| 267 | |
| 268 | find_package(PkgConfig) |
| 269 | if(PKG_CONFIG_FOUND) |
| 270 | # generate and install pkg-config file |
| 271 | configure_file("libyang.pc.in" "libyang.pc" @ONLY) |
| 272 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 273 | # check that pkg-config includes the used path |
| 274 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) |
| 275 | if(RETURN EQUAL 0) |
| 276 | string(STRIP "${PC_PATH}" PC_PATH) |
| 277 | set(PC_PATH "${PC_PATH}:$ENV{PKG_CONFIG_PATH}") |
| 278 | string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}") |
| 279 | string(LENGTH "${SUBSTR}" SUBSTR_LEN) |
| 280 | if(SUBSTR_LEN EQUAL 0) |
| 281 | 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\".") |
| 282 | endif() |
| 283 | endif() |
| 284 | endif() |
| 285 | |
| 286 | # generate doxygen documentation for libyang API |
| 287 | find_package(Doxygen) |
| 288 | if(DOXYGEN_FOUND) |
| 289 | find_program(DOT_PATH dot PATH_SUFFIXES graphviz2.38/bin graphviz/bin) |
| 290 | if(DOT_PATH) |
| 291 | set(HAVE_DOT "YES") |
| 292 | else() |
| 293 | set(HAVE_DOT "NO") |
| 294 | message(AUTHOR_WARNING "Doxygen: to generate UML diagrams please install graphviz") |
| 295 | endif() |
| 296 | add_custom_target(doc |
| 297 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 298 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 299 | configure_file(Doxyfile.in Doxyfile) |
| 300 | endif() |
| 301 | |
| 302 | # clean cmake cache |
| 303 | add_custom_target(cclean |
| 304 | COMMAND make clean |
| 305 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} + |
| 306 | COMMAND rm -rf Makefile Doxyfile |
| 307 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 308 | |
| 309 | # YANG extensions plugins |
| 310 | #set(EXTENSIONS_LIST "nacm" "metadata" "yangdata") |
| 311 | # if the tests are enabled, build libyang_ext_test |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 312 | if(ENABLE_BUILD_TESTS) |
| 313 | find_package(CMocka 1.0.0) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 314 | # if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug) |
| 315 | # list(APPEND EXTENSIONS_LIST "libyang_ext_test") |
| 316 | # endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 317 | endif(ENABLE_BUILD_TESTS) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 318 | |
| 319 | #if(ENABLE_STATIC) |
| 320 | # set(EXTENSIONS_LIST_SIZE " 0 ") |
| 321 | # set(ITEM 0) |
| 322 | # foreach(EXTENSION ${EXTENSIONS_LIST}) |
| 323 | # add_library(${EXTENSION} STATIC "src/extensions/${EXTENSION}.c") |
| 324 | # target_link_libraries(yang ${EXTENSION}) |
| 325 | # set(EXTENSIONS_LIST_SIZE "${EXTENSIONS_LIST_SIZE} + lyext_size(${EXTENSION})") |
| 326 | # set(EXTERN_EXTENSIONS_LIST "${EXTERN_EXTENSIONS_LIST}extern struct lyext_plugin_list ${EXTENSION}[];\n") |
| 327 | # set(MEMCPY_EXTENSIONS_LIST "${MEMCPY_EXTENSIONS_LIST} lyext_add(plugin, count, ${EXTENSION});\n") |
| 328 | # set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${EXTENSION}\",") |
| 329 | # MATH(EXPR ITEM "${ITEM}+1") |
| 330 | # endforeach() |
| 331 | #else() |
| 332 | # add_subdirectory(src/extensions) |
| 333 | #endif(ENABLE_STATIC) |
| 334 | |
| 335 | # YANG user types plugins ("user_ipv4" is just an example, not installed by default) |
| 336 | #set(USER_TYPE_LIST "user_date_and_time") |
| 337 | #if(ENABLE_STATIC) |
| 338 | # set(USER_TYPE_LIST_SIZE " 0 ") |
| 339 | # foreach(USER_TYPE ${USER_TYPE_LIST}) |
| 340 | # add_library(${USER_TYPE} STATIC "src/user_types/${USER_TYPE}.c") |
| 341 | # target_link_libraries(yang ${USER_TYPE}) |
| 342 | # set(USER_TYPE_LIST_SIZE "${USER_TYPE_LIST_SIZE} + lytype_size(${USER_TYPE})") |
| 343 | # set(EXTERN_USER_TYPE_LIST "${EXTERN_USER_TYPE_LIST}extern struct lytype_plugin_list ${USER_TYPE}[];\n") |
| 344 | # set(MEMCPY_USER_TYPE_LIST "${MEMCPY_USER_TYPE_LIST} lytype_add(plugin, count, ${USER_TYPE});\n") |
| 345 | # set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${USER_TYPE}\",") |
| 346 | # MATH(EXPR ITEM "${ITEM}+1") |
| 347 | # endforeach() |
| 348 | # set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}") |
| 349 | #else() |
| 350 | # add_subdirectory(src/user_types) |
| 351 | #endif(ENABLE_STATIC) |
| 352 | # |
| 353 | #configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h) |
| 354 | |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 355 | # config file for tools |
| 356 | configure_file(${PROJECT_SOURCE_DIR}/tools/config.h.in ${PROJECT_BINARY_DIR}/tools/config.h @ONLY) |
| 357 | |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 358 | # yanglint |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 359 | add_executable(yanglint ${lintsrc}) |
| 360 | target_link_libraries(yanglint yang) |
| 361 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 362 | install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 363 | target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}/tools) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 364 | |
| 365 | #yangre |
| 366 | #add_executable(yangre ${resrc}) |
| 367 | #target_link_libraries(yangre yang) |
| 368 | #install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR}) |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 369 | #target_include_directories(yangre BEFORE PRIVATE ${PROJECT_BINARY_DIR}/tools) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 370 | |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 371 | if(ENABLE_VALGRIND_TESTS) |
| 372 | set(ENABLE_BUILD_TESTS ON) |
| 373 | endif() |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 374 | |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 375 | if(ENABLE_BUILD_TESTS) |
| 376 | if(CMOCKA_FOUND) |
| 377 | enable_testing() |
| 378 | add_subdirectory(tests) |
| 379 | else(CMOCKA_FOUND) |
| 380 | message(STATUS "Disabling tests because of missing CMocka") |
| 381 | set(ENABLE_BUILD_TESTS NO) |
| 382 | endif(CMOCKA_FOUND) |
| 383 | endif(ENABLE_BUILD_TESTS) |
Radek Krejci | 2c22f12 | 2018-09-05 15:08:03 +0200 | [diff] [blame] | 384 | |
| 385 | #if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS) |
| 386 | # add_subdirectory(swig) |
| 387 | #endif() |
| 388 | |