if(... IS_NEWER_THAN ...) is misleading and easy to misuse
As discovered in !5825 (merged), the if(file1 IS_NEWER_THAN file2)
test condition is misleadingly named and has other surprising (but documented) behavior. If returns true in the following cases:
-
file1
is missing. -
file2
is missing. -
file1
andfile2
have the same timestamp. - The timestamp of
file1
is later than the timestamp offile2
.
Of the above, only the last would intuitively be expected based on the name of the keyword. CMake's own modules and tests contained a number of cases where at least one of the above conditions was not expected or handled correctly. One could reasonably expect that there will be many projects which unknowingly do likewise too.
I propose that we introduce some alternative keywords with more intuitive and safer behavior. We can also make them consistent with other existing keywords by using the form FILE_TIMESTAMP_<op>
in the same way that we have VERSION_GREATER
, VERSION_LESS_EQUAL
, etc. They should halt with an error if either file is missing.
I'm not sure if we should also deprecate the IS_NEWER_THAN
keyword. I'd like to, but I'm not sure if that could be a stronger source of irritation than other typical deprecations. Issuing a deprecation message may be worthwhile, since it would likely reveal currently undiagnosed bugs in projects.