Skip to content

Commit 54860fb

Browse files
boomanaiden154SquallATF
authored andcommitted
Reland "[CMake] Do not set CMP0116 explicitly to old (llvm#90385)"
This reverts commit fa65a22. This relands commit ab405fb. 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.
1 parent 3b43fe9 commit 54860fb

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

cmake/Modules/CMakePolicy.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# CMake policy settings shared between LLVM projects
22

3-
# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()`
4-
# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html
5-
if(POLICY CMP0116)
6-
cmake_policy(SET CMP0116 OLD)
7-
endif()
8-
93
# MSVC debug information format flags are selected via
104
# CMAKE_MSVC_DEBUG_INFORMATION_FORMAT, instead of
115
# embedding flags in e.g. CMAKE_CXX_FLAGS_RELEASE.

llvm/cmake/modules/TableGen.cmake

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@ function(tablegen project ofn)
2121
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
2222
endif()
2323

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

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,26 @@ function(_pdll_tablegen project ofn)
4242
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
4343
endif()
4444

45-
# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
46-
if(CMAKE_GENERATOR MATCHES "Ninja")
47-
# Make output path relative to build.ninja, assuming located on
48-
# ${CMAKE_BINARY_DIR}.
45+
# Use depfile instead of globbing arbitrary *.td(s) for Ninja. We force
46+
# CMake versions older than v3.30 on Windows to use the fallback behavior
47+
# due to a depfile parsing bug on Windows paths in versions prior to 3.30.
48+
# https://gitlab.kitware.com/cmake/cmake/-/issues/25943
49+
# CMake versions older than v3.23 on other platforms use the fallback
50+
# behavior as v3.22 and earlier fail to parse some depfiles that get
51+
# generated, and this behavior was fixed in CMake commit
52+
# e04a352cca523eba2ac0d60063a3799f5bb1c69e.
53+
cmake_policy(GET CMP0116 cmp0116_state)
54+
if(CMAKE_GENERATOR MATCHES "Ninja" AND cmp0116_state STREQUAL NEW
55+
AND NOT (CMAKE_HOST_WIN32 AND CMAKE_VERSION VERSION_LESS 3.30)
56+
AND NOT (CMAKE_VERSION VERSION_LESS 3.23))
4957
# CMake emits build targets as relative paths but Ninja doesn't identify
50-
# absolute path (in *.d) as relative path (in build.ninja)
51-
# Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory.
52-
file(RELATIVE_PATH ofn_rel
53-
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
58+
# absolute path (in *.d) as relative path (in build.ninja). Post CMP0116,
59+
# CMake handles this discrepancy for us. Otherwise, we use the fallback
60+
# logic.
5461
set(additional_cmdline
55-
-o ${ofn_rel}
56-
-d ${ofn_rel}.d
57-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
58-
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
62+
-o ${ofn}
63+
-d ${ofn}.d
64+
DEPFILE ${ofn}.d
5965
)
6066
set(local_tds)
6167
set(global_tds)

0 commit comments

Comments
 (0)