From e8bb3d70799c3a531e76fecf85cf0cccebc4d094 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 18 May 2022 16:53:37 -0600 Subject: [PATCH] Snapshot FindTPLNetcdf.cmake from Trilinos 8c1028df724 with small mods (#299) This was snapshotted from the Trilinos commit: commit 8c1028df724eb0096cd688b381285112bc6f914a Author: Roscoe A. Bartlett Date: Wed May 18 15:08:17 2022 -0600 FindTPLNetcdf.cmake: Lower-case function names (TriBITSPub/TriBITS#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 c716a74e8419d356fd16552eaf74ece85397eccd; Author: Greg Sjaardema ; 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 #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. --- tribits/common_tpls/FindTPLNetcdf.cmake | 50 +++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/tribits/common_tpls/FindTPLNetcdf.cmake b/tribits/common_tpls/FindTPLNetcdf.cmake index a5a98ce2c..9ffd66c06 100644 --- a/tribits/common_tpls/FindTPLNetcdf.cmake +++ b/tribits/common_tpls/FindTPLNetcdf.cmake @@ -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 ...). @@ -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) @@ -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") @@ -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() # @@ -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}")