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

release/public-v2: add NCEPLIBS umbrella modulefile and shell scripts for SRW App release #148

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "CMakeModules"]
path = CMakeModules
url = https://github.com/NOAA-EMC/CMakeModules
61 changes: 33 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ file(STRINGS "VERSION" pVersion)
project(
NCEPLIBS
VERSION ${pVersion}
LANGUAGES C Fortran)
# CXX isn't actually used, but need CMAKE_CXX_COMPILER in umbrella module
LANGUAGES C CXX Fortran)

include(ExternalProject)
include(GNUInstallDirs)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/Modules/")

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
Expand All @@ -27,13 +30,12 @@ endif()
set(DEFAULT_LIBCOMPS ${CMAKE_CURRENT_SOURCE_DIR}/COMPONENTS)

# User options
option(OPENMP "Enable OpenMP threading" OFF)
option(ENABLE_TESTS "Enable testing" OFF)
option(BUILD_CRTM "Build CRTM library" ON)
option(BUILD_POST "Build NCEPpost library" ON)
option(DEPLOY "Deploy modulefiles" OFF)
option(TCLMOD "Create Tcl modulefiles " OFF)
option(FLAT "Flat install structure" ON)
option(OPENMP "Enable OpenMP threading" OFF)
option(ENABLE_TESTS "Enable testing" OFF)
option(BUILD_CRTM "Build CRTM library" ON)
option(BUILD_POST "Build NCEPpost library" ON)
option(DEPLOY "Deploy modulefiles/shellscripts" ON)
option(FLAT "Flat install structure" ON)
option(LIBCOMPS "File to read components from" ${DEFAULT_LIBCOMPS})
option(DOWNLOAD_ONLY "Just download the components" OFF)
option(USE_LOCAL "Use locally downloaded components" OFF)
Expand All @@ -59,13 +61,9 @@ if(BUILD_POST)
set(BUILD_CRTM ON)
endif()

# Option to overwrite modulefile (if DEPLOY = ON)
# Deploy modulefile if requested
if(DEPLOY)
message(STATUS "Installing NCEPLIBS modulefiles at ${CMAKE_INSTALL_PREFIX}/modules")
option(OVERWRITEMODULES "Overwrite existing modules (if found!)" OFF)
if(OVERWRITEMODULES)
message(STATUS "WARNING: Overwriting NCEPLIBS modulefiles is ON")
endif()
message(STATUS "Installing NCEPLIBS modulefiles at ${CMAKE_INSTALL_PREFIX}/modules, NCEPLIBS shell scripts at ${CMAKE_INSTALL_PREFIX}/bin")
endif()

function(trapLocalError sourceDir)
Expand Down Expand Up @@ -255,23 +253,30 @@ if(DOWNLOAD_ONLY)
add_dependencies(tarball ${_comps})
endif()

# Prepare to deploy modulefiles
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/deploy_modulefiles.sh.in
${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh
@ONLY)
if(DEPLOY)
# Find NetCDF so that NETCDF can be added to the
# umbrella module file and the umbrella shell scripts
find_package(NetCDF REQUIRED COMPONENTS C Fortran)
execute_process(COMMAND ${NetCDF_Fortran_CONFIG_EXECUTABLE} --prefix
OUTPUT_VARIABLE NetCDF_ROOT OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Found NetCDF: ${NetCDF_ROOT}")
# Find ESMF so that ESMFMKFILE can be added to the
# umbrella module file and the umbrella shell scripts
find_package(ESMF REQUIRED)
if (NOT ESMF_FOUND)
message(FATAL_ERROR "ESMF not found, abort")
endif()

add_custom_target(prep2deploy ALL
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh)
# Prepare to deploy
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/deploy_modulefiles.sh.in
${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh
@ONLY)
add_custom_target(prep2deploy ALL
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh)

# Deploy modulefiles (if enabled), but do not add to make all (make user do it)
if(DEPLOY)
# Deploy modulefiles and shell scripts (if enabled), but do not add to make all (make user do it)
add_custom_target(deploy
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/deploy_modulefiles.sh)
add_dependencies(deploy prep2deploy)
if(TCLMOD)
add_custom_target(tcl
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lua2tcl.py ${CMAKE_INSTALL_PREFIX}/modules)
add_dependencies(tcl deploy)
endif()
endif()
1 change: 1 addition & 0 deletions CMakeModules
Submodule CMakeModules added at 186586
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
2.0.0
110 changes: 99 additions & 11 deletions deploy_modulefiles.sh.in
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
set -e

# Defaults to user options will be provided by CMake
modulesDestDir=${1:-"@CMAKE_INSTALL_PREFIX@/modules"}
DOVERWRITEMODULES=${2:-"@OVERWRITEMODULES@"}
modulesDestDir="@CMAKE_INSTALL_PREFIX@/modules"
NCEPLIBS_VERSION="@pVersion@"

# These will be filled by CMake
nceplibsInstallDir=@CMAKE_INSTALL_PREFIX@
tmplModulefilesDir=@CMAKE_CURRENT_SOURCE_DIR@/tmplModulefiles
LIBCOMPS=@LIBCOMPS_FILE@
DFLAT="@FLAT@"

[[ $DOVERWRITEMODULES == "ON" ]] && OVERWRITE="Y" || OVERWRITE="N"
[[ $DFLAT == "ON" ]] && FLAT="Y" || FLAT="N"

# All module load commands for the umbrella module
moduleLoadCommands=""

# All export statements for the umbrella shell scripts
bashScriptContents="#!/bin/bash
echo \"Setting environment variables for ufs-srweather-app/ufs-weather-model\""
tcshScriptContents="#!/bin/tcsh
echo \"Setting environment variables for ufs-srweather-app/ufs-weather-model\""

echo "Begin deploying modules ..."

for libName in $(ls -1 $tmplModulefilesDir); do

# Ensure $libName is indeed a library being installed
# Ensure $libName is indeed a library being installed - this will skip the umbrella module "NCEPLIBS"
isAbsent=$(cat $LIBCOMPS | grep -w $libName | wc -l)
[[ $isAbsent -eq 0 ]] && continue

Expand All @@ -32,28 +40,108 @@ for libName in $(ls -1 $tmplModulefilesDir); do

# Define source and destination modulefile name
# Destination filename must be consistent with CMakeLists.txt
srcModulefile=$tmplModulefilesDir/$libName/$libName.lua
dstModulefile=$modulesDestDir/$libName/$ver.lua
srcModulefile=$tmplModulefilesDir/$libName/$libName
dstModulefile=$modulesDestDir/$libName/$ver

# Create destination directory for the modulefile and copy template to it
mkdir -p $modulesDestDir/$libName
if [[ -f $dstModulefile ]]; then
[[ $OVERWRITE =~ [YyTt] ]] && ( echo "WARNING: $dstModulefile exists, OVERWRITING!"; \rm -f $dstModulefile ) \
|| ( echo "ERROR: $dstModulefile exists, ABORT!"; exit 1 )
fi
\cp $srcModulefile $dstModulefile

[[ $FLAT =~ [YyTt] ]] && prefix=${nceplibsInstallDir} || prefix=${nceplibsInstallDir}/$libName

# Replace #NAME# and #VERSION#
sed -i -e "s/#NAME#/${libName}/g" $dstModulefile
sed -i -e "s/#VERSION#/${ver}/g" $dstModulefile

# sed does not like delimiter (/) to be a part of replacement string
# so do magic
repl=$(echo ${prefix} | sed -e "s#/#\\\/#g")

# Replace #NCEPLIBS_ROOT# from template with $nceplibsInstallDir
sed -i -e "s/#NCEPLIBS_ROOT#/${repl}/g" $dstModulefile

# Workaround for macOS: remove files created because of differing sed syntax
rm -f ${dstModulefile}-e

# Add to module load commands for umbrella module
moduleLoadCommands="${moduleLoadCommands}
module load $libName/$ver"

# Add to export statements for umbrella shell scripts
bashScriptContents="${bashScriptContents}
export ${libName}_ROOT=\"${prefix}\""
tcshScriptContents="${tcshScriptContents}
setenv ${libName}_ROOT \"${prefix}\""

done

# Create NCEPLIBS umbrella module file
srcModulefile=$tmplModulefilesDir/NCEPLIBS/NCEPLIBS
dstModulefile=$modulesDestDir/NCEPLIBS/${NCEPLIBS_VERSION}
mkdir -p $modulesDestDir/NCEPLIBS
\cp $srcModulefile $dstModulefile

# Replace #NAME# and #VERSION#
sed -i -e "s/#NAME#/NCEPLIBS/g" $dstModulefile
sed -i -e "s/#VERSION#/${NCEPLIBS_VERSION}/g" $dstModulefile

# sed does not like delimiter (/) to be a part of replacement string
repl=$(echo ${nceplibsInstallDir} | sed -e "s#/#\\\/#g")

# Replace #NCEPLIBS_ROOT# from template with $nceplibsInstallDir
sed -i -e "s/#NCEPLIBS_ROOT#/${repl}/g" $dstModulefile

# Set compiler environment variables for the umbrella modulefile
repl=$(echo "@CMAKE_C_COMPILER@" | sed -e "s#/#\\\/#g")
sed -i -e "s/#CC#/${repl}/g" $dstModulefile
repl=$(echo "@CMAKE_CXX_COMPILER@" | sed -e "s#/#\\\/#g")
sed -i -e "s/#CXX#/${repl}/g" $dstModulefile
repl=$(echo "@CMAKE_Fortran_COMPILER@" | sed -e "s#/#\\\/#g")
sed -i -e "s/#FC#/${repl}/g" $dstModulefile
repl=$(echo "@NetCDF_ROOT@" | sed -e "s#/#\\\/#g")
sed -i -e "s/#NETCDF#/${repl}/g" $dstModulefile
repl=$(echo "@ESMFMKFILE@" | sed -e "s#/#\\\/#g")
sed -i -e "s/#ESMFMKFILE#/${repl}/g" $dstModulefile

# Append all module load commands to umbrella module
echo "${moduleLoadCommands}" >> $dstModulefile

# Workaround for macOS: remove files created because of differing sed syntax
rm -f ${dstModulefile}-e

echo "Done deploying modules ..."

echo "Generating shell scripts ..."

bashScript="@CMAKE_INSTALL_PREFIX@/bin/setenv_nceplibs.sh"
tcshScript="@CMAKE_INSTALL_PREFIX@/bin/setenv_nceplibs.csh"

# Set compiler environment variables for the shell scripts
bashScriptContents="${bashScriptContents}
export CC=\"@CMAKE_C_COMPILER@\"
export CXX=\"@CMAKE_CXX_COMPILER@\"
export FC=\"@CMAKE_Fortran_COMPILER@\"
export PATH=\"@CMAKE_PREFIX_PATH@:\${PATH}\"
export CMAKE_PREFIX_PATH=\"@CMAKE_PREFIX_PATH@\${CMAKE_PREFIX_PATH:+:\$CMAKE_PREFIX_PATH}\"
export NETCDF=\"@NetCDF_ROOT@\"
export ESMFMKFILE=\"@ESMFMKFILE@\""
tcshScriptContents="${tcshScriptContents}
setenv CC \"@CMAKE_C_COMPILER@\"
setenv CXX \"@CMAKE_CXX_COMPILER@\"
setenv FC \"@CMAKE_Fortran_COMPILER@\"
setenv PATH \"@CMAKE_PREFIX_PATH@:\${PATH}\"
if (! \$?CMAKE_PREFIX_PATH) then
setenv CMAKE_PREFIX_PATH \"@CMAKE_PREFIX_PATH@\"
else
setenv CMAKE_PREFIX_PATH \"@CMAKE_PREFIX_PATH@:\${CMAKE_PREFIX_PATH}\"
endif
setenv NETCDF \"@NetCDF_ROOT@\"
setenv ESMFMKFILE \"@ESMFMKFILE@\""

echo "${bashScript}"
echo "${bashScriptContents}" > $bashScript
echo "${tcshScript}"
echo "${tcshScriptContents}" > $tcshScript

echo "Done generating shell scripts ..."

exit 0
71 changes: 0 additions & 71 deletions lua2tcl.py

This file was deleted.

23 changes: 23 additions & 0 deletions tmplModulefiles/NCEPLIBS/NCEPLIBS
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#%Module######################################################################

proc ModulesHelp { } {
puts "Set environment variables for #NAME#-#VERSION#"
}

# Make sure another version of the same package is not already loaded
conflict #NAME#

setenv #NAME#_ROOT "#NCEPLIBS_ROOT#"
setenv #NAME#_VERSION "#VERSION#"

prepend-path CMAKE_PREFIX_PATH "#NCEPLIBS_ROOT#"
prepend-path PATH "#NCEPLIBS_ROOT#/bin"

setenv CC "#CC#"
setenv CXX "#CXX#"
setenv FC "#FC#"

setenv NETCDF "#NETCDF#"
setenv ESMFMKFILE "#ESMFMKFILE#"

# Module load commands
19 changes: 19 additions & 0 deletions tmplModulefiles/bacio/bacio
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#%Module######################################################################

proc ModulesHelp { } {
puts "Set environment variables for #NAME#-#VERSION#"
}

# Make sure another version of the same package is not already loaded
conflict #NAME#

# Set environment variables
set base "#NCEPLIBS_ROOT#/#NAME#-#VERSION#"

setenv #NAME#_ROOT "${base}"
setenv #NAME#_VERSION "#VERSION#"

setenv BACIO_INC4 "${base}/include_4"
setenv BACIO_INC8 "${base}/include_8"
setenv BACIO_LIB4 "${base}/lib/libbacio_4.a"
setenv BACIO_LIB8 "${base}/lib/libbacio_8.a"
17 changes: 0 additions & 17 deletions tmplModulefiles/bacio/bacio.lua

This file was deleted.

Loading