Reland "[CMake] Do not set CMP0116 explicitly to old (#90385)"

This reverts commit fa65a228f4.

This relands commit ab405fb6e9.

There was an issue where CMake versions <3.23.0 would not properly parse
dep files, causing the build to file. This patch fixes that by just
making CMake versions <3.23.0 use the fallback behavior.
This commit is contained in:
Aiden Grossman
2025-04-26 17:58:54 +00:00
parent 3f5dc586ef
commit 2f08927fd5
3 changed files with 36 additions and 30 deletions

View File

@@ -1,11 +1,5 @@
# CMake policy settings shared between LLVM projects
# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()`
# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html
if(POLICY CMP0116)
cmake_policy(SET CMP0116 OLD)
endif()
# MSVC debug information format flags are selected via
# CMAKE_MSVC_DEBUG_INFORMATION_FORMAT, instead of
# embedding flags in e.g. CMAKE_CXX_FLAGS_RELEASE.

View File

@@ -21,20 +21,26 @@ function(tablegen project ofn)
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
endif()
# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
if(CMAKE_GENERATOR MATCHES "Ninja")
# Make output path relative to build.ninja, assuming located on
# ${CMAKE_BINARY_DIR}.
# Use depfile instead of globbing arbitrary *.td(s) for Ninja. We force
# CMake versions older than v3.30 on Windows to use the fallback behavior
# due to a depfile parsing bug on Windows paths in versions prior to 3.30.
# https://gitlab.kitware.com/cmake/cmake/-/issues/25943
# CMake versions older than v3.23 on other platforms use the fallback
# behavior as v3.22 and earlier fail to parse some depfiles that get
# generated, and this behavior was fixed in CMake commit
# e04a352cca523eba2ac0d60063a3799f5bb1c69e.
cmake_policy(GET CMP0116 cmp0116_state)
if(CMAKE_GENERATOR MATCHES "Ninja" AND cmp0116_state STREQUAL NEW
AND NOT (CMAKE_HOST_WIN32 AND CMAKE_VERSION VERSION_LESS 3.30)
AND NOT (CMAKE_VERSION VERSION_LESS 3.23))
# CMake emits build targets as relative paths but Ninja doesn't identify
# absolute path (in *.d) as relative path (in build.ninja)
# Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory.
file(RELATIVE_PATH ofn_rel
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
# absolute path (in *.d) as relative path (in build.ninja). Post CMP0116,
# CMake handles this discrepancy for us, otherwise we use the fallback
# logic.
set(additional_cmdline
-o ${ofn_rel}
-d ${ofn_rel}.d
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
-o ${ofn}
-d ${ofn}.d
DEPFILE ${ofn}.d
)
set(local_tds)
set(global_tds)

View File

@@ -42,20 +42,26 @@ function(_pdll_tablegen project ofn)
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
endif()
# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
if(CMAKE_GENERATOR MATCHES "Ninja")
# Make output path relative to build.ninja, assuming located on
# ${CMAKE_BINARY_DIR}.
# Use depfile instead of globbing arbitrary *.td(s) for Ninja. We force
# CMake versions older than v3.30 on Windows to use the fallback behavior
# due to a depfile parsing bug on Windows paths in versions prior to 3.30.
# https://gitlab.kitware.com/cmake/cmake/-/issues/25943
# CMake versions older than v3.23 on other platforms use the fallback
# behavior as v3.22 and earlier fail to parse some depfiles that get
# generated, and this behavior was fixed in CMake commit
# e04a352cca523eba2ac0d60063a3799f5bb1c69e.
cmake_policy(GET CMP0116 cmp0116_state)
if(CMAKE_GENERATOR MATCHES "Ninja" AND cmp0116_state STREQUAL NEW
AND NOT (CMAKE_HOST_WIN32 AND CMAKE_VERSION VERSION_LESS 3.30)
AND NOT (CMAKE_VERSION VERSION_LESS 3.23))
# CMake emits build targets as relative paths but Ninja doesn't identify
# absolute path (in *.d) as relative path (in build.ninja)
# Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory.
file(RELATIVE_PATH ofn_rel
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
# absolute path (in *.d) as relative path (in build.ninja). Post CMP0116,
# CMake handles this discrepancy for us. Otherwise, we use the fallback
# logic.
set(additional_cmdline
-o ${ofn_rel}
-d ${ofn_rel}.d
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
-o ${ofn}
-d ${ofn}.d
DEPFILE ${ofn}.d
)
set(local_tds)
set(global_tds)