From 61eb79042f31689638022d98f93b53acfcf00eba Mon Sep 17 00:00:00 2001 From: Jeremy Kemp Date: Mon, 2 Mar 2020 17:09:08 +0000 Subject: [PATCH] Fplib build fix (#637) * Fix conversions build with gcc 4.8.5 armhf. Re-named fplib.c to fplib.cpp. Updated the conditions under which fplib.cpp will be included in the build by CMake. * Build: Added a global archtiecture variable, CLConform_TARGET_ARCH. The reset of the build can query this variable whenever archtiecture specific options are required. The current supported values of this variable are "ARM", "x86", and "x86_64". This change also replaces all existing locations where CMAKE_SYSTEM_PROCESSOR was queried. * Build: Added ARM64 as a valid value for CLConform_TARGET_ARCH. * Conversions: Don't build fplib.cpp for ARM64. --- CMakeLists.txt | 16 +++++++++++++++- test_conformance/conversions/CMakeLists.txt | 6 +++--- .../conversions/{fplib.c => fplib.cpp} | 0 3 files changed, 18 insertions(+), 4 deletions(-) rename test_conformance/conversions/{fplib.c => fplib.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ceac8655..4947ac35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,20 @@ endif (GL_IS_SUPPORTED AND CLConform_GL_LIBRARIES_DIR) include(CheckFunctionExists) include(CheckIncludeFiles) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)") + set(CLConform_TARGET_ARCH ARM) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") + set(CLConform_TARGET_ARCH ARM64) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") + set(CLConform_TARGET_ARCH x86_64) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*") + set(CLConform_TARGET_ARCH x86) +endif() + +if(NOT DEFINED CLConform_TARGET_ARCH) + message (FATAL_ERROR "Target architecture not recognised. Exiting.") +endif() + if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-narrowing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing") @@ -128,7 +142,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang" # avoiding excess precision problems that cause tests like int2float # to falsely fail. -ffloat-store also works, but WG suggested # that sse would be better. - if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*") + if(${CLConform_TARGET_ARCH} EQUAL "x86_64" OR ${CLConform_TARGET_ARCH} EQUAL "x86") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -mfpmath=sse") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -mfpmath=sse") endif() diff --git a/test_conformance/conversions/CMakeLists.txt b/test_conformance/conversions/CMakeLists.txt index 4bd0b796..ccbbe8d0 100644 --- a/test_conformance/conversions/CMakeLists.txt +++ b/test_conformance/conversions/CMakeLists.txt @@ -13,9 +13,9 @@ set (${MODULE_NAME}_SOURCES Sleep.cpp test_conversions.cpp basic_test_conversions.cpp ) -if(ANDROID) - list(APPEND CONVERSIONS_SOURCES fplib.c) -endif(ANDROID) +if(CMAKE_COMPILER_IS_GNUCC AND ${CLConform_TARGET_ARCH} EQUAL "ARM") + list(APPEND ${MODULE_NAME}_SOURCES fplib.cpp) +endif() if(NOT CMAKE_CL_64 AND NOT MSVC AND NOT ANDROID) # -march is needed for CPU atomics, default arch on gcc is i386 diff --git a/test_conformance/conversions/fplib.c b/test_conformance/conversions/fplib.cpp similarity index 100% rename from test_conformance/conversions/fplib.c rename to test_conformance/conversions/fplib.cpp