[vcpkg] Fix toolchain compatibility with cmake < 3.15#18898
[vcpkg] Fix toolchain compatibility with cmake < 3.15#18898dg0yt wants to merge 4 commits intomicrosoft:masterfrom
Conversation
|
CI didn't rebuild a single port, despite touching |
|
CC @autoantwort This amends #17336. |
a long standing very serious issue |
There is already microsoft/vcpkg-tool#80 |
Not sure if you really want to invalidate binary artifacts for each change, even documentation typos. And this won't add testing for cmake versions which are claimed to be supported (cf. https://github.com/microsoft/vcpkg/pull/18319/files#r652632414). FTR, you can't work around the current bug with VCPKG_PREFER_SYSTEM_LIBS=ON because this is not passed from the user project to cmake ports built by vcpkg, including |
I thought the same, I searched for an issue complaining about it but couldn't find one. |
scripts/buildsystems/vcpkg.cmake
Outdated
| if(VCPKG_PREFER_SYSTEM_LIBS) | ||
| set(Z_VCPKG_PATH_LIST_OP APPEND) | ||
| list(LENGTH CMAKE_PREFIX_PATH Z_VCPKG_PREFIX_PATH_POS) | ||
| list(LENGTH CMAKE_LIBRARY_PATH Z_VCPKG_LIBRARY_PATH_POS) | ||
| list(LENGTH CMAKE_FIND_ROOT_PATH Z_VCPKG_FIND_ROOT_PATH_POS) | ||
| else() | ||
| set(Z_VCPKG_PATH_LIST_OP PREPEND) | ||
| set(Z_VCPKG_PREFIX_PATH_POS 0) | ||
| set(Z_VCPKG_LIBRARY_PATH_POS 0) | ||
| set(Z_VCPKG_FIND_ROOT_PATH_POS 0) | ||
| endif() |
There was a problem hiding this comment.
One could probably do:
function(z_vcpkg_path_list_op out_var lst paths)
if(VCPKG_PREFER_SYSTEM_LIBS)
set("${out_var}" "${lst};${paths}" PARENT_SCOPE)
else()
set("${out_var}" "${paths};${lst}" PARENT_SCOPE)
endif()
endfunction()There was a problem hiding this comment.
Does "one could probably do" mean I should update the PR? I would prefer to stick to plain cmake. If there shall be a function I would prefer a name which catures the specific operation "add" or "merge" instead of the generic "op", e.g. z_vcpkg_add_to_system_libs in analogy to VCPKG_PREFER_SYSTEM_LIBS.
There was a problem hiding this comment.
I would prefer to switch to this; I don't like how this is currently working. Doing this weird INSERT bodging feels bad.
There was a problem hiding this comment.
set("${out_var}" "${paths};${lst}" PARENT_SCOPE) doesn't work correctly for empty lists.
And list(INSERT ...) is unable to append.
😕
There was a problem hiding this comment.
Doing this weird INSERT bodging feels bad.
@strega-nil INSERT is also used by VTK to insert into the beginning of CMAKE_MODULE_PATH. It is the correct way to PREPEND.
And list(INSERT ...) is unable to append.
@dg0yt: have you tried using -1 as an index? Otherwise that is the reason why list(APPEND) existed from the beginning while PREPEND was added much later (since INSERT 0 just worked for this instead)
To add: From the 3.0 docs:
If is -1 or lesser, it is indexed from the end of the list, with -1 representing the last list element.
There was a problem hiding this comment.
have you tried using -1 as an index? Otherwise that is the reason why list(APPEND) existed from the beginning while PREPEND was added much later (since INSERT 0 just worked for this instead)
To add: From the 3.0 docs:
If is -1 or lesser, it is indexed from the end of the list, with -1 representing the last list element.
Yes, I tried in a separate cmake script. INSERT inserts before the given list element, and INSERT -1 inserts before the last list element.
CMake lists aren't C++ containers...
There was a problem hiding this comment.
You can do:
if(VCPKG_PREFER_SYSTEM_LIBS)
list(APPEND lst "${paths}")
else()
list(INSERT lst 0 "${paths}")
endif()
set("${out_var}" "${lst}" PARENT_SCOPE)There was a problem hiding this comment.
You can do ...
That's what I already did.
There was a problem hiding this comment.
oh, sorry, I clearly didn't reread the PR.
|
Will be bundled in next roll-up to trigger world rebuild |
|
Closed for rollup |
[vcpkg] Fix toolchain compatibility with cmake < 3.15
* [rollup:2021-07-26 1/6] PR #18783 (@strega-nil) [scripts-audit] vcpkg_copy_tools and friends * [rollup:2021-07-26 2/6] PR #18898 (@dg0yt) [vcpkg] Fix toolchain compatibility with cmake < 3.15 * [rollup:2021-07-26 3/6] PR #18980 (@strega-nil) [cmake-guidelines] Minor update, for `if()` * [rollup:2021-07-26 4/6] PR #18981 (@strega-nil) [scripts-audit] vcpkg_check_linkage * [rollup:2021-07-26 5/6] PR #19158 (@Hoikas) [vcpkg.cmake] Fix variable case. * [rollup:2021-07-26 6/6] PR #18839 [scripts-audit] z_vcpkg_get_cmake_vars Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Since 876e67c, the toolchain used
list(PREPEND ...)by default. But this cmake command was introduced in cmake 3.15, and the toolchain is meant to work with 3.1 [!].What does your PR fix?
This PR restores compatibility with cmake < 3.15 for user projects, fixing:
Tested with CMake 3.10 (Ubuntu 18.04).
Which triplets are supported/not supported? Have you updated the CI baseline?
all, no
Does your PR follow the maintainer guide?
yes
If you have added/updated a port: Have you run
./vcpkg x-add-version --alland committed the result?not needed