Skip to content

Commit 1b58735

Browse files
committedJun 21, 2017
TableGen.cmake: Use DEPFILE for Ninja Generator with CMake>=3.7.
CMake emits build targets as relative paths (from build.ninja) but Ninja doesn't identify absolute path (in *.d) as relative path (in build.ninja). So, let file names, in the command line, relative from ${CMAKE_BINARY_DIR}, where build.ninja is. Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. Differential Revision: https://reviews.llvm.org/D33707 llvm-svn: 305961
1 parent 014db29 commit 1b58735

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed
 

‎llvm/cmake/modules/TableGen.cmake

+26-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,31 @@ function(tablegen project ofn)
1414
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
1515
endif()
1616

17-
file(GLOB local_tds "*.td")
18-
file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td")
17+
# Use depfile instead of globbing arbitrary *.td(s)
18+
# DEPFILE is available for Ninja Generator with CMake>=3.7.
19+
if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_VERSION VERSION_LESS 3.7)
20+
# Make output path relative to build.ninja, assuming located on
21+
# ${CMAKE_BINARY_DIR}.
22+
# CMake emits build targets as relative paths but Ninja doesn't identify
23+
# absolute path (in *.d) as relative path (in build.ninja)
24+
# Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory.
25+
file(RELATIVE_PATH ofn_rel
26+
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
27+
set(additional_cmdline
28+
-o ${ofn_rel}.tmp
29+
-d ${ofn_rel}.d
30+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
Has comments. Original line has comments.
31+
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
32+
)
33+
set(local_tds)
34+
set(global_tds)
35+
else()
36+
file(GLOB local_tds "*.td")
37+
file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td")
38+
set(additional_cmdline
39+
-o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
40+
)
41+
endif()
1942

2043
if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
2144
set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
@@ -44,7 +67,7 @@ function(tablegen project ofn)
4467
COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
4568
${LLVM_TABLEGEN_FLAGS}
4669
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
47-
-o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
70+
${additional_cmdline}
4871
# The file in LLVM_TARGET_DEFINITIONS may be not in the current
4972
# directory and local_tds may not contain it, so we must
5073
# explicitly list it here:

0 commit comments

Comments
 (0)
Please sign in to comment.