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 |
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) |
| 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 | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 35 | src/io.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 36 | src/log.c |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 37 | src/messages_client.c |
| 38 | src/messages_server.c |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 39 | src/session.c |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 40 | src/session_client.c |
| 41 | src/session_server.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 42 | src/time.c) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 43 | |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 44 | if(ENABLE_SSH) |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 45 | set(libsrc ${libsrc} |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 46 | src/session_client_ssh.c |
| 47 | src/session_server_ssh.c) |
| 48 | set(SSH_MACRO "#ifndef ENABLE_SSH\n#define ENABLE_SSH\n#endif") |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 49 | endif() |
| 50 | |
Radek Krejci | 9f03b48 | 2015-10-22 16:02:10 +0200 | [diff] [blame] | 51 | if(ENABLE_TLS) |
| 52 | set(libsrc ${libsrc} |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 53 | src/session_client_tls.c |
| 54 | src/session_server_tls.c) |
| 55 | set(TLS_MACRO "#ifndef ENABLE_TLS\n#define ENABLE_TLS\n#endif") |
Radek Krejci | 9f03b48 | 2015-10-22 16:02:10 +0200 | [diff] [blame] | 56 | endif() |
| 57 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 58 | set(headers |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 59 | src/log.h |
| 60 | src/netconf.h |
| 61 | src/session.h |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 62 | src/messages_client.h |
Michal Vasko | 495c946 | 2016-01-15 11:27:43 +0100 | [diff] [blame] | 63 | src/messages_server.h |
| 64 | src/session_client.h |
| 65 | src/session_server.h) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 66 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 67 | # libnetconf2 target |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 68 | add_library(netconf2 SHARED ${libsrc}) |
| 69 | set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 70 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 71 | if(CMAKE_BUILD_TYPE STREQUAL debug) |
| 72 | option(ENABLE_BUILD_TESTS "Build tests" ON) |
| 73 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON) |
| 74 | else() |
| 75 | option(ENABLE_BUILD_TESTS "Build tests" OFF) |
| 76 | option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF) |
| 77 | endif() |
| 78 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 79 | # dependencies - libssh |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 80 | if(ENABLE_SSH) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 81 | find_package(LibSSH 0.6.4 REQUIRED) |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 82 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}") |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 83 | target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads -lcrypt) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 84 | include_directories(${LIBSSH_INCLUDE_DIRS}) |
| 85 | endif() |
| 86 | |
| 87 | # dependencies - openssl |
| 88 | if(ENABLE_TLS) |
| 89 | find_package(OpenSSL REQUIRED) |
| 90 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS") |
| 91 | target_link_libraries(netconf2 ${OPENSSL_LIBRARIES}) |
| 92 | include_directories(${OPENSSL_INCLUDE_DIR}) |
| 93 | endif() |
| 94 | |
| 95 | # dependencies - libyang |
| 96 | find_package(LibYANG REQUIRED) |
| 97 | target_link_libraries(netconf2 ${LIBYANG_LIBRARIES}) |
| 98 | include_directories(${LIBYANG_INCLUDE_DIRS}) |
| 99 | |
| 100 | if(NOT LIB_INSTALL_DIR) |
Radek Krejci | b574e03 | 2015-10-21 14:19:12 +0200 | [diff] [blame] | 101 | set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 102 | endif() |
| 103 | |
| 104 | if(NOT INCLUDE_INSTALL_DIR) |
Radek Krejci | b574e03 | 2015-10-21 14:19:12 +0200 | [diff] [blame] | 105 | set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 106 | endif() |
| 107 | set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 108 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 109 | if(NOT DATA_INSTALL_DIR) |
| 110 | set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2) |
| 111 | endif() |
| 112 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 113 | # install library |
| 114 | install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR}) |
| 115 | |
| 116 | # install headers |
Radek Krejci | 5fc4c39 | 2016-01-08 14:23:22 +0100 | [diff] [blame] | 117 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 118 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 119 | #install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 120 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR}) |
| 121 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 122 | # install schemas |
| 123 | install( |
| 124 | CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")" |
| 125 | CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})" |
| 126 | ) |
| 127 | |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 128 | if(ENABLE_VALGRIND_TESTS) |
| 129 | set(ENABLE_BUILD_TESTS ON) |
| 130 | endif() |
| 131 | |
| 132 | if(ENABLE_BUILD_TESTS) |
| 133 | enable_testing() |
| 134 | add_subdirectory(tests) |
| 135 | endif() |
| 136 | |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 137 | configure_file(src/config.h.in src/config.h) |
Michal Vasko | 1128e11 | 2015-10-26 15:34:24 +0100 | [diff] [blame] | 138 | configure_file(nc_client.h.in nc_client.h) |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 139 | configure_file(nc_server.h.in nc_server.h) |
Radek Krejci | 14b1403 | 2015-10-21 15:19:43 +0200 | [diff] [blame] | 140 | |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 141 | # clean cmake cache |
| 142 | add_custom_target(cleancache |
| 143 | COMMAND make clean |
| 144 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + |
| 145 | COMMAND rm -rf Makefile Doxyfile |
| 146 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |