Michal Vasko | b8d90a3 | 2016-02-09 13:59:42 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 2 | project(libyang C) |
| 3 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 4 | set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.") |
| 5 | |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 6 | # set version |
| 7 | set(LIBYANG_MAJOR_VERSION 0) |
Radek Krejci | d5d1e4a | 2016-03-29 14:50:13 +0200 | [diff] [blame] | 8 | set(LIBYANG_MINOR_VERSION 9) |
Radek Krejci | 3577147 | 2016-06-17 14:33:19 +0200 | [diff] [blame] | 9 | set(LIBYANG_MICRO_VERSION 137) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 10 | set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION}) |
| 11 | set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}) |
| 12 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 13 | # include custom Modules |
Radek Krejci | 977c1c8 | 2015-09-01 15:18:03 +0200 | [diff] [blame] | 14 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 15 | |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 16 | find_package(FLEX) |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 17 | find_package(BISON) |
Pavol Vican | 0a9716f | 2016-05-22 17:04:06 +0200 | [diff] [blame] | 18 | find_program (SED_TOOL NAMES sed) |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 19 | |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 20 | if(NOT BISON_FOUND) |
| 21 | message(WARNING "Missing Bison.\nTarget bison does not exist.") |
| 22 | elseif (NOT FLEX_FOUND) |
| 23 | message(WARNING "Missing Flex.\nTarget bison does not exist.") |
| 24 | else() |
| 25 | if (BISON_VERSION VERSION_LESS 3) |
| 26 | set(EMPTYDIR "") |
| 27 | else () |
| 28 | set(EMPTYDIR "%empty") |
| 29 | endif() |
| 30 | configure_file(${PROJECT_SOURCE_DIR}/src/yang.y.in ${PROJECT_SOURCE_DIR}/src/yang.y) |
| 31 | add_custom_target(bison |
Pavol Vican | 15bf384 | 2016-04-05 22:25:00 +0200 | [diff] [blame] | 32 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src |
Pavol Vican | be9e383 | 2016-04-28 02:21:37 +0200 | [diff] [blame] | 33 | COMMAND bison -Wno-other -l -o parser_yang_bis.c --defines=parser_yang_bis.h yang.y |
Pavol Vican | f62e526 | 2016-04-07 11:25:19 +0200 | [diff] [blame] | 34 | COMMAND flex -L -o parser_yang_lex.c --header-file=parser_yang_lex.h yang.l |
Pavol Vican | 0a9716f | 2016-05-22 17:04:06 +0200 | [diff] [blame] | 35 | COMMAND ${SED_TOOL} -i 's/int yychar\;/int yychar\;\\nchar *s, *tmp_s\;\\nchar rev[LY_REV_SIZE]\;\\nstruct lys_module *trg\;\\nstruct lys_node *tpdf_parent, *data_node\;\\nvoid *actual\;\\nint config_inherit, actual_type\;\\nint64_t cnt_val\;/' parser_yang_bis.c |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 36 | ) |
| 37 | endif() |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 38 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 39 | # check the supported platform |
| 40 | if(NOT UNIX) |
| 41 | message(FATAL_ERROR "Only *nix like systems are supported.") |
| 42 | endif() |
| 43 | |
| 44 | if(NOT LIB_INSTALL_DIR) |
| 45 | set(LIB_INSTALL_DIR lib) |
| 46 | endif() |
| 47 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 48 | if(NOT INCLUDE_INSTALL_DIR) |
| 49 | set(INCLUDE_INSTALL_DIR include/libyang) |
| 50 | endif() |
| 51 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 52 | # set default build type if not specified by user |
| 53 | if(NOT CMAKE_BUILD_TYPE) |
| 54 | set(CMAKE_BUILD_TYPE debug) |
| 55 | endif() |
| 56 | |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 57 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden") |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 58 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
Radek Krejci | f19ac67 | 2016-02-05 16:16:36 +0100 | [diff] [blame] | 59 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 60 | |
Radek Krejci | 61cd556 | 2015-10-05 14:06:34 +0200 | [diff] [blame] | 61 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
| 62 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 63 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 64 | else() |
| 65 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 66 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 67 | endif() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 68 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 69 | set(libsrc |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 70 | src/common.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 71 | src/context.c |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 72 | src/log.c |
Radek Krejci | ee62758 | 2015-04-20 17:39:59 +0200 | [diff] [blame] | 73 | src/dict.c |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 74 | src/resolve.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 75 | src/validation.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 76 | src/xml.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 77 | src/parser.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 78 | src/parser_yin.c |
| 79 | src/parser_xml.c |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 80 | src/parser_json.c |
Pavol Vican | cae5488 | 2016-03-30 12:24:43 +0200 | [diff] [blame] | 81 | src/parser_yang_bis.c |
| 82 | src/parser_yang_lex.c |
Pavol Vican | f7cc285 | 2016-03-22 23:27:35 +0100 | [diff] [blame] | 83 | src/parser_yang.c |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 84 | src/tree_schema.c |
| 85 | src/tree_data.c |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 86 | src/printer.c |
Michal Vasko | abbdaa0 | 2015-10-06 15:47:25 +0200 | [diff] [blame] | 87 | src/xpath.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 88 | src/printer_yang.c |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 89 | src/printer_yin.c |
Michal Vasko | 9b9e4a0 | 2015-08-21 09:11:14 +0200 | [diff] [blame] | 90 | src/printer_xml.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 91 | src/printer_tree.c |
| 92 | src/printer_info.c |
| 93 | src/printer_json.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 94 | src/yang_types.c) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 95 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 96 | set(lintsrc |
Michal Vasko | f3e59f1 | 2015-06-18 11:53:56 +0200 | [diff] [blame] | 97 | tools/lint/main.c |
| 98 | tools/lint/commands.c |
Michal Vasko | e0cb252 | 2015-07-01 10:24:53 +0200 | [diff] [blame] | 99 | tools/lint/completion.c |
Michal Vasko | 203b4e7 | 2015-06-30 15:25:15 +0200 | [diff] [blame] | 100 | linenoise/linenoise.c) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 101 | |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame^] | 102 | set(yang2yinsrc |
| 103 | tools/yang2yin/main.c) |
| 104 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 105 | set(headers |
| 106 | src/libyang.h |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 107 | src/tree_schema.h |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 108 | src/tree_data.h |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 109 | src/xml.h |
| 110 | src/dict.h) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 111 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 112 | add_library(yang SHARED ${libsrc}) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 113 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION}) |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 114 | |
Radek Krejci | 89658b3 | 2016-02-08 11:14:46 +0100 | [diff] [blame] | 115 | # link math |
| 116 | target_link_libraries(yang m) |
| 117 | |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 118 | # find pthreads |
| 119 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 120 | find_package(Threads REQUIRED) |
| 121 | target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) |
| 122 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 123 | # find PCRE library |
| 124 | find_package(PCRE REQUIRED) |
| 125 | include_directories(${PCRE_INCLUDE_DIRS}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 126 | target_link_libraries(yang ${PCRE_LIBRARIES}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 127 | |
| 128 | install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR}) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 129 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 130 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 131 | find_package(PkgConfig) |
| 132 | if(PKG_CONFIG_FOUND) |
| 133 | # generate and install pkg-config file |
| 134 | configure_file("libyang.pc.in" "libyang.pc" @ONLY) |
Tomas Cejka | 9e715cc | 2016-02-23 15:05:40 +0100 | [diff] [blame] | 135 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/pkgconfig") |
Michal Vasko | 98ae1e1 | 2015-12-15 11:11:28 +0100 | [diff] [blame] | 136 | # check that pkg-config includes the used path |
| 137 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) |
| 138 | if(RETURN EQUAL 0) |
Tomas Cejka | 9e715cc | 2016-02-23 15:05:40 +0100 | [diff] [blame] | 139 | string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/pkgconfig" SUBSTR "${PC_PATH}") |
Michal Vasko | 33c001c | 2016-02-11 09:01:52 +0100 | [diff] [blame] | 140 | string(LENGTH "${SUBSTR}" SUBSTR_LEN) |
Michal Vasko | b8d90a3 | 2016-02-09 13:59:42 +0100 | [diff] [blame] | 141 | if(SUBSTR_LEN EQUAL 0) |
Tomas Cejka | 9e715cc | 2016-02-23 15:05:40 +0100 | [diff] [blame] | 142 | 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}/${LIB_INSTALL_DIR}/pkgconfig\".") |
Michal Vasko | 98ae1e1 | 2015-12-15 11:11:28 +0100 | [diff] [blame] | 143 | endif() |
| 144 | endif() |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 145 | endif() |
| 146 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 147 | # generate doxygen documentation for libyang API |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 148 | find_package(Doxygen) |
| 149 | if(DOXYGEN_FOUND) |
| 150 | set(DOXYGEN_SKIP_DOT TRUE) |
| 151 | add_custom_target(doc |
| 152 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 153 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 154 | configure_file(Doxyfile.in Doxyfile) |
| 155 | endif() |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 156 | |
| 157 | # clean cmake cache |
| 158 | add_custom_target(cclean |
Radek Krejci | 25155ac | 2015-10-08 11:26:20 +0200 | [diff] [blame] | 159 | COMMAND make clean |
| 160 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} + |
| 161 | COMMAND rm -rf Makefile Doxyfile |
| 162 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 163 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 164 | add_executable(yanglint ${lintsrc}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 165 | target_link_libraries(yanglint yang) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 166 | |
Michal Vasko | 9a54274 | 2016-06-23 13:04:51 +0200 | [diff] [blame^] | 167 | add_executable(yang2yin ${yang2yinsrc}) |
| 168 | |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 169 | if(ENABLE_VALGRIND_TESTS) |
| 170 | set(ENABLE_BUILD_TESTS ON) |
| 171 | endif() |
| 172 | |
| 173 | if(ENABLE_BUILD_TESTS) |
Radek Krejci | e02ce0a | 2015-11-04 14:14:20 +0100 | [diff] [blame] | 174 | find_package(CMocka 1.0.0) |
| 175 | if(CMOCKA_FOUND) |
| 176 | enable_testing() |
| 177 | add_subdirectory(tests) |
| 178 | endif(CMOCKA_FOUND) |
| 179 | endif(ENABLE_BUILD_TESTS) |
Mislav Novakovic | a827b5f | 2016-02-29 11:47:22 +0100 | [diff] [blame] | 180 | |
| 181 | if(JAVASCRIPT_BINDING) |
| 182 | include(swig/javascript/CMakeLists.txt) |
| 183 | endif() |