mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 02:42:48 +08:00
[vcpkg_host_path_list] add SET subcommand (#20879)
* [vcpkg_host_path_list] add SET subcommand * update docs * try to do something that Billy might like more? * wheee Co-authored-by: nicole mazzuca <mazzucan@outlook.com> Co-authored-by: PhoebeHui <20694052+PhoebeHui@users.noreply.github.com>
This commit is contained in:
parent
fdb593292c
commit
bad2c589d5
@ -7,6 +7,7 @@ Modify a host path list variable (PATH, INCLUDE, LIBPATH, etc.)
|
|||||||
```cmake
|
```cmake
|
||||||
vcpkg_host_path_list(PREPEND <list-var> [<path>...])
|
vcpkg_host_path_list(PREPEND <list-var> [<path>...])
|
||||||
vcpkg_host_path_list(APPEND <list-var> [<path>...])
|
vcpkg_host_path_list(APPEND <list-var> [<path>...])
|
||||||
|
vcpkg_host_path_list(SET <list-var> [<path>...])
|
||||||
```
|
```
|
||||||
|
|
||||||
`<list-var>` may be either a regular variable name, or `ENV{variable-name}`,
|
`<list-var>` may be either a regular variable name, or `ENV{variable-name}`,
|
||||||
@ -15,12 +16,14 @@ in which case `vcpkg_host_path_list` will modify the environment.
|
|||||||
`vcpkg_host_path_list` adds all of the paths passed to it to `<list-var>`;
|
`vcpkg_host_path_list` adds all of the paths passed to it to `<list-var>`;
|
||||||
`PREPEND` puts them before the existing list, so that they are searched first;
|
`PREPEND` puts them before the existing list, so that they are searched first;
|
||||||
`APPEND` places them after the existing list,
|
`APPEND` places them after the existing list,
|
||||||
so they would be searched after the paths which are already in the variable.
|
so they would be searched after the paths which are already in the variable,
|
||||||
|
and `SET` replaces the value of the existing list.
|
||||||
|
|
||||||
For both `APPEND` and `PREPEND`,
|
For all of `APPEND`, `PREPEND`, and `SET`,
|
||||||
the paths are added (and thus searched) in the order received.
|
the paths are added (and thus searched) in the order received.
|
||||||
|
|
||||||
If no paths are passed, then nothing will be done.
|
If no paths are passed to `APPEND` or `PREPEND`, nothing will be done;
|
||||||
|
for `SET`, the variable will be set to the empty string.
|
||||||
|
|
||||||
## Source
|
## Source
|
||||||
[scripts/cmake/vcpkg\_host\_path\_list.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_host_path_list.cmake)
|
[scripts/cmake/vcpkg\_host\_path\_list.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_host_path_list.cmake)
|
||||||
|
@ -6,6 +6,7 @@ Modify a host path list variable (PATH, INCLUDE, LIBPATH, etc.)
|
|||||||
```cmake
|
```cmake
|
||||||
vcpkg_host_path_list(PREPEND <list-var> [<path>...])
|
vcpkg_host_path_list(PREPEND <list-var> [<path>...])
|
||||||
vcpkg_host_path_list(APPEND <list-var> [<path>...])
|
vcpkg_host_path_list(APPEND <list-var> [<path>...])
|
||||||
|
vcpkg_host_path_list(SET <list-var> [<path>...])
|
||||||
```
|
```
|
||||||
|
|
||||||
`<list-var>` may be either a regular variable name, or `ENV{variable-name}`,
|
`<list-var>` may be either a regular variable name, or `ENV{variable-name}`,
|
||||||
@ -14,13 +15,36 @@ in which case `vcpkg_host_path_list` will modify the environment.
|
|||||||
`vcpkg_host_path_list` adds all of the paths passed to it to `<list-var>`;
|
`vcpkg_host_path_list` adds all of the paths passed to it to `<list-var>`;
|
||||||
`PREPEND` puts them before the existing list, so that they are searched first;
|
`PREPEND` puts them before the existing list, so that they are searched first;
|
||||||
`APPEND` places them after the existing list,
|
`APPEND` places them after the existing list,
|
||||||
so they would be searched after the paths which are already in the variable.
|
so they would be searched after the paths which are already in the variable,
|
||||||
|
and `SET` replaces the value of the existing list.
|
||||||
|
|
||||||
For both `APPEND` and `PREPEND`,
|
For all of `APPEND`, `PREPEND`, and `SET`,
|
||||||
the paths are added (and thus searched) in the order received.
|
the paths are added (and thus searched) in the order received.
|
||||||
|
|
||||||
If no paths are passed, then nothing will be done.
|
If no paths are passed to `APPEND` or `PREPEND`, nothing will be done;
|
||||||
|
for `SET`, the variable will be set to the empty string.
|
||||||
#]===]
|
#]===]
|
||||||
|
|
||||||
|
function(z_vcpkg_translate_to_host_path_list out_var lst)
|
||||||
|
if(NOT DEFINED arg_UNPARSED_ARGUMENTS)
|
||||||
|
set("${out_var}" "" PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
if("${VCPKG_HOST_PATH_SEPARATOR}" STREQUAL ";")
|
||||||
|
set("${out_var}" "${lst}" PARENT_SCOPE)
|
||||||
|
|
||||||
|
string(FIND "${lst}" [[\;]] index_of_host_path_separator)
|
||||||
|
else()
|
||||||
|
vcpkg_list(JOIN lst "${VCPKG_HOST_PATH_SEPARATOR}" arguments)
|
||||||
|
set("${out_var}" "${arguments}" PARENT_SCOPE)
|
||||||
|
|
||||||
|
string(FIND "${lst}" "${VCPKG_HOST_PATH_SEPARATOR}" index_of_host_path_separator)
|
||||||
|
endif()
|
||||||
|
if(NOT "${index_of_host_path_separator}" EQUAL "-1")
|
||||||
|
message(FATAL_ERROR "Host path separator (${VCPKG_HOST_PATH_SEPARATOR}) in path; this is unsupported.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(vcpkg_host_path_list)
|
function(vcpkg_host_path_list)
|
||||||
if("${ARGC}" LESS "2")
|
if("${ARGC}" LESS "2")
|
||||||
message(FATAL_ERROR "vcpkg_host_path_list requires at least two arguments.")
|
message(FATAL_ERROR "vcpkg_host_path_list requires at least two arguments.")
|
||||||
@ -44,30 +68,20 @@ function(vcpkg_host_path_list)
|
|||||||
set(operation "${ARGV0}")
|
set(operation "${ARGV0}")
|
||||||
set(list_var "${ARGV1}")
|
set(list_var "${ARGV1}")
|
||||||
|
|
||||||
if("${operation}" MATCHES "^(APPEND|PREPEND)$")
|
cmake_parse_arguments(PARSE_ARGV 2 arg "" "" "")
|
||||||
cmake_parse_arguments(PARSE_ARGV 2 arg "" "" "")
|
z_vcpkg_translate_to_host_path_list(arguments "${arg_UNPARSED_ARGUMENTS}")
|
||||||
if(NOT DEFINED arg_UNPARSED_ARGUMENTS)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("${VCPKG_HOST_PATH_SEPARATOR}" STREQUAL ";")
|
if("${operation}" STREQUAL "SET")
|
||||||
set(to_add "${arg_UNPARSED_ARGUMENTS}")
|
set(list "${arguments}")
|
||||||
string(FIND "${arg_UNPARSED_ARGUMENTS}" [[\;]] index_of_host_path_separator)
|
elseif("${operation}" MATCHES "^(APPEND|PREPEND)$")
|
||||||
else()
|
if("${arguments}" STREQUAL "")
|
||||||
vcpkg_list(JOIN arg_UNPARSED_ARGUMENTS "${VCPKG_HOST_PATH_SEPARATOR}" to_add)
|
# do nothing
|
||||||
string(FIND "${arg_UNPARSED_ARGUMENTS}" "${VCPKG_HOST_PATH_SEPARATOR}" index_of_host_path_separator)
|
elseif("${list}" STREQUAL "")
|
||||||
endif()
|
set(list "${arguments}")
|
||||||
|
|
||||||
if(NOT "${index_of_host_path_separator}" EQUAL "-1")
|
|
||||||
message(FATAL_ERROR "Host path separator (${VCPKG_HOST_PATH_SEPARATOR}) in path; this is unsupported.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("${list}" STREQUAL "")
|
|
||||||
set(list "${to_add}")
|
|
||||||
elseif(arg_PREPEND)
|
elseif(arg_PREPEND)
|
||||||
set(list "${to_add}${VCPKG_HOST_PATH_SEPARATOR}${list}")
|
set(list "${arguments}${VCPKG_HOST_PATH_SEPARATOR}${list}")
|
||||||
else()
|
else()
|
||||||
set(list "${list}${VCPKG_HOST_PATH_SEPARATOR}${to_add}")
|
set(list "${list}${VCPKG_HOST_PATH_SEPARATOR}${arguments}")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Operation ${operation} not recognized.")
|
message(FATAL_ERROR "Operation ${operation} not recognized.")
|
||||||
|
Loading…
Reference in New Issue
Block a user