improve MPI handling

Issue #18 resolved
Nico Schlömer created an issue

In an attempt to split PR #139 into smaller chunks, let's look at how MPI is handled in MOAB.

Currently, when configuring MOAB on a Debian system with OpenMPI installed into default directories, one gets the cryptic error

Warning: Unable to find MPI library dl
Warning: Unable to find MPI library hwloc
CMake Error at config/FindMPI.cmake:208 (list):
  list index: 1 out of range (-1, 0)
Call Stack (most recent call first):
  CMakeLists.txt:202 (find_package)

The error stems from the (outdated?) FindMPI.cmake script in ./config/.

When looking at ./CMakeLists.txt, one finds that MPI is mentioned twice. First as MPI_DIR where MOAB tries to find the MPI compiler by presenting it with a list of common and not so common compiler wrappers. Based upon this, some variables are set (CMAKE_GENERATOR_<lang>) which are never used again. If it wasn't for setting CMake_Fortran_COMPILER_INIT, setting MPI_DIR seems pointless and the related code could go.

CMake's own FindMPI tries to handle MPI such that you provide it with the compilers (MPI_<lang>_COMPILER), then CMake tries to figure out what libraries and headers are needed. This is what MOAB is using with find_package(MPI) (line 202 in ./CMakeLists.txt), except that it's not using CMake's FindMPI.cmake but its own.

Suggestion:

Remove the use of MPI_DIR (it's not doing anything anyways), use ENABLE_MPI and CMake's variables (MPI_<lang>_COMPILER) to find the correct options.