CMP0116 warning triggered even though path given to DEPFILE is absolute
I'm using CMake 3.20.0-rc5 on Qt6 sources with the Ninja generator on macOS. In one of the repos, there is a call to add_custom_command()
which includes a DEPFILE
keyword. The argument that follows after that keyword is always an absolute path. This call occurs in a subdirectory, not the top level CMakeLists.txt file. You can find the relevant code here. That code currently specifies the .cpp file in that depfile as relative, but even after I locally ensure it is absolute, the warning discussed here is still emitted.
The CMP0116 policy is not set (policy range in effect at that point is 3.14...3.19). According to the docs, I would not expect this situation to issue any warning, since an absolute path given to DEPFILE
is unambiguous and therefore not subject to any misinterpretation due to the problem the policy addresses. Despite this, after the configure stage but before the generation stage, I see many CMP0116 warnings that stem from this add_custom_command()
call. An example warning looks like this:
CMake Warning (dev) at qtdeclarative/src/qml/Qt6QmlMacros.cmake:831 (add_custom_command):
Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
add_custom_command(). Run "cmake --help-policy CMP0116" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Call Stack (most recent call first):
qtdeclarative/src/qml/CMakeLists.txt:661 (qt6_qml_type_registration)
This warning is for project developers. Use -Wno-dev to suppress it.
Looking at the code here, it appears the warning is triggered any time the current binary directory is different to the top level binary directory and CMP0116 is not set, regardless of whether the path to the depfile or its contents use relative or absolute paths.
Locally, I have explicitly set the policy around that call to confirm that all the warnings go away when CMP0116 is set to NEW, but this should not be necessary. I also confirmed by printing out the filename that it was indeed always an absolute path.