[build] How to avoid de-duplication option base the cmake configure

hi,
I tried to add some options for llvm to get better performance base the lammps. When I add -mllvm -neon-nonconst-stride-overhead=5 -mllvm -slp-threshold=100 in the cmake/CMakeLists.txt.

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_TUNE_DEFAULT "SHELL:-march=armv8-a+simd -O3 -ffast-math -mllvm -neon-nonconst-stride-overhead=5 -mllvm -slp-threshold=100")
endif()

Then, I use the following command to generate the Makefile, and found the 2nd -mllvm is missing.
If fact, I already add the Prefix SHELL: according target_compile_options — CMake 3.27.0-rc2 Documentation showed as above cmake/CMakeLists.txt, but it still failed.
So need any extra attention for the lammps project ?

cmake -C ../cmake/presets/arm_clang.cmake -D BUILD_OMP=no -D INTEL_ARCH=cpu -D INTEL_LRT_MODE=threads -D FFT=KISS -D FFT_SINGLE=yes ../cmake

A brief search on the Internet gives this: c++ - Pass compound compiler options using cmake - Stack Overflow
so it seems that one need to use multiple SHELL commands like "SHELL:-mllvm -neon-nonconst-stride-overhead=5" "SHELL:-mllvm -slp-threshold=100".

I have no personal experience on this issue.

Edit: after some experiments I think the point above is not the real problem. The real point is that it only works for parameters added by add_compile_options(), while setting CMAKE_TUNE_DEFAULT does not work. I don’t know why.

1 Like

Thank you for your analysis.
According to your idea, the problem will be solved when I replace it with CMAKE_CXX_FLAGS.

set(CMAKE_CXX_FLAGS "-march=armv8-a+simd -O3 -ffast-math -mllvm -neon-nonconst-stride-overhead=5 -mllvm -slp-threshold=100")

The other one solution is comment the separate_arguments in cmake/CMakeLists.txt

@@ -521,7 +524,7 @@ if(WITH_SWIG)
 endif()
 
 set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine specific optimization flags (compilation only)")
-separate_arguments(CMAKE_TUNE_FLAGS)
+# separate_arguments(CMAKE_TUNE_FLAGS)
 foreach(_FLAG ${CMAKE_TUNE_FLAGS})
1 Like