diff --git a/CMakeLists.txt b/CMakeLists.txt index 20d816d8..c836f022 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,21 @@ list(APPEND yquake2LinkerFlags ${CMAKE_DL_LIBS}) include_directories(${yquake2IncludeDirectories} ${CMAKE_SOURCE_DIR}/src/client/refresh/gl3/glad/include) link_directories(${yquake2LinkerDirectories}) +# If we're building with gcc for i386 let's define -ffloat-store. +# This helps the old and crappy x87 FPU to produce correct values. +# Would be nice if Clang had something comparable. +if ("${ARCH}" STREQUAL "i386") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffloat-store") + endif() +endif() + +# Force SSE math on x86_64. All sane compilers should do this +# anyway, just to protect us from broken Linux distros. +if ("${ARCH}" STREQUAL "x86_64") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse") +endif() + set(Backends-Generic-Source ${BACKENDS_SRC_DIR}/generic/misc.c ${BACKENDS_SRC_DIR}/generic/qal.c diff --git a/Makefile b/Makefile index 338525ea..801db085 100755 --- a/Makefile +++ b/Makefile @@ -124,6 +124,15 @@ else YQ2_ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/') endif +# Detect the compiler +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"), 1) +COMPILER := gcc +else +COMPILER := unknown +endif + # Disable CDA for SDL2 ifeq ($(WITH_SDL2),yes) ifeq ($(WITH_CDA),yes) @@ -178,6 +187,23 @@ endif # ---------- +# If we're building with gcc for i386 let's define -ffloat-store. +# This helps the old and crappy x87 FPU to produce correct values. +# Would be nice if Clang had something comparable. +ifeq ($(YQ2_ARCH), i386) +ifeq ($(COMPILER), gcc) +CFLAGS += -ffloat-store +endif +endif + +# Force SSE math on x86_64. All sane compilers should do this +# anyway, just to protect us from broken Linux distros. +ifeq ($(YQ2_ARCH), x86_64) +CFLAGS += -mfpmath=sse +endif + +# ---------- + # Systemwide installation ifeq ($(WITH_SYSTEMWIDE),yes) CFLAGS += -DSYSTEMWIDE