Skip to content

Commit

Permalink
Reduce hardcoded cmake logic linking ATS
Browse files Browse the repository at this point in the history
Many of the cmake steps to link ATS were hardcoded in
cime_config. Much of this has been removed now that
these have been moved to find_package(*) in
components/cime/build_model.cmake.
  • Loading branch information
rfiorella committed Dec 24, 2024
1 parent 05e5684 commit 1affbf1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 52 deletions.
32 changes: 6 additions & 26 deletions cime_config/machines/cmake_macros/universal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,13 @@ set(CMAKE_CXX_FLAGS_RELEASE "")
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "")

# ATS libraries, previously in userdefined.cmake, but which excluded in cime now.
# RPF/WIP - much of the hardcoded cmake for linking ATS libraries
# has been moved to components/cmake/build_model.cmake, but a few things remain.
set(AMANZI_TPLS_DIR "$ENV{AMANZI_TPLS_DIR}")
set(ATS_DIR "$ENV{ATS_DIR}")
if (COMP_NAME STREQUAL elm)
if (NOT ${AMANZI_TPLS_DIR} STREQUAL "")

string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/trilinos-15-1-0/include")
string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/SEACAS/include ")
string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/petsc-3.20/include -I${AMANZI_TPLS_DIR}/pflotran/src ")
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CPPDEFS " -DUSE_ATS_LIB ")
string(APPEND CMAKE_Fortran_FLAGS " -I${ATS_DIR}/include ")
endif()
endif()
endif()
if (COMP_NAME STREQUAL cpl)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -lstdc++")
if (NOT ${AMANZI_TPLS_DIR} STREQUAL "")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/lib")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/trilinos-15-1-0/lib")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/SEACAS/lib ")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/petsc-3.20/lib -L${AMANZI_TPLS_DIR}/pflotran/src ")
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${ATS_DIR}/lib -lerror_handling -latk -lfunctions -lgeometry -lgeochemutil -lgeochemsolvers -lgeochembase -lgeochemrxns -lgeochemistry -lmesh -lmesh_simple -lmesh_mstk -lmesh_extracted -lmesh_logical -lmesh_factory -ldbg -lwhetstone -ldata_structures -lmesh_functions -loutput -lstate -lsolvers -ltime_integration -loperators -lpks -lchemistry_pk -ltransport -lshallow_water -lats_operators -lats_eos -lats_surf_subsurf -lats_generic_evals -lats_column_integrator -lats_pks -lats_energy_relations -lats_energy -lats_flow_relations -lats_flow -lats_transport -lats_deform -lats_surface_balance -lats_bgc -lats_mpc_relations -lats_mpc -lats_executable -lelm_ats")
endif()
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CPPDEFS " -DUSE_ATS_LIB ")
string(APPEND CMAKE_Fortran_FLAGS " -I${ATS_DIR}/include ")
endif()
endif()


string(APPEND CPPDEFS " -DCPL_BYPASS")
endif()
27 changes: 3 additions & 24 deletions cime_config/machines/cmake_macros/userdefined.cmake
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
string(APPEND CONFIG_ARGS " ")
string(APPEND CPPDEFS " ")

# cime/CIME/case_setup.py Now doesn't include userdefined.cmake anymore
# so the following won't work. Move it to universal.cmake temporarily.

set(AMANZI_TPLS_DIR "$ENV{AMANZI_TPLS_DIR}")
set(ATS_DIR "$ENV{ATS_DIR}")
if (COMP_NAME STREQUAL elm)
if (NOT ${AMANZI_TPLS_DIR} STREQUAL "")

string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/trilinos-15-1-0/include")
string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/SEACAS/include ")
string(APPEND CMAKE_Fortran_FLAGS " -I${AMANZI_TPLS_DIR}/petsc-3.20/include -I${AMANZI_TPLS_DIR}/pflotran/src ")
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CPPDEFS " -DUSE_ATS_LIB ")
string(APPEND CMAKE_Fortran_FLAGS " -I${ATS_DIR}/include ")
endif()
endif()
endif()
if (COMP_NAME STREQUAL cpl)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -lstdc++")
if (NOT ${AMANZI_TPLS_DIR} STREQUAL "")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/lib")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/trilinos-15-1-0/lib")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/SEACAS/lib ")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${AMANZI_TPLS_DIR}/petsc-3.20/lib -L${AMANZI_TPLS_DIR}/pflotran/src ")
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${ATS_DIR}/lib -lerror_handling -latk -lfunctions -lgeometry -lgeochemutil -lgeochemsolvers -lgeochembase -lgeochemrxns -lgeochemistry -lmesh -lmesh_simple -lmesh_mstk -lmesh_extracted -lmesh_logical -lmesh_factory -ldbg -lwhetstone -ldata_structures -lmesh_functions -loutput -lstate -lsolvers -ltime_integration -loperators -lpks -lchemistry_pk -ltransport -lshallow_water -lats_operators -lats_eos -lats_surf_subsurf -lats_generic_evals -lats_column_integrator -lats_pks -lats_energy_relations -lats_energy -lats_flow_relations -lats_flow -lats_transport -lats_deform -lats_surface_balance -lats_bgc -lats_mpc_relations -lats_mpc -lats_executable -lelm_ats")
endif()
if (NOT ${ATS_DIR} STREQUAL "")
string(APPEND CPPDEFS " -DUSE_ATS_LIB ")
string(APPEND CMAKE_Fortran_FLAGS " -I${ATS_DIR}/include ")
endif()
endif()
4 changes: 2 additions & 2 deletions components/cmake/build_model.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ macro(build_model COMP_CLASS COMP_NAME)
set(ATS_DIR "$ENV{ATS_DIR}")
if (NOT ATS_DIR STREQUAL "")
set(Amanzi_DIR "${ATS_DIR}/lib")
#find_package(HDF5 REQUIRED)
#find_package(NETCDF REQUIRED)
find_package(HDF5 REQUIRED)
find_package(NETCDF REQUIRED)
find_package(Amanzi REQUIRED)
target_link_libraries(${TARGET_NAME} amanzi_elm_ats)
endif()
Expand Down

1 comment on commit 1affbf1

@fmyuan
Copy link

@fmyuan fmyuan commented on 1affbf1 Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart changes.

Please sign in to comment.