LFortran: Add support for this compiler

Fixes: #25419
This commit is contained in:
Christoph Junghans 2024-01-25 13:10:54 -07:00 committed by Brad King
parent c6f81bdacf
commit 98d0f918ba
13 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,5 @@
lfortran
--------
* The LFortran compiler is now supported with
:variable:`compiler id <CMAKE_<LANG>_COMPILER_ID>` ``LFortran``.

View File

@ -32,6 +32,7 @@ Value Name
``Intel`` Intel Classic Compiler
``IntelLLVM`` `Intel LLVM-Based Compiler`_
``LCC`` MCST Elbrus C/C++/Fortran Compiler
``LFortran`` LFortran Fortran Compiler
``MSVC`` `Microsoft Visual Studio`_
``NVHPC`` `NVIDIA HPC Compiler`_
``NVIDIA`` `NVIDIA CUDA Compiler`_

View File

@ -60,6 +60,7 @@ else()
# ifx: Intel Fortran LLVM-based compiler
# ifort: Intel Classic Fortran compiler
# nagfor: NAG Fortran compiler
# lfortran: LFortran Fortran Compiler
#
# GNU is last to be searched,
# so if you paid for a compiler it is picked by default.
@ -108,6 +109,9 @@ else()
# Intel on windows does not preprocess by default.
"-fpp"
# LFortran does not preprocess by default.
"--cpp-infer"
)
endif()

View File

@ -179,6 +179,11 @@
# elif defined(__FRT_version__)
PRINT *, 'INFO:compiler_version['//__FRT_version__//']'
# endif
#elif defined(__LFORTRAN__)
PRINT *, 'INFO:compiler[LFortran]'
#define COMPILER_VERSION_MAJOR DEC(__LFORTRAN_MAJOR__)
#define COMPILER_VERSION_MINOR DEC(__LFORTRAN_MINOR__)
#define COMPILER_VERSION_PATCH DEC(__LFORTRAN_PATCHLEVEL__)
#else
PRINT *, 'INFO:compiler[]'
#endif

View File

@ -0,0 +1,14 @@
string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g")
string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " ")
string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3")
string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g")
set(CMAKE_Fortran_MODDIR_FLAG "-J")
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "--fixed-form")
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "--cpp")
set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "--no-cpp")
set(CMAKE_Fortran_PREPROCESS_SOURCE "<CMAKE_Fortran_COMPILER> --cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> --cpp-infer <DEFINES> <INCLUDES> <FLAGS> --generate-object-code -c <SOURCE> -o <OBJECT>")
set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "--shared")
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-Wl,-export-dynamic")

View File

@ -100,6 +100,10 @@ target_link_libraries(symbols PUBLIC myfort)
# the C compiler produces PIC even if it is not its default.
set_property(TARGET symbols PROPERTY POSITION_INDEPENDENT_CODE 1)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface)
endif()
# Require symbols through Fortran.
add_executable(FortranCInterface main.F call_sub.f ${call_mod})
target_link_libraries(FortranCInterface PUBLIC symbols)

View File

@ -3335,7 +3335,10 @@ if(BUILD_TESTING)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran")
set_property(TEST Fortran APPEND PROPERTY LABELS "Fortran")
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90
# FIXME(lfortran): The compiler fails on the test's modules.
AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran"
)
add_test(FortranModules ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FortranModules"

View File

@ -37,6 +37,10 @@ if(WIN32 AND NOT CYGWIN)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface)
endif()
add_library(hello STATIC hello.f)
add_library(world ${_SHARED} world.f ${world_def})
add_executable(testf testf.f)

View File

@ -7,6 +7,10 @@ if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" MATCHES "^Intel(L
string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO " -Z7")
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface)
endif()
# create a library with hello and world functions
add_library(FortranOnlylib hello.f world.f)
set_property(TARGET FortranOnlylib PROPERTY Fortran_FORMAT FIXED)

View File

@ -3,6 +3,10 @@ project(CheckIPOSupported-Fortran LANGUAGES Fortran)
cmake_policy(SET CMP0069 NEW)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)

View File

@ -68,7 +68,10 @@ if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
unset(run_BuildDepends_skip_step_2)
endif()
if(CMake_TEST_Fortran)
if(CMake_TEST_Fortran
# FIXME(lfortran): The compiler fails on the test's includes.
AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran"
)
run_BuildDepends(FortranInclude)
endif()

View File

@ -108,7 +108,10 @@ run_cmake(JobPoolUsesTerminal)
run_cmake(RspFileC)
run_cmake(RspFileCXX)
if(CMake_TEST_Fortran)
if(CMake_TEST_Fortran
# FIXME(lfortran): The compiler does not support response files.
AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran"
)
run_cmake(RspFileFortran)
endif()

View File

@ -25,6 +25,10 @@ target_link_libraries(sunq sunquad)
set(${result} "${RESULT}" PARENT_SCOPE)
endfunction()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface)
endif()
# check for the fortran c interface mangling
include(FortranCInterface)
FortranCInterface_HEADER(HelloWorldFCMangle.h