@@ -116,12 +116,54 @@ execute_process( COMMAND ${LLVM_CONFIG} "--bindir"
116
116
# These were not properly reported in early LLVM and we don't need them
117
117
list ( APPEND LLVM_CXX_FLAGS -fno-rtti -fno-exceptions )
118
118
119
+ # Use custom toolchain to build libclc, this can be useful when dealing with
120
+ # debug builds, that do not need libclc bitcode to be built using debug tools.
121
+ if ( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
122
+ message ( WARNING "Using custom LLVM tools to build libclc: "
123
+ "${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} , "
124
+ " make sure that the tools are up to date." )
125
+
126
+ # find_program needs the variable to be cleared in order to perform a search.
127
+ # Make sure that the cached entries are cleared as well.
128
+ unset ( LLVM_CLANG CACHE )
129
+ unset ( LLVM_AS CACHE )
130
+ unset ( LLVM_LINK CACHE )
131
+ unset ( LLVM_OPT CACHE )
132
+ unset ( LLVM_SPIRV CACHE )
133
+ unset ( LIBCLC_REMANGLER CACHE )
134
+ unset ( LLVM_CLANG )
135
+ unset ( LLVM_AS )
136
+ unset ( LLVM_LINK )
137
+ unset ( LLVM_OPT )
138
+ unset ( LLVM_SPIRV )
139
+ unset ( LIBCLC_REMANGLER )
140
+ find_program ( LLVM_CLANG clang PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
141
+ NO_DEFAULT_PATH )
142
+ find_program ( LLVM_AS llvm-as PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
143
+ NO_DEFAULT_PATH )
144
+ find_program ( LLVM_LINK llvm-link PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
145
+ NO_DEFAULT_PATH )
146
+ find_program ( LLVM_OPT opt PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
147
+ NO_DEFAULT_PATH )
148
+ find_program ( LLVM_SPIRV llvm-spirv
149
+ PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
150
+ find_program ( LIBCLC_REMANGLER libclc-remangler
151
+ PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
152
+ if ( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK
153
+ OR NOT LIBCLC_REMANGLER )
154
+ message ( WARNING
155
+ "Custom toolchain incomplete, will try the default location." )
156
+ endif ()
157
+ endif ()
158
+
119
159
# Print LLVM variables
120
160
message ( "LLVM libdir: ${LLVM_LIBRARY_DIR} " )
121
161
message ( "LLVM bindir: ${LLVM_TOOLS_BINARY_DIR} " )
122
162
message ( "LLVM cxx flags: ${LLVM_CXX_FLAGS} " )
123
163
message ( "" )
124
164
165
+ # It's OK to call find program again, if the variables have been set in the
166
+ # custom location clause, find_program returns immediately.
125
167
find_program ( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
126
168
find_program ( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
127
169
find_program ( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
0 commit comments