[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: New deprecation warning in CMake 3.27



Hi Kyle,

* Kyle Edwards <kyle.edwards@kitware.com> [2023-06-19 09:18]:
CMake upstream here. We do have a tutorial that we've put together and improved over the last few years that teaches modern CMake and avoids using the old directory-level commands. You can find it here: https://cmake.org/cmake/help/latest/guide/tutorial
I agree that tutorial has improved over the last years.

If you have a cmake_minimum_required() that's older than some of the commands you're using, the expected pattern to avoid using them is:

if(NOT CMAKE_VERSION VERSION_LESS 3.25)
  # Version-gated code here
endif()
Still, I need to be *aware* that a particular command is newer than
my targeted minimum version. I'm really glad that you added the
version info to the documentation with CMake 3.20, but it is still
manual labor. Maybe there is a linter for that, though, I did not check.

More elegant is a version range: if your script does not give
any policy warnings with a recent CMake (say CMake 3.26), you can
write something like "cmake_minimum_required(VERSION 3.0...3.26)"
Please keep in mind that if you set an upper bound, any policies up to that upper bound will automatically be set to NEW, so be sure that your code is ready for that. You could potentially get some unexpected behavior if you have code that uses the OLD behavior of a policy in an older version of CMake and the NEW behavior in a newer version.
You are absolutely right, and that is what I meant to convey with
"does not give any policy warnings": If the newer CMake warns you
that your script relies on some OLD behavior, you need to address
that first. That also implies that you cannot bump the upper bound
beyond a version you have actually tested.


Cheers
Timo

--
⢀⣴⠾⠻⢶⣦⠀   ╭────────────────────────────────────────────────────╮
⣾⠁⢠⠒⠀⣿⡁   │ Timo Röhling                                       │
⢿⡄⠘⠷⠚⠋⠀   │ 9B03 EBB9 8300 DF97 C2B1  23BF CC8C 6BDD 1403 F4CA │
⠈⠳⣄⠀⠀⠀⠀   ╰────────────────────────────────────────────────────╯

Attachment: signature.asc
Description: PGP signature


Reply to: