11cmake_minimum_required (VERSION 2.6)
22
33project (libnetconf2 C)
4+ set (LIBNETCONF2_DESC "NETCONF library in C providing API for both clients and servers." )
5+
6+ # include custom Modules
7+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /CMakeModules/" )
48
59include (GNUInstallDirs)
610include (CheckFunctionExists)
711include (CheckCSourceCompiles)
812include (CheckIncludeFile)
13+ include (UseCompat)
914
1015if (POLICY CMP0075)
1116 cmake_policy (SET CMP0075 NEW)
1217endif ()
1318
14- # include custom Modules
15- list (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /CMakeModules/" )
16-
1719set (LIBNETCONF2_DESCRIPTION "NETCONF server and client library in C." )
1820
1921# check the supported platform
@@ -24,9 +26,6 @@ endif()
2426# osx specific
2527set (CMAKE_MACOSX_RPATH TRUE )
2628
27- set (INCLUDE_INSTALL_SUBDIR ${CMAKE_INSTALL_INCLUDEDIR} /libnetconf2)
28- set (DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR} /libnetconf2)
29-
3029# set default build type if not specified by user
3130if (NOT CMAKE_BUILD_TYPE )
3231 set (CMAKE_BUILD_TYPE Debug)
@@ -43,15 +42,15 @@ set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
4342# micro version is changed with a set of small changes or bugfixes anywhere in the project.
4443set (LIBNETCONF2_MAJOR_VERSION 1)
4544set (LIBNETCONF2_MINOR_VERSION 1)
46- set (LIBNETCONF2_MICRO_VERSION 7 )
45+ set (LIBNETCONF2_MICRO_VERSION 24 )
4746set (LIBNETCONF2_VERSION ${LIBNETCONF2_MAJOR_VERSION} .${LIBNETCONF2_MINOR_VERSION} .${LIBNETCONF2_MICRO_VERSION} )
4847
4948# Version of the library
5049# Major version is changed with every backward non-compatible API/ABI change in libyang, minor version changes
5150# with backward compatible change and micro version is connected with any internal change of the library.
5251set (LIBNETCONF2_MAJOR_SOVERSION 1)
53- set (LIBNETCONF2_MINOR_SOVERSION 2 )
54- set (LIBNETCONF2_MICRO_SOVERSION 1 )
52+ set (LIBNETCONF2_MINOR_SOVERSION 3 )
53+ set (LIBNETCONF2_MICRO_SOVERSION 5 )
5554set (LIBNETCONF2_SOVERSION_FULL ${LIBNETCONF2_MAJOR_SOVERSION} .${LIBNETCONF2_MINOR_SOVERSION} .${LIBNETCONF2_MICRO_SOVERSION} )
5655set (LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_SOVERSION} )
5756
@@ -64,93 +63,13 @@ set(READ_INACTIVE_TIMEOUT 20 CACHE STRING "Maximum number of seconds waiting for
6463set (READ_ACTIVE_TIMEOUT 300 CACHE STRING "Maximum number of seconds for receiving a full message" )
6564set (MAX_PSPOLL_THREAD_COUNT 6 CACHE STRING "Maximum number of threads that could simultaneously access a ps_poll structure" )
6665set (TIMEOUT_STEP 100 CACHE STRING "Number of microseconds tasks are repeated until timeout elapses" )
67- set (SCHEMAS_DIR "${CMAKE_INSTALL_PREFIX} /${DATA_INSTALL_DIR} " CACHE STRING "Directory with internal lnc2 schemas " )
66+ set (YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX} /share/yang/modules " CACHE STRING "Directory with common YANG modules " )
6867
6968if (ENABLE_DNSSEC AND NOT ENABLE_SSH)
7069 message (WARNING "DNSSEC SSHFP retrieval cannot be used without SSH support." )
7170 set (ENABLE_DNSSEC OFF )
7271endif ()
7372
74- if (ENABLE_SSH)
75- find_library (LIBCRYPT crypt)
76- if (LIBCRYPT STREQUAL LIBCRYPT-NOTFOUND )
77- message (WARNING "LIBCRYPT not found! SSH, and TLS support disabled." )
78- set (ENABLE_SSH OFF )
79- set (ENABLE_TLS OFF )
80- endif ()
81- endif ()
82-
83- # package options
84- find_program (DEB_BUILDER NAMES debuild)
85- find_program (RPM_BUILDER NAMES rpmbuild)
86-
87- if (NOT DEFINED ENV{TRAVIS_BRANCH})
88- execute_process (COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD"
89- OUTPUT_VARIABLE GIT_BRANCH
90- OUTPUT_STRIP_TRAILING_WHITESPACE
91- ERROR_QUIET
92- )
93- if (NOT GIT_BRANCH)
94- set (ENV{TRAVIS_BRANCH} "master" )
95- else ()
96- if (GIT_BRANCH MATCHES "master|devel" )
97- set (ENV{TRAVIS_BRANCH} ${GIT_BRANCH} )
98- else ()
99- set (ENV{TRAVIS_BRANCH} "master" )
100- endif ()
101- endif ()
102-
103- set (GIT_BRANCH $ENV{TRAVIS_BRANCH} ) # NOTE: used for configure_file too
104- endif ()
105-
106- if (GIT_BRANCH STREQUAL master)
107- set (PACKAGE_NAME "libnetconf2" )
108- set (BRANCH "master" )
109- set (BUILD_TYPE "Package" )
110- set (CONFLICT_PACKAGE_NAME "libnetconf2-experimental" )
111- set (PACKAGE_PART_NAME "" )
112- else ()
113- set (PACKAGE_NAME "libnetconf2-experimental" )
114- set (BRANCH "devel" )
115- set (BUILD_TYPE "Debug" )
116- set (CONFLICT_PACKAGE_NAME "libnetconf2" )
117- set (PACKAGE_PART_NAME "-experimental" )
118- endif ()
119- # change version in config files
120- configure_file (${PROJECT_SOURCE_DIR} /packages/libnetconf2.spec.in ${PROJECT_BINARY_DIR} /build -packages/libnetconf2.spec)
121- configure_file (${PROJECT_SOURCE_DIR} /packages/libnetconf2.dsc.in ${PROJECT_BINARY_DIR} /build -packages/libnetconf2.dsc)
122- configure_file (${PROJECT_SOURCE_DIR} /packages/debian.control.in ${PROJECT_BINARY_DIR} /build -packages/debian.control @ONLY)
123- configure_file (${PROJECT_SOURCE_DIR} /packages/debian.rules.in ${PROJECT_BINARY_DIR} /build -packages/debian.rules)
124- configure_file (${PROJECT_SOURCE_DIR} /packages/debian.libnetconf2-dev.install
125- ${PROJECT_BINARY_DIR} /build -packages/debian.libnetconf2${PACKAGE_PART_NAME} -dev.install COPYONLY )
126- configure_file (${PROJECT_SOURCE_DIR} /packages/debian.libnetconf2.install
127- ${PROJECT_BINARY_DIR} /build -packages/debian.libnetconf2${PACKAGE_PART_NAME} .install COPYONLY )
128- configure_file (${PROJECT_SOURCE_DIR} /packages/debian.python3-netconf2.install
129- ${PROJECT_BINARY_DIR} /build -packages/debian.python3-netconf2${PACKAGE_PART_NAME} .install COPYONLY )
130-
131- if (NOT DEB_BUILDER)
132- message (WARNING "Missing tools (devscripts, debhelper package) for building deb package.\n You won't be able to generate deb package from source code.\n Compiling libnetconf2 should still works fine." )
133- else ()
134- # target for local build deb package
135- add_custom_target (build -deb
136- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
137- COMMAND build -packages/local-deb.sh
138- )
139- configure_file (${PROJECT_SOURCE_DIR} /packages/local-deb.sh.in ${PROJECT_BINARY_DIR} /build -packages/local-deb.sh @ONLY)
140- endif ()
141-
142- if (NOT RPM_BUILDER)
143- message (WARNING "Missing tools (rpm package) for building rpm package. \n You won't be able to generate rpm package from source code.\n Compiling libnetconf2 should still work fine." )
144- else ()
145- # target for local build rpm package
146- string (REPLACE ${PROJECT_SOURCE_DIR} "." EXCLUDE_BUILD_DIR ${PROJECT_BINARY_DIR} )
147- add_custom_target (build -rpm
148- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
149- COMMAND build -packages/local-rpm.sh
150- )
151- configure_file (${PROJECT_SOURCE_DIR} /packages/local-rpm.sh.in ${PROJECT_BINARY_DIR} /build -packages/local-rpm.sh @ONLY)
152- endif ()
153-
15473include_directories (${PROJECT_BINARY_DIR} /src)
15574
15675# source files
@@ -190,9 +109,12 @@ set(headers
190109 src/session_server.h
191110 src/session_server_ch.h)
192111
112+ # use compat
113+ use_compat()
114+
193115# netconf2 target
194- add_library (netconf2 SHARED ${libsrc} ${headers} )
195- set_target_properties (netconf2 PROPERTIES VERSION ${LIBNETCONF2_VERSION } SOVERSION ${LIBNETCONF2_SOVERSION_FULL } )
116+ add_library (netconf2 SHARED ${libsrc} ${headers} $<TARGET_OBJECTS:compat> )
117+ set_target_properties (netconf2 PROPERTIES VERSION ${LIBNETCONF2_SOVERSION_FULL } SOVERSION ${LIBNETCONF2_SOVERSION } )
196118
197119if ((CMAKE_BUILD_TYPE STREQUAL Debug) OR (CMAKE_BUILD_TYPE STREQUAL Package))
198120 option (ENABLE_BUILD_TESTS "Build tests" ON )
@@ -221,29 +143,38 @@ if(ENABLE_TLS OR ENABLE_DNSSEC OR ENABLE_SSH)
221143 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNC_ENABLED_TLS" )
222144 endif ()
223145
224- #TODO target_link_libraries(netconf2 PUBLIC OpenSSL::SSL OpenSSL::Crypto)
225146 target_link_libraries (netconf2 ${OPENSSL_LIBRARIES} )
226147 include_directories (${OPENSSL_INCLUDE_DIR} )
227148endif ()
228149
229150# dependencies - libssh
230151if (ENABLE_SSH)
231- set (LIBSSH_FIND_VERSION 0.7.0)
232- find_package (LibSSH REQUIRED)
152+ find_package (LibSSH 0.7.0 REQUIRED)
233153 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNC_ENABLED_SSH" )
234- message (STATUS "LibSSH version ${LIBSSH_VERSION } found" )
154+ message (STATUS "LibSSH version ${LibSSH_VERSION } found" )
235155
236- if (LIBSSH_VERSION VERSION_EQUAL 0.9.3)
237- message (FATAL_ERROR "LIBSSH 0.9.3 includes regression bugs and libnetconf2 will NOT work properly, try to use an older version" )
156+ if (LibSSH_VERSION VERSION_EQUAL 0.9.3 OR LibSSH_VERSION VERSION_EQUAL 0.9.4 )
157+ message (FATAL_ERROR "LibSSH ${LibSSH_VERSION} includes regression bugs and libnetconf2 will NOT work properly, try to use another version" )
238158 endif ()
239159
240- if (LIBSSH_VERSION VERSION_LESS 0.8.0)
241- target_link_libraries (netconf2 "-L${LIBSSH_LIBRARY_DIR} " -lssh -lssh_threads -lcrypt)
160+ if (LibSSH_VERSION VERSION_LESS 0.8.0)
161+ target_link_libraries (netconf2 "-L${LIBSSH_LIBRARY_DIR} " -lssh -lssh_threads)
162+ list (APPEND CMAKE_REQUIRED_FLAGS "-L${LIBSSH_LIBRARY_DIR} " )
163+ list (APPEND CMAKE_REQUIRED_LIBRARIES ssh ssh_threads)
242164 else ()
243- target_link_libraries (netconf2 "-L ${LIBSSH_LIBRARY_DIR} " -lssh -lcrypt )
244- set ( CMAKE_REQUIRED_LIBRARIES "ssh;crypt" )
165+ target_link_libraries (netconf2 ${LIBSSH_LIBRARIES} )
166+ list ( APPEND CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LIBRARIES} )
245167 endif ()
246168 include_directories (${LIBSSH_INCLUDE_DIRS} )
169+
170+ # crypt
171+ if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX" )
172+ target_link_libraries (netconf2 -lcrypt)
173+ list (APPEND CMAKE_REQUIRED_LIBRARIES crypt)
174+ else ()
175+ target_link_libraries (netconf2 -llogin)
176+ list (APPEND CMAKE_REQUIRED_LIBRARIES login)
177+ endif ()
247178endif ()
248179
249180# dependencies - libval
@@ -259,6 +190,20 @@ find_package(LibYANG REQUIRED)
259190target_link_libraries (netconf2 ${LIBYANG_LIBRARIES} )
260191include_directories (${LIBYANG_INCLUDE_DIRS} )
261192
193+ # header file compatibility - shadow.h and crypt.h
194+ check_include_file("shadow.h" HAVE_SHADOW)
195+ check_include_file("crypt.h" HAVE_CRYPT)
196+
197+ # function compatibility - getpeereid on QNX
198+ if (${CMAKE_SYSTEM_NAME} MATCHES "QNX" )
199+ target_link_libraries (netconf2 -lsocket)
200+ list (APPEND CMAKE_REQUIRED_LIBRARIES socket)
201+ list (REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES pthread)
202+ list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_QNX_SOURCE)
203+ check_symbol_exists(getpeereid "sys/types.h;unistd.h" HAVE_GETPEEREID)
204+ list (REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_QNX_SOURCE)
205+ endif ()
206+
262207# generate doxygen documentation for libnetconf2 API
263208find_package (Doxygen)
264209if (DOXYGEN_FOUND)
@@ -274,19 +219,16 @@ if(ENABLE_PYTHON)
274219 add_subdirectory (python)
275220endif ()
276221
222+ # packages
223+ add_subdirectory (packages)
224+
277225# install library
278226install (TARGETS netconf2 DESTINATION ${CMAKE_INSTALL_LIBDIR} )
279227
280228# install headers
281229install (FILES ${CMAKE_CURRENT_BINARY_DIR} /nc_client.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
282230install (FILES ${CMAKE_CURRENT_BINARY_DIR} /nc_server.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
283- install (FILES ${headers} DESTINATION ${INCLUDE_INSTALL_SUBDIR} )
284-
285- # install schemas
286- install (
287- CODE "file(GLOB yin_schemas \" ${CMAKE_SOURCE_DIR} /schemas/*.yin\" )"
288- CODE "file(INSTALL \$ {yin_schemas} DESTINATION ${CMAKE_INSTALL_PREFIX} /${DATA_INSTALL_DIR} )"
289- )
231+ install (FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /libnetconf2)
290232
291233# install pkg-config file
292234find_package (PkgConfig)
0 commit comments