1- cmake_minimum_required (VERSION 3.6 )
2- project (MOM5 C Fortran )
1+ # Copyright ACCESS-NRI and contributors. See the top-level LICENSE file for details.
32
4- set ( CMAKE_VERBOSE_MAKEFILE ON )
3+ cmake_minimum_required ( VERSION 3.18 )
54
6- # make sure that the default is RELWITHDEBINFO
7- if (NOT CMAKE_BUILD_TYPE )
8- set (CMAKE_BUILD_TYPE RELWITHDEBINFO CACHE STRING
9- "Choose the type of build, options are: Debug Release Relwithdebinfo."
10- FORCE )
5+ #[==============================================================================[
6+ # Basic project definition #
7+ #]==============================================================================]
8+
9+ project (MOM5
10+ DESCRIPTION "Modular Ocean Model 5"
11+ HOMEPAGE_URL https://github.com/ACCESS-NRI/MOM5
12+ LANGUAGES C Fortran )
13+
14+ #[==============================================================================[
15+ # Options #
16+ #]==============================================================================]
17+
18+ # CMake build type
19+ if (NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo)$" )
20+ message (STATUS "Setting build type to 'RelWithDebInfo' as none was specified." )
21+ set (CMAKE_BUILD_TYPE
22+ "RelWithDebInfo"
23+ CACHE STRING "Choose the type of build." FORCE )
24+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" )
1125endif ()
12- message ("Build type: " ${CMAKE_BUILD_TYPE} )
13-
14- # If your system uses a bespoke MPI compiler wrapper then define this on the
15- # command line using the MPIFORT_EXE and MPICC_EXE environment variables
16- if ((DEFINED ENV{MPIFORT_EXE}) AND (DEFINED ENV{MPICC_EXE}))
17- message ("mpifort executable defined: " $ENV{MPIFORT_EXE} )
18- message ("Will assume system MPI implementation is sound. Remove MPIFORT_EXE from environment to automatically configure MPI" )
19- set (CMAKE_Fortran_COMPILER $ENV{MPIFORT_EXE} )
20- message ("mpicc executable found: " $ENV{MPICC_EXE} )
21- message ("Will assume system MPI implementation is sound. Remove MPICC_EXE from environment to automatically configure MPI" )
22- set (CMAKE_C_COMPILER $ENV{MPICC_EXE} )
23- else ()
24- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND (ENV{FC} STREQUAL "gfortran" AND ENV{CC} STREQUAL "gcc" ))
25- # Use compiler wrappers if FC and CC are default values
26- SET ( CMAKE_Fortran_COMPILER mpif90 )
27- SET ( CMAKE_C_COMPILER mpicc )
28- endif ()
26+
27+ # MOM5 build types
28+ set (MOM5_TYPE "MOM5_SOLO" CACHE STRING "Build type of the model" )
29+
30+ set (ALLOWED_TYPES MOM5_SOLO MOM5_SIS MOM5_ACCESS_CM MOM5_ACCESS_OM MOM5_ACCESS_ESM MOM5_ACCESS_OM_BGC)
31+ if (NOT MOM5_TYPE IN_LIST ALLOWED_TYPES)
32+ message (FATAL_ERROR "${MOM5_TYPE} is not a valid build type. Allowed types are: ${ALLOWED_TYPES} " )
2933endif ()
30- find_package (MPI REQUIRED COMPONENTS Fortran )
34+ message (STATUS "Build type = ${MOM5_TYPE} " )
35+
36+ # Build options
37+ option (MOM5_USE_NETCDF3 "Use netCDF3 rather than netCDF4. Only relevant for MOM5_TYPEs that use internal FMS" OFF )
38+ option (MOM5_DETERMINISTIC "Deterministic build" OFF )
3139
32- message ("Using Fortran: ${MPI_Fortran_COMPILER} ${CMAKE_Fortran_COMPILER} and C: ${MPI_C_COMPILER} ${CMAKE_C_COMPILER} " )
40+ message (STATUS "Build options" )
41+ message (STATUS " - MOM5_USE_NETCDF3 ${MOM5_USE_NETCDF3} " )
42+ message (STATUS " - MOM5_DETERMINISTIC ${MOM5_DETERMINISTIC} " )
3343
34- if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
35- set (CMAKE_Fortran_FLAGS "-fno-alias -stack-temps -safe-cray-ptr -ftz -shared-intel -assume byterecl -i4 -r8 -nowarn -sox -traceback" )
36- set (CMAKE_Fortran_FLAGS_RELEASE "-O2 -fp-model source" )
37- set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g" )
38- set (CMAKE_Fortran_FLAGS_DEBUG "-g -O0 -check -check noarg_temp_created -check nopointer -warn -warn noerrors -fpe0 -ftrapuv" )
44+ #[==============================================================================[
45+ # Project configuration #
46+ #]==============================================================================]
47+
48+ list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} )
49+ include (CheckFortranCompilerFlag )
50+
51+ # Fortran compiler flags
52+ if (CMAKE_Fortran_COMPILER_ID MATCHES "Intel" )
53+ set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -i4 -r8 -nowarn -check noarg_temp_created -assume nobuffered_io -convert big_endian -grecord-gcc-switches -fp-model precise -fp-model source -align all" )
54+ if (MOM5_DETERMINISTIC)
55+ set (CMAKE_Fortran_FLAGS_RELEASE "-g0 -O0 -xCORE-AVX2 -debug none -check none" )
56+ else ()
57+ set (CMAKE_Fortran_FLAGS_RELEASE "-g3 -O2 -xCORE-AVX2 -debug all -check none -traceback" )
58+ endif ()
59+ set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g" )
60+ set (CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv -traceback" )
3961elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
40- include (CheckFortranCompilerFlag )
41- set (CMAKE_Fortran_FLAGS "-fcray-pointer -fdefault-real-8 -fdefault-double-8 -Waliasing -ffree-line-length-none -fno-range-check -fbacktrace" )
62+ 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" )
4263 check_fortran_compiler_flag ("-fallow-invalid-boz" _boz_flag )
4364 check_fortran_compiler_flag ("-fallow-argument-mismatch" _argmis_flag )
4465 if (_boz_flag)
45- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-invalid-boz" )
66+ set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-invalid-boz" )
4667 endif ()
4768 if (_argmis_flag)
48- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch" )
69+ set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch" )
4970 endif ()
50- set (CMAKE_Fortran_FLAGS_RELEASE "-O2 -fbounds-check " )
51- set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g" )
52- set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -W -fbounds-check -ffpe-trap=invalid,zero,overflow " )
71+ set (CMAKE_Fortran_FLAGS_RELEASE "-O2" )
72+ set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g" )
73+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -W -fbounds-check" )
5374else ()
54- message ( "Unknown Fortran compiler default flags only... " )
75+ message ( WARNING " Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options " )
5576endif ()
5677
57- execute_process (COMMAND nf-config --includedir OUTPUT_VARIABLE NETCDF_INCDIR OUTPUT_STRIP_TRAILING_WHITESPACE )
58- execute_process (COMMAND nf-config --flibs OUTPUT_VARIABLE NETCDF_FLIBS OUTPUT_STRIP_TRAILING_WHITESPACE )
59- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -I${NETCDF_INCDIR} " )
60- # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${NETCDF_FLIBS}")
61-
62- message ("Linker flags: ${CMAKE_EXE_LINKER_FLAGS} " )
63-
64- if (CMAKE_C_COMPILER_ID STREQUAL "Intel" )
65- set (CMAKE_C_FLAGS "-sox -traceback" )
66- set (CMAKE_C_FLAGS_DEBUG "-O0 -debug" )
67- set (CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal" )
68- set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g" )
69- add_compile_definitions (__IFC )
78+ # C compiler flags
79+ if (CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM" )
80+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise" )
81+ if (MOM5_DETERMINISTIC)
82+ set (CMAKE_C_FLAGS_RELEASE "-O0 -debug none -xCORE-AVX2" )
83+ else ()
84+ set (CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2" )
85+ endif ()
86+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g" )
87+ set (CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback" )
88+ elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel" )
89+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -fp-model source" )
90+ if (MOM5_DETERMINISTIC)
91+ set (CMAKE_C_FLAGS_RELEASE "-O0 -debug none -xCORE-AVX2" )
92+ else ()
93+ set (CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal -xCORE-AVX2" )
94+ endif ()
95+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g" )
96+ set (CMAKE_C_FLAGS_DEBUG "-O0 -g -ftrapuv -traceback" )
7097elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
71- set (CMAKE_C_FLAGS "-frecord-gcc-switches" )
72- set (CMAKE_C_FLAGS_DEBUG "-O0 -Werror -Wuninitialized -Wno-stringop-overflow" )
73- set (CMAKE_C_FLAGS_RELEASE "-O2" )
74- set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g" )
98+ set (CMAKE_C_FLAGS_RELEASE "-O2" )
99+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g" )
100+ set (CMAKE_C_FLAGS_DEBUG "-O0 -g" )
75101else ()
76- message ( "Unknown C compiler default flags only... " )
102+ message ( WARNING " C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options " )
77103endif ()
78- execute_process (COMMAND nc-config --cflags OUTPUT_VARIABLE NETCDF_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE )
79- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NETCDF_CFLAGS} " )
80-
81- # Transfer command line setting of CPP defs to CMake
82- set (CPPDEFS
83- use_netCDF
84- use_netCDF3
85- use_netCDF4
86- use_libMPI
87- SPMD
88- ENABLE
89- ODA
90- USE_OCEAN_BGC
91- LAND_BND_TRACERS
92- OVERLOAD_C8
93- OVERLOAD_C4
94- OVERLOAD_R4
95- )
96- foreach (VAR ${CPPDEFS} )
97- if (${VAR} )
98- message ("Setting CPP def ${VAR} " )
99- add_compile_definitions (${VAR} )
104+
105+ # Update git hash in version/version.F90
106+ execute_process (COMMAND "${CMAKE_SOURCE_DIR} /../exp/update_version.csh" COMMAND_ERROR_IS_FATAL ANY )
107+
108+ #[==============================================================================[
109+ # External packages #
110+ #]==============================================================================]
111+
112+ find_package (MPI REQUIRED COMPONENTS Fortran )
113+
114+ if (MOM5_TYPE MATCHES "MOM5_ACCESS" )
115+ # External FMS, provides NetCDF interface
116+ find_package (fms COMPONENTS R8 REQUIRED )
117+
118+ if (NOT TARGET NetCDF::NetCDF_Fortran OR NOT TARGET NetCDF::NetCDF_C)
119+ message (FATAL_ERROR "NetCDF interface missing from FMS package" )
100120 endif ()
101- endforeach ()
102121
103- string (TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE )
104- message ("Using Fortran flags: ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${BUILD_TYPE} }" )
122+ find_package (GFDLGTracers REQUIRED )
123+
124+ find_package (PkgConfig REQUIRED )
125+ pkg_check_modules (OASIS3MCT REQUIRED IMPORTED_TARGET "oasis3-mct" )
126+ pkg_check_modules (OASIS3MPEU REQUIRED IMPORTED_TARGET "oasis3-mpeu" )
127+ pkg_check_modules (OASIS3PSMILE REQUIRED IMPORTED_TARGET "oasis3-psmile.MPI1" )
128+ pkg_check_modules (OASIS3SCRIP REQUIRED IMPORTED_TARGET "oasis3-scrip" )
129+ else ()
130+ # Internal FMS, requires NetCDF
131+ find_package (NetCDF 4.7.3 REQUIRED Fortran )
132+ endif ()
133+
134+ if (MOM5_TYPE STREQUAL "MOM5_ACCESS_OM" OR
135+ MOM5_TYPE STREQUAL "MOM5_ACCESS_OM_BGC" )
136+ pkg_check_modules (LIBACCESSOM2 REQUIRED IMPORTED_TARGET "libaccessom2" )
137+ endif ()
105138
106- set (CMAKE_DEBUG_TARGET_PROPERTIES
107- # INCLUDE_DIRECTORIES
108- # COMPILE_DEFINITIONS
109- # POSITION_INDEPENDENT_CODE
110- # CONTAINER_SIZE_REQUIRED
111- # LIB_VERSION
112- )
139+ #[==============================================================================[
140+ # Main definitions #
141+ #]==============================================================================]
113142
114143set (SRC_DIR "${CMAKE_SOURCE_DIR} /../src" )
115144
145+ add_compile_definitions (use_netCDF use_libMPI COSIMA_VERSION __IFC )
146+
147+ if (MOM5_USE_NETCDF3)
148+ add_compile_definitions (use_netCDF3 )
149+ else ()
150+ add_compile_definitions (use_netCDF4 )
151+ endif ()
152+
153+ if (MOM5_TYPE STREQUAL "MOM5_ACCESS_OM" )
154+ set (ACCESS_COMPILE_DEFS ACCESS_OM USE_OCEAN_BGC)
155+ elseif (MOM5_TYPE STREQUAL "MOM5_ACCESS_OM_BGC" )
156+ set (ACCESS_COMPILE_DEFS ACCESS_OM CSIRO_BGC)
157+ elseif (MOM5_TYPE STREQUAL "MOM5_ACCESS_ESM" )
158+ set (ACCESS_COMPILE_DEFS ACCESS_CM USE_OCEAN_BGC)
159+ elseif (MOM5_TYPE STREQUAL "MOM5_ACCESS_CM" )
160+ set (ACCESS_COMPILE_DEFS ACCESS_CM)
161+ else ()
162+ add_compile_definitions (USE_OCEAN_BGC ENABLE_ODA SPMD LAND_BND_TRACERS )
163+ endif ()
164+
116165add_subdirectory (version )
117- add_subdirectory (FMS )
118- add_subdirectory (ocean )
119- add_subdirectory (atmos_bg )
120- add_subdirectory (atmos_ebm )
121- add_subdirectory (atmos_fv )
122- add_subdirectory (atmos_null )
123- add_subdirectory (atmos_phys )
124- add_subdirectory (land_null )
125- add_subdirectory (land_lad )
126- add_subdirectory (land_lad2 )
127- add_subdirectory (ice_sis )
128- add_subdirectory (MOM5_solo )
129- add_subdirectory (MOM5_SIS )
130- add_subdirectory (MOM5_CM2M )
131- add_subdirectory (MOM5_ESM2M )
132- add_subdirectory (MOM5_ICCM )
133- add_subdirectory (MOM5_EBM )
166+
167+ if (MOM5_TYPE STREQUAL "MOM5_SOLO" )
168+ add_subdirectory (fms_mom5 )
169+ add_subdirectory (ocean )
170+ add_subdirectory (mom5_solo )
171+ elseif (MOM5_TYPE STREQUAL "MOM5_SIS" )
172+ add_subdirectory (fms_mom5 )
173+ add_subdirectory (ocean )
174+ add_subdirectory (ice_sis )
175+ add_subdirectory (atmos_null )
176+ add_subdirectory (land_null )
177+ add_subdirectory (mom5_sis )
178+ elseif (MOM5_TYPE STREQUAL "MOM5_ACCESS_OM" OR
179+ MOM5_TYPE STREQUAL "MOM5_ACCESS_OM_BGC" )
180+ add_subdirectory (ocean_access )
181+ add_subdirectory (mom5_access_om )
182+ elseif (MOM5_TYPE STREQUAL "MOM5_ACCESS_ESM" OR
183+ MOM5_TYPE STREQUAL "MOM5_ACCESS_CM" )
184+ add_subdirectory (ocean_access )
185+ add_subdirectory (mom5_access_cm )
186+ endif ()
0 commit comments