Skip to content

Commit

Permalink
Snapshot FindTPLNetcdf.cmake from Trilinos 8c1028df724 with small mods (
Browse files Browse the repository at this point in the history
TriBITSPub#299)

This was snapshotted from the Trilinos  commit:

  commit 8c1028df724eb0096cd688b381285112bc6f914a
  Author: Roscoe A. Bartlett <rabartl@sandia.gov>
  Date:   Wed May 18 15:08:17 2022 -0600

    FindTPLNetcdf.cmake: Lower-case function names (TriBITSPub#274)

soon to be merged to Trilinos 'develop' from Trilinos PR #10533.

However, this is not an snapshot as I made the following changing before
creating this commit:

* Kept the spelling fix for 'separated' made in TriBITS 'master' branch from
  commit c716a74; Author: Greg Sjaardema
  <gsjaardema@gmail.com>; Date: Mon Aug 2 16:02:20 2021 -0600; "Spelling
  fixes"

* I removed a few trailing spaces at the end of some lines

Why? There really is no value in using a different version of
FindTPLNetcdf.cmake in TriBITS that what is used in Trilinos.  When testing
Trilinos against updated versions of TriBITS, you really want the logic to
match.  In the case in testing with Trilinos (as part of TriBITSPub#299 and testing with
trilinos/Trilinos#10533), the old version of FindTPLNetcdf.cmake before this
change was not properly setting TPL_Netcdf_PARALLEL which was not allowing the
enable of the test SEACASIoss_exodus_fpp_serialize.  With this sync, we get
the exact same tests.
  • Loading branch information
bartlettroscoe committed May 26, 2022
1 parent a7c2282 commit e8bb3d7
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions tribits/common_tpls/FindTPLNetcdf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
set(REQUIRED_HEADERS netcdf.h)
set(REQUIRED_LIBS_NAMES netcdf)

if (TPL_ENABLE_MPI)
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} pnetcdf)
endif()

#
# Second, search for Netcdf components (if allowed) using the standard
# find_package(NetCDF ...).
Expand All @@ -62,7 +66,7 @@ if (Netcdf_ALLOW_PREFIND)
"${CMAKE_CURRENT_LIST_DIR}/find_modules"
"${CMAKE_CURRENT_LIST_DIR}/utils"
)

find_package(NetCDF)

if (NetCDF_FOUND)
Expand All @@ -71,7 +75,7 @@ if (Netcdf_ALLOW_PREFIND)
"True if netcdf enables netcdf-4")
set(TPL_Netcdf_Enables_PNetcdf ${NetCDF_NEEDS_PNetCDF} CACHE BOOL
"True if netcdf enables pnetcdf")
set(TPL_Netcdf_PARALLEL ${NetCDF_PARALLEL} CACHE BOOL
set(TPL_Netcdf_PARALLEL ${NetCDF_PARALLEL} CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
set(TPL_Netcdf_LIBRARY_DIRS ${_hdf5_LIBRARY_SEARCH_DIRS} CACHE PATH
"${DOCSTR} library files")
Expand All @@ -80,7 +84,20 @@ if (Netcdf_ALLOW_PREFIND)
set(TPL_Netcdf_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} CACHE PATH
"${DOCSTR} header files.")
endif()

else()
# Curl library is only required if DAP is enabled; should detect inside
# FindNetCDF.cmake, but that is not being called... SEMS has DAP enabled;
# many HPC systems don't, but they override these settings...
find_program(NC_CONFIG "nc-config")
if (NC_CONFIG)
execute_process(COMMAND "nc-config --has-dap2"
OUTPUT_VARIABLE NETCDF_HAS_DAP2)
execute_process(COMMAND "nc-config --has-dap4"
OUTPUT_VARIABLE NETCDF_HAS_DAP4)
endif()
if ((NOT NC_CONFIG) OR NETCDF_HAS_DAP2 OR NETCDF_HAS_DAP4)
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} curl)
endif()
endif()

#
Expand All @@ -95,3 +112,30 @@ tribits_tpl_find_include_dirs_and_libraries( Netcdf
# variables TPL_Netcdf_INCLUDE_DIRS and TPL_Netcdf_LIBRARIES and then print
# them out (and set some other standard variables as well). This is the final
# "hook" into the TriBITS TPL system.

# If the `find_package(NetCDF)` is not run, then this may not be set
# Need to determine how this is set in the library that is being used...

if ("${TPL_Netcdf_PARALLEL}" STREQUAL "")
assert_defined(TPL_Netcdf_INCLUDE_DIRS)
find_path(meta_path
NAMES "netcdf_meta.h"
HINTS ${TPL_Netcdf_INCLUDE_DIRS}
NO_DEFAULT_PATH)

if (meta_path)
# Search meta for NC_HAS_PARALLEL setting...
# Note that there is both NC_HAS_PARALLEL and NC_HAS_PARALLEL4, only want first...
file(STRINGS "${meta_path}/netcdf_meta.h" netcdf_par_string REGEX "NC_HAS_PARALLEL ")
string(REGEX MATCH "[01]" netcdf_par_val "${netcdf_par_string}")
if (netcdf_par_val EQUAL 1)
set(TPL_Netcdf_PARALLEL True CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
endif()
endif()
if ("${TPL_Netcdf_PARALLEL}" STREQUAL "")
set(TPL_Netcdf_PARALLEL False CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
endif()
endif()
message(STATUS "TPL_Netcdf_PARALLEL is ${TPL_Netcdf_PARALLEL}")

0 comments on commit e8bb3d7

Please sign in to comment.