blob: 6eec4a36e77b14d451087a503632b46219f90862 [file] [log] [blame]
Radek Krejci183f7e72015-09-01 17:25:47 +02001cmake_minimum_required(VERSION 2.8)
Radek Krejci183f7e72015-09-01 17:25:47 +02002
Radek Krejci4f2d40d2015-10-08 12:55:01 +02003# include custom Modules
4set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
5
6project(libnetconf2 C)
Radek Krejci183f7e72015-09-01 17:25:47 +02007
8# check the supported platform
9if(NOT UNIX)
10 message(FATAL_ERROR "Only *nix like systems are supported.")
11endif()
12
Radek Krejci183f7e72015-09-01 17:25:47 +020013# set default build type if not specified by user
14if(NOT CMAKE_BUILD_TYPE)
15 set(CMAKE_BUILD_TYPE debug)
16endif()
17
18set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden")
19set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
20set(CMAKE_C_FLAGS_DEBUG "-g -O0")
21
Radek Krejci4f2d40d2015-10-08 12:55:01 +020022# set version
23set(LIBNETCONF2_MAJOR_VERSION 0)
24set(LIBNETCONF2_MINOR_VERSION 0)
25set(LIBNETCONF2_MICRO_VERSION 0)
26set(LIBNETCONF2_VERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION}.${LIBNETCONF2_MICRO_VERSION})
27set(LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION})
28
29# source files
Radek Krejci183f7e72015-09-01 17:25:47 +020030set(libsrc
Radek Krejci206fcd62015-10-07 15:42:48 +020031 src/io.c
Radek Krejcid0d19522015-09-02 13:49:25 +020032 src/log.c
Radek Krejci206fcd62015-10-07 15:42:48 +020033 src/session.c
Radek Krejcid0d19522015-09-02 13:49:25 +020034 src/time.c)
Radek Krejci183f7e72015-09-01 17:25:47 +020035
36set(headers
37 src/log.h)
38
Radek Krejci4f2d40d2015-10-08 12:55:01 +020039# libnetconf2 target
Radek Krejci183f7e72015-09-01 17:25:47 +020040add_library(netconf2 SHARED ${libsrc})
41set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020042
43# build options
44option(ENABLE_LIBSSH "Use libssh for NETCONF over SSH implementation" ON)
45option(ENABLE_TLS "Enable NETCONF over TLS support (via OpenSSL)" OFF)
46
47# dependencies - libssh
48if(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})
53endif()
54
55# dependencies - openssl
56if(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})
61endif()
62
63# dependencies - libyang
64find_package(LibYANG REQUIRED)
65target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
66include_directories(${LIBYANG_INCLUDE_DIRS})
67
68if(NOT LIB_INSTALL_DIR)
69 set(LIB_INSTALL_DIR lib)
70endif()
71
72if(NOT INCLUDE_INSTALL_DIR)
73 set(INCLUDE_INSTALL_DIR include)
74endif()
75set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2)
Radek Krejci183f7e72015-09-01 17:25:47 +020076
77# install library
78install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR})
79
80# install headers
81install(FILES ${CMAKE_SOURCE_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR})
82install(FILES ${CMAKE_SOURCE_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR})
83install(FILES ${CMAKE_SOURCE_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR})
84install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR})
85
86# clean cmake cache
87add_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})