Skip to content
Draft
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ include(GNUInstallDirs)
include(CheckFortranCompilerFlag)

if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
message(STATUS "Setting build type to 'Release' as none was specified.")
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE
"Release"
"RelWithDebInfo"
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
Expand Down Expand Up @@ -63,37 +63,37 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(r8_flags "-fdefault-real-8 -fdefault-double-8") # Fortran flags for 64BIT precision

# Copied from MOM5/bin/mkmf.template.nci.gfortran
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer -fdefault-real-8 -ffree-line-length-none -fno-range-check -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation -Wconversion -Wline-truncation -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsic-shadow -Wno-align-commons")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer -ffree-line-length-none -fno-range-check -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation -Wconversion -Wline-truncation -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsic-shadow -Wno-align-commons")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Intel/IntelLLVM branches have an -i4 embedded into the "always-on" flags but GNU does not - is that intentional?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need a big-endian-conversion flag?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Intel/IntelLLVM branches have an -i4 embedded into the "always-on" flags but GNU does not - is that intentional?

Yeah, as far as I know, there is no equivalent flag. 4-byte integers are gfortran's default. One can set -fdefault-integer-8, but there's no equivalent flag to "unset" it back to the default like there is for ifx/ifort.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need a big-endian-conversion flag?

Yeah, probably a good idea. Added in 4a8501b

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - totally forgot to update here. I trawled through the gfortran docs and yes, there is no equivalent compiler flag for -i4

# Note, -fallow-argument-mismatch is handled further down
check_fortran_compiler_flag("-fallow-invalid-boz" _boz_flag)
if(_boz_flag)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-invalid-boz" )
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O2")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g -frecord-gcc-switches -fbacktrace")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -W -fbounds-check")

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")

# Precision-based Fortran compiler flags
set(r4_flags "-real-size 32") # Fortran flags for 32BIT precision
set(r8_flags "-real-size 64") # Fortran flags for 64BIT precision
set(r8_flags "${r8_flags} -no-prec-div -no-prec-sqrt")
set(r8_flags "-real-size 64 -no-prec-div -no-prec-sqrt") # Fortran flags for 64BIT precision

# Copied from MOM5/bin/mkmf.template.nci
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -i4 -r8 -traceback -nowarn -check noarg_temp_created -assume nobuffered_io -convert big_endian -grecord-gcc-switches -fp-model precise -fp-model source -align all")
set(CMAKE_Fortran_FLAGS_RELEASE "-g3 -O2 -xCORE-AVX2 -debug all -check none")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -integer-size 32 -nowarn -assume nobuffered_io -convert big_endian -fp-model precise -fp-model source -align all")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xCORE-AVX2 -debug all -check none")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g3 -grecord-gcc-switches -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv -traceback")

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")

# Precision-based Fortran compiler flags
set(r4_flags "-real-size 32") # Fortran flags for 32BIT precision
set(r8_flags "-real-size 64") # Fortran flags for 64BIT precision

# Copied from MOM5/bin/mkmf.template.nci
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -i4 -r8 -traceback -nowarn -check noarg_temp_created -assume nobuffered_io -convert big_endian -grecord-gcc-switches -fp-model precise -fp-model source -align all")
set(CMAKE_Fortran_FLAGS_RELEASE "-g3 -O2 -xCORE-AVX2 -debug all -check none")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -integer-size 32 -nowarn -assume nobuffered_io -convert big_endian -fp-model precise -fp-model source -align all")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xCORE-AVX2 -debug all -check none")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g3 -grecord-gcc-switches -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv -traceback")

else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
Expand All @@ -106,30 +106,34 @@ endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")

# Copied from MOM5/bin/mkmf.template.nci.gfortran
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any difference between these two changed lines? Are these whitespace-only changes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I added CMAKE_C_FLAGS_RELWITHDEBINFO (below) and tried to align things for readability/consistency (though I see I missed a space 😅)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing is sorted in 4a8501b. If I don't adjust the whitespace for the existing sets they will be inconsistent with the new CMAKE_C_FLAGS_RELWITHDEBINFO set. But happy to do this if you prefer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with whichever works for you. Was just making sure that I wasn't missing anything :D

set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")

elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")

# Copied from MOM5/bin/mkmf.template.nci
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -fp-model source")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -fp-model source")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")

elseif(CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")

# Copied from MOM5/bin/mkmf.template.nci
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")

elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")

# Copied from MOM5/bin/mkmf.template.nci.gfortran
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")

else()
message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options")
Expand All @@ -139,9 +143,8 @@ endif()

# Build options
option(OPENMP "Build FMS with OpenMP support" OFF)
# Commented out while CMAKE_Fortran_FLAGS contains -r8
# Only 64BIT (r8) builds are supported: only r8_flags (used below) is defined for the Fortran precision flags
Comment thread
manodeep marked this conversation as resolved.
# option(32BIT "Build 32-bit (r4) FMS library" OFF)
# Refer to CMAKE_Fortran_FLAGS above, it contains -r8
option(64BIT "Build 64-bit (r8) FMS library" ON)
option(FPIC "Build with position independent code" OFF)
option(SHARED_LIBS "Build shared/dynamic libraries" OFF)
Expand Down
Loading