Skip to content

[scripts-audit] add guidelines for cmake#18319

Closed
strega-nil wants to merge 12 commits intomicrosoft:masterfrom
strega-nil:scripts-guidelines
Closed

[scripts-audit] add guidelines for cmake#18319
strega-nil wants to merge 12 commits intomicrosoft:masterfrom
strega-nil:scripts-guidelines

Conversation

@strega-nil
Copy link
Contributor

No description provided.

@dg0yt
Copy link
Contributor

dg0yt commented Jun 7, 2021

Any hint about the min version of CMake scripts must be compatible with / the version scripts may assume without checks?

get_cmake_vars requires version 3.17, thus all scripts should require 3.17
update cmake_minimum_required in scripts/ports.cmake
Co-authored-by: ras0219 <533828+ras0219@users.noreply.github.com>
@dg0yt
Copy link
Contributor

dg0yt commented Jun 8, 2021

How about not allowing

set(VAR )

because it is a common trap (in particular with initialization of lists) that the real intention is

set(VAR "")

but the actual effect is

unset(VAR)

which unhides cache variables. So there are two explicit alternatives which are not ugly.

I would also encourage use of

string(APPEND VAR " xxx")

over

set(VAR "${VAR} xxx")

because it makes accidental

set(VAR "${VAR};xxx")

stand out more clearly.

@Neumann-A
Copy link
Contributor

set(VAR) is used to create an empty variable in the local/current scoped thus hiding any higher scoped variables. Setting it to an empty string instead is rarely meant and doesn't play nice with list(APPEND)

@dg0yt
Copy link
Contributor

dg0yt commented Jun 8, 2021

set(VAR) is used to create an empty variable in the local/current scoped thus hiding any higher scoped variables. Setting it to an empty string instead is rarely meant and doesn't play nice with list(APPEND)

This is what I thought until recently. But it is wrong, and that's why I'm bringing it up:

$ cat demo.cmake
set(FOO "Initial")
set(FOO "Cached value" CACHE STRING "doc")
message(STATUS "${FOO}")
set(FOO )
message(STATUS "${FOO}")
list(APPEND FOO "bar")
message(STATUS "${FOO}")
set(FOO "")
list(APPEND FOO "bar")
message(STATUS "${FOO}")
$ cmake -P demo.cmake 
-- Cached value
-- Cached value
-- Cached value;bar
-- bar

@dg0yt
Copy link
Contributor

dg0yt commented Jun 8, 2021

After adding one more message(STATUS "${FOO}"), it turns out that (at least) in script mode, the non-cache variable (aka "set" binding) doesn't even hide the cached variable (aka cache entry). This is in contradiction to cmake documentation. Oh no.

@Neumann-A
Copy link
Contributor

  1. your example should use at least one scope change
  2. cache variables in script mode are kund of funky since there is no concept of cache in script mode(no CMakeCache.txt to store them). So all Cache variables become priority read access.

@dg0yt
Copy link
Contributor

dg0yt commented Jun 8, 2021

  1. your example should use at least one scope change

The result doesn't change when I wrap the code in function(...) ... endfunction().

  1. cache variables in script mode are kund of funky since there is no concept of cache in script mode(no CMakeCache.txt to store them). So all Cache variables become priority read access.

I'm aware that there is no persistent cache in script mode but there are still the different types of variables.
Variable evaluation is documented cmake behaviour, regardless of script mode.
The documented behaviour of set(VAR ) is unsetting (actually creating an "unset" binding), regardless of scope.

I opened https://gitlab.kitware.com/cmake/cmake/-/issues/22285.

@dg0yt
Copy link
Contributor

dg0yt commented Jun 8, 2021

I opened https://gitlab.kitware.com/cmake/cmake/-/issues/22285.

A fix is already merged for CMake 3.21, and there will be a new policy, CMP0126.

My original point stands: set(VAR ) does NOT create an empty variable, and so it doesn't hide anything.

thanks robert!

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
@PhoebeHui
Copy link
Contributor

PhoebeHui commented Jun 11, 2021

  • REGRESSION: opencv4:arm-uwp: There is not enough space on the disk.
  • REGRESSION: qt5-sensors:x64-windows-static-md: Source download issue
  • REGRESSION: qt5-scxml:x64-windows-static-md: Source download issue
  • REGRESSION: otl:x64-linux: The hash changed, need update it. Fixed by PR [vcpkg baseline][otl] Update to 40463 #18383

@strega-nil-ms
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@strega-nil-ms
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Neumann-A
Copy link
Contributor

what about guidelines for vcpkg-cmake-wrapper.cmake?
#18393 (comment) shows that it seems to be required

@dg0yt
Copy link
Contributor

dg0yt commented Jun 15, 2021

what about guidelines for vcpkg-cmake-wrapper.cmake?

Fair, but the dominant problem is that documentation is completely missing vcpkg-cmake-wrapper.cmake and vcpkg-cmake-config.cmake.

- This `cmake_minimum_required` should be bumped every time a new version
of CMake is added to `vcpkgTools.xml`, as should the
`cmake_minimum_required` in all of the helper `CMakeLists.txt` files.
- `vcpkg.cmake` must assume a version of CMake back to 3.1 in general
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For vcpkg-cmake-wrapper.cmake scripts, version 3.1 even excludes if("value" IN_LIST FEATURES). This makes it more complicated to deal with port features or even with arguments to find_package (e.g. port tiff).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vcpkg.cmake must assume a version of CMake back to 3.1 in general

Is sentence is nonsense and should be ignored. I think the correct phrasing would be that vcpkg.cmake must assume that the toplevel CMakeLists.txt might not have a cmake_minimum_required or a very low cmake_minimum_required. As such, setting appropriate cmake policies are a requirement. vcpkg assume that it is at least executed with a cmake binary of <some cmake version|preferly the cmake version used by vcpkg>.
If there is somebody really arguing for a cmake binary of 3.1 I would like to have him/her invent vcpkg.old.cmake .....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we really do support CMake version back to CMake 3.1 in vcpkg.cmake. There are extra features that require more recent versions, but we do support back to CMake 3.1 (or there's a bug.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to keep it at 3.1?
What is the threshold for moving it to another version?
As I already wrote:

For vcpkg-cmake-wrapper.cmake scripts, version 3.1 even excludes if("value" IN_LIST FEATURES).

which is relevant for dealing with transitive dependencies.

Copy link
Contributor

@strega-nil-ms strega-nil-ms Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not consider ports as having to support any specific version of CMake; they can support whatever they want. All we need is that, if a port supports CMake 3.1, and the user uses 3.1 for their build, it works.

As to upgrading, not sure.

@strega-nil-ms
Copy link
Contributor

@dg0yt @Neumann-A that would be good guidelines, but these are meant more for the scripts under the scripts tree.

@PhoebeHui PhoebeHui added the info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. label Jul 2, 2021
- `include()`s are only allowed in `ports.cmake` or `vcpkg-port-config.cmake`.
- `foreach(RANGE)`'s arguments _must always be_ natural numbers,
and `<start>` _must always be_ less than or equal to `<stop>`.
- This must be checked.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- This must be checked.
- This must be checked by <insert copypaste code snippet here>.

@PhoebeHui
Copy link
Contributor

Tensorflow:x64-osx failure would be fixed by PR #18812

@strega-nil-ms
Copy link
Contributor

Closed for rollup PR #18838

strega-nil-ms pushed a commit to strega-nil/vcpkg that referenced this pull request Jul 9, 2021
[scripts-audit] add guidelines for cmake
BillyONeal pushed a commit that referenced this pull request Jul 14, 2021
* [rollup:2021-07-06 1/8] PR #18272 (@strega-nil)

[scripts-audit] vcpkg_from_*

* [rollup:2021-07-06 2/8] PR #18319 (@strega-nil)

[scripts-audit] add guidelines for cmake

* [rollup 2021-07-06 3/8] PR #18410 (@mheyman)

[vcpkg-cmake-config] documentation fix

* [rollup:2021-07-06 4/8] PR #18488 (@strega-nil)

[scripts-audit] vcpkg_execute_*

* [rollup:2021-07-06 5/8] PR #18517 (@strega-nil)

[scripts-audit] vcpkg_extract_source_archive

* [rollup:2021-07-06 6/8] PR #18674 (@NancyLi1013)

[vcpkg doc] Update examples

* [rollup:2021-07-06 7/8] PR #18695 (@JackBoosY)

[vcpkg] Update the minimum version of vcpkg

* [rollup:2021-07-06 8/8] PR #18758 (@ras0219-msft)

[vcpkg_from_git] Fix error if downloads folder does not exist

* build docs!

* fix bond:*-windows

* fix nmap

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Co-authored-by: Michael Heyman <Michael.Heyman@jhuapl.edu>
Co-authored-by: NancyLi1013 <lirui09@beyondsoft.com>
Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
Co-authored-by: Robert Schumacher <ras0219@outlook.com>
@strega-nil strega-nil deleted the scripts-guidelines branch July 16, 2021 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants