Skip to content

Commit 501388f

Browse files
committed
config/cmake: find MPI if the MPI component is requested
Otherwise projects using `conduit::conduit_mpi` may get errors about `MPI::MPI_C` not being a target without finding it themselves. Instead of requesting users to find MPI themselves, let them request support via an MPI component.
1 parent 53c3387 commit 501388f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/config/ConduitConfig.cmake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ if(NOT CONDUIT_FOUND)
6161

6262
set(Conduit_FOUND TRUE)
6363

64-
set(_conduit_known_components)
64+
set(_conduit_known_components
65+
MPI)
6566
foreach(_conduit_component IN LISTS Conduit_FIND_COMPONENTS)
6667
if (NOT _conduit_component IN_LIST _conduit_known_components)
6768
set("Conduit_${_conduit_component}_FOUND" 0)

src/config/conduit_setup_deps.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ if(CONDUIT_USE_OPENMP)
4646
endif()
4747
endif()
4848

49+
###############################################################################
50+
# Setup MPI
51+
###############################################################################
52+
if("MPI" IN_LIST Conduit_FIND_COMPONENTS)
53+
set(Conduit_MPI_NOT_FOUND_MESSAGE "")
54+
55+
if(NOT CONDUIT_USE_CMAKE_MPI_TARGETS)
56+
# The compiler is expected to have MPI implicitly available; MPI is
57+
# found.
58+
elseif(CONDUIT_RELAY_MPI_ENABLED)
59+
if(NOT TARGET MPI::MPI_C)
60+
set(_conduit_find_mpi_args "")
61+
if(Conduit_FIND_QUIETLY)
62+
list(APPEND _conduit_find_mpi_args QUIET)
63+
endif()
64+
65+
find_dependency(MPI ${_conduit_find_mpi_args} COMPONENTS C)
66+
unset(_conduit_find_mpi_args)
67+
endif()
68+
69+
if(NOT TARGET MPI::MPI_C)
70+
set(Conduit_MPI_NOT_FOUND_MESSAGE "MPI could not be found: ${MPI_NOT_FOUND_MESSAGE}")
71+
endif()
72+
else()
73+
set(Conduit_MPI_NOT_FOUND_MESSAGE "MPI support is not available")
74+
endif()
75+
76+
set(Conduit_MPI_FOUND 1)
77+
if(Conduit_MPI_NOT_FOUND_MESSAGE)
78+
set(Conduit_MPI_FOUND 0)
79+
endif()
80+
endif()
81+
4982
###############################################################################
5083
# Setup Caliper
5184
###############################################################################

0 commit comments

Comments
 (0)