cmake/search_libs.cmake
2017-01-17 19:20:12 +11:00

40 lines
1.5 KiB
CMake

# search a list of libraries for a given (C linkage) _symbol. returns the
# required library in _variable, and defines HAVE_SYMBOL if it was found.
macro(search_libs _variable _symbol)
message (STATUS "searching for ${_symbol}")
try_compile(
__search_libs_${_symbol}
"${CMAKE_BINARY_DIR}/CMakeTmp"
SOURCES "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}")
if (NOT __search_libs_${_symbol})
foreach (lib ${ARGN})
if (NOT __search_libs_${_symbol}_last)
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 "-l${lib}"
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}")
set (__search_libs_${_symbol}_last ${lib})
endif ()
endforeach()
endif()
if (__search_libs_${_symbol})
if (__search_libs_${_symbol}_last)
message (STATUS "searching for ${_symbol} - found (in ${__search_libs_${_symbol}_last})")
else ()
message (STATUS "searching for ${_symbol} - found")
endif ()
set (${_variable} __search_libs_${_symbol}_last)
string (TOUPPER ${_symbol} upper_symbol)
set (HAVE_${upper_symbol} 1)
else ()
message (STATUS "searching for ${_symbol} - not found")
endif ()
endmacro()