Skip to content

Commit 9102668

Browse files
authored
CMake support for building legacy Xbox One XDK lib (#379)
1 parent ce9c837 commit 9102668

6 files changed

+85
-11
lines changed

CMakeLists.txt

+50-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ cmake_minimum_required (VERSION 3.20)
55

66
set(DIRECTXTK_VERSION 1.8.3)
77

8+
if(DEFINED XBOX_CONSOLE_TARGET)
9+
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
10+
endif()
11+
812
project (DirectXTK
913
VERSION ${DIRECTXTK_VERSION}
1014
DESCRIPTION "DirectX Tool Kit for DirectX 11"
@@ -52,10 +56,18 @@ endif()
5256

5357
include(GNUInstallDirs)
5458

55-
if(WINDOWS_STORE)
56-
set(BUILD_GAMEINPUT OFF)
57-
set(USING_WINDOWS_GAMING_INPUT ON)
58-
set(BUILD_TOOLS OFF)
59+
if(XBOX_CONSOLE_TARGET STREQUAL "durango")
60+
set(BUILD_GAMEINPUT OFF)
61+
set(BUILD_WGI OFF)
62+
set(BUILD_XINPUT OFF)
63+
set(BUILD_XBOXONE_SHADERS ON)
64+
set(BUILD_XAUDIO_WIN10 OFF)
65+
set(BUILD_XAUDIO_WIN8 ON)
66+
set(BUILD_TOOLS OFF)
67+
elseif(WINDOWS_STORE)
68+
set(BUILD_GAMEINPUT OFF)
69+
set(BUILD_WGI ON)
70+
set(BUILD_TOOLS OFF)
5971
endif()
6072

6173
#--- Library
@@ -203,13 +215,21 @@ endif()
203215
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
204216
${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc)
205217

218+
if(BUILD_XBOXONE_SHADERS)
219+
message(STATUS "Using Shader Model 5.0 for Xbox One for shaders")
220+
set(ShaderOpts xbox)
221+
else()
222+
message(STATUS "Using Shader Model 4.0/9.1 for shaders.")
223+
set(ShaderOpts "")
224+
endif()
225+
206226
if(NOT USE_PREBUILT_SHADERS)
207227
add_custom_command(
208228
OUTPUT "${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc"
209229
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/Src/Shaders/CompileShaders.cmd"
210230
DEPENDS ${SHADER_SOURCES}
211231
COMMENT "Generating HLSL shaders..."
212-
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log"
232+
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd ARGS ${ShaderOpts} > "${COMPILED_SHADERS}/compileshaders.log"
213233
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Src/Shaders"
214234
USES_TERMINAL)
215235
endif()
@@ -272,6 +292,22 @@ elseif(BUILD_XINPUT)
272292
target_compile_definitions(${PROJECT_NAME} PUBLIC USING_XINPUT)
273293
endif()
274294

295+
if(DEFINED XBOX_CONSOLE_TARGET)
296+
message(STATUS "Building for Xbox Console Target: ${XBOX_CONSOLE_TARGET}")
297+
set(CMAKE_REQUIRED_QUIET ON)
298+
CHECK_INCLUDE_FILE_CXX(xdk.h XDKLegacy_HEADER)
299+
if(NOT XDKLegacy_HEADER)
300+
message(FATAL_ERROR "Legacy Xbox One XDK required to build for Durango.")
301+
endif()
302+
if(XBOX_CONSOLE_TARGET STREQUAL "durango")
303+
target_compile_definitions(${PROJECT_NAME} PUBLIC WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE _XBOX_ONE _TITLE MONOLITHIC=1)
304+
else()
305+
message(FATAL_ERROR "Unknown XBOX_CONSOLE_TARGET")
306+
endif()
307+
elseif(WINDOWS_STORE)
308+
target_compile_definitions(${PROJECT_NAME} PUBLIC WINAPI_FAMILY=WINAPI_FAMILY_APP)
309+
endif()
310+
275311
#--- Package
276312
include(CMakePackageConfigHelpers)
277313

@@ -362,7 +398,9 @@ else()
362398
endforeach()
363399
endif()
364400

365-
if(NOT ${DIRECTX_ARCH} MATCHES "^arm")
401+
if(XBOX_CONSOLE_TARGET MATCHES "durango")
402+
target_compile_options(${PROJECT_NAME} PRIVATE $<IF:$<CXX_COMPILER_ID:MSVC>,/favor:AMD64 /arch:AVX,-march=btver2>)
403+
elseif(NOT ${DIRECTX_ARCH} MATCHES "^arm")
366404
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
367405
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse2>)
368406
else()
@@ -376,6 +414,9 @@ endif()
376414

377415
if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
378416
set(WarningsLib "-Wpedantic" "-Wextra")
417+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
418+
list(APPEND WarningsLib "-Wno-unsafe-buffer-usage")
419+
endif()
379420
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
380421

381422
set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic"
@@ -448,11 +489,9 @@ elseif( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
448489
endif()
449490

450491
if(WIN32)
451-
if(WINDOWS_STORE)
452-
target_compile_definitions(${PROJECT_NAME} PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_APP)
453-
endif()
454-
455-
if(WINDOWS_STORE OR BUILD_XAUDIO_WIN10)
492+
if (XBOX_CONSOLE_TARGET STREQUAL "durango")
493+
set(WINVER 0x0602)
494+
elseif(WINDOWS_STORE OR BUILD_XAUDIO_WIN10)
456495
message(STATUS "Using DirectX Tool Kit for Audio on XAudio 2.9 (Windows 10/Windows 11).")
457496
set(WINVER 0x0A00)
458497
elseif((${DIRECTX_ARCH} MATCHES "^arm64") OR BUILD_GAMEINPUT OR BUILD_WGI)

CMakePresets.json

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@
135135
},
136136
"hidden": true
137137
},
138+
{
139+
"name": "Durango",
140+
"cacheVariables": {
141+
"XBOX_CONSOLE_TARGET": "durango",
142+
"BUILD_TESTING": false
143+
},
144+
"hidden": true
145+
},
138146
{
139147
"name": "VCPKG",
140148
"cacheVariables": {
@@ -197,6 +205,9 @@
197205
{ "name": "x64-Debug-GDK" , "description": "MSVC for x64 (Debug) with Microsoft GDK", "inherits": [ "base", "x64", "Debug", "MSVC", "GDK" ] },
198206
{ "name": "x64-Release-GDK" , "description": "MSVC for x64 (Release) with Microsoft GDK", "inherits": [ "base", "x64", "Release", "MSVC", "GDK" ] },
199207

208+
{ "name": "x64-Debug-Durango" , "description": "MSVC for x64 (Debug) for legacy Xbox One XDK", "inherits": [ "base", "x64", "Debug", "MSVC", "Durango" ] },
209+
{ "name": "x64-Release-Durango" , "description": "MSVC for x64 (Release) for legacy Xbox One XDK", "inherits": [ "base", "x64", "Release", "MSVC", "Durango" ] },
210+
200211
{ "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG" ] },
201212
{ "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG" ] },
202213
{ "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG" ] },

Inc/DirectXHelpers.h

+10
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ namespace DirectX
8989
mContext->Unmap(mResource, mSubresource);
9090
}
9191

92+
#ifdef __clang__
93+
#pragma clang diagnostic push
94+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
95+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
96+
#endif
97+
9298
uint8_t* get() const noexcept
9399
{
94100
return static_cast<uint8_t*>(pData);
@@ -107,6 +113,10 @@ namespace DirectX
107113
return static_cast<uint8_t*>(pData) + (slice * DepthPitch) + (row * RowPitch);
108114
}
109115

116+
#ifdef __clang__
117+
#pragma clang diagnostic pop
118+
#endif
119+
110120
template<typename T>
111121
void copy(_In_reads_(count) T const* data, size_t count) noexcept
112122
{

Inc/Keyboard.h

+10
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ namespace DirectX
426426
bool OemClear : 1; // VK_OEM_CLEAR, 0xFE
427427
bool Reserved26 : 1;
428428

429+
#ifdef __clang__
430+
#pragma clang diagnostic push
431+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
432+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
433+
#endif
434+
429435
bool __cdecl IsKeyDown(Keys key) const noexcept
430436
{
431437
if (key <= 0xfe)
@@ -447,6 +453,10 @@ namespace DirectX
447453
}
448454
return false;
449455
}
456+
457+
#ifdef __clang__
458+
#pragma clang diagnostic pop
459+
#endif
450460
};
451461

452462
class KeyboardStateTracker

Inc/SimpleMath.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#ifdef __clang__
3131
#pragma clang diagnostic push
3232
#pragma clang diagnostic ignored "-Wfloat-equal"
33+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
34+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
3335
#endif
3436

3537

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ Thanks to Garrett Serack for his help in creating the NuGet packages for DirectX
129129
Thanks to Roberto Sonnino for his help with the ``CMO``, DGSL rendering, and the VS Starter Kit animation.
130130

131131
Thanks to Pete Lewis and Justin Saunders for the normal-mapped and PBR shaders implementation.
132+
133+
Thanks to Andrew Farrier and Scott Matloff for their on-going help with code reviews.

0 commit comments

Comments
 (0)