[CMake] Add `CLANG_ENABLE_HLSL` CMake option
authorChris Bieneman <chris.bieneman@me.com>
Tue, 27 Sep 2022 02:44:13 +0000 (21:44 -0500)
committerChris Bieneman <chris.bieneman@me.com>
Tue, 27 Sep 2022 17:33:22 +0000 (12:33 -0500)
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

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

index 22b5118..f43fa51 100644 (file)
@@ -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.
index e2d02b6..71f81e5 100644 (file)
@@ -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 "")
index c374580..b8ee1fe 100644 (file)
@@ -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(
index d05b71d..e233ee7 100644 (file)
@@ -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()