[CMake] Difficulty making MPI and OpenMP Fortran shared library with CMake

Rand Huso r.huso at gns.cri.nz
Thu Mar 17 17:46:07 EDT 2016


I would like to use CMake for a personal project instead of make (which
does work), but I can't seem to get CMake to work the way I think it
should. The command "cmake ." runs fine, but the make produces this:

Scanning dependencies of target MIFF
Linking Fortran shared library libMIFF.so
gfortran: fatal error: no input files; unwilling to write output files
compilation terminated.
make[2]: *** [src/libMIFF.so] Error 4
make[1]: *** [src/CMakeFiles/MIFF.dir/all] Error 2
make: *** [all] Error 2

This surprises me because I don't think I should see "gfortran" - I
expected to see "mpif90". And that particular message seems to happen when
there are insufficient arguments to "gfortran". (the wrapper "mpif90" is
configured to use "gfortran", but all compilation should use the "mpif90" -
which doesn't appear to be the case when looking through the generated
makefiles.)

Here's what my project looks like:

Directory structure:
MIFF
 - src/
 - - CMakeLists.txt
 - - MIFFTest.f08
 - - MIFFTestMessage.f08
 - - MpiIocBaseMessage.f08
 - - MpiIocControlMessage.f08
 - - MpiIocFramework.f08
 - - MpiIocLinkedListItem.f08
 - CMakeLists.txt

My system is:
Ubuntu 14.04.4 LTS
The mpif90 compiler is:
GNU Fortran (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
CMake reports:
cmake version 2.8.12.2

Hopefully this is already fixed in newer versions of cmake - but this is
the version currently installed - but that's difficult for me to test, as
I'm working on a system that shouldn't deviate too far from our standard
development platform.

The CMakeLists.txt file in the MIFF directory is:
cmake_minimum_required (VERSION 2.8.6)
project( MIFF_Project )
add_subdirectory( src )

the CMakeLists.txt file in the MIFF/src directory is:
cmake_minimum_required( VERSION 2.8.8 )
project( MIFF_Project )
enable_language( Fortran )
set( CMAKE_FORTRAN_COMPILER mpif90 )
file( GLOB MIFF_Code *.f* )
message( STATUS "MIFF_Code: ${MIFF_Code}" )
add_library( MIFF SHARED ${MIFF_Code} )
set_target_properties( MIFF PROPERTIES LINKER_LANGUAGE Fortran ) #
OUTPUT_NAME MIFF )

I think I've exhausted Google looking for a solution, and I have a standard
Makefile that seems to work fine:

.PHONY : all clean run

COMPILER     = mpif90
FFLAGS       = -shared -fPIC -g -I/usr/include
LIBRARY      = MIFF.so
EXECUTABLE   = MIFFTest
EXESOURCES   = src/MIFFTest.f08 \
               src/MIFFTestMessage.f08
LIBSOURCES   = src/MpiIocBaseMessage.f08 \
               src/MpiIocControlMessage.f08 \
               src/MpiIocLinkedListItem.f08 \
               src/MpiIocFramework.f08

src/MIFFTest.o : src/MIFFTest.f08 src/MIFFTestMessage.f08

all : $(LIBRARY) $(EXECUTABLE)

clean :
    - rm -f *.o *.so *.mod $(EXECUTABLE)

run :
    export LD_LIBRARY_PATH=~/workspace/MIFF
    mpiexec -n 2 $(EXECUTABLE)


$(LIBRARY) : $(LIBSOURCES)
    $(COMPILER) $(FFLAGS) $(LIBSOURCES) -o $(LIBRARY)

$(EXECUTABLE) : $(EXESOURCES) $(LIBRARY)
    export LD_LIBRARY_PATH=~/workspace/MIFF
    $(COMPILER) -o $(EXECUTABLE) $(EXESOURCES) $(LIBRARY)


Except for the problem of having to issue the "make all" twice because of a
dependency problem I haven't worked out, this hand-crafted Makefile works.
It's bad enough that I'm pushing the boundaries of polymorphism in
MPI+OpenMP+Fortran.

I'd appreciate any assistance getting cmake to work for my project.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160318/b21510d1/attachment-0001.html>


More information about the CMake mailing list