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) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 10 | message(FATAL_ERROR "Only *nix like systems are supported.") |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 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) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 15 | set(CMAKE_BUILD_TYPE debug) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 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) |
Radek Krejci | 5bb4662 | 2016-01-19 14:34:00 +0100 | [diff] [blame] | 24 | set(LIBNETCONF2_MINOR_VERSION 1) |
Michal Vasko | 715de3d | 2016-02-01 12:12:20 +0100 | [diff] [blame] | 25 | set(LIBNETCONF2_MICRO_VERSION 10) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 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 |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 30 | option(ENABLE_SSH "Enable NETCONF over SSH support (via libssh)" ON) |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 31 | option(ENABLE_TLS "Enable NETCONF over TLS support (via OpenSSL)" OFF) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 32 | option(ENABLE_DNSSEC "Enable support for SSHFP retrieval using DNSSEC for SSH (requires OpenSSL and libval)" OFF) |
| 33 | |
| 34 | if(ENABLE_DNSSEC AND NOT ENABLE_SSH) |
| 35 | message(WARNING "DNSSEC SSHFP retrieval cannot be used without SSH support.") |
| 36 | set(ENABLE_DNSSEC OFF) |
| 37 | endif() |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 38 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 39 | # source files |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 40 | set(libsrc |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 41 | src/io.c |
| 42 | src/log.c |
| 43 | src/messages_client.c |
| 44 | src/messages_server.c |
| 45 | src/session.c |
| 46 | src/session_client.c |
| 47 | src/session_server.c |
| 48 | src/time.c) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 49 | |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 50 | if(ENABLE_SSH) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 51 | set(libsrc ${libsrc} |
| 52 | src/session_client_ssh.c |
| 53 | src/session_server_ssh.c) |
| 54 | set(SSH_MACRO "#ifndef ENABLE_SSH\n#define ENABLE_SSH\n#endif") |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 55 | endif() |
| 56 | |
Radek Krejci | 9f03b48 | 2015-10-22 16:02:10 +0200 | [diff] [blame] | 57 | if(ENABLE_TLS) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 58 | set(libsrc ${libsrc} |
| 59 | src/session_client_tls.c |
| 60 | src/session_server_tls.c) |
| 61 | set(TLS_MACRO "#ifndef ENABLE_TLS\n#define ENABLE_TLS\n#endif") |
Radek Krejci | 9f03b48 | 2015-10-22 16:02:10 +0200 | [diff] [blame] | 62 | endif() |
| 63 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 64 | set(headers |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 65 | src/log.h |
| 66 | src/netconf.h |
| 67 | src/session.h |
| 68 | src/messages_client.h |
| 69 | src/messages_server.h |
| 70 | src/session_client.h |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 71 | src/session_client_ch.h |
| 72 | src/session_server.h |
| 73 | src/session_server_ch.h) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 74 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 75 | # libnetconf2 target |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 76 | add_library(netconf2 SHARED ${libsrc}) |
| 77 | set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 78 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 79 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 80 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 81 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 82 | else() |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 83 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 84 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 85 | endif() |
| 86 | |
Michal Vasko | 73ed967 | 2016-01-29 13:15:15 +0100 | [diff] [blame] | 87 | #dependencies - pthread |
| 88 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 89 | find_package(Threads REQUIRED) |
| 90 | target_link_libraries(netconf2 ${CMAKE_THREAD_LIBS_INIT}) |
| 91 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 92 | # dependencies - libssh |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 93 | if(ENABLE_SSH) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 94 | find_package(LibSSH 0.6.4 REQUIRED) |
| 95 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}") |
| 96 | target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads -lcrypt) |
| 97 | include_directories(${LIBSSH_INCLUDE_DIRS}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 98 | endif() |
| 99 | |
| 100 | # dependencies - openssl |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 101 | if(ENABLE_TLS OR ENABLE_DNSSEC) |
| 102 | find_package(OpenSSL REQUIRED) |
| 103 | if (ENABLE_TLS) |
| 104 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS") |
| 105 | endif() |
| 106 | target_link_libraries(netconf2 ${OPENSSL_LIBRARIES}) |
| 107 | include_directories(${OPENSSL_INCLUDE_DIR}) |
| 108 | endif() |
| 109 | |
Michal Vasko | 73ed967 | 2016-01-29 13:15:15 +0100 | [diff] [blame] | 110 | # dependencies - libval |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 111 | if (ENABLE_DNSSEC) |
| 112 | find_package(LibVAL REQUIRED) |
| 113 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_DNSSEC") |
| 114 | target_link_libraries(netconf2 ${LIBVAL_LIBRARIES}) |
| 115 | include_directories(${LIBVAL_INCLUDE_DIRS}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 116 | endif() |
| 117 | |
| 118 | # dependencies - libyang |
| 119 | find_package(LibYANG REQUIRED) |
| 120 | target_link_libraries(netconf2 ${LIBYANG_LIBRARIES}) |
| 121 | include_directories(${LIBYANG_INCLUDE_DIRS}) |
| 122 | |
Michal Vasko | 51cda3c | 2016-01-29 14:41:26 +0100 | [diff] [blame] | 123 | # generate doxygen documentation for libnetconf2 API |
| 124 | find_package(Doxygen) |
| 125 | if(DOXYGEN_FOUND) |
| 126 | set(DOXYGEN_SKIP_DOT TRUE) |
| 127 | add_custom_target(doc |
| 128 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile |
| 129 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 130 | configure_file(Doxyfile.in Doxyfile) |
| 131 | endif() |
| 132 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 133 | if(NOT LIB_INSTALL_DIR) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 134 | set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 135 | endif() |
| 136 | |
| 137 | if(NOT INCLUDE_INSTALL_DIR) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 138 | set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 139 | endif() |
| 140 | set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 141 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 142 | if(NOT DATA_INSTALL_DIR) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 143 | set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2) |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 144 | endif() |
| 145 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 146 | # install library |
| 147 | install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR}) |
| 148 | |
| 149 | # install headers |
Radek Krejci | 5fc4c39 | 2016-01-08 14:23:22 +0100 | [diff] [blame] | 150 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 151 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 152 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR}) |
| 153 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 154 | # install schemas |
| 155 | install( |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 156 | CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")" |
| 157 | CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})" |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 158 | ) |
| 159 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 160 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 161 | set(ENABLE_BUILD_TESTS ON) |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 162 | endif() |
| 163 | |
| 164 | if(ENABLE_BUILD_TESTS) |
Michal Vasko | 3d865d2 | 2016-01-28 16:00:53 +0100 | [diff] [blame] | 165 | enable_testing() |
| 166 | add_subdirectory(tests) |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 167 | endif() |
| 168 | |
Radek Krejci | 6882496 | 2016-01-19 14:03:09 +0100 | [diff] [blame] | 169 | configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_SOURCE_DIR}/src/config.h" ESCAPE_QUOTES @ONLY) |
Michal Vasko | 1128e11 | 2015-10-26 15:34:24 +0100 | [diff] [blame] | 170 | configure_file(nc_client.h.in nc_client.h) |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 171 | configure_file(nc_server.h.in nc_server.h) |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 172 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 173 | # clean cmake cache |
| 174 | add_custom_target(cleancache |
| 175 | COMMAND make clean |
| 176 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + |
| 177 | COMMAND rm -rf Makefile Doxyfile |
| 178 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |