aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormyd7349 <myd7349@gmail.com>2020-05-02 06:28:55 +0800
committerGitHub <noreply@github.com>2020-05-01 15:28:55 -0700
commit0ab1a9e1c64a3968631b59647e771beda7d1f256 (patch)
tree5b4ff6d1fe12b2a6fcd0e560438e23289fe9ce13
parentbc7d178e62c68adffc84ef8459eecde4a5ed5315 (diff)
downloadvcpkg-0ab1a9e1c64a3968631b59647e771beda7d1f256.tar.gz
vcpkg-0ab1a9e1c64a3968631b59647e771beda7d1f256.zip
[vcpkg] Add new function vcpkg_copy_tools (#8749)
* [vcpkg] Add new function vcpkg_copy_tools * [cpuinfo][czmq][nanomsg][uriparser] Use vcpkg_copy_tools * [czmq] Clean even tools are not copied [libsvm][zyre] Use vcpkg_copy_tools * [vcpkg-copy-tools] Clean debug/bin This should fix czmq build error * [czmq] czmq does not have BUILD_TOOLS option * [vcpkg] Split clean logic into another function * [cpuinfo][czmq][nanomsg][uriparser] Fix calling of vcpkg_copy_tools * [zyre] Fix regression error * [vcpkg] Update try_remove_empty_directory * [libsvm] Fix vcpkg_copy_tools call
-rw-r--r--docs/maintainers/maintainer-guide.md1
-rw-r--r--docs/maintainers/portfile-functions.md2
-rw-r--r--docs/maintainers/vcpkg_clean_executables_in_bin.md23
-rw-r--r--docs/maintainers/vcpkg_copy_tools.md30
-rw-r--r--ports/cpuinfo/CONTROL2
-rw-r--r--ports/cpuinfo/portfile.cmake17
-rw-r--r--ports/czmq/CONTROL2
-rw-r--r--ports/czmq/portfile.cmake23
-rw-r--r--ports/libsvm/CONTROL2
-rw-r--r--ports/libsvm/portfile.cmake23
-rw-r--r--ports/nanomsg/CONTROL2
-rw-r--r--ports/nanomsg/portfile.cmake20
-rw-r--r--ports/uriparser/CONTROL2
-rw-r--r--ports/uriparser/portfile.cmake19
-rw-r--r--ports/zyre/CONTROL2
-rw-r--r--ports/zyre/portfile.cmake20
-rw-r--r--scripts/cmake/vcpkg_clean_executables_in_bin.cmake58
-rw-r--r--scripts/cmake/vcpkg_common_functions.cmake2
-rw-r--r--scripts/cmake/vcpkg_copy_tools.cmake56
19 files changed, 192 insertions, 114 deletions
diff --git a/docs/maintainers/maintainer-guide.md b/docs/maintainers/maintainer-guide.md
index 624aa46d3..0b6532258 100644
--- a/docs/maintainers/maintainer-guide.md
+++ b/docs/maintainers/maintainer-guide.md
@@ -42,6 +42,7 @@ At this time, the following helpers are deprecated:
1. `vcpkg_extract_source_archive()` should be replaced by [`vcpkg_extract_source_archive_ex()`](vcpkg_extract_source_archive_ex.md)
2. `vcpkg_apply_patches()` should be replaced by the `PATCHES` arguments to the "extract" helpers (e.g. [`vcpkg_from_github()`](vcpkg_from_github.md))
3. `vcpkg_build_msbuild()` should be replaced by [`vcpkg_install_msbuild()`](vcpkg_install_msbuild.md)
+4. `vcpkg_copy_tool_dependencies()` should be replaced by [`vcpkg_copy_tools()`](vcpkg_copy_tools.md)
### Avoid excessive comments in portfiles
diff --git a/docs/maintainers/portfile-functions.md b/docs/maintainers/portfile-functions.md
index 776ffdefc..4cd42a685 100644
--- a/docs/maintainers/portfile-functions.md
+++ b/docs/maintainers/portfile-functions.md
@@ -11,12 +11,14 @@
- [vcpkg\_build\_nmake](vcpkg_build_nmake.md)
- [vcpkg\_check\_features](vcpkg_check_features.md)
- [vcpkg\_check\_linkage](vcpkg_check_linkage.md)
+- [vcpkg\_clean\_executables\_in\_bin](vcpkg_clean_executables_in_bin.md)
- [vcpkg\_clean\_msbuild](vcpkg_clean_msbuild.md)
- [vcpkg\_common\_definitions](vcpkg_common_definitions.md)
- [vcpkg\_configure\_cmake](vcpkg_configure_cmake.md)
- [vcpkg\_configure\_make](vcpkg_configure_make.md)
- [vcpkg\_configure\_meson](vcpkg_configure_meson.md)
- [vcpkg\_copy\_pdbs](vcpkg_copy_pdbs.md)
+- [vcpkg\_copy\_tools](vcpkg_copy_tools.md)
- [vcpkg\_copy\_tool\_dependencies](vcpkg_copy_tool_dependencies.md)
- [vcpkg\_download\_distfile](vcpkg_download_distfile.md)
- [vcpkg\_execute\_build\_process](vcpkg_execute_build_process.md)
diff --git a/docs/maintainers/vcpkg_clean_executables_in_bin.md b/docs/maintainers/vcpkg_clean_executables_in_bin.md
new file mode 100644
index 000000000..36342790b
--- /dev/null
+++ b/docs/maintainers/vcpkg_clean_executables_in_bin.md
@@ -0,0 +1,23 @@
+# vcpkg_clean_executables_in_bin
+
+Remove specified executables found in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`. If, after all specified executables have been removed, and the `bin` and `debug/bin` directories are empty, then also delete `bin` and `debug/bin` directories.
+
+## Usage
+```cmake
+vcpkg_clean_executables_in_bin(
+ FILE_NAMES <file1>...
+)
+```
+
+## Parameters
+### FILE_NAMES
+A list of executable filenames without extension.
+
+## Notes
+Generally, there is no need to call this function manually. Instead, pass an extra `AUTO_CLEAN` argument when calling `vcpkg_copy_tools`.
+
+## Examples
+* [czmq](https://github.com/microsoft/vcpkg/blob/master/ports/czmq/portfile.cmake)
+
+## Source
+[scripts/cmake/vcpkg_clean_executables_in_bin.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_clean_executables_in_bin.cmake)
diff --git a/docs/maintainers/vcpkg_copy_tools.md b/docs/maintainers/vcpkg_copy_tools.md
new file mode 100644
index 000000000..1a553eb40
--- /dev/null
+++ b/docs/maintainers/vcpkg_copy_tools.md
@@ -0,0 +1,30 @@
+# vcpkg_copy_tools
+
+Copy tools and all their DLL dependencies into the `tools` folder.
+
+## Usage
+```cmake
+vcpkg_copy_tools(
+ TOOL_NAMES <tool1>...
+ [SEARCH_DIR <${CURRENT_PACKAGES_DIR}/bin>]
+ [AUTO_CLEAN]
+)
+```
+## Parameters
+### TOOL_NAMES
+A list of tool filenames without extension.
+
+### SEARCH_DIR
+The path to the directory containing the tools. This will be set to `${CURRENT_PACKAGES_DIR}/bin` if ommited.
+
+### AUTO_CLEAN
+Auto clean executables in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`.
+
+## Examples
+
+* [cpuinfo](https://github.com/microsoft/vcpkg/blob/master/ports/cpuinfo/portfile.cmake)
+* [nanomsg](https://github.com/microsoft/vcpkg/blob/master/ports/nanomsg/portfile.cmake)
+* [uriparser](https://github.com/microsoft/vcpkg/blob/master/ports/uriparser/portfile.cmake)
+
+## Source
+[scripts/cmake/vcpkg_copy_tools.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_copy_tools.cmake)
diff --git a/ports/cpuinfo/CONTROL b/ports/cpuinfo/CONTROL
index 180b26043..0c349078e 100644
--- a/ports/cpuinfo/CONTROL
+++ b/ports/cpuinfo/CONTROL
@@ -1,5 +1,5 @@
Source: cpuinfo
-Version: 2019-07-28
+Version: 2019-07-28-1
Description: CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)
Homepage: https://github.com/pytorch/cpuinfo
diff --git a/ports/cpuinfo/portfile.cmake b/ports/cpuinfo/portfile.cmake
index b5279e30d..9b3db8e45 100644
--- a/ports/cpuinfo/portfile.cmake
+++ b/ports/cpuinfo/portfile.cmake
@@ -47,19 +47,10 @@ vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/${PORT})
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
if(tools IN_LIST FEATURES)
- foreach(cpuinfo_tool cache-info cpuid-dump cpu-info isa-info)
- file(COPY
- ${CURRENT_PACKAGES_DIR}/bin/${cpuinfo_tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}
- )
- vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
- endforeach()
-
- if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
- file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin)
- else()
- # TODO: Fix it once this lib supports dynamic building.
- endif()
+ vcpkg_copy_tools(
+ TOOL_NAMES cache-info cpuid-dump cpu-info isa-info
+ AUTO_CLEAN
+ )
endif()
# Handle copyright
diff --git a/ports/czmq/CONTROL b/ports/czmq/CONTROL
index 4d68f15b1..2d190c394 100644
--- a/ports/czmq/CONTROL
+++ b/ports/czmq/CONTROL
@@ -1,5 +1,5 @@
Source: czmq
-Version: 2019-06-10-3
+Version: 2019-06-10-4
Build-Depends: zeromq
Description: High-level C binding for ZeroMQ
Homepage: https://github.com/zeromq/czmq
diff --git a/ports/czmq/portfile.cmake b/ports/czmq/portfile.cmake
index 2545feea5..a30449329 100644
--- a/ports/czmq/portfile.cmake
+++ b/ports/czmq/portfile.cmake
@@ -29,7 +29,6 @@ string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
draft ENABLE_DRAFTS
- tool BUILD_TOOLS
curl CZMQ_WITH_LIBCURL
httpd CZMQ_WITH_LIBMICROHTTPD
lz4 CZMQ_WITH_LZ4
@@ -63,18 +62,12 @@ file(COPY
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
-if(CMAKE_HOST_WIN32)
- set(EXECUTABLE_SUFFIX ".exe")
-else()
- set(EXECUTABLE_SUFFIX "")
-endif()
-
if ("tool" IN_LIST FEATURES)
- file(COPY ${CURRENT_PACKAGES_DIR}/bin/zmakecert${EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT})
- vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
+ vcpkg_copy_tools(TOOL_NAMES zmakecert)
endif()
+vcpkg_clean_executables_in_bin(FILE_NAMES zmakecert)
+
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
@@ -84,16 +77,6 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
)
endif()
-if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
- file(REMOVE_RECURSE
- ${CURRENT_PACKAGES_DIR}/bin
- ${CURRENT_PACKAGES_DIR}/debug/bin)
-else()
- file(REMOVE
- ${CURRENT_PACKAGES_DIR}/debug/bin/zmakecert${EXECUTABLE_SUFFIX}
- ${CURRENT_PACKAGES_DIR}/bin/zmakecert${EXECUTABLE_SUFFIX})
-endif()
-
# Handle copyright
configure_file(${SOURCE_PATH}/LICENSE ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright COPYONLY)
diff --git a/ports/libsvm/CONTROL b/ports/libsvm/CONTROL
index 342536cce..4a9af6018 100644
--- a/ports/libsvm/CONTROL
+++ b/ports/libsvm/CONTROL
@@ -1,5 +1,5 @@
Source: libsvm
-Version: 323
+Version: 323-1
Description: A library for Support Vector Machines
Homepage: https://www.csie.ntu.edu.tw/~cjlin/libsvm/
diff --git a/ports/libsvm/portfile.cmake b/ports/libsvm/portfile.cmake
index f4f7c6960..e473fd3c3 100644
--- a/ports/libsvm/portfile.cmake
+++ b/ports/libsvm/portfile.cmake
@@ -30,29 +30,8 @@ vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
-# Install tools
if ("tools" IN_LIST FEATURES)
- if(VCPKG_TARGET_IS_WINDOWS)
- set(EXECUTABLE_SUFFIX ".exe")
- else()
- set(EXECUTABLE_SUFFIX "")
- endif()
-
- foreach (libsvm_tool svm-predict svm-scale svm-toy svm-train)
- if (EXISTS ${CURRENT_PACKAGES_DIR}/bin/${libsvm_tool}${EXECUTABLE_SUFFIX})
- file(
- COPY ${CURRENT_PACKAGES_DIR}/bin/${libsvm_tool}${EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}
- )
- file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/${libsvm_tool}${EXECUTABLE_SUFFIX})
- endif ()
-
- vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
- endforeach ()
-
- if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
- file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin)
- endif ()
+ vcpkg_copy_tools(TOOL_NAMES svm-predict svm-scale svm-toy svm-train AUTO_CLEAN)
endif ()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
diff --git a/ports/nanomsg/CONTROL b/ports/nanomsg/CONTROL
index 8693cfef3..8f6d45e8b 100644
--- a/ports/nanomsg/CONTROL
+++ b/ports/nanomsg/CONTROL
@@ -1,5 +1,5 @@
Source: nanomsg
-Version: 1.1.5-1
+Version: 1.1.5-2
Description: a simple high-performance implementation of several "scalability protocols".
These scalability protocols are light-weight messaging protocols which can be used to solve a number of very common messaging patterns, such as request/reply, publish/subscribe, surveyor/respondent, and so forth. These protocols can run over a variety of transports such as TCP, UNIX sockets, and even WebSocket.
diff --git a/ports/nanomsg/portfile.cmake b/ports/nanomsg/portfile.cmake
index d07685f60..a4125434d 100644
--- a/ports/nanomsg/portfile.cmake
+++ b/ports/nanomsg/portfile.cmake
@@ -41,30 +41,12 @@ vcpkg_replace_string(
)
if(NN_ENABLE_NANOCAT)
- if(CMAKE_HOST_WIN32)
- set(EXECUTABLE_SUFFIX ".exe")
- else()
- set(EXECUTABLE_SUFFIX "")
- endif()
-
- file(INSTALL ${CURRENT_PACKAGES_DIR}/bin/nanocat${EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT})
- vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
-
- file(REMOVE
- ${CURRENT_PACKAGES_DIR}/bin/nanocat${EXECUTABLE_SUFFIX}
- ${CURRENT_PACKAGES_DIR}/debug/bin/nanocat${EXECUTABLE_SUFFIX}
- )
+ vcpkg_copy_tools(TOOL_NAMES nanocat AUTO_CLEAN)
endif()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include ${CURRENT_PACKAGES_DIR}/debug/share)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
- file(REMOVE_RECURSE
- ${CURRENT_PACKAGES_DIR}/bin
- ${CURRENT_PACKAGES_DIR}/debug/bin
- )
-
vcpkg_replace_string(
${CURRENT_PACKAGES_DIR}/include/nanomsg/nn.h
"defined(NN_STATIC_LIB)"
diff --git a/ports/uriparser/CONTROL b/ports/uriparser/CONTROL
index af57f871a..c86313339 100644
--- a/ports/uriparser/CONTROL
+++ b/ports/uriparser/CONTROL
@@ -1,5 +1,5 @@
Source: uriparser
-Version: 0.9.3-4
+Version: 0.9.3-5
Homepage: https://github.com/uriparser/uriparser
Description: uriparser is a strictly RFC 3986 compliant URI parsing and handling library written in C89 ("ANSI C"). uriparser is cross-platform, fast, supports Unicode, and is licensed under the New BSD license.
diff --git a/ports/uriparser/portfile.cmake b/ports/uriparser/portfile.cmake
index aafd0ae6a..5082d7e9b 100644
--- a/ports/uriparser/portfile.cmake
+++ b/ports/uriparser/portfile.cmake
@@ -31,21 +31,10 @@ vcpkg_install_cmake()
vcpkg_copy_pdbs()
if(URIPARSER_BUILD_TOOLS)
- if(CMAKE_HOST_WIN32)
- set(EXECUTABLE_SUFFIX ".exe")
- else()
- set(EXECUTABLE_SUFFIX "")
- endif()
-
- file(COPY ${CURRENT_PACKAGES_DIR}/bin/uriparse${EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT})
- vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
-
- if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
- file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin)
- else()
- file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/uriparse${EXECUTABLE_SUFFIX})
- endif()
+ vcpkg_copy_tools(
+ TOOL_NAMES uriparse
+ AUTO_CLEAN
+ )
endif()
set(_package_version_re "#define[ ]+PACKAGE_VERSION[ ]+\"([0-9]+.[0-9]+.[0-9]+)\"")
diff --git a/ports/zyre/CONTROL b/ports/zyre/CONTROL
index ca8a4507e..5351afb3e 100644
--- a/ports/zyre/CONTROL
+++ b/ports/zyre/CONTROL
@@ -1,5 +1,5 @@
Source: zyre
-Version: 2019-07-07
+Version: 2019-07-07-1
Build-Depends: czmq
Description: An open-source framework for proximity-based peer-to-peer applications
Homepage: https://github.com/zeromq/zyre
diff --git a/ports/zyre/portfile.cmake b/ports/zyre/portfile.cmake
index db7e8e8cc..de44b4b03 100644
--- a/ports/zyre/portfile.cmake
+++ b/ports/zyre/portfile.cmake
@@ -50,25 +50,7 @@ file(COPY
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
-if(NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
- set(EXECUTABLE_SUFFIX ".exe")
-else()
- set(EXECUTABLE_SUFFIX "")
-endif()
-
-file(COPY ${CURRENT_PACKAGES_DIR}/bin/zpinger${EXECUTABLE_SUFFIX}
- DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT})
-vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
-
-if(ZYRE_BUILD_SHARED)
- file(REMOVE
- ${CURRENT_PACKAGES_DIR}/debug/bin/zpinger${EXECUTABLE_SUFFIX}
- ${CURRENT_PACKAGES_DIR}/bin/zpinger${EXECUTABLE_SUFFIX})
-else()
- file(REMOVE_RECURSE
- ${CURRENT_PACKAGES_DIR}/bin
- ${CURRENT_PACKAGES_DIR}/debug/bin)
-endif()
+vcpkg_copy_tools(TOOL_NAMES zpinger AUTO_CLEAN)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
diff --git a/scripts/cmake/vcpkg_clean_executables_in_bin.cmake b/scripts/cmake/vcpkg_clean_executables_in_bin.cmake
new file mode 100644
index 000000000..5321e05b6
--- /dev/null
+++ b/scripts/cmake/vcpkg_clean_executables_in_bin.cmake
@@ -0,0 +1,58 @@
+## # vcpkg_clean_executables_in_bin
+##
+## Remove specified executables found in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`. If, after all specified executables have been removed, and the `bin` and `debug/bin` directories are empty, then also delete `bin` and `debug/bin` directories.
+##
+## ## Usage
+## ```cmake
+## vcpkg_clean_executables_in_bin(
+## FILE_NAMES <file1>...
+## )
+## ```
+##
+## ## Parameters
+## ### FILE_NAMES
+## A list of executable filenames without extension.
+##
+## ## Notes
+## Generally, there is no need to call this function manually. Instead, pass an extra `AUTO_CLEAN` argument when calling `vcpkg_copy_tools`.
+##
+## ## Examples
+## * [czmq](https://github.com/microsoft/vcpkg/blob/master/ports/czmq/portfile.cmake)
+function(vcpkg_clean_executables_in_bin)
+ cmake_parse_arguments(_vct "" "" "FILE_NAMES" ${ARGN})
+
+ if(NOT DEFINED _vct_FILE_NAMES)
+ message(FATAL_ERROR "FILE_NAMES must be specified.")
+ endif()
+
+ foreach(file_name ${_vct_FILE_NAMES})
+ file(REMOVE
+ "${CURRENT_PACKAGES_DIR}/bin/${file_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}"
+ "${CURRENT_PACKAGES_DIR}/debug/bin/${file_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}"
+ )
+ endforeach()
+
+ function(try_remove_empty_directory directory)
+ if(NOT EXISTS "${directory}")
+ return()
+ endif()
+
+ if(NOT IS_DIRECTORY "${directory}")
+ message(FATAL_ERROR "${directory} is supposed to be an existing directory.")
+ endif()
+
+ # TODO:
+ # For an empty directory,
+ # file(GLOB items "${directory}" "${directory}/*")
+ # will return a list with one item.
+ file(GLOB items "${directory}/" "${directory}/*")
+ list(LENGTH items items_count)
+
+ if(${items_count} EQUAL 0)
+ file(REMOVE_RECURSE "${directory}")
+ endif()
+ endfunction()
+
+ try_remove_empty_directory("${CURRENT_PACKAGES_DIR}/bin")
+ try_remove_empty_directory("${CURRENT_PACKAGES_DIR}/debug/bin")
+endfunction()
diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake
index c601f833c..0475a5e31 100644
--- a/scripts/cmake/vcpkg_common_functions.cmake
+++ b/scripts/cmake/vcpkg_common_functions.cmake
@@ -3,6 +3,7 @@ include(vcpkg_acquire_msys)
include(vcpkg_add_to_path)
include(vcpkg_check_features)
include(vcpkg_check_linkage)
+include(vcpkg_clean_executables_in_bin)
include(vcpkg_clean_msbuild)
include(vcpkg_download_distfile)
include(vcpkg_extract_source_archive)
@@ -35,6 +36,7 @@ include(vcpkg_configure_make)
include(vcpkg_apply_patches)
include(vcpkg_copy_pdbs)
include(vcpkg_copy_tool_dependencies)
+include(vcpkg_copy_tools)
include(vcpkg_get_program_files_32_bit)
include(vcpkg_get_program_files_platform_bitness)
include(vcpkg_get_windows_sdk)
diff --git a/scripts/cmake/vcpkg_copy_tools.cmake b/scripts/cmake/vcpkg_copy_tools.cmake
new file mode 100644
index 000000000..9651b5357
--- /dev/null
+++ b/scripts/cmake/vcpkg_copy_tools.cmake
@@ -0,0 +1,56 @@
+## # vcpkg_copy_tools
+##
+## Copy tools and all their DLL dependencies into the `tools` folder.
+##
+## ## Usage
+## ```cmake
+## vcpkg_copy_tools(
+## TOOL_NAMES <tool1>...
+## [SEARCH_DIR <${CURRENT_PACKAGES_DIR}/bin>]
+## [AUTO_CLEAN]
+## )
+## ```
+## ## Parameters
+## ### TOOL_NAMES
+## A list of tool filenames without extension.
+##
+## ### SEARCH_DIR
+## The path to the directory containing the tools. This will be set to `${CURRENT_PACKAGES_DIR}/bin` if ommited.
+##
+## ### AUTO_CLEAN
+## Auto clean executables in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`.
+##
+## ## Examples
+##
+## * [cpuinfo](https://github.com/microsoft/vcpkg/blob/master/ports/cpuinfo/portfile.cmake)
+## * [nanomsg](https://github.com/microsoft/vcpkg/blob/master/ports/nanomsg/portfile.cmake)
+## * [uriparser](https://github.com/microsoft/vcpkg/blob/master/ports/uriparser/portfile.cmake)
+function(vcpkg_copy_tools)
+ cmake_parse_arguments(_vct "AUTO_CLEAN" "SEARCH_DIR" "TOOL_NAMES" ${ARGN})
+
+ if(NOT DEFINED _vct_TOOL_NAMES)
+ message(FATAL_ERROR "TOOL_NAMES must be specified.")
+ endif()
+
+ if(NOT DEFINED _vct_SEARCH_DIR)
+ set(_vct_SEARCH_DIR ${CURRENT_PACKAGES_DIR}/bin)
+ elseif(NOT IS_DIRECTORY ${_vct_SEARCH_DIR})
+ message(FATAL_ERROR "SEARCH_DIR ${_vct_SEARCH_DIR} is supposed to be a directory.")
+ endif()
+
+ foreach(tool_name ${_vct_TOOL_NAMES})
+ set(tool_path "${_vct_SEARCH_DIR}/${tool_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}")
+
+ if(EXISTS ${tool_path})
+ file(COPY ${tool_path} DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT})
+ else()
+ message(FATAL_ERROR "Couldn't find this tool: ${tool_path}.")
+ endif()
+ endforeach()
+
+ if(_vct_AUTO_CLEAN)
+ vcpkg_clean_executables_in_bin(FILE_NAMES ${_vct_TOOL_NAMES})
+ endif()
+
+ vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
+endfunction()