intel / intel-graphics-compiler

Other
594 stars 155 forks source link

CMake failure when multiple OpenCL headers found #336

Open pvelesko opened 1 month ago

pvelesko commented 1 month ago

Multiple opencl-c.h exist in LLVM that was built specifically for compiling intel compute runtime:

╭─pvelesko@cupcake /space/pvelesko/intel-compute-runtime-build ‹main●› 
╰─$ find  ~/space/install/llvm/14.0-neo -name "opencl-c.h"                                                                                                                                                                                                                                                        130 ↵
/home/pvelesko/space/install/llvm/14.0-neo/include/cclang/opencl-c.h
/home/pvelesko/space/install/llvm/14.0-neo/lib/clang/14.0.6/include/opencl-c.h

Cmake fails in this case because opencl-header is a list. The following patch fixes the issue by picking the first header found

diff --git a/IGC/BiFModule/CMakeLists.txt b/IGC/BiFModule/CMakeLists.txt
index 445818747..1fb6b50fe 100644
--- a/IGC/BiFModule/CMakeLists.txt
+++ b/IGC/BiFModule/CMakeLists.txt
@@ -45,6 +45,10 @@ if(UNIX)
     install(FILES $<TARGET_SONAME_FILE:opencl-clang-lib> DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT igc-opencl)

     # Get header opencl-c.h directory
+    list(LENGTH opencl-header len)
+    if(len GREATER 1)
+         list(GET opencl-header 0 opencl-header)
+      endif()
     get_filename_component(opencl-headers-dir ${opencl-header} DIRECTORY)

     set(opencl-headers "${opencl-header}")