cmake: use check_symbol_exists to check dlopen + need for dl library

This commit is contained in:
Anonymous Maarten 2022-09-27 01:08:04 +02:00 committed by Ozkan Sezer
parent 4e375996d3
commit bfecd78159
2 changed files with 10 additions and 18 deletions

View File

@ -65,6 +65,7 @@ include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
include(CheckStructHasMember) include(CheckStructHasMember)
include(CMakeDependentOption) include(CMakeDependentOption)
include(CMakePushCheckState)
include(FindPkgConfig) include(FindPkgConfig)
include(GNUInstallDirs) include(GNUInstallDirs)
set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")

View File

@ -30,28 +30,19 @@ macro(FindLibraryAndSONAME _LIB)
endmacro() endmacro()
macro(CheckDLOPEN) macro(CheckDLOPEN)
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN) cmake_push_check_state(RESET)
if(NOT HAVE_DLOPEN) check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBC)
check_library_exists(dl dlopen "" DLOPEN_LIB) if(NOT HAVE_DLOPEN_IN_LIBC)
if(DLOPEN_LIB) set(CMAKE_REQUIRED_LIBRARIES dl)
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBDL)
if(HAVE_DLOPEN_IN_LIBDL)
list(APPEND EXTRA_LIBS dl) list(APPEND EXTRA_LIBS dl)
set(_DLLIB dl)
set(HAVE_DLOPEN TRUE)
endif() endif()
endif() endif()
if(HAVE_DLOPEN) if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL)
if(_DLLIB) set(HAVE_DLOPEN TRUE)
set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
endif()
check_c_source_compiles("
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle = dlopen(\"\", RTLD_NOW);
const char *loaderror = (char *) dlerror();
return 0;
}" HAVE_DLOPEN)
set(CMAKE_REQUIRED_LIBRARIES)
endif() endif()
cmake_pop_check_state()
endmacro() endmacro()
macro(CheckO_CLOEXEC) macro(CheckO_CLOEXEC)