Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake build #2

Open
wants to merge 32 commits into
base: dev/access
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6663aef
Copied CMakeLists.txt from COSIMA/access-om3/MOM6
minghangli-uni Nov 13, 2024
e371579
update CMakeLists.txt
minghangli-uni Nov 15, 2024
d656bbd
Add add_fortran_library function.
minghangli-uni Nov 14, 2024
2cd94a2
Update cmake directory to enable MOM6 standalone build
minghangli-uni Nov 26, 2024
8c4425c
Switch PROJECT_HOMEPAGE_URL and DESCRIPTION
minghangli-uni Dec 9, 2024
18135a0
Fix typos
minghangli-uni Dec 9, 2024
e08c081
Rename Fortranlib.cmake to FortranLib.cmake
minghangli-uni Dec 9, 2024
9ee3d63
Comment PIO
minghangli-uni Dec 9, 2024
6b2a366
uncomment esmf library link
minghangli-uni Dec 9, 2024
021a7f7
add esmf package
minghangli-uni Dec 9, 2024
27129b5
add findesmf cmake file
minghangli-uni Dec 9, 2024
bea9146
Add c precessor for cesmcoupled
minghangli-uni Dec 11, 2024
d2112f8
Enable MOM6 standalone exe and ACCESS3MOM6 library
minghangli-uni Jan 20, 2025
31b869f
Remove misleading comments
minghangli-uni Jan 20, 2025
c5f2b04
Replicate FMS cap initialize_ocean_public_type changes in NUOPC cap
dougiesquire Jan 22, 2025
c82b91a
Allow generic tracers in NUOPC cap
dougiesquire Jan 23, 2025
62da2a0
Accumulate fluxes%salt_flux_added and pass to new generic_tracer_upda…
dougiesquire Jan 23, 2025
a0b0226
Small tweaks
minghangli-uni Jan 23, 2025
079e53b
Configure MOM6 package
minghangli-uni Jan 23, 2025
1fbf957
fix package name
minghangli-uni Jan 23, 2025
8d0d525
remove option mom6 standalone and rename ENABLE_ACCESS_MOM6 to ACCESS…
minghangli-uni Jan 23, 2025
80a3661
Add dependency for MOM6 configuration
minghangli-uni Jan 23, 2025
50473e3
name tweaks and missing files
anton-seaice Jan 23, 2025
b648a63
fix typo
minghangli-uni Jan 23, 2025
dd52c5f
typo
anton-seaice Jan 23, 2025
ff38233
Check for Netcdf parallel
anton-seaice Feb 3, 2025
12631b3
extra checks for Netcdf parallel
anton-seaice Feb 5, 2025
b62e617
possibly better deps handling
anton-seaice Feb 5, 2025
5e1f917
Fix bug in setting Fortran compiler flags
dougiesquire Feb 13, 2025
02bd2ae
Fix bug in setting Fortran compiler flags
dougiesquire Feb 13, 2025
8448393
Merge remote-tracking branch 'origin/PRcandidate-202502-gtracer-nuopc…
anton-seaice Feb 28, 2025
dbc5f95
fix CMakeLists
anton-seaice Feb 28, 2025
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
488 changes: 488 additions & 0 deletions cmake/CMakeLists.txt

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Common compiler flags and definitions

# Fortran compiler flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fbacktrace -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none -fdefault-real-8 -fdefault-double-8")
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O")
set(CMAKE_Fortran_FLAGS_DEBUG "-g -Wall -Og -ffpe-trap=zero,overflow -fcheck=bounds")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qno-opt-dynamic-align -convert big_endian -assume byterecl -ftz -traceback -assume realloc_lhs -fp-model source -r8")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -debug minimal")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -check uninit -check bounds -check pointers -fpe0 -check noarg_temp_created")
else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
endif()

# C compiler flags
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O")
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Og -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -traceback -qno-opt-dynamic-align -fp-model precise -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
else()
message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options")
endif()
135 changes: 135 additions & 0 deletions cmake/FindESMF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# - Try to find ESMF
#
# Requires setting ESMFMKFILE to the filepath of esmf.mk. If this is NOT set,
# then ESMF_FOUND will always be FALSE. If ESMFMKFILE exists, then ESMF_FOUND=TRUE
# and all ESMF makefile variables will be set in the global scope. Optionally,
# set ESMF_MKGLOBALS to a string list to filter makefile variables. For example,
# to globally scope only ESMF_LIBSDIR and ESMF_APPSDIR variables, use this CMake
# command in CMakeLists.txt:
#
# set(ESMF_MKGLOBALS "LIBSDIR" "APPSDIR")


# Add the ESMFMKFILE path to the cache if defined as system env variable
if(DEFINED ENV{ESMFMKFILE} AND NOT DEFINED ESMFMKFILE)
set(ESMFMKFILE $ENV{ESMFMKFILE} CACHE FILEPATH "Path to ESMF mk file")
endif()

# If it's not explicitly set try to find esmf.mk file in default locations (ESMF_ROOT, CMAKE_PREFIX_PATH, etc)
if(NOT DEFINED ESMFMKFILE)
find_path(ESMFMKFILE_PATH esmf.mk PATH_SUFFIXES lib lib64)
if(ESMFMKFILE_PATH)
set(ESMFMKFILE ${ESMFMKFILE_PATH}/esmf.mk)
message(STATUS "Found esmf.mk file ${ESMFMKFILE}")
else()
message(STATUS "ESMFMKFILE not defined. This is the path to esmf.mk file. \
Without this filepath, ESMF_FOUND will always be FALSE.")
endif()
endif()

# Only parse the mk file if it is found
if(EXISTS ${ESMFMKFILE})
# Read the mk file
file(STRINGS "${ESMFMKFILE}" esmfmkfile_contents)
# Parse each line in the mk file
foreach(str ${esmfmkfile_contents})
# Only consider uncommented lines
string(REGEX MATCH "^[^#]" def ${str})
# Line is not commented
if(def)
# Extract the variable name
string(REGEX MATCH "^[^=]+" esmf_varname ${str})
# Extract the variable's value
string(REGEX MATCH "=.+$" esmf_vardef ${str})
# Only for variables with a defined value
if(esmf_vardef)
# Get rid of the assignment string
string(SUBSTRING ${esmf_vardef} 1 -1 esmf_vardef)
# Remove whitespace
string(STRIP ${esmf_vardef} esmf_vardef)
# A string or single-valued list
if(NOT DEFINED ESMF_MKGLOBALS)
# Set in global scope
set(${esmf_varname} ${esmf_vardef})
# Don't display by default in GUI
mark_as_advanced(esmf_varname)
else() # Need to filter global promotion
foreach(m ${ESMF_MKGLOBALS})
string(FIND ${esmf_varname} ${m} match)
# Found the string
if(NOT ${match} EQUAL -1)
# Promote to global scope
set(${esmf_varname} ${esmf_vardef})
# Don't display by default in the GUI
mark_as_advanced(esmf_varname)
# No need to search for the current string filter
break()
endif()
endforeach()
endif()
endif()
endif()
endforeach()

# Construct ESMF_VERSION from ESMF_VERSION_STRING_GIT
# ESMF_VERSION_MAJOR and ESMF_VERSION_MINOR are defined in ESMFMKFILE
set(ESMF_VERSION 0)
set(ESMF_VERSION_PATCH ${ESMF_VERSION_REVISION})
set(ESMF_BETA_RELEASE FALSE)
if(ESMF_VERSION_BETASNAPSHOT MATCHES "^('T')$")
set(ESMF_BETA_RELEASE TRUE)
string(REGEX REPLACE ".*beta_snapshot_*\([0-9]*\).*" "\\1" ESMF_BETA_SNAPSHOT "${ESMF_VERSION_STRING_GIT}")
message(STATUS "Detected ESMF Beta snapshot ${ESMF_BETA_SNAPSHOT}")
endif()
set(ESMF_VERSION "${ESMF_VERSION_MAJOR}.${ESMF_VERSION_MINOR}.${ESMF_VERSION_PATCH}")

separate_arguments(ESMF_F90COMPILEPATHS NATIVE_COMMAND ${ESMF_F90COMPILEPATHS})
foreach(ITEM ${ESMF_F90COMPILEPATHS})
string(REGEX REPLACE "^-I" "" ITEM "${ITEM}")
list(APPEND tmp ${ITEM})
endforeach()
set(ESMF_F90COMPILEPATHS ${tmp})

# Look for static library, if not found try dynamic library
find_library(esmf_lib NAMES libesmf.a PATHS ${ESMF_LIBSDIR})
if(esmf_lib MATCHES "esmf_lib-NOTFOUND")
unset(esmf_lib)
message(STATUS "Static ESMF library not found, searching for dynamic library instead")
find_library(esmf_lib NAMES esmf_fullylinked libesmf.so PATHS ${ESMF_LIBSDIR})
if(esmf_lib MATCHES "esmf_lib-NOTFOUND")
unset(esmf_lib)
message(STATUS "Neither the dynamic nor the static ESMF library was found")
else()
set(_library_type SHARED)
endif()
else()
set(_library_type STATIC)
endif()

string(STRIP "${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES)
set(ESMF_LIBRARY_LOCATION ${esmf_lib})

else()

message(WARNING "ESMFMKFILE ${ESMFMKFILE} does not exist")

endif()

## Finalize find_package
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
${CMAKE_FIND_PACKAGE_NAME}
REQUIRED_VARS ESMF_LIBRARY_LOCATION
ESMF_INTERFACE_LINK_LIBRARIES
ESMF_F90COMPILEPATHS
VERSION_VAR ESMF_VERSION)

## If ESMF is found create imported library target
if(ESMF_FOUND)
add_library(esmf ${_library_type} IMPORTED)
set_target_properties(esmf PROPERTIES
IMPORTED_LOCATION "${ESMF_LIBRARY_LOCATION}"
INTERFACE_INCLUDE_DIRECTORIES "${ESMF_F90COMPILEPATHS}"
INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}")
endif()
Loading