blob: 3c7f0e9d1b44b26795f9a8cc897a9f388db7cca1 [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
Radek Krejciac6d3472015-10-22 15:47:18 +020029# build options
30option(ENABLE_LIBSSH "Use libssh for NETCONF over SSH implementation" ON)
31option(ENABLE_TLS "Enable NETCONF over TLS support (via OpenSSL)" OFF)
32
Radek Krejci4f2d40d2015-10-08 12:55:01 +020033# source files
Radek Krejci183f7e72015-09-01 17:25:47 +020034set(libsrc
Radek Krejci695d4fa2015-10-22 13:23:54 +020035 src/datastore.c
Radek Krejci206fcd62015-10-07 15:42:48 +020036 src/io.c
Radek Krejcid0d19522015-09-02 13:49:25 +020037 src/log.c
Radek Krejcia53b3fe2015-10-19 17:25:04 +020038 src/messages.c
Radek Krejci206fcd62015-10-07 15:42:48 +020039 src/session.c
Radek Krejcid0d19522015-09-02 13:49:25 +020040 src/time.c)
Radek Krejci183f7e72015-09-01 17:25:47 +020041
Radek Krejciac6d3472015-10-22 15:47:18 +020042if(ENABLE_LIBSSH)
43 set(libsrc ${libsrc}
44 src/session_ssh.c)
45endif()
46
Radek Krejci183f7e72015-09-01 17:25:47 +020047set(headers
Radek Krejci695d4fa2015-10-22 13:23:54 +020048 src/log.h
49 src/netconf.h
50 src/session.h
51 src/messages.h)
Radek Krejci183f7e72015-09-01 17:25:47 +020052
Radek Krejci4f2d40d2015-10-08 12:55:01 +020053# libnetconf2 target
Radek Krejci183f7e72015-09-01 17:25:47 +020054add_library(netconf2 SHARED ${libsrc})
55set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020056
Radek Krejcice24ab82015-10-08 15:37:02 +020057if(CMAKE_BUILD_TYPE STREQUAL debug)
58 option(ENABLE_BUILD_TESTS "Build tests" ON)
59 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
60else()
61 option(ENABLE_BUILD_TESTS "Build tests" OFF)
62 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
63endif()
64
Radek Krejci4f2d40d2015-10-08 12:55:01 +020065# dependencies - libssh
66if(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})
71endif()
72
73# dependencies - openssl
74if(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})
79endif()
80
81# dependencies - libyang
82find_package(LibYANG REQUIRED)
83target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
84include_directories(${LIBYANG_INCLUDE_DIRS})
85
86if(NOT LIB_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +020087 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020088endif()
89
90if(NOT INCLUDE_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +020091 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020092endif()
93set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2)
Radek Krejci183f7e72015-09-01 17:25:47 +020094
Radek Krejci14b14032015-10-21 15:19:43 +020095if(NOT DATA_INSTALL_DIR)
96 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2)
97endif()
98
Radek Krejci183f7e72015-09-01 17:25:47 +020099# install library
100install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR})
101
102# install headers
103install(FILES ${CMAKE_SOURCE_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR})
104install(FILES ${CMAKE_SOURCE_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR})
105install(FILES ${CMAKE_SOURCE_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR})
106install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR})
107
Radek Krejci14b14032015-10-21 15:19:43 +0200108# install schemas
109install(
110 CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")"
111 CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})"
112)
113
Radek Krejcice24ab82015-10-08 15:37:02 +0200114if(ENABLE_VALGRIND_TESTS)
115 set(ENABLE_BUILD_TESTS ON)
116endif()
117
118if(ENABLE_BUILD_TESTS)
119 enable_testing()
120 add_subdirectory(tests)
121endif()
122
Radek Krejci14b14032015-10-21 15:19:43 +0200123configure_file(src/config.h.in src/config.h)
124
Radek Krejci183f7e72015-09-01 17:25:47 +0200125# clean cmake cache
126add_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})