Radek Krejci | b0cd394 | 2017-04-07 13:31:30 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 2 | project(libyang C) |
| 3 | |
Jan Kundrát | 37df09e | 2016-11-04 15:42:08 +0100 | [diff] [blame] | 4 | include(GNUInstallDirs) |
| 5 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 6 | set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.") |
| 7 | |
Radek Krejci | b0cd394 | 2017-04-07 13:31:30 +0200 | [diff] [blame] | 8 | # Correct RPATH usage on OS X |
| 9 | set(CMAKE_MACOSX_RPATH TRUE) |
| 10 | |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 11 | # set version |
| 12 | set(LIBYANG_MAJOR_VERSION 0) |
Michal Vasko | 6b1cbb2 | 2018-01-19 16:00:31 +0100 | [diff] [blame] | 13 | set(LIBYANG_MINOR_VERSION 15) |
Michal Vasko | 3b6e14f | 2018-06-04 12:09:13 +0200 | [diff] [blame] | 14 | set(LIBYANG_MICRO_VERSION 117) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 15 | set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION}) |
| 16 | set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}) |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 17 | |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 18 | # set default build type if not specified by user |
| 19 | if(NOT CMAKE_BUILD_TYPE) |
| 20 | set(CMAKE_BUILD_TYPE debug) |
| 21 | endif() |
| 22 | |
Michal Vasko | 404aea2 | 2018-03-22 14:37:27 +0100 | [diff] [blame] | 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=gnu11") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 24 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
| 25 | set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG") |
| 26 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 27 | |
| 28 | # options |
| 29 | if((CMAKE_BUILD_TYPE STREQUAL debug) OR (CMAKE_BUILD_TYPE STREQUAL Package)) |
| 30 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 31 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 32 | else() |
| 33 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 34 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 35 | endif() |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 36 | option(ENABLE_CALLGRIND_TESTS "Build performance tests to be run with callgrind" OFF) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 37 | option(ENABLE_LATEST_REVISIONS "Enable reusing of latest revisions of schemas" ON) |
Michal Vasko | 288f9ce | 2018-04-25 13:52:46 +0200 | [diff] [blame] | 38 | option(ENABLE_CACHE "Enable data caching for schemas (time-efficient at the cost of increased space-complexity)" ON) |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 39 | set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libyang" CACHE STRING "Directory with libyang plugins (extensions and user types)") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 40 | |
| 41 | if (ENABLE_LATEST_REVISIONS) |
| 42 | set(ENABLE_LATEST_REVISIONS_MACRO "/**\n * @brief Latest revisions of loaded schemas will be reused.\n */\n#define LY_ENABLED_LATEST_REVISIONS") |
| 43 | else() |
| 44 | set(ENABLE_LATEST_REVISIONS_MACRO "/**\n * @brief Latest revisions of loaded schemas will not be reused and always reloaded.\n */") |
| 45 | endif() |
| 46 | |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 47 | if(ENABLE_CACHE) |
| 48 | set(ENABLE_CACHE_MACRO "/**\n * @brief Cache of some temporary information will be used.\n */\n#define LY_ENABLED_CACHE") |
| 49 | else() |
| 50 | set(ENABLE_CACHE_MACRO "/**\n * @brief Cache of some temporary information will not be used.\n */") |
| 51 | endif() |
| 52 | |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 53 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 54 | # require at least gcc 4.9 |
| 55 | if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) |
| 56 | message(FATAL_ERROR "GCC version must be at least 4.9!") |
| 57 | endif() |
| 58 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))") |
| 59 | set(COMPILER_PACKED_ATTR "__attribute__((__packed__))") |
| 60 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 61 | # require at least clang 3.0 |
| 62 | if (CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0) |
| 63 | message(FATAL_ERROR "Clang version must be at least 3.0!") |
| 64 | endif() |
Michal Vasko | 0e9b297 | 2018-03-26 11:53:29 +0200 | [diff] [blame] | 65 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x __attribute__((__unused__))") |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 66 | set(COMPILER_PACKED_ATTR "__attribute__((__packed__))") |
| 67 | else() |
| 68 | message(WARNING "You are using an unknown compiler, it must support C11 standard \"_Generic\" statement.") |
Michal Vasko | 0e9b297 | 2018-03-26 11:53:29 +0200 | [diff] [blame] | 69 | set(COMPILER_UNUSED_ATTR "UNUSED_ ## x") |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 70 | set(COMPILER_PACKED_ATTR "") |
| 71 | endif() |
| 72 | |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 73 | include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src) |
| 74 | configure_file(${PROJECT_SOURCE_DIR}/src/libyang.h.in ${PROJECT_BINARY_DIR}/src/libyang.h @ONLY) |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 75 | configure_file(${PROJECT_SOURCE_DIR}/src/common.h.in ${PROJECT_BINARY_DIR}/src/common.h @ONLY) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 76 | |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 77 | set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions") |
| 78 | set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types") |
Radek Krejci | 858ad95 | 2017-01-04 11:16:32 +0100 | [diff] [blame] | 79 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 80 | # include custom Modules |
Radek Krejci | 977c1c8 | 2015-09-01 15:18:03 +0200 | [diff] [blame] | 81 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 82 | |
Mislav Novakovic | edc6c08 | 2017-05-30 15:21:42 +0200 | [diff] [blame] | 83 | # setup bindings |
| 84 | set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.") |
| 85 | set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.") |
| 86 | # Python bindings depend on C++ bindings because of SWIG |
| 87 | set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.") |
| 88 | set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version") |
| 89 | set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.") |
| 90 | |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 91 | find_package(FLEX) |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 92 | find_package(BISON) |
Michal Vasko | aa515e8 | 2018-03-23 08:45:19 +0100 | [diff] [blame] | 93 | find_program(DEB_BUILDER NAMES debuild) |
| 94 | find_program(RPM_BUILDER NAMES rpmbuild) |
| 95 | find_program(SED_TOOL NAMES sed) |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 96 | |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 97 | if(NOT BISON_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 98 | message(WARNING "Missing Bison.\nYou won't be able to generate source codes from changed flex/bison files.\nCompiling libyang should still works fine.") |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 99 | elseif (NOT FLEX_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 100 | message(WARNING "Missing Flex.\nYou won't be able to generate source codes from changed flex/bison files.\nCompiling libyang should still works fine.") |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 101 | else() |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 102 | if (BISON_VERSION VERSION_LESS 3) |
| 103 | set(EMPTYDIR "") |
| 104 | else () |
| 105 | set(EMPTYDIR "%empty") |
| 106 | endif() |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 107 | configure_file(${PROJECT_SOURCE_DIR}/src/yang.y.in ${PROJECT_BINARY_DIR}/src/yang.y) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 108 | add_custom_target(bison |
| 109 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src |
Radek Krejci | f2dc9c3 | 2017-10-27 14:17:52 +0200 | [diff] [blame] | 110 | COMMAND bison -l -o parser_yang_bis.c --defines=parser_yang_bis.h ${PROJECT_BINARY_DIR}/src/yang.y |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 111 | COMMAND flex -8 -L -o parser_yang_lex.c --header-file=parser_yang_lex.h yang.l |
| 112 | COMMAND ${SED_TOOL} -i 's/int yychar\;/int yychar\;\\nchar *s = NULL, *tmp_s = NULL, *ext_name = NULL\;\\nstruct lys_module *trg = NULL\;\\nstruct lys_node *tpdf_parent = NULL, *data_node = NULL\;\\nstruct lys_ext_instance_complex *ext_instance = NULL\;\\nint is_ext_instance\;\\nvoid *actual = NULL\;\\nenum yytokentype backup_type, actual_type = MODULE_KEYWORD\;\\nint64_t cnt_val = 0\;\\nint is_value = 0\;\\nvoid *yang_type = NULL\;/' parser_yang_bis.c |
| 113 | ) |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 114 | endif() |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 115 | |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 116 | if (NOT DEFINED ENV{TRAVIS_BRANCH}) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 117 | execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" |
| 118 | OUTPUT_VARIABLE GIT_BRANCH |
| 119 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 120 | ERROR_QUIET |
| 121 | ) |
| 122 | if (NOT GIT_BRANCH) |
| 123 | set(ENV{TRAVIS_BRANCH} "master") |
| 124 | else() |
| 125 | if (GIT_BRANCH MATCHES "master|devel") |
| 126 | set(ENV{TRAVIS_BRANCH} ${GIT_BRANCH}) |
| 127 | else() |
| 128 | set(ENV{TRAVIS_BRANCH} "master") |
| 129 | endif() |
| 130 | endif() |
| 131 | set(GIT_BRANCH $ENV{TRAVIS_BRANCH}) |
PavolVican | 3739627 | 2017-03-25 00:57:20 +0100 | [diff] [blame] | 132 | endif() |
| 133 | |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 134 | if ($ENV{TRAVIS_BRANCH} STREQUAL "master") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 135 | set(PACKAGE_NAME "libyang") |
PavolVican | 8738eee | 2018-02-27 01:47:02 +0100 | [diff] [blame] | 136 | set(PACKAGE_PART_NAME "") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 137 | set(BRANCH "master") |
| 138 | set(BUILD_TYPE "Package") |
| 139 | set(CONFLICT_PACKAGE_NAME "libyang-experimental") |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 140 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 141 | set(PACKAGE_NAME "libyang-experimental") |
PavolVican | 8738eee | 2018-02-27 01:47:02 +0100 | [diff] [blame] | 142 | set(PACKAGE_PART_NAME "-experimental") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 143 | set(BRANCH "devel") |
| 144 | set(BUILD_TYPE "debug") |
| 145 | set(CONFLICT_PACKAGE_NAME "libyang") |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 146 | endif() |
| 147 | # change version in config files |
| 148 | configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.spec.in ${PROJECT_BINARY_DIR}/build-packages/libyang.spec) |
| 149 | configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.dsc.in ${PROJECT_BINARY_DIR}/build-packages/libyang.dsc) |
| 150 | configure_file(${PROJECT_SOURCE_DIR}/packages/debian.control.in ${PROJECT_BINARY_DIR}/build-packages/debian.control @ONLY) |
| 151 | configure_file(${PROJECT_SOURCE_DIR}/packages/debian.rules.in ${PROJECT_BINARY_DIR}/build-packages/debian.rules) |
| 152 | |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 153 | if (NOT DEB_BUILDER) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 154 | 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.") |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 155 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 156 | # target for local build deb package |
| 157 | add_custom_target(build-deb |
| 158 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 159 | COMMAND build-packages/local-deb.sh |
| 160 | ) |
| 161 | configure_file(${PROJECT_SOURCE_DIR}/packages/local-deb.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-deb.sh @ONLY) |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 162 | endif() |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 163 | |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 164 | if (NOT RPM_BUILDER) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 165 | 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.") |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 166 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 167 | # target for local build rpm package |
| 168 | string(REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR}) |
| 169 | add_custom_target(build-rpm |
| 170 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 171 | COMMAND build-packages/local-rpm.sh |
| 172 | ) |
| 173 | configure_file(${PROJECT_SOURCE_DIR}/packages/local-rpm.sh.in ${PROJECT_BINARY_DIR}/build-packages/local-rpm.sh @ONLY) |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 174 | endif() |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 175 | |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 176 | # by default build shared library |
| 177 | # static build requires static libpcre library |
| 178 | option(ENABLE_STATIC "Build static (.a) library" OFF) |
| 179 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 180 | # check the supported platform |
| 181 | if(NOT UNIX) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 182 | message(FATAL_ERROR "Only *nix like systems are supported.") |
Radek Krejci | 61cd556 | 2015-10-05 14:06:34 +0200 | [diff] [blame] | 183 | endif() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 184 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 185 | set(libsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 186 | src/common.c |
| 187 | src/context.c |
| 188 | src/log.c |
Michal Vasko | 6c81070 | 2018-03-14 16:23:21 +0100 | [diff] [blame] | 189 | src/hash_table.c |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 190 | src/resolve.c |
| 191 | src/validation.c |
| 192 | src/xml.c |
| 193 | src/parser.c |
| 194 | src/parser_yin.c |
| 195 | src/parser_xml.c |
| 196 | src/parser_json.c |
| 197 | src/parser_yang_bis.c |
| 198 | src/parser_yang_lex.c |
| 199 | src/parser_yang.c |
| 200 | src/tree_schema.c |
| 201 | src/tree_data.c |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 202 | src/plugins.c |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 203 | src/printer.c |
| 204 | src/xpath.c |
| 205 | src/printer_yang.c |
| 206 | src/printer_yin.c |
| 207 | src/printer_xml.c |
| 208 | src/printer_tree.c |
| 209 | src/printer_info.c |
| 210 | src/printer_json.c |
| 211 | src/yang_types.c) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 212 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 213 | set(lintsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 214 | tools/lint/main.c |
| 215 | tools/lint/main_ni.c |
| 216 | tools/lint/commands.c |
| 217 | tools/lint/completion.c |
| 218 | tools/lint/configuration.c |
| 219 | linenoise/linenoise.c) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 220 | |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 221 | set(resrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 222 | tools/re/main.c) |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 223 | |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 224 | set(yang2yinsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 225 | tools/yang2yin/main.c) |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 226 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 227 | set(headers |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 228 | src/tree_schema.h |
| 229 | src/tree_data.h |
| 230 | src/extensions.h |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 231 | src/user_types.h |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 232 | src/xml.h |
| 233 | src/dict.h) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 234 | |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 235 | # create static libyang library |
| 236 | if(ENABLE_STATIC) |
| 237 | add_definitions(-DSTATIC) |
| 238 | set(CMAKE_EXE_LINKER_FLAGS -static) |
| 239 | set(CMAKE_FIND_LIBRARY_SUFFIXES .a) |
| 240 | set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic |
| 241 | set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) |
| 242 | add_library(yang STATIC ${libsrc}) |
| 243 | else() |
| 244 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 245 | add_library(yangobj OBJECT ${libsrc}) |
| 246 | add_library(yang SHARED $<TARGET_OBJECTS:yangobj>) |
Mislav Novakovic | 7073ef5 | 2018-05-24 17:23:02 +0200 | [diff] [blame] | 247 | |
| 248 | #link dl |
| 249 | target_link_libraries(yang ${CMAKE_DL_LIBS}) |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 250 | endif(ENABLE_STATIC) |
| 251 | |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 252 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION}) |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 253 | set_target_properties(yang PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 254 | |
Radek Krejci | 89658b3 | 2016-02-08 11:14:46 +0100 | [diff] [blame] | 255 | # link math |
| 256 | target_link_libraries(yang m) |
| 257 | |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 258 | # find pthreads |
| 259 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 260 | find_package(Threads REQUIRED) |
Mislav Novakovic | 7073ef5 | 2018-05-24 17:23:02 +0200 | [diff] [blame] | 261 | if(ENABLE_STATIC) |
| 262 | target_link_libraries(yang -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive) |
| 263 | else() |
| 264 | target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) |
| 265 | endif(ENABLE_STATIC) |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 266 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 267 | # find PCRE library |
Mislav Novakovic | 4c31955 | 2018-05-29 16:27:08 +0200 | [diff] [blame] | 268 | unset(PCRE_LIBRARY CACHE) |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 269 | find_package(PCRE REQUIRED) |
| 270 | include_directories(${PCRE_INCLUDE_DIRS}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 271 | target_link_libraries(yang ${PCRE_LIBRARIES}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 272 | |
Jan Kundrát | bffd9e4 | 2016-11-04 16:33:49 +0100 | [diff] [blame] | 273 | install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 274 | install(FILES ${headers} ${PROJECT_BINARY_DIR}/src/libyang.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 275 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 276 | find_package(PkgConfig) |
| 277 | if(PKG_CONFIG_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 278 | # generate and install pkg-config file |
| 279 | configure_file("libyang.pc.in" "libyang.pc" @ONLY) |
| 280 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 281 | # check that pkg-config includes the used path |
| 282 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) |
| 283 | if(RETURN EQUAL 0) |
| 284 | string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}") |
| 285 | string(LENGTH "${SUBSTR}" SUBSTR_LEN) |
| 286 | if(SUBSTR_LEN EQUAL 0) |
| 287 | 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\".") |
| 288 | endif() |
| 289 | endif() |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 290 | endif() |
| 291 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 292 | # generate doxygen documentation for libyang API |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 293 | find_package(Doxygen) |
| 294 | if(DOXYGEN_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 295 | set(DOXYGEN_SKIP_DOT TRUE) |
| 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) |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 300 | endif() |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 301 | |
| 302 | # clean cmake cache |
| 303 | add_custom_target(cclean |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 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}) |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 308 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 309 | # YANG extensions plugins |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 310 | set(EXTENSIONS_LIST "nacm" "metadata" "yangdata") |
Mislav Novakovic | 609b748 | 2018-05-23 15:01:58 +0200 | [diff] [blame] | 311 | # if the tests are enabled, build libyang_ext_test |
| 312 | if(ENABLE_BUILD_TESTS) |
| 313 | find_package(CMocka 1.0.0) |
Mislav Novakovic | 675ebb0 | 2018-05-25 17:40:19 +0200 | [diff] [blame] | 314 | if(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug) |
Mislav Novakovic | 609b748 | 2018-05-23 15:01:58 +0200 | [diff] [blame] | 315 | list(APPEND EXTENSIONS_LIST "libyang_ext_test") |
Mislav Novakovic | 675ebb0 | 2018-05-25 17:40:19 +0200 | [diff] [blame] | 316 | endif(CMOCKA_FOUND AND CMAKE_BUILD_TYPE MATCHES debug) |
Mislav Novakovic | 609b748 | 2018-05-23 15:01:58 +0200 | [diff] [blame] | 317 | endif(ENABLE_BUILD_TESTS) |
| 318 | |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 319 | if(ENABLE_STATIC) |
Mislav Novakovic | 3bef44a | 2018-05-23 18:08:52 +0200 | [diff] [blame] | 320 | set(EXTENSIONS_LIST_SIZE " 0 ") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 321 | set(ITEM 0) |
| 322 | foreach(EXTENSION ${EXTENSIONS_LIST}) |
| 323 | add_library(${EXTENSION} STATIC "src/extensions/${EXTENSION}.c") |
| 324 | target_link_libraries(yang ${EXTENSION}) |
Mislav Novakovic | 3bef44a | 2018-05-23 18:08:52 +0200 | [diff] [blame] | 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") |
Mislav Novakovic | 7472693 | 2018-06-04 13:14:03 +0200 | [diff] [blame^] | 328 | set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${EXTENSION}\",") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 329 | MATH(EXPR ITEM "${ITEM}+1") |
| 330 | endforeach() |
| 331 | else() |
| 332 | add_subdirectory(src/extensions) |
Mislav Novakovic | e5bcc13 | 2018-05-29 16:28:02 +0200 | [diff] [blame] | 333 | endif(ENABLE_STATIC) |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 334 | |
Michal Vasko | 25b59c7 | 2018-03-21 11:49:23 +0100 | [diff] [blame] | 335 | # YANG user types plugins |
Mislav Novakovic | 922025e | 2018-05-23 12:45:31 +0200 | [diff] [blame] | 336 | set(USER_TYPE_LIST "user_date_and_time" "user_ipv4") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 337 | if(ENABLE_STATIC) |
Mislav Novakovic | 3bef44a | 2018-05-23 18:08:52 +0200 | [diff] [blame] | 338 | set(USER_TYPE_LIST_SIZE " 0 ") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 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}) |
Mislav Novakovic | 3bef44a | 2018-05-23 18:08:52 +0200 | [diff] [blame] | 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") |
Mislav Novakovic | 7472693 | 2018-06-04 13:14:03 +0200 | [diff] [blame^] | 345 | set(STATIC_LOADED_PLUGINS "${STATIC_LOADED_PLUGINS} \"${USER_TYPE}\",") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 346 | MATH(EXPR ITEM "${ITEM}+1") |
| 347 | endforeach() |
Mislav Novakovic | 7472693 | 2018-06-04 13:14:03 +0200 | [diff] [blame^] | 348 | set(STATIC_LOADED_PLUGINS_COUNT "${ITEM}") |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 349 | else() |
| 350 | add_subdirectory(src/user_types) |
Mislav Novakovic | e5bcc13 | 2018-05-29 16:28:02 +0200 | [diff] [blame] | 351 | endif(ENABLE_STATIC) |
Mislav Novakovic | 61c7908 | 2018-05-21 13:08:24 +0200 | [diff] [blame] | 352 | |
| 353 | configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h) |
Michal Vasko | 25b59c7 | 2018-03-21 11:49:23 +0100 | [diff] [blame] | 354 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 355 | # yanglint |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 356 | add_executable(yanglint ${lintsrc}) |
Radek Krejci | 40dcad2 | 2017-06-08 11:35:32 +0200 | [diff] [blame] | 357 | target_link_libraries(yanglint yang) |
Jan Kundrát | bffd9e4 | 2016-11-04 16:33:49 +0100 | [diff] [blame] | 358 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 359 | install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 360 | |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 361 | #yangre |
| 362 | add_executable(yangre ${resrc}) |
| 363 | target_link_libraries(yangre yang) |
| 364 | install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 365 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 366 | # yang2yin |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 367 | add_executable(yang2yin ${yang2yinsrc}) |
| 368 | |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 369 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 370 | set(ENABLE_BUILD_TESTS ON) |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 371 | endif() |
| 372 | |
| 373 | if(ENABLE_BUILD_TESTS) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 374 | if(CMOCKA_FOUND) |
| 375 | enable_testing() |
| 376 | add_subdirectory(tests) |
Radek Krejci | bf123af | 2018-02-21 08:05:21 +0100 | [diff] [blame] | 377 | else(CMOCKA_FOUND) |
| 378 | message(STATUS "Disabling tests because of missing CMocka") |
| 379 | set(ENABLE_BUILD_TESTS NO) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 380 | endif(CMOCKA_FOUND) |
Radek Krejci | e02ce0a | 2015-11-04 14:14:20 +0100 | [diff] [blame] | 381 | endif(ENABLE_BUILD_TESTS) |
Mislav Novakovic | a827b5f | 2016-02-29 11:47:22 +0100 | [diff] [blame] | 382 | |
Mislav Novakovic | edc6c08 | 2017-05-30 15:21:42 +0200 | [diff] [blame] | 383 | if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS) |
| 384 | add_subdirectory(swig) |
| 385 | endif() |