summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-05-08 17:04:46 -0400
committerBrad King <brad.king@kitware.com>2023-05-09 09:56:42 -0400
commit1f1894af1fb263762c062c55fce28b5f9678dc5e (patch)
tree5c02c55f2849221450d3c4ff1c4e14814c7a3475 /Tests
parent9075ebda60922d8d11dd15d15c714c36ec3874cd (diff)
downloadcmake-1f1894af1fb263762c062c55fce28b5f9678dc5e.tar.gz
Ninja: Fix Fortran INCLUDE directive dependencies when not preprocessing
Since commit b0a6161190 (Fortran: Add Fortran_PREPROCESS property, 2020-04-24, v3.18.0-rc1~116^2~3), if `Fortran_PREPROCESS` is `OFF`, the Ninja generator does not properly detect dependencies on sources loaded via the Fortran INCLUDE directive. Fix this and add a test.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/BuildDepends/FortranInclude-build1-stderr.txt1
-rw-r--r--Tests/RunCMake/BuildDepends/FortranInclude-build2-stderr.txt1
-rw-r--r--Tests/RunCMake/BuildDepends/FortranInclude.cmake20
-rw-r--r--Tests/RunCMake/BuildDepends/FortranInclude.step1.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/FortranInclude.step2.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/FortranIncludeNoPreprocess.f3
-rw-r--r--Tests/RunCMake/BuildDepends/FortranIncludePreprocess.F3
-rw-r--r--Tests/RunCMake/BuildDepends/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/CMakeLists.txt4
9 files changed, 40 insertions, 0 deletions
diff --git a/Tests/RunCMake/BuildDepends/FortranInclude-build1-stderr.txt b/Tests/RunCMake/BuildDepends/FortranInclude-build1-stderr.txt
new file mode 100644
index 0000000000..8d98f9debd
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranInclude-build1-stderr.txt
@@ -0,0 +1 @@
+.*
diff --git a/Tests/RunCMake/BuildDepends/FortranInclude-build2-stderr.txt b/Tests/RunCMake/BuildDepends/FortranInclude-build2-stderr.txt
new file mode 100644
index 0000000000..8d98f9debd
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranInclude-build2-stderr.txt
@@ -0,0 +1 @@
+.*
diff --git a/Tests/RunCMake/BuildDepends/FortranInclude.cmake b/Tests/RunCMake/BuildDepends/FortranInclude.cmake
new file mode 100644
index 0000000000..fa9f39912d
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranInclude.cmake
@@ -0,0 +1,20 @@
+enable_language(Fortran)
+
+set(check_pairs "")
+
+add_executable(preprocess FortranIncludePreprocess.F)
+set_property(TARGET preprocess PROPERTY Fortran_PREPROCESS ON)
+target_include_directories(preprocess PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+list(APPEND check_pairs "$<TARGET_FILE:preprocess>|${CMAKE_CURRENT_BINARY_DIR}/preprocess.inc")
+
+# LCC < 1.24 has no way to disable Fortran preprocessor
+if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LCC" OR CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL "1.24.00")
+ add_executable(no_preprocess FortranIncludeNoPreprocess.f)
+ set_property(TARGET no_preprocess PROPERTY Fortran_PREPROCESS OFF)
+ target_include_directories(no_preprocess PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ list(APPEND check_pairs "$<TARGET_FILE:no_preprocess>|${CMAKE_CURRENT_BINARY_DIR}/no_preprocess.inc")
+endif()
+
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+set(check_pairs \"${check_pairs}\")
+")
diff --git a/Tests/RunCMake/BuildDepends/FortranInclude.step1.cmake b/Tests/RunCMake/BuildDepends/FortranInclude.step1.cmake
new file mode 100644
index 0000000000..53fdc2fe0f
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranInclude.step1.cmake
@@ -0,0 +1,2 @@
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/preprocess.inc" "\tPRINT *, 'FortranIncludePreprocess 1'\n")
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/no_preprocess.inc" "\tPRINT *, 'FortranIncludeNoPreprocess 1'\n")
diff --git a/Tests/RunCMake/BuildDepends/FortranInclude.step2.cmake b/Tests/RunCMake/BuildDepends/FortranInclude.step2.cmake
new file mode 100644
index 0000000000..05a9f11c6b
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranInclude.step2.cmake
@@ -0,0 +1,2 @@
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/preprocess.inc" "\tPRINT *, 'FortranIncludePreprocess 2'\n")
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/no_preprocess.inc" "\tPRINT *, 'FortranIncludeNoPreprocess 2'\n")
diff --git a/Tests/RunCMake/BuildDepends/FortranIncludeNoPreprocess.f b/Tests/RunCMake/BuildDepends/FortranIncludeNoPreprocess.f
new file mode 100644
index 0000000000..00b04dc446
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranIncludeNoPreprocess.f
@@ -0,0 +1,3 @@
+ PROGRAM FortranIncludeNoPreprocess
+ INCLUDE 'no_preprocess.inc'
+ END
diff --git a/Tests/RunCMake/BuildDepends/FortranIncludePreprocess.F b/Tests/RunCMake/BuildDepends/FortranIncludePreprocess.F
new file mode 100644
index 0000000000..680313a806
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/FortranIncludePreprocess.F
@@ -0,0 +1,3 @@
+ PROGRAM FortranIncludePreprocess
+#include "preprocess.inc"
+ END
diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
index b52758045e..dfa4f498e7 100644
--- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
+++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
@@ -68,6 +68,10 @@ if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
unset(run_BuildDepends_skip_step_2)
endif()
+if(CMake_TEST_Fortran)
+ run_BuildDepends(FortranInclude)
+endif()
+
run_BuildDepends(Custom-Symbolic-and-Byproduct)
run_BuildDepends(Custom-Always)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 3007660dee..75f2d3507d 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -292,6 +292,10 @@ if(NOT DEFINED CMake_TEST_BuildDepends_GNU_AS
endif()
endif()
+if(CMAKE_Fortran_COMPILER)
+ list(APPEND BuildDepends_ARGS -DCMake_TEST_Fortran=1)
+endif()
+
add_RunCMake_test(BuildDepends
-DMSVC_VERSION=${MSVC_VERSION}
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}