From fe3cc6fc449589ca76cf5e723aa6b31d3d4e1c3b Mon Sep 17 00:00:00 2001 From: John Parent Date: Tue, 24 Jan 2023 15:07:39 -0500 Subject: [PATCH 1/4] Find MPI during CMake package import When MPI::MPI_C is included in link interface of exported netcdf::netcdf target the config module is responsible for locating that target and providing it to the consuming project via find_dependency --- CMakeLists.txt | 2 ++ netCDFConfig.cmake.in | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b0573111b..f3a5262322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1471,6 +1471,7 @@ ENDIF() # Enable Parallel IO with netCDF-4/HDF5 files using HDF5 parallel I/O. SET(STATUS_PARALLEL "OFF") +set(IMPORT_MPI "") OPTION(ENABLE_PARALLEL4 "Build netCDF-4 with parallel IO" "${HDF5_PARALLEL}") IF(ENABLE_PARALLEL4 AND ENABLE_HDF5) IF(NOT HDF5_PARALLEL) @@ -1492,6 +1493,7 @@ IF(ENABLE_PARALLEL4 AND ENABLE_HDF5) FILE(COPY "${netCDF_BINARY_DIR}/tmp/run_par_tests.sh" DESTINATION ${netCDF_BINARY_DIR}/h5_test FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + set(IMPORT_MPI "include(CMakeFindDependencyMacro)\nfind_dependency(MPI COMPONENTS C)") ENDIF() ENDIF() diff --git a/netCDFConfig.cmake.in b/netCDFConfig.cmake.in index 9d68eec5a2..dae2429e4a 100644 --- a/netCDFConfig.cmake.in +++ b/netCDFConfig.cmake.in @@ -14,6 +14,8 @@ set(netCDF_LIBRARIES netCDF::netcdf) # include target information include("${CMAKE_CURRENT_LIST_DIR}/netCDFTargets.cmake") +@IMPORT_MPI@ + # Compiling Options # set(netCDF_C_COMPILER "@CC_VERSION@") From ce3bb54d555afcaef48c51687c9f65e37d899bea Mon Sep 17 00:00:00 2001 From: John Parent Date: Tue, 24 Jan 2023 15:16:55 -0500 Subject: [PATCH 2/4] If using MPI, should link against MPI target Failing to do this results in unresolved symbols during link time. --- liblib/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt index e3eddc0fb1..3df7918675 100644 --- a/liblib/CMakeLists.txt +++ b/liblib/CMakeLists.txt @@ -52,6 +52,10 @@ IF(MPI_C_INCLUDE_PATH) target_include_directories(netcdf PUBLIC ${MPI_C_INCLUDE_PATH}) ENDIF(MPI_C_INCLUDE_PATH) +IF(TARGET MPI::MPI_C) + target_link_libraries(netcdf PUBLIC MPI::MPI_C) +ENDIF(TARGET MPI::MPI_C) + IF(MOD_NETCDF_NAME) SET_TARGET_PROPERTIES(netcdf PROPERTIES LIBRARY_OUTPUT_NAME ${NETCDF_LIB_NAME}) SET_TARGET_PROPERTIES(netcdf PROPERTIES ARCHIVE_OUTPUT_NAME ${NETCDF_LIB_NAME}) From 96c7d58f04f7cea9d9c8bd95127f66a99a73b3c4 Mon Sep 17 00:00:00 2001 From: John Parent Date: Tue, 24 Jan 2023 15:18:11 -0500 Subject: [PATCH 3/4] Plug dependencies should include MPI Plugin deps should include MPI if MPI is being used in the build. This is at least the case of HDF5 --- plugins/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 65891d82ee..15567c8f6b 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -62,6 +62,9 @@ MACRO(buildplugin TARGET TARGETLIB) set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") # Set file name & location set_target_properties(${TARGET} PROPERTIES COMPILE_PDB_NAME ${TARGET} COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR}) + IF(MPI_C_INCLUDE_PATH) + target_include_directories(${TARGET} PRIVATE ${MPI_C_INCLUDE_PATH}) + ENDIF(MPI_C_INCLUDE_PATH) ENDIF() ENDMACRO() From f8a34e930b714d2c535fba9b8f8395c84b54fb1d Mon Sep 17 00:00:00 2001 From: John Parent Date: Wed, 25 Jan 2023 16:41:27 -0500 Subject: [PATCH 4/4] Linux: consistent use of blank link vis --- liblib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt index 3df7918675..8fdfd75614 100644 --- a/liblib/CMakeLists.txt +++ b/liblib/CMakeLists.txt @@ -53,7 +53,7 @@ IF(MPI_C_INCLUDE_PATH) ENDIF(MPI_C_INCLUDE_PATH) IF(TARGET MPI::MPI_C) - target_link_libraries(netcdf PUBLIC MPI::MPI_C) + target_link_libraries(netcdf MPI::MPI_C) ENDIF(TARGET MPI::MPI_C) IF(MOD_NETCDF_NAME)