[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
This commit is contained in:
myd7349 2020-05-02 06:28:55 +08:00 committed by GitHub
parent bc7d178e62
commit 0ab1a9e1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 192 additions and 114 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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,17 +62,11 @@ file(COPY
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
if(CMAKE_HOST_WIN32)
set(EXECUTABLE_SUFFIX ".exe")
else()
set(EXECUTABLE_SUFFIX "")
if ("tool" IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES zmakecert)
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})
endif()
vcpkg_clean_executables_in_bin(FILE_NAMES zmakecert)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
@ -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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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]+)\"")

View File

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

View File

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

View File

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

View File

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

View File

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