Manage compiler flags and some include options per file or target, not globally
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 31 Jul 2019 09:55:35 +0000 (11:55 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 1 Aug 2019 13:16:43 +0000 (15:16 +0200)
The legacy CMake approach of adding to the global compiler flags
variables is no longer accepted practice. Following the new idiom will
give us more control, e.g. over whether warning flags intended for
GROMACS code will apply to e.g. external code. Now all kinds of
generated and external code cannot emit any of the warnings that we
intend to enable for GROMACS code.

Compiler command lines are now constructed from proper CMake lists of
flags, ie. with semicolon separators. This means we can use more
modern CMake idiom with generator strings, rather than munging our own
strings into compiler command lines.

Similarly, include directories such as for thread-MPI are no longer
added globally.

Some flags that disable warnings activated by bulk warning flags are
changed to be detected in an order that still produces a list of flags
that disables groups of warnings as intended.

Silenced a few MSVC warnings about things that are not worth fixing
for GROMACS.

Change-Id: I8cc470ad74264dc11bc292988f50cc16cbb02437

30 files changed:
CMakeLists.txt
cmake/gmxCFlags.cmake
cmake/gmxManageFFTLibraries.cmake
cmake/gmxManageSimd.cmake
cmake/gmxManageTNG.cmake
share/template/CMakeLists.txt
share/template/template.cpp
src/CMakeLists.txt
src/api/cpp/CMakeLists.txt
src/external/googletest/CMakeLists.txt
src/gromacs/CMakeLists.txt
src/gromacs/analysisdata/dataframe.h
src/gromacs/domdec/partition.cpp
src/gromacs/ewald/pme_spread.cpp
src/gromacs/fileio/CMakeLists.txt
src/gromacs/linearalgebra/CMakeLists.txt
src/gromacs/listed_forces/position_restraints.cpp
src/gromacs/math/functions.h
src/gromacs/math/vec.h
src/gromacs/selection/CMakeLists.txt
src/gromacs/selection/nbsearch.h
src/gromacs/topology/block.h
src/gromacs/topology/forcefieldparameters.h
src/gromacs/topology/idef.h
src/gromacs/topology/topology.h
src/gromacs/utility/smalloc.h
src/programs/CMakeLists.txt
src/programs/mdrun/tests/CMakeLists.txt
src/testutils/CMakeLists.txt
src/testutils/TestMacros.cmake

index ecc8d18281a4fb8e71fb194092cb271df9043c57..cd8a31a09338920ce66cf94b88c275eb1b3e5109 100644 (file)
@@ -310,13 +310,14 @@ include(gmxManageOpenMP)
 include(gmxCFlags)
 gmx_c_flags()
 
-# This variable should be used for additional compiler flags which are not
-# generated in gmxCFlags nor are SIMD or MPI related.
+# These variables should be used for CMake-style lists (ie. separated
+# by semicolons) of additional compiler flags which are not generated
+# in gmxCFlags nor are SIMD or MPI related.
 #
 # TODO These variables should be consolidated into
 # EXTRA_COMPILER_FLAGS so that we we don't perpetrate bugs where
 # things that work in C compilation (e.g. merging from old branches)
-# also work for C++ compilation.
+# might not also work for C++ compilation.
 set(EXTRA_C_FLAGS "")
 set(EXTRA_CXX_FLAGS "")
 
@@ -587,11 +588,7 @@ gmx_add_cache_dependency(GMX_BUILD_UNITTESTS BOOL BUILD_TESTING OFF)
 # Our own GROMACS tests
 ########################################################################
 
-add_definitions( -DHAVE_CONFIG_H )
 include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src)
-# TODO required at high level because both libgromacs and progs/mdrun
-# require it, both for thread-MPI and its atomics and mutexes.
-include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/include)
 # Required for config.h, maybe should only be set in src/CMakeLists.txt
 include_directories(BEFORE ${CMAKE_BINARY_DIR}/src)
 
@@ -761,18 +758,18 @@ endif()
 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
 # these are set after everything else
 if (NOT GMX_SKIP_DEFAULT_CFLAGS)
-    set(CMAKE_C_FLAGS "${SIMD_C_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_C_FLAGS} ${CMAKE_C_FLAGS}")
-    set(CMAKE_CXX_FLAGS "${SIMD_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
     set(CMAKE_EXE_LINKER_FLAGS "${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
     set(CMAKE_SHARED_LINKER_FLAGS "${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
 else()
     message("Recommended flags which are not added because GMX_SKIP_DEFAULT_CFLAGS=yes:")
-    message("CMAKE_C_FLAGS: ${SIMD_C_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_C_FLAGS} ${GMXC_CFLAGS}")
-    message("CMAKE_C_FLAGS_RELEASE: ${GMXC_CFLAGS_RELEASE}")
-    message("CMAKE_C_FLAGS_DEBUG: ${GMXC_CFLAGS_DEBUG}")
-    message("CMAKE_CXX_FLAGS: ${SIMD_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_CXX_FLAGS} ${GMXC_CXXFLAGS}")
-    message("CMAKE_CXX_FLAGS_RELEASE: ${GMXC_CXXFLAGS_RELEASE}")
-    message("CMAKE_CXX_FLAGS_DEBUG: ${GMXC_CXXFLAGS_DEBUG}")
+    message("CMAKE_C_FLAGS: ${SIMD_C_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_C_FLAGS};${GMXC_CFLAGS}")
+    foreach(build_type ${build_types_with_explicit_flags})
+        message("CMAKE_C_FLAGS_${build_type}: ${GMXC_CFLAGS_${build_type}}")
+    endforeach()
+    message("CMAKE_CXX_FLAGS: ${SIMD_CXX_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_CXX_FLAGS};${GMXC_CXXFLAGS}")
+    foreach(build_type ${build_types_with_explicit_flags})
+        message("CMAKE_CXX_FLAGS_${build_type}: ${GMXC_CXXFLAGS_${build_type}}")
+    endforeach()
     message("CMAKE_EXE_LINKER_FLAGS: ${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS}")
     message("CMAKE_SHARED_LINKER_FLAGS: ${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS}")
 endif()
index a345d31632b79018129363d80eab3f53531f6bb0..5400fc5f1b9a2f2ffaa00beb9f2effd54af2de39 100644 (file)
@@ -39,7 +39,7 @@ MACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
         CHECK_C_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
     ENDIF()
     IF (${VARIABLE})
-        SET (${CFLAGSVAR} "${FLAGS} ${${CFLAGSVAR}}")
+        list(APPEND ${CFLAGSVAR} "${FLAGS}")
     ENDIF ()
 ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
 
@@ -50,7 +50,7 @@ MACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
         CHECK_CXX_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
     ENDIF()
     IF (${VARIABLE})
-        SET (${CXXFLAGSVAR} "${FLAGS} ${${CXXFLAGSVAR}}")
+        list(APPEND ${CXXFLAGSVAR} "${FLAGS}")
     ENDIF ()
 ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
 
@@ -65,7 +65,7 @@ function(gmx_set_cmake_compiler_flags)
         # inconvenient in CMake to pass more than one list, and such a
         # list is only used here.
         foreach(build_type RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
-            set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE} ${GMXC_${language}FLAGS_${build_type}}")
+            set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE}" "${GMXC_${language}FLAGS_${build_type}}")
         endforeach()
         # Copy the flags that are only used by the real Release build
         # type. Used for, e.g., -Wno-array-bounds in Release to work around
@@ -73,30 +73,44 @@ function(gmx_set_cmake_compiler_flags)
         # while using RelWithAssert (ie. without that suppression) in Jenkins.
         #
         # TODO check the behaviour of more recent gcc on the improved code
-        set(GMXC_${language}FLAGS_RELEASE "${GMXC_${language}FLAGS_RELEASE} ${GMXC_${language}FLAGS_RELEASE_ONLY}")
-
-        # Modify the real CMake variables for compiler flags for all
-        # builds and language types, and also those common to all
-        # build types.
-        foreach(build_type "" ${build_types_with_explicit_flags})
-            if("${build_type}" STREQUAL "")
-                set(punctuation "") # for general compiler flags (e.g.) CMAKE_CXX_FLAGS
-            else()
-                set(punctuation "_") # for build-type-specific compiler flags (e.g.) CMAKE_CXX_FLAGS_RELEASE
-            endif()
+        set(GMXC_${language}FLAGS_RELEASE "${GMXC_${language}FLAGS_RELEASE}" "${GMXC_${language}FLAGS_RELEASE_ONLY}")
+    endforeach()
+endfunction()
 
-            # Append to the variables for the given build type for
-            # each language, in the parent scope. We add our new variables at the end, so
-            # compiler-specific choices are more likely to override default CMake choices.
-            # This is for instance useful for RelWithDebInfo builds, where we want to use the full
-            # set of our optimization flags detected in this file, rather than having -O2 override them.
-            set(CMAKE_${language}_FLAGS${punctuation}${build_type}
-                "${CMAKE_${language}_FLAGS${punctuation}${build_type}} ${GMXC_${language}FLAGS${punctuation}${build_type}}"
-                PARENT_SCOPE)
+# Add compiler flags expected for all GROMACS build configurations,
+# and those expected for the current CMake build type (e.g. Release)
+# to TARGET.
+#
+# Most targets (ie. libraries, executables) need compiler flags that
+# are characteristic of the build configuration. This function
+# provides a central point for adding such flags. This approach is
+# more flexible than e.g. setting CMAKE_CXX_FLAGS globally, because
+# that setting will apply globally, which means it applies also to
+# "external" code that the build of GROMACS might also build.
+function(gmx_target_compile_options TARGET)
+    if (NOT GMX_SKIP_DEFAULT_CFLAGS)
+        target_compile_options(${TARGET}
+            PRIVATE
+            $<$<COMPILE_LANGUAGE:C>:${SIMD_C_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_C_FLAGS};${GMXC_CFLAGS}>
+            $<$<COMPILE_LANGUAGE:CXX>:${SIMD_CXX_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_CXX_FLAGS};${GMXC_CXXFLAGS}>
+            )
+        foreach(build_type ${build_types_with_explicit_flags})
+            target_compile_options(${TARGET}
+                BEFORE PRIVATE
+                $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:${build_type}>>:${GMXC_CFLAGS_${build_type}}>
+                $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:${build_type}>>:${GMXC_CXXFLAGS_${build_type}}>
+                )
         endforeach()
-    endforeach()
+    endif()
 endfunction()
 
+# Add the WARNING_FLAG to the compile options for TARGET if the
+# compiler supports that flag. VARNAME is used to cache the result of
+# the check whether the compiler supports that flag, as multiple
+# targets may use the same suppression.
+#
+# This is generally used to suppress warnings judged not worth fixing
+# in code external to, or generated by, GROMACS.
 function(gmx_target_warning_suppression TARGET WARNING_FLAG VARNAME)
     check_cxx_compiler_flag(${WARNING_FLAG} ${VARNAME})
     if(${VARNAME})
@@ -117,8 +131,8 @@ macro (gmx_c_flags)
             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
         endif()
         if (GMX_COMPILER_WARNINGS)
-            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
-            GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wpointer-arith" GMXC_CFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wno-sign-compare;-Wpointer-arith" GMXC_CFLAGS)
             GMX_TEST_CFLAG(CFLAGS_WARN_UNDEF "-Wundef" GMXC_CFLAGS)
             GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY)
             if(CYGWIN)
@@ -141,7 +155,7 @@ macro (gmx_c_flags)
             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
             # Problematic with CUDA
             # GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EFFCXX "-Wnon-virtual-dtor" GMXC_CXXFLAGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith -Wmissing-declarations" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-declarations" GMXC_CXXFLAGS)
             # CUDA versions prior to 7.5 come with a header (math_functions.h) which uses the _MSC_VER macro
             # unconditionally, so we don't use -Wundef for earlier CUDA versions.
             if(NOT(GMX_GPU AND CUDA_VERSION VERSION_LESS "7.5"))
@@ -184,12 +198,15 @@ macro (gmx_c_flags)
 #3280: declaration hides member ".."
 #11074: Inlining inhibited by limit max-size(/max-total-size)
 #11076: To get full report use -opt-report=3 -opt-report-phase ipo (shown for previous remark)
-                GMX_TEST_CFLAG(CFLAGS_WARN "-w3 -wd177 -wd411 -wd593 -wd981 -wd1418 -wd1419 -wd1572 -wd1599 -wd2259 -wd2415 -wd2547 -wd2557 -wd3280 -wd11074 -wd11076" GMXC_CFLAGS)
+                GMX_TEST_CFLAG(CFLAGS_WARN "-w3;-wd177;-wd411;-wd593;-wd981;-wd1418;-wd1419;-wd1572;-wd1599;-wd2259;-wd2415;-wd2547;-wd2557;-wd3280;-wd11074;-wd11076" GMXC_CFLAGS)
             endif()
             GMX_TEST_CFLAG(CFLAGS_STDGNU "-std=gnu99" GMXC_CFLAGS)
-            GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias -no-prec-div -fimf-domain-exclusion=14 -qoverride-limits" GMXC_CFLAGS_RELEASE)
+            GMX_TEST_CFLAG(CFLAGS_OPT "-ip;-funroll-all-loops;-alias-const;-ansi-alias;-no-prec-div;-fimf-domain-exclusion=14;-qoverride-limits" GMXC_CFLAGS_RELEASE)
             GMX_TEST_CFLAG(CFLAGS_DEBUG "-O0" GMXC_CFLAGS_DEBUG) #icc defaults to -O2 even with -g
-            GMX_TEST_CFLAG(CFLAGS_FP_RELASSERT "-fp-model except -fp-model precise" GMXC_CFLAGS_RELWITHASSERT)
+            # The "except" fp-model requires something other than the
+            # default "fast" model, so we test and use it with
+            # "precise".
+            GMX_TEST_CFLAG(CFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CFLAGS_RELWITHASSERT)
         else()
             if(NOT GMX_OPENMP)
                 GMX_TEST_CFLAG(CFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
@@ -198,7 +215,7 @@ macro (gmx_c_flags)
 #only on Windows
 #161: unrecognized pragma
 #1786 function was declared deprecated (is issued for stdlib function such as strncpy which have a _s version)
-GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd1419 /wd1572 /wd1599 /wd1786 /wd2259 /wd2415 /wd2547 /wd2557 /wd3280" GMXC_CFLAGS)
+GMX_TEST_CFLAG(CFLAGS_WARN "/W3;/wd161;/wd177;/wd411;/wd593;/wd981;/wd1418;/wd1419;/wd1572;/wd1599;/wd1786;/wd2259;/wd2415;/wd2547;/wd2557;/wd3280" GMXC_CFLAGS)
             endif()
             GMX_TEST_CFLAG(CFLAGS_OPT "/Qip" GMXC_CFLAGS_RELEASE)
         endif()
@@ -216,11 +233,14 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
 # 444: destructor for base class ".." is not virtual
 # 869: was never referenced (false positives)
 #2282: unrecognized GCC pragma
-                GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3 -wd177 -wd304 -wd383 -wd411 -wd444 -wd869 -wd981 -wd1418 -wd1572 -wd1599 -wd2259 -wd2547 -wd3280 -wd11074 -wd11076 -wd2282" GMXC_CXXFLAGS)
+                GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3;-wd177;-wd304;-wd383;-wd411;-wd444;-wd869;-wd981;-wd1418;-wd1572;-wd1599;-wd2259;-wd2547;-wd3280;-wd11074;-wd11076;-wd2282" GMXC_CXXFLAGS)
             endif()
-            GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias -no-prec-div -fimf-domain-exclusion=14 -qoverride-limits" GMXC_CXXFLAGS_RELEASE)
+            GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip;-funroll-all-loops;-alias-const;-ansi-alias;-no-prec-div;-fimf-domain-exclusion=14;-qoverride-limits" GMXC_CXXFLAGS_RELEASE)
             GMX_TEST_CXXFLAG(CXXFLAGS_DEBUG "-O0" GMXC_CXXFLAGS_DEBUG)
-            GMX_TEST_CXXFLAG(CXXFLAGS_FP_RELASSERT "-fp-model except -fp-model precise" GMXC_CXXFLAGS_RELWITHASSERT)
+            # The "except" fp-model requires something other than the
+            # default "fast" model, so we test and use it with
+            # "precise".
+            GMX_TEST_CXXFLAG(CXXFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CXXFLAGS_RELWITHASSERT)
         else()
             if(NOT GMX_OPENMP)
                 GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
@@ -228,7 +248,7 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
             if (GMX_COMPILER_WARNINGS)
 #161: unrecognized pragma
 #809: exception specification for virtual function X is incompatible with that of overridden function
-                GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3 /wd161 /wd177 /wd304 /wd383 /wd411 /wd444 /wd809 /wd869 /wd981 /wd1418 /wd1572 /wd1599 /wd1786 /wd2259 /wd2547 /wd3280 /wd11074 /wd11076 /wd2282" GMXC_CXXFLAGS)
+                GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3;/wd161;/wd177;/wd304;/wd383;/wd411;/wd444;/wd809;/wd869;/wd981;/wd1418;/wd1572;/wd1599;/wd1786;/wd2259;/wd2547;/wd3280;/wd11074;/wd11076;/wd2282" GMXC_CXXFLAGS)
             endif()
             GMX_TEST_CXXFLAG(CXXFLAGS_OPT "/Qip" GMXC_CXXFLAGS_RELEASE)
         endif()
@@ -254,9 +274,9 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
         endif()
         if (GMX_COMPILER_WARNINGS)
-            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CFLAGS)
         endif()
-        GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
+        GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
                          GMXC_CFLAGS_RELEASE)
         GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
     endif()
@@ -265,9 +285,9 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
         endif()
         if (GMX_COMPILER_WARNINGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CXXFLAGS)
         endif()
-        GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
+        GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
                          GMXC_CXXFLAGS_RELEASE)
     endif()
 
@@ -277,15 +297,15 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
     # 1500-010: (W) about correct PBC-related use of maximum array indices of DIM-sized C arrays
     # 1500-030: (I) Additional optimization may be attained by recompiling and specifying MAXMEM option with a value greater than 8192.
     if (CMAKE_C_COMPILER_ID MATCHES "XL")
-        GMX_TEST_CFLAG(CFLAGS_ARCH "-qarch=auto -qtune=auto" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CFLAGS)
         GMX_TEST_CFLAG(CFLAGS_OPT  "-O3" GMXC_CFLAGS_RELEASE)
         GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
-        GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010 -qsuppress=1500-030" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CFLAGS)
     endif()
     if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
-        GMX_TEST_CXXFLAG(CXXFLAGS_ARCH "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CXXFLAGS)
         GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-O3" GMXC_CXXFLAGS_RELEASE)
-        GMX_TEST_CXXFLAG(CXXFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010 -qsuppress=1500-030" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CXXFLAGS)
     endif()
 
     # msvc
@@ -294,17 +314,17 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
         #      forcing value to bool
         #      "this" in initializer list
         #      deprecated (posix, secure) functions
-        #      truncation (double -> float)
-        #      conversion from 'double' to 'real', possible loss of data
+        #      C4305: truncation (double -> float)
+        #      C4244: conversion from 'double' to 'real', possible loss of data
         #      unreferenced local variable (only C)
-        #      conversion from 'size_t' to 'int', possible loss of data
+        #      C4267: conversion from 'size_t' to 'int', possible loss of data
         #      conversion from 'const char*' to 'void*', different 'const' qualifiers (only C)
         #      unknown pragma (4068)
         if(NOT CMAKE_CONFIGURATION_TYPES)
-            GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090 /wd4068" GMXC_CFLAGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4267 /wd4068" GMXC_CXXFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068" GMXC_CFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4267;/wd4068" GMXC_CXXFLAGS)
         else() # MSVC projects only use the C++ flags
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090 /wd4068" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068" GMXC_CXXFLAGS)
         endif()
     endif()
 
@@ -313,36 +333,37 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd14
             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
         endif()
         if (GMX_COMPILER_WARNINGS)
-            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
             GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wpointer-arith" GMXC_CFLAGS_EXTRA)
         endif()
     endif()
 
     if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-        if(NOT GMX_OPENMP)
-            GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
-        endif()
         if (GMX_COMPILER_WARNINGS)
+            # If used, -Wall should precede other options that silence warnings it enables
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
             if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") #LLVM BUG #21629
                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN_NO_BRACES "-Wno-missing-braces" GMXC_CXXFLAGS)
             endif()
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith -Wmissing-prototypes" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-prototypes" GMXC_CXXFLAGS)
             GMX_TEST_CXXFLAG(CXXFLAGS_DEPRECATED "-Wdeprecated" GMXC_CXXFLAGS)
         endif()
+        if(NOT GMX_OPENMP)
+            GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
+        endif()
     endif()
 
     # Fujitsu compilers on PrimeHPC/Sparc64
     if(${CMAKE_C_COMPILER_ID} MATCHES Fujitsu OR
        (${CMAKE_C_COMPILER_ID} MATCHES unknown AND ${CMAKE_C_COMPILER} MATCHES ^fcc))
-        GMX_TEST_CFLAG(CFLAG_GNUCOMPAT "-Xg -w" GMXC_CFLAGS)
-        GMX_TEST_CFLAG(CFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple -x100" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAG_GNUCOMPAT "-Xg;-w" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CFLAGS)
     endif()
 
     if(${CMAKE_CXX_COMPILER_ID} MATCHES Fujitsu OR
        (${CMAKE_CXX_COMPILER_ID} MATCHES unknown AND ${CMAKE_CXX_COMPILER} MATCHES ^FCC))
-        GMX_TEST_CXXFLAG(CXXFLAG_GNUCOMPAT "-Xg -w" GMXC_CXXFLAGS)
-        GMX_TEST_CXXFLAG(CXXFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple -x100" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAG_GNUCOMPAT "-Xg;-w" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CXXFLAGS)
     endif()
 
     # now actually set the flags:
index 46818d006aa8ea8b79e8c9c015e4cea47331b147..ff485cd95fc14be9621f106fa913082a6d9d5a56 100644 (file)
@@ -137,8 +137,8 @@ elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
         endif()
         # Some versions of icc require this in order that mkl.h can be
         # found at compile time.
-        set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} ${FFT_LINKER_FLAGS}")
-        set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} ${FFT_LINKER_FLAGS}")
+        list(APPEND EXTRA_C_FLAGS ${FFT_LINKER_FLAGS})
+        list(APPEND EXTRA_CXX_FLAGS ${FFT_LINKER_FLAGS})
 
         set(MKL_ERROR_MESSAGE "Make sure you have configured your compiler so that ${FFT_LINKER_FLAGS} will work.")
     else()
index 4bfbe799c7d53da3672d1813afcb2ef2782d0ffc..4e01441e31eeced8ca13df01e6b53b821c1617a9 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -105,8 +105,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "SSE2")
         gmx_give_fatal_error_when_simd_support_not_found("SSE2" "disable SIMD support (slow)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_SSE2_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_SSE2_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_SSE2_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_SSE2_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling SSE2 SIMD instructions using CXX flags: ${SIMD_SSE2_CXX_FLAGS}")
 
@@ -119,8 +120,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "SSE4.1")
         gmx_give_fatal_error_when_simd_support_not_found("SSE4.1" "choose SSE2 SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_SSE4_1_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_SSE4_1_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_SSE4_1_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_SSE4_1_CXX_FLAGS})
     set(GMX_SIMD_X86_SSE4_1 1)
     set(SIMD_STATUS_MESSAGE "Enabling SSE4.1 SIMD instructions using CXX flags: ${SIMD_SSE4_1_CXX_FLAGS}")
 
@@ -133,8 +135,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "AVX_128_FMA")
         gmx_give_fatal_error_when_simd_support_not_found("128-bit AVX with FMA support" "choose SSE4.1 SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_AVX_128_FMA_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_AVX_128_FMA_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_AVX_128_FMA_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_AVX_128_FMA_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling 128-bit AMD FMA SIMD instructions using CXX flags: ${SIMD_AVX_128_FMA_CXX_FLAGS}")
 
@@ -147,8 +150,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "AVX_256")
         gmx_give_fatal_error_when_simd_support_not_found("AVX" "choose SSE4.1 SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_AVX_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_AVX_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_AVX_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_AVX_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling 256-bit AVX SIMD instructions using CXX flags: ${SIMD_AVX_CXX_FLAGS}")
 
@@ -161,8 +165,9 @@ elseif(GMX_SIMD_ACTIVE MATCHES "AVX2_")
         gmx_give_fatal_error_when_simd_support_not_found("AVX2" "choose AVX SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_AVX2_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_AVX2_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_AVX2_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_AVX2_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
 
     if(GMX_SIMD_ACTIVE STREQUAL "AVX2_128")
@@ -186,8 +191,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "AVX_512")
         gmx_give_fatal_error_when_simd_support_not_found("AVX 512F" "choose a lower level of SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_AVX_512_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_AVX_512_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_AVX_512_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_AVX_512_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling 512-bit AVX-512 SIMD instructions using CXX flags: ${SIMD_AVX_512_CXX_FLAGS}")
 
@@ -200,8 +206,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "AVX_512_KNL")
         gmx_give_fatal_error_when_simd_support_not_found("AVX 512ER" "choose a lower level of SIMD (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_AVX_512_KNL_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_AVX_512_KNL_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_AVX_512_KNL_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_AVX_512_KNL_CXX_FLAGS})
     set(GMX_SIMD_X86_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling 512-bit AVX-512-KNL SIMD instructions using CXX flags: ${SIMD_AVX_512_KNL_CXX_FLAGS}")
 
@@ -218,8 +225,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "ARM_NEON")
         gmx_give_fatal_error_when_simd_support_not_found("ARM NEON" "disable SIMD support (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_ARM_NEON_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_ARM_NEON_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_ARM_NEON_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_ARM_NEON_CXX_FLAGS})
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling 32-bit ARM NEON SIMD instructions using CXX flags: ${SIMD_ARM_NEON_CXX_FLAGS}")
 
@@ -232,8 +240,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "ARM_NEON_ASIMD")
         gmx_give_fatal_error_when_simd_support_not_found("ARM (AArch64) NEON Advanced SIMD" "particularly gcc version 4.9 or later, or disable SIMD support (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_ARM_NEON_ASIMD_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_ARM_NEON_ASIMD_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_ARM_NEON_ASIMD_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_ARM_NEON_ASIMD_CXX_FLAGS})
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling ARM (AArch64) NEON Advanced SIMD instructions using CXX flags: ${SIMD_ARM_NEON_ASIMD_CXX_FLAGS}")
 
@@ -246,8 +255,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "IBM_VMX")
         gmx_give_fatal_error_when_simd_support_not_found("IBM VMX" "disable SIMD support (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_IBM_VMX_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_IBM_VMX_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_IBM_VMX_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_IBM_VMX_CXX_FLAGS})
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling IBM VMX SIMD instructions using CXX flags: ${SIMD_IBM_VMX_CXX_FLAGS}")
 
@@ -265,8 +275,9 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "IBM_VSX")
         gmx_give_fatal_error_when_simd_support_not_found("IBM VSX" "disable SIMD support (slower)" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
 
-    set(SIMD_C_FLAGS "${SIMD_IBM_VSX_C_FLAGS}")
-    set(SIMD_CXX_FLAGS "${SIMD_IBM_VSX_CXX_FLAGS}")
+    # If multiple flags are neeed, make them into a list
+    string(REPLACE " " ";" SIMD_C_FLAGS ${SIMD_IBM_VSX_C_FLAGS})
+    string(REPLACE " " ";" SIMD_CXX_FLAGS ${SIMD_IBM_VSX_CXX_FLAGS})
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
     set(SIMD_STATUS_MESSAGE "Enabling IBM VSX SIMD instructions using CXX flags: ${SIMD_IBM_VSX_CXX_FLAGS}")
 
index 8ef96a298d184c44870bda924db76fc16bf2af90..a9ac209c7841a496b391dfe76b07843d32e85d48 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2016, by the GROMACS development team, led by
+# Copyright (c) 2016,2019, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -82,6 +82,7 @@ function(gmx_setup_tng_for_libgromacs)
             include(${BUNDLED_TNG_LOCATION}/BuildTNG.cmake)
             add_tng_io_library(tng_io OBJECT ${_zlib_arg})
             add_library(tng_io::tng_io ALIAS tng_io)
+            gmx_target_compile_options(tng_io_obj)
             target_link_libraries(libgromacs PRIVATE $<BUILD_INTERFACE:tng_io::tng_io>)
         endif()
     endif()
index e4d4c0a674e844d13fcd93978d0c49eb613ef869..330cbbd460739e2bf14991f7068869445bcf2746 100644 (file)
 # the research papers on the package. Check out http://www.gromacs.org.
 
 add_executable(template template.cpp)
+if (WIN32)
+    gmx_target_warning_suppression(template /wd4244 HAS_NO_MSVC_LOSSY_CONVERSION_DOUBLE_TO_REAL)
+    gmx_target_warning_suppression(template /wd4267 HAS_NO_MSVC_LOSSY_CONVERSION_SIZE_T_TO_INT)
+endif()
 target_link_libraries(template libgromacs ${GMX_EXE_LINKER_FLAGS})
 
 set(DOCUMENTATION_HTTP_URL_BASE
index 5b82cd5fdd1ce5b4a156de7da49f269d31ebd55b..e2111c53db9b81d6712b627ed82af2ec85c0af78 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -125,7 +125,7 @@ void
 AnalysisTemplate::initAnalysis(const TrajectoryAnalysisSettings &settings,
                                const TopologyInformation         & /*top*/)
 {
-    nb_.setCutoff(cutoff_);
+    nb_.setCutoff(static_cast<real>(cutoff_));
 
     data_.setColumnCount(0, sel_.size());
 
index d65461a98991966c7e5cca326d2c615377ad4a36..028a5ba1736e6521fa8bc09f1524b0601e6d0e8b 100644 (file)
@@ -41,6 +41,9 @@ get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
 if(GMX_USE_CUDA)
     if(NOT GMX_CLANG_CUDA)
         GMX_SET_CUDA_NVCC_FLAGS()
+        # Source files generated by NVCC can include gmxmpi.h, and so
+        # need access to thread-MPI.
+        set(CUDA_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
     endif()
 
     get_cuda_compiler_info(CUDA_COMPILER_INFO CUDA_COMPILER_FLAGS)
index bdfabf97e771ad124ea2f63919c9954a269da06c..4eb50201c474856f40dbf85d14092e1e5f9f8969 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2018, by the GROMACS development team, led by
+# Copyright (c) 2018,2019, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -61,6 +61,9 @@ add_library(gmxapi SHARED
             system.cpp
             version.cpp
             workflow.cpp)
+gmx_target_compile_options(gmxapi)
+target_compile_definitions(gmxapi PRIVATE HAVE_CONFIG_H)
+target_include_directories(gmxapi SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
 
 # Define public interface. Make sure targets linking against `gmxapi` in the build
 # system don't accidentally have the implementation headers (this directory))
index f37e34f30978ec5a876c643063a2ae68aec66f72..43ebcb687c3fc2dc3ef3c92e47afe206fdd29a08 100644 (file)
@@ -50,6 +50,9 @@ else()
     list(APPEND GMOCK_COMPILE_DEFINITIONS "GTEST_HAS_PTHREAD=0")
     set(GTEST_IS_THREADSAFE 0)
 endif()
+if (WIN32)
+    list(APPEND GMOCK_COMPILE_DEFINITIONS _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
+endif()
 
 set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googlemock)
 set(GTEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
@@ -70,7 +73,7 @@ endif()
 
 add_library(gmock STATIC ${UNITTEST_TARGET_OPTIONS} ${GMOCK_SOURCES} ${GTEST_SOURCES})
 set_property(TARGET gmock APPEND PROPERTY COMPILE_DEFINITIONS
-             "_GNU_SOURCE=1;${GMOCK_COMPILE_DEFINITIONS};GTEST_CAN_STREAM_RESULTS=0")
+    "_GNU_SOURCE=1;${GMOCK_COMPILE_DEFINITIONS};GTEST_CAN_STREAM_RESULTS=0")
 set_property(TARGET gmock APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
 
 set(GMOCK_LIBRARIES gmock ${PTHREADS_LIBRARIES} PARENT_SCOPE)
index 13f823b6422c7ec161e8e13c897c9e8ce2a1e4f7..5239949b9bc8c1bec4d0cbf8bc4c4f475bbb8cba 100644 (file)
@@ -110,7 +110,6 @@ add_subdirectory(timing)
 add_subdirectory(topology)
 add_subdirectory(trajectory)
 add_subdirectory(utility)
-add_subdirectory(fileio)
 add_subdirectory(swap)
 add_subdirectory(essentialdynamics)
 add_subdirectory(pulling)
@@ -126,7 +125,6 @@ if (NOT GMX_BUILD_MDRUN_ONLY)
     add_subdirectory(statistics)
     add_subdirectory(analysisdata)
     add_subdirectory(coordinateio)
-    add_subdirectory(selection)
     add_subdirectory(trajectoryanalysis)
     add_subdirectory(energyanalysis)
     add_subdirectory(tools)
@@ -143,6 +141,11 @@ list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES} ${PROPERTY_SOU
 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
 tmpi_get_source_list(THREAD_MPI_SOURCES ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/src)
 add_library(thread_mpi OBJECT ${THREAD_MPI_SOURCES})
+target_compile_definitions(thread_mpi PRIVATE HAVE_CONFIG_H)
+gmx_target_compile_options(thread_mpi)
+if (WIN32)
+    gmx_target_warning_suppression(thread_mpi /wd4996 HAS_NO_MSVC_UNSAFE_FUNCTION)
+endif()
 list(APPEND libgromacs_object_library_dependencies thread_mpi)
 
 configure_file(version.h.cmakein version.h)
@@ -160,7 +163,7 @@ gmx_install_headers(
 # This code is here instead of utility/CMakeLists.txt, because CMake
 # custom commands and source file properties can only be set in the directory
 # that contains the target that uses them.
-# TODO: Generate a header instead that can be included from baseversion.c.
+# TODO: Generate a header instead that can be included from baseversion.cpp.
 # That probably simplifies things somewhat.
 set(GENERATED_VERSION_FILE utility/baseversion-gen.cpp)
 gmx_configure_version_file(
@@ -207,6 +210,11 @@ else()
     add_library(libgromacs ${LIBGROMACS_SOURCES})
 endif()
 
+add_subdirectory(fileio)
+if (NOT GMX_BUILD_MDRUN_ONLY)
+    add_subdirectory(selection)
+endif()
+
 # Handle the object libraries that contain the source file
 # dependencies that need special handling because they are generated
 # or external code.
@@ -219,6 +227,9 @@ foreach(object_library ${libgromacs_object_library_dependencies})
     # Add the sources from the object libraries to the main library.
     target_sources(libgromacs PRIVATE $<TARGET_OBJECTS:${object_library}>)
 endforeach()
+gmx_target_compile_options(libgromacs)
+target_compile_definitions(libgromacs PRIVATE HAVE_CONFIG_H)
+target_include_directories(libgromacs SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
 
 if (GMX_USE_OPENCL)
     option(GMX_EXTERNAL_CLFFT "True if an external clFFT is required to be used" FALSE)
index 883722985f2e2b619c94772b4b403b211b218f84..033855d4d8505a746eea004720df3f248bd17b77 100644 (file)
@@ -431,7 +431,7 @@ class AnalysisDataPointSetRef
         //! Returns the number of columns included in this set.
         int columnCount() const
         {
-            return values().size();
+            return ssize(values());
         }
         //! Returns zero-based index of the last column included in this set (inclusive).
         int lastColumn() const
@@ -600,7 +600,7 @@ class AnalysisDataFrameRef
          */
         int pointSetCount() const
         {
-            return pointSets_.size();
+            return ssize(pointSets_);
         }
         /*! \brief
          * Returns point set reference for a given point set.
index b05843ae5b42a788230b2c81e40c222a8ab47698..e36f49cf45c1702b79533a009cdc5d1ce87f011a 100644 (file)
@@ -2460,8 +2460,7 @@ static void set_zones_size(gmx_domdec_t *dd,
                 corner[d] -= corner[ZZ]*box[ZZ][d]/box[ZZ][ZZ];
             }
             /* Apply the triclinic couplings */
-            assert(ddbox->npbcdim <= DIM);
-            for (i = YY; i < ddbox->npbcdim; i++)
+            for (i = YY; i < ddbox->npbcdim && i < DIM; i++)
             {
                 for (j = XX; j < i; j++)
                 {
index 88cbad784d890b2ad511376b98ffe13a1fb5140e..d21f4c6a240c28faa3ec8ab2dffddeb38eab0c39 100644 (file)
@@ -206,6 +206,13 @@ static void make_thread_local_ind(const PmeAtomComm *atc,
     spline->n = n;
 }
 
+// At run time, the values of order used and asserted upon mean that
+// indexing out of bounds does not occur. However compilers don't
+// always understand that, so we suppress this warning for this code
+// region.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+
 /* Macro to force loop unrolling by fixing order.
  * This gives a significant performance gain.
  */
@@ -286,6 +293,8 @@ static void make_bsplines(splinevec theta, splinevec dtheta, int order,
     }
 }
 
+#pragma GCC diagnostic pop
+
 /* This has to be a macro to enable full compiler optimization with xlC (and probably others too) */
 #define DO_BSPLINE(order)                            \
     for (ithx = 0; (ithx < (order)); ithx++)                    \
index 16830c4f6793fbdab5022dfd51f2a9edc7ca6a69..2b6194ca8e16c9fbc620ec79488b4c52a0ccf141 100644 (file)
 
 file(GLOB FILEIO_SOURCES *.cpp)
 
+target_sources(libgromacs PRIVATE ${FILEIO_SOURCES})
+
 if(GMX_USE_PLUGINS)
     add_library(vmddlopen OBJECT ${CMAKE_SOURCE_DIR}/src/external/vmd_molfile/vmddlopen.cpp)
+    gmx_target_compile_options(vmddlopen)
     if (WIN32)
         gmx_target_warning_suppression(vmddlopen /wd4996 HAS_NO_MSVC_UNSAFE_FUNCTION)
     endif()
@@ -43,8 +46,6 @@ if(GMX_USE_PLUGINS)
     set(libgromacs_object_library_dependencies ${libgromacs_object_library_dependencies} PARENT_SCOPE)
 endif()
 
-set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${FILEIO_SOURCES} PARENT_SCOPE)
-
 gmx_install_headers(
     confio.h
     enxio.h
index bf84cbcb08c738477a0d678a437b48fac49d564e..df00b8464d8e947462bf68c8625809ffab0b69e2 100644 (file)
@@ -46,6 +46,8 @@ set(LINEARALGEBRA_SOURCES
     ${LINEARALGEBRA_SOURCES} ${BLAS_SOURCES} ${LAPACK_SOURCES})
 
 add_library(linearalgebra OBJECT ${LINEARALGEBRA_SOURCES})
+gmx_target_compile_options(linearalgebra)
+target_compile_definitions(linearalgebra PRIVATE HAVE_CONFIG_H)
 # The linearalgebra code is all considered external, and we will
 # not keep it free of warnings. Any compiler suppressions required
 # should be added here.
index 460b055d9eeb04ab85e847e72bd949212d18a748..b3309e623625b0a54a17aee44ee282efd0acbb72 100644 (file)
@@ -100,7 +100,7 @@ void posres_dx(const rvec x, const rvec pos0A, const rvec pos0B,
                     posA *= pbc->box[m][m];
                     posB *= pbc->box[m][m];
                     assert(npbcdim <= DIM);
-                    for (d = m+1; d < npbcdim; d++)
+                    for (d = m+1; d < npbcdim && d < DIM; d++)
                     {
                         posA += pos0A[d]*pbc->box[d][m];
                         posB += pos0B[d]*pbc->box[d][m];
index ddb3f6541fac226baf636598b74c381cfaf24e0b..aa8d9fefb4c399caeb3ade89b714818be5e2b5ef 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -418,7 +418,7 @@ power12(T x)
 static inline real series_sinhx(real x)
 {
     real x2 = x*x;
-    return (1 + (x2/6.0)*(1 + (x2/20.0)*(1 + (x2/42.0)*(1 + (x2/72.0)*(1 + (x2/110.0))))));
+    return (1 + (x2/6.0_real)*(1 + (x2/20.0_real)*(1 + (x2/42.0_real)*(1 + (x2/72.0_real)*(1 + (x2/110.0_real))))));
 }
 
 /*! \brief Inverse error function, double precision.
index 8769c876be8860289966d170a6679e8073b4e006..b5f4a959fe78c1f7f29b6652dad4bb31daddd2b1 100644 (file)
@@ -216,9 +216,9 @@ static inline void copy_rvec_to_dvec(const rvec a, dvec b)
 
 static inline void copy_dvec_to_rvec(const dvec a, rvec b)
 {
-    b[XX] = a[XX];
-    b[YY] = a[YY];
-    b[ZZ] = a[ZZ];
+    b[XX] = static_cast<real>(a[XX]);
+    b[YY] = static_cast<real>(a[YY]);
+    b[ZZ] = static_cast<real>(a[ZZ]);
 }
 
 static inline void copy_rvecn(const rvec *a, rvec *b, int startn, int endn)
@@ -396,7 +396,7 @@ static inline real cos_angle(const rvec a, const rvec b)
     ipab = ipa*ipb;
     if (ipab > 0)
     {
-        cosval = ip*gmx::invsqrt(ipab);  /*  7 */
+        cosval = static_cast<real>(ip*gmx::invsqrt(ipab));  /*  7 */
     }
     else
     {
index 14d855d676cb6606594f108b8b9e0238a6cdb808..50a9dc2ce73d0d8b0e78168f78c3bce422b07c7f 100644 (file)
@@ -36,9 +36,11 @@ file(GLOB SELECTION_SOURCES *.cpp)
 file(GLOB SCANNER_SOURCES scanner.cpp parser.cpp)
 list(REMOVE_ITEM SELECTION_SOURCES ${SCANNER_SOURCES})
 # Add the non-generated sources to libgromacs, so that they have only the normal warning suppressions
-set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${SELECTION_SOURCES} PARENT_SCOPE)
+target_sources(libgromacs PRIVATE ${SELECTION_SOURCES})
 
 add_library(scanner OBJECT ${SCANNER_SOURCES})
+gmx_target_compile_options(scanner)
+target_compile_definitions(scanner PRIVATE HAVE_CONFIG_H)
 # Compilers give lots of warnings on these generated files.  These
 # are awkward to suppress inline, so we do it in the compilation
 # command (after testing that the compiler supports the
@@ -50,7 +52,7 @@ if (WIN32)
 else()
     gmx_target_warning_suppression(scanner -Wno-unused HAS_NO_UNUSED)
     gmx_target_warning_suppression(scanner -Wno-unused-parameter HAS_NO_UNUSED_PARAMETER)
-    gmx_target_warning_suppression(scanner -Wno-missing-declarartions HAS_NO_MISSING_DECLARATIONS)
+    gmx_target_warning_suppression(scanner -Wno-missing-declarations HAS_NO_MISSING_DECLARATIONS)
     gmx_target_warning_suppression(scanner -wd1419 HAS_DECL_IN_SOURCE)
 endif()
 list(APPEND libgromacs_object_library_dependencies scanner)
index 16fb23f4799fc4401c80d4c6a3f2ca40f68633b4..7280d206bb5b44e4707ca741df080e0d1ffc754a 100644 (file)
@@ -123,7 +123,7 @@ class AnalysisNeighborhoodPositions
          * Initializes positions from a vector of position vectors.
          */
         AnalysisNeighborhoodPositions(const std::vector<RVec> &x)
-            : count_(x.size()), index_(-1), x_(as_rvec_array(x.data())),
+            : count_(ssize(x)), index_(-1), x_(as_rvec_array(x.data())),
               exclusionIds_(nullptr), indices_(nullptr)
         {
         }
@@ -154,7 +154,7 @@ class AnalysisNeighborhoodPositions
         AnalysisNeighborhoodPositions &
         indexed(ArrayRef<const int> indices)
         {
-            count_   = indices.size();
+            count_   = ssize(indices);
             indices_ = indices.data();
             return *this;
         }
index 68a99a6b807ed36fc44f44795907d0e629046065..f047f6680946b765bd9a1f5b9b3e69e10fa53207 100644 (file)
@@ -117,7 +117,7 @@ class RangePartitioning
         /*! \brief Returns the number of blocks */
         int numBlocks() const
         {
-            return index_.size() - 1;
+            return static_cast<int>(index_.size() - 1);
         }
 
         /*! \brief Returns the size of the block with index \p blockIndex */
index 3f144d19f10d438d04b186b17a7c61d479d6dcf7..55792988fea8099203c465d4e3535d3244c33036 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -54,7 +54,7 @@ struct gmx_ffparams_t
     {
         GMX_ASSERT(iparams.size() == functype.size(), "Parameters and function types go together");
 
-        return functype.size();
+        return gmx::ssize(functype);
     }
 
     /* TODO: Consider merging functype and iparams, either by storing
index 901df4f5559353b9db0ce6139f70af78a19d674b..fa0a06ae048db491cc65a1253efb49f19628bd0d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -180,7 +180,7 @@ struct InteractionList
     /* Returns the total number of elements in iatoms */
     int size() const
     {
-        return iatoms.size();
+        return gmx::ssize(iatoms);
     }
 
     /* List of interactions, see explanation further down */
index e4159ed6ea17c05b8225bcd80eada97bd7722527..5ed1fc9a24a610d6d2dc78dfb35edb8b8162923c 100644 (file)
@@ -129,7 +129,7 @@ struct SimulationGroups
      *
      * \param[in] group Integer value for the group type.
      */
-    int numberOfGroupNumbers(SimulationAtomGroupType group) const { return groupNumbers[group].size(); }
+    int numberOfGroupNumbers(SimulationAtomGroupType group) const { return gmx::ssize(groupNumbers[group]); }
 };
 
 /*! \brief
index 906da1c66c9220f818a12629b15a6687f73cf0ac..ad6a3c5c2c9b09f60dbb8ef0c625d0db1df0e071 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -352,7 +352,7 @@ void gmx_sfree_aligned_impl(const char *name, const char *file, int line, T *ptr
  *
  * This factor leads to 4 realloc calls to double the array size.
  */
-constexpr float OVER_ALLOC_FAC = 1.19;
+constexpr float OVER_ALLOC_FAC = 1.19F;
 
 /*! \brief
  * Turns over allocation for variable size atoms/cg/top arrays on or off,
index 339c3d92063d0203874155977a9fb838f5e968b2..8d632261b91e9332033edabc8b7eca11c6fe095a 100644 (file)
@@ -35,6 +35,9 @@
 file(GLOB MDRUN_SOURCES mdrun/*.cpp)
 # make an "object library" that we can re-use for multiple targets
 add_library(mdrun_objlib OBJECT ${MDRUN_SOURCES})
+gmx_target_compile_options(mdrun_objlib)
+target_compile_definitions(mdrun_objlib PRIVATE HAVE_CONFIG_H)
+target_include_directories(mdrun_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
 
 if(GMX_FAHCORE)
     # The lack of a real source file here alongside the object library
@@ -44,6 +47,8 @@ if(GMX_FAHCORE)
     target_link_libraries(fahcore PRIVATE ${GMX_COMMON_LIBRARIES})
 elseif(GMX_BUILD_MDRUN_ONLY)
     add_executable(mdrun $<TARGET_OBJECTS:mdrun_objlib> mdrun_main.cpp)
+    gmx_target_compile_options(mdrun)
+    target_compile_definitions(mdrun PRIVATE HAVE_CONFIG_H)
     target_link_libraries(mdrun libgromacs
         ${GMX_COMMON_LIBRARIES}
         ${GMX_EXE_LINKER_FLAGS})
@@ -63,10 +68,14 @@ else()
         file(GLOB VIEW_SOURCES view/view.cpp)
     endif()
     add_library(view_objlib OBJECT ${VIEW_SOURCES})
+    gmx_target_compile_options(view_objlib)
+    target_compile_definitions(view_objlib PRIVATE HAVE_CONFIG_H)
     add_executable(gmx
         ${GMX_MAIN_SOURCES}
         $<TARGET_OBJECTS:mdrun_objlib>
         $<TARGET_OBJECTS:view_objlib>)
+    gmx_target_compile_options(gmx)
+    target_compile_definitions(gmx PRIVATE HAVE_CONFIG_H)
     target_link_libraries(gmx libgromacs
         ${GMX_COMMON_LIBRARIES}
         ${GMX_EXE_LINKER_FLAGS})
index 90846163afb2a2e5b43873028b16c289d4978112..7b716823205b76ace4aade4e9513a0188f0d3753 100644 (file)
@@ -42,6 +42,9 @@ add_library(mdrun_test_objlib OBJECT
     trajectorycomparison.cpp
     trajectoryreader.cpp
     )
+gmx_target_compile_options(mdrun_test_objlib)
+target_compile_definitions(mdrun_test_objlib PRIVATE HAVE_CONFIG_H)
+target_include_directories(mdrun_test_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
 
 set(testname "MdrunTests")
 set(exename "mdrun-test")
index 0747669960b52e325c4b98640e15b1a902e38029..5b461d48a74971d5384a68b09fe9b7011773ed19 100644 (file)
@@ -66,6 +66,9 @@ if(NOT HAVE_TINYXML2)
 endif()
 
 add_library(testutils STATIC ${UNITTEST_TARGET_OPTIONS} ${TESTUTILS_SOURCES})
+gmx_target_compile_options(testutils)
+target_compile_definitions(testutils PRIVATE HAVE_CONFIG_H)
+target_include_directories(testutils SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
 set(TESTUTILS_LIBS testutils)
 set_property(TARGET testutils APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
 set_property(TARGET testutils APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
index bf2f3518dfd49225f28b0e9d3e8fa016e9f873e9..0af9f820b1e35f2c3fb640c212f162767d371395 100644 (file)
@@ -36,10 +36,11 @@ include(CMakeParseArguments)
 
 function (gmx_add_unit_test_object_library NAME)
     if (GMX_BUILD_UNITTESTS AND BUILD_TESTING)
-        include_directories(BEFORE SYSTEM ${GMOCK_INCLUDE_DIRS})
         add_library(${NAME} OBJECT ${UNITTEST_TARGET_OPTIONS} ${ARGN})
-        set_property(TARGET ${NAME} APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
-        set_property(TARGET ${NAME} APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
+        gmx_target_compile_options(${NAME})
+        target_compile_options(${NAME} PRIVATE "${GMOCK_COMPILE_FLAGS}")
+        target_compile_definitions(${NAME} PRIVATE HAVE_CONFIG_H "${GMOCK_COMPILE_DEFINITIONS}")
+        target_include_directories(${NAME} SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include ${GMOCK_INCLUDE_DIRS})
     endif()
 endfunction ()
 
@@ -74,22 +75,20 @@ function (gmx_add_gtest_executable EXENAME)
         include_directories(BEFORE SYSTEM ${GMOCK_INCLUDE_DIRS})
         add_executable(${EXENAME} ${UNITTEST_TARGET_OPTIONS}
             ${_source_files} ${TESTUTILS_DIR}/unittest_main.cpp)
-        target_link_libraries(${EXENAME}
-            ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES}
-            ${GMX_COMMON_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
-        set_property(TARGET ${EXENAME}
-            APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
-        set_property(TARGET ${EXENAME}
-            APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
-        set_property(TARGET ${EXENAME}
-            APPEND PROPERTY COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS}")
-
+        gmx_target_compile_options(${EXENAME})
+        target_compile_options(${EXENAME} PRIVATE "${GMOCK_COMPILE_FLAGS}")
+        target_compile_definitions(${EXENAME} PRIVATE HAVE_CONFIG_H "${GMOCK_COMPILE_DEFINITIONS}" "${EXTRA_COMPILE_DEFINITIONS}")
+        target_include_directories(${EXENAME} SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
         # Permit GROMACS code to include externally developed headers,
         # such as the functionality from the nonstd project that we
         # use for gmx::compat::optional. These are included as system
         # headers so that no warnings are issued from them.
         target_include_directories(${EXENAME} SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
 
+        target_link_libraries(${EXENAME}
+            ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES}
+            ${GMX_COMMON_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
+
         if(GMX_CLANG_TIDY)
             set_target_properties(${EXENAME} PROPERTIES CXX_CLANG_TIDY
                 "${CLANG_TIDY_EXE};-warnings-as-errors=*;-header-filter=.*")