ExternalProject: Support substituting <DOWNLOAD_DIR>

This commit is contained in:
Craig Scott
2017-11-30 08:32:26 +11:00
parent b311b87518
commit b8b8748977
5 changed files with 69 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
ExternalProject
---------------
* The :module:`ExternalProject` module learnt to substitute ``<DOWNLOAD_DIR>``
in comments, commands, working directory and byproducts.

View File

@@ -714,8 +714,9 @@ control needed to implement such step-level capabilities.
The command line, comment, working directory and byproducts of every The command line, comment, working directory and byproducts of every
standard and custom step are processed to replace the tokens standard and custom step are processed to replace the tokens
``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>`` ``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``
and ``<TMP_DIR>`` with their corresponding property values defined in the ``<TMP_DIR>``, ``<DOWNLOAD_DIR>`` and ``<DOWNLOADED_FILE>`` with their
original call to :command:`ExternalProject_Add`. corresponding property values defined in the original call to
:command:`ExternalProject_Add`.
.. command:: ExternalProject_Add_StepTargets .. command:: ExternalProject_Add_StepTargets
@@ -1665,7 +1666,7 @@ macro(_ep_replace_location_tags target_name)
set(vars ${ARGN}) set(vars ${ARGN})
foreach(var ${vars}) foreach(var ${vars})
if(${var}) 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}) get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}") string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
endforeach() endforeach()

View File

@@ -15,10 +15,31 @@ run_cmake(UsesTerminal)
# Run both cmake and build steps. We always do a clean before the # Run both cmake and build steps. We always do a clean before the
# build to ensure that the download step re-runs each time. # build to ensure that the download step re-runs each time.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MultiCommand-build) function(__ep_test_with_build testName)
set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") set(RunCMake_TEST_NO_CLEAN 1)
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
run_cmake(MultiCommand) file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake_command(MultiCommand-clean ${CMAKE_COMMAND} --build . --target clean) run_cmake(${testName})
run_cmake_command(MultiCommand-build ${CMAKE_COMMAND} --build .) 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()

View File

@@ -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

View File

@@ -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 = <DOWNLOAD_DIR>"
COMMAND ${CMAKE_COMMAND} -E echo "Download file = <DOWNLOADED_FILE>"
COMMAND ${CMAKE_COMMAND} -E echo "Source dir = <SOURCE_DIR>"
COMMAND ${CMAKE_COMMAND} -E echo "Source subdir = <SOURCE_SUBDIR>"
COMMAND ${CMAKE_COMMAND} -E echo "Binary dir = <BINARY_DIR>"
COMMAND ${CMAKE_COMMAND} -E echo "Install dir = <INSTALL_DIR>"
COMMAND ${CMAKE_COMMAND} -E echo "Tmp dir = <TMP_DIR>"
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)