blob: faed0481bddc801bcdd3ef1622990bd0000beb1c [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)
Michal Vasko3d865d22016-01-28 16:00:53 +010010 message(FATAL_ERROR "Only *nix like systems are supported.")
Radek Krejci183f7e72015-09-01 17:25:47 +020011endif()
12
Radek Krejci183f7e72015-09-01 17:25:47 +020013# set default build type if not specified by user
14if(NOT CMAKE_BUILD_TYPE)
Michal Vasko3d865d22016-01-28 16:00:53 +010015 set(CMAKE_BUILD_TYPE debug)
Radek Krejci183f7e72015-09-01 17:25:47 +020016endif()
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)
Radek Krejci5bb46622016-01-19 14:34:00 +010024set(LIBNETCONF2_MINOR_VERSION 1)
Michal Vaskodb64c1c2016-01-28 16:23:06 +010025set(LIBNETCONF2_MICRO_VERSION 8)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020026set(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)
Michal Vasko3d865d22016-01-28 16:00:53 +010032option(ENABLE_DNSSEC "Enable support for SSHFP retrieval using DNSSEC for SSH (requires OpenSSL and libval)" OFF)
33
34if(ENABLE_DNSSEC AND NOT ENABLE_SSH)
35 message(WARNING "DNSSEC SSHFP retrieval cannot be used without SSH support.")
36 set(ENABLE_DNSSEC OFF)
37endif()
Radek Krejciac6d3472015-10-22 15:47:18 +020038
Radek Krejci4f2d40d2015-10-08 12:55:01 +020039# source files
Radek Krejci183f7e72015-09-01 17:25:47 +020040set(libsrc
Michal Vasko3d865d22016-01-28 16:00:53 +010041 src/io.c
42 src/log.c
43 src/messages_client.c
44 src/messages_server.c
45 src/session.c
46 src/session_client.c
47 src/session_server.c
48 src/time.c)
Radek Krejci183f7e72015-09-01 17:25:47 +020049
Michal Vaskofb2fb762015-10-27 11:44:32 +010050if(ENABLE_SSH)
Michal Vasko3d865d22016-01-28 16:00:53 +010051 set(libsrc ${libsrc}
52 src/session_client_ssh.c
53 src/session_server_ssh.c)
54 set(SSH_MACRO "#ifndef ENABLE_SSH\n#define ENABLE_SSH\n#endif")
Radek Krejciac6d3472015-10-22 15:47:18 +020055endif()
56
Radek Krejci9f03b482015-10-22 16:02:10 +020057if(ENABLE_TLS)
Michal Vasko3d865d22016-01-28 16:00:53 +010058 set(libsrc ${libsrc}
59 src/session_client_tls.c
60 src/session_server_tls.c)
61 set(TLS_MACRO "#ifndef ENABLE_TLS\n#define ENABLE_TLS\n#endif")
Radek Krejci9f03b482015-10-22 16:02:10 +020062endif()
63
Radek Krejci183f7e72015-09-01 17:25:47 +020064set(headers
Michal Vasko3d865d22016-01-28 16:00:53 +010065 src/log.h
66 src/netconf.h
67 src/session.h
68 src/messages_client.h
69 src/messages_server.h
70 src/session_client.h
Michal Vasko45f298f2016-01-29 10:26:26 +010071 src/session_client_ch.h
72 src/session_server.h
73 src/session_server_ch.h)
Radek Krejci183f7e72015-09-01 17:25:47 +020074
Radek Krejci4f2d40d2015-10-08 12:55:01 +020075# libnetconf2 target
Radek Krejci183f7e72015-09-01 17:25:47 +020076add_library(netconf2 SHARED ${libsrc})
77set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020078
Radek Krejcice24ab82015-10-08 15:37:02 +020079if(CMAKE_BUILD_TYPE STREQUAL debug)
Michal Vasko3d865d22016-01-28 16:00:53 +010080 option(ENABLE_BUILD_TESTS "Build tests" ON)
81 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
Radek Krejcice24ab82015-10-08 15:37:02 +020082else()
Michal Vasko3d865d22016-01-28 16:00:53 +010083 option(ENABLE_BUILD_TESTS "Build tests" OFF)
84 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
Radek Krejcice24ab82015-10-08 15:37:02 +020085endif()
86
Michal Vasko73ed9672016-01-29 13:15:15 +010087#dependencies - pthread
88set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
89find_package(Threads REQUIRED)
90target_link_libraries(netconf2 ${CMAKE_THREAD_LIBS_INIT})
91
Radek Krejci4f2d40d2015-10-08 12:55:01 +020092# dependencies - libssh
Michal Vaskofb2fb762015-10-27 11:44:32 +010093if(ENABLE_SSH)
Michal Vasko3d865d22016-01-28 16:00:53 +010094 find_package(LibSSH 0.6.4 REQUIRED)
95 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}")
96 target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads -lcrypt)
97 include_directories(${LIBSSH_INCLUDE_DIRS})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020098endif()
99
100# dependencies - openssl
Michal Vasko3d865d22016-01-28 16:00:53 +0100101if(ENABLE_TLS OR ENABLE_DNSSEC)
102 find_package(OpenSSL REQUIRED)
103 if (ENABLE_TLS)
104 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS")
105 endif()
106 target_link_libraries(netconf2 ${OPENSSL_LIBRARIES})
107 include_directories(${OPENSSL_INCLUDE_DIR})
108endif()
109
Michal Vasko73ed9672016-01-29 13:15:15 +0100110# dependencies - libval
Michal Vasko3d865d22016-01-28 16:00:53 +0100111if (ENABLE_DNSSEC)
112 find_package(LibVAL REQUIRED)
113 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_DNSSEC")
114 target_link_libraries(netconf2 ${LIBVAL_LIBRARIES})
115 include_directories(${LIBVAL_INCLUDE_DIRS})
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200116endif()
117
118# dependencies - libyang
119find_package(LibYANG REQUIRED)
120target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
121include_directories(${LIBYANG_INCLUDE_DIRS})
122
Michal Vasko51cda3c2016-01-29 14:41:26 +0100123# generate doxygen documentation for libnetconf2 API
124find_package(Doxygen)
125if(DOXYGEN_FOUND)
126 set(DOXYGEN_SKIP_DOT TRUE)
127 add_custom_target(doc
128 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
129 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
130 configure_file(Doxyfile.in Doxyfile)
131endif()
132
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200133if(NOT LIB_INSTALL_DIR)
Michal Vasko3d865d22016-01-28 16:00:53 +0100134 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200135endif()
136
137if(NOT INCLUDE_INSTALL_DIR)
Michal Vasko3d865d22016-01-28 16:00:53 +0100138 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200139endif()
140set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2)
Radek Krejci183f7e72015-09-01 17:25:47 +0200141
Radek Krejci14b14032015-10-21 15:19:43 +0200142if(NOT DATA_INSTALL_DIR)
Michal Vasko3d865d22016-01-28 16:00:53 +0100143 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2)
Radek Krejci14b14032015-10-21 15:19:43 +0200144endif()
145
Radek Krejci183f7e72015-09-01 17:25:47 +0200146# install library
147install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR})
148
149# install headers
Radek Krejci5fc4c392016-01-08 14:23:22 +0100150install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR})
151install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejci183f7e72015-09-01 17:25:47 +0200152install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR})
153
Radek Krejci14b14032015-10-21 15:19:43 +0200154# install schemas
155install(
Michal Vasko3d865d22016-01-28 16:00:53 +0100156 CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")"
157 CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})"
Radek Krejci14b14032015-10-21 15:19:43 +0200158)
159
Radek Krejcice24ab82015-10-08 15:37:02 +0200160if(ENABLE_VALGRIND_TESTS)
Michal Vasko3d865d22016-01-28 16:00:53 +0100161 set(ENABLE_BUILD_TESTS ON)
Radek Krejcice24ab82015-10-08 15:37:02 +0200162endif()
163
164if(ENABLE_BUILD_TESTS)
Michal Vasko3d865d22016-01-28 16:00:53 +0100165 enable_testing()
166 add_subdirectory(tests)
Radek Krejcice24ab82015-10-08 15:37:02 +0200167endif()
168
Radek Krejci68824962016-01-19 14:03:09 +0100169configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_SOURCE_DIR}/src/config.h" ESCAPE_QUOTES @ONLY)
Michal Vasko1128e112015-10-26 15:34:24 +0100170configure_file(nc_client.h.in nc_client.h)
Michal Vasko086311b2016-01-08 09:53:11 +0100171configure_file(nc_server.h.in nc_server.h)
Radek Krejci14b14032015-10-21 15:19:43 +0200172
Radek Krejci183f7e72015-09-01 17:25:47 +0200173# clean cmake cache
174add_custom_target(cleancache
175 COMMAND make clean
176 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
177 COMMAND rm -rf Makefile Doxyfile
178 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})