diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index eaef02aa71..10947bfef9 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -47,6 +47,14 @@ Fortran code in order to uses the Fortran interface. A working example can be found together with equivalent examples in C and C++ in the ``examples/COUPLE/simple`` folder of the LAMMPS distribution. +.. admonitions:: Fortran compiler compatibility + + A fully Fortran 2003 compatible Fortran compiler is required. + This means that currently only GNU Fortran 9 and later are + compatible and thus the default compilers of Red Hat or CentOS 7 + and Ubuntu 18.04 LTS and not compatible. Either newer compilers + need to be installed or the Linux updated. + .. versionchanged:: TBD .. note:: diff --git a/examples/COUPLE/simple/CMakeLists.txt b/examples/COUPLE/simple/CMakeLists.txt index 46eedcf2d4..14c253e5a1 100644 --- a/examples/COUPLE/simple/CMakeLists.txt +++ b/examples/COUPLE/simple/CMakeLists.txt @@ -52,32 +52,37 @@ if(LAMMPS_SOURCE_DIR) include(CheckLanguage) check_language(Fortran) - - if(CMAKE_Fortran_COMPILER AND MPI_Fortran_FOUND AND MPI_Fortran_HAVE_F90_MODULE) + if(CMAKE_Fortran_COMPILER) enable_language(Fortran) + # need to check for MPI again to include Fortran components, since Fortran wasn't enabled before + find_package(MPI QUIET COMPONENTS Fortran) - if(NOT CMAKE_Fortran_COMPILER_ID) - message(STATUS "Skipping Tests for the LAMMPS Fortran Module: cannot identify Fortran compiler") + if(NOT (MPI_Fortran_FOUND AND MPI_Fortran_HAVE_F90_MODULE)) + message(STATUS "Insufficient MPI Fortran support. Skipping building simpleF90") return() endif() # GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module. + # GNU Fortran 7.x on Ubuntu 18.04LTS fails as well. # Work around flang being detected as GNU get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME) - if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) AND NOT (_tmp_fc STREQUAL "flang")) - message(FATAL_ERROR "Need GNU Fortran compiler version 6.x or later for unit testing") + if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) AND NOT (_tmp_fc STREQUAL "flang")) + message(STATUS "Need GNU Fortran compiler version 9.x or later for LAMMPS Fortran module") + return() endif() get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE) add_executable(simpleF90 ${LAMMPS_FORTRAN_MODULE} simple.f90) target_link_libraries(simpleF90 PRIVATE MPI::MPI_Fortran LAMMPS::lammps) - if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - target_compile_options(simpleF90 PRIVATE -fallow-argument-mismatch) - endif() get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME) if (_tmp_fc STREQUAL "flang") target_link_libraries(simpleF90 PRIVATE gfortran) endif() + include(CheckFortranCompilerFlag) + check_fortran_compiler_flag(-fallow-argument-mismatch HAS_MISMATCH) + if(HAS_MISMATCH) + target_compile_options(simpleF90 PRIVATE -fallow-argument-mismatch) + endif() endif() endif() diff --git a/fortran/README b/fortran/README index 6a19cd7dc2..2da71b2dc2 100644 --- a/fortran/README +++ b/fortran/README @@ -1,6 +1,7 @@ This directory contains Fortran code that acts as an interface to LAMMPS as a library and allows the LAMMPS library interface to be invoked from Fortran -code. It requires a Fortran compiler that supports the Fortran 2003 standard. +code. It requires a Fortran compiler that supports the Fortran 2003 standard +sufficiently well. For example GNU Fortran 9.x or later is currently required. This interface is based on and supersedes the previous Fortran interfaces in the examples/COUPLE/fortran* folders, but it is fully supported by the diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 9ca83d1741..7543e21948 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -88,8 +88,7 @@ if(BUILD_MPI) add_test(NAME RunCoupleSimpleCC COMMAND $ 1 ${LAMMPS_DIR}/examples/COUPLE/simple/in.lj) - find_package(MPI QUIET) - if(CMAKE_Fortran_COMPILER AND MPI_Fortran_FOUND AND MPI_Fortran_HAVE_F90_MODULE) + if($) add_test(NAME RunCoupleSimpleF90 COMMAND $ 1 ${LAMMPS_DIR}/examples/COUPLE/simple/in.lj) set_tests_properties(RunCoupleSimpleF90 PROPERTIES diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index cec38ae55c..138af65f18 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -14,10 +14,12 @@ if(CMAKE_Fortran_COMPILER) message(STATUS "Skipping Tests for the LAMMPS Fortran Module: cannot identify Fortran compiler") return() endif() - # GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module. Work around flang being detected as GNU + # GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module. + # Also GNU Fortran 7.x on Ubuntu18.04LTS is not sufficient. Work around flang being detected as GNU get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME) - if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) AND NOT (_tmp_fc STREQUAL "flang")) - message(FATAL_ERROR "Need GNU Fortran compiler version 6.x or later for unit testing") + if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) AND NOT (_tmp_fc STREQUAL "flang")) + message(STATUS "Need GNU Fortran compiler version 9.x or later for Fortran unit testing. Skipping...") + return() endif() get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE)