cmake: use check_symbol_exists to check dlopen + need for dl library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44e4d72..ebc7835 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,7 @@ include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckStructHasMember)
include(CMakeDependentOption)
+include(CMakePushCheckState)
include(FindPkgConfig)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index e1939dc..8b7eb03 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -30,28 +30,19 @@ macro(FindLibraryAndSONAME _LIB)
endmacro()
macro(CheckDLOPEN)
- check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN)
- if(NOT HAVE_DLOPEN)
- check_library_exists(dl dlopen "" DLOPEN_LIB)
- if(DLOPEN_LIB)
+ cmake_push_check_state(RESET)
+ check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBC)
+ if(NOT HAVE_DLOPEN_IN_LIBC)
+ 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)
- set(_DLLIB dl)
- set(HAVE_DLOPEN TRUE)
endif()
endif()
- if(HAVE_DLOPEN)
- if(_DLLIB)
- 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)
+ if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL)
+ set(HAVE_DLOPEN TRUE)
endif()
+ cmake_pop_check_state()
endmacro()
macro(CheckO_CLOEXEC)