summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Junghans <junghans@votca.org>2024-01-25 20:10:54 (GMT)
committerBrad King <brad.king@kitware.com>2024-07-22 20:50:33 (GMT)
commit98d0f918ba74003bd66f4d12d8bcbe69b945caf2 (patch)
tree197a558c8d4779d1d0ebb4ae068b98632a7de92f
parentc6f81bdacfeb2e99771ec4a5750964fee5e97dd3 (diff)
downloadCMake-98d0f918ba74003bd66f4d12d8bcbe69b945caf2.zip
CMake-98d0f918ba74003bd66f4d12d8bcbe69b945caf2.tar.gz
CMake-98d0f918ba74003bd66f4d12d8bcbe69b945caf2.tar.bz2
LFortran: Add support for this compiler
Fixes: #25419
-rw-r--r--Help/release/dev/lfortran.rst5
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_ID.rst1
-rw-r--r--Modules/CMakeDetermineFortranCompiler.cmake4
-rw-r--r--Modules/CMakeFortranCompilerId.F.in5
-rw-r--r--Modules/Compiler/LFortran-Fortran.cmake14
-rw-r--r--Modules/FortranCInterface/CMakeLists.txt4
-rw-r--r--Tests/CMakeLists.txt5
-rw-r--r--Tests/Fortran/CMakeLists.txt4
-rw-r--r--Tests/FortranOnly/CMakeLists.txt4
-rw-r--r--Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/BuildDepends/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/Ninja/RunCMakeTest.cmake5
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt4
13 files changed, 61 insertions, 3 deletions
diff --git a/Help/release/dev/lfortran.rst b/Help/release/dev/lfortran.rst
new file mode 100644
index 0000000..e63835e
--- /dev/null
+++ b/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``.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
index b1e2687..72cd832 100644
--- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst
+++ b/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`_
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index 613b0c4..f051163 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/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()
diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in
index a040073..d97bd68 100644
--- a/Modules/CMakeFortranCompilerId.F.in
+++ b/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
diff --git a/Modules/Compiler/LFortran-Fortran.cmake b/Modules/Compiler/LFortran-Fortran.cmake
new file mode 100644
index 0000000..4180730
--- /dev/null
+++ b/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")
diff --git a/Modules/FortranCInterface/CMakeLists.txt b/Modules/FortranCInterface/CMakeLists.txt
index 2e8e14f..56a045c 100644
--- a/Modules/FortranCInterface/CMakeLists.txt
+++ b/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)
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 69f48f5..0ff2cdc 100644
--- a/Tests/CMakeLists.txt
+++ b/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"
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
index 41d3b4e..71f9413 100644
--- a/Tests/Fortran/CMakeLists.txt
+++ b/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)
diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt
index 73312a0..e4a5019 100644
--- a/Tests/FortranOnly/CMakeLists.txt
+++ b/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)
diff --git a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt b/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
index 3872b56..eea8981 100644
--- a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
+++ b/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)
diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
index a5f9622..d5be807 100644
--- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
+++ b/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()
diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
index c247ac4..d1f99b2 100644
--- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake
+++ b/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()
diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
index 8918d98..f8c2a25 100644
--- a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
+++ b/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