Could NOT find ClangFormat:

Hi,
LAMMPS version: (23 Jun 2022 - Update 2)
OS: Ubuntu 22.04.1 LTS
I run the following CMake

“~/lammps/lammps/build$ cmake -C …/cmake/presets/minimal.cmake -D PKG_GPU=on -D GPU_API=cuda -D GPU_PREC=double -D OCL_TUNE=generic -D GPU_ARCH=sm_51 -D CUDPP_OPT=no -D CUDA_MPS_SUPPORT=yes -D PKG_USER-OMP=on …/cmake
loading initial cache file …/cmake/presets/minimal.cmake”

The output was

  • “CMake Error: Error processing file: /home/…/lammps/lammps/cmake/presets/minimal.cmake”
    i.e.
  • Could NOT find ClangFormat: Found unsuitable version “0.0”, but required is at least “8.0” (found /usr/bin/clang-format)

However in terminal

  • :/usr/bin$ clang-format-
    clang-format-13 clang-format-diff-13

Therefore I made few changes in the FindClangFormat.cmake file as follows,

  • find_program(ClangFormat_EXECUTABLE NAMES clang-format
    clang-format-15.0
    clang-format-14.0
    clang-format-13.0
    clang-format-12.0
    clang-format-11.0

  • if(ClangFormat_EXECUTABLE)

    execute_process(COMMAND ${ClangFormat_EXECUTABLE} --version
    OUTPUT_VARIABLE clang_format_version
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

    if(clang_format_version MATCHES “^(Ubuntu |)clang-format version.*”)

    string(REGEX REPLACE “^(Ubuntu |)clang-format version ([0-9.]+).*”
    “\2”

but the configuration process provides still the same error.

Thank you for your assistance
Wenu

Your problem has nothing to do with clang-format and does not need any changes to the CMake files. With your LAMMPS version there is no “minimal” preset file. That is why the configuration fails. This is a very nice demonstration of the principle that one first must completely understand an error before you can attempt to “fix” it.

If you check with the documentation and look in the corresponding folder you will see that the preset file you want to load is called “basic.cmake”. Which is the second important lesson here: always double check the documentation and look very carefully at the error messages and where they happen.

P.S.: the clang-format executable detection has been updated for Ubuntu 20 and later in LAMMPS version 3 November 2022. If you want to correct that, you can just copy the corresponding file from the new version to your version. It won’t make a difference for compilation, though. The only difference it makes is that there is an additional compilation target called “format-src” in case a compatible version of clang-format is detected.

1 Like

Thank you for the quick response and valuable advice.
Work done!