cmake/search_libs.cmake

48 lines
1.7 KiB
CMake

macro(search_libs _variable _symbol)
if (NOT DEFINED __search_libs_${_symbol})
message (STATUS "searching for ${_symbol}")
if (NOT DEFINED __search_libs_${_symbol}_lib)
try_compile(
__search_libs_${_symbol}
"${CMAKE_BINARY_DIR}/CMakeTmp"
SOURCES
"${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
COMPILE_DEFINITIONS
"-DSYMBOL=${_symbol}")
if (__search_libs_${_symbol})
set (__search_libs_${_symbol}_lib)
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
"${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
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()
endif ()
endif ()
if (__search_libs_${_symbol})
message (STATUS "searching for ${_symbol} - found")
else ()
message (STATUS "searching for ${_symbol} - not found")
endif()
endif ()
set (${_variable} ${__search_libs_${_symbol}_lib})
endmacro()