blob: 5655db34c2e419ecb96bc6cb8e49e97bfa04648d [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 Vaskoadbf0152020-05-06 16:23:33 +02009# LIBYANG_CPP_FOUND - system has LibYANG C++ bindings
10# LIBYANG_CPP_INCLUDE_DIRS - the LibYANG C++ include directory
11# LIBYANG_CPP_LIBRARIES - Link these to use LibYANG C++ bindings
12#
Radek Krejci4f2d40d2015-10-08 12:55:01 +020013# Author Radek Krejci <rkrejci@cesnet.cz>
14# Copyright (c) 2015 CESNET, z.s.p.o.
15#
16# Redistribution and use in source and binary forms, with or without
17# modification, are permitted provided that the following conditions
18# are met:
19#
20# 1. Redistributions of source code must retain the copyright
21# notice, this list of conditions and the following disclaimer.
22# 2. Redistributions in binary form must reproduce the copyright
23# notice, this list of conditions and the following disclaimer in the
24# documentation and/or other materials provided with the distribution.
Claus Klein22091912020-01-20 13:45:47 +010025# 3. The name of the author may not be used to endorse or promote products
Radek Krejci4f2d40d2015-10-08 12:55:01 +020026# derived from this software without specific prior written permission.
27#
28# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38#
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020039include(FindPackageHandleStandardArgs)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020040
Claus Klein22091912020-01-20 13:45:47 +010041if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020042 # in cache already
Radek Krejci4f2d40d2015-10-08 12:55:01 +020043 set(LIBYANG_FOUND TRUE)
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020044else()
45 find_path(LIBYANG_INCLUDE_DIR
46 NAMES
47 libyang/libyang.h
48 PATHS
49 /usr/include
50 /usr/local/include
51 /opt/local/include
52 /sw/include
53 ${CMAKE_INCLUDE_PATH}
54 ${CMAKE_INSTALL_PREFIX}/include
55 )
Radek Krejci4f2d40d2015-10-08 12:55:01 +020056
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020057 find_library(LIBYANG_LIBRARY
58 NAMES
59 yang
60 libyang
61 PATHS
62 /usr/lib
63 /usr/lib64
64 /usr/local/lib
65 /usr/local/lib64
66 /opt/local/lib
67 /sw/lib
68 ${CMAKE_LIBRARY_PATH}
69 ${CMAKE_INSTALL_PREFIX}/lib
70 )
Radek Krejci4f2d40d2015-10-08 12:55:01 +020071
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020072 if(LIBYANG_INCLUDE_DIR)
73 find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
74 file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_HEADER)
75 string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_HEADER}")
76 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
77 endif()
Claus Klein22091912020-01-20 13:45:47 +010078
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020079 set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
80 set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
81 mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
Radek Krejci4f2d40d2015-10-08 12:55:01 +020082
Michal Vaskoadbf0152020-05-06 16:23:33 +020083 # handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE
Michal Vaskob0f5e0e2020-05-05 11:59:17 +020084 # if all listed variables are TRUE
85 find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND
86 REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR
87 VERSION_VAR LIBYANG_VERSION)
Claus Klein22091912020-01-20 13:45:47 +010088endif()
Michal Vaskoadbf0152020-05-06 16:23:33 +020089
90#C++ bindings
91if (LIBYANG_CPP_LIBRARIES AND LIBYANG_CPP_INCLUDE_DIRS)
92 # in cache already
93 set(LIBYANG_CPP_FOUND TRUE)
94else ()
95 find_path(LIBYANG_CPP_INCLUDE_DIR
96 NAMES
97 libyang/Libyang.hpp
98 PATHS
99 /usr/include
100 /usr/local/include
101 /opt/local/include
102 /sw/include
103 ${CMAKE_INCLUDE_PATH}
104 ${CMAKE_INSTALL_PREFIX}/include
105 )
106
107 find_library(LIBYANG_CPP_LIBRARY
108 NAMES
109 yang-cpp
110 libyang-cpp
111 PATHS
112 /usr/lib
113 /usr/lib64
114 /usr/local/lib
115 /usr/local/lib64
116 /opt/local/lib
117 /sw/lib
118 ${CMAKE_LIBRARY_PATH}
119 ${CMAKE_INSTALL_PREFIX}/lib
120 )
121
122 if (LIBYANG_CPP_INCLUDE_DIR AND LIBYANG_CPP_LIBRARY)
123 set(LIBYANG_CPP_FOUND TRUE)
124 else ()
125 set(LIBYANG_CPP_FOUND FALSE)
126 endif ()
127
128 set(LIBYANG_CPP_INCLUDE_DIRS ${LIBYANG_CPP_INCLUDE_DIR})
129 set(LIBYANG_CPP_LIBRARIES ${LIBYANG_CPP_LIBRARY})
130
131 # show the LIBYANG_CPP_INCLUDE_DIRS and LIBYANG_CPP_LIBRARIES variables only in the advanced view
132 mark_as_advanced(LIBYANG_CPP_INCLUDE_DIRS LIBYANG_CPP_LIBRARIES)
133endif()