MPI recognition with Conda on Apple silicon

I am building a make file with Cmake version 3.27 on a MacBook with Sonoma and an Apple Silicon M2 Chip.
Also, I use a Conda environment with Cmake, make, clang, mpich and hdf5 installed.
When running Cmake (Conda environment activated) with “cmake <path_to_project> -DCMAKE_PREFIX_PATH=$CONDA_PREFIX” the compilers are recognized correctly.
However, it fails finding the mpi:
– Could NOT find MPI_C (missing: MPI_C_WORKS)
– Found MPI_CXX: /Users//anaconda3/envs/alpaca/lib/libmpicxx.dylib (found version “4.0”)
CMake Error at /Users//anaconda3/envs/alpaca/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find MPI (missing: MPI_C_FOUND) (found version “4.0”)
Call Stack (most recent call first):
/Users//anaconda3/envs/alpaca/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/Users//anaconda3/envs/alpaca/share/cmake-3.27/Modules/FindMPI.cmake:1837 (find_package_handle_standard_args)
CMakeLists.txt:11 (FIND_PACKAGE)

What I do not understand is, that Cmake finds MPI_CXX, but not MPI_C as both libmpicxx.dylib and libmpi.dylib are existent in the lib-directory.

I am glad for any help!

In general across operating systems I’ve found the conda libraries may not be ABI compatible with non-conda compilers. Looking at CMakeConfigureLog.yaml and/or cmake -Bbuild --debug-find-pkg=MPI might give hints.

Thank you for this suggestion. Looking at the output revealed, that all packages are found. I think the decisive line might be missing: MPI_C_WORKS.
Does Cmake test what it found in the background? What can make this test fail?

Look at ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeConfigureLog.yaml to see why mpi_c_works fails