🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

630 lines
24 KiB

  1. # - Find the Windows SDK aka Platform SDK
  2. #
  3. # Relevant Wikipedia article: http://en.wikipedia.org/wiki/Microsoft_Windows_SDK
  4. #
  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
  7. # for compiling.
  8. #
  9. # Variables:
  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
  16. #
  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
  19. #
  20. # Functions:
  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.
  23. #
  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.
  26. #
  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.
  29. #
  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)
  32. #
  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.
  36. #
  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)
  39. #
  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.
  43. #
  44. # Requires these CMake modules:
  45. # FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
  46. #
  47. # Original Author:
  48. # 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
  49. # http://academic.cleardefinition.com
  50. # Iowa State University HCI Graduate Program/VRAC
  51. #
  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)
  56. set(_preferred_sdk_dirs) # pre-output
  57. set(_win_sdk_dirs) # pre-output
  58. set(_win_sdk_versanddirs) # pre-output
  59. set(_win_sdk_buildsanddirs) # pre-output
  60. set(_winsdk_vistaonly) # search parameters
  61. set(_winsdk_kits) # search parameters
  62. set(_WINDOWSSDK_ANNOUNCE OFF)
  63. if(NOT WINDOWSSDK_FOUND AND (NOT WindowsSDK_FIND_QUIETLY))
  64. set(_WINDOWSSDK_ANNOUNCE ON)
  65. endif()
  66. macro(_winsdk_announce)
  67. if(_WINSDK_ANNOUNCE)
  68. message(STATUS ${ARGN})
  69. endif()
  70. endmacro()
  71. set(_winsdk_win10vers
  72. 10.0.17763.0 # Windows 10 Version 1809
  73. 10.0.17134.0 # Windows 10 Version 1803 (April 2018 Update)
  74. 10.0.16299.0 # Windows 10 Version 1709 (Fall Creators Update)
  75. 10.0.15063.0 # Windows 10 Version 1703 (Creators Update)
  76. 10.0.14393.0 # Redstone aka Win10 1607 "Anniversary Update"
  77. 10.0.10586.0 # TH2 aka Win10 1511
  78. 10.0.10240.0 # Win10 RTM
  79. 10.0.10150.0 # just ucrt
  80. 10.0.10056.0
  81. )
  82. if(WindowsSDK_FIND_COMPONENTS MATCHES "tools")
  83. set(_WINDOWSSDK_IGNOREMSVC ON)
  84. _winsdk_announce("Checking for tools from Windows/Platform SDKs...")
  85. else()
  86. set(_WINDOWSSDK_IGNOREMSVC OFF)
  87. _winsdk_announce("Checking for Windows/Platform SDKs...")
  88. endif()
  89. # Appends to the three main pre-output lists used only if the path exists
  90. # and is not already in the list.
  91. function(_winsdk_conditional_append _vername _build _path)
  92. if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
  93. # Path invalid - do not add
  94. return()
  95. endif()
  96. list(FIND _win_sdk_dirs "${_path}" _win_sdk_idx)
  97. if(_win_sdk_idx GREATER -1)
  98. # Path already in list - do not add
  99. return()
  100. endif()
  101. _winsdk_announce( " - ${_vername}, Build ${_build} @ ${_path}")
  102. # Not yet in the list, so we'll add it
  103. list(APPEND _win_sdk_dirs "${_path}")
  104. set(_win_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
  105. list(APPEND
  106. _win_sdk_versanddirs
  107. "${_vername}"
  108. "${_path}")
  109. set(_win_sdk_versanddirs "${_win_sdk_versanddirs}" CACHE INTERNAL "" FORCE)
  110. list(APPEND
  111. _win_sdk_buildsanddirs
  112. "${_build}"
  113. "${_path}")
  114. set(_win_sdk_buildsanddirs "${_win_sdk_buildsanddirs}" CACHE INTERNAL "" FORCE)
  115. endfunction()
  116. # Appends to the "preferred SDK" lists only if the path exists
  117. function(_winsdk_conditional_append_preferred _info _path)
  118. if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
  119. # Path invalid - do not add
  120. return()
  121. endif()
  122. get_filename_component(_path "${_path}" ABSOLUTE)
  123. list(FIND _win_sdk_preferred_sdk_dirs "${_path}" _win_sdk_idx)
  124. if(_win_sdk_idx GREATER -1)
  125. # Path already in list - do not add
  126. return()
  127. endif()
  128. _winsdk_announce( " - Found \"preferred\" SDK ${_info} @ ${_path}")
  129. # Not yet in the list, so we'll add it
  130. list(APPEND _win_sdk_preferred_sdk_dirs "${_path}")
  131. set(_win_sdk_preferred_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
  132. # Just in case we somehow missed it:
  133. _winsdk_conditional_append("${_info}" "" "${_path}")
  134. endfunction()
  135. # Given a version like v7.0A, looks for an SDK in the registry under "Microsoft SDKs".
  136. # If the given version might be in both HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows
  137. # and HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots aka "Windows Kits",
  138. # use this macro first, since these registry keys usually have more information.
  139. #
  140. # Pass a "default" build number as an extra argument in case we can't find it.
  141. function(_winsdk_check_microsoft_sdks_registry _winsdkver)
  142. set(SDKKEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver}")
  143. get_filename_component(_sdkdir
  144. "[${SDKKEY};InstallationFolder]"
  145. ABSOLUTE)
  146. set(_sdkname "Windows SDK ${_winsdkver}")
  147. # Default build number passed as extra argument
  148. set(_build ${ARGN})
  149. # See if the registry holds a Microsoft-mutilated, err, designated, product name
  150. # (just using get_filename_component to execute the registry lookup)
  151. get_filename_component(_sdkproductname
  152. "[${SDKKEY};ProductName]"
  153. NAME)
  154. if(NOT "${_sdkproductname}" MATCHES "registry")
  155. # Got a product name
  156. set(_sdkname "${_sdkname} (${_sdkproductname})")
  157. endif()
  158. # try for a version to augment our name
  159. # (just using get_filename_component to execute the registry lookup)
  160. get_filename_component(_sdkver
  161. "[${SDKKEY};ProductVersion]"
  162. NAME)
  163. if(NOT "${_sdkver}" MATCHES "registry" AND NOT MATCHES)
  164. # Got a version
  165. if(NOT "${_sdkver}" MATCHES "\\.\\.")
  166. # and it's not an invalid one with two dots in it:
  167. # use to override the default build
  168. set(_build ${_sdkver})
  169. if(NOT "${_sdkname}" MATCHES "${_sdkver}")
  170. # Got a version that's not already in the name, let's use it to improve our name.
  171. set(_sdkname "${_sdkname} (${_sdkver})")
  172. endif()
  173. endif()
  174. endif()
  175. _winsdk_conditional_append("${_sdkname}" "${_build}" "${_sdkdir}")
  176. endfunction()
  177. # Given a name for identification purposes, the build number, and a key (technically a "value name")
  178. # corresponding to a Windows SDK packaged as a "Windows Kit", look for it
  179. # in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
  180. # Note that the key or "value name" tends to be something weird like KitsRoot81 -
  181. # no easy way to predict, just have to observe them in the wild.
  182. # Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
  183. # sometimes you get keys in both parts of the registry (in the wow64 portion especially),
  184. # and the non-"Windows Kits" location is often more descriptive.
  185. function(_winsdk_check_windows_kits_registry _winkit_name _winkit_build _winkit_key)
  186. get_filename_component(_sdkdir
  187. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;${_winkit_key}]"
  188. ABSOLUTE)
  189. _winsdk_conditional_append("${_winkit_name}" "${_winkit_build}" "${_sdkdir}")
  190. endfunction()
  191. # Given a name for identification purposes and the build number
  192. # corresponding to a Windows 10 SDK packaged as a "Windows Kit", look for it
  193. # in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
  194. # Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
  195. # sometimes you get keys in both parts of the registry (in the wow64 portion especially),
  196. # and the non-"Windows Kits" location is often more descriptive.
  197. function(_winsdk_check_win10_kits _winkit_build)
  198. get_filename_component(_sdkdir
  199. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]"
  200. ABSOLUTE)
  201. if(("${_sdkdir}" MATCHES "registry") OR (NOT EXISTS "${_sdkdir}"))
  202. return() # not found
  203. endif()
  204. if(EXISTS "${_sdkdir}/Include/${_winkit_build}/um")
  205. _winsdk_conditional_append("Windows Kits 10 (Build ${_winkit_build})" "${_winkit_build}" "${_sdkdir}")
  206. endif()
  207. endfunction()
  208. # Given a name for indentification purposes, the build number, and the associated package GUID,
  209. # look in the registry under both HKLM and HKCU in \\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\
  210. # for that guid and the SDK it points to.
  211. function(_winsdk_check_platformsdk_registry _platformsdkname _build _platformsdkguid)
  212. foreach(_winsdk_hive HKEY_LOCAL_MACHINE HKEY_CURRENT_USER)
  213. get_filename_component(_sdkdir
  214. "[${_winsdk_hive}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
  215. ABSOLUTE)
  216. _winsdk_conditional_append("${_platformsdkname} (${_build})" "${_build}" "${_sdkdir}")
  217. endforeach()
  218. endfunction()
  219. ###
  220. # Detect toolchain information: to know whether it's OK to use Vista+ only SDKs
  221. ###
  222. set(_winsdk_vistaonly_ok OFF)
  223. if(MSVC AND NOT _WINDOWSSDK_IGNOREMSVC)
  224. # VC 10 and older has broad target support
  225. if(MSVC_VERSION LESS 1700)
  226. # VC 11 by default targets Vista and later only, so we can add a few more SDKs that (might?) only work on vista+
  227. elseif("${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "_xp")
  228. # This is the XP-compatible v110+ toolset
  229. elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v100" OR "${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v90")
  230. # This is the VS2010/VS2008 toolset
  231. else()
  232. # OK, we're VC11 or newer and not using a backlevel or XP-compatible toolset.
  233. # These versions have no XP (and possibly Vista pre-SP1) support
  234. set(_winsdk_vistaonly_ok ON)
  235. if(_WINDOWSSDK_ANNOUNCE AND NOT _WINDOWSSDK_VISTAONLY_PESTERED)
  236. set(_WINDOWSSDK_VISTAONLY_PESTERED ON CACHE INTERNAL "" FORCE)
  237. message(STATUS "FindWindowsSDK: Detected Visual Studio 2012 or newer, not using the _xp toolset variant: including SDK versions that drop XP support in search!")
  238. endif()
  239. endif()
  240. endif()
  241. if(_WINDOWSSDK_IGNOREMSVC)
  242. set(_winsdk_vistaonly_ok ON)
  243. endif()
  244. ###
  245. # MSVC version checks - keeps messy conditionals in one place
  246. # (messy because of _WINDOWSSDK_IGNOREMSVC)
  247. ###
  248. set(_winsdk_msvc_greater_1200 OFF)
  249. if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1200)))
  250. set(_winsdk_msvc_greater_1200 ON)
  251. endif()
  252. # Newer than VS .NET/VS Toolkit 2003
  253. set(_winsdk_msvc_greater_1310 OFF)
  254. if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1310)))
  255. set(_winsdk_msvc_greater_1310 ON)
  256. endif()
  257. # VS2005/2008
  258. set(_winsdk_msvc_less_1600 OFF)
  259. if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION LESS 1600)))
  260. set(_winsdk_msvc_less_1600 ON)
  261. endif()
  262. # VS2013+
  263. set(_winsdk_msvc_not_less_1800 OFF)
  264. if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (NOT MSVC_VERSION LESS 1800)))
  265. set(_winsdk_msvc_not_less_1800 ON)
  266. endif()
  267. ###
  268. # START body of find module
  269. ###
  270. if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
  271. ###
  272. # Look for "preferred" SDKs
  273. ###
  274. # Environment variable for SDK dir
  275. if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
  276. _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
  277. endif()
  278. if(_winsdk_msvc_less_1600)
  279. # Per-user current Windows SDK for VS2005/2008
  280. get_filename_component(_sdkdir
  281. "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
  282. ABSOLUTE)
  283. _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
  284. # System-wide current Windows SDK for VS2005/2008
  285. get_filename_component(_sdkdir
  286. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
  287. ABSOLUTE)
  288. _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
  289. endif()
  290. ###
  291. # Begin the massive list of SDK searching!
  292. ###
  293. if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
  294. # These require at least Visual Studio 2013 (VC12)
  295. _winsdk_check_microsoft_sdks_registry(v10.0A)
  296. # Windows Software Development Kit (SDK) for Windows 10
  297. # Several different versions living in the same directory - if nothing else we can assume RTM (10240)
  298. _winsdk_check_microsoft_sdks_registry(v10.0 10.0.10240.0)
  299. foreach(_win10build ${_winsdk_win10vers})
  300. _winsdk_check_win10_kits(${_win10build})
  301. endforeach()
  302. endif() # vista-only and 2013+
  303. # Included in Visual Studio 2013
  304. # Includes the v120_xp toolset
  305. _winsdk_check_microsoft_sdks_registry(v8.1A 8.1.51636)
  306. if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
  307. # Windows Software Development Kit (SDK) for Windows 8.1
  308. # http://msdn.microsoft.com/en-gb/windows/desktop/bg162891
  309. _winsdk_check_microsoft_sdks_registry(v8.1 8.1.25984.0)
  310. _winsdk_check_windows_kits_registry("Windows Kits 8.1" 8.1.25984.0 KitsRoot81)
  311. endif() # vista-only and 2013+
  312. if(_winsdk_vistaonly_ok)
  313. # Included in Visual Studio 2012
  314. _winsdk_check_microsoft_sdks_registry(v8.0A 8.0.50727)
  315. # Microsoft Windows SDK for Windows 8 and .NET Framework 4.5
  316. # This is the first version to also include the DirectX SDK
  317. # http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx
  318. _winsdk_check_microsoft_sdks_registry(v8.0 6.2.9200.16384)
  319. _winsdk_check_windows_kits_registry("Windows Kits 8.0" 6.2.9200.16384 KitsRoot)
  320. endif() # vista-only
  321. # Included with VS 2012 Update 1 or later
  322. # Introduces v110_xp toolset
  323. _winsdk_check_microsoft_sdks_registry(v7.1A 7.1.51106)
  324. if(_winsdk_vistaonly_ok)
  325. # Microsoft Windows SDK for Windows 7 and .NET Framework 4
  326. # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
  327. _winsdk_check_microsoft_sdks_registry(v7.1 7.1.7600.0.30514)
  328. endif() # vista-only
  329. # Included with VS 2010
  330. _winsdk_check_microsoft_sdks_registry(v7.0A 6.1.7600.16385)
  331. # Windows SDK for Windows 7 and .NET Framework 3.5 SP1
  332. # Works with VC9
  333. # http://www.microsoft.com/en-us/download/details.aspx?id=18950
  334. _winsdk_check_microsoft_sdks_registry(v7.0 6.1.7600.16385)
  335. # Two versions call themselves "v6.1":
  336. # Older:
  337. # Windows Vista Update & .NET 3.0 SDK
  338. # http://www.microsoft.com/en-us/download/details.aspx?id=14477
  339. # Newer:
  340. # Windows Server 2008 & .NET 3.5 SDK
  341. # may have broken VS9SP1? they recommend v7.0 instead, or a KB...
  342. # http://www.microsoft.com/en-us/download/details.aspx?id=24826
  343. _winsdk_check_microsoft_sdks_registry(v6.1 6.1.6000.16384.10)
  344. # Included in VS 2008
  345. _winsdk_check_microsoft_sdks_registry(v6.0A 6.1.6723.1)
  346. # Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components
  347. # 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
  348. _winsdk_check_microsoft_sdks_registry(v6.0 6.0.6000.16384)
  349. endif()
  350. # Let's not forget the Platform SDKs, which sometimes are useful!
  351. if(_winsdk_msvc_greater_1200)
  352. _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 R2" "5.2.3790.2075.51" "D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1")
  353. _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 SP1" "5.2.3790.1830.15" "8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3")
  354. endif()
  355. ###
  356. # Finally, look for "preferred" SDKs
  357. ###
  358. if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
  359. # Environment variable for SDK dir
  360. if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
  361. _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
  362. endif()
  363. if(_winsdk_msvc_less_1600)
  364. # Per-user current Windows SDK for VS2005/2008
  365. get_filename_component(_sdkdir
  366. "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
  367. ABSOLUTE)
  368. _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
  369. # System-wide current Windows SDK for VS2005/2008
  370. get_filename_component(_sdkdir
  371. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
  372. ABSOLUTE)
  373. _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
  374. endif()
  375. endif()
  376. function(windowssdk_name_lookup _dir _outvar)
  377. list(FIND _win_sdk_versanddirs "${_dir}" _diridx)
  378. math(EXPR _idx "${_diridx} - 1")
  379. if(${_idx} GREATER -1)
  380. list(GET _win_sdk_versanddirs ${_idx} _ret)
  381. else()
  382. set(_ret "NOTFOUND")
  383. endif()
  384. set(${_outvar} "${_ret}" PARENT_SCOPE)
  385. endfunction()
  386. function(windowssdk_build_lookup _dir _outvar)
  387. list(FIND _win_sdk_buildsanddirs "${_dir}" _diridx)
  388. math(EXPR _idx "${_diridx} - 1")
  389. if(${_idx} GREATER -1)
  390. list(GET _win_sdk_buildsanddirs ${_idx} _ret)
  391. else()
  392. set(_ret "NOTFOUND")
  393. endif()
  394. set(${_outvar} "${_ret}" PARENT_SCOPE)
  395. endfunction()
  396. # If we found something...
  397. if(_win_sdk_dirs)
  398. list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR)
  399. windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
  400. WINDOWSSDK_LATEST_NAME)
  401. set(WINDOWSSDK_DIRS ${_win_sdk_dirs})
  402. # Fallback, in case no preference found.
  403. set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}")
  404. set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}")
  405. set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS})
  406. set(WINDOWSSDK_FOUND_PREFERENCE OFF)
  407. endif()
  408. # If we found indications of a user preference...
  409. if(_win_sdk_preferred_sdk_dirs)
  410. list(GET _win_sdk_preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
  411. windowssdk_name_lookup("${WINDOWSSDK_PREFERRED_DIR}"
  412. WINDOWSSDK_PREFERRED_NAME)
  413. set(WINDOWSSDK_PREFERRED_FIRST_DIRS
  414. ${_win_sdk_preferred_sdk_dirs}
  415. ${_win_sdk_dirs})
  416. list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
  417. set(WINDOWSSDK_FOUND_PREFERENCE ON)
  418. endif()
  419. include(FindPackageHandleStandardArgs)
  420. find_package_handle_standard_args(WindowsSDK
  421. "No compatible version of the Windows SDK or Platform SDK found."
  422. WINDOWSSDK_DIRS)
  423. if(WINDOWSSDK_FOUND)
  424. # Internal: Architecture-appropriate library directory names.
  425. if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")
  426. if(CMAKE_SIZEOF_VOID_P MATCHES "8")
  427. # Only supported in Win10 SDK and up.
  428. set(_winsdk_arch8 arm64) # what the WDK for Win8+ calls this architecture
  429. else()
  430. set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs
  431. set(_winsdk_arch arm) # what the architecture used to be called
  432. set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture
  433. endif()
  434. else()
  435. if(CMAKE_SIZEOF_VOID_P MATCHES "8")
  436. set(_winsdk_archbare /x64) # what the architecture used to be called in oldest SDKs
  437. set(_winsdk_arch amd64) # what the architecture used to be called
  438. set(_winsdk_arch8 x64) # what the WDK for Win8+ calls this architecture
  439. else()
  440. set(_winsdk_archbare ) # what the architecture used to be called in oldest SDKs
  441. set(_winsdk_arch i386) # what the architecture used to be called
  442. set(_winsdk_arch8 x86) # what the WDK for Win8+ calls this architecture
  443. endif()
  444. endif()
  445. function(get_windowssdk_from_component _component _var)
  446. get_filename_component(_component "${_component}" ABSOLUTE)
  447. file(TO_CMAKE_PATH "${_component}" _component)
  448. foreach(_sdkdir ${WINDOWSSDK_DIRS})
  449. get_filename_component(_sdkdir "${_sdkdir}" ABSOLUTE)
  450. string(LENGTH "${_sdkdir}" _sdklen)
  451. file(RELATIVE_PATH _rel "${_sdkdir}" "${_component}")
  452. # If we don't have any "parent directory" items...
  453. if(NOT "${_rel}" MATCHES "[.][.]")
  454. set(${_var} "${_sdkdir}" PARENT_SCOPE)
  455. return()
  456. endif()
  457. endforeach()
  458. # Fail.
  459. set(${_var} "NOTFOUND" PARENT_SCOPE)
  460. endfunction()
  461. function(get_windowssdk_library_dirs _winsdk_dir _var)
  462. set(_dirs)
  463. set(_suffixes
  464. "lib${_winsdk_archbare}" # SDKs like 7.1A
  465. "lib/${_winsdk_arch}" # just because some SDKs have x86 dir and root dir
  466. "lib/w2k/${_winsdk_arch}" # Win2k min requirement
  467. "lib/wxp/${_winsdk_arch}" # WinXP min requirement
  468. "lib/wnet/${_winsdk_arch}" # Win Server 2003 min requirement
  469. "lib/wlh/${_winsdk_arch}"
  470. "lib/wlh/um/${_winsdk_arch8}" # Win Vista ("Long Horn") min requirement
  471. "lib/win7/${_winsdk_arch}"
  472. "lib/win7/um/${_winsdk_arch8}" # Win 7 min requirement
  473. )
  474. foreach(_ver
  475. wlh # Win Vista ("Long Horn") min requirement
  476. win7 # Win 7 min requirement
  477. win8 # Win 8 min requirement
  478. winv6.3 # Win 8.1 min requirement
  479. )
  480. list(APPEND _suffixes
  481. "lib/${_ver}/${_winsdk_arch}"
  482. "lib/${_ver}/um/${_winsdk_arch8}"
  483. "lib/${_ver}/km/${_winsdk_arch8}"
  484. )
  485. endforeach()
  486. # Look for WDF libraries in Win10+ SDK
  487. foreach(_mode umdf kmdf)
  488. file(GLOB _wdfdirs RELATIVE "${_winsdk_dir}" "${_winsdk_dir}/lib/wdf/${_mode}/${_winsdk_arch8}/*")
  489. if(_wdfdirs)
  490. list(APPEND _suffixes ${_wdfdirs})
  491. endif()
  492. endforeach()
  493. # Look in each Win10+ SDK version for the components
  494. foreach(_win10ver ${_winsdk_win10vers})
  495. foreach(_component um km ucrt mmos)
  496. list(APPEND _suffixes "lib/${_win10ver}/${_component}/${_winsdk_arch8}")
  497. endforeach()
  498. endforeach()
  499. foreach(_suffix ${_suffixes})
  500. # Check to see if a library actually exists here.
  501. file(GLOB _libs "${_winsdk_dir}/${_suffix}/*.lib")
  502. if(_libs)
  503. list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
  504. endif()
  505. endforeach()
  506. if("${_dirs}" STREQUAL "")
  507. set(_dirs NOTFOUND)
  508. else()
  509. list(REMOVE_DUPLICATES _dirs)
  510. endif()
  511. set(${_var} ${_dirs} PARENT_SCOPE)
  512. endfunction()
  513. function(get_windowssdk_include_dirs _winsdk_dir _var)
  514. set(_dirs)
  515. set(_subdirs shared um winrt km wdf mmos ucrt)
  516. set(_suffixes Include)
  517. foreach(_dir ${_subdirs})
  518. list(APPEND _suffixes "Include/${_dir}")
  519. endforeach()
  520. foreach(_ver ${_winsdk_win10vers})
  521. foreach(_dir ${_subdirs})
  522. list(APPEND _suffixes "Include/${_ver}/${_dir}")
  523. endforeach()
  524. endforeach()
  525. foreach(_suffix ${_suffixes})
  526. # Check to see if a header file actually exists here.
  527. file(GLOB _headers "${_winsdk_dir}/${_suffix}/*.h")
  528. if(_headers)
  529. list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
  530. endif()
  531. endforeach()
  532. if("${_dirs}" STREQUAL "")
  533. set(_dirs NOTFOUND)
  534. else()
  535. list(REMOVE_DUPLICATES _dirs)
  536. endif()
  537. set(${_var} ${_dirs} PARENT_SCOPE)
  538. endfunction()
  539. function(get_windowssdk_library_dirs_multiple _var)
  540. set(_dirs)
  541. foreach(_sdkdir ${ARGN})
  542. get_windowssdk_library_dirs("${_sdkdir}" _current_sdk_libdirs)
  543. if(_current_sdk_libdirs)
  544. list(APPEND _dirs ${_current_sdk_libdirs})
  545. endif()
  546. endforeach()
  547. if("${_dirs}" STREQUAL "")
  548. set(_dirs NOTFOUND)
  549. else()
  550. list(REMOVE_DUPLICATES _dirs)
  551. endif()
  552. set(${_var} ${_dirs} PARENT_SCOPE)
  553. endfunction()
  554. function(get_windowssdk_include_dirs_multiple _var)
  555. set(_dirs)
  556. foreach(_sdkdir ${ARGN})
  557. get_windowssdk_include_dirs("${_sdkdir}" _current_sdk_incdirs)
  558. if(_current_sdk_libdirs)
  559. list(APPEND _dirs ${_current_sdk_incdirs})
  560. endif()
  561. endforeach()
  562. if("${_dirs}" STREQUAL "")
  563. set(_dirs NOTFOUND)
  564. else()
  565. list(REMOVE_DUPLICATES _dirs)
  566. endif()
  567. set(${_var} ${_dirs} PARENT_SCOPE)
  568. endfunction()
  569. endif()