I’m trying to compile the Elmer FEM repository inside the “MSYS2 MinGW 64-bit” environment on Windows. I’m encountering a bizarre issue where CMake fails to find MPI libraries on the first few runs but eventually succeeds without any changes to the command or environment.
Here’s the CMake command I’m using:
git clone https://github.com/ElmerCSC/elmerfem
git checkout 8bff09ddc7a0da78b6ba17b19a9afebe2c7824d7
cmake -DMPI_C_LIBRARIES=/mingw64/lib/libmsmpi.dll.a -DMPI_CXX_LIBRARIES=/mingw64/lib/libmsmpi.dll.a -DMPI_Fortran_LIBRARIES=/mingw64/lib/libmsmpi.dll.a ..
On the first run, I get:
CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MPI_C (missing: MPI_C_LIBRARIES)
On the second run (without any changes):
CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MPI_CXX (missing: MPI_CXX_LIBRARIES)
On the third run:
CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MPI_Fortran (missing: MPI_Fortran_LIBRARIES)
Finally, on the fourth run, CMake succeeds without any errors.
Each time, it seems to find one more MPI component (C, then CXX, then Fortran) but still fails until the fourth attempt. This happens consistently: if I delete the build directory and start over, the same pattern repeats.
Questions:
- What could be causing this behavior?
- How can I resolve this issue to make CMake succeed on the first run?
- Is this a bug in CMake, Elmer FEM’s build system, or my setup?
Environment:
- Windows 10
- MSYS2 MinGW 64-bit
- CMake 3.26.4
- GCC 14.1.0
- Elmer FEM (commit
8bff09ddc7a0da78b6ba17b19a9afebe2c7824d7
)
Any insights or solutions would be greatly appreciated!