18 std::filesystem::path cl_exe_name = L
"cl.exe";
19 std::filesystem::path found_path;
22 const char *path_env = std::getenv(
"PATH");
25 size_t current_pos = 0;
28 while ((delimiter_pos = path_env_str.find(L
';', current_pos)) != std::wstring::npos) {
29 std::filesystem::path dir = path_env_str.substr(current_pos, delimiter_pos - current_pos);
30 std::filesystem::path potential_cl_path = dir / cl_exe_name;
31 if (std::filesystem::exists(potential_cl_path) && std::filesystem::is_regular_file(potential_cl_path)) {
32 found_path = potential_cl_path;
35 current_pos = delimiter_pos + 1;
38 if (found_path.empty()) {
39 std::filesystem::path dir = path_env_str.substr(current_pos);
40 std::filesystem::path potential_cl_path = dir / cl_exe_name;
41 if (std::filesystem::exists(potential_cl_path) && std::filesystem::is_regular_file(potential_cl_path)) {
42 found_path = potential_cl_path;
47 if (!found_path.empty()) {
52 bool isResolved{
false};
56 std::vector<std::filesystem::path> vs_install_bases = {
57 L
"C:/Program Files (x86)/Microsoft Visual Studio/",
58 L
"C:/Program Files/Microsoft Visual Studio/"
61 std::vector<std::filesystem::path> windows_kit_install_bases = {L
"C:/Program Files (x86)/Windows Kits/10/Lib",
62 L
"C:/Program Files/Windows Kits/10/Lib"};
64 for (
const auto &base_path : vs_install_bases) {
65 if (!std::filesystem::exists(base_path) || !std::filesystem::is_directory(base_path)) {
68 for (
const auto &year_entry : std::filesystem::directory_iterator(base_path)) {
69 if (!year_entry.is_directory())
72 for (
const auto &component_entry : std::filesystem::directory_iterator(year_entry.path())) {
73 if (!component_entry.is_directory())
76 std::filesystem::path vc_tools_msvc_path = component_entry.path() / L
"VC" / L
"Tools" / L
"MSVC";
78 if (!std::filesystem::exists(vc_tools_msvc_path) ||
79 !std::filesystem::is_directory(vc_tools_msvc_path)) {
84 for (
const auto &msvc_version_entry : std::filesystem::directory_iterator(vc_tools_msvc_path)) {
85 if (!msvc_version_entry.is_directory())
89 std::vector<std::filesystem::path> bin_sub_paths = {
96 std::vector<std::filesystem::path> lib_sub_paths = {L
"lib\\x64", L
"lib\\x86"};
98 for (
const auto &bin_sub_path : bin_sub_paths) {
99 std::filesystem::path potential_cl_path =
100 msvc_version_entry.path() / bin_sub_path / cl_exe_name;
101 if (std::filesystem::exists(potential_cl_path) &&
102 std::filesystem::is_regular_file(potential_cl_path)) {
103 found_path = potential_cl_path;
105 std::wcout << L
"clObjectLinker: Found cl.exe by searching VS installs: "
112 yoi_assert(isResolved, 0, 0,
"Unable to find cl.exe. Please ensure Visual Studio Build Tools are installed.");
115 for (
const auto &lib_sub_path : lib_sub_paths) {
116 std::filesystem::path lib_path = msvc_version_entry.path() / lib_sub_path;
118 if (std::filesystem::exists(lib_path) && std::filesystem::is_directory(lib_path)) {
120 std::wcout << L
"clObjectLinker: Found c runtime library by searching VS installs: "
127 yoi_assert(isResolved, 0, 0,
"Unable to find C runtime library. Please ensure Visual Studio Build Tools are installed.");
135 for (
const auto &base_path : windows_kit_install_bases) {
136 if (!std::filesystem::exists(base_path) || !std::filesystem::is_directory(base_path)) {
139 for (
const auto &version_entry : std::filesystem::directory_iterator(base_path)) {
140 if (!version_entry.is_directory())
143 std::vector<std::filesystem::path> um_sub_paths = {L
"um/x64", L
"um/x86"};
145 std::vector<std::filesystem::path> ucrt_sub_paths = {L
"ucrt/x64", L
"ucrt/x86"};
146 for (
const auto &um_sub_path : um_sub_paths) {
147 std::filesystem::path lib_path = version_entry.path() / um_sub_path;
149 if (std::filesystem::exists(lib_path) && std::filesystem::is_directory(lib_path)) {
151 std::wcout << L
"clObjectLinker: Found UM library by searching Windows Kits: "
158 yoi_assert(isResolved, 0, 0,
"Unable to find UM library. Please ensure Windows Kits are installed.");
161 for (
const auto &ucrt_sub_path : ucrt_sub_paths) {
162 std::filesystem::path lib_path = version_entry.path() / ucrt_sub_path;
164 if (std::filesystem::exists(lib_path) && std::filesystem::is_directory(lib_path)) {
166 std::wcout << L
"clObjectLinker: Found UCRT library by searching Windows Kits: "
177 warning(0, 0,
"Unable to find UCRT library. Please ensure Windows Kits are installed.",
"UCRT_NOT_FOUND");
179 const char* lib_env = std::getenv(
"LIB");
183 for (
auto pos = lib_env_str.find(L
';'); pos != std::wstring::npos; pos = lib_env_str.find(L
';', pos + 1)) {
184 std::wstring path = lib_env_str.substr(0, pos);
188 std::wstring path = lib_env_str.substr(0, lib_env_str.find(L
';'));
194 throw std::runtime_error(
"cl.exe linker not found. Please ensure Visual Studio Build Tools are installed and "
195 "configured, or add cl.exe to your system PATH.");