summaryrefslogtreecommitdiffstats
path: root/Tests/Module
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-09-07 19:09:19 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-07 19:17:33 (GMT)
commitf9973166e82c3f5d8e05e2ab57aceb15ff267295 (patch)
tree314c324832b45f310b2982a7a3c53da18872b686 /Tests/Module
parent024eecd9106a4d3a6adebd918c0afdceb02cd4bb (diff)
downloadCMake-f9973166e82c3f5d8e05e2ab57aceb15ff267295.zip
CMake-f9973166e82c3f5d8e05e2ab57aceb15ff267295.tar.gz
CMake-f9973166e82c3f5d8e05e2ab57aceb15ff267295.tar.bz2
ExternalData: Tolerate files duplicated across multiple targets
If multiple ExternalData_Target_Add calls generate the same output file then we need to avoid calling add_custom_command multiple times with that output. This was already done within a single target by setting a variable in the local function scope. This will not be visible in other calls though so we need to use a directory property instead to prevent adding a custom command multiple times for one output in a directory. Normally it is not safe to have multiple custom commands that produce the same output file across multiple independent targets, but since we use atomic replacement of outputs the resulting races should not be a problem. For the convenience of projects, tolerate this instead of diagnosing it. In particular, we previously allowed up to two copies of the custom command in one directory because CMake has a fallback from MAIN_DEPENDENCY to an `<output>.rule` file. While at it, add a note to the documentation that typically only one external data target should be needed for a project. Reported-by: David Manthey <david.manthey@kitware.com>
Diffstat (limited to 'Tests/Module')
-rw-r--r--Tests/Module/ExternalData/CMakeLists.txt1
-rw-r--r--Tests/Module/ExternalData/Data5/CMakeLists.txt22
-rw-r--r--Tests/Module/ExternalData/Data5/Data5Check.cmake4
3 files changed, 27 insertions, 0 deletions
diff --git a/Tests/Module/ExternalData/CMakeLists.txt b/Tests/Module/ExternalData/CMakeLists.txt
index f07ab71..1018dd8 100644
--- a/Tests/Module/ExternalData/CMakeLists.txt
+++ b/Tests/Module/ExternalData/CMakeLists.txt
@@ -53,4 +53,5 @@ ExternalData_Add_Target(Data1)
add_subdirectory(Data2)
add_subdirectory(Data3)
add_subdirectory(Data4)
+add_subdirectory(Data5)
add_subdirectory(DataNoSymlinks)
diff --git a/Tests/Module/ExternalData/Data5/CMakeLists.txt b/Tests/Module/ExternalData/Data5/CMakeLists.txt
new file mode 100644
index 0000000..13c7fab
--- /dev/null
+++ b/Tests/Module/ExternalData/Data5/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Test adding the same data file in multiple tests
+ExternalData_Add_Test(Data5.A
+ NAME Data5Check.A
+ COMMAND ${CMAKE_COMMAND}
+ -D Data5=DATA{../Data.dat}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
+ )
+ExternalData_Add_Target(Data5.A)
+ExternalData_Add_Test(Data5.B
+ NAME Data5Check.B
+ COMMAND ${CMAKE_COMMAND}
+ -D Data5=DATA{../Data.dat}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
+ )
+ExternalData_Add_Target(Data5.B)
+ExternalData_Add_Test(Data5.C
+ NAME Data5Check.C
+ COMMAND ${CMAKE_COMMAND}
+ -D Data5=DATA{../Data.dat}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
+ )
+ExternalData_Add_Target(Data5.C)
diff --git a/Tests/Module/ExternalData/Data5/Data5Check.cmake b/Tests/Module/ExternalData/Data5/Data5Check.cmake
new file mode 100644
index 0000000..4dea9a4
--- /dev/null
+++ b/Tests/Module/ExternalData/Data5/Data5Check.cmake
@@ -0,0 +1,4 @@
+file(STRINGS "${Data5}" lines LIMIT_INPUT 1024)
+if(NOT "x${lines}" STREQUAL "xInput file already transformed.")
+ message(SEND_ERROR "Input file:\n ${Data5}\ndoes not have expected content, but [[${lines}]]")
+endif()