cmake FEATURE full-featured cmake find file
#
# LIBYANG_FOUND - system has LibYANG
# LIBYANG_INCLUDE_DIRS - the LibYANG include directory
-# LIBYANG_LIBRARIES - Link these to use LibSSH
+# LIBYANG_LIBRARIES - Link these to use LibYANG
+# LIBYANG_VERSION - SO version of the found libyang library
#
-# Author Radek Krejci <rkrejci@cesnet.cz>
-# Copyright (c) 2015 CESNET, z.s.p.o.
+# Author Michal Vasko <mvasko@cesnet.cz>
+# Copyright (c) 2021 CESNET, z.s.p.o.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
+include(FindPackageHandleStandardArgs)
if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
# in cache already
set(LIBYANG_FOUND TRUE)
-else (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
-
+else()
find_path(LIBYANG_INCLUDE_DIR
NAMES
libyang/libyang.h
@@ -64,17 +65,25 @@ else (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
${CMAKE_INSTALL_PREFIX}/lib
)
- if (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
- set(LIBYANG_FOUND TRUE)
- else (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
- set(LIBYANG_FOUND FALSE)
- endif (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
+ if(LIBYANG_INCLUDE_DIR)
+ find_path(LY_VERSION_PATH "libyang/version.h" HINTS ${LIBYANG_INCLUDE_DIR})
+ if(LY_VERSION_PATH)
+ file(READ "${LY_VERSION_PATH}/libyang/version.h" LY_VERSION_FILE)
+ else()
+ find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
+ file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_VERSION_FILE)
+ endif()
+ string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_VERSION_FILE}")
+ string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
+ endif()
set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
-
- # show the LIBYANG_INCLUDE_DIRS and LIBYANG_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
-endif (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
-
+ # handle the QUIETLY and REQUIRED arguments and set LIBYANG_FOUND to TRUE
+ # if all listed variables are TRUE
+ find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND
+ REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR
+ VERSION_VAR LIBYANG_VERSION)
+endif()
