Skip to content

Commit fa490e1

Browse files
committed
[comgr] fix detecting SPIR-V include path for LLVMSPIRVLib.h in comgr
- Improve SPIR-V support detection in comgr by searching for LLVMSPIRVLib.h in three candidate locations: 1. ${LLVM_INCLUDE_DIRS}/LLVMSPIRVLib (standalone builds) 2. ${LLVM_EXTERNAL_SPIRV_LLVM_TRANSLATOR_SOURCE_DIR}/include (external project builds) 3. ${CMAKE_SOURCE_DIR}/projects/SPIRV-LLVM-Translator/include (default llvm-spirv location) - Use the first valid path found to enable SPIR-V support and add the appropriate include directory to amd_comgr. - If the header is not found in any of the candidate locations, disable SPIR-V support as before. - This change improves build robustness for various repo and CMake configurations, including standalone and external project builds.
1 parent 0de3479 commit fa490e1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

amd/comgr/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,24 @@ message("")
179179
option(COMGR_DISABLE_SPIRV "To disable SPIRV in Comgr" OFF)
180180

181181
if (NOT COMGR_DISABLE_SPIRV)
182-
# TODO: Explore switching this to CHECK_INCLUDE_FILE_CXX() macro
183-
if (NOT EXISTS "${LLVM_INCLUDE_DIRS}/LLVMSPIRVLib/LLVMSPIRVLib.h")
182+
# Candidate include paths for LLVMSPIRVLib.h:
183+
# 1. ${LLVM_INCLUDE_DIRS}/LLVMSPIRVLib (standalone build)
184+
# 2. ${LLVM_EXTERNAL_SPIRV_LLVM_TRANSLATOR_SOURCE_DIR}/include (external project)
185+
# 3. ${CMAKE_SOURCE_DIR}/projects/SPIRV-LLVM-Translator/include (usual location)
186+
find_path(
187+
FOUND_SPIRV_INCLUDE_DIR
188+
LLVMSPIRVLib.h
189+
PATHS
190+
"${LLVM_INCLUDE_DIRS}/LLVMSPIRVLib"
191+
"${LLVM_EXTERNAL_SPIRV_LLVM_TRANSLATOR_SOURCE_DIR}/include"
192+
"${CMAKE_SOURCE_DIR}/projects/SPIRV-LLVM-Translator/include"
193+
NO_DEFAULT_PATH
194+
)
195+
if (NOT EXISTS "${FOUND_SPIRV_INCLUDE_DIR}/LLVMSPIRVLib.h")
184196
message("-- LLVMSPIRVLib/LLVMSPIRVLib.h not found")
185197
set(COMGR_DISABLE_SPIRV ON)
186198
else()
187-
message("-- LLVMSPIRVLib/LLVMSPIRVLib.h found")
199+
message("-- LLVMSPIRVLib/LLVMSPIRVLib.h found at ${FOUND_SPIRV_INCLUDE_DIR}")
188200
endif()
189201
endif()
190202

@@ -195,7 +207,7 @@ else()
195207
message("-- Comgr SPIRV Enabled")
196208
target_include_directories(amd_comgr
197209
PRIVATE
198-
"${LLVM_INCLUDE_DIRS}/LLVMSPIRVLib")
210+
"${FOUND_SPIRV_INCLUDE_DIR}")
199211
endif()
200212

201213

0 commit comments

Comments
 (0)