diff --git a/CHANGELOG.md b/CHANGELOG.md index 7312935dd..f35c5a0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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**: diff --git a/CMakeLists.txt b/CMakeLists.txt index 59fc2f5bb..67a42027e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/toolchains/xbox/CMakeGDKScarlett.cmake b/toolchains/xbox/CMakeGDKScarlett.cmake index 5eac20406..4b4c0cf88 100644 --- a/toolchains/xbox/CMakeGDKScarlett.cmake +++ b/toolchains/xbox/CMakeGDKScarlett.cmake @@ -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) @@ -80,34 +79,15 @@ 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 @@ -115,7 +95,7 @@ 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" @@ -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" @@ -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) diff --git a/toolchains/xbox/DetectGDK.cmake b/toolchains/xbox/DetectGDK.cmake new file mode 100644 index 000000000..74913f9a4 --- /dev/null +++ b/toolchains/xbox/DetectGDK.cmake @@ -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}") \ No newline at end of file diff --git a/toolchains/xbox/DetectWindowsSDK.cmake b/toolchains/xbox/DetectWindowsSDK.cmake new file mode 100644 index 000000000..312e6ab52 --- /dev/null +++ b/toolchains/xbox/DetectWindowsSDK.cmake @@ -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}") \ No newline at end of file diff --git a/toolchains/xbox/GDK-targets.cmake b/toolchains/xbox/GDK-targets.cmake index 23b96b39c..b6a34837e 100644 --- a/toolchains/xbox/GDK-targets.cmake +++ b/toolchains/xbox/GDK-targets.cmake @@ -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 @@ -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 @@ -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) diff --git a/toolchains/xbox/gxdk_xs_toolchain.cmake b/toolchains/xbox/gxdk_xs_toolchain.cmake index 2f600a512..9d94a5e39 100644 --- a/toolchains/xbox/gxdk_xs_toolchain.cmake +++ b/toolchains/xbox/gxdk_xs_toolchain.cmake @@ -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) @@ -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) diff --git a/toolchains/xbox/xbox_build.md b/toolchains/xbox/xbox_build.md index 02cc94f9d..977b2a0b7 100644 --- a/toolchains/xbox/xbox_build.md +++ b/toolchains/xbox/xbox_build.md @@ -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`. \ No newline at end of file + (`dll`, `pdb`, `lib`, `h`) to include into any Xbox X/S game project into the directory `install`.