Repository: lammps/lammps
Pull request #4536: Remove CMAKE_TUNE_FLAGS
Author: login: akohlmey
Labels: name: cmake
Created: 2025-04-06T22:43:17Z | Merged: 2025-04-17T15:02:04Z

**Summary**

This pull request removes the CMAKE_TUNE_FLAGS setting from LAMMPS' CMake configuration.
The setting was created for convenience, but has caused as much (or more?) problems than it has solved.
There are also several CMake best practices that its use violates.

**Related Issue(s)**

Fixes #4525 

**Author(s)**

Axel Kohlmeyer, Temple U

**Licensing**

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

**Backward Compatibility**

No. You have to set `CMAKE_<language>_FLAGS` or `CMAKE_<language>_FLAGS_<build type>` instead.

**Implementation Notes**

This implements similar functionality by appending the settings to the `CMAKE_<language>_FLAGS_<build type>` variables. Since `CMAKE_<language>_FLAGS` overrides the build type specific settings, it is not appended there unless the variable is set (and the build type specific flags correspondingly ignore).

**Post Submission Checklist**

- [x] The feature or features in this pull request is complete
- [x] Licensing information is complete
- [x] Corresponding author information is complete
- [x] The source code follows the LAMMPS formatting guidelines
- [x] Suitable new documentation files and/or updates to the existing docs are included
- [x] The added/updated documentation is integrated and tested with the documentation build system
- [ ] The feature has been verified to work with the CMake based build system


Linked issue #4525: [BUG] Setting CMake global compile flags can cause issues
**Summary**

`CMAKE_TUNE_DEFAULT` adds compiler flags globally. This can affect builds of utility libraries such as libyaml and google test. E.g. if NVCC specific flags are added, gcc and gfortran compilers in those utilities will error out.

They become dependent on the cmake execution order, which is why it may only show up after certain CMake runs.

Further motivation for #4233 and a target based approach. CMake generator expressions may need to guard these kind of flags.

It's also bad practice to prefix any variable with `CMAKE_`. LAMMPS should use its own `LAMMPS_` prefix for such variables.

**LAMMPS Version and Platform**

`develop`

**Expected Behavior**

No errors.

**Actual Behavior**

Errors due to unknown flags `-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128` for both gcc and gfortran.

**Steps to Reproduce**

<!--Describe the steps required to (quickly) reproduce the issue. You can attach (small) files to the section below or add URLs where to download an archive with all necessary files. Please try to create an input set that is as minimal and small as possible and reproduces the bug as quickly as possible. **NOTE:** the less effort and time it takes to reproduce your reported bug, the more likely it becomes, that somebody will look into it and fix the problem.-->

**Further Information, Files, and Links**

<!--Put any additional information here, attach relevant text or image files and URLs to external sites, e.g. relevant publications-->

Linked issue comments: user: login: akohlmey
created_at: 2025-04-06T01:17:05Z
body: `CMAKE_TUNE_DEFAULT` was started a bit of a crutch to have a simple mechanism to set some compiler specific flags. Mostly for the INTEL package. Later also to silence some (spammy) warnings due to the crazy way how nvcc compiles everything twice.

It is a mixed blessing, though, and creating problems in some cases rather than solving them.

After having gained some more experience in CMake scripting, I believe it should be removed altogether and its functionality delegated to preset files or similar. Also with requiring newer CMake versions, it may be time to check again, if we can have some CMake scripting that will remove incompatible flags from the settings.

> Errors due to unknown flags -Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128 for both gcc and gfortran.

Shouldn't those be avoided when using nvcc_wrapper and that be forwarded to the ancillary tools?


author_association: MEMBER

Diff:
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index f22fa401a26..61ad2299233 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -105,46 +105,33 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict")
     endif()
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "/QxCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QxCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "/QxHost")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QxHost")
     endif()
   else()
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
     endif()
   endif()
 endif()
 
 # silence excessive warnings for new Intel Compilers
 if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
-  set(CMAKE_TUNE_DEFAULT "-fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
 endif()
 
 # silence excessive warnings for PGI/NVHPC compilers
 if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI"))
-  set(CMAKE_TUNE_DEFAULT "-Minform=severe")
-endif()
-
-# this hack is required to compile fmt lib with CrayClang version 15.0.2
-# CrayClang is only directly recognized by version 3.28 and later
-if(CMAKE_VERSION VERSION_LESS 3.28)
-  get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
-  if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
-    set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
-  endif()
-else()
-  if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
-    set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
-  endif()
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Minform=severe")
 endif()
 
 # silence nvcc warnings
 if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA) AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
-  set(CMAKE_TUNE_DEFAULT "${CMAKE_TUNE_DEFAULT}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
 endif()
 
 # we *require* C++11 without extensions but prefer C++17.
@@ -450,6 +437,19 @@ if(NOT ${LAMMPS_MEMALIGN} STREQUAL "0")
   target_compile_definitions(lammps PRIVATE -DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN})
 endif()
 
+# this hack is required to compile fmt lib with CrayClang version 15.0.2
+# CrayClang is only directly recognized by CMake version 3.28 and later
+if(CMAKE_VERSION VERSION_LESS 3.28)
+  get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
+  if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
+    target_compile_definitions(lammps PRIVATE -DFMT_STATIC_THOUSANDS_SEPARATOR)
+  endif()
+else()
+  if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
+    target_compile_definitions(lammps PRIVATE -DFMT_STATIC_THOUSANDS_SEPARATOR)
+  endif()
+endif()
+
 # "hard" dependencies between packages resulting
 # in an error instead of skipping over files
 pkg_depends(ML-IAP ML-SNAP)
@@ -507,13 +507,13 @@ if(BUILD_OMP)
   if(CMAKE_VERSION VERSION_LESS 3.28)
     get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
     if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
-      set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp")
-      set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp")
+      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
+      set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fopenmp")
     endif()
   else()
     if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
-      set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp")
-      set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp")
+      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
+      set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fopenmp")
     endif()
   endif()
 endif()
@@ -628,10 +628,6 @@ if(WITH_SWIG)
   add_subdirectory(${LAMMPS_SWIG_DIR} swig)
 endif()
 
-set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine specific optimization flags (compilation only)")
-separate_arguments(CMAKE_TUNE_FLAGS)
-target_compile_options(lammps PRIVATE ${CMAKE_TUNE_FLAGS})
-target_compile_options(lmp PRIVATE ${CMAKE_TUNE_FLAGS})
 ########################################################################
 # Basic system tests (standard libraries, headers, functions, types)   #
 ########################################################################
diff --git a/cmake/Modules/Packages/COLVARS.cmake b/cmake/Modules/Packages/COLVARS.cmake
index b943a0345eb..8fa0d84f01e 100644
--- a/cmake/Modules/Packages/COLVARS.cmake
+++ b/cmake/Modules/Packages/COLVARS.cmake
@@ -14,10 +14,6 @@ endif()
 
 add_library(colvars STATIC ${COLVARS_SOURCES})
 target_compile_definitions(colvars PRIVATE -DCOLVARS_LAMMPS)
-separate_arguments(CMAKE_TUNE_FLAGS)
-foreach(_FLAG ${CMAKE_TUNE_FLAGS})
-  target_compile_options(colvars PRIVATE ${_FLAG})
-endforeach()
 set_target_properties(colvars PROPERTIES OUTPUT_NAME lammps_colvars${LAMMPS_MACHINE})
 target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars)
 # The line below is needed to locate math_eigen_impl.h
diff --git a/cmake/presets/kokkos-hip.cmake b/cmake/presets/kokkos-hip.cmake
index 38bf27092f9..c1968c0ffae 100644
--- a/cmake/presets/kokkos-hip.cmake
+++ b/cmake/presets/kokkos-hip.cmake
@@ -9,8 +9,7 @@ set(Kokkos_ARCH_VEGA90A on CACHE BOOL "" FORCE)
 set(Kokkos_ENABLE_HIP_MULTIPLE_KERNEL_INSTANTIATIONS ON CACHE BOOL "" FORCE)
 set(BUILD_OMP ON CACHE BOOL "" FORCE)
 
-set(CMAKE_CXX_COMPILER hipcc CACHE STRING "" FORCE)
-set(CMAKE_TUNE_FLAGS "-munsafe-fp-atomics" CACHE STRING "" FORCE)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -munsafe-fp-atomics" CACHE STRING "" FORCE)
 
 # If KSPACE is also enabled, use CUFFT for FFTs
 set(FFT_KOKKOS "HIPFFT" CACHE STRING "" FORCE)
diff --git a/cmake/presets/kokkos-sycl-intel.cmake b/cmake/presets/kokkos-sycl-intel.cmake
index eba386564d1..fe5999dae68 100644
--- a/cmake/presets/kokkos-sycl-intel.cmake
+++ b/cmake/presets/kokkos-sycl-intel.cmake
@@ -21,9 +21,10 @@ set(CMAKE_C_COMPILER icx CACHE STRING "" FORCE)
 set(CMAKE_Fortran_COMPILER "" CACHE STRING "" FORCE)
 set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
 set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE)
-# Silence everything
-set(CMAKE_CXX_FLAGS "-w" CACHE STRING "" FORCE)
+
+# set(_intel_sycl_flags " -w -fsycl -flink-huge-device-code -fsycl-targets=spir64_gen "
+set(_intel_sycl_flags " -w -fsycl -fsycl-device-code-split=per_kernel -fsycl-targets=spir64_gen "
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_intel_sycl_flags}" CACHE STRING "" FORCE)
+
 #set(CMAKE_EXE_LINKER_FLAGS "-fsycl -flink-huge-device-code -fsycl-targets=spir64_gen " CACHE STRING "" FORCE)
-#set(CMAKE_TUNE_FLAGS "-O3 -fsycl -fsycl-device-code-split=per_kernel -fsycl-targets=spir64_gen" CACHE STRING "" FORCE)
-set(CMAKE_EXE_LINKER_FLAGS "-fsycl -flink-huge-device-code " CACHE STRING "" FORCE)
-set(CMAKE_TUNE_FLAGS "-O3 -fsycl -fsycl-device-code-split=per_kernel " CACHE STRING "" FORCE)
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsycl -flink-huge-device-code " CACHE STRING "" FORCE)
diff --git a/cmake/presets/kokkos-sycl-nvidia.cmake b/cmake/presets/kokkos-sycl-nvidia.cmake
index c706aca7d86..bf4dfba2252 100644
--- a/cmake/presets/kokkos-sycl-nvidia.cmake
+++ b/cmake/presets/kokkos-sycl-nvidia.cmake
@@ -14,5 +14,7 @@ set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE)
 set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE)
 set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
 set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE)
-set(CMAKE_SHARED_LINKER_FLAGS "-Xsycl-target-frontend -O3" CACHE STRING "" FORCE)
-set(CMAKE_TUNE_FLAGS "-fgpu-inline-threshold=100000 -Xsycl-target-frontend -O3  -Xsycl-target-frontend -ffp-contract=on -Wno-unknown-cuda-version" CACHE STRING "" FORCE)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xsycl-target-frontend -O3 " CACHE STRING "" FORCE)
+
+set(_intel_sycl_flags "-fgpu-inline-threshold=100000 -Xsycl-target-frontend -O3  -Xsycl-target-frontend -ffp-contract=on -Wno-unknown-cuda-version")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_intel_sycl_flags}" CACHE STRING "" FORCE)
diff --git a/cmake/presets/mingw-cross.cmake b/cmake/presets/mingw-cross.cmake
index 413744b078f..b5c5adb1f6d 100644
--- a/cmake/presets/mingw-cross.cmake
+++ b/cmake/presets/mingw-cross.cmake
@@ -91,7 +91,7 @@ endif()
 set(DOWNLOAD_VORO ON CACHE BOOL "" FORCE)
 set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE)
 set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE)
-set(CMAKE_TUNE_FLAGS "-Wno-missing-include-dirs" CACHE STRING "" FORCE)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-include-dirs" CACHE STRING "" FORCE)
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
 set(BUILD_TOOLS ON CACHE BOOL "" FORCE)
diff --git a/cmake/presets/windows-intel-llvm.cmake b/cmake/presets/windows-intel-llvm.cmake
index e9d88d22fe0..ead4fbcfb58 100644
--- a/cmake/presets/windows-intel-llvm.cmake
+++ b/cmake/presets/windows-intel-llvm.cmake
@@ -5,4 +5,4 @@ set(CMAKE_C_COMPILER "icx" CACHE STRING "" FORCE)
 set(CMAKE_Fortran_COMPILER "ifx" CACHE STRING "" FORCE)
 set(INTEL_LRT_MODE "C++11" CACHE STRING "" FORCE)
 unset(HAVE_OMP_H_INCLUDE CACHE)
-set(CMAKE_TUNE_FLAGS -Wno-unused-command-line-argument)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst
index be4b3125788..f9cf2516880 100644
--- a/doc/src/Build_basics.rst
+++ b/doc/src/Build_basics.rst
@@ -212,11 +212,7 @@ LAMMPS.
       You can tell CMake to look for a specific compiler with setting
       CMake variables (listed below) during configuration.  For a few
       common choices, there are also presets in the ``cmake/presets``
-      folder.  For convenience, there is a ``CMAKE_TUNE_FLAGS`` variable
-      that can be set to apply global compiler options (applied to
-      compilation only), to be used for adding compiler or host specific
-      optimization flags in addition to the "flags" variables listed
-      below. You may also specify the corresponding ``CMAKE_*_FLAGS``
+      folder.  You may also specify the corresponding ``CMAKE_*_FLAGS``
       variables individually, if you want to experiment with alternate
       optimization flags.  You should specify all 3 compilers, so that
       the (few) LAMMPS source files written in C or Fortran are built
@@ -266,10 +262,6 @@ LAMMPS.
       ``-C ../cmake/presets/pgi.cmake`` will switch the compiler to the PGI compilers,
       and ``-C ../cmake/presets/nvhpc.cmake`` will switch to the NVHPC compilers.
 
-      Furthermore, you can set ``CMAKE_TUNE_FLAGS`` to specifically add
-      compiler flags to tune for optimal performance on given hosts.
-      This variable is empty by default.
-
       .. note::
 
          When the cmake command completes, it prints a summary to the
diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst
index 226e19bfc35..7c164099952 100644
--- a/doc/src/Build_settings.rst
+++ b/doc/src/Build_settings.rst
@@ -18,7 +18,6 @@ explains how to do this for building both with CMake and make.
 * `Memory allocation alignment`_
 * `Workaround for long long integers`_
 * `Exception handling when using LAMMPS as a library`_ to capture errors
-* `Trigger selected floating-point exceptions`_
 
 ----------
 
@@ -659,40 +658,3 @@ code has to be set up to *catch* exceptions thrown from within LAMMPS.
    throw an exception and thus other MPI ranks may get stuck waiting for
    messages from the ones with errors.
 
-----------
-
-.. _trap_fpe:
-
-Trigger selected floating-point exceptions
-------------------------------------------
-
-Many kinds of CPUs have the capability to detect when a calculation
-results in an invalid math operation, like a division by zero or calling
-the square root with a negative argument.  The default behavior on
-most operating systems is to continue and have values for ``NaN`` (= not
-a number) or ``Inf`` (= infinity).  This allows software to detect and
-recover from such conditions.  This behavior can be changed, however,
-often through use of compiler flags.  On Linux systems (or more general
-on systems using the GNU C library), these so-called floating-point traps
-can also be selectively enabled through library calls.  LAMMPS supports
-that by setting the ``-DLAMMPS_TRAP_FPE`` pre-processor define.  As it is
-done in the ``main()`` function, this applies only to the standalone
-executable, not the library.
-
-.. tabs::
-
-   .. tab:: CMake build
-
-      .. code-block:: bash
-
-         -D CMAKE_TUNE_FLAGS=-DLAMMPS_TRAP_FPE
-
-   .. tab:: Traditional make
-
-      .. code-block:: make
-
-         LMP_INC = -DLAMMPS_TRAP_FPE  <other LMP_INC settings>
-
-After compilation with this flag set, the LAMMPS executable will stop
-and produce a core dump when a division by zero, overflow, illegal math
-function argument or other invalid floating point operation is encountered.
diff --git a/doc/src/Howto_cmake.rst b/doc/src/Howto_cmake.rst
index 6b8fc82bad1..64acee47dd9 100644
--- a/doc/src/Howto_cmake.rst
+++ b/doc/src/Howto_cmake.rst
@@ -285,7 +285,7 @@ when used before the CMake directory, there may be a space between the
 can have boolean values (on/off, yes/no, or 1/0 are all valid) or are
 strings representing a choice, or a path, or are free format. If the
 string would contain whitespace, it must be put in quotes, for example
-``-D CMAKE_TUNE_FLAGS="-ftree-vectorize -ffast-math"``.
+``-D CMAKE_CXX_FLAGS="-O3 -Wall -ftree-vectorize -ffast-math"``.
 
 CMake variables fall into two categories: 1) common CMake variables that
 are used by default for any CMake configuration setup and 2) project
@@ -341,8 +341,6 @@ Some common LAMMPS specific variables
      - compile some additional executables from the ``tools`` folder (default: ``off``)
    * - ``BUILD_DOC``
      - include building the HTML format documentation for packaging/installing (default: ``off``)
-   * - ``CMAKE_TUNE_FLAGS``
-     - common compiler flags, for optimization or instrumentation (default:)
    * - ``LAMMPS_MACHINE``
      - when set to ``name`` the LAMMPS executable and library will be called ``lmp_name`` and ``liblammps_name.a``
    * - ``FFT``
diff --git a/src/main.cpp b/src/main.cpp
index a1f9772455f..649550735c4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,10 +21,6 @@
 #include <mpi.h>
 #include <new>
 
-#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
-#include <fenv.h>
-#endif
-
 // import MolSSI Driver Interface library
 #if defined(LMP_MDI)
 #include <mdi.h>
@@ -62,17 +58,6 @@ int main(int argc, char **argv)
     if (MDI_MPI_get_world_comm(&lammps_comm)) MPI_Abort(MPI_COMM_WORLD, 1);
 #endif
 
-#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
-  // enable trapping selected floating point exceptions.
-  // this uses GNU extensions and is only tested on Linux
-  // therefore we make it depend on -D_GNU_SOURCE, too.
-  fesetenv(FE_NOMASK_ENV);
-  fedisableexcept(FE_ALL_EXCEPT);
-  feenableexcept(FE_DIVBYZERO);
-  feenableexcept(FE_INVALID);
-  feenableexcept(FE_OVERFLOW);
-#endif
-
   try {
     auto lammps = new LAMMPS(argc, argv, lammps_comm);
     lammps->input->file();
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
index 7c94cad4e3b..dcb44ffbe7b 100644
--- a/unittest/CMakeLists.txt
+++ b/unittest/CMakeLists.txt
@@ -33,10 +33,6 @@ mark_as_advanced(SKIP_DEATH_TESTS)
 if(SKIP_DEATH_TESTS)
   add_compile_definitions(LAMMPS_SKIP_DEATH_TESTS)
 endif()
-# import
-foreach(_FLAG ${CMAKE_TUNE_FLAGS})
-  add_compile_options(${_FLAG})
-endforeach()
 
 # must repeat handling coverage for older CMake
 if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND ENABLE_COVERAGE)


Reviews:
user: login: rbberger
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T02:06:38Z
user: login: akohlmey
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-08T02:15:38Z
user: login: akohlmey
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-08T02:19:45Z
user: login: giacomofiorin
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-08T15:50:58Z

Review comments:
diff_hunk: @@ -102,49 +102,49 @@ include(CheckIncludeFileCXX)
 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
   if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
     if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
-      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /Qrestrict")
     endif()
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "/QxCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /QxCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "/QxHost")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /QxHost")
     endif()
   else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
+    set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -restrict")
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -xCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
     endif()
   endif()
 endif()
 
 # silence excessive warnings for new Intel Compilers
 if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
-  set(CMAKE_TUNE_DEFAULT "-fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
+  set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
 endif()
 
 # silence excessive warnings for PGI/NVHPC compilers
 if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI"))
-  set(CMAKE_TUNE_DEFAULT "-Minform=severe")
+  set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -Minform=severe")
 endif()
 
 # this hack is required to compile fmt lib with CrayClang version 15.0.2
 # CrayClang is only directly recognized by version 3.28 and later
 if(CMAKE_VERSION VERSION_LESS 3.28)
   get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
   if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
-    set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
+    set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -DFMT_STATIC_THOUSANDS_SEPARATOR")
path: cmake/CMakeLists.txt
user: login: rbberger
body: This is FMT specific and should be a `target_compile_definition` on the library target.
created_at: 2025-04-07T01:52:59Z
author_association: MEMBER
diff_hunk: @@ -102,49 +102,49 @@ include(CheckIncludeFileCXX)
 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
   if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
     if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
-      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /Qrestrict")
path: cmake/CMakeLists.txt
user: login: rbberger
body: What is the rationale to set the Config flags instead of just `CMAKE_CXX_FLAGS`? Both `CMAKE_CXX_FLAGS` and `CMAKE_CXX_FLAGS_<Config>` are passed, in that order, to the compiler.
created_at: 2025-04-07T01:55:42Z
author_association: MEMBER
diff_hunk: @@ -659,40 +658,3 @@ code has to be set up to *catch* exceptions thrown from within LAMMPS.
    throw an exception and thus other MPI ranks may get stuck waiting for
    messages from the ones with errors.
 
-----------
-
-.. _trap_fpe:
-
-Trigger selected floating-point exceptions
-------------------------------------------
-
-Many kinds of CPUs have the capability to detect when a calculation
-results in an invalid math operation, like a division by zero or calling
-the square root with a negative argument.  The default behavior on
-most operating systems is to continue and have values for ``NaN`` (= not
-a number) or ``Inf`` (= infinity).  This allows software to detect and
-recover from such conditions.  This behavior can be changed, however,
-often through use of compiler flags.  On Linux systems (or more general
-on systems using the GNU C library), these so-called floating-point traps
-can also be selectively enabled through library calls.  LAMMPS supports
-that by setting the ``-DLAMMPS_TRAP_FPE`` pre-processor define.  As it is
-done in the ``main()`` function, this applies only to the standalone
-executable, not the library.
-
-.. tabs::
-
-   .. tab:: CMake build
-
-      .. code-block:: bash
-
-         -D CMAKE_TUNE_FLAGS=-DLAMMPS_TRAP_FPE
path: doc/src/Build_settings.rst
user: login: rbberger
body: This should be it's own CMake option and enable the `LAMMPS_TRAP_FPE` define if set.
created_at: 2025-04-07T02:06:33Z
author_association: MEMBER
diff_hunk: @@ -102,49 +102,49 @@ include(CheckIncludeFileCXX)
 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
   if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
     if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
-      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /Qrestrict")
     endif()
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "/QxCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /QxCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "/QxHost")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} /QxHost")
     endif()
   else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
+    set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -restrict")
     if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
-      set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -xCOMMON-AVX512")
     else()
-      set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
+      set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
     endif()
   endif()
 endif()
 
 # silence excessive warnings for new Intel Compilers
 if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
-  set(CMAKE_TUNE_DEFAULT "-fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
+  set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
 endif()
 
 # silence excessive warnings for PGI/NVHPC compilers
 if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI"))
-  set(CMAKE_TUNE_DEFAULT "-Minform=severe")
+  set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -Minform=severe")
 endif()
 
 # this hack is required to compile fmt lib with CrayClang version 15.0.2
 # CrayClang is only directly recognized by version 3.28 and later
 if(CMAKE_VERSION VERSION_LESS 3.28)
   get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
   if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
-    set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
+    set(CMAKE_CXX_FLAGS_${BTYPE} "${CMAKE_CXX_FLAGS_${BTYPE}} -DFMT_STATIC_THOUSANDS_SEPARATOR")
path: cmake/CMakeLists.txt
user: login: akohlmey
body: done
created_at: 2025-04-08T02:15:37Z
author_association: MEMBER
diff_hunk: @@ -659,40 +658,3 @@ code has to be set up to *catch* exceptions thrown from within LAMMPS.
    throw an exception and thus other MPI ranks may get stuck waiting for
    messages from the ones with errors.
 
-----------
-
-.. _trap_fpe:
-
-Trigger selected floating-point exceptions
-------------------------------------------
-
-Many kinds of CPUs have the capability to detect when a calculation
-results in an invalid math operation, like a division by zero or calling
-the square root with a negative argument.  The default behavior on
-most operating systems is to continue and have values for ``NaN`` (= not
-a number) or ``Inf`` (= infinity).  This allows software to detect and
-recover from such conditions.  This behavior can be changed, however,
-often through use of compiler flags.  On Linux systems (or more general
-on systems using the GNU C library), these so-called floating-point traps
-can also be selectively enabled through library calls.  LAMMPS supports
-that by setting the ``-DLAMMPS_TRAP_FPE`` pre-processor define.  As it is
-done in the ``main()`` function, this applies only to the standalone
-executable, not the library.
-
-.. tabs::
-
-   .. tab:: CMake build
-
-      .. code-block:: bash
-
-         -D CMAKE_TUNE_FLAGS=-DLAMMPS_TRAP_FPE
path: doc/src/Build_settings.rst
user: login: akohlmey
body: I am removing this setting. It doesn't work as expected most of the time and I don't know of anyone outside of me that has ever used it.
created_at: 2025-04-08T02:19:45Z
author_association: MEMBER

PR comments:
user: login: akohlmey
created_at: 2025-04-06T22:46:56Z
body: @stanmoore1 @rbberger @giacomofiorin This will require extensive testing for the various use cases where `CMAKE_TUNE_FLAGS` was previously applied. I'm submitting this in its unfinished and untested stage to get feedback on the overall concept.
author_association: MEMBER
user: login: giacomofiorin
created_at: 2025-04-08T16:05:44Z
body: > @stanmoore1 @rbberger @giacomofiorin This will require extensive testing for the various use cases where `CMAKE_TUNE_FLAGS` was previously applied. I'm submitting this in its unfinished and untested stage to get feedback on the overall concept.

Hi @akohlmey! As far as I am concerned this looks great to me. I have never used `CMAKE_TUNE_FLAGS`. Flags shared by Colvars and LAMMPS are communicated using `target_compile_definitions()` or `target_compile_options()`. If there is something else I can look into please let me know?
author_association: COLLABORATOR
user: login: akohlmey
created_at: 2025-04-08T20:07:17Z
body: > If there is something else I can look into please let me know?

No, I am mostly waiting on @stanmoore1 and @rbberger to let me know if this PR is not creating unexpected problems, specifically with KOKKOS and external ML packages.
author_association: MEMBER