Skip to content

Commit aaaada2

Browse files
committed
Merge branch 'devel'
2 parents a7c8a81 + 9d8abaf commit aaaada2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+6668
-427
lines changed

CMakeLists.txt

Lines changed: 51 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
cmake_minimum_required(VERSION 2.6)
22

33
project(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

59
include(GNUInstallDirs)
610
include(CheckFunctionExists)
711
include(CheckCSourceCompiles)
812
include(CheckIncludeFile)
13+
include(UseCompat)
914

1015
if(POLICY CMP0075)
1116
cmake_policy(SET CMP0075 NEW)
1217
endif()
1318

14-
# include custom Modules
15-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules/")
16-
1719
set(LIBNETCONF2_DESCRIPTION "NETCONF server and client library in C.")
1820

1921
# check the supported platform
@@ -24,9 +26,6 @@ endif()
2426
# osx specific
2527
set(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
3130
if(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.
4443
set(LIBNETCONF2_MAJOR_VERSION 1)
4544
set(LIBNETCONF2_MINOR_VERSION 1)
46-
set(LIBNETCONF2_MICRO_VERSION 7)
45+
set(LIBNETCONF2_MICRO_VERSION 24)
4746
set(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.
5251
set(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)
5554
set(LIBNETCONF2_SOVERSION_FULL ${LIBNETCONF2_MAJOR_SOVERSION}.${LIBNETCONF2_MINOR_SOVERSION}.${LIBNETCONF2_MICRO_SOVERSION})
5655
set(LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_SOVERSION})
5756

@@ -64,93 +63,13 @@ set(READ_INACTIVE_TIMEOUT 20 CACHE STRING "Maximum number of seconds waiting for
6463
set(READ_ACTIVE_TIMEOUT 300 CACHE STRING "Maximum number of seconds for receiving a full message")
6564
set(MAX_PSPOLL_THREAD_COUNT 6 CACHE STRING "Maximum number of threads that could simultaneously access a ps_poll structure")
6665
set(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

6968
if(ENABLE_DNSSEC AND NOT ENABLE_SSH)
7069
message(WARNING "DNSSEC SSHFP retrieval cannot be used without SSH support.")
7170
set(ENABLE_DNSSEC OFF)
7271
endif()
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.\nYou won't be able to generate deb package from source code.\nCompiling 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. \nYou won't be able to generate rpm package from source code.\nCompiling 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-
15473
include_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

197119
if((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})
227148
endif()
228149

229150
# dependencies - libssh
230151
if(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()
247178
endif()
248179

249180
# dependencies - libval
@@ -259,6 +190,20 @@ find_package(LibYANG REQUIRED)
259190
target_link_libraries(netconf2 ${LIBYANG_LIBRARIES})
260191
include_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
263208
find_package(Doxygen)
264209
if(DOXYGEN_FOUND)
@@ -274,19 +219,16 @@ if(ENABLE_PYTHON)
274219
add_subdirectory(python)
275220
endif()
276221

222+
# packages
223+
add_subdirectory(packages)
224+
277225
# install library
278226
install(TARGETS netconf2 DESTINATION ${CMAKE_INSTALL_LIBDIR})
279227

280228
# install headers
281229
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
282230
install(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
292234
find_package(PkgConfig)

CMakeModules/FindLibSSH.cmake

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# LIBSSH_FOUND - system has LibSSH
55
# LIBSSH_INCLUDE_DIRS - the LibSSH include directory
66
# LIBSSH_LIBRARY_DIR - the LibSSH library directory
7+
# LIBSSH_LIBRARIES - link these to use LibSSH
78
#
89
# Copyright (c) 2009 Andreas Schneider <asn@cryptomilk.org>
910
#
@@ -31,7 +32,7 @@
3132
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3233
#
3334

34-
if(LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS)
35+
if(LIBSSH_LIBRARY_DIR AND LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)
3536
# in cache already
3637
set(LIBSSH_FOUND TRUE)
3738
else()
@@ -63,12 +64,13 @@ else()
6364
)
6465

6566
if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY)
66-
set(LIBSSH_FOUND TRUE)
67+
set(SSH_FOUND TRUE)
6768
endif()
6869

6970
set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR})
71+
set(LIBSSH_LIBRARIES ${LIBSSH_LIBRARY})
7072

71-
if(LIBSSH_FOUND)
73+
if (SSH_FOUND)
7274
string(REPLACE "libssh.so" ""
7375
LIBSSH_LIBRARY_DIR
7476
${LIBSSH_LIBRARY}
@@ -82,23 +84,23 @@ else()
8284
${LIBSSH_LIBRARY_DIR}
8385
)
8486

85-
if(LIBSSH_FIND_VERSION)
87+
if (LibSSH_FIND_VERSION)
8688
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MAJOR
8789
REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+")
8890
# Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR
89-
if(LIBSSH_VERSION_MAJOR)
91+
if (LIBSSH_VERSION_MAJOR)
9092
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR})
9193
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR
92-
REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+")
94+
REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+")
9395
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR})
9496
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH
95-
REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+")
97+
REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+")
9698
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH})
9799

98-
set(LIBSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})
100+
set(LibSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})
99101

100102
include(FindPackageVersionCheck)
101-
find_package_version_check(LIBSSH DEFAULT_MSG)
103+
find_package_version_check(LibSSH DEFAULT_MSG)
102104
else()
103105
message(STATUS "LIBSSH_VERSION_MAJOR not found in ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h, assuming libssh is too old")
104106
set(LIBSSH_FOUND FALSE)
@@ -111,11 +113,11 @@ else()
111113
# so we need this if() here.
112114
if(LIBSSH_FOUND)
113115
include(FindPackageHandleStandardArgs)
114-
find_package_handle_standard_args(LIBSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS)
116+
find_package_handle_standard_args(LibSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS)
115117
endif()
116118

117-
# show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARY_DIR variables only in the advanced view
118-
mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARY_DIR)
119+
# show the LIBSSH_INCLUDE_DIRS, LIBSSH_LIBRARIES, and LIBSSH_LIBRARY_DIR variables only in the advanced view
120+
mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARY_DIR LIBSSH_LIBRARIES)
119121

120122
endif()
121123

0 commit comments

Comments
 (0)