Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 1 | # - Try to find LibNETCONF2 |
| 2 | # Once done this will define |
| 3 | # |
| 4 | # LIBNETCONF2_FOUND - system has LibNETCONF2 |
| 5 | # LIBNETCONF2_INCLUDE_DIRS - the LibNETCONF2 include directory |
| 6 | # LIBNETCONF2_LIBRARIES - Link these to use LibNETCONF2 |
Michal Vasko | a20332f | 2021-11-09 12:41:21 +0100 | [diff] [blame] | 7 | # LIBNETCONF2_VERSION - SO version of the found libNETCONF2 library |
Radek Krejci | 97df27a | 2016-02-22 16:39:01 +0100 | [diff] [blame] | 8 | # LIBNETCONF2_ENABLED_SSH - LibNETCONF2 was compiled with SSH support |
| 9 | # LIBNETCONF2_ENABLED_TLS - LibNETCONF2 was compiled with TLS support |
Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 10 | # |
| 11 | # Author Michal Vasko <mvasko@cesnet.cz> |
Michal Vasko | a20332f | 2021-11-09 12:41:21 +0100 | [diff] [blame] | 12 | # Copyright (c) 2021 CESNET, z.s.p.o. |
Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 13 | # |
| 14 | # Redistribution and use in source and binary forms, with or without |
| 15 | # modification, are permitted provided that the following conditions |
| 16 | # are met: |
| 17 | # |
| 18 | # 1. Redistributions of source code must retain the copyright |
| 19 | # notice, this list of conditions and the following disclaimer. |
| 20 | # 2. Redistributions in binary form must reproduce the copyright |
| 21 | # notice, this list of conditions and the following disclaimer in the |
| 22 | # documentation and/or other materials provided with the distribution. |
| 23 | # 3. The name of the author may not be used to endorse or promote products |
| 24 | # derived from this software without specific prior written permission. |
| 25 | # |
| 26 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 27 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 28 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 29 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 30 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 31 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 32 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 33 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 35 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | # |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 37 | include(FindPackageHandleStandardArgs) |
Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 38 | |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 39 | if(LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS) |
| 40 | # in cache already |
Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 41 | set(LIBNETCONF2_FOUND TRUE) |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 42 | else() |
| 43 | find_path(LIBNETCONF2_INCLUDE_DIR |
| 44 | NAMES |
| 45 | nc_client.h |
| 46 | nc_server.h |
| 47 | PATHS |
| 48 | /usr/include |
| 49 | /usr/local/include |
| 50 | /opt/local/include |
| 51 | /sw/include |
| 52 | ${CMAKE_INCLUDE_PATH} |
| 53 | ${CMAKE_INSTALL_PREFIX}/include |
| 54 | ) |
| 55 | |
| 56 | find_library(LIBNETCONF2_LIBRARY |
| 57 | NAMES |
| 58 | netconf2 |
| 59 | libnetconf2 |
| 60 | PATHS |
| 61 | /usr/lib |
| 62 | /usr/lib64 |
| 63 | /usr/local/lib |
| 64 | /usr/local/lib64 |
| 65 | /opt/local/lib |
| 66 | /sw/lib |
| 67 | ${CMAKE_LIBRARY_PATH} |
| 68 | ${CMAKE_INSTALL_PREFIX}/lib |
| 69 | ) |
| 70 | |
Michal Vasko | a20332f | 2021-11-09 12:41:21 +0100 | [diff] [blame] | 71 | if(LIBNETCONF2_INCLUDE_DIR) |
| 72 | find_path(NC_VERSION_PATH "nc_version.h" HINTS ${LIBNETCONF2_INCLUDE_DIR}) |
| 73 | if(NOT NC_VERSION_PATH) |
| 74 | message(STATUS "libnetconf2 version header not found, assuming libnetconf2 is too old and cannot be used!") |
| 75 | set(LIBNETCONF2_INCLUDE_DIR "LIBNETCONF2_INCLUDE_DIR-NOTFOUND") |
| 76 | set(LIBNETCONF2_LIBRARY "LIBNETCONF2_LIBRARY-NOTFOUND") |
| 77 | else() |
| 78 | file(READ "${NC_VERSION_PATH}/nc_version.h" NC_VERSION_FILE) |
| 79 | string(REGEX MATCH "#define NC_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" NC_VERSION_MACRO "${NC_VERSION_FILE}") |
| 80 | string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBNETCONF2_VERSION "${NC_VERSION_MACRO}") |
| 81 | endif() |
| 82 | endif() |
| 83 | |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 84 | set(LIBNETCONF2_INCLUDE_DIRS ${LIBNETCONF2_INCLUDE_DIR}) |
| 85 | set(LIBNETCONF2_LIBRARIES ${LIBNETCONF2_LIBRARY}) |
| 86 | mark_as_advanced(LIBNETCONF2_INCLUDE_DIRS LIBNETCONF2_LIBRARIES) |
| 87 | |
| 88 | # handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE |
| 89 | # if all listed variables are TRUE |
Michal Vasko | a20332f | 2021-11-09 12:41:21 +0100 | [diff] [blame] | 90 | find_package_handle_standard_args(LibNETCONF2 FOUND_VAR LIBNETCONF2_FOUND |
| 91 | REQUIRED_VARS LIBNETCONF2_LIBRARY LIBNETCONF2_INCLUDE_DIR |
| 92 | VERSION_VAR LIBNETCONF2_VERSION) |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 93 | |
Michal Vasko | 2d304e3 | 2016-07-26 15:44:16 +0200 | [diff] [blame] | 94 | # check the configured options and make them available through cmake |
| 95 | list(INSERT CMAKE_REQUIRED_INCLUDES 0 "${LIBNETCONF2_INCLUDE_DIR}") |
Radek Krejci | 97df27a | 2016-02-22 16:39:01 +0100 | [diff] [blame] | 96 | check_symbol_exists("NC_ENABLED_SSH" "nc_client.h" LIBNETCONF2_ENABLED_SSH) |
| 97 | check_symbol_exists("NC_ENABLED_TLS" "nc_client.h" LIBNETCONF2_ENABLED_TLS) |
Michal Vasko | 2d304e3 | 2016-07-26 15:44:16 +0200 | [diff] [blame] | 98 | list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0) |
Michal Vasko | b0f5e0e | 2020-05-05 11:59:17 +0200 | [diff] [blame] | 99 | endif() |
Michal Vasko | 1130880 | 2016-02-17 14:11:05 +0100 | [diff] [blame] | 100 | |