[clang] e432108 - [CMake] Add `CLANG_ENABLE_HLSL` CMake option

Chris Bieneman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 10:33:33 PDT 2022


Author: Chris Bieneman
Date: 2022-09-27T12:33:22-05:00
New Revision: e432108bf25456f428a3956fd79d29ea7fc196ac

URL: https://github.com/llvm/llvm-project/commit/e432108bf25456f428a3956fd79d29ea7fc196ac
DIFF: https://github.com/llvm/llvm-project/commit/e432108bf25456f428a3956fd79d29ea7fc196ac.diff

LOG: [CMake] Add `CLANG_ENABLE_HLSL` CMake option

The HLSL support in clang is in progress and not fully functioning. As
such we don't want to install the related optional build components by
default (yet), but we do need an option to build and install them
locally for testing and for some key users.

This adds the `CLANG_ENABLE_HLSL` option which is off by default and can
be enabled to install the HLSL clang headers and the clang-dxc symlink.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D134693

Added: 
    

Modified: 
    clang/CMakeLists.txt
    clang/cmake/caches/HLSL.cmake
    clang/lib/Headers/CMakeLists.txt
    clang/tools/driver/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 22b5118c83eda..f43fa51a3379c 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -482,6 +482,10 @@ option(CLANG_INCLUDE_TESTS
        "Generate build targets for the Clang unit tests."
        ${LLVM_INCLUDE_TESTS})
 
+option(CLANG_ENABLE_HLSL "Include HLSL build products" Off)
+# While HLSL support is experimental this should stay hidden.
+mark_as_advanced(CLANG_ENABLE_HLSL)
+
 add_subdirectory(utils/TableGen)
 
 # Export CLANG_TABLEGEN_EXE for use by flang docs.

diff  --git a/clang/cmake/caches/HLSL.cmake b/clang/cmake/caches/HLSL.cmake
index e2d02b6b281a3..71f81e53f6bd3 100644
--- a/clang/cmake/caches/HLSL.cmake
+++ b/clang/cmake/caches/HLSL.cmake
@@ -9,3 +9,5 @@ set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD DirectX CACHE STRING "")
 # HLSL support is currently limted to clang, eventually it will expand to
 # clang-tools-extra too.
 set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+
+set(CLANG_ENABLE_HLSL On CACHE BOOL "")

diff  --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index c374580ceb5c8..b8ee1fec86a2a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -62,11 +62,15 @@ set(hip_files
   __clang_hip_runtime_wrapper.h
   )
 
-set(hlsl_files
-  hlsl.h
+set(hlsl_h hlsl.h)
+set(hlsl_subdir_files
   hlsl/hlsl_basic_types.h
   hlsl/hlsl_intrinsics.h
   )
+set(hlsl_files
+  ${hlsl_h}
+  ${hlsl_subdir_files}
+  )
 
 set(mips_msa_files
   msa.h
@@ -548,10 +552,20 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+if(NOT CLANG_ENABLE_HLSL)
+  set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
+endif()
+
 install(
-  FILES ${hlsl_files}
+  FILES ${hlsl_h}
   DESTINATION ${header_install_dir}
-  EXCLUDE_FROM_ALL
+  ${EXCLUDE_HLSL}
+  COMPONENT hlsl-resource-headers)
+
+install(
+  FILES ${hlsl_subdir_files}
+  DESTINATION ${header_install_dir}/hlsl
+  ${EXCLUDE_HLSL}
   COMPONENT hlsl-resource-headers)
 
 install(

diff  --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt
index d05b71db13f21..e233ee7168080 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -61,7 +61,11 @@ if(NOT CLANG_LINKS_TO_CREATE)
   set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
 endif()
 
-foreach(link ${CLANG_LINKS_TO_CREATE})
+if (CLANG_ENABLE_HLSL)
+  set(HLSL_LINK clang-dxc)
+endif()
+
+foreach(link ${CLANG_LINKS_TO_CREATE} ${HLSL_LINK})
   add_clang_symlink(${link} clang)
 endforeach()
 


        


More information about the cfe-commits mailing list