# Possible regression: FindMPI.cmake doesn't locate MPI in non-standard installation location

**URL:** https://discourse.cmake.org/t/possible-regression-findmpi-cmake-doesnt-locate-mpi-in-non-standard-installation-location/15589
**Category:** Usage
**Tags:** os:linux
**Created:** [April 1, 2026, 5:38pm UTC](https://discourse.cmake.org/t/possible-regression-findmpi-cmake-doesnt-locate-mpi-in-non-standard-installation-location/15589 "2026-04-01T17:38:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jhendersonHDF](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/848f3c/32.png) [@jhendersonHDF](https://discourse.cmake.org/u/jhendersonHDF)
#### Post date: [April 1, 2026, 5:38pm UTC](https://discourse.cmake.org/t/possible-regression-findmpi-cmake-doesnt-locate-mpi-in-non-standard-installation-location/15589/1 "2026-04-01T17:38:48Z")

</div>

Hi all,

On Linux, I typically install several different MPI versions to `/opt` for testing. After updating CMake to 4.3.1 (the behavior probably changed long before this), it seems CMake can no longer fully find and use these installations. Debugging through the `find_package()` process with `--debug-find`, it appears that this is due to the `_MPI_BASE_DIR` variable derived from `MPIEXEC_EXECUTABLE` not being used in some cases.

When `MPIEXEC_EXECUTABLE` is specified, `mpiexec` and `mpicc` appear to be found fine:

```auto
CMake Debug Log at /usr/share/cmake-4.3/Modules/FindMPI.cmake:1543 (find_program):
   find_program called with the following settings:

     VAR: MPIEXEC_EXECUTABLE
     NAMES:
     Documentation: Executable for running MPI programs.
     Framework
       Only Search Frameworks: 0
       Search Frameworks Last: 0
       Search Frameworks First: 0
     AppBundle
       Only Search AppBundle: 0
       Search AppBundle Last: 0
       Search AppBundle First: 0
     CMAKE_FIND_USE_CMAKE_PATH: 1
     CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
     CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
     CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1 
     CMAKE_FIND_USE_INSTALL_PREFIX: 1	 

   find_program considered the following locations:

   The item was found at

     /opt/openmpi-5.0.5/bin/mpiexec	 

CMake Debug Log at /usr/share/cmake-4.3/Modules/FindMPI.cmake:1694 (find_program):
   find_program called with the following settings:

     VAR: MPI_C_COMPILER
     NAMES: "mpigcc"
            "mpgcc"
            "mpigcc_r"
            "mpgcc_r"
            "mpicc"
            "mpcc"
            "mpicc_r"
            "mpcc_r"
     Documentation: MPI compiler for C	 
     Framework
       Only Search Frameworks: 0
       Search Frameworks Last: 0
       Search Frameworks First: 0
     AppBundle
       Only Search AppBundle: 0
       Search AppBundle Last: 0
       Search AppBundle First: 0
     NO_DEFAULT_PATH Enabled

   find_program considered the following locations:

     /opt/openmpi-5.0.5/bin/mpigcc	 
     /opt/openmpi-5.0.5/sbin/mpigcc	 
     /opt/openmpi-5.0.5/mpigcc
     /opt/openmpi-5.0.5/bin/mpgcc
     /opt/openmpi-5.0.5/sbin/mpgcc	 
     /opt/openmpi-5.0.5/mpgcc
     /opt/openmpi-5.0.5/bin/mpigcc_r	 
     /opt/openmpi-5.0.5/sbin/mpigcc_r	 
     /opt/openmpi-5.0.5/mpigcc_r
     /opt/openmpi-5.0.5/bin/mpgcc_r	 
     /opt/openmpi-5.0.5/sbin/mpgcc_r	 
     /opt/openmpi-5.0.5/mpgcc_r

   The item was found at

     /opt/openmpi-5.0.5/bin/mpicc

```

But `mpi.h` is not found:

```auto
Checking for module 'mpi-c'
   Package 'mpi-c' not found
CMake Debug Log at /usr/share/cmake-4.3/Modules/FindMPI.cmake:1337 (find_path):
   find_path called with the following settings:

     VAR: MPI_C_HEADER_DIR
     NAMES: "mpi.h"
     Documentation: Path to a file.	 
     Framework
       Only Search Frameworks: 0
       Search Frameworks Last: 0
       Search Frameworks First: 0
     AppBundle
       Only Search AppBundle: 0
       Search AppBundle Last: 0
       Search AppBundle First: 0
     CMAKE_FIND_USE_CMAKE_PATH: 1
     CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
     CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
     CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1 
     CMAKE_FIND_USE_INSTALL_PREFIX: 1	 

   find_path considered the following locations:

     /usr/lib64/go1.25.7/go/bin/mpi.h	 
     /usr/local/bin/mpi.h
     /usr/bin/mpi.h
     /bin/mpi.h
     /usr/games/mpi.h
     /usr/lib64/libexec/kf5/mpi.h
     /usr/lib64/qt5/bin/mpi.h
     /usr/lib64/qt6/bin/mpi.h
     /usr/local/include/mpi.h
     /usr/local/mpi.h
     /usr/include/mpi.h
     /usr/mpi.h
     /include/mpi.h
     /usr/X11R6/include/mpi.h
     /usr/X11R6/mpi.h
     /usr/pkg/include/mpi.h
     /usr/pkg/mpi.h
     /opt/include/mpi.h
     /opt/mpi.h
     /usr/include/X11/mpi.h

   The item was not found.

```

I also tried using `MPI_HOME`, but that didn’t work either.

Patching FindMPI.cmake as in:

```auto
diff --git a/FindMPI.cmake b/usr/share/cmake-4.3/Modules/FindMPI.cmake
index ebfd79f..f0ce949 100644
--- a/FindMPI.cmake
+++ b/usr/share/cmake-4.3/Modules/FindMPI.cmake
@@ -1326,6 +1326,12 @@ macro(_MPI_split_include_dirs LANG)
   # We try to find the headers/modules among those paths (and system paths)
   # For C/C++, we just need to have a look for mpi.h.
   if(LANG MATCHES "^(C|CXX)$")
+ if (_MPI_BASE_DIR)
+ find_path(MPI_${LANG}_HEADER_DIR "mpi.h"
+ HINTS
+ ${_MPI_BASE_DIR}/include
+ )
+ endif()
     find_path(MPI_${LANG}_HEADER_DIR "mpi.h"
       HINTS
         ${MPI_${LANG}_COMPILER_INCLUDE_DIRS}

```

works to find the header, but of course is just a quick solution and also still leaves me with:

```auto
Could NOT find MPI_C (missing: MPI_C_LIB_NAMES MPI_C_WORKS)
CMake Error at /usr/share/cmake-4.3/Modules/FindPackageHandleStandardArgs.cmake:290 (message):
   Could NOT find MPI (missing: MPI_C_FOUND)
 Call Stack (most recent call first):
   /usr/share/cmake-4.3/Modules/FindPackageHandleStandardArgs.cmake:654 (_FPHSA_FAILURE_MESSAGE)
   /usr/share/cmake-4.3/Modules/FindMPI.cmake:2012 (find_package_handle_standard_args)

```

at which point the module is complicated enough that I’m not sure how to get the last two variables set correctly without setting them manually.

Any help on temporarily patching this would be much appreciated!
