From fa65a228f4b46346e69e9b95805a8bcfa8483a60 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Sat, 26 Apr 2025 04:51:16 +0000 Subject: [PATCH] Revert "[CMake] Do not set CMP0116 explicitly to old (#90385)" This reverts commit ab405fb6e9ff9202ca722f632b945d4b84c653f5. This caused quite a few buildbot failures that need further investigation. --- cmake/Modules/CMakePolicy.cmake | 6 ++++++ llvm/cmake/modules/TableGen.cmake | 25 ++++++++++++------------- mlir/cmake/modules/AddMLIR.cmake | 25 ++++++++++++------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/cmake/Modules/CMakePolicy.cmake b/cmake/Modules/CMakePolicy.cmake index 421f5a4dda6c..bafd6bb5b025 100644 --- a/cmake/Modules/CMakePolicy.cmake +++ b/cmake/Modules/CMakePolicy.cmake @@ -1,5 +1,11 @@ # 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. diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake index dfe002fde43f..bf914c379e80 100644 --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/cmake/modules/TableGen.cmake @@ -21,21 +21,20 @@ function(tablegen project ofn) message(FATAL_ERROR "${project}_TABLEGEN_EXE not set") endif() - # 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_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)) + # 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}. # CMake emits build targets as relative paths but Ninja doesn't identify - # absolute path (in *.d) as relative path (in build.ninja). Post CMP0116, - # CMake handles this discrepancy for us, otherwise we use the fallback - # logic. + # 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}) set(additional_cmdline - -o ${ofn} - -d ${ofn}.d - DEPFILE ${ofn}.d + -o ${ofn_rel} + -d ${ofn_rel}.d + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d ) set(local_tds) set(global_tds) diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake index e923950f9c81..2fc84a5b2879 100644 --- a/mlir/cmake/modules/AddMLIR.cmake +++ b/mlir/cmake/modules/AddMLIR.cmake @@ -42,21 +42,20 @@ function(_pdll_tablegen project ofn) message(FATAL_ERROR "${project}_TABLEGEN_EXE not set") endif() - # 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_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)) + # 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}. # CMake emits build targets as relative paths but Ninja doesn't identify - # absolute path (in *.d) as relative path (in build.ninja). Post CMP0116, - # CMake handles this discrepancy for us. Otherwise, we use the fallback - # logic. + # 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}) set(additional_cmdline - -o ${ofn} - -d ${ofn}.d - DEPFILE ${ofn}.d + -o ${ofn_rel} + -d ${ofn_rel}.d + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d ) set(local_tds) set(global_tds)