Skip to content

Commit

Permalink
Auto detect latest GDK and Windows SDK (#1124)
Browse files Browse the repository at this point in the history
* Auto detect latest GDK and Windows SDK

* Update changelog

* Accept Suggestions and allow GDK override

---------

Co-authored-by: PlasmaDev5 <dragpmCASTjosh@gmail.com>
Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent 2aa4b16 commit 1fc2c77
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Features**:

- Auto-detect the latest GDK and Windows SDK for the XBox build. ([#1124](https://github.com/getsentry/sentry-native/pull/1124))
- Enable debug-option by default when running in a debug-build. ([#1128](https://github.com/getsentry/sentry-native/pull/1128))

**Fixes**:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(WIN32)
cmake_minimum_required (VERSION 3.16.4)
cmake_minimum_required (VERSION 3.18)

# enables support for CMAKE_MSVC_RUNTIME_LIBRARY
cmake_policy(SET CMP0091 NEW)
Expand Down
48 changes: 14 additions & 34 deletions toolchains/xbox/CMakeGDKScarlett.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ endif()
set(XBOX_CONSOLE_TARGET "scarlett" CACHE STRING "")

#--- Microsoft Game Development Kit
set(XdkEditionTarget "240603" CACHE STRING "Microsoft GDK Edition")

message("XdkEditionTarget = ${XdkEditionTarget}")
include("${CMAKE_CURRENT_LIST_DIR}/DetectGDK.cmake")

set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES XdkEditionTarget BUILD_USING_BWOI)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES GDK_VERSION BUILD_USING_BWOI)

#--- Windows SDK
set(SDKVersion 10.0.19041.0)
include("${CMAKE_CURRENT_LIST_DIR}/DetectWindowsSDK.cmake")

set(CMAKE_SYSTEM_NAME WINDOWS)
set(CMAKE_SYSTEM_VERSION 10.0.19041.0)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION ${SDKVersion})
set(CMAKE_SYSTEM_VERSION ${WINDOWS_SDK_VER})
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION ${WINDOWS_SDK_VER})

#--- Locate Visual Studio (needed for VC Runtime DLLs)

Expand Down Expand Up @@ -80,42 +79,23 @@ message("VCToolsRedistVersion = ${VCToolsRedistVersion}")
set(_GDK_XBOX_ ON)
include("${SENTRY_TOOLCHAINS_DIR}/xbox/GDK-targets.cmake")

set(DurangoXdkInstallPath "${Console_SdkRoot}/${XdkEditionTarget}")
set(DurangoXdkInstallPath "${Console_SdkRoot}/${GDK_VERSION}")

message("Microsoft GDK = ${DurangoXdkInstallPath}")

#--- Windows SDK (BWOI or installed)
if(BUILD_USING_BWOI)
if (DEFINED ENV{ExtractedFolder})
cmake_path(SET ExtractedFolder "$ENV{ExtractedFolder}")
else()
set(ExtractedFolder "d:/xtrctd.sdks/BWOIExample/")
endif()

if(NOT EXISTS ${ExtractedFolder})
message(FATAL_ERROR "ERROR: BWOI requires a valid ExtractedFolder (${ExtractedFolder})")
endif()

set(WindowsSdkDir "${ExtractedFolder}/Windows Kits/10")
if (NOT EXISTS ${WindowsSdkDir})
cmake_path(SET WindowsSdkDir "$ENV{ProgramFiles\(x86\)}/Windows Kits/10")
endif()
else()
cmake_path(SET WindowsSdkDir "$ENV{ProgramFiles\(x86\)}/Windows Kits/10")
endif()

if(EXISTS "${WindowsSdkDir}/Include/${SDKVersion}" )
message("Windows SDK = v${SDKVersion} in ${WindowsSdkDir}")
#--- Windows SDK
if(EXISTS "${WINDOWS_SDK}/Include/${WINDOWS_SDK_VER}" )
message("Windows SDK = v${WINDOWS_SDK_VER} in ${WINDOWS_SDK}")
else()
message(FATAL_ERROR "ERROR: Cannot locate Windows SDK (${SDKVersion})")
message(FATAL_ERROR "ERROR: Cannot locate Windows SDK (${WINDOWS_SDK_VER})")
endif()

#--- Headers
set(Console_EndpointIncludeRoot
"${DurangoXdkInstallPath}/GXDK/gameKit/Include"
"${DurangoXdkInstallPath}/GXDK/gameKit/Include/Scarlett"
"${DurangoXdkInstallPath}/GRDK/gameKit/Include")
set(Console_WindowsIncludeRoot ${WindowsSdkDir}/Include/${SDKVersion})
set(Console_WindowsIncludeRoot ${WINDOWS_SDK}/Include/${WINDOWS_SDK_VER})
set(Console_SdkIncludeRoot
"${Console_EndpointIncludeRoot}"
"${Console_WindowsIncludeRoot}/um"
Expand All @@ -135,7 +115,7 @@ if(NOT EXISTS ${VC_OneCore_LibPath}/msvcrt.lib)
message(FATAL_ERROR "ERROR: Cannot locate msvcrt.lib for the Visual C++ toolset (${VCToolsVersion})")
endif()

set(Console_LibRoot ${WindowsSdkDir}/Lib/${SDKVersion})
set(Console_LibRoot ${WINDOWS_SDK}/Lib/${WINDOWS_SDK_VER})
set(Console_EndpointLibRoot
"${DurangoXdkInstallPath}/GXDK/gameKit/Lib/amd64"
"${DurangoXdkInstallPath}/GXDK/gameKit/Lib/amd64/Scarlett"
Expand All @@ -150,9 +130,9 @@ set(Console_Libs pixevt.lib d3d12_xs.lib xgameplatform.lib xgameruntime.lib xmem
#--- Binaries
set(GameOSFilePath ${DurangoXdkInstallPath}/GXDK/sideload/gameos.xvd)

set(Console_UCRTRedistDebug ${WindowsSdkDir}/bin/${SDKVersion}/x64/ucrt)
set(Console_UCRTRedistDebug ${WINDOWS_SDK}/bin/${WINDOWS_SDK_VER}/x64/ucrt)
if(NOT EXISTS ${Console_UCRTRedistDebug}/ucrtbased.dll)
message(FATAL_ERROR "ERROR: Cannot locate ucrtbased.dll in the Windows SDK (${SDKVersion})")
message(FATAL_ERROR "ERROR: Cannot locate ucrtbased.dll in the Windows SDK (${WINDOWS_SDK_VER})")
endif()

set(CRTPlatformToolset 143)
Expand Down
10 changes: 10 additions & 0 deletions toolchains/xbox/DetectGDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get_filename_component(GDK_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\GDK;InstallPath]" ABSOLUTE CACHE)

if(NOT GDK_VERSION)
FILE(GLOB subfolders RELATIVE "${GDK_DIR}" "${GDK_DIR}/*")
list(FILTER subfolders INCLUDE REGEX "[0-9]+")
list(SORT subfolders COMPARE NATURAL) # sort by version number
list(GET subfolders -1 GDK_VERSION) # GET -1 is last element, i.e. highest version
endif()

message(STATUS "Using GDK version ${GDK_VERSION} at ${GDK_DIR}")
9 changes: 9 additions & 0 deletions toolchains/xbox/DetectWindowsSDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
get_filename_component(WINDOWS_SDK "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)

if(NOT WINDOWS_SDK_VER)
file(GLOB subfolders RELATIVE "${WINDOWS_SDK}/Lib" "${WINDOWS_SDK}/Lib/*")
list(SORT subfolders COMPARE NATURAL) # sort by version number
list(GET subfolders -1 WINDOWS_SDK_VER) # GET -1 is last element, i.e. highest version
endif ()

message(STATUS "Using Windows SDK version ${WINDOWS_SDK_VER} at ${WINDOWS_SDK}")
22 changes: 11 additions & 11 deletions toolchains/xbox/GDK-targets.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Adapted by Sentry from:
# Adapted by Sentry from:
# https://github.com/microsoft/Xbox-GDK-Samples/blob/e5328b9c06443739ec9c7c0089a36c5743c9da15/Samples/Tools/CMakeExample/CMake/GDK-targets.cmake
#
# GDK-targets.cmake : Defines library imports for the Microsoft GDK shared libraries
Expand All @@ -14,8 +14,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "ERROR: Microsoft GDK only supports 64-bit")
endif()

if(NOT XdkEditionTarget)
message(FATAL_ERROR "ERROR: XdkEditionTarget must be set")
if(NOT GDK_VERSION)
message(FATAL_ERROR "ERROR: GDK_VERSION must be set")
endif()

#--- Locate Microsoft GDK
Expand All @@ -35,34 +35,34 @@ else()
GET_FILENAME_COMPONENT(Console_SdkRoot "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\GDK;GRDKInstallPath]" ABSOLUTE CACHE)
endif()

if(NOT EXISTS "${Console_SdkRoot}/${XdkEditionTarget}")
message(FATAL_ERROR "ERROR: Cannot locate Microsoft Game Development Kit (GDK) - ${XdkEditionTarget}")
if(NOT EXISTS "${Console_SdkRoot}/${GDK_VERSION}")
message(FATAL_ERROR "ERROR: Cannot locate Microsoft Game Development Kit (GDK) - ${GDK_VERSION}")
endif()

#--- GameRuntime Library (for Xbox these are included in the Console_Libs variable)
if(NOT _GDK_XBOX_)
add_library(Xbox::GameRuntime STATIC IMPORTED)
set_target_properties(Xbox::GameRuntime PROPERTIES
IMPORTED_LOCATION "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Lib/amd64/xgameruntime.lib"
IMPORTED_LOCATION "${Console_SdkRoot}/${GDK_VERSION}/GRDK/gameKit/Lib/amd64/xgameruntime.lib"
MAP_IMPORTED_CONFIG_MINSIZEREL ""
MAP_IMPORTED_CONFIG_RELWITHDEBINFO ""
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Include"
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${GDK_VERSION}/GRDK/gameKit/Include"
INTERFACE_COMPILE_FEATURES "cxx_std_11"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")

if(XdkEditionTarget GREATER_EQUAL 220600)
if(GDK_VERSION GREATER_EQUAL 220600)
add_library(Xbox::GameInput STATIC IMPORTED)
set_target_properties(Xbox::GameInput PROPERTIES
IMPORTED_LOCATION "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Lib/amd64/gameinput.lib"
IMPORTED_LOCATION "${Console_SdkRoot}/${GDK_VERSION}/GRDK/gameKit/Lib/amd64/gameinput.lib"
MAP_IMPORTED_CONFIG_MINSIZEREL ""
MAP_IMPORTED_CONFIG_RELWITHDEBINFO ""
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Include"
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${GDK_VERSION}/GRDK/gameKit/Include"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
endif()
endif()

#--- Extension Libraries
set(Console_GRDKExtLibRoot "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/ExtensionLibraries")
set(Console_GRDKExtLibRoot "${Console_SdkRoot}/${GDK_VERSION}/GRDK/ExtensionLibraries")
set(ExtensionPlatformToolset 142)

set(_GDK_TARGETS_ ON)
9 changes: 4 additions & 5 deletions toolchains/xbox/gxdk_xs_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ if(_GXDK_XS_TOOLCHAIN_)
endif()

# Microsoft Game Development Kit
set(XdkEditionTarget "220303" CACHE STRING "Microsoft GDK Edition")

message("XdkEditionTarget = ${XdkEditionTarget}")
include("${CMAKE_CURRENT_LIST_DIR}/DetectGDK.cmake")

set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES XdkEditionTarget)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES GDK_VERSION)

set(CMAKE_SYSTEM_NAME WINDOWS)
set(CMAKE_SYSTEM_VERSION 10.0.19041)
set(CMAKE_SYSTEM_VERSION ${GDK_VERSION})

set(CMAKE_GENERATOR_PLATFORM "Gaming.Xbox.Scarlett.x64" CACHE STRING "" FORCE)
set(CMAKE_VS_PLATFORM_NAME "Gaming.Xbox.Scarlett.x64" CACHE STRING "" FORCE)
Expand Down Expand Up @@ -53,7 +52,7 @@ if(NOT GDK_DXCTool)
find_program(
GDK_DXCTool
NAMES dxc
PATHS "${Console_SdkRoot}/${XdkEditionTarget}/GXDK/bin/Scarlett"
PATHS "${Console_SdkRoot}/${GDK_VERSION}/GXDK/bin/Scarlett"
)

mark_as_advanced(GDK_DXCTool)
Expand Down
7 changes: 5 additions & 2 deletions toolchains/xbox/xbox_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
-B build
-G "Visual Studio 17 2022"
-A "Gaming.Xbox.Scarlett.x64"
-DXdkEditionTarget="240603"
-DCMAKE_TOOLCHAIN_FILE="./toolchains/xbox/gxdk_xs_toolchain.cmake"
```
* Optionally you can specify the GDK version
```
-DGDK_VERSION="241000"
```
* after this you can either build the library directly in the CLI with
`cmake --build build --config RelWithDebInfo` (or any other build config)
or in Visual Studio by opening the solution in the `build` directory.
* `cmake --install build --prefix install --config RelWithDebInfo` installs all required development and release files
(`dll`, `pdb`, `lib`, `h`) to include into any Xbox X/S game project into the directory `install`.
(`dll`, `pdb`, `lib`, `h`) to include into any Xbox X/S game project into the directory `install`.

0 comments on commit 1fc2c77

Please sign in to comment.