Compile fails with "The compiler for CXX can not consume flag(s) ... in combination with the CMAKE_CXX_FLAGS=."

I’m trying to compile the latest git version of LAMMPS (as of the time of writing, with latest commit hash fbd7c51e4b1c62b83b9d26b474e5a501a2560e33) on an HPC system with Kokkos, CUDA, MPI, and OpenMP.

(As to why I’m using the latest version rather than a stable release, I’m being tasked with making modifications that hopefully will be upstreamed.)

Here’s the CMake command line:

cmake -DCMAKE_CXX_STANDARD=17 \
      -DBUILD_SHARED_LIBS=ON -DLAMMPS_EXCEPTIONS=ON \
      -DBUILD_MPI=ON -DBUILD_OPENMP=ON \
      -DKokkos_ENABLE_CUDA=yes \
      -DKokkos_ARCH_AMPERE80=yes \
      -DKokkos_ENABLE_OPENMP=yes \
      -DCUFFT_LIBRARY="$CUDA_HOME/lib64/libcufft.so" \
      -DPKG_PYTHON=ON -DPKG_KSPACE=ON \
      -DPKG_DPD-BASIC=ON -DPKG_DPD-MESO=ONE -DPKG_DPD-REACT=ON -DPKG_DPD-SMOOTH=ON \
      -DPKG_EXTRA-COMPUTE=ON -DPKG_EXTRA-DUMP=ON -DPKG_EXTRA-FIX=ON \
      -DPKG_EXTRA-MOLECULE=ON -DPKG_EXTRA-PAIR=ON -DPKG_MEAM=ON -DPKG_FEP=ON \
      -DPKG_MANYBODY=ON -DPKG_MC=ON -DPKG_MISC=ON -DPKG_MOLECULE=ON \
      -DPKG_REAXFF=ON -DPKG_REPLICA=ON -DPKG_RIGID=ON -DPKG_KOKKOS=ON \
      -DCMAKE_INSTALL_PREFIX="$INST_DIR" "$CMAKE_DIR"

The compiler is AOCC 5.0.0, which is basically Clang 17.0.6 under the hood (and that’s how CMake itself detects it), and the CUDA library is at version 12.4.

(FWIW, the MPI implementation is OpenMPI 5.0.8.)

The error message that I get is as follows:

CMake Error at /p/home/jjramsey/lammps-dpd-react-stuff/lammps-src/lib/kokkos/cmake/kokkos_functions.cmake:992 (message):
The compiler for CXX can not consume flag(s) -x cuda --cuda-gpu-arch=sm_80
in combination with the CMAKE_CXX_FLAGS=. Please check the given
configuration.
Call Stack (most recent call first):
/p/home/jjramsey/lammps-dpd-react-stuff/lammps-src/lib/kokkos/cmake/kokkos_tribits.cmake:325 (kokkos_check_flags)
/p/home/jjramsey/lammps-dpd-react-stuff/lammps-src/lib/kokkos/cmake/kokkos_tribits.cmake:402 (kokkos_set_library_properties)
/p/home/jjramsey/lammps-dpd-react-stuff/lammps-src/lib/kokkos/core/src/CMakeLists.txt:134 (kokkos_add_library)

Not sure if this is relevant, but this error looks very similar to that from an old Kokkos bug report that had been closed: Configuration failure: The compiler for CXX can not consume flag(s) --relocatable-device-code=true... · Issue #7974 · kokkos/kokkos · GitHub

This is an error originating with the Kokkos library CMake scripts. You have to ask the Kokkos developers about this. We don’t manage this code, we just include a curated and validated copy for the convenience of the LAMMPS users.

You can confirm this, by disabling the KOKKOS package.

I would suggest to first try with a GCC compiler (11 or later) and also skip any package that you don’t need immediately.