aboutsummaryrefslogtreecommitdiff
path: root/scripts
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 /scripts
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
Diffstat (limited to 'scripts')
-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
3 files changed, 116 insertions, 0 deletions
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()