Skip to content

Commit 37a0826

Browse files
authored
CMake dxc as subproject fixes (microsoft#6050)
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.
1 parent 71afbcc commit 37a0826

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,10 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}
588588

589589
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
590590
if (APPLE)
591-
set(CMAKE_INSTALL_NAME_DIR "@rpath")
592-
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
591+
if(NOT DEFINED CMAKE_INSTALL_RPATH)
592+
set(CMAKE_INSTALL_NAME_DIR "@rpath")
593+
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
594+
endif(NOT DEFINED CMAKE_INSTALL_RPATH)
593595
else(UNIX)
594596
if(NOT DEFINED CMAKE_INSTALL_RPATH)
595597
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ if( LLVM_ENABLE_ASSERTIONS )
7878
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
7979
endforeach()
8080
endif()
81+
else()
82+
# Disable assertions in Debug builds
83+
if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
84+
add_definitions( -DNDEBUG )
85+
endif()
8186
endif()
8287

8388
string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)

external/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ if (NOT HLSL_ENABLE_DEBUG_ITERATORS)
88
endif (NOT HLSL_ENABLE_DEBUG_ITERATORS)
99

1010
# Need DirectX-Headers module if not on windows
11-
if (NOT WIN32)
12-
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
13-
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
14-
else()
15-
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
16-
endif()
17-
endif (NOT WIN32)
11+
if (NOT DIRECTX_HEADER_INCLUDE_DIR)
12+
if (NOT WIN32)
13+
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
14+
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
15+
else()
16+
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
17+
endif()
18+
endif (NOT WIN32)
19+
endif(NOT DIRECTX_HEADER_INCLUDE_DIR)
1820

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

0 commit comments

Comments
 (0)