Skip to content

Commit

Permalink
Update CMake project
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Dec 17, 2024
1 parent 09e8721 commit 34dd279
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
46 changes: 22 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ option(BUILD_WITH_NEW_WARP "Use the WARP package on NuGet" OFF)
set(DIRECTX_WARP_VERSION 1.0.13)

option(BUILD_WITH_NEW_DX12 "Use the DirectX 12 Agility SDK Binaries" OFF)
set(DIRECTX_DX12_VERSION 1.614.1)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -68,6 +67,12 @@ if(directx-headers_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE USING_DIRECTX_HEADERS)
endif()

if(BUILD_WITH_NEW_DX12)
message(STATUS "Using DirectX 12 Agility SDK")
find_package(directx12-agility CONFIG REQUIRED)
target_compile_definitions(${PROJECT_NAME} PRIVATE USING_D3D12_AGILITY_SDK)
endif()

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /GR- "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
target_link_options(${PROJECT_NAME} PRIVATE /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO)
Expand Down Expand Up @@ -177,28 +182,21 @@ if(WIN32)

file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/temp")
endif()
endif()

if (BUILD_WITH_NEW_DX12)
target_compile_definitions(${PROJECT_NAME} PRIVATE USING_D3D12_AGILITY_SDK)

message(STATUS "Downloading Microsoft.Direct3D.D3D12...")
set(DIRECTX_DX12_ARCHIVE "${CMAKE_BINARY_DIR}/Microsoft.Direct3D.D3D12.${DIRECTX_DX12_VERSION}.zip")
file(DOWNLOAD "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/${DIRECTX_DX12_VERSION}/"
${DIRECTX_DX12_ARCHIVE}
EXPECTED_HASH SHA512=05baa55231684ab10a3e905c9b85ce78f04ade9360f7de84a06bbae3bfc3123bcccaa563647a25e151cc759106bc19e37740ef78563592d28e3a723fd744b42f
)

file(ARCHIVE_EXTRACT INPUT ${DIRECTX_DX12_ARCHIVE} DESTINATION "${CMAKE_BINARY_DIR}/temp" PATTERNS *${NUGET_ARCH}*dll *${NUGET_ARCH}*exe *${NUGET_ARCH}*pdb)

file(GLOB_RECURSE DXBINS "${CMAKE_BINARY_DIR}/temp/*.dll" "${CMAKE_BINARY_DIR}/temp/*.exe" $<IF:$<CONFIG:DEBUG>,"${CMAKE_BINARY_DIR}/temp/*.pdb">)

file(MAKE_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/D3D12")

foreach(FILE ${DXBINS})
get_filename_component(FILENAME ${FILE} NAME)
file(COPY_FILE ${FILE} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/D3D12//${FILENAME}")
endforeach(FILE)

file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/temp")
endif()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>>,copy,true>
$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}> $<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMAND_EXPAND_LISTS
)

if(TARGET Microsoft::DirectX12-Agility)
file(MAKE_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/D3D12")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Core,IMPORTED_LOCATION_RELEASE> $<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Layers,IMPORTED_LOCATION_DEBUG> $<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12
COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12Core.dll
COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE_DIR:${PROJECT_NAME}>/d3d12SDKLayers.dll
COMMAND_EXPAND_LISTS
)
endif()
25 changes: 11 additions & 14 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"configurePresets": [
{
"name": "base",
Expand All @@ -8,7 +8,7 @@
"generator": "Ninja",
"hidden": true,
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" }
"installDir": "${sourceDir}/out/install/${presetName}"
},

{
Expand Down Expand Up @@ -103,20 +103,17 @@
},

{
"name": "NuGet",
"name": "WARP",
"cacheVariables": {
"BUILD_WITH_NEW_WARP": true,
"BUILD_WITH_NEW_DX12": true
"BUILD_WITH_NEW_WARP": true
},
"hidden": true
},
{
"name": "VCPKG",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
}
"BUILD_WITH_NEW_DX12": true
},
"hidden": true
},
Expand All @@ -130,11 +127,11 @@
{ "name": "arm64ec-Debug" , "description": "MSVC for ARM64EC (Debug)", "inherits": [ "base", "ARM64EC", "Debug", "MSVC" ] },
{ "name": "arm64ec-Release", "description": "MSVC for ARM64EC (Release)", "inherits": [ "base", "ARM64EC", "Release", "MSVC" ] },

{ "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG", "NuGet" ] },
{ "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG", "NuGet" ] },
{ "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG", "NuGet" ] },
{ "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG", "NuGet" ] },
{ "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG", "NuGet" ] },
{ "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG", "WARP" ] },
{ "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG", "WARP" ] },
{ "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG", "WARP" ] },
{ "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG", "WARP" ] },
{ "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG", "WARP" ] },
{ "name": "arm64-Release-VCPKG", "description": "MSVC for ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "MSVC", "VCPKG" ] },
{ "name": "arm64ec-Debug-VCPKG" , "description": "MSVC for ARM64EC (Debug)", "inherits": [ "base", "ARM64EC", "Debug", "MSVC", "VCPKG" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } },
{ "name": "arm64ec-Release-VCPKG", "description": "MSVC for ARM64EC (Release)", "inherits": [ "base", "ARM64EC", "Release", "MSVC", "VCPKG" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } },
Expand Down
11 changes: 6 additions & 5 deletions build/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
"directx-headers"
]
}
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
"directx-headers",
"directx12-agility"
]
}

0 comments on commit 34dd279

Please sign in to comment.