From fed794baa7fb1e57a652e3884d89a4f852898b3e Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 6 Mar 2025 14:55:15 +1100 Subject: [PATCH 01/13] set IFDEFs correctly to allow W3_IC4 build without numerics fix --- model/src/w3srcemd.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model/src/w3srcemd.F90 b/model/src/w3srcemd.F90 index 9bd97c6fbd..c51a86094d 100644 --- a/model/src/w3srcemd.F90 +++ b/model/src/w3srcemd.F90 @@ -2088,7 +2088,7 @@ SUBROUTINE W3SRCE ( srce_call, IT, ISEA, JSEA, IX, IY, IMOD, & #ifdef W3_IC3 CALL W3SIC3 ( SPEC,DEPTH, CG1, WN1, IX, IY, VSIC, VDIC ) #endif -#ifndef W3_IC4_NUMERICS +#if defined(W3_IC4) && !defined(W3_IC4_NUMERICS) CALL W3SIC4 ( SPEC,DEPTH, CG1, IX, IY, VSIC, VDIC ) #endif #ifdef W3_IC5 @@ -2119,7 +2119,7 @@ SUBROUTINE W3SRCE ( srce_call, IT, ISEA, JSEA, IX, IY, IMOD, & #ifdef W3_IC3 ATT=EXP(ICE*VDIC(IS)*DTG) #endif -#ifndef W3_IC4_NUMERICS +#if defined(W3_IC4) && !defined(W3_IC4_NUMERICS) ATT=EXP(ICE*VDIC(IS)*DTG) #endif #ifdef W3_IC5 From 4425747a97ae1ff2d201bb0190fd5778027a0d75 Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 13 Mar 2025 16:28:11 +1100 Subject: [PATCH 02/13] access3 cmake build --- CMakeLists.txt | 257 +++++++++++++++++++++------ cmake/Access3Ww3libConfig.cmake.in | 12 ++ cmake/FortranLib.cmake | 8 + model/src/cmake/check_switches.cmake | 2 +- 4 files changed, 227 insertions(+), 52 deletions(-) create mode 100644 cmake/Access3Ww3libConfig.cmake.in create mode 100644 cmake/FortranLib.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dff6c12fc..fea5aa99f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,68 +1,223 @@ -# CMake build written by Kyle Gerheiser - -# Requires CMake 3.19 for JSON strings cmake_minimum_required(VERSION 3.19) -# Get VERSION from VERSION file -file(STRINGS "VERSION" pVersion) - -project( - WW3 - VERSION ${pVersion} - LANGUAGES C Fortran) - -get_directory_property(hasParent PARENT_DIRECTORY) -if(hasParent) - # Unset flags that come from Parent (ie UFS or other coupled build) - # for potential (-r8/-r4) conflict - set(CMAKE_Fortran_FLAGS "") - set(CMAKE_C_FLAGS "") - remove_definitions(-DDEBUG) -endif() +#[==============================================================================[ +# Basic project definition # +#]==============================================================================] -set(valid_caps "MULTI_ESMF" "NUOPC_MESH") +project(WW3 + DESCRIPTION "WAVEWATCH III numerical wave model" + HOMEPAGE_URL https://github.com/ACCESS-NRI/WW3/ + LANGUAGES C Fortran) -set(UFS_CAP "" CACHE STRING "Valid options are ${valid_caps}") -set(NETCDF ON CACHE BOOL "Build NetCDF programs (requires NetCDF)") -set(ENDIAN "BIG" CACHE STRING "Endianness of unformatted output files. Valid values are 'BIG', 'LITTLE', 'NATIVE'.") -set(EXCLUDE_FIND "" CACHE STRING "Don't try and search for these libraries (assumd to be handled by the compiler/wrapper)") +#[==============================================================================[ +# Options # +#]==============================================================================] -# make sure all "exclude_find" entries are lower case -list(TRANSFORM EXCLUDE_FIND TOLOWER) +## List of switches +list(APPEND switches "CESMCOUPLED" "DIST" "MPI" "PR1" "FLX4" "ST6" "STAB0" "LN1" "NL1" "BT1" "DB1" "MLIM" "TR0" "BS0" "RWND" "WNX1" "WNT0" "CRX1" "CRT0" "O0" "O1" "O2" "O3" "O4" "O5" "O6" "O7" "O14" "O15" "IS2" "REF0" "NOGRB" "IC3") -# Make Find modules visible to CMake -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +## Global compile definitions +foreach(switch ${switches}) + add_compile_definitions(W3_${switch}) +endforeach() -# Set switch file on command line when running CMake -set(SWITCH "" CACHE STRING "Switch file, either full path, relative path from location of top-level WW3/ dir, or a switch in model/bin") +option(ACCESS3_WW3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) +message(STATUS " - ACCESS3_WW3 ${ACCESS3_WW3}") -# Search for switch file as a full path or in model/bin -if(EXISTS ${SWITCH}) - set(switch_file ${SWITCH}) -else() - set(switch_file ${CMAKE_CURRENT_SOURCE_DIR}/model/bin/switch_${SWITCH}) - if(NOT EXISTS ${switch_file}) - message(FATAL_ERROR "Switch file '${switch_file}' does not exist, set switch with -DSWITCH=") - endif() +if(NOT ACCESS3_WW3) + message(FATAL_ERROR " ACCESS3_WW3 is only supported build, set to ON") endif() -if(UFS_CAP) - if(NOT UFS_CAP IN_LIST valid_caps) - message(FATAL_ERROR "Invalid UFS_CAP selection. Valids options are ${valid_caps}") +if(ACCESS3_WW3) + option(CESMCOUPLED "CESMCOUPLED Build CPP" OFF) + message(STATUS " - CESMCOUPLED ${CESMCOUPLED}") +endif() + +#[==============================================================================[ +# Project configuration # +#]==============================================================================] + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) +include(FortranLib) + +# Common compiler flags and definitions +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") + 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 precise") + 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() + +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() + +if (CESMCOUPLED) + add_compile_definitions( + CESMCOUPLED + ) +endif() + +## Fortran modules path; currently this is simply set to be the include dir +set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} + CACHE STRING + "Fortran module installation path (Not a cmake native variable)" +) + +#[==============================================================================[ +# External packages # +#]==============================================================================] + +if(ACCESS3_WW3) + find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) + find_package(ESMF 8.3.0 MODULE REQUIRED) endif() -message(STATUS "Build with switch: ${switch_file}") -# Copy switch file to build dir -configure_file(${switch_file} ${CMAKE_BINARY_DIR}/switch COPYONLY) +find_package(NetCDF 4.7.3 REQUIRED Fortran) + + +#[==============================================================================[ +# Main definitions # +#]==============================================================================] + +## WW3 library + +set(SRC "${CMAKE_SOURCE_DIR}/model/src") + +add_fortran_library(ww3lib mod STATIC) +target_include_directories(ww3lib PRIVATE $) +target_compile_definitions(ww3lib PRIVATE ENDIANNESS="big_endian") +set_property(SOURCE ${SRC}/w3initmd.F90 + APPEND + PROPERTY COMPILE_DEFINITIONS + "__WW3_SWITCHES__=\'\'" +) +target_link_libraries(ww3lib + PUBLIC esmf +) +# Process switches and get list of extra source files +include(${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/check_switches.cmake) +check_switches("${switches}" switch_files) +message(VERBOSE "WW3 switch files: ${switch_files}") + +include(${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/src_list.cmake) +list(APPEND ftn_src ${nuopc_mesh_cap_src}) + +list(APPEND ftn_src ${switch_files}) + +foreach(file ${ftn_src} ) + # list(REMOVE_ITEM srcfiles ${file}) + list(APPEND srcfiles "${CMAKE_CURRENT_SOURCE_DIR}/model/src/${file}") +endforeach() + +target_sources(ww3lib PRIVATE + ${srcfiles} +) + +## Utilities + +# ww3_grid +add_executable(ww3_grid ${SRC}/ww3_grid.F90) +set_target_properties(ww3_grid PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ww3_grid +) +target_link_libraries(ww3_grid PRIVATE ww3lib) + +# ww3_strt +add_executable(ww3_strt ${SRC}/ww3_strt.F90) +set_target_properties(ww3_strt PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ww3_strt +) +target_link_libraries(ww3_strt PRIVATE ww3lib) + +# ww3_outf +add_executable(ww3_outf ${SRC}/ww3_outf.F90) +set_target_properties(ww3_outf PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ww3_outf +) +target_link_libraries(ww3_outf PRIVATE ww3lib) + +# ww3_ounf +add_executable(ww3_ounf) +target_sources(ww3_ounf PRIVATE + ${SRC}/ww3_ounf.F90 + ${SRC}/w3ounfmetamd.F90 +) +set_target_properties(ww3_ounf PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ww3_ounf +) +target_link_libraries(ww3_ounf PRIVATE ww3lib) + +# ww3_ounp +add_executable(ww3_ounp ${SRC}/ww3_ounp.F90) +set_target_properties(ww3_ounp PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ww3_ounp +) +target_link_libraries(ww3_ounp PRIVATE ww3lib) + +### Install and Export -# Re-configure CMake when switch changes -set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_BINARY_DIR}/switch) +## Library +if(ACCESS3_WW3) + set_target_properties(ww3lib PROPERTIES + OUTPUT_NAME access-ww3lib + EXPORT_NAME ww3lib + ) + install(TARGETS ww3lib + EXPORT Ww3libTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3Cmeps_RunTime NAMELINK_COMPONENT AccessWW3Cmeps_Development + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3Cmeps_Development + ) + # Fortran module files are a special case, as currently there is no standard + # way of handling them in CMake + target_include_directories(ww3lib PUBLIC "$") + get_target_property(ww3_moddir ww3lib Fortran_MODULE_DIRECTORY) + install(FILES ${ww3_moddir}/wav_comp_nuopc.mod + DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-ww3 + COMPONENT AccessWW3Cmeps_Development + ) + install(EXPORT Ww3libTargets + FILE Ww3libTargets.cmake + NAMESPACE Access3:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib + ) -if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$") - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + # Make sure the dependencies get exported too + configure_package_config_file( + cmake/Access3Ww3libConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/Ww3libConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib + ) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Ww3libConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib + COMPONENT AccessWW3Cmeps_Development + ) endif() -add_subdirectory(model) +## Utilities +install(TARGETS ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp +RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/cmake/Access3Ww3libConfig.cmake.in b/cmake/Access3Ww3libConfig.cmake.in new file mode 100644 index 0000000000..9363d416c2 --- /dev/null +++ b/cmake/Access3Ww3libConfig.cmake.in @@ -0,0 +1,12 @@ +@PACKAGE_INIT@ + +# Request components +set(_required_components ${Ww3lib_FIND_COMPONENTS}) + +# Run the normal Targets.cmake +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) +include("${CMAKE_CURRENT_LIST_DIR}/Ww3libTargets.cmake") +list(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) + +# Check the requested components are valid +check_required_components(_required_components) \ No newline at end of file diff --git a/cmake/FortranLib.cmake b/cmake/FortranLib.cmake new file mode 100644 index 0000000000..08bcccbf8c --- /dev/null +++ b/cmake/FortranLib.cmake @@ -0,0 +1,8 @@ +function(add_fortran_library LIB MOD_DIR) + add_library(${LIB} ${ARGN}) + + get_target_property(LIB_DIR ${LIB} BINARY_DIR) + set_target_properties(${LIB} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_DIR}/${MOD_DIR}) + + target_include_directories(${LIB} INTERFACE "$") + endfunction(add_fortran_library) diff --git a/model/src/cmake/check_switches.cmake b/model/src/cmake/check_switches.cmake index 563d529e21..12c5edbebf 100644 --- a/model/src/cmake/check_switches.cmake +++ b/model/src/cmake/check_switches.cmake @@ -1,6 +1,6 @@ function(check_switches switches switch_files) # Read JSON file - file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/switches.json json_str) + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/switches.json json_str) # Get length of top-level array of all switch categories string(JSON len LENGTH ${json_str}) # CMake's foreach RANGE is inclusive, so subtract 1 when looping From 85b9420adb2f0c00bfd072ea5bc0da91a6f1b48e Mon Sep 17 00:00:00 2001 From: Anton Steketee <79179784+anton-seaice@users.noreply.github.com> Date: Thu, 13 Mar 2025 20:42:44 +1100 Subject: [PATCH 03/13] find MPI --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fea5aa99f8..8823f875dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,8 +91,8 @@ if(ACCESS3_WW3) find_package(ESMF 8.3.0 MODULE REQUIRED) endif() -find_package(NetCDF 4.7.3 REQUIRED Fortran) - +# find_package(NetCDF 4.7.3 REQUIRED Fortran) +find_package(MPI REQUIRED) #[==============================================================================[ # Main definitions # @@ -220,4 +220,4 @@ endif() ## Utilities install(TARGETS ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp -RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file +RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) From 0d3efee79a4bd59490e83ce60f505b016aee2a7a Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Fri, 14 Mar 2025 17:11:20 +1100 Subject: [PATCH 04/13] incremental gains --- CMakeLists.txt | 99 +++++++++++++++--------------- cmake/Access3Ww3libConfig.cmake.in | 4 ++ 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fea5aa99f8..95888f9078 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,11 +21,13 @@ foreach(switch ${switches}) add_compile_definitions(W3_${switch}) endforeach() -option(ACCESS3_WW3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) +option(ACCESS3_WW3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) +option(OPENMP "Enable OpenMP threading" OFF) message(STATUS " - ACCESS3_WW3 ${ACCESS3_WW3}") +message(STATUS " - OPENMP ${OPENMP}") if(NOT ACCESS3_WW3) - message(FATAL_ERROR " ACCESS3_WW3 is only supported build, set to ON") + message(STATUS " - NOT ACCESS3_WW3: Building standalone ww3_shel for testing") endif() if(ACCESS3_WW3) @@ -33,6 +35,11 @@ if(ACCESS3_WW3) message(STATUS " - CESMCOUPLED ${CESMCOUPLED}") endif() +if(OPENMP) + list(APPEND switches "OMPG") +endif() + + #[==============================================================================[ # Project configuration # #]==============================================================================] @@ -73,6 +80,7 @@ endif() if (CESMCOUPLED) add_compile_definitions( CESMCOUPLED + W3_CESMCOUPLED ) endif() @@ -86,13 +94,16 @@ set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} # External packages # #]==============================================================================] +find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) + if(ACCESS3_WW3) find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) find_package(ESMF 8.3.0 MODULE REQUIRED) endif() -find_package(NetCDF 4.7.3 REQUIRED Fortran) - +if(OPENMP) + find_package(OpenMP REQUIRED COMPONENTS Fortran) +endif() #[==============================================================================[ # Main definitions # @@ -110,21 +121,30 @@ set_property(SOURCE ${SRC}/w3initmd.F90 PROPERTY COMPILE_DEFINITIONS "__WW3_SWITCHES__=\'\'" ) -target_link_libraries(ww3lib - PUBLIC esmf -) +target_link_libraries(ww3lib PUBLIC NetCDF::NetCDF_Fortran) + +if(ACCESS3_WW3) + target_link_libraries(ww3lib PUBLIC esmf) +endif() + +if(OpenMP_Fortran_FOUND) + target_link_libraries(ww3lib PUBLIC OpenMP::OpenMP_Fortran) +endif() + # Process switches and get list of extra source files include(${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/check_switches.cmake) check_switches("${switches}" switch_files) message(VERBOSE "WW3 switch files: ${switch_files}") include(${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/src_list.cmake) -list(APPEND ftn_src ${nuopc_mesh_cap_src}) + +if(ACCESS3_WW3) + list(APPEND ftn_src ${nuopc_mesh_cap_src}) +endif() list(APPEND ftn_src ${switch_files}) foreach(file ${ftn_src} ) - # list(REMOVE_ITEM srcfiles ${file}) list(APPEND srcfiles "${CMAKE_CURRENT_SOURCE_DIR}/model/src/${file}") endforeach() @@ -132,51 +152,34 @@ target_sources(ww3lib PRIVATE ${srcfiles} ) -## Utilities -# ww3_grid -add_executable(ww3_grid ${SRC}/ww3_grid.F90) -set_target_properties(ww3_grid PROPERTIES - LINKER_LANGUAGE Fortran - OUTPUT_NAME ww3_grid -) -target_link_libraries(ww3_grid PRIVATE ww3lib) -# ww3_strt -add_executable(ww3_strt ${SRC}/ww3_strt.F90) -set_target_properties(ww3_strt PROPERTIES - LINKER_LANGUAGE Fortran - OUTPUT_NAME ww3_strt -) -target_link_libraries(ww3_strt PRIVATE ww3lib) - -# ww3_outf -add_executable(ww3_outf ${SRC}/ww3_outf.F90) -set_target_properties(ww3_outf PROPERTIES - LINKER_LANGUAGE Fortran - OUTPUT_NAME ww3_outf -) -target_link_libraries(ww3_outf PRIVATE ww3lib) +## Utilities +# Always build utilities: +set(utility_apps ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp) +if(NOT ACCESS3_WW3) + # A generic WW3 "shell" for testing + list(APPEND utility_apps ww3_shel) +endif() + #to-do: confim when other utilities are needed: + # ww3_bound ww3_outp ww3_trck ww3_grib + # ww3_gint gx_outf gx_outp ww3_uprstr ww3_prep ww3_gspl ww3_multi ww3_systrk + # ww3_ounf ww3_ounp ww3_bounc ww3_trnc ww3_prnc + +foreach(program ${utility_apps}) + add_executable(${program} ${SRC}/${program}.F90) + set_target_properties(${program} PROPERTIES + LINKER_LANGUAGE Fortran + OUTPUT_NAME ${program} + ) + target_link_libraries(${program} PRIVATE ww3lib) +endforeach() -# ww3_ounf -add_executable(ww3_ounf) +# ww3_ounf has en extra file target_sources(ww3_ounf PRIVATE - ${SRC}/ww3_ounf.F90 ${SRC}/w3ounfmetamd.F90 ) -set_target_properties(ww3_ounf PROPERTIES - LINKER_LANGUAGE Fortran - OUTPUT_NAME ww3_ounf -) -target_link_libraries(ww3_ounf PRIVATE ww3lib) -# ww3_ounp -add_executable(ww3_ounp ${SRC}/ww3_ounp.F90) -set_target_properties(ww3_ounp PROPERTIES - LINKER_LANGUAGE Fortran - OUTPUT_NAME ww3_ounp -) -target_link_libraries(ww3_ounp PRIVATE ww3lib) ### Install and Export @@ -219,5 +222,5 @@ if(ACCESS3_WW3) endif() ## Utilities -install(TARGETS ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp +install(TARGETS ${utility_apps} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/cmake/Access3Ww3libConfig.cmake.in b/cmake/Access3Ww3libConfig.cmake.in index 9363d416c2..406343c7f5 100644 --- a/cmake/Access3Ww3libConfig.cmake.in +++ b/cmake/Access3Ww3libConfig.cmake.in @@ -1,5 +1,9 @@ @PACKAGE_INIT@ +if(@OPENMP@) + find_package(OpenMP REQUIRED) +endif() + # Request components set(_required_components ${Ww3lib_FIND_COMPONENTS}) From e5a5e9be937fd7ddef1b5cdb64587e90578515fb Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Mon, 17 Mar 2025 14:26:24 +1100 Subject: [PATCH 05/13] tidyup --- CMakeLists.txt | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc8666225d..8372b1f5df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,13 +14,9 @@ project(WW3 #]==============================================================================] ## List of switches +# to-do: make configurable list(APPEND switches "CESMCOUPLED" "DIST" "MPI" "PR1" "FLX4" "ST6" "STAB0" "LN1" "NL1" "BT1" "DB1" "MLIM" "TR0" "BS0" "RWND" "WNX1" "WNT0" "CRX1" "CRT0" "O0" "O1" "O2" "O3" "O4" "O5" "O6" "O7" "O14" "O15" "IS2" "REF0" "NOGRB" "IC3") -## Global compile definitions -foreach(switch ${switches}) - add_compile_definitions(W3_${switch}) -endforeach() - option(ACCESS3_WW3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) option(OPENMP "Enable OpenMP threading" OFF) message(STATUS " - ACCESS3_WW3 ${ACCESS3_WW3}") @@ -30,21 +26,22 @@ if(NOT ACCESS3_WW3) message(STATUS " - NOT ACCESS3_WW3: Building standalone ww3_shel for testing") endif() -if(ACCESS3_WW3) - option(CESMCOUPLED "CESMCOUPLED Build CPP" OFF) - message(STATUS " - CESMCOUPLED ${CESMCOUPLED}") -endif() - if(OPENMP) list(APPEND switches "OMPG") endif() +set(NETCDF ON CACHE BOOL "Build NetCDF programs (requires NetCDF)") +set(ENDIAN "BIG" CACHE STRING "Endianness of unformatted output files. Valid values are 'BIG', 'LITTLE', 'NATIVE'.") + #[==============================================================================[ # Project configuration # #]==============================================================================] -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + + + include(CMakePackageConfigHelpers) include(GNUInstallDirs) include(FortranLib) @@ -77,11 +74,13 @@ else() message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options") endif() -if (CESMCOUPLED) - add_compile_definitions( - CESMCOUPLED - W3_CESMCOUPLED - ) +## Global compile definitions +foreach(switch ${switches}) + add_compile_definitions(W3_${switch}) +endforeach() + +if ("CESMCOUPLED" IN_LIST switches) + add_compile_definitions(CESMCOUPLED) endif() ## Fortran modules path; currently this is simply set to be the include dir @@ -144,15 +143,11 @@ endif() list(APPEND ftn_src ${switch_files}) -foreach(file ${ftn_src} ) +foreach(file ${ftn_src}) list(APPEND srcfiles "${CMAKE_CURRENT_SOURCE_DIR}/model/src/${file}") endforeach() -target_sources(ww3lib PRIVATE - ${srcfiles} -) - - +target_sources(ww3lib PRIVATE ${srcfiles}) ## Utilities # Always build utilities: @@ -180,8 +175,9 @@ target_sources(ww3_ounf PRIVATE ${SRC}/w3ounfmetamd.F90 ) - -### Install and Export +#[==============================================================================[ +# Install and Export # +#]==============================================================================] ## Library if(ACCESS3_WW3) @@ -222,10 +218,6 @@ if(ACCESS3_WW3) endif() ## Utilities -<<<<<<< HEAD install(TARGETS ${utility_apps} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -======= -install(TARGETS ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp -RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ->>>>>>> origin/1-cmake_build + From f55819771a21cd7a6604f111ee38a0c0c4eb98f4 Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Mon, 17 Mar 2025 14:30:14 +1100 Subject: [PATCH 06/13] tidup --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8372b1f5df..c61c3102f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,6 @@ if(OPENMP) list(APPEND switches "OMPG") endif() -set(NETCDF ON CACHE BOOL "Build NetCDF programs (requires NetCDF)") -set(ENDIAN "BIG" CACHE STRING "Endianness of unformatted output files. Valid values are 'BIG', 'LITTLE', 'NATIVE'.") #[==============================================================================[ From d22fdc44ecc1bf2248de1af94037b68fab1580d1 Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Tue, 18 Mar 2025 14:55:21 +1100 Subject: [PATCH 07/13] license --- CMakeLists.txt | 4 +- cmake/Access3Ww3libConfig.cmake.in | 2 + cmake/FindESMF.cmake | 181 +++++++++++++++++++---------- cmake/FortranLib.cmake | 2 + 4 files changed, 126 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c61c3102f8..e04071b756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +# Copyright ACCESS-NRI and contributors. See the top-level LICENSE file for details. + cmake_minimum_required(VERSION 3.19) #[==============================================================================[ @@ -38,8 +40,6 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - - include(CMakePackageConfigHelpers) include(GNUInstallDirs) include(FortranLib) diff --git a/cmake/Access3Ww3libConfig.cmake.in b/cmake/Access3Ww3libConfig.cmake.in index 406343c7f5..ce8f22ec95 100644 --- a/cmake/Access3Ww3libConfig.cmake.in +++ b/cmake/Access3Ww3libConfig.cmake.in @@ -1,3 +1,5 @@ +# Copyright ACCESS-NRI and contributors. See the top-level LICENSE file for details. + @PACKAGE_INIT@ if(@OPENMP@) diff --git a/cmake/FindESMF.cmake b/cmake/FindESMF.cmake index 5ba7003bdb..8dfb926ce1 100644 --- a/cmake/FindESMF.cmake +++ b/cmake/FindESMF.cmake @@ -1,34 +1,81 @@ +# Earth System Modeling Framework + +# Copyright (c) 2002-2025 University Corporation for Atmospheric Research, +# Massachusetts Institute of Technology, Geophysical Fluid Dynamics Laboratory, +# University of Michigan, National Centers for Environmental Prediction, +# Los Alamos National Laboratory, Argonne National Laboratory, +# NASA Goddard Space Flight Center. +# All rights reserved. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal with the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimers. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimers in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the names of the organizations developing this software, nor +# the names of its contributors may be used to endorse or promote products +# derived from this Software without specific prior written permission. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# WITH THE SOFTWARE. + # - 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: +# Uses ESMFMKFILE to find the filepath of esmf.mk. If this is NOT set, then this +# module will attempt to find esmf.mk. 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") +# Set ESMFMKFILE as defined by system env variable. If it's not explicitly set +# try to find esmf.mk file in default locations (ESMF_ROOT, CMAKE_PREFIX_PATH, +# etc) -# 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() +# - Common Usage +# +# Where to look for this FindESMF.cmake file +# list(APPEND CMAKE_MODULE_PATH "") +# is to be replaced with the directory for this file +# +# How to locate ESMF libraries and create target +# find_package(ESMF MODULE REQUIRED) +# is to be replaced with the minimum version required +# +# How to link targets +# target_link_libraries( PUBLIC ESMF::ESMF) +# is to be replaced with your CMake target -# 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}") + if(NOT DEFINED ENV{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}") + endif() else() - message(STATUS "ESMFMKFILE not defined. This is the path to esmf.mk file. \ -Without this filepath, ESMF_FOUND will always be FALSE.") + set(ESMFMKFILE $ENV{ESMFMKFILE}) endif() endif() # Only parse the mk file if it is found if(EXISTS ${ESMFMKFILE}) + set(ESMFMKFILE ${ESMFMKFILE} CACHE FILEPATH "Path to esmf.mk file") + set(ESMF_FOUND TRUE CACHE BOOL "esmf.mk file found" FORCE) + # Read the mk file file(STRINGS "${ESMFMKFILE}" esmfmkfile_contents) # Parse each line in the mk file @@ -78,58 +125,70 @@ if(EXISTS ${ESMFMKFILE}) 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}") + if(ESMF_VERSION_STRING_GIT MATCHES "^ESMF.*beta_snapshot") + set(ESMF_BETA_SNAPSHOT ${ESMF_VERSION_STRING_GIT}) + elseif(ESMF_VERSION_STRING_GIT MATCHES "^v.\..\..b") + set(ESMF_BETA_SNAPSHOT ${ESMF_VERSION_STRING_GIT}) + else() + set(ESMF_BETA_SNAPSHOT 0) + endif() + 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) + # Find the ESMF library + if(USE_ESMF_STATIC_LIBS) + find_library(ESMF_LIBRARY_LOCATION NAMES libesmf.a PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH) + if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND") + message(WARNING "Static ESMF library (libesmf.a) not found in \ + ${ESMF_LIBSDIR}. Try setting USE_ESMF_STATIC_LIBS=OFF") + endif() + if(NOT TARGET ESMF::ESMF) + add_library(ESMF::ESMF STATIC IMPORTED) endif() else() - set(_library_type STATIC) + find_library(ESMF_LIBRARY_LOCATION NAMES esmf PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH) + if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND") + message(WARNING "ESMF library not found in ${ESMF_LIBSDIR}.") + endif() + if(NOT TARGET ESMF::ESMF) + add_library(ESMF::ESMF UNKNOWN IMPORTED) + endif() endif() - string(STRIP "${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES) - set(ESMF_LIBRARY_LOCATION ${esmf_lib}) + # Add ESMF as an alias to ESMF::ESMF for backward compatibility + if(NOT TARGET ESMF) + add_library(ESMF ALIAS ESMF::ESMF) + endif() -else() + # Add ESMF include directories + set(ESMF_INCLUDE_DIRECTORIES "") + separate_arguments(_ESMF_F90COMPILEPATHS UNIX_COMMAND ${ESMF_F90COMPILEPATHS}) + foreach(_ITEM ${_ESMF_F90COMPILEPATHS}) + string(REGEX REPLACE "^-I" "" _ITEM "${_ITEM}") + list(APPEND ESMF_INCLUDE_DIRECTORIES ${_ITEM}) + endforeach() - message(WARNING "ESMFMKFILE ${ESMFMKFILE} does not exist") + # Add ESMF link libraries + string(STRIP "${ESMF_F90LINKRPATHS} ${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES) -endif() + # Finalize find_package + include(FindPackageHandleStandardArgs) -## 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() + find_package_handle_standard_args( + ${CMAKE_FIND_PACKAGE_NAME} + REQUIRED_VARS ESMF_LIBRARY_LOCATION + ESMF_INTERFACE_LINK_LIBRARIES + ESMF_F90COMPILEPATHS + VERSION_VAR ESMF_VERSION) + + set_target_properties(ESMF::ESMF PROPERTIES + IMPORTED_LOCATION "${ESMF_LIBRARY_LOCATION}" + INTERFACE_INCLUDE_DIRECTORIES "${ESMF_INCLUDE_DIRECTORIES}" + INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}") + +else() + set(ESMF_FOUND FALSE CACHE BOOL "esmf.mk file NOT found" FORCE) + message(WARNING "ESMFMKFILE ${ESMFMKFILE} not found. Try setting ESMFMKFILE \ + to esmf.mk location.") +endif() \ No newline at end of file diff --git a/cmake/FortranLib.cmake b/cmake/FortranLib.cmake index 08bcccbf8c..6eaec978be 100644 --- a/cmake/FortranLib.cmake +++ b/cmake/FortranLib.cmake @@ -1,3 +1,5 @@ +# Copyright ACCESS-NRI and contributors. See the top-level LICENSE file for details. + function(add_fortran_library LIB MOD_DIR) add_library(${LIB} ${ARGN}) From e8616cee0efe46c6db5587057bb0f064bc1c902a Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Wed, 19 Mar 2025 14:38:39 +1100 Subject: [PATCH 08/13] add find package MPI for completeness --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e04071b756..2974d4a64c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} #]==============================================================================] find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) +find_package(MPI REQUIRED) if(ACCESS3_WW3) find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) @@ -208,7 +209,6 @@ if(ACCESS3_WW3) "${CMAKE_CURRENT_BINARY_DIR}/Ww3libConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib ) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Ww3libConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib COMPONENT AccessWW3Cmeps_Development From d59bb4d82f45fa3a86446e4a9ebee396aa217bef Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Wed, 19 Mar 2025 16:52:57 +1100 Subject: [PATCH 09/13] upto to date ESMF linking --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2974d4a64c..355ca9f74d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,10 @@ find_package(MPI REQUIRED) if(ACCESS3_WW3) find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) find_package(ESMF 8.3.0 MODULE REQUIRED) + # ESMF doesn't come linked to PIO library: + if (NOT TARGET PIO::PIO_C) + find_package(PIO 2.5.3 REQUIRED COMPONENTS C) + endif() endif() if(OPENMP) @@ -122,7 +126,7 @@ set_property(SOURCE ${SRC}/w3initmd.F90 target_link_libraries(ww3lib PUBLIC NetCDF::NetCDF_Fortran) if(ACCESS3_WW3) - target_link_libraries(ww3lib PUBLIC esmf) + target_link_libraries(ww3lib PUBLIC ESMF::ESMF PIO::PIO_C) endif() if(OpenMP_Fortran_FOUND) From 100140817f6e31ed6196e5cdb6460d15f64015da Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 20 Mar 2025 12:14:53 +1100 Subject: [PATCH 10/13] use deps from access3-share where possible --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 355ca9f74d..5fe979e5f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,16 +91,17 @@ set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} # External packages # #]==============================================================================] -find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) find_package(MPI REQUIRED) if(ACCESS3_WW3) find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) - find_package(ESMF 8.3.0 MODULE REQUIRED) - # ESMF doesn't come linked to PIO library: - if (NOT TARGET PIO::PIO_C) - find_package(PIO 2.5.3 REQUIRED COMPONENTS C) - endif() + if(NOT TARGET ESMF::ESMF) #Access3Share probably already has ESMF with PUBLIC interface + find_package(ESMF 8.3.0 MODULE REQUIRED) + endif() +endif() + +if(NOT TARGET NetCDF::NetCDF_Fortran) #Access3Share probably already has NetCDF with PUBLIC interface + find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) endif() if(OPENMP) From 97655811bb003567c0f87b8aecb0489e85a5d446 Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 27 Mar 2025 09:23:47 +1100 Subject: [PATCH 11/13] Update option names --- CMakeLists.txt | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fe979e5f0..ac94820324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,16 +19,16 @@ project(WW3 # to-do: make configurable list(APPEND switches "CESMCOUPLED" "DIST" "MPI" "PR1" "FLX4" "ST6" "STAB0" "LN1" "NL1" "BT1" "DB1" "MLIM" "TR0" "BS0" "RWND" "WNX1" "WNT0" "CRX1" "CRT0" "O0" "O1" "O2" "O3" "O4" "O5" "O6" "O7" "O14" "O15" "IS2" "REF0" "NOGRB" "IC3") -option(ACCESS3_WW3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) -option(OPENMP "Enable OpenMP threading" OFF) -message(STATUS " - ACCESS3_WW3 ${ACCESS3_WW3}") -message(STATUS " - OPENMP ${OPENMP}") +option(WW3_ACCESS3 "Use ACCESS3 dependencies and install ACCESS3 libraries" OFF) +option(WW3_OPENMP "Enable OpenMP threading" OFF) +message(STATUS " - WW3_ACCESS3 ${WW3_ACCESS3}") +message(STATUS " - WW3_OPENMP ${WW3_OPENMP}") -if(NOT ACCESS3_WW3) - message(STATUS " - NOT ACCESS3_WW3: Building standalone ww3_shel for testing") +if(NOT WW3_ACCESS3) + message(STATUS " - NOT WW3_ACCESS3: Building standalone ww3_shel for testing") endif() -if(OPENMP) +if(WW3_OPENMP) list(APPEND switches "OMPG") endif() @@ -93,7 +93,7 @@ set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} find_package(MPI REQUIRED) -if(ACCESS3_WW3) +if(WW3_ACCESS3) find_package(Access3Share REQUIRED cdeps timing share nuopc_cap_share) if(NOT TARGET ESMF::ESMF) #Access3Share probably already has ESMF with PUBLIC interface find_package(ESMF 8.3.0 MODULE REQUIRED) @@ -104,7 +104,7 @@ if(NOT TARGET NetCDF::NetCDF_Fortran) #Access3Share probably already has NetCDF find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) endif() -if(OPENMP) +if(WW3_OPENMP) find_package(OpenMP REQUIRED COMPONENTS Fortran) endif() @@ -126,7 +126,7 @@ set_property(SOURCE ${SRC}/w3initmd.F90 ) target_link_libraries(ww3lib PUBLIC NetCDF::NetCDF_Fortran) -if(ACCESS3_WW3) +if(WW3_ACCESS3) target_link_libraries(ww3lib PUBLIC ESMF::ESMF PIO::PIO_C) endif() @@ -141,7 +141,7 @@ message(VERBOSE "WW3 switch files: ${switch_files}") include(${CMAKE_CURRENT_SOURCE_DIR}/model/src/cmake/src_list.cmake) -if(ACCESS3_WW3) +if(WW3_ACCESS3) list(APPEND ftn_src ${nuopc_mesh_cap_src}) endif() @@ -156,7 +156,7 @@ target_sources(ww3lib PRIVATE ${srcfiles}) ## Utilities # Always build utilities: set(utility_apps ww3_grid ww3_strt ww3_outf ww3_ounf ww3_ounp) -if(NOT ACCESS3_WW3) +if(NOT WW3_ACCESS3) # A generic WW3 "shell" for testing list(APPEND utility_apps ww3_shel) endif() @@ -184,15 +184,15 @@ target_sources(ww3_ounf PRIVATE #]==============================================================================] ## Library -if(ACCESS3_WW3) +if(WW3_ACCESS3) set_target_properties(ww3lib PROPERTIES OUTPUT_NAME access-ww3lib EXPORT_NAME ww3lib ) install(TARGETS ww3lib EXPORT Ww3libTargets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3Cmeps_RunTime NAMELINK_COMPONENT AccessWW3Cmeps_Development - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3Cmeps_Development + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3_RunTime NAMELINK_COMPONENT AccessWW3_Development + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessWW3_Development ) # Fortran module files are a special case, as currently there is no standard # way of handling them in CMake @@ -200,7 +200,7 @@ if(ACCESS3_WW3) get_target_property(ww3_moddir ww3lib Fortran_MODULE_DIRECTORY) install(FILES ${ww3_moddir}/wav_comp_nuopc.mod DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-ww3 - COMPONENT AccessWW3Cmeps_Development + COMPONENT AccessWW3_Development ) install(EXPORT Ww3libTargets FILE Ww3libTargets.cmake @@ -216,7 +216,7 @@ if(ACCESS3_WW3) ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Ww3libConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ww3lib - COMPONENT AccessWW3Cmeps_Development + COMPONENT AccessWW3_Development ) endif() From 1b1851b96c56c78452c8bdba07f0684367690dd4 Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 27 Mar 2025 13:38:24 +1100 Subject: [PATCH 12/13] netcdf min version note --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac94820324..4753b299e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ endif() if(NOT TARGET NetCDF::NetCDF_Fortran) #Access3Share probably already has NetCDF with PUBLIC interface find_package(NetCDF 4.7.3 MODULE REQUIRED Fortran) + # Code has not been tested with versions older than 4.7.3, but probably still works fine endif() if(WW3_OPENMP) From 617c21b0cd2d37c239d1d99a421d6a7e5fc4be9c Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Thu, 27 Mar 2025 14:42:16 +1100 Subject: [PATCH 13/13] This was based on the https://github.com/cOSIMA/access-om3 CMake Co-authored-by: Micael Oliveira