MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / findBestSysroot

Method findBestSysroot

Libraries/Plugin/Plugin.cpp:745–805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745SC::Result SC::PluginSysroot::findBestSysroot(PluginCompiler::Type compilerType, PluginSysroot& sysroot)
746{
747#if SC_PLATFORM_WINDOWS
748 // TODO: This is clearly semi-hardcoded, and we could get the installed directory by looking at registry
749 StringSpan baseDirectory = SC_NATIVE_STR("C:\\Program Files (x86)\\Windows Kits\\10");
750
751 StringPath windowsSdkVersion;
752 StringSpan searchPath = SC_NATIVE_STR("C:\\Program Files (x86)\\Windows Kits\\10\\include");
753
754 PluginFileSystemIterator iterator;
755 SC_TRY(iterator.init(searchPath));
756 PluginFileSystemIterator::Entry entry;
757 while (iterator.next(entry))
758 {
759 if (entry.isDirectory and entry.name != SC_NATIVE_STR(".") and entry.name != SC_NATIVE_STR(".."))
760 {
761 SC_TRY(windowsSdkVersion.assign(entry.name));
762 break;
763 }
764 }
765
766 SC_TRY_MSG(not windowsSdkVersion.isEmpty(), "Cannot find Windows Kits 10 include directory")
767 switch (compilerType)
768 {
769 case PluginCompiler::Type::MicrosoftCompiler: {
770 constexpr StringSpan includeDirectories[] = {SC_NATIVE_STR("ucrt"), SC_NATIVE_STR("um"),
771 SC_NATIVE_STR("shared"), SC_NATIVE_STR("winrt"),
772 SC_NATIVE_STR("cppwinrt")};
773 for (StringSpan it : includeDirectories)
774 {
775 StringPath str;
776 SC_TRY(PluginString::assign(
777 str, {baseDirectory, SC_NATIVE_STR("\\include\\"), windowsSdkVersion.view(), SC_NATIVE_STR("\\"), it}));
778 SC_TRY(sysroot.includePaths.push_back(move(str)));
779 }
780 StringSpan instructionSet = "x64";
781 switch (HostInstructionSet)
782 {
783 case InstructionSet::Intel32: instructionSet = "x86"; break;
784 case InstructionSet::Intel64: instructionSet = "x64"; break;
785 case InstructionSet::ARM64: instructionSet = "arm64"; break;
786 }
787
788 constexpr StringSpan libraryDirectories[] = {SC_NATIVE_STR("ucrt"), SC_NATIVE_STR("um")};
789 for (StringSpan it : libraryDirectories)
790 {
791 StringPath str;
792 SC_TRY(PluginString::assign(str, {baseDirectory, SC_NATIVE_STR("\\lib\\"), windowsSdkVersion.view(),
793 SC_NATIVE_STR("\\"), it, SC_NATIVE_STR("\\"), instructionSet}));
794 SC_TRY(sysroot.libraryPaths.push_back(move(str)));
795 }
796 }
797 break;
798 default: break;
799 }
800#else
801 (void)compilerType;
802 (void)sysroot;

Callers

nothing calls this directly

Calls 8

assignFunction · 0.50
ResultClass · 0.50
initMethod · 0.45
nextMethod · 0.45
assignMethod · 0.45
isEmptyMethod · 0.45
viewMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected