From 2ea11b3195ece92f1ca1f4cea395cd90c31e5e87 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Sep 2019 15:50:26 -0400 Subject: [PATCH 1/2] implement test for C++11 and document it --- cmake/CMakeLists.txt | 9 ++++++++- doc/src/Build_settings.txt | 23 +++++++++++++++++++++++ src/MAKE/Makefile.mpi | 6 +++--- src/MAKE/Makefile.serial | 6 +++--- src/lmptype.h | 7 +++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 91fb930be2..ed9825a830 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -52,10 +52,17 @@ check_for_autogen_files(${LAMMPS_SOURCE_DIR}) include(CheckCCompilerFlag) include(CheckIncludeFileCXX) -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict") endif() +option(DISABLE_CXX11_REQUIREMENT "Disable check that requires C++11 for compiling LAMMPS" OFF) +if(DISABLE_CXX11_REQUIREMENT) + add_definitions(-DLAMMPS_CXX98) +else() + set(CMAKE_CXX_STANDARD 11) +endif() + # GNU compiler features if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") option(ENABLE_COVERAGE "Enable code coverage" OFF) diff --git a/doc/src/Build_settings.txt b/doc/src/Build_settings.txt index 287cd39ff6..baff537e3b 100644 --- a/doc/src/Build_settings.txt +++ b/doc/src/Build_settings.txt @@ -12,6 +12,7 @@ Optional build settings :h3 LAMMPS can be built with several optional settings. Each sub-section explain how to do this for building both with CMake and make. +"C++11 standard compliance test"_#cxx11 when building all of LAMMPS "FFT library"_#fft for use with the "kspace_style pppm"_kspace_style.html command "Size of LAMMPS data types"_#size "Read or write compressed files"_#gzip @@ -23,6 +24,28 @@ explain how to do this for building both with CMake and make. :line +C++11 standard compliance test :h4(cxx11) + +The LAMMPS developers plan to transition to make the C++11 standard the +minimum requirement for compiling LAMMPS. Currently this only applies to +some packages like KOKKOS while the rest aims to be compatible with the C++98 +standard. Most currently used compilers are compatible with C++11; some need +to set extra flags to switch. To determine the impact of requiring C++11, +we have added a simple compliance test to the source code, that will cause +the compilation to abort, if C++11 compliance is not available or enabled. +To bypass this check, you need to change a setting in the makefile or +when calling CMake. + +[CMake variable]: + +-D DISABLE_CXX11_REQUIREMENT=yes + +[Makefile.machine setting]: + +LMP_INC = -DLAMMPS_CXX98 + +:line + FFT library :h4,link(fft) When the KSPACE package is included in a LAMMPS build, the diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index f30220da3d..3be2e20f95 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -26,12 +26,12 @@ SHLIBFLAGS = -shared # if you change any -D setting, do full re-compile after "make clean" # LAMMPS ifdef settings -# see possible settings in Section 2.2 (step 4) of manual +# see possible settings in Section 3.5 of the manual -LMP_INC = -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 +LMP_INC = -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 # -DLAMMPS_CXX98 # MPI library -# see discussion in Section 2.2 (step 5) of manual +# see discussion in Section 3.4 of the manual # MPI wrapper compiler/linker can provide this info # can point to dummy MPI library in src/STUBS as in Makefile.serial # use -D MPICH and OMPI settings in INC to avoid C++ lib conflicts diff --git a/src/MAKE/Makefile.serial b/src/MAKE/Makefile.serial index 5954d97761..86ddd05053 100644 --- a/src/MAKE/Makefile.serial +++ b/src/MAKE/Makefile.serial @@ -26,12 +26,12 @@ SHLIBFLAGS = -shared # if you change any -D setting, do full re-compile after "make clean" # LAMMPS ifdef settings -# see possible settings in Section 2.2 (step 4) of manual +# see possible settings in Section 3.5 of the manual -LMP_INC = -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 +LMP_INC = -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 # -DLAMMPS_CXX98 # MPI library -# see discussion in Section 2.2 (step 5) of manual +# see discussion in Section 3.4 of the manual # MPI wrapper compiler/linker can provide this info # can point to dummy MPI library in src/STUBS as in Makefile.serial # use -D MPICH and OMPI settings in INC to avoid C++ lib conflicts diff --git a/src/lmptype.h b/src/lmptype.h index 65e46535fc..b220538190 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -28,6 +28,13 @@ #ifndef LMP_LMPTYPE_H #define LMP_LMPTYPE_H +// C++11 check +#ifndef LAMMPS_CXX98 +#if __cplusplus <= 199711L + #error LAMMPS is planning to transition to C++11. Do disable this error please use a C++11 compliant compiler, enable C++11 (or later) compliance, or define LAMMPS_CXX98 in your makefile +#endif +#endif + #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS #endif From 5dba4b66c8964a362d7944e461eda820743ba605 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Sep 2019 16:49:48 -0400 Subject: [PATCH 2/2] add warning banner to the LAMMPS output and refer to the C++11 issue on github --- doc/src/Build_settings.txt | 2 +- src/lammps.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/src/Build_settings.txt b/doc/src/Build_settings.txt index baff537e3b..c40a91d781 100644 --- a/doc/src/Build_settings.txt +++ b/doc/src/Build_settings.txt @@ -24,7 +24,7 @@ explain how to do this for building both with CMake and make. :line -C++11 standard compliance test :h4(cxx11) +C++11 standard compliance test :h4,link(cxx11) The LAMMPS developers plan to transition to make the C++11 standard the minimum requirement for compiling LAMMPS. Currently this only applies to diff --git a/src/lammps.cpp b/src/lammps.cpp index 5ddc1600a4..d58c04e998 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -444,6 +444,19 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : if ((universe->me == 0) && !helpflag) { if (screen) fprintf(screen,"LAMMPS (%s)\n",universe->version); if (logfile) fprintf(logfile,"LAMMPS (%s)\n",universe->version); +#if defined(LAMMPS_CXX98) + const char warning[] = "\nWARNING-WARNING-WARNING-WARNING-WARNING\n" + "This LAMMPS executable was compiled using C++98 compatibility.\n" + "Please report the compiler info below at https://github.com/lammps/lammps/issues/1659\n"; + const char *infobuf = Info::get_compiler_info(); + if (screen) + fprintf(screen,"%s%s\nWARNING-WARNING-WARNING-WARNING-WARNING\n\n", + warning,infobuf); + if (logfile) + fprintf(logfile,"%s%s\nWARNING-WARNING-WARNING-WARNING-WARNING\n\n", + warning,infobuf); + delete[] infobuf; +#endif } // universe is one or more worlds, as setup by partition switch