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 | f924c36 | 2018-04-25 11:31:15 +0200 | [diff] [blame] | 14 | set(LIBYANG_MICRO_VERSION 89) |
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") |
| 79 | configure_file(${PROJECT_SOURCE_DIR}/src/plugin_config.h.in ${PROJECT_BINARY_DIR}/src/plugin_config.h) |
Radek Krejci | 858ad95 | 2017-01-04 11:16:32 +0100 | [diff] [blame] | 80 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 81 | # include custom Modules |
Radek Krejci | 977c1c8 | 2015-09-01 15:18:03 +0200 | [diff] [blame] | 82 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 83 | |
Mislav Novakovic | edc6c08 | 2017-05-30 15:21:42 +0200 | [diff] [blame] | 84 | # setup bindings |
| 85 | set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.") |
| 86 | set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.") |
| 87 | # Python bindings depend on C++ bindings because of SWIG |
| 88 | set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.") |
| 89 | set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version") |
| 90 | set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.") |
| 91 | |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 92 | find_package(FLEX) |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 93 | find_package(BISON) |
Michal Vasko | aa515e8 | 2018-03-23 08:45:19 +0100 | [diff] [blame] | 94 | find_program(DEB_BUILDER NAMES debuild) |
| 95 | find_program(RPM_BUILDER NAMES rpmbuild) |
| 96 | find_program(SED_TOOL NAMES sed) |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 97 | |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 98 | if(NOT BISON_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 99 | 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] | 100 | elseif (NOT FLEX_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 101 | 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] | 102 | else() |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 103 | if (BISON_VERSION VERSION_LESS 3) |
| 104 | set(EMPTYDIR "") |
| 105 | else () |
| 106 | set(EMPTYDIR "%empty") |
| 107 | endif() |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 108 | 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] | 109 | add_custom_target(bison |
| 110 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src |
Radek Krejci | f2dc9c3 | 2017-10-27 14:17:52 +0200 | [diff] [blame] | 111 | 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] | 112 | COMMAND flex -8 -L -o parser_yang_lex.c --header-file=parser_yang_lex.h yang.l |
| 113 | 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 |
| 114 | ) |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 115 | endif() |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 116 | |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 117 | if (NOT DEFINED ENV{TRAVIS_BRANCH}) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 118 | execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" |
| 119 | OUTPUT_VARIABLE GIT_BRANCH |
| 120 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 121 | ERROR_QUIET |
| 122 | ) |
| 123 | if (NOT GIT_BRANCH) |
| 124 | set(ENV{TRAVIS_BRANCH} "master") |
| 125 | else() |
| 126 | if (GIT_BRANCH MATCHES "master|devel") |
| 127 | set(ENV{TRAVIS_BRANCH} ${GIT_BRANCH}) |
| 128 | else() |
| 129 | set(ENV{TRAVIS_BRANCH} "master") |
| 130 | endif() |
| 131 | endif() |
| 132 | set(GIT_BRANCH $ENV{TRAVIS_BRANCH}) |
PavolVican | 3739627 | 2017-03-25 00:57:20 +0100 | [diff] [blame] | 133 | endif() |
| 134 | |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 135 | if ($ENV{TRAVIS_BRANCH} STREQUAL "master") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 136 | set(PACKAGE_NAME "libyang") |
PavolVican | 8738eee | 2018-02-27 01:47:02 +0100 | [diff] [blame] | 137 | set(PACKAGE_PART_NAME "") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 138 | set(BRANCH "master") |
| 139 | set(BUILD_TYPE "Package") |
| 140 | set(CONFLICT_PACKAGE_NAME "libyang-experimental") |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 141 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 142 | set(PACKAGE_NAME "libyang-experimental") |
PavolVican | 8738eee | 2018-02-27 01:47:02 +0100 | [diff] [blame] | 143 | set(PACKAGE_PART_NAME "-experimental") |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 144 | set(BRANCH "devel") |
| 145 | set(BUILD_TYPE "debug") |
| 146 | set(CONFLICT_PACKAGE_NAME "libyang") |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 147 | endif() |
| 148 | # change version in config files |
| 149 | configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.spec.in ${PROJECT_BINARY_DIR}/build-packages/libyang.spec) |
| 150 | configure_file(${PROJECT_SOURCE_DIR}/packages/libyang.dsc.in ${PROJECT_BINARY_DIR}/build-packages/libyang.dsc) |
| 151 | configure_file(${PROJECT_SOURCE_DIR}/packages/debian.control.in ${PROJECT_BINARY_DIR}/build-packages/debian.control @ONLY) |
| 152 | configure_file(${PROJECT_SOURCE_DIR}/packages/debian.rules.in ${PROJECT_BINARY_DIR}/build-packages/debian.rules) |
| 153 | |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 154 | if (NOT DEB_BUILDER) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 155 | 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] | 156 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 157 | # target for local build deb package |
| 158 | add_custom_target(build-deb |
| 159 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 160 | COMMAND build-packages/local-deb.sh |
| 161 | ) |
| 162 | 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] | 163 | endif() |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 164 | |
PavolVican | cf74925 | 2017-06-08 09:31:49 +0200 | [diff] [blame] | 165 | if (NOT RPM_BUILDER) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 166 | 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] | 167 | else () |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 168 | # target for local build rpm package |
| 169 | string(REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR}) |
| 170 | add_custom_target(build-rpm |
| 171 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 172 | COMMAND build-packages/local-rpm.sh |
| 173 | ) |
| 174 | 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] | 175 | endif() |
PavolVican | 5d37752 | 2017-06-07 15:08:14 +0200 | [diff] [blame] | 176 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 177 | # check the supported platform |
| 178 | if(NOT UNIX) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 179 | message(FATAL_ERROR "Only *nix like systems are supported.") |
Radek Krejci | 61cd556 | 2015-10-05 14:06:34 +0200 | [diff] [blame] | 180 | endif() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 181 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 182 | set(libsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 183 | src/common.c |
| 184 | src/context.c |
| 185 | src/log.c |
Michal Vasko | 6c81070 | 2018-03-14 16:23:21 +0100 | [diff] [blame] | 186 | src/hash_table.c |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 187 | src/resolve.c |
| 188 | src/validation.c |
| 189 | src/xml.c |
| 190 | src/parser.c |
| 191 | src/parser_yin.c |
| 192 | src/parser_xml.c |
| 193 | src/parser_json.c |
| 194 | src/parser_yang_bis.c |
| 195 | src/parser_yang_lex.c |
| 196 | src/parser_yang.c |
| 197 | src/tree_schema.c |
| 198 | src/tree_data.c |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 199 | src/plugins.c |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 200 | src/printer.c |
| 201 | src/xpath.c |
| 202 | src/printer_yang.c |
| 203 | src/printer_yin.c |
| 204 | src/printer_xml.c |
| 205 | src/printer_tree.c |
| 206 | src/printer_info.c |
| 207 | src/printer_json.c |
| 208 | src/yang_types.c) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 209 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 210 | set(lintsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 211 | tools/lint/main.c |
| 212 | tools/lint/main_ni.c |
| 213 | tools/lint/commands.c |
| 214 | tools/lint/completion.c |
| 215 | tools/lint/configuration.c |
| 216 | linenoise/linenoise.c) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 217 | |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 218 | set(resrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 219 | tools/re/main.c) |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 220 | |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 221 | set(yang2yinsrc |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 222 | tools/yang2yin/main.c) |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 223 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 224 | set(headers |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 225 | src/tree_schema.h |
| 226 | src/tree_data.h |
| 227 | src/extensions.h |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 228 | src/user_types.h |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 229 | src/xml.h |
| 230 | src/dict.h) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 231 | |
Radek Krejci | 5708fe6 | 2016-09-14 12:25:12 +0200 | [diff] [blame] | 232 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 233 | add_library(yangobj OBJECT ${libsrc}) |
| 234 | add_library(yang SHARED $<TARGET_OBJECTS:yangobj>) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 235 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION}) |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 236 | set_target_properties(yang PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 237 | |
Radek Krejci | 89658b3 | 2016-02-08 11:14:46 +0100 | [diff] [blame] | 238 | # link math |
| 239 | target_link_libraries(yang m) |
| 240 | |
Radek Krejci | 858ad95 | 2017-01-04 11:16:32 +0100 | [diff] [blame] | 241 | #link dl |
| 242 | target_link_libraries(yang ${CMAKE_DL_LIBS}) |
| 243 | |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 244 | # find pthreads |
| 245 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 246 | find_package(Threads REQUIRED) |
| 247 | target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) |
| 248 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 249 | # find PCRE library |
| 250 | find_package(PCRE REQUIRED) |
| 251 | include_directories(${PCRE_INCLUDE_DIRS}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 252 | target_link_libraries(yang ${PCRE_LIBRARIES}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 253 | |
Jan Kundrát | bffd9e4 | 2016-11-04 16:33:49 +0100 | [diff] [blame] | 254 | install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 255 | 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] | 256 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 257 | find_package(PkgConfig) |
| 258 | if(PKG_CONFIG_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 259 | # generate and install pkg-config file |
| 260 | configure_file("libyang.pc.in" "libyang.pc" @ONLY) |
| 261 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 262 | # check that pkg-config includes the used path |
| 263 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) |
| 264 | if(RETURN EQUAL 0) |
| 265 | string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}") |
| 266 | string(LENGTH "${SUBSTR}" SUBSTR_LEN) |
| 267 | if(SUBSTR_LEN EQUAL 0) |
| 268 | 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\".") |
| 269 | endif() |
| 270 | endif() |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 271 | endif() |
| 272 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 273 | # generate doxygen documentation for libyang API |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 274 | find_package(Doxygen) |
| 275 | if(DOXYGEN_FOUND) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 276 | set(DOXYGEN_SKIP_DOT TRUE) |
| 277 | add_custom_target(doc |
| 278 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 279 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 280 | configure_file(Doxyfile.in Doxyfile) |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 281 | endif() |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 282 | |
| 283 | # clean cmake cache |
| 284 | add_custom_target(cclean |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 285 | COMMAND make clean |
| 286 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} + |
| 287 | COMMAND rm -rf Makefile Doxyfile |
| 288 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 289 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 290 | # YANG extensions plugins |
| 291 | add_subdirectory(src/extensions) |
| 292 | |
Michal Vasko | 25b59c7 | 2018-03-21 11:49:23 +0100 | [diff] [blame] | 293 | # YANG user types plugins |
| 294 | add_subdirectory(src/user_types) |
| 295 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 296 | # yanglint |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 297 | add_executable(yanglint ${lintsrc}) |
Radek Krejci | 40dcad2 | 2017-06-08 11:35:32 +0200 | [diff] [blame] | 298 | target_link_libraries(yanglint yang) |
Jan Kundrát | bffd9e4 | 2016-11-04 16:33:49 +0100 | [diff] [blame] | 299 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 300 | 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] | 301 | |
Radek Krejci | b4a481c | 2017-07-12 15:12:34 +0200 | [diff] [blame] | 302 | #yangre |
| 303 | add_executable(yangre ${resrc}) |
| 304 | target_link_libraries(yangre yang) |
| 305 | install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 306 | |
Radek Krejci | c43058d | 2017-01-04 16:29:58 +0100 | [diff] [blame] | 307 | # yang2yin |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame] | 308 | add_executable(yang2yin ${yang2yinsrc}) |
| 309 | |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 310 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 311 | set(ENABLE_BUILD_TESTS ON) |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 312 | endif() |
| 313 | |
| 314 | if(ENABLE_BUILD_TESTS) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 315 | find_package(CMocka 1.0.0) |
| 316 | if(CMOCKA_FOUND) |
| 317 | enable_testing() |
| 318 | add_subdirectory(tests) |
Radek Krejci | bf123af | 2018-02-21 08:05:21 +0100 | [diff] [blame] | 319 | else(CMOCKA_FOUND) |
| 320 | message(STATUS "Disabling tests because of missing CMocka") |
| 321 | set(ENABLE_BUILD_TESTS NO) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 322 | endif(CMOCKA_FOUND) |
Radek Krejci | e02ce0a | 2015-11-04 14:14:20 +0100 | [diff] [blame] | 323 | endif(ENABLE_BUILD_TESTS) |
Mislav Novakovic | a827b5f | 2016-02-29 11:47:22 +0100 | [diff] [blame] | 324 | |
Mislav Novakovic | edc6c08 | 2017-05-30 15:21:42 +0200 | [diff] [blame] | 325 | if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS) |
| 326 | add_subdirectory(swig) |
| 327 | endif() |
| 328 | |
| 329 | if(GEN_LANGUAGE_BINDINGS AND GEN_JAVASCRIPT_BINDINGS) |
Michal Vasko | 8f3160e | 2017-09-27 11:25:26 +0200 | [diff] [blame] | 330 | include(swig/javascript/CMakeLists.txt) |
Mislav Novakovic | a827b5f | 2016-02-29 11:47:22 +0100 | [diff] [blame] | 331 | endif() |