summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-09-18 23:58:49 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-09-18 23:58:49 (GMT)
commit619aca80ae94b909085344af1098c7f4bf80f0c2 (patch)
treebf0b7ce17856b67d035183197edee87f55579e40
parent45513c1a69853372a1abf137adea262e5df7df71 (diff)
downloadCMake-619aca80ae94b909085344af1098c7f4bf80f0c2.zip
CMake-619aca80ae94b909085344af1098c7f4bf80f0c2.tar.gz
CMake-619aca80ae94b909085344af1098c7f4bf80f0c2.tar.bz2
Tests/FortranModules: add a test case for #25223
-rw-r--r--Tests/FortranModules/CMakeLists.txt1
-rw-r--r--Tests/FortranModules/Issue25223/CMakeLists.txt15
-rw-r--r--Tests/FortranModules/Issue25223/m1.f9011
-rw-r--r--Tests/FortranModules/Issue25223/m2.f9013
-rw-r--r--Tests/FortranModules/Issue25223/m3.f9013
-rw-r--r--Tests/FortranModules/Issue25223/m4.f9013
-rw-r--r--Tests/FortranModules/Issue25223/main.f9015
7 files changed, 81 insertions, 0 deletions
diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt
index 487491f..f5b2822 100644
--- a/Tests/FortranModules/CMakeLists.txt
+++ b/Tests/FortranModules/CMakeLists.txt
@@ -127,3 +127,4 @@ if(CMake_TEST_Fortran_SUBMODULES)
endif()
add_subdirectory(Issue25112)
+add_subdirectory(Issue25223)
diff --git a/Tests/FortranModules/Issue25223/CMakeLists.txt b/Tests/FortranModules/Issue25223/CMakeLists.txt
new file mode 100644
index 0000000..f2afcb9
--- /dev/null
+++ b/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)
diff --git a/Tests/FortranModules/Issue25223/m1.f90 b/Tests/FortranModules/Issue25223/m1.f90
new file mode 100644
index 0000000..6b5ddd5
--- /dev/null
+++ b/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
diff --git a/Tests/FortranModules/Issue25223/m2.f90 b/Tests/FortranModules/Issue25223/m2.f90
new file mode 100644
index 0000000..c614d0e
--- /dev/null
+++ b/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
diff --git a/Tests/FortranModules/Issue25223/m3.f90 b/Tests/FortranModules/Issue25223/m3.f90
new file mode 100644
index 0000000..a29ca84
--- /dev/null
+++ b/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
diff --git a/Tests/FortranModules/Issue25223/m4.f90 b/Tests/FortranModules/Issue25223/m4.f90
new file mode 100644
index 0000000..b1ec1a8
--- /dev/null
+++ b/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
diff --git a/Tests/FortranModules/Issue25223/main.f90 b/Tests/FortranModules/Issue25223/main.f90
new file mode 100644
index 0000000..3ec3920
--- /dev/null
+++ b/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