From 45513c1a69853372a1abf137adea262e5df7df71 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Sep 2023 19:41:47 -0400 Subject: Tests/FortranModules: move issue 25112 fix from FortranOnly It involves modules, so it belongs in the `FortranModules` test set. --- Tests/FortranModules/CMakeLists.txt | 2 ++ Tests/FortranModules/Issue25112/CMakeLists.txt | 4 ++++ Tests/FortranModules/Issue25112/objmain.f90 | 5 +++++ Tests/FortranModules/Issue25112/objmod.f90 | 7 +++++++ Tests/FortranOnly/CMakeLists.txt | 6 ------ Tests/FortranOnly/objmain.f90 | 5 ----- Tests/FortranOnly/objmod.f90 | 7 ------- 7 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 Tests/FortranModules/Issue25112/CMakeLists.txt create mode 100644 Tests/FortranModules/Issue25112/objmain.f90 create mode 100644 Tests/FortranModules/Issue25112/objmod.f90 delete mode 100644 Tests/FortranOnly/objmain.f90 delete mode 100644 Tests/FortranOnly/objmod.f90 diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index 5c76132..487491f 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/Tests/FortranModules/CMakeLists.txt @@ -125,3 +125,5 @@ add_subdirectory(Executable) if(CMake_TEST_Fortran_SUBMODULES) add_subdirectory(Submodules) endif() + +add_subdirectory(Issue25112) diff --git a/Tests/FortranModules/Issue25112/CMakeLists.txt b/Tests/FortranModules/Issue25112/CMakeLists.txt new file mode 100644 index 0000000..cf0c69e --- /dev/null +++ b/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) diff --git a/Tests/FortranModules/Issue25112/objmain.f90 b/Tests/FortranModules/Issue25112/objmain.f90 new file mode 100644 index 0000000..d41d454 --- /dev/null +++ b/Tests/FortranModules/Issue25112/objmain.f90 @@ -0,0 +1,5 @@ +program main + use objmod, only : hello + implicit none + call hello() +end program diff --git a/Tests/FortranModules/Issue25112/objmod.f90 b/Tests/FortranModules/Issue25112/objmod.f90 new file mode 100644 index 0000000..6b79cc7 --- /dev/null +++ b/Tests/FortranModules/Issue25112/objmod.f90 @@ -0,0 +1,7 @@ +module objmod + implicit none +contains + subroutine hello() + print '(a)', "hello world" + end subroutine hello +end module objmod diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index dfc28dd..02bf2b8 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/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) diff --git a/Tests/FortranOnly/objmain.f90 b/Tests/FortranOnly/objmain.f90 deleted file mode 100644 index d41d454..0000000 --- a/Tests/FortranOnly/objmain.f90 +++ /dev/null @@ -1,5 +0,0 @@ -program main - use objmod, only : hello - implicit none - call hello() -end program diff --git a/Tests/FortranOnly/objmod.f90 b/Tests/FortranOnly/objmod.f90 deleted file mode 100644 index 6b79cc7..0000000 --- a/Tests/FortranOnly/objmod.f90 +++ /dev/null @@ -1,7 +0,0 @@ -module objmod - implicit none -contains - subroutine hello() - print '(a)', "hello world" - end subroutine hello -end module objmod -- cgit v0.12 From 619aca80ae94b909085344af1098c7f4bf80f0c2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Sep 2023 19:58:49 -0400 Subject: Tests/FortranModules: add a test case for #25223 --- Tests/FortranModules/CMakeLists.txt | 1 + Tests/FortranModules/Issue25223/CMakeLists.txt | 15 +++++++++++++++ Tests/FortranModules/Issue25223/m1.f90 | 11 +++++++++++ Tests/FortranModules/Issue25223/m2.f90 | 13 +++++++++++++ Tests/FortranModules/Issue25223/m3.f90 | 13 +++++++++++++ Tests/FortranModules/Issue25223/m4.f90 | 13 +++++++++++++ Tests/FortranModules/Issue25223/main.f90 | 15 +++++++++++++++ 7 files changed, 81 insertions(+) create mode 100644 Tests/FortranModules/Issue25223/CMakeLists.txt create mode 100644 Tests/FortranModules/Issue25223/m1.f90 create mode 100644 Tests/FortranModules/Issue25223/m2.f90 create mode 100644 Tests/FortranModules/Issue25223/m3.f90 create mode 100644 Tests/FortranModules/Issue25223/m4.f90 create mode 100644 Tests/FortranModules/Issue25223/main.f90 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 -- cgit v0.12 From 978b68d3bbb44e3bc6adbe5109eb8295f8232ce6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Sep 2023 19:59:56 -0400 Subject: add_custom_target: Fix regression with Fortran sources Since commit 74b1d6caf3 (cmComputeLinkInformation: compute link info for module-using targets, 2023-09-05, v3.27.5~7^2) we accidentally try to compute link information for custom targets if they have Fortran sources. For module dependencies, we only need to consider target types that can compile. Fixes: #25252 --- Source/cmComputeLinkInformation.cxx | 5 +++-- Tests/FortranModules/CMakeLists.txt | 4 ++++ Tests/FortranModules/Issue25252/CMakeLists.txt | 6 ++++++ Tests/FortranModules/Issue25252/custom_target.f90 | 5 +++++ Tests/FortranModules/Issue25252/lib.f90 | 11 +++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Tests/FortranModules/Issue25252/CMakeLists.txt create mode 100644 Tests/FortranModules/Issue25252/custom_target.f90 create mode 100644 Tests/FortranModules/Issue25252/lib.f90 diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 4804565..7d3675e 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/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; } diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index f5b2822..8ebd9b2 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/Tests/FortranModules/CMakeLists.txt @@ -128,3 +128,7 @@ 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) +endif() diff --git a/Tests/FortranModules/Issue25252/CMakeLists.txt b/Tests/FortranModules/Issue25252/CMakeLists.txt new file mode 100644 index 0000000..8111c42 --- /dev/null +++ b/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) diff --git a/Tests/FortranModules/Issue25252/custom_target.f90 b/Tests/FortranModules/Issue25252/custom_target.f90 new file mode 100644 index 0000000..0528d41 --- /dev/null +++ b/Tests/FortranModules/Issue25252/custom_target.f90 @@ -0,0 +1,5 @@ +program main + +implicit none + +end program diff --git a/Tests/FortranModules/Issue25252/lib.f90 b/Tests/FortranModules/Issue25252/lib.f90 new file mode 100644 index 0000000..a6d7fa6 --- /dev/null +++ b/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 -- cgit v0.12 From e3d511fb9ca895bcf5aa74640e4a5df640bf9503 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Sep 2023 20:12:14 -0400 Subject: Tests/FortranModules: also test INTERFACE targets with Fortran sources --- Tests/FortranModules/CMakeLists.txt | 1 + Tests/FortranModules/Issue25252-iface-target/CMakeLists.txt | 5 +++++ Tests/FortranModules/Issue25252-iface-target/iface.f90 | 5 +++++ Tests/FortranModules/Issue25252-iface-target/lib.f90 | 11 +++++++++++ 4 files changed, 22 insertions(+) create mode 100644 Tests/FortranModules/Issue25252-iface-target/CMakeLists.txt create mode 100644 Tests/FortranModules/Issue25252-iface-target/iface.f90 create mode 100644 Tests/FortranModules/Issue25252-iface-target/lib.f90 diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index 8ebd9b2..895c14c 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/Tests/FortranModules/CMakeLists.txt @@ -131,4 +131,5 @@ 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() diff --git a/Tests/FortranModules/Issue25252-iface-target/CMakeLists.txt b/Tests/FortranModules/Issue25252-iface-target/CMakeLists.txt new file mode 100644 index 0000000..b312fcd --- /dev/null +++ b/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) diff --git a/Tests/FortranModules/Issue25252-iface-target/iface.f90 b/Tests/FortranModules/Issue25252-iface-target/iface.f90 new file mode 100644 index 0000000..0528d41 --- /dev/null +++ b/Tests/FortranModules/Issue25252-iface-target/iface.f90 @@ -0,0 +1,5 @@ +program main + +implicit none + +end program diff --git a/Tests/FortranModules/Issue25252-iface-target/lib.f90 b/Tests/FortranModules/Issue25252-iface-target/lib.f90 new file mode 100644 index 0000000..a6d7fa6 --- /dev/null +++ b/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 -- cgit v0.12 From d870a47e2382b15e66f2ef1990415e37d7723e25 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Sep 2023 20:21:02 -0400 Subject: Tests/FortranModules: add a test for iface Fortran sources This tests that a library that doesn't compile Fortran sources but provides one via `INTERFACE` sources works as intended. --- Tests/FortranModules/CMakeLists.txt | 1 + .../FortranModules/Issue25252-iface-sources/CMakeLists.txt | 9 +++++++++ Tests/FortranModules/Issue25252-iface-sources/iface.f90 | 11 +++++++++++ Tests/FortranModules/Issue25252-iface-sources/lib.c | 4 ++++ Tests/FortranModules/Issue25252-iface-sources/lib.f90 | 13 +++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 Tests/FortranModules/Issue25252-iface-sources/CMakeLists.txt create mode 100644 Tests/FortranModules/Issue25252-iface-sources/iface.f90 create mode 100644 Tests/FortranModules/Issue25252-iface-sources/lib.c create mode 100644 Tests/FortranModules/Issue25252-iface-sources/lib.f90 diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index 895c14c..00f3e57 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/Tests/FortranModules/CMakeLists.txt @@ -133,3 +133,4 @@ if( # Intel Fortran VS Integration breaks on custom targets with Fortran sources add_subdirectory(Issue25252) add_subdirectory(Issue25252-iface-target) endif() +add_subdirectory(Issue25252-iface-sources) diff --git a/Tests/FortranModules/Issue25252-iface-sources/CMakeLists.txt b/Tests/FortranModules/Issue25252-iface-sources/CMakeLists.txt new file mode 100644 index 0000000..574435f --- /dev/null +++ b/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) diff --git a/Tests/FortranModules/Issue25252-iface-sources/iface.f90 b/Tests/FortranModules/Issue25252-iface-sources/iface.f90 new file mode 100644 index 0000000..6b5ddd5 --- /dev/null +++ b/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 diff --git a/Tests/FortranModules/Issue25252-iface-sources/lib.c b/Tests/FortranModules/Issue25252-iface-sources/lib.c new file mode 100644 index 0000000..6ccdb8d --- /dev/null +++ b/Tests/FortranModules/Issue25252-iface-sources/lib.c @@ -0,0 +1,4 @@ +int f() +{ + return 0; +} diff --git a/Tests/FortranModules/Issue25252-iface-sources/lib.f90 b/Tests/FortranModules/Issue25252-iface-sources/lib.f90 new file mode 100644 index 0000000..f971909 --- /dev/null +++ b/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 -- cgit v0.12