1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Move more compiler workarounds to library setup

These are details of the glfw CMake target and belong in the creation of
that target.
This commit is contained in:
Camilla Löwy 2020-05-25 16:33:44 +02:00
parent 8369880b56
commit e47705d8fb
2 changed files with 51 additions and 49 deletions

View File

@ -66,17 +66,6 @@ endif()
# Set compiler specific flags
#--------------------------------------------------------------------
if (MSVC)
if (MSVC90)
# Workaround for VS 2008 not shipping with the DirectX 9 SDK
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND)
message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK")
endif()
# Workaround for VS 2008 not shipping with stdint.h
list(APPEND glfw_INCLUDE_DIRS "${GLFW_SOURCE_DIR}/deps/vs2008")
endif()
if (NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
foreach (flag CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
@ -95,44 +84,6 @@ if (MSVC)
endif()
endif()
if (MINGW)
# Workaround for legacy MinGW not providing XInput and DirectInput
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
check_include_file(xinput.h XINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND OR NOT XINPUT_H_FOUND)
list(APPEND glfw_INCLUDE_DIRS "${GLFW_SOURCE_DIR}/deps/mingw")
endif()
# Enable link-time exploit mitigation features enabled by default on MSVC
include(CheckCCompilerFlag)
# Compatibility with data execution prevention (DEP)
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
check_c_compiler_flag("" _GLFW_HAS_DEP)
if (_GLFW_HAS_DEP)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--nxcompat ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
# Compatibility with address space layout randomization (ASLR)
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
check_c_compiler_flag("" _GLFW_HAS_ASLR)
if (_GLFW_HAS_ASLR)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--dynamicbase ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
# Compatibility with 64-bit address space layout randomization (ASLR)
set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va")
check_c_compiler_flag("" _GLFW_HAS_64ASLR)
if (_GLFW_HAS_64ASLR)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--high-entropy-va ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
# Clear flags again to avoid breaking later tests
set(CMAKE_REQUIRED_FLAGS)
endif()
#--------------------------------------------------------------------
# Detect and select backend APIs
#--------------------------------------------------------------------

View File

@ -136,6 +136,28 @@ if (MINGW)
target_compile_definitions(glfw PRIVATE UNICODE WINVER=0x0501)
endif()
# Workaround for legacy MinGW not providing XInput and DirectInput
if (MINGW)
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
check_include_file(xinput.h XINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND OR NOT XINPUT_H_FOUND)
target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/deps/mingw")
endif()
endif()
if (MSVC90)
# Workaround for VS 2008 not shipping with the DirectX 9 SDK
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND)
message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK")
endif()
# Workaround for VS 2008 not shipping with stdint.h
target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/deps/vs2008")
endif()
if (BUILD_SHARED_LIBS)
if (WIN32)
if (MINGW)
@ -159,6 +181,35 @@ if (BUILD_SHARED_LIBS)
INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}")
endif()
if (MINGW)
# Enable link-time exploit mitigation features enabled by default on MSVC
include(CheckCCompilerFlag)
# Compatibility with data execution prevention (DEP)
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
check_c_compiler_flag("" _GLFW_HAS_DEP)
if (_GLFW_HAS_DEP)
target_link_libraries(glfw PRIVATE "-Wl,--nxcompat")
endif()
# Compatibility with address space layout randomization (ASLR)
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
check_c_compiler_flag("" _GLFW_HAS_ASLR)
if (_GLFW_HAS_ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase")
endif()
# Compatibility with 64-bit address space layout randomization (ASLR)
set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va")
check_c_compiler_flag("" _GLFW_HAS_64ASLR)
if (_GLFW_HAS_64ASLR)
target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va")
endif()
# Clear flags again to avoid breaking later tests
set(CMAKE_REQUIRED_FLAGS)
endif()
if (UNIX)
# Hide symbols not explicitly tagged for export from the shared library
target_compile_options(glfw PRIVATE "-fvisibility=hidden")