Переглянути джерело

LFortran: Add support for this compiler

Fixes: #25419
Christoph Junghans 1 рік тому
батько
коміт
98d0f918ba

+ 5 - 0
Help/release/dev/lfortran.rst

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

+ 1 - 0
Help/variable/CMAKE_LANG_COMPILER_ID.rst

@@ -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`_

+ 4 - 0
Modules/CMakeDetermineFortranCompiler.cmake

@@ -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()
 

+ 5 - 0
Modules/CMakeFortranCompilerId.F.in

@@ -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

+ 14 - 0
Modules/Compiler/LFortran-Fortran.cmake

@@ -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")

+ 4 - 0
Modules/FortranCInterface/CMakeLists.txt

@@ -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)

+ 4 - 1
Tests/CMakeLists.txt

@@ -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"

+ 4 - 0
Tests/Fortran/CMakeLists.txt

@@ -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)

+ 4 - 0
Tests/FortranOnly/CMakeLists.txt

@@ -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)

+ 4 - 0
Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt

@@ -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)

+ 4 - 1
Tests/RunCMake/BuildDepends/RunCMakeTest.cmake

@@ -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()
 

+ 4 - 1
Tests/RunCMake/Ninja/RunCMakeTest.cmake

@@ -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()
 

+ 4 - 0
Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt

@@ -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