Skip to content

[CMake][TableGen] Make TableGen CMake functions compatible with CMP0116 #72333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions llvm/cmake/modules/TableGen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,34 @@ function(tablegen project ofn)

# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
if(CMAKE_GENERATOR MATCHES "Ninja")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(CMAKE_GENERATOR MATCHES "Ninja" AND cmp0116_state STREQUAL "NEW")

I think it would be fair to fall back to file(GLOB) if CMP0116 is OLD.

# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we omit it since we use CMake>=3.20?

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
)
Comment on lines +38 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may rely on the new policy and drop old logic.
Instead, we could delegate to fallback logic file(GLOB).

endif()
set(local_tds)
set(global_tds)
else()
Expand Down
39 changes: 27 additions & 12 deletions mlir/cmake/modules/AddMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,34 @@ function(_pdll_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
)
endif()
set(local_tds)
set(global_tds)
else()
Expand Down