Skip to content

Commit

Permalink
Update model level build system to work with UFS Coastal (#122)
Browse files Browse the repository at this point in the history
* extra work to make it run under UFS

* add target to idry_e to use in the cap

* enable utilities

* fix pre processing build
  • Loading branch information
uturuncoglu authored Feb 6, 2024
1 parent 5d92ec6 commit c5cd940
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 177 deletions.
116 changes: 57 additions & 59 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ define_opt(USE_GEN "Enable generic tracer module" OFF)
define_opt(USE_AGE "Enable age tracer module" OFF)
define_opt(ICM_PH "Enable pH module in ICM" OFF)
define_opt(USE_DVD "Enable DVD module" OFF)


define_opt(BLD_STANDALONE "Standalone build mode" ON)

if(NOT DEFINED TVD_LIM)
message(WARNING "TVD_LIM must be provided, either in the cache. It must be one of SB, VL, MM or OS for Superbee, Van Leer, Minmod, or Osher. Default is VL")
Expand Down Expand Up @@ -120,39 +119,41 @@ endif (CMAKE_C_FLAGS)
include_directories(${MPI_C_INCLUDE_PATH})

########### NetCDF Dependency is handled here because so many libraries use it ##############
message(STATUS "\n### Configuring NetCDF ")
#set(NetCDF_DIR "/usr/local/dms/pkg/netcdf/4.1.3-intel12.0-parallel")
if( NOT DEFINED NetCDF_DIR AND DEFINED NETCDF_DIR)
message(WARNING "Note the mixed case of NetCDF_DIR if you put it in your cache. This CMake variable is mixed case, different from the typical environment NETCDF_DIR. Proceeding anyway.")
set(NetCDF_C_DIR ${NETCDF_C_DIR})
endif()

if( NOT DEFINED NetCDF_C_DIR AND ($ENV{NETCDF_C_DIR} MATCHES ".+") )
message(STATUS "Using NETCDF_C_DIR location from environment.")
set(NetCDF_C_DIR $ENV{NETCDF_C_DIR})
endif()

if( NOT DEFINED NetCDF_FORTRAN_DIR AND ($ENV{NETCDF_FORTRAN_DIR} MATCHES ".+") )
message(STATUS "Using NETCDF_FORTRAN_DIR location from environment.")
set(NetCDF_FORTRAN_DIR $ENV{NETCDF_FORTRAN_DIR})
if (BLD_STANDALONE)
message(STATUS "\n### Configuring NetCDF ")
#set(NetCDF_DIR "/usr/local/dms/pkg/netcdf/4.1.3-intel12.0-parallel")
if( NOT DEFINED NetCDF_DIR AND DEFINED NETCDF_DIR)
message(WARNING "Note the mixed case of NetCDF_DIR if you put it in your cache. This CMake variable is mixed case, different from the typical environment NETCDF_DIR. Proceeding anyway.")
set(NetCDF_C_DIR ${NETCDF_C_DIR})
endif()

if( NOT DEFINED NetCDF_C_DIR AND ($ENV{NETCDF_C_DIR} MATCHES ".+") )
message(STATUS "Using NETCDF_C_DIR location from environment.")
set(NetCDF_C_DIR $ENV{NETCDF_C_DIR})
endif()

if( NOT DEFINED NetCDF_FORTRAN_DIR AND ($ENV{NETCDF_FORTRAN_DIR} MATCHES ".+") )
message(STATUS "Using NETCDF_FORTRAN_DIR location from environment.")
set(NetCDF_FORTRAN_DIR $ENV{NETCDF_FORTRAN_DIR})
endif()

find_package(NetCDF REQUIRED COMPONENTS ${comp_lang_list})
if(NetCDF_NEEDS_HDF5)
set( HDF5_USE_STATIC_LIBRARIES 1 )
find_package(HDF5 COMPONENTS C REQUIRED)
# link_directories is bad cmake form, and was used because I would have had to add a lot to 2.6 to get the magic
# these next couple lines can be removed if we uniformly require cmake 2.8
set( HDF_LIB_NAMES "hdf5_hl;hdf5;z" )
link_directories( ${HDF5_LIBRARY_DIRS} )
if(HDF5_FOUND)
message(STATUS "HDF5 found")
endif(HDF5_FOUND)
endif(NetCDF_NEEDS_HDF5)
include_directories( ${NetCDF_INCLUDE_DIRS} )

set (NetCDFLIBS ${NetCDF_LIBRARIES} ${HDF_LIB_NAMES})
endif()

find_package(NetCDF REQUIRED COMPONENTS ${comp_lang_list})
if(NetCDF_NEEDS_HDF5)
set( HDF5_USE_STATIC_LIBRARIES 1 )
find_package(HDF5 COMPONENTS C REQUIRED)
# link_directories is bad cmake form, and was used because I would have had to add a lot to 2.6 to get the magic
# these next couple lines can be removed if we uniformly require cmake 2.8
set( HDF_LIB_NAMES "hdf5_hl;hdf5;z" )
link_directories( ${HDF5_LIBRARY_DIRS} )
if(HDF5_FOUND)
message(STATUS "HDF5 found")
endif(HDF5_FOUND)
endif(NetCDF_NEEDS_HDF5)
include_directories( ${NetCDF_INCLUDE_DIRS} )

set (NetCDFLIBS ${NetCDF_LIBRARIES} ${HDF_LIB_NAMES})

# this might help to use old or pre-compiled GOTM versions:
#if (USE_GOTM)
# if (NOT DEFINED GOTM_DIR)
Expand All @@ -171,25 +172,23 @@ set (NetCDFLIBS ${NetCDF_LIBRARIES} ${HDF_LIB_NAMES})

########### Put each type of output (exe, libraries, modules) in the normal places
### This file is untested for compilers with no output module directory option
message(STATUS "\n### Assigning output directories for binaries (bin), modules (include) and libraries (lib)")
if( CMAKE_Fortran_MODDIR_FLAG)
if (BLD_STANDALONE)
message(STATUS "\n### Assigning output directories for binaries (bin), modules (include) and libraries (lib)")
if( CMAKE_Fortran_MODDIR_FLAG)
SET( CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include
CACHE PATH "Output location for include files and fortran modules")
include_directories("${CMAKE_Fortran_MODULE_DIRECTORY}")
endif(CMAKE_Fortran_MODDIR_FLAG)

set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
CACHE PATH "Output Directory for executables."
)
include_directories("${CMAKE_Fortran_MODULE_DIRECTORY}")
endif(CMAKE_Fortran_MODDIR_FLAG)

set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
CACHE PATH "Output Directory for all static libraries."
)
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
CACHE PATH "Output Directory for executables.")

set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
CACHE PATH "Output Directory for all shared libraries."
)
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
CACHE PATH "Output Directory for all static libraries.")

set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
CACHE PATH "Output Directory for all shared libraries.")
endif()

########### Process libraries ######
message(STATUS "\n### Adding enabled libraries to project") ######
Expand Down Expand Up @@ -344,19 +343,18 @@ endif(GOTM_BASE)
endif(USE_GOTM)

######## Main executable #######
message(STATUS "\n### Configuring Driver")
add_subdirectory( Driver )

get_property(all_define_options GLOBAL PROPERTY DEFINE-LIST)
message(STATUS "All defines: ${all_define_options}")
# Now that the list of global options are accumulated, apply it on all the directories
foreach (moddir ${schismmoddirs} "Driver")
set_property( DIRECTORY ${moddir} APPEND PROPERTY COMPILE_DEFINITIONS ${all_define_options} ${all_use_mod_defs})
endforeach()


if (BLD_STANDALONE)
message(STATUS "\n### Configuring Driver")
add_subdirectory( Driver )

get_property(all_define_options GLOBAL PROPERTY DEFINE-LIST)
message(STATUS "All defines: ${all_define_options}")
# Now that the list of global options are accumulated, apply it on all the directories
foreach (moddir ${schismmoddirs} "Driver")
set_property( DIRECTORY ${moddir} APPEND PROPERTY COMPILE_DEFINITIONS ${all_define_options} ${all_use_mod_defs})
endforeach()
endif()

######## Utilities ########
message(STATUS "\n### Configuring Utilities")
add_subdirectory( Utility )

26 changes: 9 additions & 17 deletions src/Utility/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@

add_custom_target(utility)
add_subdirectory( UtilLib)
add_subdirectory( Combining_Scripts )
add_subdirectory( Post-Processing-Fortran )
add_subdirectory( Pre-Processing )
add_subdirectory( Tides )
add_subdirectory( OneWayNestScripts )
add_subdirectory( Particle_Tracking )
add_subdirectory( Gen_Hotstart )
add_subdirectory( Grid_Scripts)

add_dependencies(utility utillib)


# Currently a link problem with NCOM
# add_subdirectory( NCOM )

#add_subdirectory( ArcGIS )
add_subdirectory(UtilLib)
add_subdirectory(Combining_Scripts)
add_subdirectory(Post-Processing-Fortran)
add_subdirectory(Pre-Processing)
add_subdirectory(Tides)
add_subdirectory(OneWayNestScripts)
add_subdirectory(Particle_Tracking)
add_subdirectory(Gen_Hotstart)
add_subdirectory(Grid_Scripts)
19 changes: 10 additions & 9 deletions src/Utility/Combining_Scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
message(STATUS "In /Utility NetCDF_LIBS ${NetCDFLIBS}")
add_definitions(${C_PREPROCESS_FLAG})
add_executable( combine_gr3 combine_gr3.f90 )
#add_executable( combine_outHA combine_outHA.f90 )
add_executable( combine_hotstart7 combine_hotstart7.f90 )
##add_executable( combine_output10 combine_output10.f90 netcdf_var_names.f90)
add_executable( combine_output11 combine_output11.f90 netcdf_var_names.f90)

target_link_libraries (combine_hotstart7 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
##target_link_libraries (combine_output10 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (combine_output11 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
add_executable(combine_gr3 combine_gr3.f90)
add_executable(combine_hotstart7 combine_hotstart7.f90)
add_executable(combine_output11 combine_output11.f90 netcdf_var_names.f90)

target_link_libraries(combine_hotstart7 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries(combine_output11 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})

add_dependencies(utility combine_gr3 combine_hotstart7 combine_output11)
target_include_directories(combine_hotstart7 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
target_include_directories(combine_output11 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)

add_dependencies(combine_gr3 utillib)
add_dependencies(combine_hotstart7 utillib)
add_dependencies(combine_output11 utillib)
30 changes: 14 additions & 16 deletions src/Utility/Gen_Hotstart/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
message(STATUS "In Utility/Gen_Hotstart")

add_executable( convert_hotstart_nc convert_hotstart_nc.f90 )
# set list of files
set(gen_hotstart_file_list
convert_hotstart_nc.f90
gen_hot_3Dth_from_hycom.f90
gen_hot_from_hycom.f90
gen_3Dth_from_hycom.f90)

# Removed from cmake because it contains huge arrays and kind of forces mcmodel=medium and doesn't
# necessarily compile gracefully even with that. Below are some flags to add these things on a
# file specific basis, but that isn't working yet.
add_executable( gen_hot_3Dth_from_hycom gen_hot_3Dth_from_hycom.f90)
add_executable( gen_hot_from_hycom gen_hot_from_hycom.f90)
add_executable( gen_3Dth_from_hycom gen_3Dth_from_hycom.f90)
# target_compile_options(gen_hot_3Dth_from_hycom PRIVATE "-O2 -CB -mcmodel=medium")
# target_link_options(gen_hot_3Dth_from_hycom PRIVATE "-mcmodel=medium -CB")

target_link_libraries (convert_hotstart_nc utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (gen_hot_3Dth_from_hycom utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (gen_hot_from_hycom utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (gen_3Dth_from_hycom utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )

add_dependencies(utility convert_hotstart_nc gen_hot_3Dth_from_hycom gen_hot_from_hycom gen_3Dth_from_hycom)
# define executables and their dependencies
foreach(f ${gen_hotstart_file_list})
get_filename_component(fwe ${f} NAME_WE)
add_executable(${fwe} ${f})
target_include_directories(${fwe} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
target_link_libraries(${fwe} utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
add_dependencies(${fwe} utillib)
endforeach()
29 changes: 14 additions & 15 deletions src/Utility/Grid_Scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
message(STATUS "In Utility/Grid_Scripts")

add_executable( cpp_bp cpp_bp.f90)
add_executable( cpp cpp.f90)
add_executable( arctic_stereo arctic_stereo.f90)
add_executable( grid_spring grid_spring.f90)
add_executable( grid_subsampler grid_subsampler.f)
add_executable( interpolate_depth_structured2 interpolate_depth_structured2.f90)
add_executable( interpolate_unstructured interpolate_unstructured.f90)
add_executable( periodic_grid periodic_grid.f90)
add_executable( gen_boundary_global gen_boundary_global.f90)
add_executable( check_lonlat_grid check_lonlat_grid.f90)
add_executable( mergegrid5 mergegrid5.f90)

target_link_libraries (mergegrid5 utillib)
#mpi_wrap( combine_output6 combine_output5 combine_output4 )
#add_dependencies(utility cpp_bp cpp grid_spring grid_subsampler interpolate_unstructured periodic_grid gen_boundary_global check_lonlat_grid mergegrid5)
add_executable(cpp_bp cpp_bp.f90)
add_executable(cpp cpp.f90)
add_executable(arctic_stereo arctic_stereo.f90)
add_executable(grid_spring grid_spring.f90)
add_executable(grid_subsampler grid_subsampler.f)
add_executable(interpolate_depth_structured2 interpolate_depth_structured2.f90)
add_executable(interpolate_unstructured interpolate_unstructured.f90)
add_executable(periodic_grid periodic_grid.f90)
add_executable(gen_boundary_global gen_boundary_global.f90)
add_executable(check_lonlat_grid check_lonlat_grid.f90)
add_executable(mergegrid5 mergegrid5.f90)

target_link_libraries(mergegrid5 utillib)
target_include_directories(mergegrid5 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
add_dependencies(mergegrid5 utillib)
18 changes: 11 additions & 7 deletions src/Utility/OneWayNestScripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

add_executable(interpolate_variables7 interpolate_variables7.f90 )
add_executable(interpolate_variables7 interpolate_variables7.f90)
add_executable(timeint_3Dth2 timeint_3Dth2.f90)
add_executable(interpolate_variables8 interpolate_variables8.f90)

add_dependencies(interpolate_variables7 utillib)
add_dependencies(timeint_3Dth2 utillib)
add_dependencies(interpolate_variables8 utillib)

target_link_libraries(interpolate_variables8 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_include_directories(interpolate_variables8 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)

add_dependencies(utility interpolate_variables7 timeint_3Dth2)
target_link_libraries(interpolate_variables7 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries(interpolate_variables7 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_include_directories(interpolate_variables7 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)

add_executable(interpolate_variables8 interpolate_variables8.f90 )
add_dependencies(utility interpolate_variables8 timeint_3Dth2)
target_link_libraries(interpolate_variables8 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
4 changes: 2 additions & 2 deletions src/Utility/Particle_Tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ add_executable(ptrack4 ptrack4.f90)

add_dependencies(utility ptrack3 ptrack4)
target_link_libraries(ptrack3 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_include_directories(ptrack3 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
target_link_libraries(ptrack4 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})


target_include_directories(ptrack4 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
56 changes: 24 additions & 32 deletions src/Utility/Post-Processing-Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@

add_definitions(${C_PREPROCESS_FLAG})
add_executable( compute_alongchannel_vel compute_alongchannel_vel.f90)
add_executable( compute_average3 compute_average3.f90)
add_executable( compute_fluxes_ns compute_fluxes_ns.f90)
add_executable( extract_subregion2 extract_subregion2.f90)
add_executable( read_output8_allnodes read_output8_allnodes.f90)
add_executable( read_output9_transect read_output9_transect.f90)
add_executable( read_output9_xyt read_output9_xyt.f90)
add_executable( read_output9_xyz read_output9_xyz.f90)
add_executable( read_output9_xyzt read_output9_xyzt.f90)
add_executable( read_output10_allnodes read_output10_allnodes.f90)
add_executable( read_output10_xyz read_output10_xyz.f90)
add_executable( read_output10_transect read_output10_transect.f90)
add_executable( read_output10_xyt read_output10_xyt.f90)
add_executable( read_output10_xyzt read_output10_xyzt.f90)


target_link_libraries (compute_alongchannel_vel utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (compute_average3 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES} )
target_link_libraries (compute_fluxes_ns utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (extract_subregion2 utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output8_allnodes utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output9_transect utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output9_xyt utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output9_xyz utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output9_xyzt utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output10_allnodes utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output10_xyz utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output10_xyt utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output10_xyzt utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_link_libraries (read_output10_transect utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})

add_dependencies(utility compute_alongchannel_vel compute_average3 compute_fluxes_ns extract_subregion2 read_output8_allnodes read_output9_transect read_output9_xyt read_output9_xyz read_output9_xyzt read_output10_xyz)
# set list of files
set(post_processing_files
compute_alongchannel_vel.f90
compute_average3.f90
compute_fluxes_ns.f90
extract_subregion2.f90
read_output8_allnodes.f90
read_output9_transect.f90
read_output9_xyt.f90
read_output9_xyz.f90
read_output9_xyzt.f90
read_output10_allnodes.f90
read_output10_xyz.f90
read_output10_transect.f90
read_output10_xyt.f90
read_output10_xyzt.f90)

# define executables, their dependencies and libraries that will be used in linking
foreach(f ${post_processing_files})
get_filename_component(fwe ${f} NAME_WE)
add_executable(${fwe} ${f})
target_link_libraries(${fwe} utillib ${NetCDFLIBS} ${HDF5_LIBRARIES})
target_include_directories(${fwe} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../UtilLib)
add_dependencies(${fwe} utillib)
endforeach()
Loading

0 comments on commit c5cd940

Please sign in to comment.