blob: 1077da40c5d3511cafbfd13e31d095c8ecc8ff58 [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
Michal Vasko7bcb48e2016-01-15 10:28:54 +010039 src/messages_client.c
40 src/messages_server.c
Radek Krejci206fcd62015-10-07 15:42:48 +020041 src/session.c
Michal Vasko086311b2016-01-08 09:53:11 +010042 src/session_client.c
43 src/session_server.c
Radek Krejcid0d19522015-09-02 13:49:25 +020044 src/time.c)
Radek Krejci183f7e72015-09-01 17:25:47 +020045
Michal Vaskofb2fb762015-10-27 11:44:32 +010046if(ENABLE_SSH)
Radek Krejciac6d3472015-10-22 15:47:18 +020047 set(libsrc ${libsrc}
Michal Vasko086311b2016-01-08 09:53:11 +010048 src/session_client_ssh.c
49 src/session_server_ssh.c)
50 set(SSH_MACRO "#ifndef ENABLE_SSH\n#define ENABLE_SSH\n#endif")
Radek Krejciac6d3472015-10-22 15:47:18 +020051endif()
52
Radek Krejci9f03b482015-10-22 16:02:10 +020053if(ENABLE_TLS)
54 set(libsrc ${libsrc}
Michal Vasko086311b2016-01-08 09:53:11 +010055 src/session_client_tls.c
56 src/session_server_tls.c)
57 set(TLS_MACRO "#ifndef ENABLE_TLS\n#define ENABLE_TLS\n#endif")
Radek Krejci9f03b482015-10-22 16:02:10 +020058endif()
59
Radek Krejci183f7e72015-09-01 17:25:47 +020060set(headers
Radek Krejci695d4fa2015-10-22 13:23:54 +020061 src/log.h
62 src/netconf.h
63 src/session.h
Michal Vasko086311b2016-01-08 09:53:11 +010064 src/session_client.h
65 src/session_server.h
Michal Vasko7bcb48e2016-01-15 10:28:54 +010066 src/messages.h
67 src/messages_client.h
68 src/messages_server.h)
Radek Krejci183f7e72015-09-01 17:25:47 +020069
Radek Krejci4f2d40d2015-10-08 12:55:01 +020070# libnetconf2 target
Radek Krejci183f7e72015-09-01 17:25:47 +020071add_library(netconf2 SHARED ${libsrc})
72set_target_properties(netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION} SOVERSION ${LIBNETCONF2_SOVERSION})
Radek Krejci4f2d40d2015-10-08 12:55:01 +020073
Radek Krejcice24ab82015-10-08 15:37:02 +020074if(CMAKE_BUILD_TYPE STREQUAL debug)
75 option(ENABLE_BUILD_TESTS "Build tests" ON)
76 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
77else()
78 option(ENABLE_BUILD_TESTS "Build tests" OFF)
79 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
80endif()
81
Radek Krejci4f2d40d2015-10-08 12:55:01 +020082# dependencies - libssh
Michal Vaskofb2fb762015-10-27 11:44:32 +010083if(ENABLE_SSH)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020084 find_package(LibSSH 0.6.4 REQUIRED)
Michal Vaskofb2fb762015-10-27 11:44:32 +010085 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}")
Michal Vasko086311b2016-01-08 09:53:11 +010086 target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads -lcrypt)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020087 include_directories(${LIBSSH_INCLUDE_DIRS})
88endif()
89
90# dependencies - openssl
91if(ENABLE_TLS)
92 find_package(OpenSSL REQUIRED)
93 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_TLS")
94 target_link_libraries(netconf2 ${OPENSSL_LIBRARIES})
95 include_directories(${OPENSSL_INCLUDE_DIR})
96endif()
97
98# dependencies - libyang
99find_package(LibYANG REQUIRED)
100target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
101include_directories(${LIBYANG_INCLUDE_DIRS})
102
103if(NOT LIB_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +0200104 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200105endif()
106
107if(NOT INCLUDE_INSTALL_DIR)
Radek Krejcib574e032015-10-21 14:19:12 +0200108 set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
Radek Krejci4f2d40d2015-10-08 12:55:01 +0200109endif()
110set(INCLUDE_INSTALL_SUBDIR ${INCLUDE_INSTALL_DIR}/libnetconf2)
Radek Krejci183f7e72015-09-01 17:25:47 +0200111
Radek Krejci14b14032015-10-21 15:19:43 +0200112if(NOT DATA_INSTALL_DIR)
113 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/libnetconf2)
114endif()
115
Radek Krejci183f7e72015-09-01 17:25:47 +0200116# install library
117install(TARGETS netconf2 DESTINATION ${LIB_INSTALL_DIR})
118
119# install headers
Radek Krejci5fc4c392016-01-08 14:23:22 +0100120install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${INCLUDE_INSTALL_DIR})
121install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_server.h DESTINATION ${INCLUDE_INSTALL_DIR})
122#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_transapi.h DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejci183f7e72015-09-01 17:25:47 +0200123install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR})
124
Radek Krejci14b14032015-10-21 15:19:43 +0200125# install schemas
126install(
127 CODE "file(GLOB yin_schemas \"${CMAKE_SOURCE_DIR}/schemas/*.yin\")"
128 CODE "file(INSTALL \${yin_schemas} DESTINATION ${DATA_INSTALL_DIR})"
129)
130
Radek Krejcice24ab82015-10-08 15:37:02 +0200131if(ENABLE_VALGRIND_TESTS)
132 set(ENABLE_BUILD_TESTS ON)
133endif()
134
135if(ENABLE_BUILD_TESTS)
136 enable_testing()
137 add_subdirectory(tests)
138endif()
139
Radek Krejci14b14032015-10-21 15:19:43 +0200140configure_file(src/config.h.in src/config.h)
Michal Vasko1128e112015-10-26 15:34:24 +0100141configure_file(nc_client.h.in nc_client.h)
Michal Vasko086311b2016-01-08 09:53:11 +0100142configure_file(nc_server.h.in nc_server.h)
Radek Krejci14b14032015-10-21 15:19:43 +0200143
Radek Krejci183f7e72015-09-01 17:25:47 +0200144# clean cmake cache
145add_custom_target(cleancache
146 COMMAND make clean
147 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
148 COMMAND rm -rf Makefile Doxyfile
149 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})