From 8ff984a32037947c7224cb46e72627d32ba5d81e Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Fri, 20 Sep 2019 18:55:32 +0200 Subject: [PATCH] Fix log file flag output Fixes #3099 Change-Id: I5049e8807b87c83959a0a2a5b3439b904d5edc8b --- cmake/gmxManageGPU.cmake | 15 ++++--- docs/doxygen/check-source.py | 13 ++++++ src/CMakeLists.txt | 15 +++++-- src/GetCompilerInfo.cmake | 7 +-- src/buildinfo.h.cmakein | 14 +++--- ...ldinfo.h.cmakein => compilerflaginfo.h.cmakein} | 52 +++------------------- 6 files changed, 48 insertions(+), 68 deletions(-) copy src/{buildinfo.h.cmakein => compilerflaginfo.h.cmakein} (51%) diff --git a/cmake/gmxManageGPU.cmake b/cmake/gmxManageGPU.cmake index 8ff10db160..aeaa9993cd 100644 --- a/cmake/gmxManageGPU.cmake +++ b/cmake/gmxManageGPU.cmake @@ -148,11 +148,12 @@ endif() # Note that semicolon is used as separator for nvcc. # # Parameters: -# COMPILER_INFO - [output variable] string with compiler path, ID and -# some compiler-provided information -# COMPILER_FLAGS - [output variable] flags for the compiler +# COMPILER_INFO - [output variable] string with compiler path, ID and +# some compiler-provided information +# DEVICE_COMPILER_FLAGS - [output variable] device flags for the compiler +# HOST_COMPILER_FLAGS - [output variable] host flags for the compiler, if propagated # -macro(get_cuda_compiler_info COMPILER_INFO COMPILER_FLAGS) +macro(get_cuda_compiler_info COMPILER_INFO DEVICE_COMPILER_FLAGS HOST_COMPILER_FLAGS) if(NOT GMX_CLANG_CUDA) if(CUDA_NVCC_EXECUTABLE) @@ -171,9 +172,11 @@ macro(get_cuda_compiler_info COMPILER_INFO COMPILER_FLAGS) string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type) SET(_compiler_flags "${CUDA_NVCC_FLAGS_${_build_type}}") if(CUDA_PROPAGATE_HOST_FLAGS) - string(REGEX REPLACE "[ ]+" ";" _cxx_flags_nospace "${BUILD_CXXFLAGS}") + set(${HOST_COMPILER_FLAGS} BUILD_CXXFLAGS) + else() + set(${HOST_COMPILER_FLAGS} "") endif() - SET(${COMPILER_FLAGS} "${CUDA_NVCC_FLAGS}${CUDA_NVCC_FLAGS_${_build_type}}; ${_cxx_flags_nospace}") + SET(${DEVICE_COMPILER_FLAGS} "${CUDA_NVCC_FLAGS}${CUDA_NVCC_FLAGS_${_build_type}}") else() SET(${COMPILER_INFO} "N/A") SET(${COMPILER_FLAGS} "N/A") diff --git a/docs/doxygen/check-source.py b/docs/doxygen/check-source.py index 5a582c5a87..8790eb6a17 100755 --- a/docs/doxygen/check-source.py +++ b/docs/doxygen/check-source.py @@ -136,6 +136,19 @@ def check_include(fileobj, includedfile, reporter): return reporter.code_issue(includedfile, "includes local file as {0}".format(includedfile)) + # To report compiler flags in the log file, include files must be + # generated by CMake, with a name that is only known at generation + # time (not even configuration time). This looks like the + # inclusion of a non-local file to the source checker. We usually + # suppress issues with generated files using file-name matching, + # but this is not suitable in this case because it is hard to map + # the repository file named src/compilerflaginfo.h.cmakein to two + # generated header files + # $builddir/src/compilerflaginfo-$buildtype-CXX.h and + # $builddir/src/compilerflaginfo-$buildtype-C.h. So we use a hack + # to just avoid the warning for this special source file. + if "compilerflaginfo" in str(includedfile): + return if not otherfile: reporter.code_issue(includedfile, "includes non-local file as {0}".format(includedfile)) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c7a63bf7d..427fce5f08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,20 +36,29 @@ # Output compiler and CFLAGS used ###################################### include(GetCompilerInfo.cmake) -get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS) -get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS) +get_compiler_info(C BUILD_C_COMPILER) +get_compiler_info(CXX BUILD_CXX_COMPILER) if(GMX_USE_CUDA) if(NOT GMX_CLANG_CUDA) GMX_SET_CUDA_NVCC_FLAGS() endif() - get_cuda_compiler_info(CUDA_COMPILER_INFO CUDA_COMPILER_FLAGS) + get_cuda_compiler_info(CUDA_COMPILER_INFO CUDA_DEVICE_COMPILER_FLAGS CUDA_HOST_COMPILER_FLAGS) endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) configure_file(config.h.cmakein config.h) configure_file(gmxpre-config.h.cmakein gmxpre-config.h) configure_file(buildinfo.h.cmakein buildinfo.h ESCAPE_QUOTES) +# Make a file with compiler flags used for libgromacs for each +# langauge and build configuration. The one that corresponds to +# CMAKE_BUILD_TYPE is #included into buildinfo.h and populates the +# fields e.g. printed to the log file. +file(GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/compilerflaginfo-$-$.h + INPUT ${CMAKE_CURRENT_SOURCE_DIR}/compilerflaginfo.h.cmakein + CONDITION $ + ) #### set(IGNORED_CLANG_ALL_WARNINGS diff --git a/src/GetCompilerInfo.cmake b/src/GetCompilerInfo.cmake index a827daebed..4720f492d6 100644 --- a/src/GetCompilerInfo.cmake +++ b/src/GetCompilerInfo.cmake @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2012,2013,2014, by the GROMACS development team, led by +# Copyright (c) 2012,2013,2014,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. @@ -39,10 +39,7 @@ # LANGUAGE - C or CXX, the compiler to check for # BUILD_COMPILER - [output variable] string with compiler path, ID and # some compiler-provided information -# BUILD_FLAGS - [output variable] flags for the compiler # -macro(get_compiler_info LANGUAGE BUILD_COMPILER BUILD_FLAGS) +macro(get_compiler_info LANGUAGE BUILD_COMPILER) set(${BUILD_COMPILER} "${CMAKE_${LANGUAGE}_COMPILER} ${CMAKE_${LANGUAGE}_COMPILER_ID} ${CMAKE_${LANGUAGE}_COMPILER_VERSION}") - string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) - set(${BUILD_FLAGS} "${CMAKE_${LANGUAGE}_FLAGS} ${CMAKE_${LANGUAGE}_FLAGS_${_build_type}}") endmacro() diff --git a/src/buildinfo.h.cmakein b/src/buildinfo.h.cmakein index a6f63b07a1..0a8f07aca6 100644 --- a/src/buildinfo.h.cmakein +++ b/src/buildinfo.h.cmakein @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015,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. @@ -42,14 +42,12 @@ /** C compiler used to build */ #define BUILD_C_COMPILER "@BUILD_C_COMPILER@" -/** C compiler flags used to build */ -#define BUILD_CFLAGS "@BUILD_CFLAGS@" +#include "compilerflaginfo-@CMAKE_BUILD_TYPE@-C.h" /** C++ compiler flags used to build, or empty string if no C++ */ #define BUILD_CXX_COMPILER "@BUILD_CXX_COMPILER@" -/** C++ compiler flags used to build */ -#define BUILD_CXXFLAGS "@BUILD_CXXFLAGS@" +#include "compilerflaginfo-@CMAKE_BUILD_TYPE@-CXX.h" /** Installation prefix (default location of data files) */ #define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" @@ -72,8 +70,10 @@ /** CUDA compiler version information */ #define CUDA_COMPILER_INFO "@CUDA_COMPILER_INFO@" -/** CUDA compiler flags */ -#define CUDA_COMPILER_FLAGS "@CUDA_COMPILER_FLAGS@" +/** CUDA compiler flags (device flags, plus host flags if propagated)*/ +#define CUDA_DEVICE_COMPILER_FLAGS "@CUDA_DEVICE_COMPILER_FLAGS@" +#define CUDA_HOST_COMPILER_FLAGS @CUDA_HOST_COMPILER_FLAGS@ +#define CUDA_COMPILER_FLAGS CUDA_DEVICE_COMPILER_FLAGS CUDA_HOST_COMPILER_FLAGS /** OpenCL include dir */ #define OPENCL_INCLUDE_DIR "@OpenCL_INCLUDE_DIR@" diff --git a/src/buildinfo.h.cmakein b/src/compilerflaginfo.h.cmakein similarity index 51% copy from src/buildinfo.h.cmakein copy to src/compilerflaginfo.h.cmakein index a6f63b07a1..5a87c6cf34 100644 --- a/src/buildinfo.h.cmakein +++ b/src/compilerflaginfo.h.cmakein @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by + * Copyright (c) 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. @@ -34,52 +34,10 @@ */ /*! \internal \file * \brief - * Build information from the build system. + * Compiler flag information from the build system. * - * Used for log and version output. + * Used for log output. */ -/** C compiler used to build */ -#define BUILD_C_COMPILER "@BUILD_C_COMPILER@" - -/** C compiler flags used to build */ -#define BUILD_CFLAGS "@BUILD_CFLAGS@" - -/** C++ compiler flags used to build, or empty string if no C++ */ -#define BUILD_CXX_COMPILER "@BUILD_CXX_COMPILER@" - -/** C++ compiler flags used to build */ -#define BUILD_CXXFLAGS "@BUILD_CXXFLAGS@" - -/** Installation prefix (default location of data files) */ -#define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" - -/** Source directory for the build */ -#define CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@" - -/** Directory for test input files */ -#define GMX_TESTSIMULATIONDATABASE_DIR "@CMAKE_SOURCE_DIR@/src/testutils/simulationdatabase" - -/** Binary directory for the build */ -#define CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" - -/** Location of GROMACS-specific data files */ -#define GMX_INSTALL_GMXDATADIR "@GMX_INSTALL_GMXDATADIR@" - -/** HWLOC version information */ -#define HWLOC_VERSION "@HWLOC_VERSION@" - -/** CUDA compiler version information */ -#define CUDA_COMPILER_INFO "@CUDA_COMPILER_INFO@" - -/** CUDA compiler flags */ -#define CUDA_COMPILER_FLAGS "@CUDA_COMPILER_FLAGS@" - -/** OpenCL include dir */ -#define OPENCL_INCLUDE_DIR "@OpenCL_INCLUDE_DIR@" - -/** OpenCL library */ -#define OPENCL_LIBRARY "@OpenCL_LIBRARY@" - -/** OpenCL version */ -#define OPENCL_VERSION_STRING "@OpenCL_VERSION_STRING@" +/** $ compiler flags used to build */ +#define BUILD_$FLAGS "$, >" -- 2.11.4.GIT