From: Teemu Murtola Date: Tue, 9 Sep 2014 18:27:36 +0000 (+0300) Subject: Move _GNU_SOURCE to gmxpre.h X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?p=alexxy%2Fgromacs.git;a=commitdiff_plain;h=2c8e4fac688f51c7b779c13a542f4700a221715d Move _GNU_SOURCE to gmxpre.h 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 --- diff --git a/src/external/gmock-1.7.0/CMakeLists.txt b/src/external/gmock-1.7.0/CMakeLists.txt index d0552fb3f9..c9404bf48b 100644 --- a/src/external/gmock-1.7.0/CMakeLists.txt +++ b/src/external/gmock-1.7.0/CMakeLists.txt @@ -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) diff --git a/src/gmxpre.h b/src/gmxpre.h index baccdc1f48..3ae077ecb3 100644 --- a/src/gmxpre.h +++ b/src/gmxpre.h @@ -53,12 +53,27 @@ * * \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 diff --git a/src/gromacs/gmxlib/gmx_cpuid.c b/src/gromacs/gmxlib/gmx_cpuid.c index 18109192d9..3ea2d42c40 100644 --- a/src/gromacs/gmxlib/gmx_cpuid.c +++ b/src/gromacs/gmxlib/gmx_cpuid.c @@ -34,21 +34,17 @@ */ #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 -#endif - #include #include #include #include + #ifdef GMX_NATIVE_WINDOWS /* MSVC definition for __cpuid() */ #ifdef _MSC_VER @@ -57,14 +53,14 @@ /* sysinfo functions */ #include #endif +#ifdef HAVE_SCHED_H + #include +#endif #ifdef HAVE_UNISTD_H /* sysconf() definition */ #include #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. diff --git a/src/gromacs/gmxlib/gmx_thread_affinity.c b/src/gromacs/gmxlib/gmx_thread_affinity.c index 69e256fbca..75e277999b 100644 --- a/src/gromacs/gmxlib/gmx_thread_affinity.c +++ b/src/gromacs/gmxlib/gmx_thread_affinity.c @@ -34,23 +34,20 @@ */ #include "gmxpre.h" -#include "config.h" - -#ifdef HAVE_SCHED_AFFINITY -# ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -# endif -# include -# include -#endif - #include "gromacs/legacyheaders/gmx_thread_affinity.h" +#include "config.h" + #include #include #include #include +#ifdef HAVE_SCHED_AFFINITY +# include +# include +#endif + #include "thread_mpi/threads.h" #include "gromacs/legacyheaders/copyrite.h"