Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

dg0yt
Copy link
Contributor

@dg0yt dg0yt commented Jul 10, 2021

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:

    CMake Error at /home/dg0yt/Projekte/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:390 (list):
      list does not recognize sub-command PREPEND
    

    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

@dg0yt
Copy link
Contributor Author

dg0yt commented Jul 10, 2021

CI didn't rebuild a single port, despite touching vcpkg.cmake.
There is no automated test of building at least a dummy project with the vcpkg toolchain and a supported ancient version of cmake.

@dg0yt
Copy link
Contributor Author

dg0yt commented Jul 10, 2021

CC @autoantwort This amends #17336.

@dg0yt dg0yt marked this pull request as draft July 10, 2021 11:55
@dg0yt dg0yt marked this pull request as ready for review July 10, 2021 11:56
@cenit
Copy link
Contributor

cenit commented Jul 10, 2021

CI didn't rebuild a single port, despite touching vcpkg.cmake.

There is no automated test of building at least a dummy project with the vcpkg toolchain and a supported ancient version of cmake.

a long standing very serious issue
(it has already let slip some bad bugs into master...)

@strega-nil

@autoantwort
Copy link
Contributor

a long standing very serious issue
(it has already let slip some bad bugs into master...)

@strega-nil

There is already microsoft/vcpkg-tool#80

@dg0yt
Copy link
Contributor Author

dg0yt commented Jul 10, 2021

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).
(Nobody noticed the current issue until now. Is cmake 3.1 support really needed?)


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 detect_compiler and get_cmake_vars.

@autoantwort
Copy link
Contributor

(Nobody noticed the current issue until now. Is cmake 3.1 support really needed?)

I thought the same, I searched for an issue complaining about it but couldn't find one.

Comment on lines 384 to 392
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()
Copy link
Contributor

@strega-nil strega-nil Jul 11, 2021

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()

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.
😕

Copy link
Contributor

@Neumann-A Neumann-A Jul 13, 2021

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.

Copy link
Contributor Author

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...

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@dg0yt dg0yt mentioned this pull request Jul 11, 2021
@PhoebeHui PhoebeHui changed the title Fix toolchain compatibility with cmake < 3.15 [vcpkg] Fix toolchain compatibility with cmake < 3.15 Jul 12, 2021
@PhoebeHui PhoebeHui added category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. labels Jul 12, 2021
scripts/buildsystems/vcpkg.cmake Outdated Show resolved Hide resolved
scripts/buildsystems/vcpkg.cmake Outdated Show resolved Hide resolved
scripts/buildsystems/vcpkg.cmake Outdated Show resolved Hide resolved
@vicroms vicroms added info:next-rollup and removed requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. labels Jul 23, 2021
@vicroms
Copy link
Member

vicroms commented Jul 23, 2021

Will be bundled in next roll-up to trigger world rebuild

@strega-nil-ms
Copy link
Contributor

Closed for rollup

strega-nil-ms pushed a commit to strega-nil/vcpkg that referenced this pull request Jul 28, 2021
[vcpkg] Fix toolchain compatibility with cmake < 3.15
strega-nil-ms added a commit that referenced this pull request Jul 29, 2021
* [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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants