Skip to content
6 changes: 0 additions & 6 deletions cmake/Modules/CMakePolicy.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 8 additions & 11 deletions llvm/cmake/modules/TableGen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ function(tablegen project ofn)
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}.
cmake_policy(GET CMP0116 CMP0116_STATE)
if(CMAKE_GENERATOR MATCHES "Ninja" AND CMP0116_STATE STREQUAL NEW)
# 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)
Expand Down
19 changes: 8 additions & 11 deletions mlir/cmake/modules/AddMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ function(_pdll_tablegen project ofn)
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}.
cmake_policy(GET CMP0116 CMP0116_STATE)
if(CMAKE_GENERATOR MATCHES "Ninja" AND CMP0116_STATE STREQUAL NEW)
# 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)
Expand Down
Loading