Skip to content

Commit

Permalink
[vcpkg] Add new function vcpkg_copy_tools (#8749)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
myd7349 committed May 1, 2020
1 parent bc7d178 commit 0ab1a9e
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 114 deletions.
1 change: 1 addition & 0 deletions docs/maintainers/maintainer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/maintainers/portfile-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions docs/maintainers/vcpkg_clean_executables_in_bin.md
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions docs/maintainers/vcpkg_copy_tools.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion ports/cpuinfo/CONTROL
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 4 additions & 13 deletions ports/cpuinfo/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/czmq/CONTROL
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 3 additions & 20 deletions ports/czmq/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ports/libsvm/CONTROL
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
23 changes: 1 addition & 22 deletions ports/libsvm/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ports/nanomsg/CONTROL
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
20 changes: 1 addition & 19 deletions ports/nanomsg/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ports/uriparser/CONTROL
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
19 changes: 4 additions & 15 deletions ports/uriparser/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)\"")
Expand Down
2 changes: 1 addition & 1 deletion ports/zyre/CONTROL
Original file line number Diff line number Diff line change
@@ -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
20 changes: 1 addition & 19 deletions ports/zyre/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
58 changes: 58 additions & 0 deletions scripts/cmake/vcpkg_clean_executables_in_bin.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions scripts/cmake/vcpkg_common_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 0ab1a9e

Please sign in to comment.