[CMake] Mixed C and Fortran with FIND_PACKAGE
Benjamin Matthews
ben at kc2vjw.com
Tue Aug 3 14:04:27 EDT 2010
I'm working on replacing an antiquated custom build system with cmake on
a project which uses a mix of several flavors of Fortran as well as some
C and C++. The problem I'm running into is that FIND_MPI (and I would
guess a variety of other modules) just assume that the compiler flags
should be the same for each language and this simply isn't the case.
For example, FIND_MPI uses mpicc --show to get the compiler and linker
flags required to make MPI work:
mpicc --show
icc -I/usr/local/openmpi/1.4.2-intel/include -pthread
-L/usr/local/openmpi/1.4.2-intel/lib -lmpi -lopen-rte -lopen-pal -ldl
-Wl,--export-dynamic -lnsl -lutil
To get Fortran bindings, you have to use a couple different libraries:
mpif90 --show
ifort -I/usr/local/openmpi/1.4.2-intel/include
-I/usr/local/openmpi/1.4.2-intel/lib
-L/usr/local/openmpi/1.4.2-intel/lib -lmpi_f90 -lmpi_f77 -lmpi
-lopen-rte -lopen-pal -ldl -Wl,--export-dynamic -lnsl -lutil
It is possible to force FIND_MPI to use mpif90 rather than mpicc, but
that just breaks the C[++] part of the code.
Ideally, the variables set by FIND_MPI would change dynamically
depending on the type of code that cmake happens to be building, but
that doesn't seem to be the case. The only other (halfway reasonable)
solution I can think of is to modify FIND_MPI to export a second set of
variables for Fortran.
For now I'm manually setting the compiler flags for the Fortran compiler
at cmake runtime, but that's not a good solution. Does anyone have a
better way to do this?
Thanks
Ben
More information about the CMake
mailing list