Skip to content

Commit

Permalink
[vcpkg/scripts] add a way to define another tool destination (microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
Neumann-A authored Mar 31, 2021
1 parent 93304d1 commit 2779b73
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/maintainers/vcpkg_copy_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Copy tools and all their DLL dependencies into the `tools` folder.
vcpkg_copy_tools(
TOOL_NAMES <tool1>...
[SEARCH_DIR <${CURRENT_PACKAGES_DIR}/bin>]
[DESTINATION <${CURRENT_PACKAGES_DIR}/tools/${PORT}>]
[AUTO_CLEAN]
)
```
Expand All @@ -19,6 +20,9 @@ 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.

### DESTINATION
Destination to copy the tools to. This will be set to `${CURRENT_PACKAGES_DIR}/tools/${PORT}` if ommited.

### AUTO_CLEAN
Auto clean executables in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`.

Expand Down
12 changes: 9 additions & 3 deletions docs/maintainers/vcpkg_fixup_cmake_targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Additionally corrects common issues with targets, such as absolute paths and inc

## Usage
```cmake
vcpkg_fixup_cmake_targets([CONFIG_PATH <share/${PORT}>] [TARGET_PATH <share/${PORT}>] [DO_NOT_DELETE_PARENT_CONFIG_PATH])
vcpkg_fixup_cmake_targets([CONFIG_PATH <share/${PORT}>]
[TARGET_PATH <share/${PORT}>]
[TOOLS_PATH <tools/${PORT}>]
[DO_NOT_DELETE_PARENT_CONFIG_PATH])
```

## Parameters
Expand All @@ -36,12 +39,15 @@ Disables the correction of_IMPORT_PREFIX done by vcpkg due to moving the targets
Currently the correction does not take into account how the files are moved and applies
I rather simply correction which in some cases will yield the wrong results.

### TOOLS_PATH
Define the base path to tools. Default: `tools/<PORT>`

## Notes
Transform all `/debug/<CONFIG_PATH>/*targets-debug.cmake` files and move them to `/<TARGET_PATH>`.
Removes all `/debug/<CONFIG_PATH>/*targets.cmake` and `/debug/<CONFIG_PATH>/*config.cmake`.

Transform all references matching `/bin/*.exe` to `/tools/<port>/*.exe` on Windows.
Transform all references matching `/bin/*` to `/tools/<port>/*` on other platforms.
Transform all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
Transform all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.

Fix `${_IMPORT_PREFIX}` in auto generated targets to be one folder deeper.
Replace `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs and targets.
Expand Down
16 changes: 12 additions & 4 deletions scripts/cmake/vcpkg_copy_tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Copy tools and all their DLL dependencies into the `tools` folder.
vcpkg_copy_tools(
TOOL_NAMES <tool1>...
[SEARCH_DIR <${CURRENT_PACKAGES_DIR}/bin>]
[DESTINATION <${CURRENT_PACKAGES_DIR}/tools/${PORT}>]
[AUTO_CLEAN]
)
```
Expand All @@ -18,6 +19,9 @@ 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.
### DESTINATION
Destination to copy the tools to. This will be set to `${CURRENT_PACKAGES_DIR}/tools/${PORT}` if ommited.
### AUTO_CLEAN
Auto clean executables in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`.
Expand All @@ -30,12 +34,16 @@ Auto clean executables in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_

function(vcpkg_copy_tools)
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
cmake_parse_arguments(PARSE_ARGV 0 _vct "AUTO_CLEAN" "SEARCH_DIR" "TOOL_NAMES")
cmake_parse_arguments(PARSE_ARGV 0 _vct "AUTO_CLEAN" "SEARCH_DIR;DESTINATION" "TOOL_NAMES")

if(NOT DEFINED _vct_TOOL_NAMES)
message(FATAL_ERROR "TOOL_NAMES must be specified.")
endif()

if(NOT DEFINED _vct_DESTINATION)
set(_vct_DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
endif()

if(NOT DEFINED _vct_SEARCH_DIR)
set(_vct_SEARCH_DIR "${CURRENT_PACKAGES_DIR}/bin")
elseif(NOT IS_DIRECTORY ${_vct_SEARCH_DIR})
Expand All @@ -46,18 +54,18 @@ function(vcpkg_copy_tools)
set(tool_path "${_vct_SEARCH_DIR}/${tool_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}")
set(tool_pdb "${_vct_SEARCH_DIR}/${tool_name}.pdb")
if(EXISTS "${tool_path}")
file(COPY "${tool_path}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
file(COPY "${tool_path}" DESTINATION "${_vct_DESTINATION}")
else()
message(FATAL_ERROR "Couldn't find this tool: ${tool_path}.")
endif()
if(EXISTS "${tool_pdb}")
file(COPY "${tool_pdb}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
file(COPY "${tool_pdb}" DESTINATION "${_vct_DESTINATION}")
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}")
vcpkg_copy_tool_dependencies("${_vct_DESTINATION}")
endfunction()
22 changes: 16 additions & 6 deletions scripts/cmake/vcpkg_fixup_cmake_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Additionally corrects common issues with targets, such as absolute paths and inc
## Usage
```cmake
vcpkg_fixup_cmake_targets([CONFIG_PATH <share/${PORT}>] [TARGET_PATH <share/${PORT}>] [DO_NOT_DELETE_PARENT_CONFIG_PATH])
vcpkg_fixup_cmake_targets([CONFIG_PATH <share/${PORT}>]
[TARGET_PATH <share/${PORT}>]
[TOOLS_PATH <tools/${PORT}>]
[DO_NOT_DELETE_PARENT_CONFIG_PATH])
```
## Parameters
Expand All @@ -35,12 +38,15 @@ Disables the correction of_IMPORT_PREFIX done by vcpkg due to moving the targets
Currently the correction does not take into account how the files are moved and applies
I rather simply correction which in some cases will yield the wrong results.
### TOOLS_PATH
Define the base path to tools. Default: `tools/<PORT>`
## Notes
Transform all `/debug/<CONFIG_PATH>/*targets-debug.cmake` files and move them to `/<TARGET_PATH>`.
Removes all `/debug/<CONFIG_PATH>/*targets.cmake` and `/debug/<CONFIG_PATH>/*config.cmake`.
Transform all references matching `/bin/*.exe` to `/tools/<port>/*.exe` on Windows.
Transform all references matching `/bin/*` to `/tools/<port>/*` on other platforms.
Transform all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
Transform all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.
Fix `${_IMPORT_PREFIX}` in auto generated targets to be one folder deeper.
Replace `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs and targets.
Expand All @@ -57,7 +63,7 @@ function(vcpkg_fixup_cmake_targets)
message(FATAL_ERROR "The ${PORT} port already depends on vcpkg-cmake-config; using both vcpkg-cmake-config and vcpkg_fixup_cmake_targets in the same port is unsupported.")
endif()

cmake_parse_arguments(PARSE_ARGV 0 arg "DO_NOT_DELETE_PARENT_CONFIG_PATH" "CONFIG_PATH;TARGET_PATH;NO_PREFIX_CORRECTION" "")
cmake_parse_arguments(PARSE_ARGV 0 arg "DO_NOT_DELETE_PARENT_CONFIG_PATH" "CONFIG_PATH;TARGET_PATH;NO_PREFIX_CORRECTION;TOOLS_PATH" "")

if(arg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_fixup_cmake_targets was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
Expand All @@ -66,6 +72,10 @@ function(vcpkg_fixup_cmake_targets)
if(NOT arg_TARGET_PATH)
set(arg_TARGET_PATH share/${PORT})
endif()

if(NOT arg_TOOLS_PATH)
set(arg_TOOLS_PATH tools/${PORT})
endif()

string(REPLACE "." "\\." EXECUTABLE_SUFFIX "${VCPKG_TARGET_EXECUTABLE_SUFFIX}")

Expand Down Expand Up @@ -148,7 +158,7 @@ function(vcpkg_fixup_cmake_targets)
foreach(RELEASE_TARGET IN LISTS RELEASE_TARGETS)
file(READ ${RELEASE_TARGET} _contents)
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" _contents "${_contents}")
string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \"]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" _contents "${_contents}")
string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \"]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/${arg_TOOLS_PATH}/\\1" _contents "${_contents}")
file(WRITE ${RELEASE_TARGET} "${_contents}")
endforeach()

Expand All @@ -161,7 +171,7 @@ function(vcpkg_fixup_cmake_targets)

file(READ ${DEBUG_TARGET} _contents)
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" _contents "${_contents}")
string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \";]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" _contents "${_contents}")
string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \";]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/${arg_TOOLS_PATH}/\\1" _contents "${_contents}")
string(REPLACE "\${_IMPORT_PREFIX}/lib" "\${_IMPORT_PREFIX}/debug/lib" _contents "${_contents}")
string(REPLACE "\${_IMPORT_PREFIX}/bin" "\${_IMPORT_PREFIX}/debug/bin" _contents "${_contents}")
file(WRITE ${RELEASE_SHARE}/${DEBUG_TARGET_REL} "${_contents}")
Expand Down

0 comments on commit 2779b73

Please sign in to comment.