-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeGDKXbox.cmake
291 lines (235 loc) · 11.2 KB
/
CMakeGDKXbox.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#
# CMakeGDKXbox.cmake : CMake definitions for Microsoft GDK
#
# This version does not include the XboxOne or Scarlett include/lib paths required for Direct3D graphics,
# and uses /SUBSYSTEM:CONSOLE.
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)
if(_GDK_XBOX_TOOLCHAIN_)
return()
endif()
#--- fix for Could NOT find Threads (missing: Threads_FOUND)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
#--- Microsoft Game Development Kit
set(XdkEditionTarget "240602" CACHE STRING "Microsoft GDK Edition")
message("XdkEditionTarget = ${XdkEditionTarget}")
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES XdkEditionTarget BUILD_USING_BWOI)
#--- Windows SDK
set(SDKVersion 10.0.22000.0)
set(CMAKE_SYSTEM_NAME WINDOWS)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION ${SDKVersion})
#--- Locate Visual Studio (needed for VC Runtime DLLs)
if (NOT DEFINED VCInstallDir AND DEFINED ENV{VCINSTALLDIR})
cmake_path(SET VCInstallDir "$ENV{VCINSTALLDIR}")
endif()
if (NOT DEFINED VCInstallDir)
set(GDK_VS_EDITIONS "Community" "Professional" "Enterprise" "Preview" "BuildTools")
if (MSVC_TOOLSET_VERSION MATCHES "143")
foreach(vsedition IN LISTS GDK_VS_EDITIONS)
cmake_path(SET VCInstallDir "$ENV{ProgramFiles}/Microsoft Visual Studio/2022/${vsedition}/VC")
if(EXISTS ${VCInstallDir})
break()
endif()
endforeach()
else()
foreach(vsedition IN LISTS GDK_VS_EDITIONS)
cmake_path(SET VCInstallDir "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/2019/${vsedition}/VC")
if(EXISTS ${VCInstallDir})
break()
endif()
endforeach()
if (NOT EXISTS ${VCInstallDir})
foreach(vsedition IN LISTS GDK_VS_EDITIONS)
cmake_path(SET VCInstallDir "$ENV{ProgramFiles}/Microsoft Visual Studio/2022/${vsedition}/VC")
if(EXISTS ${VCInstallDir})
break()
endif()
endforeach()
endif()
endif()
endif()
if(EXISTS ${VCInstallDir})
message("VCInstallDir = ${VCInstallDir}")
else()
message(FATAL_ERROR "ERROR: Failed to locate Visual Studio 2019 or 2022 install")
endif()
# Find VC toolset/runtime versions
file(STRINGS "${VCInstallDir}/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" VCToolsVersion)
message("VCToolsVersion = ${VCToolsVersion}")
file(STRINGS "${VCInstallDir}/Auxiliary/Build/Microsoft.VCRedistVersion.default.txt" VCToolsRedistVersion)
message("VCToolsRedistVersion = ${VCToolsRedistVersion}")
#--- GameRuntime and Extension Libraries
set(_GDK_XBOX_ ON)
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")
endif()
#--- Locate Microsoft GDK
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(Console_SdkRoot "${ExtractedFolder}/Microsoft GDK")
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}")
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"
MAP_IMPORTED_CONFIG_MINSIZEREL ""
MAP_IMPORTED_CONFIG_RELWITHDEBINFO ""
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Include"
INTERFACE_COMPILE_FEATURES "cxx_std_11"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
if(XdkEditionTarget 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"
MAP_IMPORTED_CONFIG_MINSIZEREL ""
MAP_IMPORTED_CONFIG_RELWITHDEBINFO ""
INTERFACE_INCLUDE_DIRECTORIES "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/gameKit/Include"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
endif()
endif()
#--- Extension Libraries
set(Console_GRDKExtLibRoot "${Console_SdkRoot}/${XdkEditionTarget}/GRDK/ExtensionLibraries")
set(ExtensionPlatformToolset 142)
set(DurangoXdkInstallPath "${Console_SdkRoot}/${XdkEditionTarget}")
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}")
else()
message(FATAL_ERROR "ERROR: Cannot locate Windows SDK (${SDKVersion})")
endif()
#--- Headers
set(Console_EndpointIncludeRoot
"${DurangoXdkInstallPath}/GXDK/gameKit/Include"
"${DurangoXdkInstallPath}/GRDK/gameKit/Include")
set(Console_WindowsIncludeRoot ${WindowsSdkDir}/Include/${SDKVersion})
set(Console_SdkIncludeRoot
"${Console_EndpointIncludeRoot}"
"${Console_WindowsIncludeRoot}/um"
"${Console_WindowsIncludeRoot}/shared"
"${Console_WindowsIncludeRoot}/winrt"
"${Console_WindowsIncludeRoot}/cppwinrt"
"${Console_WindowsIncludeRoot}/ucrt")
#--- Libraries
# Don't link with onecore.lib, kernel32.lib, etc.
set(CMAKE_CXX_STANDARD_LIBRARIES "")
set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "")
# Need to link with "onecore" versions of Visual C++ libraries ("msvc_x64_x64" environment uses desktop libpath)
set(VC_OneCore_LibPath "${VCInstallDir}/Tools/MSVC/${VCToolsVersion}/lib/onecore/x64")
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_EndpointLibRoot
"${DurangoXdkInstallPath}/GXDK/gameKit/Lib/amd64"
"${DurangoXdkInstallPath}/GRDK/gameKit/Lib/amd64")
set(Console_SdkLibPath
"${Console_EndpointLibRoot}"
"${Console_LibRoot}/ucrt/x64"
"${Console_LibRoot}/um/x64")
set(Console_Libs xgameplatform.lib xgameruntime.lib)
#--- Binaries
set(Console_UCRTRedistDebug ${WindowsSdkDir}/bin/${SDKVersion}/x64/ucrt)
if(NOT EXISTS ${Console_UCRTRedistDebug}/ucrtbased.dll)
message(FATAL_ERROR "ERROR: Cannot locate ucrtbased.dll in the Windows SDK (${SDKVersion})")
endif()
set(CRTPlatformToolset 143)
if (NOT EXISTS "${VCInstallDir}/redist/MSVC/${VCToolsRedistVersion}/onecore/x64/Microsoft.VC${CRTPlatformToolset}.CRT")
set(CRTPlatformToolset 142)
endif()
message("CRT Platform Toolset = ${CRTPlatformToolset}")
set(CppRuntimeFilesPath "${VCInstallDir}/redist/MSVC/${VCToolsRedistVersion}/onecore/x64/Microsoft.VC${CRTPlatformToolset}.CRT")
set(OpenMPRuntimeFilesPath "${VCInstallDir}/redist/MSVC/${VCToolsRedistVersion}/onecore/x64/Microsoft.VC${CRTPlatformToolset}.OpenMP")
set(DebugCppRuntimeFilesPath "${VCInstallDir}/redist/MSVC/${VCToolsRedistVersion}/onecore/Debug_NonRedist/x64/Microsoft.VC${CRTPlatformToolset}.DebugCRT")
set(DebugOpenMPRuntimeFilesPath "${VCInstallDir}/redist/MSVC/${VCToolsRedistVersion}/onecore/Debug_NonRedist/x64/Microsoft.VC${CRTPlatformToolset}.DebugOpenMP")
#--- Build options
# Required preprocessor defines
# WIN32
# _WINDOWS
# Traditional indicator of a 'Win32 console' application
set(Console_Defines ${Console_Defines} _CONSOLE)
# Standard Debug vs. Release preprocessor definitions
# (automatically defined by MSVC and MSVC-like compilers)
# _DEBUG (Debug)
# NDEBUG (Release without asserts)
# Build as Unicode (see UTF-8 Everywhere article's Win32 recommendations)
set(Console_Defines ${Console_Defines} _UNICODE UNICODE)
# Game Core on Xbox preprocessor definitions
set(Console_Defines ${Console_Defines} WIN32_LEAN_AND_MEAN _GAMING_XBOX WINAPI_FAMILY=WINAPI_FAMILY_GAMES)
# Additional recommended preprocessor defines
set(Console_Defines ${Console_Defines} _CRT_USE_WINAPI_PARTITION_APP _UITHREADCTXT_SUPPORT=0 __WRL_CLASSIC_COM_STRICT__)
# Default library controls
set(Console_Defines ${Console_Defines} _ATL_NO_DEFAULT_LIBS __WRL_NO_DEFAULT_LIB__)
set(UnsupportedLibs advapi32.lib comctl32.lib comsupp.lib dbghelp.lib gdi32.lib gdiplus.lib guardcfw.lib kernel32.lib mmc.lib msimg32.lib msvcole.lib msvcoled.lib mswsock.lib ntstrsafe.lib ole2.lib ole2autd.lib ole2auto.lib ole2d.lib ole2ui.lib ole2uid.lib ole32.lib oleacc.lib oleaut32.lib oledlg.lib oledlgd.lib oldnames.lib runtimeobject.lib shell32.lib shlwapi.lib strsafe.lib urlmon.lib user32.lib userenv.lib wlmole.lib wlmoled.lib onecore.lib)
# Required compiler switches:
# /MD or /MDd (VC Runtime DLL)
# /O? or /Od (Optimize code)
# Required linker switches:
# /MACHINE:X64 /SUBSYSTEM:CONSOLE
# /DYNAMICBASE
# /NXCOMPAT
set(Console_LinkOptions "/SUBSYSTEM:CONSOLE,10.0" "/DYNAMICBASE" "/NXCOMPAT")
# Prevent accidental use of libraries that are not supported by Game Core on Xbox
foreach(arg ${UnsupportedLibs})
list(APPEND Console_LinkOptions "/NODEFAULTLIB:${arg}")
endforeach()
if (OPTIMIZE_FOR_SCARLETT)
message("Optimizing code for Xbox Series X|S (won't run on Xbox One)")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(Console_ArchOptions /favor:AMD64 $<IF:$<BOOL:${OPTIMIZE_FOR_SCARLETT}>,/arch:AVX2,/arch:AVX>)
# Titles should use this switch to optimize the vzeroupper codegen based on console target
if(OPTIMIZE_FOR_SCARLETT)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.23)
set(Console_ArchOptions ${Console_ArchOptions} /d2vzeroupper)
set(Console_ArchOptions_LTCG /d2:-vzeroupper)
endif()
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.30)
set(Console_ArchOptions ${Console_ArchOptions} /d2vzeroupper-)
set(Console_ArchOptions_LTCG /d2:-vzeroupper-)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# -march=btver2 to target AMD Jaguar CPU; -march=znver2 to target AMD Hercules CPU (requires clang v9; otherwise use znver1)
set(Console_ArchOptions -march=$<IF:$<BOOL:${OPTIMIZE_FOR_SCARLETT}>,$<IF:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9.0>,znver2,znver1>,btver2>)
endif()
set(_GDK_XBOX_TOOLCHAIN_ ON)