Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 2 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 3 | # include custom Modules |
| 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
| 5 | |
| 6 | project(libnetconf2 C) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 7 | |
| 8 | # check the supported platform |
| 9 | if(NOT UNIX) |
| 10 | message(FATAL_ERROR "Only *nix like systems are supported.") |
| 11 | endif() |
| 12 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 13 | # set default build type if not specified by user |
| 14 | if(NOT CMAKE_BUILD_TYPE) |
| 15 | set(CMAKE_BUILD_TYPE debug) |
| 16 | endif() |
| 17 | |
| 18 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden") |
| 19 | set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") |
| 20 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 21 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 22 | # set version |
| 23 | set(LIBNETCONF2_MAJOR_VERSION 0) |
| 24 | set(LIBNETCONF2_MINOR_VERSION 0) |
| 25 | set(LIBNETCONF2_MICRO_VERSION 0) |
| 26 | set(LIBNETCONF2_VERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION}.${LIBNETCONF2_MICRO_VERSION}) |
| 27 | set(LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION}) |
| 28 | |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame^] | 29 | # build options |
| 30 | option(ENABLE_LIBSSH "Use libssh for NETCONF over SSH implementation" ON) |
| 31 | option(ENABLE_TLS "Enable NETCONF over TLS support (via OpenSSL)" OFF) |
| 32 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 33 | # source files |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 34 | set(libsrc |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 35 | src/datastore.c |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 36 | src/io.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 37 | src/log.c |
Radek Krejci | a53b3fe | 2015-10-19 17:25:04 +0200 | [diff] [blame] | 38 | src/messages.c |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 39 | src/session.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 40 | src/time.c) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 41 | |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame^] | 42 | if(ENABLE_LIBSSH) |
| 43 | set(libsrc ${libsrc} |
| 44 | src/session_ssh.c) |
| 45 | endif() |
| 46 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 47 | set(headers |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 48 | src/log.h |
| 49 | src/netconf.h |
| 50 | src/session.h |
| 51 | src/messages.h) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 52 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 53 | # libnetconf2 target |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 54 | add_library(netconf2 SHARED ${libsrc}) |
| 55 | set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 56 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 57 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
| 58 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 59 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 60 | else() |
| 61 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 62 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 63 | endif() |
| 64 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 65 | # dependencies - libssh |
| 66 | if(ENABLE_LIBSSH) |
| 67 | find_package(LibSSH 0.6.4 REQUIRED) |
| 68 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LIBSSH ${LIBSSH_DEFINITIONS}") |
| 69 | target_link_libraries(netconf2 ${LIBSSH_LIBRARIES}) |
| 70 | include_directories(${LIBSSH_INCLUDE_DIRS}) |
| 71 | endif() |
| 72 | |
| 73 | # dependencies - openssl |
| 74 | if(ENABLE_TLS) |
| 75 | find_package(OpenSSL REQUIRED) |
| 76 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS") |
| 77 | target_link_libraries(netconf2 ${OPENSSL_LIBRARIES}) |
| 78 | include_directories(${OPENSSL_INCLUDE_DIR}) |
| 79 | endif() |
| 80 | |
| 81 | # dependencies - libyang |
| 82 | find_package(LibYANG REQUIRED) |
| 83 | target_link_libraries(netconf2 ${LIBYANG_LIBRARIES}) |
| 84 | include_directories(${LIBYANG_INCLUDE_DIRS}) |
| 85 | |
| 86 | if(NOT LIB_INSTALL_DIR) |
Radek Krejci | b574e03 | 2015-10-21 14:19:12 +0200 | [diff] [blame] | 87 | set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 88 | endif() |
| 89 | |
| 90 | if(NOT INCLUDE_INSTALL_DIR) |
Radek Krejci | b574e03 | 2015-10-21 14:19:12 +0200 | [diff] [blame] | 91 | set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 92 | endif() |
| 93 | set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 94 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 95 | if(NOT DATA_INSTALL_DIR) |
| 96 | set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2) |
| 97 | endif() |
| 98 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 99 | # install library |
| 100 | install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR}) |
| 101 | |
| 102 | # install headers |
| 103 | install(FILES ${CMAKE_SOURCE_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 104 | install(FILES ${CMAKE_SOURCE_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 105 | install(FILES ${CMAKE_SOURCE_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 106 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR}) |
| 107 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 108 | # install schemas |
| 109 | install( |
| 110 | CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")" |
| 111 | CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})" |
| 112 | ) |
| 113 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 114 | if(ENABLE_VALGRIND_TESTS) |
| 115 | set(ENABLE_BUILD_TESTS ON) |
| 116 | endif() |
| 117 | |
| 118 | if(ENABLE_BUILD_TESTS) |
| 119 | enable_testing() |
| 120 | add_subdirectory(tests) |
| 121 | endif() |
| 122 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 123 | configure_file(src/config.h.in src/config.h) |
| 124 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 125 | # clean cmake cache |
| 126 | add_custom_target(cleancache |
| 127 | COMMAND make clean |
| 128 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + |
| 129 | COMMAND rm -rf Makefile Doxyfile |
| 130 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |