From a31639682b633e4b12b7153a975e9eb2d2ca7125 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 23 Oct 2011 15:59:27 +0100 Subject: [PATCH] Use a compile test to see if we need to provide the GCC atomic built-ins ourselves, or not. --- CMakeLists.txt | 9 ++++++++- simgear/simgear_config_cmake.h.in | 2 ++ simgear/structure/SGAtomic.cxx | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6729155..fc2d2630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ find_package(ZLIB REQUIRED) find_package(Threads REQUIRED) if(SIMGEAR_HEADLESS) - message(STATUS "headlesss mode") + message(STATUS "headless mode") set(NO_OPENSCENEGRAPH_INTERFACE 1) else() find_package(OpenGL REQUIRED) @@ -179,6 +179,13 @@ check_cxx_source_compiles( if(CMAKE_COMPILER_IS_GNUCXX) set(WARNING_FLAGS -Wall) + + # certain GCC versions don't provide the atomic builds, and hence + # require is to provide them in SGAtomic.cxx + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) + check_cxx_source_compiles( + "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }" + GCC_ATOMIC_BUILTINS_FOUND) endif(CMAKE_COMPILER_IS_GNUCXX) if(WIN32) diff --git a/simgear/simgear_config_cmake.h.in b/simgear/simgear_config_cmake.h.in index 3d132306..a1192283 100644 --- a/simgear/simgear_config_cmake.h.in +++ b/simgear/simgear_config_cmake.h.in @@ -16,5 +16,7 @@ #cmakedefine HAVE_SVN_CLIENT_H #cmakedefine HAVE_LIBSVN_CLIENT_1 +#cmakedefine GCC_ATOMIC_BUILTINS_FOUND + // set if building headless (no OSG or OpenGL libs) #cmakedefine NO_OPENSCENEGRAPH_INTERFACE diff --git a/simgear/structure/SGAtomic.cxx b/simgear/structure/SGAtomic.cxx index 728994df..3f0b9f44 100644 --- a/simgear/structure/SGAtomic.cxx +++ b/simgear/structure/SGAtomic.cxx @@ -17,10 +17,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ +#ifdef HAVE_CONFIG_H +# include +#endif #include "SGAtomic.hxx" -#if defined(SGATOMIC_USE_GCC4_BUILTINS) && defined (__i386__) +#if defined(SGATOMIC_USE_GCC4_BUILTINS) && !defined (GCC_ATOMIC_BUILTINS_FOUND) // Usually the appropriate functions are inlined by gcc. // But if gcc is called with something equivalent to -march=i386, -- 2.39.5