Browse Source

Setup `install-distribution` target for DXC (#5154)

* [CMake] Update distribution build for DXC

Building off the LLVM 3.9 changes, this gets the `install-distribution`
target working for DXC with preset parameters that configure the
normal distribution. It also enables the DXC distribution to be built
through Visual Studio builds since DXC has a limited number of
components so it doesn't suffer from the IDE issues that upstream
LLVM & Clang do.

The `hctbuild` tooling has been updated to set a default install
prefix relative to the build directory, and allow overriding with a flag.

Cherry-picked commit details below:

From c90e12fe9fd7eb9fd7b342e7ac0cec971dd3e4db Mon Sep 17 00:00:00 2001
From: Chris Bieneman <[email protected]>
Date: Tue, 23 Feb 2016 20:33:53 +0000
Subject: [PATCH] [CMake] Create an install-distribution target driven by LLVM_DISTRIBUTION_COMPONENTS

The idea here is to provide a customizable install target that only depends on building the things you actually want to install. It relies on each component being installed having an auto-generated install-${component}, which in turn depends only on the target being installed.

This is fundamentally a workaround for the fact that CMake generates build files which have their "install" target depend on the "all" target. This results in "ninja install" building a bunch of unneeded things.

llvm-svn: 261681
Chris B 2 years ago
parent
commit
4f5e4d1b74

+ 20 - 0
CMakeLists.txt

@@ -788,6 +788,26 @@ endif()
 
 include(CoverageReport)
 
+# HLSL Change begin - Set default distribution value.
+set(LLVM_DISTRIBUTION_COMPONENTS "dxc;dxcompiler;dxc-headers" CACHE STRING "")
+# HLSL Change end - Set default distribution value.
+
+# This must be at the end of the LLVM root CMakeLists file because it must run
+# after all targets are created.
+if(LLVM_DISTRIBUTION_COMPONENTS)
+  # HLSL Change - Deleted restriction for non-IDE builds. This works with Visual
+  # Studio for DXC because of the limited number of targets.
+  
+  add_custom_target(install-distribution)
+  foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
+    if(TARGET install-${target})
+      add_dependencies(install-distribution install-${target})
+    else()
+      message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")
+    endif()
+  endforeach()
+endif()
+
 # Disable regeneration target for official builds as they always fun a full clean build.
 # This should eliminate the race-condition issue with "Cannot restore timestamp".
 if (HLSL_OFFICIAL_BUILD)

+ 26 - 0
include/dxc/CMakeLists.txt

@@ -15,3 +15,29 @@ add_subdirectory(DxilContainer)
 add_subdirectory(HLSL)
 add_subdirectory(Support)
 add_subdirectory(Tracing)
+
+set(DXC_PUBLIC_HEADERS
+    ${CMAKE_CURRENT_SOURCE_DIR}/dxcapi.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/dxcerrors.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/dxcisense.h)
+
+if (NOT WIN32)
+  set(DXC_PLATFORM_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/WinAdapter.h)
+endif()
+
+# This target just needs to exist for the distribution build, it doesn't need to
+# actually build anything since the headers are static.
+add_custom_target(dxc-headers)
+
+install(FILES 
+    ${DXC_PUBLIC_HEADERS}
+    ${DXC_PLATFORM_PUBLIC_HEADERS}
+    DESTINATION include/dxc
+    COMPONENT dxc-headers
+    )
+
+add_custom_target(install-dxc-headers
+    DEPENDS dxc-headers
+    COMMAND "${CMAKE_COMMAND}"
+            -DCMAKE_INSTALL_COMPONENT=dxc-headers
+            -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")

+ 8 - 1
tools/clang/tools/dxc/CMakeLists.txt

@@ -51,5 +51,12 @@ else()
 endif()
 
 install(TARGETS dxc
-  RUNTIME DESTINATION bin)
+  RUNTIME DESTINATION bin
+  COMPONENT dxc)
+
+add_custom_target(install-dxc
+  DEPENDS dxc
+  COMMAND "${CMAKE_COMMAND}"
+          -DCMAKE_INSTALL_COMPONENT=dxc
+          -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
 

+ 16 - 0
tools/clang/tools/dxcompiler/CMakeLists.txt

@@ -141,3 +141,19 @@ set_target_properties(dxcompiler
   OUTPUT_NAME "dxcompiler"
   VERSION ${LIBCLANG_LIBRARY_VERSION}
   DEFINE_SYMBOL _CINDEX_LIB_)
+
+if (WIN32)
+  set(install_dest RUNTIME DESTINATION bin)
+else()
+  set(install_dest LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+endif()
+
+install(TARGETS dxcompiler
+  ${install_dest}
+  COMPONENT dxcompiler)
+
+add_custom_target(install-dxcompiler
+  DEPENDS dxcompiler
+  COMMAND "${CMAKE_COMMAND}"
+          -DCMAKE_INSTALL_COMPONENT=dxcompiler
+          -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")

+ 12 - 0
utils/hct/hctbuild.cmd

@@ -44,6 +44,7 @@ set DXC_CMAKE_SYSTEM_VERSION=
 set SHOW_CMAKE_LOG=0
 set ENABLE_LIT=OFF
 set WINSDK_MIN_VERSION=10.0.17763.0
+set INSTALL_DIR=
 
 :parse_args
 if "%1"=="" (
@@ -227,6 +228,12 @@ if "%1"=="-lto" (
   set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_LTO=On
   shift /1 & goto :parse_args
 )
+if "%1"=="-installdir" (
+  echo Build install directory set to %~2
+  set "INSTALL_DIR=%~2"
+  shift /1
+  shift /1 & goto :parse_args
+)
 if "%1" NEQ "" ( 
     echo Unrecognized argument: %1
     exit /b 1
@@ -238,6 +245,10 @@ if "%HLSL_BLD_DIR%"=="" (
   exit /b 1
 )
 
+if "%INSTALL_DIR%"=="" (
+  set "INSTALL_DIR=%HLSL_BLD_DIR%\install"
+)
+
 if "%CMAKE_PATH%"=="" (
   where cmake.exe 1>nul 2>nul
   if errorlevel 1 (
@@ -322,6 +333,7 @@ set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_DEFAULT_TARGET_TRIPLE:STRING=dxil-ms-dx
 set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_BUILD_EXAMPLES:BOOL=OFF
 set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_CL:BOOL=OFF
 set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_SYSTEM_VERSION=%DXC_CMAKE_SYSTEM_VERSION%
+set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%
 
 rem ARM cross-compile setup
 if %BUILD_ARM_CROSSCOMPILING% == 0 goto :after-cross-compile