[CMake] FindMPI and setting C/C++ compiler

Marcel Loose loose at astron.nl
Thu May 27 03:31:19 EDT 2010


OK, thanks.

I noted one issue with the current FindMPI, though.
I'm using MPICH, and upon inspection of the mpicc and mpicxx scripts, I
noticed that these scripts also set a lot of -f options for GCC. These
settings are not picked up by FindMPI, as it does not search for compile
flags that start with -f.

For example, running 'mpicxx -show' gives me:

$ /opt/mpich/ch-p4/bin/mpicxx -show
g++ -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector
-funwind-tables -fasynchronous-unwind-tables -g -fno-strict-aliasing
-Impid/mpd/ -Iinclude -DUSE_STDARG -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1
-DHAVE_UNISTD_H=1 -DHAVE_STDARG_H=1 -DUSE_STDARG=1 -DMALLOC_RET_VOID=1
-L/opt/mpich/ch-p4/lib64 -lpmpich++ -lmpich -lpthread -lrt

But the -f options do not appear in the CMakeCache.txt file:

$ grep ^MPI_ CMakeCache.txt | grep -v ADVANCED
MPI_COMPILER:FILEPATH=/opt/mpich/ch-p4/bin/mpicxx
MPI_COMPILE_FLAGS:STRING= -D_FORTIFY_SOURCE=2  -DUSE_STDARG
-DHAVE_STDLIB_H=1  -DHAVE_STRING_H=1  -DHAVE_UNISTD_H=1
-DHAVE_STDARG_H=1  -DUSE_STDARG=1  -DMALLOC_RET_VOID=1
MPI_EXTRA_LIBRARY:STRING=/opt/mpich/ch-p4/lib64/libmpich.a;/usr/lib64/libpthread.so;/usr/lib64/librt.so
MPI_INCLUDE_PATH:STRING=mpid/mpd/;include
MPI_LIBRARY:FILEPATH=/opt/mpich/ch-p4/lib64/libpmpich++.a
MPI_LINK_FLAGS:STRING=
MPI_ROOT_DIR:UNINITIALIZED=/opt/mpich/ch-p4
MPI_LIB:INTERNAL=MPI_LIB-NOTFOUND

This means, that sources will be compiled differently when using g++
directly, supplying the options gathered by FindMPI, compared to using
mpicxx. So, preferably the C/C++ compiler should be set to mpicc/mpicxx.
However, that cannot be done after the project() statement has been run.
So, I feel this is kind of a chicken-and-egg problem.

Best regards,
Marcel Loose.

On Wed, 2010-05-26 at 20:10 +0200, Michael Wild wrote:
> Well, the MPI_COMPILER variable is certainly used internally by
FindMPI to detect all the stuff. And to use MPI_LINK_FLAGS, just set
them as the target property LINK_FLAGS.
> 
> 
> Michael
> 
> 
> On 26. May, 2010, at 18:15 , Marcel Loose wrote:
> 
> > True, but that raises (at least) two questions:
> > 
> > 1) What's the use of the variable MPI_COMPILER if it cannot be used
to
> > set the C/C++ compiler.
> > 
> > 2) I know how to handle MPI_COMPILE_FLAGS - use add_definitions();
> > MPI_INCLUDE_PATH - use include_directories(); MPI_LIBRARIES - use
> > target_link_libraries(). But how do I handle MPI_LINK_FLAGS?
> > 
> > Regards,
> > Marcel Loose.
> > 
> > On Wed, 2010-05-26 at 17:38 +0200, Michael Wild wrote:
> >> On 26. May, 2010, at 17:20 , Marcel Loose wrote:
> >> 
> >>> Hi all,
> >>> 
> >>> I was wondering how one should use find_package(MPI) to properly
set
> > the
> >>> C/C++ compiler(s). Normally, you call find_package() after the
> > project()
> >>> command. However, by that time the CMAKE_<LANG>_COMPILER cache
> > variables
> >>> have already been set. Should one FORCE these cache variables to
the
> >>> value of MPI_COMPILER?
> >>> 
> >>> I vaguely remember that setting CMAKE_<LANG>_COMPILER after the
> >>> project() statement was a definite no-no, because all kinds of
> > tests,
> >>> executed by the project() command, are done with the default C/C++
> >>> compilers.
> >>> 
> >>> Best regards,
> >>> Marcel Loose.
> >> 
> >> 
> >> Usually mpiCC and cohorts are just wrapper scripts which add
> > appropriate include directories and libraries to the command line.
If I
> > remember correctly, FindMPI.cmake detects those and provides them
via
> > MPI_COMPILE_FLAGS, MPI_INCLUDE_PATH, MPI_LINK_FLAGS and
MPI_LIBRARIES.
> > So, you actually don't need to set the compiler to one of the MPI
> > compiler wrappers.
> >> 
> >> Michael
> > 
> > 
> 




More information about the CMake mailing list