Skip to content

Commit a20332f

Browse files
committed
build FEATURE new separate version header
1 parent 95ea9ff commit a20332f

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,15 @@ endif()
285285
configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_BINARY_DIR}/src/config.h" ESCAPE_QUOTES @ONLY)
286286
configure_file(nc_client.h.in nc_client.h)
287287
configure_file(nc_server.h.in nc_server.h)
288+
configure_file(nc_version.h.in nc_version.h)
288289

289290
# install library
290291
install(TARGETS netconf2 DESTINATION ${CMAKE_INSTALL_LIBDIR})
291292

292293
# install headers
293294
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_client.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
294295
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_server.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
296+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nc_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
295297
install(FILES ${headers} ${PROJECT_BINARY_DIR}/src/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libnetconf2)
296298

297299
# install pkg-config file

FindLibNETCONF2.cmake

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
# LIBNETCONF2_FOUND - system has LibNETCONF2
55
# LIBNETCONF2_INCLUDE_DIRS - the LibNETCONF2 include directory
66
# LIBNETCONF2_LIBRARIES - Link these to use LibNETCONF2
7+
# LIBNETCONF2_VERSION - SO version of the found libNETCONF2 library
78
# LIBNETCONF2_ENABLED_SSH - LibNETCONF2 was compiled with SSH support
89
# LIBNETCONF2_ENABLED_TLS - LibNETCONF2 was compiled with TLS support
910
#
1011
# Author Michal Vasko <[email protected]>
11-
# Copyright (c) 2020 CESNET, z.s.p.o.
12+
# Copyright (c) 2021 CESNET, z.s.p.o.
1213
#
1314
# Redistribution and use in source and binary forms, with or without
1415
# modification, are permitted provided that the following conditions
@@ -34,7 +35,6 @@
3435
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3536
#
3637
include(FindPackageHandleStandardArgs)
37-
include(CheckSymbolExists)
3838

3939
if(LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS)
4040
# in cache already
@@ -68,13 +68,28 @@ else()
6868
${CMAKE_INSTALL_PREFIX}/lib
6969
)
7070

71+
if(LIBNETCONF2_INCLUDE_DIR)
72+
find_path(NC_VERSION_PATH "nc_version.h" HINTS ${LIBNETCONF2_INCLUDE_DIR})
73+
if(NOT NC_VERSION_PATH)
74+
message(STATUS "libnetconf2 version header not found, assuming libnetconf2 is too old and cannot be used!")
75+
set(LIBNETCONF2_INCLUDE_DIR "LIBNETCONF2_INCLUDE_DIR-NOTFOUND")
76+
set(LIBNETCONF2_LIBRARY "LIBNETCONF2_LIBRARY-NOTFOUND")
77+
else()
78+
file(READ "${NC_VERSION_PATH}/nc_version.h" NC_VERSION_FILE)
79+
string(REGEX MATCH "#define NC_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" NC_VERSION_MACRO "${NC_VERSION_FILE}")
80+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBNETCONF2_VERSION "${NC_VERSION_MACRO}")
81+
endif()
82+
endif()
83+
7184
set(LIBNETCONF2_INCLUDE_DIRS ${LIBNETCONF2_INCLUDE_DIR})
7285
set(LIBNETCONF2_LIBRARIES ${LIBNETCONF2_LIBRARY})
7386
mark_as_advanced(LIBNETCONF2_INCLUDE_DIRS LIBNETCONF2_LIBRARIES)
7487

7588
# handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE
7689
# if all listed variables are TRUE
77-
find_package_handle_standard_args(LibNETCONF2 DEFAULT_MSG LIBNETCONF2_LIBRARY LIBNETCONF2_INCLUDE_DIR)
90+
find_package_handle_standard_args(LibNETCONF2 FOUND_VAR LIBNETCONF2_FOUND
91+
REQUIRED_VARS LIBNETCONF2_LIBRARY LIBNETCONF2_INCLUDE_DIR
92+
VERSION_VAR LIBNETCONF2_VERSION)
7893

7994
# check the configured options and make them available through cmake
8095
list(INSERT CMAKE_REQUIRED_INCLUDES 0 "${LIBNETCONF2_INCLUDE_DIR}")

nc_version.h.in

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file nc_version.h
3+
* @author Michal Vasko <[email protected]>
4+
* @brief libnetconf2 version information
5+
*
6+
* @copyright
7+
* Copyright (c) 2021 CESNET, z.s.p.o.
8+
*
9+
* This source code is licensed under BSD 3-Clause License (the "License").
10+
* You may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* https://opensource.org/licenses/BSD-3-Clause
14+
*/
15+
16+
#ifndef NC_VERSION_H_
17+
#define NC_VERSION_H_
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#define NC_VERSION_MAJOR @LIBNETCONF2_MAJOR_SOVERSION@ /**< libnetconf2 major version number */
24+
#define NC_VERSION_MINOR @LIBNETCONF2_MINOR_SOVERSION@ /**< libnetconf2 minor version number */
25+
#define NC_VERSION_MICRO @LIBNETCONF2_MICRO_SOVERSION@ /**< libnetconf2 micro version number */
26+
#define NC_VERSION "@LIBNETCONF2_SOVERSION_FULL@" /**< libnetconf2 version string */
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif /* NC_VERSION_H_ */

0 commit comments

Comments
 (0)