Skip to content

Commit

Permalink
CMake dxc as subproject fixes (microsoft#6050)
Browse files Browse the repository at this point in the history
These changes allow us to use DXC as as CMake subproject (via
add_subdirectory).

Commit comments from each commit:

===

cmake: allow CMAKE_INSTALL_RPATH to be defined in superproject on APPLE
platforms

As on Linux, allow CMAKE_INSTALL_RPATH to be defined in a CMake
superproject.

===

cmake: Allow LLVM_ENABLE_ASSERTIONS=OFF to disable assertions in Debug
builds

Currently, this flag is only used to enable assertions in non-Debug
builds, but is not respected in Debug builds. That is, if set to false,
Debug builds will still assert. This change fixes that.

Note that by default, LLVM_ENABLE_ASSERTIONS is true in Debug builds, so
unless it's explicitly set to false, this is a no-op for most people.

===

cmake: Allow DIRECTX_HEADERS_INCLUDE_DIR to be defined from superproject

Useful for when DXC is included as a subdirectory. In Dawn/Chrome, we
use our own mirror of DirectX-Headers instead of checking out the repo's
submodules, so we need to override this variable.
  • Loading branch information
amaiorano authored Nov 22, 2023
1 parent 71afbcc commit 37a0826
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,10 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}

set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if (APPLE)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
if(NOT DEFINED CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
endif(NOT DEFINED CMAKE_INSTALL_RPATH)
else(UNIX)
if(NOT DEFINED CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
Expand Down
5 changes: 5 additions & 0 deletions cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ if( LLVM_ENABLE_ASSERTIONS )
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
endforeach()
endif()
else()
# Disable assertions in Debug builds
if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
add_definitions( -DNDEBUG )
endif()
endif()

string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)
Expand Down
16 changes: 9 additions & 7 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ if (NOT HLSL_ENABLE_DEBUG_ITERATORS)
endif (NOT HLSL_ENABLE_DEBUG_ITERATORS)

# Need DirectX-Headers module if not on windows
if (NOT WIN32)
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
else()
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
endif()
endif (NOT WIN32)
if (NOT DIRECTX_HEADER_INCLUDE_DIR)
if (NOT WIN32)
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
else()
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
endif()
endif (NOT WIN32)
endif(NOT DIRECTX_HEADER_INCLUDE_DIR)

# Enabling SPIR-V codegen requires SPIRV-Headers for spirv.hpp and
# SPIRV-Tools for SPIR-V disassembling functionality.
Expand Down

0 comments on commit 37a0826

Please sign in to comment.