doctest: cmake: Warning/error because of low minimum required cmake version
Description
Doctest CMakeLists.txt contains the following line:
cmake_minimum_required(VERSION 3.0)
When doctest is used in another CMake project as test framework, the following CMake warning is shown:
CMake Deprecation Warning at build/_deps/doctest-src/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
This warning can be removed by adapting the line using the solution below:
# -- SOLUTION NEEDS: CMAKE_MIN_VERSION >= 3.5
cmake_minimum_required(VERSION 3.5)
AFFECTED FILES IN REPOSITORY:
CMakeLists.txtexamples/installed_doctest_cmake/executable/CMakeLists.txtexamples/installed_doctest_cmake/dll/CMakeLists.txtscripts/how_stuff_works/CMakeLists.txt
Steps to reproduce
$ pip install cmake
$ cmake --version
cmake version 3.29.3
$ cmake -S . -B build
...
CMake Deprecation Warning at build/_deps/doctest-src/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
...
Extra information
- doctest version: v2.4.11
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 15 (11 by maintainers)
Commits related to this issue
- Temporarily(?) use Doctest fork to fix CMake CMake has been issuing deprecation warnings for Doctest for quite a while now (https://github.com/doctest/doctest/issues/854), and unfortunately CMake 4.0... — committed to tcbrindle/flux by tcbrindle 2 years ago
- Update to Doctest v2.4.12 https://github.com/doctest/doctest/issues/854 has now been fixed (at least until the next CMake minimum version bump), so switch back to using the latest upstream Doctest ra... — committed to tcbrindle/flux by tcbrindle a year ago
For anyone else who finds themselves here because Doctest no longer works with CMake 4, I’ve created a temporary fork of the master branch that fixes the issue. Feel free to use it until such time as we get an updated Doctest release:
https://github.com/tcbrindle/doctest/tree/cmake4-fix
Specifically, it has a one-line change that sets the CMake policy version to 3.10, while keeping the minimum version at 3.0.
Based on this I’m simply merging dev to master. I haven’t read anything else from this issue. Any further changes should come in future PRs and someone else will handle that
Thanks for your input @a4z . Then it does sound like the cmake strategy is to continuously bump up the minimum required version in order to stay forward compatible with future versions of cmake. While I think this is weird from a semver perspective, I’ll stay practical and accept that this is the way it works 😃
@onqtam TL;DR: A new release is required to help downstream consumers using cmake 4.x. All necessary changes are already in dev branch.
This issue is tricky. Changing minimum required version to 3.5 breaks downstream consumers who use 3.0 … 3.4 . As noted in the deprecation warning, one can whitelist maximum allowed versions to circumvent this.
The deprecation is introduced in 3.27: https://cmake.org/cmake/help/latest/release/3.27.html . However, they don’t say why it’s deprecated… and I hope that “future versions” means cmake 4.xx (that’s the point of semver right?).
There is a simple workaround though, add
-Wno-deprecatedflag to cmake. If you don’t rely on any new features introduced in cmake >= 3.27, then you can downgrade cmake to 3.26 also.Longer discussion on how to “actually” solve this
Question is, what changes between 3.0 and 3.5 are cmake actually deprecating? Looking at release notes for cmake 3.28 they deprecate
exec_programwhich seems to be a left over from cmake 2.xx series. It is not used in doctest cmake lists. Otherwise deprecations seems to be related to some CUDA, Python, Dart, Visual Studio and Xcode stuff. I did some grepping in the code base and could find no usage of these.If we can ensure that doctest doesn’t use any deprecated feature then we can declare compatibility with the <min>…<max> syntax. However, then the responsibility to ensure compatibility with newer versions of cmake lies on doctest devs, which needs to be continuously bumped up and tested with new cmake versions.
There is no good solution here I think, I don’t think it’s worth the trouble doing it. Instead, let us assume that cmake will not break semver and we can postpone this for cmake 4.xx.