From 4597fee41f08afe3489761f8b2f08b8ca0243408 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Nov 2023 08:12:41 -0500 Subject: GNU: Remove duplicate and unnecessary optimization flags for gfortran Since commit a66004bee0 (Honor CMAKE__FLAGS[_]_INIT set in toolchain files, 2016-07-05, v3.7.0-rc1~392^2) we've accidentally been adding extra optimization flags instead of replacing unwanted flags. Fixes: #25434 --- Modules/Compiler/GNU-Fortran.cmake | 4 ---- Modules/Compiler/GNU.cmake | 11 ++++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake index 5dfb03e..452598b 100644 --- a/Modules/Compiler/GNU-Fortran.cmake +++ b/Modules/Compiler/GNU-Fortran.cmake @@ -17,10 +17,6 @@ endif() set(CMAKE_Fortran_POSTPROCESS_FLAG "-fpreprocessed") -# No -DNDEBUG for Fortran. -string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") -string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") - # No -isystem for Fortran because it will not find .mod files. unset(CMAKE_INCLUDE_SYSTEM_FLAG_Fortran) diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index bb367ea..88c8997 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -109,9 +109,14 @@ macro(__compiler_gnu lang) # Initial configuration flags. string(APPEND CMAKE_${lang}_FLAGS_INIT " ") string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") - string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG") - string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") - string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") + if(NOT "x${lang}" STREQUAL "xFortran") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -DNDEBUG") + endif() set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE " -E > ") set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE " -S -o ") if(NOT APPLE OR NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4) # work around #4462 -- cgit v0.12