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