From daf6cc89ee62df12cc9bbc6cfd396104d10df139 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 9 Jan 2025 15:49:19 +0530 Subject: [PATCH] LFortran: Remove hard-coded --generate-object-code flag This was added in commit 98d0f918ba (LFortran: Add support for this compiler, 2024-01-25, v3.31.0-rc1~303^2~2) because it is needed for cases covered by CMake's Fortran tests. However, it does not work with Fortran modules and breaks lfortran's own `examples/project1`. Move the flag to the test cases that need it, just as the original commit did with `--implicit-interface`. Fixes: #26597 Co-authored-by: Brad King --- Modules/Compiler/LFortran-Fortran.cmake | 2 +- Modules/FortranCInterface/CMakeLists.txt | 2 +- Modules/FortranCInterface/Verify/CMakeLists.txt | 4 ++++ Tests/Fortran/CMakeLists.txt | 2 +- Tests/FortranOnly/CMakeLists.txt | 2 +- Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt | 2 +- Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Modules/Compiler/LFortran-Fortran.cmake b/Modules/Compiler/LFortran-Fortran.cmake index 9090e1d570..f3f28cc172 100644 --- a/Modules/Compiler/LFortran-Fortran.cmake +++ b/Modules/Compiler/LFortran-Fortran.cmake @@ -9,6 +9,6 @@ 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 " --cpp -E > ") -set(CMAKE_Fortran_COMPILE_OBJECT " --cpp-infer --generate-object-code -c -o ") +set(CMAKE_Fortran_COMPILE_OBJECT " --cpp-infer -c -o ") 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 56a045cc98..bc3309670c 100644 --- a/Modules/FortranCInterface/CMakeLists.txt +++ b/Modules/FortranCInterface/CMakeLists.txt @@ -101,7 +101,7 @@ target_link_libraries(symbols PUBLIC myfort) set_property(TARGET symbols PROPERTY POSITION_INDEPENDENT_CODE 1) if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") - add_compile_options(--implicit-interface) + add_compile_options(--implicit-interface --generate-object-code) endif() # Require symbols through Fortran. diff --git a/Modules/FortranCInterface/Verify/CMakeLists.txt b/Modules/FortranCInterface/Verify/CMakeLists.txt index 98cdeb7504..caf42061c3 100644 --- a/Modules/FortranCInterface/Verify/CMakeLists.txt +++ b/Modules/FortranCInterface/Verify/CMakeLists.txt @@ -4,6 +4,10 @@ cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(VerifyFortranC C Fortran) +if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") + add_compile_options("$<$:--generate-object-code>") +endif() + option(VERIFY_CXX "Whether to verify C++ and Fortran" OFF) if(VERIFY_CXX) enable_language(CXX) diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index d488efff63..456a9fe37a 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -38,7 +38,7 @@ if(WIN32 AND NOT CYGWIN) endif() if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") - add_compile_options("$<$:--implicit-interface>") + add_compile_options("$<$:--implicit-interface;--generate-object-code>") endif() add_library(hello STATIC hello.f) diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index fa1012b913..c9f89cb326 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/Tests/FortranOnly/CMakeLists.txt @@ -8,7 +8,7 @@ if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" MATCHES "^Intel(L endif() if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") - add_compile_options(--implicit-interface) + add_compile_options(--implicit-interface --generate-object-code) endif() # create a library with hello and world functions diff --git a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt b/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt index a44a75dc34..4d03a93891 100644 --- a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt +++ b/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt @@ -4,7 +4,7 @@ project(CheckIPOSupported-Fortran LANGUAGES Fortran) cmake_policy(SET CMP0069 NEW) if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") - add_compile_options(--implicit-interface) + add_compile_options(--implicit-interface --generate-object-code) endif() include(CheckIPOSupported) diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt index 6c7265f052..5689289b78 100644 --- a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt +++ b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt @@ -26,7 +26,7 @@ target_link_libraries(sunq sunquad) endfunction() if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran") - add_compile_options(--implicit-interface) + add_compile_options(--implicit-interface --generate-object-code) endif() # check for the fortran c interface mangling