1111#include < sw/builder/program.h>
1212
1313#include < boost/algorithm/string.hpp>
14+ #ifdef _WIN32
15+ #include < WinReg.hpp>
16+ #endif
1417
1518#include < regex>
1619#include < string>
@@ -672,7 +675,32 @@ static path getWindowsKitRoot()
672675 auto p = getProgramFilesX86 () / " Windows Kits" ;
673676 if (fs::exists (p))
674677 return p;
675- throw SW_RUNTIME_ERROR (" No Windows Kits available" );
678+ // throw SW_RUNTIME_ERROR("No Windows Kits available");
679+ return {};
680+ }
681+
682+ static path getWindows10KitRoot ()
683+ {
684+ #ifdef _WIN32
685+ winreg::RegKey kits10 (HKEY_LOCAL_MACHINE, L" SOFTWARE\\ Microsoft\\ Windows Kits\\ Installed Roots" , KEY_READ);
686+ return kits10.GetStringValue (L" KitsRoot10" );
687+ #endif
688+ // throw SW_RUNTIME_ERROR("No Windows Kits available");
689+ return {};
690+ }
691+
692+ static VersionSet listWindows10Kits ()
693+ {
694+ VersionSet kits;
695+ #ifdef _WIN32
696+ winreg::RegKey kits10 (HKEY_LOCAL_MACHINE, L" SOFTWARE\\ Microsoft\\ Windows Kits\\ Installed Roots" , KEY_READ);
697+ for (auto &k : kits10.EnumSubKeys ())
698+ {
699+ kits.insert (to_string (k));
700+ }
701+ #endif
702+ // throw SW_RUNTIME_ERROR("No Windows Kits available");
703+ return kits;
676704}
677705
678706static String getWin10KitDirName ()
@@ -683,10 +711,16 @@ static String getWin10KitDirName()
683711static Strings listWindowsKits ()
684712{
685713 // https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
686- static const Strings known_kits{ getWin10KitDirName (), " 8.1A" , " 8.1" , " 8.0" , " 7.1A" , " 7.1" , " 7.0A" , " 7.0A" ," 6.0A" };
714+ static const Strings known_kits{ " 8.1A" , " 8.1" , " 8.0" , " 7.1A" , " 7.1" , " 7.0A" , " 7.0A" ," 6.0A" };
687715
688716 Strings kits;
689- auto kr = getWindowsKitRoot ();
717+
718+ // special handling for win10 kits
719+ auto kr = getWindows10KitRoot ();
720+ if (fs::exists (kr))
721+ kits.push_back (getWin10KitDirName ());
722+
723+ kr = getWindowsKitRoot ();
690724 for (auto &k : known_kits)
691725 {
692726 auto d = kr / k;
@@ -696,30 +730,6 @@ static Strings listWindowsKits()
696730 return kits;
697731}
698732
699- static path getWin10KitInspectionDir ()
700- {
701- auto kr = getWindowsKitRoot ();
702- auto dir = kr / getWin10KitDirName () / " Include" ;
703- return dir;
704- }
705-
706- static VersionSet listWindows10Kits ()
707- {
708- VersionSet kits;
709- auto dir = getWin10KitInspectionDir ();
710- for (auto &i : fs::directory_iterator (dir))
711- {
712- if (fs::is_directory (i))
713- {
714- auto d = i.path ().filename ().u8string ();
715- Version v = d;
716- if (v.isVersion ())
717- kits.insert (d);
718- }
719- }
720- return kits;
721- }
722-
723733void detectWindowsSdk (DETECT_ARGS)
724734{
725735 // ucrt - universal CRT
@@ -806,7 +816,7 @@ void detectWindowsSdk(DETECT_ARGS)
806816
807817 for (auto &k : listWindowsKits ())
808818 {
809- auto kr = getWindowsKitRoot () /k;
819+ auto kr = getWindowsKitRoot () / k;
810820 if (k == getWin10KitDirName ())
811821 {
812822 for (auto &v : listWindows10Kits ())
0 commit comments