Explorar o código

Merge topic 'fortran-in-custom-targets' into release-3.27

d870a47e23 Tests/FortranModules: add a test for iface Fortran sources
e3d511fb9c Tests/FortranModules: also test INTERFACE targets with Fortran sources
978b68d3bb add_custom_target: Fix regression with Fortran sources
619aca80ae Tests/FortranModules: add a test case for #25223
45513c1a69 Tests/FortranModules: move issue 25112 fix from FortranOnly

Acked-by: Kitware Robot <[email protected]>
Merge-request: !8814
Brad King %!s(int64=2) %!d(string=hai) anos
pai
achega
ea3e9ba054

+ 3 - 2
Source/cmComputeLinkInformation.cxx

@@ -539,8 +539,9 @@ bool cmComputeLinkInformation::Compute()
         this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
         this->Target->GetType() == cmStateEnums::MODULE_LIBRARY ||
         this->Target->GetType() == cmStateEnums::STATIC_LIBRARY ||
-        this->Target->HaveCxx20ModuleSources() ||
-        this->Target->HaveFortranSources())) {
+        (this->Target->CanCompileSources() &&
+         (this->Target->HaveCxx20ModuleSources() ||
+          this->Target->HaveFortranSources())))) {
     return false;
   }
 

+ 9 - 0
Tests/FortranModules/CMakeLists.txt

@@ -125,3 +125,12 @@ add_subdirectory(Executable)
 if(CMake_TEST_Fortran_SUBMODULES)
   add_subdirectory(Submodules)
 endif()
+
+add_subdirectory(Issue25112)
+add_subdirectory(Issue25223)
+if( # Intel Fortran VS Integration breaks on custom targets with Fortran sources
+    NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+  add_subdirectory(Issue25252)
+  add_subdirectory(Issue25252-iface-target)
+endif()
+add_subdirectory(Issue25252-iface-sources)

+ 4 - 0
Tests/FortranModules/Issue25112/CMakeLists.txt

@@ -0,0 +1,4 @@
+set(CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
+add_library(objmod OBJECT objmod.f90)
+add_executable(objmain objmain.f90)
+target_link_libraries(objmain PRIVATE objmod)

+ 0 - 0
Tests/FortranOnly/objmain.f90 → Tests/FortranModules/Issue25112/objmain.f90


+ 0 - 0
Tests/FortranOnly/objmod.f90 → Tests/FortranModules/Issue25112/objmod.f90


+ 15 - 0
Tests/FortranModules/Issue25223/CMakeLists.txt

@@ -0,0 +1,15 @@
+# See https://gist.github.com/scivision/8e3070319f0577f7d3efcba863638cae
+set(CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
+add_library(m1 OBJECT m1.f90)
+
+add_library(m2 OBJECT m2.f90)
+target_link_libraries(m2 PRIVATE m1)
+
+add_library(m3 OBJECT m3.f90)
+target_link_libraries(m3 PRIVATE m2)
+
+add_library(m4 OBJECT m4.f90)
+target_link_libraries(m4 PRIVATE m3)
+
+add_executable(main25223 main.f90)
+target_link_libraries(main25223 PRIVATE m4 m3 m2 m1)

+ 11 - 0
Tests/FortranModules/Issue25223/m1.f90

@@ -0,0 +1,11 @@
+module m1
+
+implicit none
+
+contains
+
+pure real function pi()
+pi = 4*atan(1.)
+end function
+
+end module m1

+ 13 - 0
Tests/FortranModules/Issue25223/m2.f90

@@ -0,0 +1,13 @@
+module m2
+
+use m1, only : pi
+
+implicit none
+
+contains
+
+pure real function twopi()
+twopi = 2*pi()
+end function
+
+end module

+ 13 - 0
Tests/FortranModules/Issue25223/m3.f90

@@ -0,0 +1,13 @@
+module m3
+
+use m2, only : twopi
+
+implicit none
+
+contains
+
+pure real function fourpi()
+fourpi = 2*twopi()
+end function
+
+end module

+ 13 - 0
Tests/FortranModules/Issue25223/m4.f90

@@ -0,0 +1,13 @@
+module m4
+
+use m3, only : fourpi
+
+implicit none
+
+contains
+
+pure real function halfpi()
+halfpi = fourpi() / 8.0
+end function
+
+end module

+ 15 - 0
Tests/FortranModules/Issue25223/main.f90

@@ -0,0 +1,15 @@
+program main
+
+use m1, only : pi
+use m4, only : halfpi
+
+implicit none
+
+real :: rpi, rhalfpi
+
+rpi = pi() / 2
+rhalfpi = halfpi()
+
+print '(a,ES15.8)', 'floating point precision loss: ', rpi - rhalfpi
+
+end program

+ 9 - 0
Tests/FortranModules/Issue25252-iface-sources/CMakeLists.txt

@@ -0,0 +1,9 @@
+enable_language(C)
+
+add_library(fortran_source_iface_sources STATIC lib.c)
+target_sources(fortran_source_iface_sources
+  INTERFACE
+    "${CMAKE_CURRENT_SOURCE_DIR}/iface.f90")
+
+add_library(lib25252-iface-sources lib.f90)
+target_link_libraries(lib25252-iface-sources PRIVATE fortran_source_iface_sources)

+ 11 - 0
Tests/FortranModules/Issue25252-iface-sources/iface.f90

@@ -0,0 +1,11 @@
+module m1
+
+implicit none
+
+contains
+
+pure real function pi()
+pi = 4*atan(1.)
+end function
+
+end module m1

+ 4 - 0
Tests/FortranModules/Issue25252-iface-sources/lib.c

@@ -0,0 +1,4 @@
+int f()
+{
+  return 0;
+}

+ 13 - 0
Tests/FortranModules/Issue25252-iface-sources/lib.f90

@@ -0,0 +1,13 @@
+module lib
+
+use m1, only : pi
+
+implicit none
+
+contains
+
+pure real function func()
+func = pi()
+end function
+
+end module

+ 5 - 0
Tests/FortranModules/Issue25252-iface-target/CMakeLists.txt

@@ -0,0 +1,5 @@
+add_library(fortran_source_iface INTERFACE
+  iface.f90)
+
+add_library(lib25252-iface-target lib.f90)
+add_dependencies(lib25252-iface-target fortran_source_iface)

+ 5 - 0
Tests/FortranModules/Issue25252-iface-target/iface.f90

@@ -0,0 +1,5 @@
+program main
+
+implicit none
+
+end program

+ 11 - 0
Tests/FortranModules/Issue25252-iface-target/lib.f90

@@ -0,0 +1,11 @@
+module lib
+
+implicit none
+
+contains
+
+pure real function func()
+func = 1.0
+end function
+
+end module

+ 6 - 0
Tests/FortranModules/Issue25252/CMakeLists.txt

@@ -0,0 +1,6 @@
+add_custom_target(custom_target_with_fortran
+  COMMAND "${CMAKE_COMMAND}" -E echo "custom target with fortran sources"
+  SOURCES custom_target.f90)
+
+add_library(lib25252 lib.f90)
+add_dependencies(lib25252 custom_target_with_fortran)

+ 5 - 0
Tests/FortranModules/Issue25252/custom_target.f90

@@ -0,0 +1,5 @@
+program main
+
+implicit none
+
+end program

+ 11 - 0
Tests/FortranModules/Issue25252/lib.f90

@@ -0,0 +1,11 @@
+module lib
+
+implicit none
+
+contains
+
+pure real function func()
+func = 1.0
+end function
+
+end module

+ 0 - 6
Tests/FortranOnly/CMakeLists.txt

@@ -186,9 +186,3 @@ if(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF AND
 
   set_property(SOURCE no_preprocess_source_upper.F no_preprocess_source_fpp.fpp PROPERTY Fortran_PREPROCESS OFF)
 endif()
-
-# Issue 25112
-set(CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
-add_library(objmod OBJECT objmod.f90)
-add_executable(objmain objmain.f90)
-target_link_libraries(objmain PRIVATE objmod)