From d73369d34cdac446d27ce6388117e78cfaefb0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Fri, 18 Jul 2025 13:25:25 +0200 Subject: [PATCH] CMake: Re-structure compiler configs --- cmake/CompilerConfiguration.cmake | 102 ++++++++++++++++++++++-------- src/CMakeLists.txt | 3 - 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/cmake/CompilerConfiguration.cmake b/cmake/CompilerConfiguration.cmake index 21480fc158..d115c5e2a9 100644 --- a/cmake/CompilerConfiguration.cmake +++ b/cmake/CompilerConfiguration.cmake @@ -31,29 +31,89 @@ if(NOT CMAKE_Fortran_COMPILER_ID IN_LIST CP2K_Fortran_COMPILER_LIST) "-- CMAKE_Fortran_COMPILER full path: ${CMAKE_Fortran_COMPILER}\n") endif() -# OpenACC support with CCE is EOL: causes -# https://github.com/cp2k/dbcsr/issues/261 eventually check compiler version -# (similar to -h system_alloc) +# ================================ GNU Compilers =============================== + +# Baseline +add_compile_options( + "$<$:-std=f2008;-fopenmp;-ffree-form;-fimplicit-none>" + "$<$:-g;-fno-omit-frame-pointer;-fbacktrace>" + "$<$:$<$:-fallow-argument-mismatch>>" + "$<$:-Wno-deprecated-declarations;-Wno-maybe-uninitialized;-Wuninitialized;-Wuse-without-only>" + "$<$:-Werror=aliasing;-Werror=ampersand;-Werror=c-binding-type;-Werror=intrinsic-shadow>" + "$<$:-Werror=intrinsics-std;-Werror=line-truncation;-Werror=tabs;-Werror=target-lifetime>" + "$<$:-Werror=underflow;-Werror=unused-but-set-variable;-Werror=unused-variable>" + "$<$:-Werror=unused-dummy-argument;-Werror=unused-parameter>" + "$<$:-Werror=unused-label;-Werror=conversion;-Werror=zerotrip>" +) +add_compile_options( + "$<$:--std=c++17;-fopenmp>" + "$<$:-g;-fno-omit-frame-pointer>" + "$<$:-Wno-deprecated-declarations;-Wno-vla-parameter>" +) +add_compile_options( + "$<$:-std=c11;-fopenmp>" + "$<$:-g;-fno-omit-frame-pointer>" + "$<$:-Wno-deprecated-declarations;-Wno-vla-parameter>" +) + +# Release +add_compile_options( + "$<$,$>:-O3;-march=native;-mtune=native;-funroll-loops>" + "$<$,$>:-O3;-march=native;-mtune=native;-funroll-loops>" + "$<$,$>:-O3;-march=native;-mtune=native;-funroll-loops>" +) + +# Generic +add_compile_options( + "$<$,$>:-O3;-march=generic;-mtune=generic;-funroll-loops>" + "$<$,$>:-O3;-march=generic;-mtune=generic;-funroll-loops>" + "$<$,$>:-O3;-march=generic;-mtune=generic;-funroll-loops>" +) + +# Debug +add_compile_options( + "$<$,$>:-O1;-march=native;-mtune=native>" + "$<$,$>:-O1;-march=native;-mtune=native>" + "$<$,$>:-O1;-march=native;-mtune=native>" +) +add_compile_options( + "$<$,$>:-fsanitize=leak;-Werror=realloc-lhs;-D__CHECK_DIAG>" + "$<$,$>:-fcheck=all,no-array-temps;-finline-matmul-limit=0>" + "$<$,$>:-D__HAS_IEEE_EXCEPTIONS;-ffpe-trap=invalid,zero,overflow>" + "$<$,$>:-finit-derived;-finit-real=snan;-finit-integer=-42>" +) + +# TODO Prevent CMake from wrongly adding -fbacktrace and +# -fallow-argument-mismatch to CFLAGS. add_compile_options( +# "$<$,$>:-Wall;-Wextra;-Werror>" +# "$<$,$>:-Wall;-Wextra;-Werror>" +# ) + +# Coverage +add_compile_options( + "$<$:-coverage;-fkeep-static-functions;-D__NO_ABORT>") + +# =============================== Other Compilers ============================== + +# Baseline add_compile_options( - "$<$:-march=native;-mtune=native>" - "$<$:-march=native;-mtune=native;-fbacktrace;-ffree-line-length-none;-ffree-form;-std=f2008;-fimplicit-none;-Werror=aliasing;-Werror=ampersand;-Werror=c-binding-type;-Werror=conversion;-Werror=intrinsic-shadow;-Werror=intrinsics-std;-Werror=line-truncation;-Werror=tabs;-Werror=target-lifetime;-Werror=underflow;-Werror=unused-but-set-variable;-Werror=unused-variable;-D__MAX_CONTR=4>" - "$<$,$>:-fallow-argument-mismatch>" "$<$:-free;-stand f18;-fpp;-heap-arrays;-D__MAX_CONTR=4>" "$<$:-free;-fpp;-D__MAX_CONTR=4>" "$<$:-Mfreeform;-Mextend;-Mallocatable=03>" "$<$:-f2008;-free;-Warn=reallocation;-Warn=subnormal>" - "$<$:-hnoacc;-h;nomessage=1234>" "$<$:-f;free;-M3105;-ME7212;-hnoacc;-M1234>" ) - add_compile_options( - "$<$,$>:-g;-funroll-loops;-D__HAS_IEEE_EXCEPTIONS>" + "$<$:-hnoacc;-h;nomessage=1234>") + +# Release +add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O3;-g;-D__HAS_IEEE_EXCEPTIONS>" "$<$,$>:-O3;-g;-D__HAS_IEEE_EXCEPTIONS>" "$<$,$>:-O2;-G2>" - "$<$,$>:-gline>" - "$<$,$>:-g;-funroll-loops;-Wall>" + "$<$,$>:-gline>") +add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O3;-g>" "$<$,$>:-O3;-g>" @@ -64,13 +124,13 @@ add_compile_options( "$<$>:$<$,$>:-gline>>" ) +# Debug add_compile_options( - "$<$,$>:-fbacktrace;-ffree-form;-fimplicit-none;-std=f2008;-fsanitize=leak;-fcheck=all,no-array-temps;-ffpe-trap=invalid,zero,overflow;-finit-derived;-finit-real=snan;-finit-integer=-42;-Werror=realloc-lhs;-finline-matmul-limit=0>" "$<$,$>:-g>" "$<$,$>:-O2;-debug>" "$<$,$>:-O2;-debug>" - "$<$,$>:-G2>" - "$<$,$>:-O2;-ggdb;-Wall;-fsanitize=undefined;-fsanitize=address;-fsanitize-recover=all;-Wall;-Wextra;-Werror;-Wno-vla-parameter;-Wno-deprecated-declarations>" + "$<$,$>:-G2>") +add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O3;-g>" "$<$,$>:-O3;-g>" @@ -80,19 +140,7 @@ add_compile_options( "$<$,$>:-O0;-g>" "$<$,$>:-C=all>") -add_compile_options( - "$<$,$>:-O0;-g;--coverage;-fno-omit-frame-pointer;-fcheck=all;-ffpe-trap=invalid,zero,overflow;-fbacktrace;-finit-real=snan;-finit-integer=-42;-finit-derived;-Werror=realloc-lhs;-finline-matmul-limit=0>" - "$<$,$>:-O0;-g;--coverage;-Wall>" -) - -if(NOT CP2K_USE_MPI OR NOT "${MPI_Fortran_LIBRARY_VERSION_STRING}" MATCHES - "Open MPI") - add_compile_options( - "$<$,$>:-fsanitize=leak>" - "$<$,$>:-O0;-g;--coverage;-Wall>" - ) -endif() - +# Tweaks if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang") set(CMAKE_Fortran_MODOUT_FLAG "-ef") # override to get lower-case module file # names diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46bec2e369..8c70072093 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1747,9 +1747,6 @@ target_compile_definitions( __COMPILE_REVISION=\"${CP2K_GIT_HASH}\" __DATA_DIR=\"${CP2K_DATA_DIR}\" __COMPILE_ARCH=\"${CMAKE_SYSTEM_PROCESSOR}\" - $<$:__NO_ABORT> - $<$:__HAS_IEEE_EXCEPTIONS> - $<$:__CHECK_DIAG> $<$:__PLUMED2> $<$:__LIBMAXWELL> $<$:__LIBVORI>