-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vcpkg] Fix toolchain compatibility with cmake < 3.15 #18898
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do ...
That's what I already did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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 --all
and committed the result?not needed