| 1 |
# Copyright (C) Alexander Lamaison <[email protected]> |
| 2 |
# |
| 3 |
# Redistribution and use in source and binary forms, |
| 4 |
# with or without modification, are permitted provided |
| 5 |
# that the following conditions are met: |
| 6 |
# |
| 7 |
# Redistributions of source code must retain the above |
| 8 |
# copyright notice, this list of conditions and the |
| 9 |
# following disclaimer. |
| 10 |
# |
| 11 |
# Redistributions in binary form must reproduce the above |
| 12 |
# copyright notice, this list of conditions and the following |
| 13 |
# disclaimer in the documentation and/or other materials |
| 14 |
# provided with the distribution. |
| 15 |
# |
| 16 |
# Neither the name of the copyright holder nor the names |
| 17 |
# of any other contributors may be used to endorse or |
| 18 |
# promote products derived from this software without |
| 19 |
# specific prior written permission. |
| 20 |
# |
| 21 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 22 |
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 23 |
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 |
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 26 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 28 |
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 29 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 30 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 31 |
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 |
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 33 |
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
| 34 |
# OF SUCH DAMAGE. |
| 35 |
# |
| 36 |
# SPDX-License-Identifier: BSD-3-Clause |
| 37 |
|
| 38 |
|
| 39 |
# - check_function_exists_maybe_need_library(<function> <var> [lib1 ... libn]) |
| 40 |
# |
| 41 |
# Check if function is available for linking, first without extra libraries, and |
| 42 |
# then, if not found that way, linking in each optional library as well. This |
| 43 |
# function is similar to autotools AC_SEARCH_LIBS. |
| 44 |
# |
| 45 |
# If the function if found, this will define <var>. |
| 46 |
# |
| 47 |
# If the function was only found by linking in an additional library, this |
| 48 |
# will define NEED_LIB_LIBX, where LIBX is the one of lib1 to libn that |
| 49 |
# makes the function available, in uppercase. |
| 50 |
# |
| 51 |
# The following variables may be set before calling this macro to |
| 52 |
# modify the way the check is run: |
| 53 |
# |
| 54 |
# CMAKE_REQUIRED_FLAGS = string of compile command line flags |
| 55 |
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) |
| 56 |
# CMAKE_REQUIRED_INCLUDES = list of include directories |
| 57 |
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link |
| 58 |
# |
| 59 |
|
| 60 |
include(CheckFunctionExists) |
| 61 |
include(CheckLibraryExists) |
| 62 |
|
| 63 |
function(check_function_exists_may_need_library _function _variable) |
| 64 |
|
| 65 |
check_function_exists(${_function} ${_variable}) |
| 66 |
|
| 67 |
if(NOT ${_variable}) |
| 68 |
foreach(_lib IN LISTS ARGN) |
| 69 |
string(TOUPPER ${_lib} _up_lib) |
| 70 |
# Use new variable to prevent cache from previous step shortcircuiting |
| 71 |
# new test |
| 72 |
check_library_exists(${_lib} ${_function} "" HAVE_${_function}_IN_${_lib}) |
| 73 |
if(HAVE_${_function}_IN_${_lib}) |
| 74 |
set(${_variable} 1 CACHE INTERNAL "Function ${_function} found in library ${_lib}") |
| 75 |
set(NEED_LIB_${_up_lib} 1 CACHE INTERNAL "Need to link ${_lib}") |
| 76 |
break() |
| 77 |
endif() |
| 78 |
endforeach() |
| 79 |
endif() |
| 80 |
|
| 81 |
endfunction() |