cmake: use CMakePushCheckState to handle check states

main
Anonymous Maarten 2022-12-18 21:48:24 +01:00 committed by Sam Lantinga
parent fab33545fa
commit 8f9227e4be
2 changed files with 60 additions and 62 deletions

View File

@ -283,19 +283,14 @@ else()
endif() endif()
endif() endif()
# Emscripten toolchain has a nonempty default value for this, and the checks
# in this file need to change that, so remember the original value, and
# restore back to that afterwards. For check_function_exists() to work in
# Emscripten, this value must be at its default value.
set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
if(CYGWIN) if(CYGWIN)
# We build SDL on cygwin without the UNIX emulation layer # We build SDL on cygwin without the UNIX emulation layer
target_include_directories(sdl-build-options INTERFACE "/usr/include/mingw") target_include_directories(sdl-build-options INTERFACE "/usr/include/mingw")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
check_c_source_compiles("int main(int argc, char **argv) { return 0; }" check_c_source_compiles("int main(int argc, char **argv) { return 0; }"
HAVE_GCC_NO_CYGWIN) HAVE_GCC_NO_CYGWIN)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) cmake_pop_check_state()
if(HAVE_GCC_NO_CYGWIN) if(HAVE_GCC_NO_CYGWIN)
list(APPEND EXTRA_LDFLAGS_BUILD "-mno-cygwin") list(APPEND EXTRA_LDFLAGS_BUILD "-mno-cygwin")
list(APPEND SDL_LIBS "-mno-cygwin") list(APPEND SDL_LIBS "-mno-cygwin")
@ -473,22 +468,18 @@ set(HAVE_STATIC_PIC "${SDL_STATIC_PIC}")
if(SDL_WERROR) if(SDL_WERROR)
if(MSVC) if(MSVC)
cmake_push_check_state()
check_c_compiler_flag(/WX HAVE_WX) check_c_compiler_flag(/WX HAVE_WX)
if(HAVE_WX) if(HAVE_WX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
endif() endif()
cmake_pop_check_state()
elseif(USE_GCC OR USE_CLANG) elseif(USE_GCC OR USE_CLANG)
cmake_push_check_state()
check_c_compiler_flag(-Werror HAVE_WERROR) check_c_compiler_flag(-Werror HAVE_WERROR)
if(HAVE_WERROR) if(HAVE_WERROR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -Werror") set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -Werror")
endif() endif()
cmake_pop_check_state()
endif() endif()
endif() endif()
@ -616,21 +607,23 @@ if(USE_GCC OR USE_CLANG)
endif() endif()
endif() endif()
set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mpreferred-stack-boundary=2")
check_c_source_compiles("int x = 0; int main(int argc, char **argv) { return 0; }" check_c_source_compiles("int x = 0; int main(int argc, char **argv) { return 0; }"
HAVE_GCC_PREFERRED_STACK_BOUNDARY) HAVE_GCC_PREFERRED_STACK_BOUNDARY)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) cmake_pop_check_state()
set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror")
check_c_source_compiles(" check_c_source_compiles("
#if !defined(__GNUC__) || __GNUC__ < 4 #if !defined(__GNUC__) || __GNUC__ < 4
#error SDL only uses visibility attributes in GCC 4 or newer #error SDL only uses visibility attributes in GCC 4 or newer
#endif #endif
int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY) int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY)
cmake_pop_check_state()
if(HAVE_GCC_FVISIBILITY) if(HAVE_GCC_FVISIBILITY)
list(APPEND EXTRA_CFLAGS "-fvisibility=hidden") list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW) check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
if(HAVE_GCC_WSHADOW) if(HAVE_GCC_WSHADOW)
@ -650,9 +643,10 @@ if(USE_GCC OR USE_CLANG)
list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-compatibility_version,${SDL_DYLIB_COMPAT_VERSION}") list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-compatibility_version,${SDL_DYLIB_COMPAT_VERSION}")
list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-current_version,${SDL_DYLIB_CURRENT_VERSION}") list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-current_version,${SDL_DYLIB_CURRENT_VERSION}")
elseif(NOT OPENBSD) elseif(NOT OPENBSD)
set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wl,--no-undefined")
check_c_compiler_flag("" HAVE_NO_UNDEFINED) check_c_compiler_flag("" HAVE_NO_UNDEFINED)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) cmake_pop_check_state()
if(HAVE_NO_UNDEFINED AND NOT (USE_CLANG AND WINDOWS)) if(HAVE_NO_UNDEFINED AND NOT (USE_CLANG AND WINDOWS))
list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,--no-undefined") list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,--no-undefined")
endif() endif()
@ -702,7 +696,8 @@ if(SDL_ASSEMBLY)
# reworked for better compiler support # reworked for better compiler support
set(HAVE_ASSEMBLY TRUE) set(HAVE_ASSEMBLY TRUE)
if(SDL_MMX) if(SDL_MMX)
set(CMAKE_REQUIRED_FLAGS "-mmmx") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mmmx")
check_c_source_compiles(" check_c_source_compiles("
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <_mingw.h> #include <_mingw.h>
@ -718,14 +713,15 @@ if(SDL_ASSEMBLY)
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
#endif #endif
int main(int argc, char **argv) { return 0; }" HAVE_MMX) int main(int argc, char **argv) { return 0; }" HAVE_MMX)
cmake_pop_check_state()
if(HAVE_MMX) if(HAVE_MMX)
list(APPEND EXTRA_CFLAGS "-mmmx") list(APPEND EXTRA_CFLAGS "-mmmx")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(SDL_3DNOW) if(SDL_3DNOW)
set(CMAKE_REQUIRED_FLAGS "-m3dnow") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -m3dnow")
check_c_source_compiles(" check_c_source_compiles("
#include <mm3dnow.h> #include <mm3dnow.h>
#ifndef __3dNOW__ #ifndef __3dNOW__
@ -736,15 +732,16 @@ if(SDL_ASSEMBLY)
_m_prefetch(p); _m_prefetch(p);
return 0; return 0;
}" CPU_SUPPORTS_3DNOW) }" CPU_SUPPORTS_3DNOW)
cmake_pop_check_state()
if(CPU_SUPPORTS_3DNOW) if(CPU_SUPPORTS_3DNOW)
set(HAVE_3DNOW TRUE) set(HAVE_3DNOW TRUE)
list(APPEND EXTRA_CFLAGS "-m3dnow") list(APPEND EXTRA_CFLAGS "-m3dnow")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(SDL_SSE) if(SDL_SSE)
set(CMAKE_REQUIRED_FLAGS "-msse") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse")
check_c_source_compiles(" check_c_source_compiles("
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <_mingw.h> #include <_mingw.h>
@ -760,15 +757,16 @@ if(SDL_ASSEMBLY)
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
#endif #endif
int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE) int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE)
cmake_pop_check_state()
if(CPU_SUPPORTS_SSE) if(CPU_SUPPORTS_SSE)
set(HAVE_SSE ON) set(HAVE_SSE ON)
list(APPEND EXTRA_CFLAGS "-msse") list(APPEND EXTRA_CFLAGS "-msse")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(SDL_SSE2) if(SDL_SSE2)
set(CMAKE_REQUIRED_FLAGS "-msse2") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse2")
check_c_source_compiles(" check_c_source_compiles("
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <_mingw.h> #include <_mingw.h>
@ -784,15 +782,16 @@ if(SDL_ASSEMBLY)
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
#endif #endif
int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE2) int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE2)
cmake_pop_check_state()
if(CPU_SUPPORTS_SSE2) if(CPU_SUPPORTS_SSE2)
set(HAVE_SSE2 TRUE) set(HAVE_SSE2 TRUE)
list(APPEND EXTRA_CFLAGS "-msse2") list(APPEND EXTRA_CFLAGS "-msse2")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(SDL_SSE3) if(SDL_SSE3)
set(CMAKE_REQUIRED_FLAGS "-msse3") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse3")
check_c_source_compiles(" check_c_source_compiles("
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <_mingw.h> #include <_mingw.h>
@ -808,11 +807,11 @@ if(SDL_ASSEMBLY)
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
#endif #endif
int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE3) int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE3)
cmake_pop_check_state()
if(CPU_SUPPORTS_SSE3) if(CPU_SUPPORTS_SSE3)
set(HAVE_SSE3 TRUE) set(HAVE_SSE3 TRUE)
list(APPEND EXTRA_CFLAGS "-msse3") list(APPEND EXTRA_CFLAGS "-msse3")
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(NOT SDL_SSEMATH) if(NOT SDL_SSEMATH)
@ -831,7 +830,8 @@ if(SDL_ASSEMBLY)
check_include_file("immintrin.h" HAVE_IMMINTRIN_H) check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
if(SDL_ALTIVEC) if(SDL_ALTIVEC)
set(CMAKE_REQUIRED_FLAGS "-maltivec") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -maltivec")
check_c_source_compiles(" check_c_source_compiles("
#include <altivec.h> #include <altivec.h>
vector unsigned int vzero() { vector unsigned int vzero() {
@ -843,7 +843,7 @@ if(SDL_ASSEMBLY)
return vec_splat_u32(0); return vec_splat_u32(0);
} }
int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_ALTIVEC) int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_ALTIVEC)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) cmake_pop_check_state()
if(CPU_SUPPORTS_ALTIVEC OR HAVE_ALTIVEC_H_HDR) if(CPU_SUPPORTS_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
list(APPEND EXTRA_CFLAGS "-maltivec") list(APPEND EXTRA_CFLAGS "-maltivec")
@ -856,7 +856,7 @@ if(SDL_ASSEMBLY)
if(SDL_LSX) if(SDL_LSX)
cmake_push_check_state() cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_FLAGS "-mlsx") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mlsx")
check_c_source_compiles([[ check_c_source_compiles([[
#ifndef __loongarch_sx #ifndef __loongarch_sx
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
@ -873,7 +873,7 @@ if(SDL_ASSEMBLY)
if(SDL_LASX) if(SDL_LASX)
cmake_push_check_state() cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_FLAGS "-mlasx") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mlasx")
check_c_source_compiles([[ check_c_source_compiles([[
#ifndef __loongarch_asx #ifndef __loongarch_asx
#error Assembler CPP flag not enabled #error Assembler CPP flag not enabled
@ -888,7 +888,7 @@ if(SDL_ASSEMBLY)
endif() endif()
if(SDL_ARMSIMD) if(SDL_ARMSIMD)
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
check_c_source_compiles(" check_c_source_compiles("
.text .text
@ -902,7 +902,7 @@ if(SDL_ASSEMBLY)
pld [r0] pld [r0]
uqadd8 r0, r0, r0 uqadd8 r0, r0, r0
" ARMSIMD_FOUND) " ARMSIMD_FOUND)
set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}") cmake_pop_check_state()
if(ARMSIMD_FOUND) if(ARMSIMD_FOUND)
set(HAVE_ARMSIMD TRUE) set(HAVE_ARMSIMD TRUE)
@ -1057,7 +1057,7 @@ if(SDL_LIBC)
check_library_exists(m pow "" HAVE_LIBM) check_library_exists(m pow "" HAVE_LIBM)
if(HAVE_LIBM) if(HAVE_LIBM)
set(CMAKE_REQUIRED_LIBRARIES m) cmake_push_check_state()
foreach(_FN foreach(_FN
atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf
exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f
@ -1068,7 +1068,7 @@ if(SDL_LIBC)
check_symbol_exists("${_FN}" "math.h" ${LIBC_HASVAR}) check_symbol_exists("${_FN}" "math.h" ${LIBC_HASVAR})
set(HAVE_${_UPPER} ${${LIBC_HASVAR}}) set(HAVE_${_UPPER} ${${LIBC_HASVAR}})
endforeach() endforeach()
set(CMAKE_REQUIRED_LIBRARIES) cmake_pop_check_state()
if(NOT VITA) if(NOT VITA)
list(APPEND EXTRA_LIBS m) list(APPEND EXTRA_LIBS m)
endif() endif()
@ -1206,12 +1206,12 @@ if(ANDROID)
# see: https://issuetracker.google.com/issues/62264618 # see: https://issuetracker.google.com/issues/62264618
# Another option would be to set ARM mode to all compiled files # Another option would be to set ARM mode to all compiled files
cmake_push_check_state() cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unused-command-line-argument")
check_c_compiler_flag(-marm HAVE_ARM_MODE) check_c_compiler_flag(-marm HAVE_ARM_MODE)
cmake_pop_check_state()
if(HAVE_ARM_MODE) if(HAVE_ARM_MODE)
set_property(SOURCE "${SDL3_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm") set_property(SOURCE "${SDL3_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
endif() endif()
cmake_pop_check_state()
if(SDL_AUDIO) if(SDL_AUDIO)
set(SDL_AUDIO_DRIVER_ANDROID 1) set(SDL_AUDIO_DRIVER_ANDROID 1)
@ -1662,9 +1662,10 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
set(SDL_RLD_FLAGS "") set(SDL_RLD_FLAGS "")
if(SDL_RPATH AND SDL_SHARED) if(SDL_RPATH AND SDL_SHARED)
if(BSDI OR FREEBSD OR LINUX OR NETBSD) if(BSDI OR FREEBSD OR LINUX OR NETBSD)
set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wl,--enable-new-dtags")
check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS) check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) cmake_pop_check_state()
if(HAVE_ENABLE_NEW_DTAGS) if(HAVE_ENABLE_NEW_DTAGS)
set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags") set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
else() else()
@ -1711,6 +1712,7 @@ elseif(WINDOWS)
# Check for DirectX # Check for DirectX
if(SDL_DIRECTX) if(SDL_DIRECTX)
cmake_push_check_state()
if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700) if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
set(USE_WINSDK_DIRECTX TRUE) set(USE_WINSDK_DIRECTX TRUE)
endif() endif()
@ -1718,7 +1720,7 @@ elseif(WINDOWS)
if("$ENV{DXSDK_DIR}" STREQUAL "") if("$ENV{DXSDK_DIR}" STREQUAL "")
message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set") message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
endif() endif()
set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /I\"$ENV{DXSDK_DIR}\\Include\"")
endif() endif()
check_include_file(d3d9.h HAVE_D3D_H) check_include_file(d3d9.h HAVE_D3D_H)
@ -1738,6 +1740,7 @@ elseif(WINDOWS)
set(HAVE_DINPUT_H 0) set(HAVE_DINPUT_H 0)
endif() endif()
check_include_file(dxgi.h HAVE_DXGI_H) check_include_file(dxgi.h HAVE_DXGI_H)
cmake_pop_check_state()
if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_D3D12_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H) if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_D3D12_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H)
set(HAVE_DIRECTX TRUE) set(HAVE_DIRECTX TRUE)
if(NOT MINGW AND NOT USE_WINSDK_DIRECTX) if(NOT MINGW AND NOT USE_WINSDK_DIRECTX)
@ -1746,7 +1749,6 @@ elseif(WINDOWS)
target_include_directories(sdl-build-options INTERFACE "$ENV{DXSDK_DIR}\\Include") target_include_directories(sdl-build-options INTERFACE "$ENV{DXSDK_DIR}\\Include")
endif() endif()
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
endif() endif()
if(SDL_XINPUT) if(SDL_XINPUT)
@ -2380,12 +2382,12 @@ elseif(RISCOS)
elseif(VITA) elseif(VITA)
# SDL_spinlock.c Needs to be compiled in ARM mode. # SDL_spinlock.c Needs to be compiled in ARM mode.
cmake_push_check_state() cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unused-command-line-argument")
check_c_compiler_flag(-marm HAVE_ARM_MODE) check_c_compiler_flag(-marm HAVE_ARM_MODE)
cmake_pop_check_state()
if(HAVE_ARM_MODE) if(HAVE_ARM_MODE)
set_property(SOURCE "${SDL3_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm") set_property(SOURCE "${SDL3_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
endif() endif()
cmake_pop_check_state()
if(SDL_MISC) if(SDL_MISC)
file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/vita/*.c) file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/vita/*.c)
@ -2971,11 +2973,11 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG)
set(FLAG "-fsanitize=${ASAN_FLAG}") set(FLAG "-fsanitize=${ASAN_FLAG}")
set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES}) cmake_push_check_state()
set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan") list(APPEND CMAKE_REQUIRED_LIBRARIES ${FLAG} asan)
check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG}) check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG}) check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS}) cmake_pop_check_state()
if (HAS_C_FLAG_${ASAN_FLAG}) if (HAS_C_FLAG_${ASAN_FLAG})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")

View File

@ -42,11 +42,12 @@ macro(FindLibraryAndSONAME _LIB)
endmacro() endmacro()
macro(CheckDLOPEN) macro(CheckDLOPEN)
cmake_push_check_state()
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBC) check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBC)
if(NOT HAVE_DLOPEN_IN_LIBC) if(NOT HAVE_DLOPEN_IN_LIBC)
set(CMAKE_REQUIRED_LIBRARIES dl) cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBDL) check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBDL)
cmake_pop_check_state()
if(HAVE_DLOPEN_IN_LIBDL) if(HAVE_DLOPEN_IN_LIBDL)
list(APPEND EXTRA_LIBS dl) list(APPEND EXTRA_LIBS dl)
endif() endif()
@ -54,7 +55,6 @@ macro(CheckDLOPEN)
if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL) if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL)
set(HAVE_DLOPEN TRUE) set(HAVE_DLOPEN TRUE)
endif() endif()
cmake_pop_check_state()
endmacro() endmacro()
macro(CheckO_CLOEXEC) macro(CheckO_CLOEXEC)
@ -385,7 +385,7 @@ macro(CheckX11)
list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB}) list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
endif() endif()
set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB}) list(APPEND CMAKE_REQUIRED_LIBRARIES ${X11_LIB})
check_c_source_compiles(" check_c_source_compiles("
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -487,8 +487,6 @@ macro(CheckX11)
set(SDL_VIDEO_DRIVER_X11_XSHAPE 1) set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
set(HAVE_X11_XSHAPE TRUE) set(HAVE_X11_XSHAPE TRUE)
endif() endif()
set(CMAKE_REQUIRED_LIBRARIES)
endif() endif()
endif() endif()
if(NOT HAVE_X11) if(NOT HAVE_X11)
@ -749,6 +747,7 @@ endmacro()
# PTHREAD_CFLAGS # PTHREAD_CFLAGS
# PTHREAD_LIBS # PTHREAD_LIBS
macro(CheckPTHREAD) macro(CheckPTHREAD)
cmake_push_check_state()
if(SDL_THREADS AND SDL_PTHREADS) if(SDL_THREADS AND SDL_PTHREADS)
if(ANDROID) if(ANDROID)
# the android libc provides built-in support for pthreads, so no # the android libc provides built-in support for pthreads, so no
@ -797,7 +796,6 @@ macro(CheckPTHREAD)
endif() endif()
# Run some tests # Run some tests
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
check_c_source_compiles(" check_c_source_compiles("
#include <pthread.h> #include <pthread.h>
@ -881,8 +879,8 @@ macro(CheckPTHREAD)
endif() endif()
set(HAVE_SDL_THREADS TRUE) set(HAVE_SDL_THREADS TRUE)
endif() endif()
set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
endif() endif()
cmake_pop_check_state()
endmacro() endmacro()
# Requires # Requires
@ -892,6 +890,7 @@ endmacro()
# USB_LIBS # USB_LIBS
# USB_CFLAGS # USB_CFLAGS
macro(CheckUSBHID) macro(CheckUSBHID)
cmake_push_check_state()
check_library_exists(usbhid hid_init "" LIBUSBHID) check_library_exists(usbhid hid_init "" LIBUSBHID)
if(LIBUSBHID) if(LIBUSBHID)
check_include_file(usbhid.h HAVE_USBHID_H) check_include_file(usbhid.h HAVE_USBHID_H)
@ -919,9 +918,8 @@ macro(CheckUSBHID)
endif() endif()
endif() endif()
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}") list(APPEND CMAKE_REQUIRED_LIBRARIES ${USB_LIBS})
check_c_source_compiles(" check_c_source_compiles("
#include <sys/types.h> #include <sys/types.h>
#if defined(HAVE_USB_H) #if defined(HAVE_USB_H)
@ -1020,9 +1018,8 @@ macro(CheckUSBHID)
list(APPEND EXTRA_LIBS ${USB_LIBS}) list(APPEND EXTRA_LIBS ${USB_LIBS})
set(HAVE_SDL_JOYSTICK TRUE) set(HAVE_SDL_JOYSTICK TRUE)
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
endif() endif()
cmake_pop_check_state()
endmacro() endmacro()
# Check for HIDAPI support # Check for HIDAPI support
@ -1093,9 +1090,9 @@ macro(CheckRPI)
listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I") listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L") listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}") list(APPEND CMAKE_REQUIRED_LIBRARIES ${VIDEO_RPI_LIBRARIES})
check_c_source_compiles(" check_c_source_compiles("
#include <bcm_host.h> #include <bcm_host.h>
#include <EGL/eglplatform.h> #include <EGL/eglplatform.h>
@ -1103,8 +1100,7 @@ macro(CheckRPI)
EGL_DISPMANX_WINDOW_T window; EGL_DISPMANX_WINDOW_T window;
bcm_host_init(); bcm_host_init();
}" HAVE_RPI) }" HAVE_RPI)
set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}") cmake_pop_check_state()
set(CMAKE_REQUIRED_LIBRARIES)
if(SDL_VIDEO AND HAVE_RPI) if(SDL_VIDEO AND HAVE_RPI)
set(HAVE_SDL_VIDEO TRUE) set(HAVE_SDL_VIDEO TRUE)