blob: 3700c7c6496a19b68c9fb32884b41795c2e7a0e3 [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
Michal Vaskofb2fb762015-10-27 11:44:32 +010030option(ENABLE_SSH "Enable NETCONF over SSH support (via libssh)" ON)
Radek Krejciac6d3472015-10-22 15:47:18 +020031option(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
Michal Vasko086311b2016-01-08 09:53:11 +010040 src/session_client.c
41 src/session_server.c
Radek Krejcid0d19522015-09-02 13:49:25 +020042 src/time.c)
Radek Krejci183f7e72015-09-01 17:25:47 +020043
Michal Vaskofb2fb762015-10-27 11:44:32 +010044if(ENABLE_SSH)
Radek Krejciac6d3472015-10-22 15:47:18 +020045 set(libsrc ${libsrc}
Michal Vasko086311b2016-01-08 09:53:11 +010046 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 Krejciac6d3472015-10-22 15:47:18 +020049endif()
50
Radek Krejci9f03b482015-10-22 16:02:10 +020051if(ENABLE_TLS)
52 set(libsrc ${libsrc}
Michal Vasko086311b2016-01-08 09:53:11 +010053 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 Krejci9f03b482015-10-22 16:02:10 +020056endif()
57
Radek Krejci183f7e72015-09-01 17:25:47 +020058set(headers
Radek Krejci695d4fa2015-10-22 13:23:54 +020059 src/log.h
60 src/netconf.h
61 src/session.h
Michal Vasko086311b2016-01-08 09:53:11 +010062 src/session_client.h
63 src/session_server.h
Radek Krejci695d4fa2015-10-22 13:23:54 +020064 src/messages.h)
Radek Krejci183f7e72015-09-01 17:25:47 +020065
Radek Krejci4f2d40d2015-10-08 12:55:01 +020066# libnetconf2 target
Radek Krejci183f7e72015-09-01 17:25:47 +020067add_library(netconf2 SHARED ${libsrc})
68set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020069
Radek Krejcice24ab82015-10-08 15:37:02 +020070if(CMAKE_BUILD_TYPE STREQUAL debug)
71 option(ENABLE_BUILD_TESTS "Build tests" ON)
72 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
73else()
74 option(ENABLE_BUILD_TESTS "Build tests" OFF)
75 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
76endif()
77
Radek Krejci4f2d40d2015-10-08 12:55:01 +020078# dependencies - libssh
Michal Vaskofb2fb762015-10-27 11:44:32 +010079if(ENABLE_SSH)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020080 find_package(LibSSH 0.6.4 REQUIRED)
Michal Vaskofb2fb762015-10-27 11:44:32 +010081 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}")
Michal Vasko086311b2016-01-08 09:53:11 +010082 target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads -lcrypt)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020083 include_directories(${LIBSSH_INCLUDE_DIRS})
84endif()
85
86# dependencies - openssl
87if(ENABLE_TLS)
88 find_package(OpenSSL REQUIRED)
89 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS")
90 target_link_libraries(netconf2 ${OPENSSL_LIBRARIES})
91 include_directories(${OPENSSL_INCLUDE_DIR})
92endif()
93
94# dependencies - libyang
95find_package(LibYANG REQUIRED)
96target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
97include_directories(${LIBYANG_INCLUDE_DIRS})
98
99if(NOT LIB_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +0200100 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200101endif()
102
103if(NOT INCLUDE_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +0200104 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200105endif()
106set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2)
Radek Krejci183f7e72015-09-01 17:25:47 +0200107
Radek Krejci14b14032015-10-21 15:19:43 +0200108if(NOT DATA_INSTALL_DIR)
109 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2)
110endif()
111
Radek Krejci183f7e72015-09-01 17:25:47 +0200112# install library
113install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR})
114
115# install headers
116install(FILES ${CMAKE_SOURCE_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR})
117install(FILES ${CMAKE_SOURCE_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR})
118install(FILES ${CMAKE_SOURCE_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR})
119install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR})
120
Radek Krejci14b14032015-10-21 15:19:43 +0200121# install schemas
122install(
123 CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")"
124 CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})"
125)
126
Radek Krejcice24ab82015-10-08 15:37:02 +0200127if(ENABLE_VALGRIND_TESTS)
128 set(ENABLE_BUILD_TESTS ON)
129endif()
130
131if(ENABLE_BUILD_TESTS)
132 enable_testing()
133 add_subdirectory(tests)
134endif()
135
Radek Krejci14b14032015-10-21 15:19:43 +0200136configure_file(src/config.h.in src/config.h)
Michal Vasko1128e112015-10-26 15:34:24 +0100137configure_file(nc_client.h.in nc_client.h)
Michal Vasko086311b2016-01-08 09:53:11 +0100138configure_file(nc_server.h.in nc_server.h)
Radek Krejci14b14032015-10-21 15:19:43 +0200139
Radek Krejci183f7e72015-09-01 17:25:47 +0200140# clean cmake cache
141add_custom_target(cleancache
142 COMMAND make clean
143 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
144 COMMAND rm -rf Makefile Doxyfile
145 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})