Skip to content

Commit 0aeeff3

Browse files
committed
[libclc] Allow building with pre-built tools
Building the libclc project in-tree with debug tools can be very slow. This commit adds an option for a user to specify a dierctory from which to import (e.g., release-built) tools. All tools required by the project must be imported from the same location, for simplicity. Original patch downstream authored by @jchlanda.
1 parent 93d5119 commit 0aeeff3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

libclc/CMakeLists.txt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI
5050
endif()
5151

5252
# Import required tools as targets
53-
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
54-
find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
55-
add_executable( libclc::${tool} IMPORTED GLOBAL )
56-
set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION ${LLVM_TOOL_${tool}} )
57-
endforeach()
53+
if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
54+
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
55+
find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
56+
add_executable( libclc::${tool} IMPORTED GLOBAL )
57+
set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION ${LLVM_TOOL_${tool}} )
58+
endforeach()
59+
endif()
5860
else()
5961
# In-tree configuration
6062
set( LIBCLC_STANDALONE_BUILD FALSE )
@@ -68,8 +70,27 @@ else()
6870
message(FATAL_ERROR "Clang is not enabled, but is required to build libclc in-tree")
6971
endif()
7072

73+
if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
74+
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
75+
add_executable(libclc::${tool} ALIAS ${tool})
76+
endforeach()
77+
endif()
78+
endif()
79+
80+
if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
81+
message( WARNING "Using custom LLVM tools to build libclc: "
82+
"${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "
83+
" ensure the tools are up to date." )
84+
# Note - use a differently named variable than LLVM_TOOL_${tool} as above, as
85+
# the variable name is used to cache the result of find_program. If we used
86+
# the same name, a user wouldn't be able to switch a build between default
87+
# and custom tools.
7188
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
72-
add_executable(libclc::${tool} ALIAS ${tool})
89+
find_program( LLVM_CUSTOM_TOOL_${tool} ${tool}
90+
PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
91+
add_executable( libclc::${tool} IMPORTED GLOBAL )
92+
set_target_properties( libclc::${tool} PROPERTIES
93+
IMPORTED_LOCATION ${LLVM_CUSTOM_TOOL_${tool}} )
7394
endforeach()
7495
endif()
7596

0 commit comments

Comments
 (0)