Use CMakePushCheckState for check state management

This commit is contained in:
Camilla Löwy 2024-05-09 17:18:39 +02:00
parent b35641f4a3
commit 043378876a

View File

@ -313,30 +313,34 @@ if (GLFW_BUILD_SHARED_LIBRARY)
if (MINGW) if (MINGW)
# Enable link-time exploit mitigation features enabled by default on MSVC # Enable link-time exploit mitigation features enabled by default on MSVC
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(CMakePushCheckState)
# Compatibility with data execution prevention (DEP) # Compatibility with data execution prevention (DEP)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
check_c_compiler_flag("" _GLFW_HAS_DEP) check_c_compiler_flag("" _GLFW_HAS_DEP)
if (_GLFW_HAS_DEP) if (_GLFW_HAS_DEP)
target_link_libraries(glfw PRIVATE "-Wl,--nxcompat") target_link_libraries(glfw PRIVATE "-Wl,--nxcompat")
endif() endif()
cmake_pop_check_state()
# Compatibility with address space layout randomization (ASLR) # Compatibility with address space layout randomization (ASLR)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
check_c_compiler_flag("" _GLFW_HAS_ASLR) check_c_compiler_flag("" _GLFW_HAS_ASLR)
if (_GLFW_HAS_ASLR) if (_GLFW_HAS_ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase") target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase")
endif() endif()
cmake_pop_check_state()
# Compatibility with 64-bit address space layout randomization (ASLR) # Compatibility with 64-bit address space layout randomization (ASLR)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va") set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va")
check_c_compiler_flag("" _GLFW_HAS_64ASLR) check_c_compiler_flag("" _GLFW_HAS_64ASLR)
if (_GLFW_HAS_64ASLR) if (_GLFW_HAS_64ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va") target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va")
endif() endif()
cmake_pop_check_state()
# Clear flags again to avoid breaking later tests
set(CMAKE_REQUIRED_FLAGS)
endif() endif()
if (UNIX) if (UNIX)