Skip to content

Commit

Permalink
Fix how FindNetCDF finds MPI (#44)
Browse files Browse the repository at this point in the history
Fix FindNetCDF with MPI

Remove COMPONENTS from FindMPI. If blank it search for all enabled languages. Otherwise, for a project without C enabled it would fail to fail to find MPI C.
  • Loading branch information
kgerheiser authored Sep 4, 2020
1 parent 7fe17de commit 3eaddb8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Modules/FindNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ if( NOT _val MATCHES "^(yes|no)$" )
endif()
if( _val MATCHES "^(yes)$" )
set(NetCDF_PARALLEL TRUE CACHE STRING "NetCDF has parallel IO capability via pnetcdf or hdf5." FORCE)
find_package(MPI REQUIRED COMPONENTS C)
else()
set(NetCDF_PARALLEL FALSE CACHE STRING "NetCDF has no parallel IO capability." FORCE)
endif()

if(NetCDF_PARALLEL)
find_package(MPI REQUIRED)
endif()

## Find libraries for each component
set( NetCDF_LIBRARIES )
foreach( _comp IN LISTS _search_components )
Expand Down Expand Up @@ -242,11 +245,9 @@ foreach( _comp IN LISTS _search_components )
INTERFACE_LINK_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} )
if( NOT _comp MATCHES "^(C)$" )
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE NetCDF::NetCDF_C)
else()
# Link NetCDF C lib to MPI (which transitively applies to other components)
if(NetCDF_PARALLEL)
target_link_libraries(NetCDF::NetCDF_C INTERFACE MPI::MPI_C)
endif()
endif()
if(MPI_${_comp}_FOUND)
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE MPI::MPI_${_comp})
endif()
endif()
endif()
Expand Down

0 comments on commit 3eaddb8

Please sign in to comment.