[CMake] Using MPI and non-MPI compiler in the same cmake project?

Ateljevich, Eli eli at water.ca.gov
Mon Jun 25 22:43:03 EDT 2012


Hi all,
My project is mostly built with Fortran that uses mpif90 as a wrapper. I use find_package(MPI REQUIRED) to locate f90mpi and then change set the CMAKE_Fortran_COMPILER to ${MPI_Fortran_COMPILER}.



This seemed to work fine until started wrapping up some utilities that do not need to be parallelized. The MPI compiler seems to take quite a bit longer to compile than the serial compiler (ifort). The utilities that would be appropriate for serial compilation have a slighlty different extension (f90 instead of F90).



I realize it is unusual to maintain two compilers for the same language , but in this case the two are related as "mpi wrapper" and "wrapee". There seem to be a few possibilities:
1. Maintain a variable that refers to the compiler and flags for serial and switch to them for just the utilities. Is this even legal? Can I change CMAKE_Fortran_COMPILER at the file or library scope? Could I create a custom rule that somehow inherits from the Fortran rule or is this a can of worms?
2. Never switch to mpiwrapper, but instead make us of the libraries it finds. I have seen this technique referenced more than I have seen the use of mpif90, but I don't know what aspects of mpif90 might get left out by doing this. How would I maintain two sets of flags ... is there an easy way to override flags on a per-target or per-file basis?



Or is there a better way entirely?



Thanks so much,



Eli




More information about the CMake mailing list