Update CMakeLists.txt

check_c_compiler_flag is used to check ​​compiler flags​​ (such as -Wall), not linker flags. Passing an empty string directly will result in checking nothing substantial, and the outcome may always be TRUE.
This commit is contained in:
t1c 2025-04-30 13:06:11 +08:00 committed by GitHub
parent dc77205ff2
commit fc89a317fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -314,7 +314,7 @@ if (GLFW_BUILD_SHARED_LIBRARY)
# Compatibility with data execution prevention (DEP)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
check_c_compiler_flag("" _GLFW_HAS_DEP)
check_linker_flag(C "-Wl,--nxcompat" _GLFW_HAS_DEP)
if (_GLFW_HAS_DEP)
target_link_libraries(glfw PRIVATE "-Wl,--nxcompat")
endif()
@ -323,7 +323,7 @@ if (GLFW_BUILD_SHARED_LIBRARY)
# Compatibility with address space layout randomization (ASLR)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
check_c_compiler_flag("" _GLFW_HAS_ASLR)
check_linker_flag(C "-Wl,--dynamicbase" _GLFW_HAS_ASLR)
if (_GLFW_HAS_ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase")
endif()
@ -332,7 +332,7 @@ if (GLFW_BUILD_SHARED_LIBRARY)
# Compatibility with 64-bit address space layout randomization (ASLR)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va")
check_c_compiler_flag("" _GLFW_HAS_64ASLR)
check_linker_flag(C "-Wl,--high-entropy-va" _GLFW_HAS_64ASLR)
if (_GLFW_HAS_64ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va")
endif()