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

CMake prints a spammy warning about "policy CMP0000" #8355

Closed
ulfalizer opened this issue Jun 13, 2018 · 16 comments · Fixed by #9186
Closed

CMake prints a spammy warning about "policy CMP0000" #8355

ulfalizer opened this issue Jun 13, 2018 · 16 comments · Fixed by #9186
Assignees
Labels
area: Build System Enhancement Changes/Updates/Additions to existing features

Comments

@ulfalizer
Copy link
Collaborator

I'm a CMake noob, so I have no idea what the proper fix is here, but having 12 lines of spam about CMP0000 whenever you run CMake is pretty bad:

CMake Deprecation Warning at /home/ulf/zephyr/cmake/app/boilerplate.cmake:38 (cmake_policy):
  The OLD behavior for policy CMP0000 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:2 (include)
@SebastianBoe SebastianBoe added Enhancement Changes/Updates/Additions to existing features area: Build System labels Jun 13, 2018
@SebastianBoe
Copy link
Collaborator

This affects CMake version >= 3.9.0 so the simplest solution is to use CMake 3.8.x.

Last I looked into this I concluded that longterm we need to either fork CMake or convince upstream to allow projects to suppress this warning, as they were allowed to before 3.9.x.

Any other solution suggestions are welcome.

@ulfalizer
Copy link
Collaborator Author

What about not using "the OLD behavior for policy CMP0000", whatever that means?

@SebastianBoe
Copy link
Collaborator

IIRC that creates bigger problems than this warning, can't remember the details though.

@ulfalizer
Copy link
Collaborator Author

Probably worth looking into.

@ulfalizer
Copy link
Collaborator Author

@tejlmand
Do you know anything about this btw? :)

@tejlmand
Copy link
Collaborator

What CMake requires is the line:
cmake_minimum_required(VERSION a.b), e.g.
cmake_minimum_required(VERSION 3.8.2) as it is written in
cmake/app/boilerplate.cmake
to be placed in the top-level CMakeLists.txt file.
(CMake doesn't allow this line to be in an included file)

Setting the CMP0000 allows this line to be placed in another file
but as CMake warns, this will be removed in future.

So CMake tells us we should write:
cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
in all sample apps.

I'm unaware why it was chosen to not write this line in all CMakeLists.txt app files, but I could imagine that it makes life harder if bumping the CMake version in future as all files would need to be updated.

Although a search and replace should be easy in this case.
https://cmake.org/cmake/help/v3.11/policy/CMP0000.html

Out of curiosity I would like to hear more about what problems placing this line in sample apps is causing.

@SebastianBoe
Copy link
Collaborator

SebastianBoe commented Jun 19, 2018

but I could imagine that it makes life harder if bumping the CMake version in future as all files would need to be updated

Yep. And more importantly, backwards-compatibility with customer applications.

@SebastianBoe
Copy link
Collaborator

I wonder, does CMake support multiple invocations of minimum required?

Then we would not have a compatibility issue when bumping the version ...

@SebastianBoe
Copy link
Collaborator

I imagine they don't, the whole point is for them to be able to determine how CMake should behave as early as possible ...

@ulfalizer
Copy link
Collaborator Author

Guess it might need to be changed anyway eventually, since the warning says that the behavior will be removed.

@tejlmand
Copy link
Collaborator

Multiple invocations of cmake_minimum_required is allowed.
This is very useful when you include other projects, which might have different requirements.

Imagine if you have project A, e.g. Zephyr, which requires version 3.8, and you then include mbedTLS, which requires, let's say version 3.10 in its CMakeLists.txt file.
Then CMake will complain if you're running version 3.9.

But versions 3.10 and above are fine, as it satisfies the versions specified for both Zephyr and mbedTLS :)

@tejlmand
Copy link
Collaborator

@SebastianBoe Do you know why version 3.8.2 is chosen ?
Is zephyr using any 3.8 specific features or was it just the version most people were running at that time, so it's not verified to work with older versions. (which is a very good reason)

For fun, I just tried run CMake version 3.5.1 without any apparent problems (except I had to specify a lower required version)

https://cmake.org/cmake/help/v3.8/release/3.8.html

@SebastianBoe
Copy link
Collaborator

Multiple invocations of cmake_minimum_required is allowed.

Great!

Then it is safe to duplicate the version information in every application AFAICT.

I can't recall how we landed on 3.8.2, you would have to check the git history, there has been a back-and-forth. If the version is too high it won't be packaged by distrubutions. If the version is too low you will lose out on features and bugfixes.

It might have been that we wanted to support 3.8.2 so that users could avoid the issue reported here. But since multiple invocations of cmake_minimum_required is permitted we might not need to work around it any more.

@henrikbrixandersen
Copy link
Member

Still, git ls-files '**/CMakeLists.txt' | xargs sed -i '1s/^/cmake_minimum_required(VERSION 3.8.2)\n/' gives us approximately 780 added lines of boiler plate code...

@tejlmand
Copy link
Collaborator

you should disregard files under subsys/ ext/ kernel/, etc.
Only the entry point for the applications, i.e. all CMakeLists.txt files under samples/ and tests/.
which still amounts to roughly ~150 under samples and ~200 under tests.

Basically all the files which contains the line project(none) would most likely also need the line cmake_minimum_required()

@SebastianBoe
Copy link
Collaborator

@henrikbrixandersen : Yes, not great, but for those that use CMake version > 3.8.x I believe this is the best solution (apart from convincing upstream to re-introduce support for having cmake_minimum_required outside of the toplevel CMakeLists.txt).

SebastianBoe added a commit to SebastianBoe/zephyr that referenced this issue Aug 15, 2018
Prepend the text 'cmake_minimum_required(VERSION 3.8.2)' into the
application and test build scripts.

Modern versions of CMake will spam users with a deprecation warning
when the toplevel CMakeLists.txt does not specify a CMake
version. This is documented in bug zephyrproject-rtos#8355.

To resolve this we include a cmake_minimum_required() line into the
toplevel build scripts. Additionally, cmake_minimum_required is
invoked from within boilerplate.cmake. The highest version will be
enforced.

This patch allows us to afterwards change CMake policy CMP000 from OLD
to NEW which in turn finally rids us of the verbose warning.

The extra boilerplate is considered more acceptable than the verbosity
of the CMP0000 policy.

Signed-off-by: Sebastian Bøe <[email protected]>
SebastianBoe added a commit to SebastianBoe/zephyr that referenced this issue Aug 15, 2018
Change CMake policy CMP0000 from OLD to NEW to resolve zephyrproject-rtos#8355.

Signed-off-by: Sebastian Bøe <[email protected]>
nashif pushed a commit that referenced this issue Aug 15, 2018
Prepend the text 'cmake_minimum_required(VERSION 3.8.2)' into the
application and test build scripts.

Modern versions of CMake will spam users with a deprecation warning
when the toplevel CMakeLists.txt does not specify a CMake
version. This is documented in bug #8355.

To resolve this we include a cmake_minimum_required() line into the
toplevel build scripts. Additionally, cmake_minimum_required is
invoked from within boilerplate.cmake. The highest version will be
enforced.

This patch allows us to afterwards change CMake policy CMP000 from OLD
to NEW which in turn finally rids us of the verbose warning.

The extra boilerplate is considered more acceptable than the verbosity
of the CMP0000 policy.

Signed-off-by: Sebastian Bøe <[email protected]>
nashif pushed a commit that referenced this issue Aug 15, 2018
Change CMake policy CMP0000 from OLD to NEW to resolve #8355.

Signed-off-by: Sebastian Bøe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants