Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
| 2 | project(libyang C) |
| 3 | |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 4 | # set version |
| 5 | set(LIBYANG_MAJOR_VERSION 0) |
Radek Krejci | d66c778 | 2015-08-17 10:25:06 +0200 | [diff] [blame] | 6 | set(LIBYANG_MINOR_VERSION 2) |
Radek Krejci | c2b137c | 2015-10-21 16:37:33 +0200 | [diff] [blame^] | 7 | set(LIBYANG_MICRO_VERSION 61) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 8 | set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION}) |
| 9 | set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}) |
| 10 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 11 | # include custom Modules |
Radek Krejci | 977c1c8 | 2015-09-01 15:18:03 +0200 | [diff] [blame] | 12 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 13 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 14 | # check the supported platform |
| 15 | if(NOT UNIX) |
| 16 | message(FATAL_ERROR "Only *nix like systems are supported.") |
| 17 | endif() |
| 18 | |
| 19 | if(NOT LIB_INSTALL_DIR) |
| 20 | set(LIB_INSTALL_DIR lib) |
| 21 | endif() |
| 22 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 23 | if(NOT INCLUDE_INSTALL_DIR) |
| 24 | set(INCLUDE_INSTALL_DIR include/libyang) |
| 25 | endif() |
| 26 | |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 27 | # set default build type if not specified by user |
| 28 | if(NOT CMAKE_BUILD_TYPE) |
| 29 | set(CMAKE_BUILD_TYPE debug) |
| 30 | endif() |
| 31 | |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 32 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden") |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 33 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 34 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 35 | |
Radek Krejci | 61cd556 | 2015-10-05 14:06:34 +0200 | [diff] [blame] | 36 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
| 37 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 38 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 39 | else() |
| 40 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 41 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 42 | endif() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 43 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 44 | set(libsrc |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 45 | src/common.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 46 | src/context.c |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 47 | src/log.c |
Radek Krejci | ee62758 | 2015-04-20 17:39:59 +0200 | [diff] [blame] | 48 | src/dict.c |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 49 | src/resolve.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 50 | src/validation.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 51 | src/xml.c |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 52 | src/parser.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 53 | src/parser_yin.c |
| 54 | src/parser_xml.c |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 55 | src/tree_schema.c |
| 56 | src/tree_data.c |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 57 | src/printer.c |
Michal Vasko | abbdaa0 | 2015-10-06 15:47:25 +0200 | [diff] [blame] | 58 | src/xpath.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 59 | src/printer_yang.c |
Michal Vasko | 9b9e4a0 | 2015-08-21 09:11:14 +0200 | [diff] [blame] | 60 | src/printer_xml.c |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 61 | src/printer_tree.c |
| 62 | src/printer_info.c |
| 63 | src/printer_json.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 64 | src/yang_types.c) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 65 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 66 | set(lintsrc |
Michal Vasko | f3e59f1 | 2015-06-18 11:53:56 +0200 | [diff] [blame] | 67 | tools/lint/main.c |
| 68 | tools/lint/commands.c |
Michal Vasko | e0cb252 | 2015-07-01 10:24:53 +0200 | [diff] [blame] | 69 | tools/lint/completion.c |
Michal Vasko | 203b4e7 | 2015-06-30 15:25:15 +0200 | [diff] [blame] | 70 | linenoise/linenoise.c) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 71 | |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 72 | set(headers |
| 73 | src/libyang.h |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 74 | src/tree_schema.h |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 75 | src/tree_data.h |
| 76 | src/xml.h) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 77 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 78 | add_library(yang SHARED ${libsrc}) |
Radek Krejci | 8f7cf40 | 2015-08-13 08:05:48 +0200 | [diff] [blame] | 79 | set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION}) |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 80 | |
| 81 | # find PCRE library |
| 82 | find_package(PCRE REQUIRED) |
| 83 | include_directories(${PCRE_INCLUDE_DIRS}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 84 | target_link_libraries(yang ${PCRE_LIBRARIES}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 85 | |
| 86 | install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR}) |
Tomas Cejka | 422c007 | 2015-07-21 18:18:25 +0200 | [diff] [blame] | 87 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR}) |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 88 | |
| 89 | # generate doxygen documentation for libyang API |
Radek Krejci | e262609 | 2015-10-08 11:25:44 +0200 | [diff] [blame] | 90 | find_package(Doxygen) |
| 91 | if(DOXYGEN_FOUND) |
| 92 | set(DOXYGEN_SKIP_DOT TRUE) |
| 93 | add_custom_target(doc |
| 94 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 95 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 96 | configure_file(Doxyfile.in Doxyfile) |
| 97 | endif() |
Radek Krejci | e74ea8c | 2015-04-09 18:06:20 +0200 | [diff] [blame] | 98 | |
| 99 | # clean cmake cache |
| 100 | add_custom_target(cclean |
Radek Krejci | 25155ac | 2015-10-08 11:26:20 +0200 | [diff] [blame] | 101 | COMMAND make clean |
| 102 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} + |
| 103 | COMMAND rm -rf Makefile Doxyfile |
| 104 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
Radek Krejci | 2cb3054 | 2015-04-10 08:33:57 +0200 | [diff] [blame] | 105 | |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 106 | add_executable(yanglint ${lintsrc}) |
Radek Krejci | 1d949ec | 2015-10-02 13:35:05 +0200 | [diff] [blame] | 107 | target_link_libraries(yanglint yang) |
Radek Krejci | 5a06554 | 2015-05-22 15:02:07 +0200 | [diff] [blame] | 108 | |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 109 | if(ENABLE_VALGRIND_TESTS) |
| 110 | set(ENABLE_BUILD_TESTS ON) |
| 111 | endif() |
| 112 | |
| 113 | if(ENABLE_BUILD_TESTS) |
Radek Krejci | 800a079 | 2015-10-05 14:05:48 +0200 | [diff] [blame] | 114 | enable_testing() |
Mislav Novakovic | 021b9a1 | 2015-10-01 20:50:21 +0200 | [diff] [blame] | 115 | add_subdirectory(tests) |
| 116 | endif() |