blob: 5655db34c2e419ecb96bc6cb8e49e97bfa04648d [file] [log] [blame]
Michal Vaskob11c70c2020-05-05 11:58:13 +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
6# LIBYANG_LIBRARIES - Link these to use LibYANG
7# LIBYANG_VERSION - SO version of the found libyang library
8#
Michal Vasko0599d132020-05-06 16:25:22 +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#
Michal Vaskob11c70c2020-05-05 11:58:13 +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.
25# 3. The name of the author may not be used to endorse or promote products
26# 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#
39include(FindPackageHandleStandardArgs)
40
41if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
42 # in cache already
43 set(LIBYANG_FOUND TRUE)
44else()
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 )
56
57 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 )
71
72 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()
78
79 set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
80 set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
81 mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
82
Michal Vasko0599d132020-05-06 16:25:22 +020083 # handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE
Michal Vaskob11c70c2020-05-05 11:58:13 +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)
88endif()
Michal Vasko0599d132020-05-06 16:25:22 +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()