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 | |
| 29 | # source files |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 30 | set(libsrc |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 31 | src/io.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 32 | src/log.c |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 33 | src/session.c |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 34 | src/time.c) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 35 | |
| 36 | set(headers |
| 37 | src/log.h) |
| 38 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame^] | 39 | # libnetconf2 target |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 40 | add_library(netconf2 SHARED ${libsrc}) |
| 41 | set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame^] | 42 | |
| 43 | # build options |
| 44 | option(ENABLE_LIBSSH "Use libssh for NETCONF over SSH implementation" ON) |
| 45 | option(ENABLE_TLS "Enable NETCONF over TLS support (via OpenSSL)" OFF) |
| 46 | |
| 47 | # dependencies - libssh |
| 48 | if(ENABLE_LIBSSH) |
| 49 | find_package(LibSSH 0.6.4 REQUIRED) |
| 50 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LIBSSH ${LIBSSH_DEFINITIONS}") |
| 51 | target_link_libraries(netconf2 ${LIBSSH_LIBRARIES}) |
| 52 | include_directories(${LIBSSH_INCLUDE_DIRS}) |
| 53 | endif() |
| 54 | |
| 55 | # dependencies - openssl |
| 56 | if(ENABLE_TLS) |
| 57 | find_package(OpenSSL REQUIRED) |
| 58 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS") |
| 59 | target_link_libraries(netconf2 ${OPENSSL_LIBRARIES}) |
| 60 | include_directories(${OPENSSL_INCLUDE_DIR}) |
| 61 | endif() |
| 62 | |
| 63 | # dependencies - libyang |
| 64 | find_package(LibYANG REQUIRED) |
| 65 | target_link_libraries(netconf2 ${LIBYANG_LIBRARIES}) |
| 66 | include_directories(${LIBYANG_INCLUDE_DIRS}) |
| 67 | |
| 68 | if(NOT LIB_INSTALL_DIR) |
| 69 | set(LIB_INSTALL_DIR lib) |
| 70 | endif() |
| 71 | |
| 72 | if(NOT INCLUDE_INSTALL_DIR) |
| 73 | set(INCLUDE_INSTALL_DIR include) |
| 74 | endif() |
| 75 | set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2) |
Radek Krejci | 183f7e7 | 2015-09-01 17:25:47 +0200 | [diff] [blame] | 76 | |
| 77 | # install library |
| 78 | install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR}) |
| 79 | |
| 80 | # install headers |
| 81 | install(FILES ${CMAKE_SOURCE_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 82 | install(FILES ${CMAKE_SOURCE_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 83 | install(FILES ${CMAKE_SOURCE_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR}) |
| 84 | install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR}) |
| 85 | |
| 86 | # clean cmake cache |
| 87 | add_custom_target(cleancache |
| 88 | COMMAND make clean |
| 89 | COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + |
| 90 | COMMAND rm -rf Makefile Doxyfile |
| 91 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |