Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
58 changes: 58 additions & 0 deletions cmake/build_type_compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# (C) Copyright 2026 UCAR
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.


# IntelLLVM
if(CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C++ compiler flags" FORCE)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL IntelLLVM)
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C compiler flags" FORCE)
set(CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C compiler flags" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C compiler flags" FORCE)
set(CMAKE_C_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C compiler flags" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C compiler flags" FORCE)
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
set(Fortran_AUTOMATIC_ARRAYS_LIMIT 32768) # (32 kb)
math(EXPR Fortran_AUTOMATIC_ARRAYS_LIMIT_KB "${Fortran_AUTOMATIC_ARRAYS_LIMIT}/1024")

set(Fortran_FLAG_STACK_ARRAYS "-no-heap-arrays")
set(Fortran_FLAG_AUTOMATIC_ARRAYS "-heap-arrays ${Fortran_AUTOMATIC_ARRAYS_LIMIT_KB}")

set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG -unroll -inline ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Release Fortran flags" FORCE)
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Release-with-debug-info Fortran flags" FORCE)
set(CMAKE_Fortran_FLAGS_BIT "-O2 -DNDEBUG -unroll -inline ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Bit-reproducible Fortran flags" FORCE)
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -traceback ${Fortran_FLAG_AUTOMATIC_ARRAYS} -check all" CACHE STRING "Debug Fortran flags" FORCE)
set(CMAKE_Fortran_FLAGS_PRODUCTION "-O3 -g ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Production Fortran compiler flags" FORCE)
endif()


# NVHPC
if(CMAKE_CXX_COMPILER_ID STREQUAL NVHPC)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C++ compiler flags" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C++ compiler flags" FORCE)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL NVHPC)
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C compiler flags" FORCE)
set(CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C compiler flags" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C compiler flags" FORCE)
set(CMAKE_C_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C compiler flags" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C compiler flags" FORCE)
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL NVHPC)
set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release Fortran compiler flags" FORCE)
set(CMAKE_Fortran_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible Fortran compiler flags" FORCE)
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug Fortran compiler flags" FORCE)
set(CMAKE_Fortran_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production Fortran compiler flags" FORCE)
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info Fortran compiler flags" FORCE)
endif()
56 changes: 0 additions & 56 deletions cmake/compiler_flags_Cray_Fortran.cmake

This file was deleted.

50 changes: 0 additions & 50 deletions cmake/compiler_flags_GNU_Fortran.cmake

This file was deleted.

51 changes: 0 additions & 51 deletions cmake/compiler_flags_IntelLLVM_Fortran.cmake

This file was deleted.

43 changes: 0 additions & 43 deletions cmake/compiler_flags_Intel_Fortran.cmake

This file was deleted.

59 changes: 0 additions & 59 deletions cmake/compiler_flags_XL_Fortran.cmake

This file was deleted.

54 changes: 22 additions & 32 deletions cmake/crtm_compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
# (C) Copyright 2026 UCAR
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.

if( NOT CMAKE_BUILD_TYPE MATCHES "Debug" )
add_definitions( -DNDEBUG )
endif()

#######################################################################################
# Fortran
#######################################################################################

message(STATUS "Compiler ID: ${CMAKE_Fortran_COMPILER_ID}")
message(STATUS "Compiler: ${CMAKE_Fortran_COMPILER}")

set(CMAKE_FORTRAN_STANDARD 08)
set(CMAKE_FORTRAN_STANDARD_REQUIRED ON)
set(CMAKE_FORTRAN_EXTENSIONS OFF)

if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
include( compiler_flags_GNU_Fortran )

elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM" )
include( compiler_flags_IntelLLVM_Fortran )
# Set compiler flags for basic build types,
# for compilers where this is not provided by ecbuild.
include(build_type_compiler_flags)

elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
include( compiler_flags_Intel_Fortran )
# Set JEDI's common compiler flags
include(jedi_common_compiler_flags)

elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" OR CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" )
include( compiler_flags_NVHPC_Fortran )

elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "XL" )
include( compiler_flags_XL_Fortran )

elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Cray" )
include( compiler_flags_Cray_Fortran )

else()
message( STATUS "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
# Set CRTM-specific compiler flags
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
ecbuild_add_fortran_flags("-ffree-line-length-none")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Spoke with @BenjaminTJohnson — CRTM has the requirement of being buildable outside of the JEDI environment, in particular of being buildable as a standalone repo with a CMake (not ecbuild) build system.

Thus, these ecbuild functions shouldn't be used to specify flags.

I'll go back and rethink this PR to see if I can improve the consistency of CRTM flags with the rest of JEDI, while still falling within CRTM's constraints.

endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
ecbuild_add_fortran_flags("-assume byterecl")
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
# to match historical behavior, disable RelWithDebugInfo optimization for IntelLLVM
# TODO: determine source of problem and resolve in a more elegant way, then return
# to default compiler flags so that RELWITHDEBINFO does what it says
set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O0 -g -DNDEBUG -traceback -heap-arrays 32" )
ecbuild_add_fortran_flags("-assume byterecl")
endif()
Loading
Loading