2017-02-01 13:45:48 +11:00
|
|
|
###############################################################################
|
|
|
|
## Search a (possibly empty) list of libraries for the library required to link
|
|
|
|
## against a given (extern C) symbol. Pass the list of libraries as variadic
|
|
|
|
## arguments to the macro.
|
|
|
|
##
|
|
|
|
## Operates analogously to autoconfs AC_SEARCH_LIBS.
|
|
|
|
##
|
|
|
|
## If the symbol is found the variable provided will be set to the required
|
|
|
|
## library, or cleared for no library. Sets variable_FOUND to true if the
|
|
|
|
## symbol was discovered in some capacity (to differentiate between no library
|
|
|
|
## required, and the symbol not being found)
|
|
|
|
##
|
|
|
|
## Does not work for C++ symbols.
|
|
|
|
|
2017-01-17 19:20:12 +11:00
|
|
|
macro(search_libs _variable _symbol)
|
2017-01-18 21:43:30 +11:00
|
|
|
if (NOT DEFINED __search_libs_${_symbol})
|
|
|
|
message (STATUS "searching for ${_symbol}")
|
2017-01-17 19:20:12 +11:00
|
|
|
|
2017-01-18 21:43:30 +11:00
|
|
|
if (NOT DEFINED __search_libs_${_symbol}_lib)
|
|
|
|
try_compile(
|
|
|
|
__search_libs_${_symbol}
|
|
|
|
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
|
|
|
SOURCES
|
2022-06-15 10:46:52 +10:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp"
|
2017-01-18 21:43:30 +11:00
|
|
|
COMPILE_DEFINITIONS
|
|
|
|
"-DSYMBOL=${_symbol}")
|
2017-01-17 19:20:12 +11:00
|
|
|
|
2017-01-18 21:43:30 +11:00
|
|
|
if (__search_libs_${_symbol})
|
2017-02-01 13:45:48 +11:00
|
|
|
set (__search_libs_${_symbol}_lib CACHE INTERNAL "library exposing ${_symbol}")
|
2017-01-18 21:43:30 +11:00
|
|
|
else ()
|
|
|
|
foreach (lib ${ARGN})
|
|
|
|
if (NOT __search_libs_${_symbol})
|
|
|
|
message (STATUS "searching for ${_symbol} in ${lib}")
|
|
|
|
|
|
|
|
try_compile(
|
|
|
|
__search_libs_${_symbol}
|
|
|
|
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
|
|
|
SOURCES
|
2022-06-15 10:46:52 +10:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/search_libs.cpp"
|
2017-01-18 21:43:30 +11:00
|
|
|
LINK_LIBRARIES
|
|
|
|
"${lib}"
|
|
|
|
COMPILE_DEFINITIONS
|
|
|
|
"-DSYMBOL=${_symbol}")
|
|
|
|
|
|
|
|
if (__search_libs_${_symbol})
|
|
|
|
set (__search_libs_${_symbol}_lib ${lib} CACHE INTERNAL "library exposing ${_symbol}")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endforeach()
|
2017-01-17 19:20:12 +11:00
|
|
|
endif ()
|
2017-01-18 21:43:30 +11:00
|
|
|
endif ()
|
2017-01-17 19:20:12 +11:00
|
|
|
|
2017-01-18 21:43:30 +11:00
|
|
|
if (__search_libs_${_symbol})
|
2017-01-17 19:20:12 +11:00
|
|
|
message (STATUS "searching for ${_symbol} - found")
|
2017-01-18 21:43:30 +11:00
|
|
|
else ()
|
|
|
|
message (STATUS "searching for ${_symbol} - not found")
|
|
|
|
endif()
|
2017-01-17 19:20:12 +11:00
|
|
|
endif ()
|
2017-01-18 21:43:30 +11:00
|
|
|
|
2017-02-01 13:36:43 +11:00
|
|
|
set (${_variable}_FOUND ${__search_libs_${_symbol}})
|
2017-01-18 21:43:30 +11:00
|
|
|
set (${_variable} ${__search_libs_${_symbol}_lib})
|
2017-01-17 19:20:12 +11:00
|
|
|
endmacro()
|