Move _GNU_SOURCE to gmxpre.h
authorTeemu Murtola <teemu.murtola@gmail.com>
Tue, 9 Sep 2014 18:27:36 +0000 (21:27 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 11 Sep 2014 11:34:33 +0000 (13:34 +0200)
This makes life simpler in files that require it, and removes clutter
from there.  The only (minor) disadvantage is that it is now defined
everywhere, so people who develop on a system where it has effect may
accidentally introduce additional function calls that depend on the
define.  But Jenkins should catch those easily.

Change-Id: Ia4ed8b5d189138694076705ded695d818bbc73e3

src/external/gmock-1.7.0/CMakeLists.txt
src/gmxpre.h
src/gromacs/gmxlib/gmx_cpuid.c
src/gromacs/gmxlib/gmx_thread_affinity.c

index d0552fb3f968f8d0fcb39e45e6ac343d7d2eaf5a..c9404bf48be0b3eef9b666d115a8fcbe65910753 100644 (file)
@@ -37,8 +37,6 @@
 
 include(gmxGetGmockTupleWorkaround)
 get_gmock_tuple_workaround(GMOCK_COMPILE_DEFINITIONS)
-set(GMOCK_COMPILE_DEFINITIONS "_GNU_SOURCE=1;${GMOCK_COMPILE_DEFINITIONS}")
-set(GMOCK_COMPILE_DEFINITIONS ${GMOCK_COMPILE_DEFINITIONS} PARENT_SCOPE)
 
 # GTest/GMock suggest linking with pthreads when available for thread safety
 set(CMAKE_THREAD_PREFER_PTHREAD 1)
@@ -68,9 +66,11 @@ if (HAS_NO_UNUSED_VARIABLE)
 endif()
 
 add_library(gmock STATIC ${UNITTEST_TARGET_OPTIONS} ${GMOCK_SOURCES} ${GTEST_SOURCES})
-set_property(TARGET gmock APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
+set_property(TARGET gmock APPEND PROPERTY COMPILE_DEFINITIONS
+             "_GNU_SOURCE=1;${GMOCK_COMPILE_DEFINITIONS}")
 
 set(GMOCK_LIBRARIES gmock ${PTHREADS_LIBRARIES} PARENT_SCOPE)
 set(GTEST_LIBRARIES ${GMOCK_LIBRARIES} PARENT_SCOPE)
 set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS} PARENT_SCOPE)
 set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} PARENT_SCOPE)
+set(GMOCK_COMPILE_DEFINITIONS ${GMOCK_COMPILE_DEFINITIONS} PARENT_SCOPE)
index baccdc1f48d70392adae124bff98658b085824e9..3ae077ecb3fe7247b03ad71fb154a0d4d8115aca 100644 (file)
  *
  * \inlibraryapi
  */
+//! \cond
 #ifdef HAVE_CONFIG_H
 #include "gmxpre-config.h"
 #endif
 
+/* We use a few GNU functions for thread affinity and other low-level stuff.
+ * However, all such uses should be accompanied by #ifdefs and a feature test
+ * at CMake level, so that the actual uses will be compiled only when available.
+ * But since the define affects system headers, it should be defined before
+ * including any system headers, and this is a robust location to do that.
+ * If this were defined only in source files that needed it, it would clutter
+ * the list of includes somewhere close to the beginning and make automatic
+ * sorting of the includes more difficult.
+ */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
 #ifdef GMX_FAHCORE
 #define FULLINDIRECT 1
 #define USE_FAH_XDR  1
 #include "swindirect.h"
 #endif
+//! \endcond
index 18109192d9cd1410f7b4119f83aa4e6c1bd2089a..3ea2d42c4032442e9afbc324c83be739edec9689 100644 (file)
  */
 #include "gmxpre.h"
 
+#include "gromacs/legacyheaders/gmx_cpuid.h"
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#ifdef HAVE_SCHED_H
-#  ifndef _GNU_SOURCE
-#    define _GNU_SOURCE 1
-#  endif
-#  include <sched.h>
-#endif
-
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #ifdef GMX_NATIVE_WINDOWS
 /* MSVC definition for __cpuid() */
     #ifdef _MSC_VER
 /* sysinfo functions */
     #include <windows.h>
 #endif
+#ifdef HAVE_SCHED_H
+    #include <sched.h>
+#endif
 #ifdef HAVE_UNISTD_H
 /* sysconf() definition */
     #include <unistd.h>
 #endif
 
-#include "gromacs/legacyheaders/gmx_cpuid.h"
-
-
 
 /* For convenience, and to enable configure-time invocation, we keep all architectures
  * in a single file, but to avoid repeated ifdefs we set the overall architecture here.
index 69e256fbca94283f969d57c9f7473f63103b940d..75e277999be1fcef991d5d14a30d2456a8449214 100644 (file)
  */
 #include "gmxpre.h"
 
-#include "config.h"
-
-#ifdef HAVE_SCHED_AFFINITY
-#  ifndef _GNU_SOURCE
-#    define _GNU_SOURCE 1
-#  endif
-#  include <sched.h>
-#  include <sys/syscall.h>
-#endif
-
 #include "gromacs/legacyheaders/gmx_thread_affinity.h"
 
+#include "config.h"
+
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
+#ifdef HAVE_SCHED_AFFINITY
+#  include <sched.h>
+#  include <sys/syscall.h>
+#endif
+
 #include "thread_mpi/threads.h"
 
 #include "gromacs/legacyheaders/copyrite.h"