#!-------------------------------------------------------------------------------------------------! #! CP2K: A general program to perform molecular dynamics simulations ! #! Copyright 2000-2025 CP2K developers group ! #! ! #! SPDX-License-Identifier: GPL-2.0-or-later ! #!-------------------------------------------------------------------------------------------------! set(CP2K_C_COMPILER_LIST "GNU;Intel;IntelLLVM;NAG;Cray;PGI;Clang;AppleClang") set(CP2K_Fortran_COMPILER_LIST "GNU;Intel;IntelLLVM;NAG;Cray;PGI") if(NOT CMAKE_C_COMPILER_ID IN_LIST CP2K_C_COMPILER_LIST) message( WARNING "Unknown C compiler, trying without any additional (optimization) flags.\n" "You may have to specify flags for C11 support manually.\n Please open an\n" "issue at https://github.com/cp2k/cp2k/issues with the reported compiler \n" "name and the required flags.") message("-- CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}\n" "-- CMAKE_C_COMPILER full path: ${CMAKE_C_COMPILER}\n") endif() if(NOT CMAKE_Fortran_COMPILER_ID IN_LIST CP2K_Fortran_COMPILER_LIST) message( WARNING "Unknown Fortran compiler, trying without any additional (optimization) flags.\n" "You will most likely have to specify extra options for free-form Fortran 2008\n" "for your compiler! Please open an issue at https://github.com/cp2k/cp2k/issues\n" "with the reported compiler name and the required flags.") message("-- CMAKE_Fortran_COMPILER_ID: ${CMAKE_Fortran_COMPILER_ID}\n" "-- CMAKE_Fortran_COMPILER full path: ${CMAKE_Fortran_COMPILER}\n") endif() # ================================ GNU Compilers =============================== # Baseline add_compile_options( "$<$:-std=f2008;-ffree-form;-ffree-line-length-none;-fimplicit-none>" "$<$:-g;-fno-omit-frame-pointer;-fbacktrace>" "$<$:$<$:-fallow-argument-mismatch>>" "$<$:-Wno-deprecated-declarations;-Wno-maybe-uninitialized;-Wuninitialized;-Wuse-without-only>" ) add_compile_options( "$<$:--std=c++17>" "$<$:-g;-fno-omit-frame-pointer>" "$<$:-Wno-deprecated-declarations;-Wno-vla-parameter>" ) add_compile_options( "$<$:-std=c11>" "$<$:-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;-mtune=generic;-funroll-loops>" "$<$,$>:-O3;-mtune=generic;-funroll-loops>" "$<$,$>:-O3;-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>" "$<$,$>:-fcheck=all,no-array-temps;-finline-matmul-limit=0>" "$<$,$>:-ffpe-trap=invalid,zero,overflow>" "$<$,$>:-finit-derived;-finit-real=snan;-finit-integer=-42>" "$<$,$>:-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_definitions("$<$:__HAS_IEEE_EXCEPTIONS;__CHECK_DIAG>") add_link_options( "$<$,$>:-fsanitize=leak>" "$<$,$>:-fsanitize=leak>" "$<$,$>:-fsanitize=leak>") # 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>") # Address Sanitizer add_compile_options( "$<$:-fsanitize=address;-no-pie;-O3;-march=native;-mtune=native;-funroll-loops>" ) add_link_options("$<$:-fsanitize=address>") # =============================== Other Compilers ============================== # Baseline add_compile_options( "$<$:-free;-stand f18;-fpp;-qopenmp;-heap-arrays;-D__MAX_CONTR=4>" "$<$:-free;-fpp;-qopenmp;-D__MAX_CONTR=4>" "$<$:-Mfreeform;-Mextend;-Mallocatable=03>" "$<$:-f2008;-free;-Warn=reallocation;-Warn=subnormal>" "$<$:-f;free;-M3105;-ME7212;-hnoacc;-M1234>" ) add_compile_options( "$<$:-hnoacc;-h;nomessage=1234>") # Release add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O3;-g;-D__HAS_IEEE_EXCEPTIONS>" "$<$,$>:-O3;-g;-D__HAS_IEEE_EXCEPTIONS>" "$<$,$>:-O2;-G2>" "$<$,$>:-gline>") add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O3;-g>" "$<$,$>:-O3;-g>" "$<$,$>:-O3>" "$<$,$>:-gline>" "$<$,$>:-O3;-funroll-loops>" "$<$,$>:-O3;-funroll-loops>" "$<$>:$<$,$>:-gline>>" ) # Debug add_compile_options( "$<$,$>:-g>" "$<$,$>:-O2;-debug>" "$<$,$>:-O2;-debug>" "$<$,$>:-G2>") add_compile_options( "$<$,$>:-fast>" "$<$,$>:-O2;-g>" "$<$,$>:-O2;-g>" "$<$,$>:-G2>" "$<$,$>:-g;-C>" "$<$,$>:-O1;-g;-fno-omit-frame-pointer>" "$<$,$>:-O0;-g>" "$<$,$>:-C=all>") # Tweaks if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang") set(CMAKE_Fortran_MODOUT_FLAG "-ef") # override to get lower-case module file # names set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-lgcov") # Apple's Clang needs an extra endif() if(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray") set(CMAKE_Fortran_MODOUT_FLAG "-ef") # override to get lower-case module file # names endif() if(CMAKE_C_COMPILER_ID STREQUAL "Cray" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9) # prevent deallocation failures due to tcmalloc's free with glibc's # aligned_alloc, see https://bugzilla.redhat.com/show_bug.cgi?id=1569391 add_compile_options("$<$:-h;system_alloc>" "$<$:-h;system_alloc>") # since the detection of the implicitly linked libraries occurs before we can # intervene, filter them out again list(FILTER CMAKE_C_IMPLICIT_LINK_LIBRARIES EXCLUDE REGEX "tcmalloc") list(FILTER CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES EXCLUDE REGEX "tcmalloc") endif()