1 # - Find the Windows SDK aka Platform SDK
3 # Relevant Wikipedia article: http://en.wikipedia.org/wiki/Microsoft_Windows_SDK
5 # Pass "COMPONENTS tools" to ignore Visual Studio version checks: in case
6 # you just want the tool binaries to run, rather than the libraries and headers
10 # WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
11 # WINDOWSSDK_LATEST_DIR
12 # WINDOWSSDK_LATEST_NAME
13 # WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version
14 # WINDOWSSDK_PREFERRED_DIR
15 # WINDOWSSDK_PREFERRED_NAME
17 # WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first.
18 # WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency
21 # windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
22 # NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
24 # windowssdk_build_lookup(<directory> <output variable>) - Find the build version number corresponding with the SDK directory you pass in, or
25 # NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
27 # get_windowssdk_from_component(<file or dir> <output variable>) - Given a library or include dir,
28 # find the Windows SDK root dir corresponding to it, or NOTFOUND if unrecognized.
30 # get_windowssdk_library_dirs(<directory> <output variable>) - Find the architecture-appropriate
31 # library directories corresponding to the SDK directory you pass in (or NOTFOUND if none)
33 # get_windowssdk_library_dirs_multiple(<output variable> <directory> ...) - Find the architecture-appropriate
34 # library directories corresponding to the SDK directories you pass in, in order, skipping those not found. NOTFOUND if none at all.
35 # Good for passing WINDOWSSDK_DIRS or WINDOWSSDK_DIRS to if you really just want a file and don't care where from.
37 # get_windowssdk_include_dirs(<directory> <output variable>) - Find the
38 # include directories corresponding to the SDK directory you pass in (or NOTFOUND if none)
40 # get_windowssdk_include_dirs_multiple(<output variable> <directory> ...) - Find the
41 # include directories corresponding to the SDK directories you pass in, in order, skipping those not found. NOTFOUND if none at all.
42 # Good for passing WINDOWSSDK_DIRS or WINDOWSSDK_DIRS to if you really just want a file and don't care where from.
44 # Requires these CMake modules:
45 # FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
48 # 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
49 # http://academic.cleardefinition.com
50 # Iowa State University HCI Graduate Program/VRAC
52 # Copyright Iowa State University 2012.
53 # Distributed under the Boost Software License, Version 1.0.
54 # (See accompanying file LICENSE_1_0.txt or copy at
55 # http://www.boost.org/LICENSE_1_0.txt)
57 set(_preferred_sdk_dirs) # pre-output
58 set(_win_sdk_dirs) # pre-output
59 set(_win_sdk_versanddirs) # pre-output
60 set(_win_sdk_buildsanddirs) # pre-output
61 set(_winsdk_vistaonly) # search parameters
62 set(_winsdk_kits) # search parameters
65 set(_WINDOWSSDK_ANNOUNCE OFF)
66 if(NOT WINDOWSSDK_FOUND AND (NOT WindowsSDK_FIND_QUIETLY))
67 set(_WINDOWSSDK_ANNOUNCE ON)
69 macro(_winsdk_announce)
71 message(STATUS ${ARGN})
76 10.0.19041.0 # Windows 10 Version 2004
77 10.0.18362.0 # Windows 10 Version 1903
78 10.0.17763.0 # Windows 10 Version 1809
79 10.0.17134.0 # Windows 10 Version 1803 (April 2018 Update)
80 10.0.16299.0 # Windows 10 Version 1709 (Fall Creators Update)
81 10.0.15063.0 # Windows 10 Version 1703 (Creators Update)
82 10.0.14393.0 # Redstone aka Win10 1607 "Anniversary Update"
83 10.0.10586.0 # TH2 aka Win10 1511
84 10.0.10240.0 # Win10 RTM
85 10.0.10150.0 # just ucrt
89 if(WindowsSDK_FIND_COMPONENTS MATCHES "tools")
90 set(_WINDOWSSDK_IGNOREMSVC ON)
91 _winsdk_announce("Checking for tools from Windows/Platform SDKs...")
93 set(_WINDOWSSDK_IGNOREMSVC OFF)
94 _winsdk_announce("Checking for Windows/Platform SDKs...")
97 # Appends to the three main pre-output lists used only if the path exists
98 # and is not already in the list.
99 function(_winsdk_conditional_append _vername _build _path)
100 if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
101 # Path invalid - do not add
104 list(FIND _win_sdk_dirs "${_path}" _win_sdk_idx)
105 if(_win_sdk_idx GREATER -1)
106 # Path already in list - do not add
109 _winsdk_announce( " - ${_vername}, Build ${_build} @ ${_path}")
110 # Not yet in the list, so we'll add it
111 list(APPEND _win_sdk_dirs "${_path}")
112 set(_win_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
117 set(_win_sdk_versanddirs "${_win_sdk_versanddirs}" CACHE INTERNAL "" FORCE)
119 _win_sdk_buildsanddirs
122 set(_win_sdk_buildsanddirs "${_win_sdk_buildsanddirs}" CACHE INTERNAL "" FORCE)
125 # Appends to the "preferred SDK" lists only if the path exists
126 function(_winsdk_conditional_append_preferred _info _path)
127 if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
128 # Path invalid - do not add
132 get_filename_component(_path "${_path}" ABSOLUTE)
134 list(FIND _win_sdk_preferred_sdk_dirs "${_path}" _win_sdk_idx)
135 if(_win_sdk_idx GREATER -1)
136 # Path already in list - do not add
139 _winsdk_announce( " - Found \"preferred\" SDK ${_info} @ ${_path}")
140 # Not yet in the list, so we'll add it
141 list(APPEND _win_sdk_preferred_sdk_dirs "${_path}")
142 set(_win_sdk_preferred_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
144 # Just in case we somehow missed it:
145 _winsdk_conditional_append("${_info}" "" "${_path}")
148 # Given a version like v7.0A, looks for an SDK in the registry under "Microsoft SDKs".
149 # If the given version might be in both HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows
150 # and HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots aka "Windows Kits",
151 # use this macro first, since these registry keys usually have more information.
153 # Pass a "default" build number as an extra argument in case we can't find it.
154 function(_winsdk_check_microsoft_sdks_registry _winsdkver)
155 set(SDKKEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver}")
156 get_filename_component(_sdkdir
157 "[${SDKKEY};InstallationFolder]"
160 set(_sdkname "Windows SDK ${_winsdkver}")
162 # Default build number passed as extra argument
164 # See if the registry holds a Microsoft-mutilated, err, designated, product name
165 # (just using get_filename_component to execute the registry lookup)
166 get_filename_component(_sdkproductname
167 "[${SDKKEY};ProductName]"
169 if(NOT "${_sdkproductname}" MATCHES "registry")
171 set(_sdkname "${_sdkname} (${_sdkproductname})")
174 # try for a version to augment our name
175 # (just using get_filename_component to execute the registry lookup)
176 get_filename_component(_sdkver
177 "[${SDKKEY};ProductVersion]"
179 if(NOT "${_sdkver}" MATCHES "registry" AND NOT MATCHES)
181 if(NOT "${_sdkver}" MATCHES "\\.\\.")
182 # and it's not an invalid one with two dots in it:
183 # use to override the default build
184 set(_build ${_sdkver})
185 if(NOT "${_sdkname}" MATCHES "${_sdkver}")
186 # Got a version that's not already in the name, let's use it to improve our name.
187 set(_sdkname "${_sdkname} (${_sdkver})")
191 _winsdk_conditional_append("${_sdkname}" "${_build}" "${_sdkdir}")
194 # Given a name for identification purposes, the build number, and a key (technically a "value name")
195 # corresponding to a Windows SDK packaged as a "Windows Kit", look for it
196 # in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
197 # Note that the key or "value name" tends to be something weird like KitsRoot81 -
198 # no easy way to predict, just have to observe them in the wild.
199 # Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
200 # sometimes you get keys in both parts of the registry (in the wow64 portion especially),
201 # and the non-"Windows Kits" location is often more descriptive.
202 function(_winsdk_check_windows_kits_registry _winkit_name _winkit_build _winkit_key)
203 get_filename_component(_sdkdir
204 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;${_winkit_key}]"
206 _winsdk_conditional_append("${_winkit_name}" "${_winkit_build}" "${_sdkdir}")
209 # Given a name for identification purposes and the build number
210 # corresponding to a Windows 10 SDK packaged as a "Windows Kit", look for it
211 # in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
212 # Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
213 # sometimes you get keys in both parts of the registry (in the wow64 portion especially),
214 # and the non-"Windows Kits" location is often more descriptive.
215 function(_winsdk_check_win10_kits _winkit_build)
216 get_filename_component(_sdkdir
217 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]"
219 if(("${_sdkdir}" MATCHES "registry") OR (NOT EXISTS "${_sdkdir}"))
222 if(EXISTS "${_sdkdir}/Include/${_winkit_build}/um")
223 _winsdk_conditional_append("Windows Kits 10 (Build ${_winkit_build})" "${_winkit_build}" "${_sdkdir}")
227 # Given a name for indentification purposes, the build number, and the associated package GUID,
228 # look in the registry under both HKLM and HKCU in \\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\
229 # for that guid and the SDK it points to.
230 function(_winsdk_check_platformsdk_registry _platformsdkname _build _platformsdkguid)
231 foreach(_winsdk_hive HKEY_LOCAL_MACHINE HKEY_CURRENT_USER)
232 get_filename_component(_sdkdir
233 "[${_winsdk_hive}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
235 _winsdk_conditional_append("${_platformsdkname} (${_build})" "${_build}" "${_sdkdir}")
240 # Detect toolchain information: to know whether it's OK to use Vista+ only SDKs
242 set(_winsdk_vistaonly_ok OFF)
243 if(MSVC AND NOT _WINDOWSSDK_IGNOREMSVC)
244 # VC 10 and older has broad target support
245 if(MSVC_VERSION LESS 1700)
246 # VC 11 by default targets Vista and later only, so we can add a few more SDKs that (might?) only work on vista+
247 elseif("${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "_xp")
248 # This is the XP-compatible v110+ toolset
249 elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v100" OR "${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v90")
250 # This is the VS2010/VS2008 toolset
252 # OK, we're VC11 or newer and not using a backlevel or XP-compatible toolset.
253 # These versions have no XP (and possibly Vista pre-SP1) support
254 set(_winsdk_vistaonly_ok ON)
255 if(_WINDOWSSDK_ANNOUNCE AND NOT _WINDOWSSDK_VISTAONLY_PESTERED)
256 set(_WINDOWSSDK_VISTAONLY_PESTERED ON CACHE INTERNAL "" FORCE)
257 message(STATUS "FindWindowsSDK: Detected Visual Studio 2012 or newer, not using the _xp toolset variant: including SDK versions that drop XP support in search!")
261 if(_WINDOWSSDK_IGNOREMSVC)
262 set(_winsdk_vistaonly_ok ON)
266 # MSVC version checks - keeps messy conditionals in one place
267 # (messy because of _WINDOWSSDK_IGNOREMSVC)
269 set(_winsdk_msvc_greater_1200 OFF)
270 if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1200)))
271 set(_winsdk_msvc_greater_1200 ON)
273 # Newer than VS .NET/VS Toolkit 2003
274 set(_winsdk_msvc_greater_1310 OFF)
275 if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1310)))
276 set(_winsdk_msvc_greater_1310 ON)
280 set(_winsdk_msvc_less_1600 OFF)
281 if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION LESS 1600)))
282 set(_winsdk_msvc_less_1600 ON)
286 set(_winsdk_msvc_not_less_1800 OFF)
287 if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (NOT MSVC_VERSION LESS 1800)))
288 set(_winsdk_msvc_not_less_1800 ON)
292 # START body of find module
294 if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
296 # Look for "preferred" SDKs
299 # Environment variable for SDK dir
300 if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
301 _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
304 if(_winsdk_msvc_less_1600)
305 # Per-user current Windows SDK for VS2005/2008
306 get_filename_component(_sdkdir
307 "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
309 _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
311 # System-wide current Windows SDK for VS2005/2008
312 get_filename_component(_sdkdir
313 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
315 _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
319 # Begin the massive list of SDK searching!
321 if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
322 # These require at least Visual Studio 2013 (VC12)
324 _winsdk_check_microsoft_sdks_registry(v10.0A)
326 # Windows Software Development Kit (SDK) for Windows 10
327 # Several different versions living in the same directory - if nothing else we can assume RTM (10240)
328 _winsdk_check_microsoft_sdks_registry(v10.0 10.0.10240.0)
329 foreach(_win10build ${_winsdk_win10vers})
330 _winsdk_check_win10_kits(${_win10build})
332 endif() # vista-only and 2013+
334 # Included in Visual Studio 2013
335 # Includes the v120_xp toolset
336 _winsdk_check_microsoft_sdks_registry(v8.1A 8.1.51636)
338 if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
339 # Windows Software Development Kit (SDK) for Windows 8.1
340 # http://msdn.microsoft.com/en-gb/windows/desktop/bg162891
341 _winsdk_check_microsoft_sdks_registry(v8.1 8.1.25984.0)
342 _winsdk_check_windows_kits_registry("Windows Kits 8.1" 8.1.25984.0 KitsRoot81)
343 endif() # vista-only and 2013+
345 if(_winsdk_vistaonly_ok)
346 # Included in Visual Studio 2012
347 _winsdk_check_microsoft_sdks_registry(v8.0A 8.0.50727)
349 # Microsoft Windows SDK for Windows 8 and .NET Framework 4.5
350 # This is the first version to also include the DirectX SDK
351 # http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx
352 _winsdk_check_microsoft_sdks_registry(v8.0 6.2.9200.16384)
353 _winsdk_check_windows_kits_registry("Windows Kits 8.0" 6.2.9200.16384 KitsRoot)
356 # Included with VS 2012 Update 1 or later
357 # Introduces v110_xp toolset
358 _winsdk_check_microsoft_sdks_registry(v7.1A 7.1.51106)
359 if(_winsdk_vistaonly_ok)
360 # Microsoft Windows SDK for Windows 7 and .NET Framework 4
361 # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
362 _winsdk_check_microsoft_sdks_registry(v7.1 7.1.7600.0.30514)
365 # Included with VS 2010
366 _winsdk_check_microsoft_sdks_registry(v7.0A 6.1.7600.16385)
368 # Windows SDK for Windows 7 and .NET Framework 3.5 SP1
370 # http://www.microsoft.com/en-us/download/details.aspx?id=18950
371 _winsdk_check_microsoft_sdks_registry(v7.0 6.1.7600.16385)
373 # Two versions call themselves "v6.1":
375 # Windows Vista Update & .NET 3.0 SDK
376 # http://www.microsoft.com/en-us/download/details.aspx?id=14477
379 # Windows Server 2008 & .NET 3.5 SDK
380 # may have broken VS9SP1? they recommend v7.0 instead, or a KB...
381 # http://www.microsoft.com/en-us/download/details.aspx?id=24826
382 _winsdk_check_microsoft_sdks_registry(v6.1 6.1.6000.16384.10)
384 # Included in VS 2008
385 _winsdk_check_microsoft_sdks_registry(v6.0A 6.1.6723.1)
387 # Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components
388 # http://blogs.msdn.com/b/stanley/archive/2006/11/08/microsoft-windows-software-development-kit-for-windows-vista-and-net-framework-3-0-runtime-components.aspx
389 _winsdk_check_microsoft_sdks_registry(v6.0 6.0.6000.16384)
392 # Let's not forget the Platform SDKs, which sometimes are useful!
393 if(_winsdk_msvc_greater_1200)
394 _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 R2" "5.2.3790.2075.51" "D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1")
395 _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 SP1" "5.2.3790.1830.15" "8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3")
398 # Finally, look for "preferred" SDKs
400 if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
403 # Environment variable for SDK dir
404 if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
405 _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
408 if(_winsdk_msvc_less_1600)
409 # Per-user current Windows SDK for VS2005/2008
410 get_filename_component(_sdkdir
411 "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
413 _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
415 # System-wide current Windows SDK for VS2005/2008
416 get_filename_component(_sdkdir
417 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
419 _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
424 function(windowssdk_name_lookup _dir _outvar)
425 list(FIND _win_sdk_versanddirs "${_dir}" _diridx)
426 math(EXPR _idx "${_diridx} - 1")
427 if(${_idx} GREATER -1)
428 list(GET _win_sdk_versanddirs ${_idx} _ret)
432 set(${_outvar} "${_ret}" PARENT_SCOPE)
435 function(windowssdk_build_lookup _dir _outvar)
436 list(FIND _win_sdk_buildsanddirs "${_dir}" _diridx)
437 math(EXPR _idx "${_diridx} - 1")
438 if(${_idx} GREATER -1)
439 list(GET _win_sdk_buildsanddirs ${_idx} _ret)
443 set(${_outvar} "${_ret}" PARENT_SCOPE)
446 # If we found something...
448 list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR)
449 windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
450 WINDOWSSDK_LATEST_NAME)
451 set(WINDOWSSDK_DIRS ${_win_sdk_dirs})
453 # Fallback, in case no preference found.
454 set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}")
455 set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}")
456 set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS})
457 set(WINDOWSSDK_FOUND_PREFERENCE OFF)
460 # If we found indications of a user preference...
461 if(_win_sdk_preferred_sdk_dirs)
462 list(GET _win_sdk_preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
463 windowssdk_name_lookup("${WINDOWSSDK_PREFERRED_DIR}"
464 WINDOWSSDK_PREFERRED_NAME)
465 set(WINDOWSSDK_PREFERRED_FIRST_DIRS
466 ${_win_sdk_preferred_sdk_dirs}
468 list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
469 set(WINDOWSSDK_FOUND_PREFERENCE ON)
472 include(FindPackageHandleStandardArgs)
473 find_package_handle_standard_args(WindowsSDK
474 "No compatible version of the Windows SDK or Platform SDK found."
478 # Internal: Architecture-appropriate library directory names.
479 if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")
480 if(CMAKE_SIZEOF_VOID_P MATCHES "8")
481 # Only supported in Win10 SDK and up.
482 set(_winsdk_arch8 arm64) # what the WDK for Win8+ calls this architecture
484 set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs
485 set(_winsdk_arch arm) # what the architecture used to be called
486 set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture
489 if(CMAKE_SIZEOF_VOID_P MATCHES "8")
490 set(_winsdk_archbare /x64) # what the architecture used to be called in oldest SDKs
491 set(_winsdk_arch amd64) # what the architecture used to be called
492 set(_winsdk_arch8 x64) # what the WDK for Win8+ calls this architecture
494 set(_winsdk_archbare ) # what the architecture used to be called in oldest SDKs
495 set(_winsdk_arch i386) # what the architecture used to be called
496 set(_winsdk_arch8 x86) # what the WDK for Win8+ calls this architecture
500 function(get_windowssdk_from_component _component _var)
501 get_filename_component(_component "${_component}" ABSOLUTE)
502 file(TO_CMAKE_PATH "${_component}" _component)
503 foreach(_sdkdir ${WINDOWSSDK_DIRS})
504 get_filename_component(_sdkdir "${_sdkdir}" ABSOLUTE)
505 string(LENGTH "${_sdkdir}" _sdklen)
506 file(RELATIVE_PATH _rel "${_sdkdir}" "${_component}")
507 # If we don't have any "parent directory" items...
508 if(NOT "${_rel}" MATCHES "[.][.]")
509 set(${_var} "${_sdkdir}" PARENT_SCOPE)
514 set(${_var} "NOTFOUND" PARENT_SCOPE)
516 function(get_windowssdk_library_dirs _winsdk_dir _var)
519 "lib${_winsdk_archbare}" # SDKs like 7.1A
520 "lib/${_winsdk_arch}" # just because some SDKs have x86 dir and root dir
521 "lib/w2k/${_winsdk_arch}" # Win2k min requirement
522 "lib/wxp/${_winsdk_arch}" # WinXP min requirement
523 "lib/wnet/${_winsdk_arch}" # Win Server 2003 min requirement
524 "lib/wlh/${_winsdk_arch}"
525 "lib/wlh/um/${_winsdk_arch8}" # Win Vista ("Long Horn") min requirement
526 "lib/win7/${_winsdk_arch}"
527 "lib/win7/um/${_winsdk_arch8}" # Win 7 min requirement
530 wlh # Win Vista ("Long Horn") min requirement
531 win7 # Win 7 min requirement
532 win8 # Win 8 min requirement
533 winv6.3 # Win 8.1 min requirement
536 list(APPEND _suffixes
537 "lib/${_ver}/${_winsdk_arch}"
538 "lib/${_ver}/um/${_winsdk_arch8}"
539 "lib/${_ver}/km/${_winsdk_arch8}"
543 # Look for WDF libraries in Win10+ SDK
544 foreach(_mode umdf kmdf)
545 file(GLOB _wdfdirs RELATIVE "${_winsdk_dir}" "${_winsdk_dir}/lib/wdf/${_mode}/${_winsdk_arch8}/*")
547 list(APPEND _suffixes ${_wdfdirs})
551 # Look in each Win10+ SDK version for the components
552 foreach(_win10ver ${_winsdk_win10vers})
553 foreach(_component um km ucrt mmos)
554 list(APPEND _suffixes "lib/${_win10ver}/${_component}/${_winsdk_arch8}")
558 foreach(_suffix ${_suffixes})
559 # Check to see if a library actually exists here.
560 file(GLOB _libs "${_winsdk_dir}/${_suffix}/*.lib")
562 list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
565 if("${_dirs}" STREQUAL "")
568 list(REMOVE_DUPLICATES _dirs)
570 set(${_var} ${_dirs} PARENT_SCOPE)
572 function(get_windowssdk_include_dirs _winsdk_dir _var)
575 set(_subdirs shared um winrt km wdf mmos ucrt)
576 set(_suffixes Include)
578 foreach(_dir ${_subdirs})
579 list(APPEND _suffixes "Include/${_dir}")
582 foreach(_ver ${_winsdk_win10vers})
583 foreach(_dir ${_subdirs})
584 list(APPEND _suffixes "Include/${_ver}/${_dir}")
588 foreach(_suffix ${_suffixes})
589 # Check to see if a header file actually exists here.
590 file(GLOB _headers "${_winsdk_dir}/${_suffix}/*.h")
592 list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
595 if("${_dirs}" STREQUAL "")
598 list(REMOVE_DUPLICATES _dirs)
600 set(${_var} ${_dirs} PARENT_SCOPE)
602 function(get_windowssdk_library_dirs_multiple _var)
604 foreach(_sdkdir ${ARGN})
605 get_windowssdk_library_dirs("${_sdkdir}" _current_sdk_libdirs)
606 if(_current_sdk_libdirs)
607 list(APPEND _dirs ${_current_sdk_libdirs})
610 if("${_dirs}" STREQUAL "")
613 list(REMOVE_DUPLICATES _dirs)
615 set(${_var} ${_dirs} PARENT_SCOPE)
617 function(get_windowssdk_include_dirs_multiple _var)
619 foreach(_sdkdir ${ARGN})
620 get_windowssdk_include_dirs("${_sdkdir}" _current_sdk_incdirs)
621 if(_current_sdk_libdirs)
622 list(APPEND _dirs ${_current_sdk_incdirs})
625 if("${_dirs}" STREQUAL "")
628 list(REMOVE_DUPLICATES _dirs)
630 set(${_var} ${_dirs} PARENT_SCOPE)