CMake CMP0116 policy warning on build
Newer versions of CMake produce the following warnings as a normal part of the build:
Documentation on CMP0116 is as follows:
CMP0116
.. versionadded:: 3.20
Ninja generators transform
DEPFILE
s fromadd_custom_command()
.In CMake 3.19 and below, files given to the
DEPFILE
argument ofadd_custom_command()
were passed directly to Ninja'sdepfile
variable without any path resolution. This meant that ifadd_custom_command()
was called from a subdirectory (created byadd_subdirectory()
), theDEPFILE
argument would have to be either an absolute path or a path relative toCMAKE_BINARY_DIR
, rather thanCMAKE_CURRENT_BINARY_DIR
. In addition, no transformation was done on the file listed inDEPFILE
, which meant that the paths within theDEPFILE
had the same restrictions.Starting with CMake 3.20, the
DEPFILE
argument is relative toCMAKE_CURRENT_BINARY_DIR
(unless it is absolute), and the paths in theDEPFILE
are also relative toCMAKE_CURRENT_BINARY_DIR
. CMake automatically transforms the paths in theDEPFILE
(unless they are absolute) after the custom command is run. The file listed inDEPFILE
is not modified in any way. Instead, CMake writes the transformation to its own internal file, and passes this internal file to Ninja'sdepfile
variable. This transformation happens regardless of whether or notDEPFILE
is relative, and regardless of whether or notadd_custom_command()
is called from a subdirectory.The
OLD
behavior for this policy is to pass theDEPFILE
to Ninja unaltered. TheNEW
behavior for this policy is to transform theDEPFILE
after running the custom command. The status ofCMP0116
is recorded at the time of the custom command's creation, and you can have custom commands in the same directory with different values forCMP0116
by setting the policy before each custom command.This policy was introduced in CMake version 3.20. Unlike most policies, CMake version 3.22.0 does not warn by default when this policy is not set (unless
DEPFILE
is used in a subdirectory) and simply usesOLD
behavior. See documentation of theCMAKE_POLICY_WARNING_CMP0116
variable to control the warning.
Setting an explicit policy for CMP0116 in CMAKE resolves this.