Skip to content

MPI variants of ADIOS2 libraries always require MPI::MPI_C in CMake #4082

@lahwaacz

Description

@lahwaacz

Describe the bug
MPI variants of ADIOS2 libraries always require the MPI::MPI_C target in CMake, even when MPI::MPI_CXX would be more appropriate.

Recall that FindMPI says:

The module exposes the components C, CXX, MPICXX and Fortran. Each of these controls the various MPI languages to search for. The difference between CXX and MPICXX is that CXX refers to the MPI C API being usable from C++, whereas MPICXX refers to the MPI-2 C++ API that was removed again in MPI-3.

Hence, when building a C++ project and linking to e.g. adios2::cxx11_mpi, the MPI::MPI_CXX target is the best option and MPI::MPI_C might even be unavailable (see the reproducer below).

To Reproduce
Create the following CMakeLists.txt and an empty foo.cpp file:

cmake_minimum_required(VERSION 3.28.3)
project(foo LANGUAGES CXX)
add_executable(foo foo.cpp)

find_package(MPI COMPONENTS CXX REQUIRED)
find_package(ADIOS2 REQUIRED)
target_link_libraries(foo PUBLIC MPI::MPI_CXX adios2::cxx11_mpi)

Try to configure the project:

$ cmake -B build -S .
-- Found MPI_CXX: /usr/lib/libmpi.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1") found components: CXX
-- Found MPI: TRUE (found version "3.1")
-- Found ADIOS2: /usr/lib/cmake/adios2/adios2-config.cmake (found version "2.9.2") found components: CXX MPI
-- Configuring done (0.6s)
CMake Error at /usr/lib/cmake/adios2/adios2-cxx11-targets.cmake:78 (set_target_properties):
  The link interface of target "adios2::cxx11_mpi" contains:

    MPI::MPI_C

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /usr/lib/cmake/adios2/adios2-config-common.cmake:199 (include)
  /usr/lib/cmake/adios2/adios2-config.cmake:29 (include)
  CMakeLists.txt:6 (find_package)


-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

Note that changing find_package(MPI COMPONENTS CXX REQUIRED) to find_package(MPI COMPONENTS C REQUIRED) and linking to MPI::MPI_C is not enough alone, because the C language is not enabled in this project and it would lead to this error:

$ cmake -B build -S .
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)

      Reason given by package: MPI component 'C' was requested, but language C is not enabled.

Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindMPI.cmake:1837 (find_package_handle_standard_args)
  CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!

Expected behavior
The adios2::cxx11_mpi target (and others?) should work just fine with MPI::MPI_CXX and MPI::MPI_C should not be required.

Desktop (please complete the following information):

  • OS/Platform: Arch Linux
  • adios2 2.9.2
  • cmake 3.28.3
  • openmpi 5.0.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions