blob: 89cd93ad5026b62984ec1b4d184cd3e24314429e [file] [log] [blame]
Radek Krejci2c22f122018-09-05 15:08:03 +02001# - Try to find LibYANG
2# Once done this will define
3#
4# LIBYANG_FOUND - system has LibYANG
5# LIBYANG_INCLUDE_DIRS - the LibYANG include directory
Michal Vasko0a5a3322021-04-15 07:59:25 +02006# LIBYANG_LIBRARIES - Link these to use LibYANG
7# LIBYANG_VERSION - SO version of the found libyang library
Radek Krejci2c22f122018-09-05 15:08:03 +02008#
Michal Vasko0a5a3322021-04-15 07:59:25 +02009# Author Michal Vasko <mvasko@cesnet.cz>
10# Copyright (c) 2021 CESNET, z.s.p.o.
Radek Krejci2c22f122018-09-05 15:08:03 +020011#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions
14# are met:
15#
16# 1. Redistributions of source code must retain the copyright
17# notice, this list of conditions and the following disclaimer.
18# 2. Redistributions in binary form must reproduce the copyright
19# notice, this list of conditions and the following disclaimer in the
20# documentation and/or other materials provided with the distribution.
Michal Vasko0a5a3322021-04-15 07:59:25 +020021# 3. The name of the author may not be used to endorse or promote products
Radek Krejci2c22f122018-09-05 15:08:03 +020022# derived from this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34#
Michal Vasko0a5a3322021-04-15 07:59:25 +020035include(FindPackageHandleStandardArgs)
Radek Krejci2c22f122018-09-05 15:08:03 +020036
Michal Vasko0a5a3322021-04-15 07:59:25 +020037if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
38 # in cache already
Radek Krejci2c22f122018-09-05 15:08:03 +020039 set(LIBYANG_FOUND TRUE)
Michal Vasko0a5a3322021-04-15 07:59:25 +020040else()
41 find_path(LIBYANG_INCLUDE_DIR
42 NAMES
43 libyang/libyang.h
44 PATHS
45 /usr/include
46 /usr/local/include
47 /opt/local/include
48 /sw/include
49 ${CMAKE_INCLUDE_PATH}
50 ${CMAKE_INSTALL_PREFIX}/include
51 )
Radek Krejci2c22f122018-09-05 15:08:03 +020052
Michal Vasko0a5a3322021-04-15 07:59:25 +020053 find_library(LIBYANG_LIBRARY
54 NAMES
55 yang
56 libyang
57 PATHS
58 /usr/lib
59 /usr/lib64
60 /usr/local/lib
61 /usr/local/lib64
62 /opt/local/lib
63 /sw/lib
64 ${CMAKE_LIBRARY_PATH}
65 ${CMAKE_INSTALL_PREFIX}/lib
66 )
Radek Krejci2c22f122018-09-05 15:08:03 +020067
Michal Vasko0a5a3322021-04-15 07:59:25 +020068 if(LIBYANG_INCLUDE_DIR)
69 find_path(LY_VERSION_PATH "libyang/version.h" HINTS ${LIBYANG_INCLUDE_DIR})
70 if(LY_VERSION_PATH)
71 file(READ "${LY_VERSION_PATH}/libyang/version.h" LY_VERSION_FILE)
72 else()
73 find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
74 file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_VERSION_FILE)
75 endif()
76 string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_VERSION_FILE}")
77 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
78 endif()
Radek Krejci2c22f122018-09-05 15:08:03 +020079
Michal Vasko0a5a3322021-04-15 07:59:25 +020080 set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
81 set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
82 mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
Radek Krejci2c22f122018-09-05 15:08:03 +020083
Michal Vasko0a5a3322021-04-15 07:59:25 +020084 # handle the QUIETLY and REQUIRED arguments and set LIBYANG_FOUND to TRUE
85 # if all listed variables are TRUE
86 find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND
87 REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR
88 VERSION_VAR LIBYANG_VERSION)
89endif()