summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-12-04 17:35:04 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-12-23 14:47:46 (GMT)
commitcfd8a5ac1f443725342517ddbaee51692d8d0324 (patch)
treebf2224cb9c6b6ba1a7aed1eb2fbcaf31799cbc17 /Tests
parenta526f71266c2fed017c65a3d90b63286221476c0 (diff)
downloadCMake-cfd8a5ac1f443725342517ddbaee51692d8d0324.zip
CMake-cfd8a5ac1f443725342517ddbaee51692d8d0324.tar.gz
CMake-cfd8a5ac1f443725342517ddbaee51692d8d0324.tar.bz2
Makefiles: Add support of DEPFILE for add_custom_command
Issue: #20286 Fixes: #21415
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-result.txt (renamed from Tests/RunCMake/Make/CustomCommandDepfile-ERROR-result.txt)0
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-stderr.txt4
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs.cmake10
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies.cmake73
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies.step1.cmake3
-rw-r--r--Tests/RunCMake/BuildDepends/CustomCommandDependencies.step2.cmake3
-rw-r--r--Tests/RunCMake/BuildDepends/GenerateDepFile.cmake6
-rw-r--r--Tests/RunCMake/BuildDepends/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/Make/CustomCommandDepfile-ERROR-stderr.txt5
-rw-r--r--Tests/RunCMake/Make/CustomCommandDepfile-ERROR.cmake8
-rw-r--r--Tests/RunCMake/Make/RunCMakeTest.cmake1
11 files changed, 104 insertions, 14 deletions
diff --git a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR-result.txt b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-result.txt
index d00491f..d00491f 100644
--- a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR-result.txt
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-result.txt
diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-stderr.txt b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-stderr.txt
new file mode 100644
index 0000000..cddea3c
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CustomCommandDependencies-BadArgs.cmake:[0-9]+ \(add_custom_command\):
+ add_custom_command IMPLICIT_DEPENDS and DEPFILE can not both be specified.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs.cmake
new file mode 100644
index 0000000..91ee338
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies-BadArgs.cmake
@@ -0,0 +1,10 @@
+enable_language(C)
+
+add_custom_command(OUTPUT main.c
+ DEPFILE main.c.d
+ IMPLICIT_DEPENDS C main.c.in
+ COMMAND "${CMAKE_COMMAND}" -DINFILE=main.c.in -DOUTFILE=main.c -DDEPFILE=main.c.d
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/GenerateDepFile.cmake"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_custom_target(mainc ALL DEPENDS main.c)
diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDependencies.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.cmake
new file mode 100644
index 0000000..28bbf11
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.cmake
@@ -0,0 +1,73 @@
+enable_language(C)
+
+add_custom_command(OUTPUT main.c
+ DEPFILE main.c.d
+ COMMAND "${CMAKE_COMMAND}" -DINFILE=main.c.in -DOUTFILE=main.c -DDEPFILE=main.c.d
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/GenerateDepFile.cmake"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_custom_target(mainc ALL DEPENDS main.c)
+
+add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/main.c)
+
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+cmake_minimum_required(VERSION 3.19)
+set(check_pairs
+ \"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/main.c.in\"
+ \"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/main.c\"
+ )
+set(check_exes
+ \"$<TARGET_FILE:main>\"
+ )
+
+if (check_step EQUAL 2)
+ include(\"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Makefile.cmake\")
+ if (NOT CMAKE_DEPEND_INFO_FILES)
+ set(RunCMake_TEST_FAILED \"Variable CMAKE_DEPEND_INFO_FILES not found.\")
+ else()
+ foreach(DEPEND_INFO_FILE IN LISTS CMAKE_DEPEND_INFO_FILES)
+ include(\"${CMAKE_CURRENT_BINARY_DIR}/\${DEPEND_INFO_FILE}\")
+ if (NOT CMAKE_DEPENDS_DEPENDENCY_FILES)
+ set(RunCMake_TEST_FAILED \"Variable CMAKE_DEPENDS_DEPENDENCY_FILES not found.\")
+ else()
+ list(LENGTH CMAKE_DEPENDS_DEPENDENCY_FILES DEPENDENCY_FILES_SIZE)
+ math(EXPR STOP_INDEX \"\${DEPENDENCY_FILES_SIZE} - 1\")
+ foreach(INDEX RANGE 0 \${STOP_INDEX} 4)
+ math(EXPR OBJECT_INDEX \"\${INDEX} + 1\")
+ math(EXPR FORMAT_INDEX \"\${INDEX} + 2\")
+ math(EXPR DEP_INDEX \"\${INDEX} + 3\")
+ list(GET CMAKE_DEPENDS_DEPENDENCY_FILES \${OBJECT_INDEX} OBJECT_FILE)
+ list(GET CMAKE_DEPENDS_DEPENDENCY_FILES \${FORMAT_INDEX} DEP_FORMAT)
+ list(GET CMAKE_DEPENDS_DEPENDENCY_FILES \${DEP_INDEX} DEP_FILE)
+ if (NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/\${DEP_FILE}\")
+ set(RunCMake_TEST_FAILED \"File \${DEP_FILE} not found.\")
+ else()
+ cmake_path(APPEND TARGET_DEP_FILE \"${CMAKE_CURRENT_BINARY_DIR}\" \"\${DEPEND_INFO_FILE}\")
+ cmake_path(REPLACE_FILENAME TARGET_DEP_FILE \"compiler_depend.make\")
+ file(READ \"\${TARGET_DEP_FILE}\" DEPENDS_CONTENT)
+ if (WIN32)
+ string (REPLACE \"\\\\\" \"/\" DEPENDS_CONTENT \"\${DEPENDS_CONTENT}\")
+ string (TOLOWER \"\${DEPENDS_CONTENT}\" DEPENDS_CONTENT)
+ string (TOLOWER \"\${OBJECT_FILE}\" OBJECT_FILE)
+ else()
+ string(REPLACE \"\\\\ \" \" \" DEPENDS_CONTENT \"\${DEPENDS_CONTENT}\")
+ endif()
+ if(DEPEND_INFO_FILE MATCHES \"main\\\\.dir\")
+ if (DEP_FORMAT STREQUAL \"gcc\" AND NOT DEPENDS_CONTENT MATCHES \"\${OBJECT_FILE} *:.+main.c\")
+ set(RunCMake_TEST_FAILED \"Dependency file '\${TARGET_DEP_FILE}' badly generated:\\n\${DEPENDS_CONTENT}\")
+ endif()
+ if (DEP_FORMAT STREQUAL \"custom\" AND NOT DEPENDS_CONTENT MATCHES \"\${OBJECT_FILE} *:.+main.c.in\")
+ set(RunCMake_TEST_FAILED \"Dependency file '\${TARGET_DEP_FILE}' badly generated:\\n\${DEPENDS_CONTENT}\")
+ endif()
+ else()
+ if (NOT DEPENDS_CONTENT MATCHES \"\${OBJECT_FILE} *:.+main.c.in\")
+ set(RunCMake_TEST_FAILED \"Dependency file '\${TARGET_DEP_FILE}' badly generated:\\n\${DEPENDS_CONTENT}\")
+ endif()
+ endif()
+ endif()
+ endforeach()
+ endif()
+ endforeach()
+ endif()
+endif()
+")
diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step1.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step1.cmake
new file mode 100644
index 0000000..87576eb
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step1.cmake
@@ -0,0 +1,3 @@
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/main.c.in" [[
+int main(void) { return 1; }
+]])
diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step2.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step2.cmake
new file mode 100644
index 0000000..69b21b8
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/CustomCommandDependencies.step2.cmake
@@ -0,0 +1,3 @@
+file(WRITE "${RunCMake_TEST_BINARY_DIR}/main.c.in" [[
+int main(void) { return 2; }
+]])
diff --git a/Tests/RunCMake/BuildDepends/GenerateDepFile.cmake b/Tests/RunCMake/BuildDepends/GenerateDepFile.cmake
new file mode 100644
index 0000000..f7d0f13
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/GenerateDepFile.cmake
@@ -0,0 +1,6 @@
+file(READ "${INFILE}" INCONTENT)
+file(WRITE "${OUTFILE}" "${INCONTENT}")
+
+string(REPLACE [[ ]] [[\ ]] OUTFILE "${OUTFILE}")
+string(REPLACE [[ ]] [[\ ]] INFILE "${INFILE}")
+file(WRITE "${DEPFILE}" "${OUTFILE}: ${INFILE}\n")
diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
index 23e222a..f40cde6 100644
--- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
+++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
@@ -122,4 +122,9 @@ if ((RunCMake_GENERATOR STREQUAL "Unix Makefiles"
AND MSVC_VERSION GREATER 1300
AND CMAKE_C_COMPILER_ID STREQUAL "MSVC"))
run_BuildDepends(CompilerDependencies)
+ run_BuildDepends(CustomCommandDependencies)
+endif()
+
+if (RunCMake_GENERATOR MATCHES "Makefiles")
+ run_cmake(CustomCommandDependencies-BadArgs)
endif()
diff --git a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR-stderr.txt b/Tests/RunCMake/Make/CustomCommandDepfile-ERROR-stderr.txt
deleted file mode 100644
index 74d62a4..0000000
--- a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR-stderr.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-^CMake Error at CustomCommandDepfile-ERROR.cmake:1 \(add_custom_command\):
- add_custom_command Option DEPFILE not supported by [^
-]+
-Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR.cmake b/Tests/RunCMake/Make/CustomCommandDepfile-ERROR.cmake
deleted file mode 100644
index bad7955..0000000
--- a/Tests/RunCMake/Make/CustomCommandDepfile-ERROR.cmake
+++ /dev/null
@@ -1,8 +0,0 @@
-add_custom_command(
- OUTPUT hello.copy.c
- COMMAND "${CMAKE_COMMAND}" -E copy
- "${CMAKE_CURRENT_SOURCE_DIR}/hello.c"
- hello.copy.c
- WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
- DEPFILE "test.d"
- )
diff --git a/Tests/RunCMake/Make/RunCMakeTest.cmake b/Tests/RunCMake/Make/RunCMakeTest.cmake
index b66e30e..c7717ec 100644
--- a/Tests/RunCMake/Make/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Make/RunCMakeTest.cmake
@@ -39,7 +39,6 @@ function(run_VerboseBuild)
endfunction()
run_VerboseBuild()
-run_cmake(CustomCommandDepfile-ERROR)
run_cmake(IncludeRegexSubdir)
function(run_MakefileConflict)