I am currently working on a CMake script, and I faced a peculiar problem. Upon running find_package(MPI REQUIRED), I get an error that MPI could not be found, despite having both OpenMPI and MPICH installed on my machine.
A way to resolve this is to first add /usr/lib64/openmpi/bin to $PATH (by simply running PATH=$PATH:/usr/lib64/openmpi/bin on the terminal, and similarly if I want to use MPICH instead) and then build the project. However, clearly this solution is not portable if I assume that the user who would build does not want to go around looking for the location where MPI is installed.
How do include this as a part of the CMake script?
I thought of doing set(CMAKE_PREFIX_PATH "/usr/lib64/openmpi/bin" ${CMAKE_PREFIX_PATH}) but this also seems a bit hardcoded in my opinion. Because, 1) this prefers OpenMPI over MPICH (which could be resolved by adding both paths) and 2) it's not guaranteed that all computers would have the same directory structure