[CMake] Seemingly-unfixable warning about CMP0058 after upgrade to CMake 3.3

Brad King brad.king at kitware.com
Mon Sep 28 11:51:52 EDT 2015


On 09/27/2015 08:47 PM, Michael Catanzaro wrote:
> CMake Warning (dev):
>   Policy CMP0058 is not set: Ninja requires custom command byproducts to be
>   explicit.  Run "cmake --help-policy CMP0058" for policy details.  Use the
>   cmake_policy command to set the policy and suppress this warning.

Add this code to the project:

 if(POLICY CMP0058)
   cmake_policy(SET CMP0058 NEW)
 endif()

just after any cmake_minimum_required(VERSION) call that does not
specify at least CMake 3.3.  This will set the policy to NEW and get
the new behavior with no warning.  In the future when the project's
call to cmake_minimum_required(VERSION) specifies 3.3 or higher then
this explicit policy setting can be removed.

>   This project specifies custom command DEPENDS on files in the build tree
>   that are not specified as the OUTPUT or BYPRODUCTS of any
>   add_custom_command or add_custom_target:
[snip]
> But DerivedSources/webkit2gtk/WebKit2ResourcesGResourceBundle.xml is
> not generated by add_custom_command or add_custom_target

The warning says the file is in the DEPENDS of a custom command, which
it is.  The warning also says that the file is not specified as generated
by a custom command, which it isn't.  This is a case for which the warning
was intended.

> it's generated by the file command (in WebKit/Source/WebKit2/PlatformGTK.cmake [1]):
> 
> file(WRITE ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.xml
[snip]
> So there's no way to specify it as a BYPRODUCT.
[snip]
>   For compatibility with versions of CMake that did not have the BYPRODUCTS
>   option, CMake is generating phony rules for such files to convince 'ninja'
>   to build.

CMake is warning that it now prefers to generate the Ninja build file
for this case a different way than it did before but is doing it the
old way for compatibility just in case the project needs that to build.
In this case we know we are providing the file ourselves so it is safe
to allow CMake to generate the build file without the extra phony rule.
One can set the policy to NEW to get the new preferred behavior, but
this has to be done in the project itself once it is known that the new
behavior works for the project.

See the full policy documentation here for more details:

 https://cmake.org/cmake/help/v3.3/policy/CMP0058.html

-Brad



More information about the CMake mailing list