diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-12-26 10:55:46 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-12-26 10:55:55 (GMT) |
commit | f5cdcd0606bbed903f5c8bbb3310788b2d180429 (patch) | |
tree | 3984b8ae9477602eae1a6c88eb9f30a6a8c87cd3 /Tests/RunCMake | |
parent | fb6b2042f2843f8d205434e081e1db6bf7798f4c (diff) | |
parent | 3eacf857e38d0835c629d7443f333de79bd13b81 (diff) | |
download | CMake-f5cdcd0606bbed903f5c8bbb3310788b2d180429.zip CMake-f5cdcd0606bbed903f5c8bbb3310788b2d180429.tar.gz CMake-f5cdcd0606bbed903f5c8bbb3310788b2d180429.tar.bz2 |
Merge topic 'makefiles-custom_command-depfile'
3eacf857e3 Tests: Add case for DEPFILE in add_custom_command
cfd8a5ac1f Makefiles: Add support of DEPFILE for add_custom_command
a526f71266 cmGccDepfileReader: Add new function ensuring paths are valid
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5617
Diffstat (limited to 'Tests/RunCMake')
17 files changed, 227 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/CustomCommandDepfile.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake new file mode 100644 index 0000000..6ac1291 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake @@ -0,0 +1,61 @@ +cmake_policy(SET CMP0116 NEW) +enable_language(C) + +add_custom_command( + OUTPUT topcc.c + DEPFILE topcc.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=topcc.c -DINFILE=topccdep.txt -DDEPFILE=topcc.c.d -P "${CMAKE_CURRENT_LIST_DIR}/WriteDepfile.cmake" + ) +add_custom_target(topcc ALL DEPENDS topcc.c) + +add_custom_command( + OUTPUT topexe.c + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/topexe.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=topexe.c "-DINFILE=${CMAKE_CURRENT_BINARY_DIR}/topexedep.txt" -DDEPFILE=topexe.c.d -P "${CMAKE_CURRENT_LIST_DIR}/WriteDepfile.cmake" + ) +add_executable(topexe "${CMAKE_CURRENT_BINARY_DIR}/topexe.c") + +add_custom_command( + OUTPUT toplib.c + DEPFILE toplib.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=toplib.c -DINFILE=toplibdep.txt -DDEPFILE=toplib.c.d -P "${CMAKE_CURRENT_LIST_DIR}/WriteDepfile.cmake" + ) +add_library(toplib STATIC toplib.c) + +add_subdirectory(DepfileSubdir) + +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +function(check_exists file) + if(NOT EXISTS \"\${file}\") + string(APPEND RunCMake_TEST_FAILED \"\${file} does not exist\\n\") + endif() + set(RunCMake_TEST_FAILED \"\${RunCMake_TEST_FAILED}\" PARENT_SCOPE) +endfunction() + +function(check_not_exists file) + if(EXISTS \"\${file}\") + string(APPEND RunCMake_TEST_FAILED \"\${file} exists\\n\") + endif() + set(RunCMake_TEST_FAILED \"\${RunCMake_TEST_FAILED}\" PARENT_SCOPE) +endfunction() + +set(check_pairs + \"${CMAKE_BINARY_DIR}/topcc.c|${CMAKE_BINARY_DIR}/topccdep.txt\" + \"$<TARGET_FILE:topexe>|${CMAKE_BINARY_DIR}/topexedep.txt\" + \"$<TARGET_FILE:toplib>|${CMAKE_BINARY_DIR}/toplibdep.txt\" + \"${CMAKE_BINARY_DIR}/DepfileSubdir/subcc.c|${CMAKE_BINARY_DIR}/DepfileSubdir/subccdep.txt\" + \"$<TARGET_FILE:subexe>|${CMAKE_BINARY_DIR}/DepfileSubdir/subexedep.txt\" + \"$<TARGET_FILE:sublib>|${CMAKE_BINARY_DIR}/DepfileSubdir/sublibdep.txt\" + ) + +if(check_step EQUAL 3) + list(APPEND check_pairs + \"${CMAKE_BINARY_DIR}/step3.timestamp|${CMAKE_BINARY_DIR}/topcc.c\" + \"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:topexe>\" + \"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:toplib>\" + \"${CMAKE_BINARY_DIR}/step3.timestamp|${CMAKE_BINARY_DIR}/DepfileSubdir/subcc.c\" + \"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:subexe>\" + \"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:sublib>\" + ) +endif() +") diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step1.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step1.cmake new file mode 100644 index 0000000..0dfe78e --- /dev/null +++ b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step1.cmake @@ -0,0 +1,10 @@ +file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir") +file(REMOVE "${RunCMake_TEST_BINARY_DIR}/../sublib.c") +file(REMOVE "${RunCMake_TEST_BINARY_DIR}/step3.timestamp") + +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/topccdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/topexedep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/toplibdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/subccdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/subexedep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/sublibdep.txt") diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step2.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step2.cmake new file mode 100644 index 0000000..c711514 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step2.cmake @@ -0,0 +1,6 @@ +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/topccdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/topexedep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/toplibdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/subccdep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/subexedep.txt") +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/DepfileSubdir/sublibdep.txt") diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step3.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step3.cmake new file mode 100644 index 0000000..c55ccc1 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.step3.cmake @@ -0,0 +1 @@ +file(TOUCH "${RunCMake_TEST_BINARY_DIR}/step3.timestamp") diff --git a/Tests/RunCMake/BuildDepends/DepfileSubdir/CMakeLists.txt b/Tests/RunCMake/BuildDepends/DepfileSubdir/CMakeLists.txt new file mode 100644 index 0000000..06db47c --- /dev/null +++ b/Tests/RunCMake/BuildDepends/DepfileSubdir/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_policy(SET CMP0116 NEW) + +add_custom_command( + OUTPUT subcc.c + DEPFILE subcc.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=subcc.c -DINFILE=subccdep.txt -DDEPFILE=subcc.c.d -P "${CMAKE_CURRENT_LIST_DIR}/../WriteDepfile.cmake" + ) +add_custom_target(subcc ALL DEPENDS subcc.c) + +add_custom_command( + OUTPUT subexe.c + DEPFILE subexe.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=subexe.c -DINFILE=subexedep.txt -DDEPFILE=subexe.c.d -P "${CMAKE_CURRENT_LIST_DIR}/../WriteDepfile.cmake" + ) +add_executable(subexe subexe.c) + +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/../sublib.c + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/sublib.c.d + COMMAND ${CMAKE_COMMAND} -DOUTFILE=${CMAKE_BINARY_DIR}/../sublib.c "-DINFILE=${CMAKE_CURRENT_BINARY_DIR}/sublibdep.txt" -DDEPFILE=sublib.c.d -P "${CMAKE_CURRENT_LIST_DIR}/../WriteDepfile.cmake" + ) +add_library(sublib STATIC "${CMAKE_BINARY_DIR}/../sublib.c") 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..1b7b8d9 100644 --- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake +++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake @@ -30,8 +30,17 @@ function(run_BuildDepends CASE) include(${RunCMake_SOURCE_DIR}/${CASE}.step2.cmake OPTIONAL) set(check_step 2) run_cmake_command(${CASE}-build2 ${CMAKE_COMMAND} --build . --config Debug) + if(run_BuildDepends_skip_step_3) + return() + endif() + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution + include(${RunCMake_SOURCE_DIR}/${CASE}.step3.cmake OPTIONAL) + set(check_step 3) + run_cmake_command(${CASE}-build3 ${CMAKE_COMMAND} --build . --config Debug) endfunction() +set(run_BuildDepends_skip_step_3 1) + run_BuildDepends(C-Exe) if(NOT RunCMake_GENERATOR STREQUAL "Xcode") if(RunCMake_GENERATOR MATCHES "Visual Studio 10" OR @@ -122,4 +131,15 @@ 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() + +if(RunCMake_GENERATOR MATCHES "Make|Ninja") + unset(run_BuildDepends_skip_step_3) + run_BuildDepends(CustomCommandDepfile) + set(run_BuildDepends_skip_step_3 1) endif() diff --git a/Tests/RunCMake/BuildDepends/WriteDepfile.cmake b/Tests/RunCMake/BuildDepends/WriteDepfile.cmake new file mode 100644 index 0000000..c958cde --- /dev/null +++ b/Tests/RunCMake/BuildDepends/WriteDepfile.cmake @@ -0,0 +1,8 @@ +file(WRITE "${OUTFILE}" [[int main(void) +{ + return 0; +} +]]) +string(REPLACE [[ ]] [[\ ]] OUTFILE "${OUTFILE}") +string(REPLACE [[ ]] [[\ ]] INFILE "${INFILE}") +file(WRITE "${DEPFILE}" "${OUTFILE}: ${INFILE}\n") 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) |