[mlir] [llvm] [CMake][TableGen] Make TableGen CMake functions compatible with CMP0116 (PR #72333)
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 06:37:07 PST 2023
================
@@ -19,19 +19,34 @@ function(tablegen project ofn)
# 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)
- # 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_rel}
- -d ${ofn_rel}.d
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
- )
+ # absolute path (in *.d) as relative path (in build.ninja). If CMP0116 is
+ # NEW, CMake handles this discrepancy for us -- otherwise, we have to work
+ # around it ourselves.
+ if(POLICY CMP0116)
+ cmake_policy(GET CMP0116 cmp0116_state)
+ else()
+ set(cmp0116_state OLD)
+ endif()
+ if(cmp0116_state STREQUAL NEW)
+ set(additional_cmdline
+ -o ${ofn}
+ -d ${ofn}.d
+ DEPFILE ${ofn}.d
+ )
+ else()
+ # Make output path relative to build.ninja, assuming located on
+ # ${CMAKE_BINARY_DIR}.
+ # 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_rel}
+ -d ${ofn_rel}.d
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
+ )
----------------
chapuni wrote:
I think we may rely on the new policy and drop old logic.
Instead, we could delegate to fallback logic `file(GLOB)`.
https://github.com/llvm/llvm-project/pull/72333
More information about the llvm-commits
mailing list