From b8b87489770bd29ffcfc4b2faec3f98bd089f3ff Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Thu, 30 Nov 2017 08:32:26 +1100 Subject: ExternalProject: Support substituting --- Help/release/dev/ExternalProject-DOWNLOAD_DIR.rst | 5 ++++ Modules/ExternalProject.cmake | 7 +++-- Tests/RunCMake/ExternalProject/RunCMakeTest.cmake | 35 +++++++++++++++++----- .../ExternalProject/Substitutions-build-stdout.txt | 7 +++++ Tests/RunCMake/ExternalProject/Substitutions.cmake | 25 ++++++++++++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 Help/release/dev/ExternalProject-DOWNLOAD_DIR.rst create mode 100644 Tests/RunCMake/ExternalProject/Substitutions-build-stdout.txt create mode 100644 Tests/RunCMake/ExternalProject/Substitutions.cmake diff --git a/Help/release/dev/ExternalProject-DOWNLOAD_DIR.rst b/Help/release/dev/ExternalProject-DOWNLOAD_DIR.rst new file mode 100644 index 0000000..823a14b --- /dev/null +++ b/Help/release/dev/ExternalProject-DOWNLOAD_DIR.rst @@ -0,0 +1,5 @@ +ExternalProject +--------------- + +* The :module:`ExternalProject` module learnt to substitute ```` + in comments, commands, working directory and byproducts. diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 67aac4f..d284e27 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -714,8 +714,9 @@ control needed to implement such step-level capabilities. The command line, comment, working directory and byproducts of every standard and custom step are processed to replace the tokens ````, ````, ````, ```` - and ```` with their corresponding property values defined in the - original call to :command:`ExternalProject_Add`. + ````, ```` and ```` with their + corresponding property values defined in the original call to + :command:`ExternalProject_Add`. .. command:: ExternalProject_Add_StepTargets @@ -1665,7 +1666,7 @@ macro(_ep_replace_location_tags target_name) set(vars ${ARGN}) foreach(var ${vars}) if(${var}) - foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOADED_FILE) + foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOAD_DIR DOWNLOADED_FILE) get_property(val TARGET ${target_name} PROPERTY _EP_${dir}) string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}") endforeach() diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake index 994e2aa..09607f6 100644 --- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake @@ -15,10 +15,31 @@ run_cmake(UsesTerminal) # Run both cmake and build steps. We always do a clean before the # build to ensure that the download step re-runs each time. -set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MultiCommand-build) -set(RunCMake_TEST_NO_CLEAN 1) -file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") -file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") -run_cmake(MultiCommand) -run_cmake_command(MultiCommand-clean ${CMAKE_COMMAND} --build . --target clean) -run_cmake_command(MultiCommand-build ${CMAKE_COMMAND} --build .) +function(__ep_test_with_build testName) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${testName}) + run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean) + run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .) +endfunction() + +__ep_test_with_build(MultiCommand) + +# We can't test the substitution when using the old MSYS due to +# make/sh mangling the paths (substitution is performed correctly, +# but the mangling means we can't reliably test the output). +# There is no such issue when using the newer MSYS though. Therefore, +# we need to bypass the substitution test if using old MSYS. +# See merge request 1537 for discussion. +set(doSubstitutionTest YES) +if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles") + execute_process(COMMAND uname OUTPUT_VARIABLE uname) + if(uname MATCHES "^MINGW32_NT") + set(doSubstitutionTest NO) + endif() +endif() +if(doSubstitutionTest) + __ep_test_with_build(Substitutions) +endif() diff --git a/Tests/RunCMake/ExternalProject/Substitutions-build-stdout.txt b/Tests/RunCMake/ExternalProject/Substitutions-build-stdout.txt new file mode 100644 index 0000000..d6a823a --- /dev/null +++ b/Tests/RunCMake/ExternalProject/Substitutions-build-stdout.txt @@ -0,0 +1,7 @@ +.*Download dir = .*/xxxx_dwn +.*Download file = .*/zzzz_tmp.txt +.*Source dir = .*/xxxx_src +.*Source subdir = /yyyy_subdir +.*Binary dir = .*/xxxx_bin +.*Install dir = .*/xxxx_install +.*Tmp dir = .*/xxxx_tmp diff --git a/Tests/RunCMake/ExternalProject/Substitutions.cmake b/Tests/RunCMake/ExternalProject/Substitutions.cmake new file mode 100644 index 0000000..db79491 --- /dev/null +++ b/Tests/RunCMake/ExternalProject/Substitutions.cmake @@ -0,0 +1,25 @@ +include(ExternalProject) + +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zzzz_tmp.txt "Dummy file") +file(MD5 ${CMAKE_CURRENT_BINARY_DIR}/zzzz_tmp.txt md5hash) +ExternalProject_Add(Subst + URL file://${CMAKE_CURRENT_BINARY_DIR}/zzzz_tmp.txt + URL_HASH MD5=${md5hash} + DOWNLOAD_NO_EXTRACT ON + DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/xxxx_dwn + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/xxxx_src + SOURCE_SUBDIR yyyy_subdir + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/xxxx_bin + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/xxxx_install + TMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/xxxx_tmp + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Download dir = " + COMMAND ${CMAKE_COMMAND} -E echo "Download file = " + COMMAND ${CMAKE_COMMAND} -E echo "Source dir = " + COMMAND ${CMAKE_COMMAND} -E echo "Source subdir = " + COMMAND ${CMAKE_COMMAND} -E echo "Binary dir = " + COMMAND ${CMAKE_COMMAND} -E echo "Install dir = " + COMMAND ${CMAKE_COMMAND} -E echo "Tmp dir = " + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) -- cgit v0.12