diff --git a/CMakeLists.txt b/CMakeLists.txt index 702cf6a459..2d962d0417 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,7 +377,12 @@ target_link_libraries(ufs PUBLIC "${_ufs_libs_public}") add_executable(ufs_model driver/UFS.F90) add_dependencies(ufs_model ufs) target_link_libraries(ufs_model ufs esmf w3emc::w3emc_d) -set_target_properties(ufs_model PROPERTIES LINKER_LANGUAGE Fortran) + +if(CMAKE_Platform MATCHES "macosx.gnu") + set_target_properties(ufs_model PROPERTIES LINKER_LANGUAGE CXX) +else() + set_target_properties(ufs_model PROPERTIES LINKER_LANGUAGE Fortran) +endif() ############################################################################### ### Install diff --git a/modulefiles/ufs_macosx.gnu b/modulefiles/ufs_macosx.gnu deleted file mode 100644 index 961d673b67..0000000000 --- a/modulefiles/ufs_macosx.gnu +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -#%Module###################################################################### -## -## UFS prerequisites: macOS with gcc/gfortran or clang/gfortran compilers - -echo "Setting environment variables for UFS Model on macOS with gcc/gfortran or clang/gfortran" - -## -## load programming environment: compiler, flags, paths -## -export CC=${MPICC:-mpicc} -export CXX=${MPICXX:-mpicxx} -export F77=${MPIF77:-mpif77} -export F90=${MPIF90:-mpif90} -export FC=${MPIFORT:-mpifort} -export CPP=${CPP:-"${F90} -E -x f95-cpp-input"} -export MPICC=${MPICC:-mpicc} -export MPIF90=${MPIF90:-mpif90} - -## -## load cmake -## -export CMAKE_Platform=macosx.gnu diff --git a/modulefiles/ufs_macosx.gnu.lua b/modulefiles/ufs_macosx.gnu.lua new file mode 100644 index 0000000000..62a39b0a9c --- /dev/null +++ b/modulefiles/ufs_macosx.gnu.lua @@ -0,0 +1,65 @@ +help([[ +loads UFS Model prerequisites for MacOS clang/gcc ("gnu") +]]) + +prepend_path("MODULEPATH", "/Users/username/spack-stack/spack-stack-1.8.0/envs/ufs-srw-env/install/modulefiles/Core") + +stack_gnu_ver=os.getenv("stack_apple_clang_ver") or "15.0.0" +load(pathJoin("stack-apple-clang", stack_gnu_ver)) + +stack_openmpi_ver=os.getenv("stack_openmpi_ver") or "5.0.3" +load(pathJoin("stack-openmpi", stack_openmpi_ver)) + +cmake_ver=os.getenv("cmake_ver") or "3.27.9" +load(pathJoin("cmake", cmake_ver)) + +local ufs_modules = { + {["jasper"] = "2.0.32"}, + {["zlib"] = "1.2.13"}, + {["libpng"] = "1.6.37"}, + {["hdf5"] = "1.14.0"}, + {["netcdf-c"] = "4.9.2"}, + {["netcdf-fortran"] = "4.6.1"}, + {["parallelio"] = "2.6.2"}, + {["esmf"] = "8.6.0"}, + {["fms"] = "2024.02"}, + {["bacio"] = "2.4.1"}, + {["crtm"] = "2.4.0.1"}, + {["g2"] = "3.5.1"}, + {["g2tmpl"] = "1.13.0"}, + {["ip"] = "5.0.0"}, + {["sp"] = "2.5.0"}, + {["w3emc"] = "2.10.0"}, + {["gftl-shared"] = "1.9.0"}, + {["mapl"] = "2.40.3-esmf-8.6.0"}, + {["scotch"] = "7.0.4"}, +} + +for i = 1, #ufs_modules do + for name, default_version in pairs(ufs_modules[i]) do + local env_version_name = string.gsub(name, "-", "_") .. "_ver" + load(pathJoin(name, os.getenv(env_version_name) or default_version)) + end +end + +nccmp_ver=os.getenv("nccmp_ver") or "1.9.0.1" +load(pathJoin("nccmp", nccmp_ver)) + +setenv("CC", "mpicc") +setenv("CXX", "mpicxx") +setenv("FC", "mpifort") +setenv("CMAKE_Platform", "macosx.gnu") +setenv("CMAKE_Fortran_COMPILER_ID", "GNU") + +osx_sysroot=os.getenv("OSX_SYSROOT") +setenv("CMAKE_OSX_SYSROOT","OSX_SYSROOT") + +setenv("CFLAGS"," -Wno-implicit-function-declaration ") + +if mode() == "load" then + LmodMsgRaw([===[ + Please export these env. variables after the module is successfully loaded: + > export LDFLAGS+=" -L${libjpeg_turbo_ROOT}/lib -ljpeg -Wl,-rpath,$libjpeg_turbo_ROOT}/lib -L${jasper_ROOT}/lib -ljasper -Wl,-rpath,${jasper_ROOT}/lib -L${libpng_ROOT}/lib -lpng -Wl,-rpath,${libpng_ROOT}/lib " + ]===]) +end +whatis("Description: UFS build environment")