Skip to content

Instantly share code, notes, and snippets.

@angus-g
Created March 2, 2017 23:53
Show Gist options
  • Save angus-g/2f51c35f201c33350a610ee92a11871a to your computer and use it in GitHub Desktop.
Save angus-g/2f51c35f201c33350a610ee92a11871a to your computer and use it in GitHub Desktop.
# we need at least 3.7 to generate Ninja output
# that will deal with the preprocessing to get dependencies
# correct in FMS
cmake_minimum_required(VERSION 3.7)
project(MOM6 C Fortran)
# gfortran configuration
set(CMAKE_Fortran_COMPILER mpifort)
set(CMAKE_Fortran_FLAGS "-fcray-pointer -fdefault-real-8 -fdefault-double-8 -Waliasing -ffree-line-length-none -fno-range-check -O3")
set(CMAKE_C_FLAGS "-O2")
add_definitions(-Duse_libMPI -Duse_netCDF -DSPMD -D__IFC)
# FMS static library
file(GLOB_RECURSE FMS_SOURCE LIST_DIRECTORIES false
../src/FMS/*.[fF]90 ../src/FMS/*.c)
# these two module depend on whether we're coupled or not,
# and will segfault gfortran with -J (Fortran_MODULE_DIRECTORY)
# because the solo_drive defines its own coupler types in a different directory
# which confuses everything
list(FILTER FMS_SOURCE EXCLUDE REGEX "(coupler_types|atmos_ocean_fluxes).F90$")
add_library(FMS ${FMS_SOURCE})
target_include_directories(FMS PRIVATE
/usr/include ../src/FMS/include ../src/FMS/mosaic ../src/FMS/drifters ../src/FMS/fms ../src/FMS/mpp/include)
# common files for both builds
file(GLOB_RECURSE MOM6_SOURCE LIST_DIRECTORIES false FOLLOW_SYMLINKS
../src/MOM6/src/*.[fF]90 ../src/MOM6/src/*.c)
# MOM6 ocean only
file(GLOB_RECURSE MOM6_SOLO_SOURCE LIST_DIRECTORIES false
../src/MOM6/config_src/solo_driver/*.[fF]90)
add_executable(MOM6 ${MOM6_SOURCE} ${MOM6_SOLO_SOURCE})
target_include_directories(MOM6 PRIVATE
/usr/include ../src/MOM6/config_src/dynamic ../src/MOM6/src/framework)
target_link_libraries(MOM6 FMS netcdff netcdf hdf5_hl hdf5 z)
# output modules in separate directory so parallel builds don't clash
# there's a race condition with MOM6 and MOM6-SIS2 otherwise
set_target_properties(MOM6 PROPERTIES Fortran_MODULE_DIRECTORY MOM6-modules)
# MOM6 ice_ocean_SIS2
file(GLOB_RECURSE MOM6_COUPLED_SOURCE LIST_DIRECTORIES false FOLLOW_SYMLINKS
../src/MOM6/config_src/coupled_driver/*.[fF]90 ../src/FMS/coupler/*.[fF]90
../src/atmos_null/*.[fF]90 ../src/coupler/*.[fF]90 ../src/land_null/*.[fF]90
../src/ice_ocean_extras/*.[fF]90 ../src/icebergs/*.[fF]90 ../src/SIS2/*.[fF]90)
add_executable(MOM6-SIS2 ${MOM6_SOURCE} ${MOM6_COUPLED_SOURCE})
target_include_directories(MOM6-SIS2 PRIVATE
/usr/include ../src/MOM6/config_src/dynamic
../src/MOM6/src/framework ../src/FMS/include ../src/SIS2)
target_compile_definitions(MOM6-SIS2 PRIVATE -DUSE_LOG_DIAG_FIELD_INFO -Duse_AM3_physics)
target_link_libraries(MOM6-SIS2 FMS netcdff netcdf hdf5_hl hdf5 z)
set_target_properties(MOM6-SIS2 PROPERTIES Fortran_MODULE_DIRECTORY MOM6-SIS2-modules)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment