Skip to content

Commit 89ce3d0

Browse files
authored
Merge pull request #265 from billsacks/gfortran10_default
Use gfortran v10+ behavior for undefined CMAKE_Fortran_COMPILER_VERSION The typical CESM unit test CMake-based builds include CIME_initial_setup.cmake before the `project` line (as is recommended in comments in CIME_initial_setup.cmake). This pulls in the Macros at that point. However, CMAKE_Fortran_COMPILER_VERSION is not defined until after the `project` line. This causes problems on machines that need this logic for gfortran 10+. I have worked around it before by defining FFLAGS unconditionally in the machine-specific cmake file (e.g., gnu_green.cmake), but now that most machines are using gfortran 10+, it seems like the cleaner fix is to use the gfortran 10+ behavior as the default if CMAKE_Fortran_COMPILER_VERSION is not yet defined. This is needed for the GitHub Actions to pass in ESCOMP/CESM_share#71
2 parents 6c22a0f + ee4e437 commit 89ce3d0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

machines/cmake_macros/gnu.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ set(SUPPORTS_CXX "TRUE")
2929

3030
message("C compiler version is ${CMAKE_C_COMPILER_VERSION}")
3131
message("Fortran compiler version is ${CMAKE_Fortran_COMPILER_VERSION}")
32-
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
32+
# Note that we use the gfortran 10+ behavior if CMAKE_Fortran_COMPILER_VERSION is
33+
# undefined. This is needed for the unit test build, where the Macros file is often
34+
# included before the "project" line (which is the point at which
35+
# CMAKE_Fortran_COMPILER_VERSION becomes defined).
36+
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10 OR NOT DEFINED CMAKE_Fortran_COMPILER_VERSION)
3337
string(APPEND FFLAGS " -fallow-argument-mismatch -fallow-invalid-boz ")
3438
if (DEBUG)
3539
string(APPEND CFLAGS " -g -Wall -O0 -g -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds")
@@ -47,4 +51,4 @@ if (NOT DEBUG)
4751
string(APPEND CFLAGS " -O2 -ffp-contract=off")
4852
string(APPEND CXXFLAGS " -O2 -ffp-contract=off")
4953
string(APPEND FFLAGS " -O2 -ffp-contract=off")
50-
endif()
54+
endif()

0 commit comments

Comments
 (0)