blob: 89cd93ad5026b62984ec1b4d184cd3e24314429e [file] [log] [blame]
Radek Krejci4f2d40d2015-10-08 12:55:01 +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
Claus Klein22091912020-01-20 13:45:47 +01006# LIBYANG_LIBRARIES - Link these to use LibYANG
Michal Vaskob0f5e0e2020-05-05 11:59:17 +02007# LIBYANG_VERSION - SO version of the found libyang library
Radek Krejci4f2d40d2015-10-08 12:55:01 +02008#
Michal Vasko429a7472021-04-15 10:00:28 +02009# Author Michal Vasko <mvasko@cesnet.cz>
10# Copyright (c) 2021 CESNET, z.s.p.o.
Radek Krejci4f2d40d2015-10-08 12:55:01 +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.
Claus Klein22091912020-01-20 13:45:47 +010021# 3. The name of the author may not be used to endorse or promote products
Radek Krejci4f2d40d2015-10-08 12:55:01 +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 Vaskob0f5e0e2020-05-05 11:59:17 +020035include(FindPackageHandleStandardArgs)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020036
Claus Klein22091912020-01-20 13:45:47 +010037if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020038 # in cache already
Radek Krejci4f2d40d2015-10-08 12:55:01 +020039 set(LIBYANG_FOUND TRUE)
Michal Vaskob0f5e0e2020-05-05 11:59:17 +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 Krejci4f2d40d2015-10-08 12:55:01 +020052
Michal Vaskob0f5e0e2020-05-05 11:59:17 +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 Krejci4f2d40d2015-10-08 12:55:01 +020067
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020068 if(LIBYANG_INCLUDE_DIR)
Michal Vasko429a7472021-04-15 10:00:28 +020069 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}")
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020077 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
78 endif()
Claus Klein22091912020-01-20 13:45:47 +010079
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020080 set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
81 set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
82 mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020083
Michal Vasko429a7472021-04-15 10:00:28 +020084 # handle the QUIETLY and REQUIRED arguments and set LIBYANG_FOUND to TRUE
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020085 # 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)
Claus Klein22091912020-01-20 13:45:47 +010089endif()