Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
| 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 | 7067397 | 2016-01-04 17:13:23 +0100 | [diff] [blame] | 8 | set(LIBYANG_MINOR_VERSION 5) |
Radek Krejci | 04a19dc | 2016-02-04 15:00:45 +0100 | [diff] [blame] | 9 | set(LIBYANG_MICRO_VERSION 31) |
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 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 16 | # check the supported platform |
| 17 | if(NOT UNIX) |
| 18 | message(FATAL_ERROR "Only *nix like systems are supported.") |
| 19 | endif() |
| 20 | |
| 21 | if(NOT LIB_INSTALL_DIR) |
| 22 | set(LIB_INSTALL_DIR lib) |
| 23 | endif() |
| 24 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 25 | if(NOT INCLUDE_INSTALL_DIR) |
| 26 | set(INCLUDE_INSTALL_DIR include/libyang) |
| 27 | endif() |
| 28 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 29 | # set default build type if not specified by user |
| 30 | if(NOT CMAKE_BUILD_TYPE) |
| 31 | set(CMAKE_BUILD_TYPE debug) |
| 32 | endif() |
| 33 | |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 34 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden") |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 35 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 36 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 37 | |
Radek Krejci | 61cd556 | 2015-10-05 14:06:34 +0200 | [diff] [blame] | 38 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
| 39 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 40 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 41 | else() |
| 42 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 43 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 44 | endif() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 45 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 46 | set(libsrc |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 47 | src/common.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 48 | src/context.c |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 49 | src/log.c |
Radek Krejci | ee62758 | 2015-04-20 17:39:59 +0200 | [diff] [blame] | 50 | src/dict.c |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 51 | src/resolve.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 52 | src/validation.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 53 | src/xml.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 54 | src/parser.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 55 | src/parser_yin.c |
| 56 | src/parser_xml.c |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 57 | src/parser_json.c |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 58 | src/tree_schema.c |
| 59 | src/tree_data.c |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 60 | src/printer.c |
Michal Vasko | abbdaa0 | 2015-10-06 15:47:25 +0200 | [diff] [blame] | 61 | src/xpath.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 62 | src/printer_yang.c |
Michal Vasko | 9b9e4a0 | 2015-08-21 09:11:14 +0200 | [diff] [blame] | 63 | src/printer_xml.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 64 | src/printer_tree.c |
| 65 | src/printer_info.c |
| 66 | src/printer_json.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 67 | src/yang_types.c) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 68 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 69 | set(lintsrc |
Michal Vasko | f3e59f1 | 2015-06-18 11:53:56 +0200 | [diff] [blame] | 70 | tools/lint/main.c |
| 71 | tools/lint/commands.c |
Michal Vasko | e0cb252 | 2015-07-01 10:24:53 +0200 | [diff] [blame] | 72 | tools/lint/completion.c |
Michal Vasko | 203b4e7 | 2015-06-30 15:25:15 +0200 | [diff] [blame] | 73 | linenoise/linenoise.c) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 74 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 75 | set(headers |
| 76 | src/libyang.h |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 77 | src/tree_schema.h |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 78 | src/tree_data.h |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 79 | src/xml.h |
| 80 | src/dict.h) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 81 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 82 | add_library(yang SHARED ${libsrc}) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 83 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION}) |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 84 | |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 85 | # find pthreads |
| 86 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 87 | find_package(Threads REQUIRED) |
| 88 | target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) |
| 89 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 90 | # find PCRE library |
| 91 | find_package(PCRE REQUIRED) |
| 92 | include_directories(${PCRE_INCLUDE_DIRS}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 93 | target_link_libraries(yang ${PCRE_LIBRARIES}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 94 | |
| 95 | install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR}) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 96 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 97 | |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 98 | find_package(PkgConfig) |
| 99 | if(PKG_CONFIG_FOUND) |
| 100 | # generate and install pkg-config file |
| 101 | configure_file("libyang.pc.in" "libyang.pc" @ONLY) |
| 102 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") |
Michal Vasko | 98ae1e1 | 2015-12-15 11:11:28 +0100 | [diff] [blame] | 103 | # check that pkg-config includes the used path |
| 104 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) |
| 105 | if(RETURN EQUAL 0) |
| 106 | string(FIND ${PC_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig" PC_PATH_IDX) |
| 107 | if(PC_PATH_IDX EQUAL -1) |
| 108 | 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/pkgconfig\".") |
| 109 | endif() |
| 110 | endif() |
Michal Vasko | e5cf992 | 2015-11-11 11:06:40 +0100 | [diff] [blame] | 111 | endif() |
| 112 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 113 | # generate doxygen documentation for libyang API |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 114 | find_package(Doxygen) |
| 115 | if(DOXYGEN_FOUND) |
| 116 | set(DOXYGEN_SKIP_DOT TRUE) |
| 117 | add_custom_target(doc |
| 118 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 119 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 120 | configure_file(Doxyfile.in Doxyfile) |
| 121 | endif() |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 122 | |
| 123 | # clean cmake cache |
| 124 | add_custom_target(cclean |
Radek Krejci | 25155ac | 2015-10-08 11:26:20 +0200 | [diff] [blame] | 125 | COMMAND make clean |
| 126 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} + |
| 127 | COMMAND rm -rf Makefile Doxyfile |
| 128 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 129 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 130 | add_executable(yanglint ${lintsrc}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 131 | target_link_libraries(yanglint yang) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 132 | |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 133 | if(ENABLE_VALGRIND_TESTS) |
| 134 | set(ENABLE_BUILD_TESTS ON) |
| 135 | endif() |
| 136 | |
| 137 | if(ENABLE_BUILD_TESTS) |
Radek Krejci | e02ce0a | 2015-11-04 14:14:20 +0100 | [diff] [blame] | 138 | find_package(CMocka 1.0.0) |
| 139 | if(CMOCKA_FOUND) |
| 140 | enable_testing() |
| 141 | add_subdirectory(tests) |
| 142 | endif(CMOCKA_FOUND) |
| 143 | endif(ENABLE_BUILD_TESTS) |