44# Clang/LLVM toolchain for Windows
55# Usage: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/clang.cmake
66
7- # Locate ml64.exe (MASM assembler) from MSVC installation
7+ # Use vswhere to find the VS installation path without hardcoding version/edition
8+ find_program (_VSWHERE vswhere
9+ PATHS "C:/Program Files (x86)/Microsoft Visual Studio/Installer"
10+ NO_DEFAULT_PATH
11+ )
12+ if (_VSWHERE)
13+ execute_process (
14+ COMMAND "${_VSWHERE} " -latest -property installationPath
15+ OUTPUT_VARIABLE _VS_INSTALL_PATH
16+ OUTPUT_STRIP_TRAILING_WHITESPACE
17+ )
18+ file (GLOB _MSVC_TOOL_DIRS "${_VS_INSTALL_PATH} /VC/Tools/MSVC/*/bin/Hostx64/x64" )
19+ endif ()
20+
21+ # Locate ml64.exe (MASM assembler)
822find_program (_ML64_PATH ml64
9- PATHS
23+ HINTS
1024 "$ENV{VCToolsInstallDir} /bin/Hostx64/x64"
11- "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/*/bin/Hostx64/x64"
12- "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/*/bin/Hostx64/x64"
13- "C:/Program Files/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/*/bin/Hostx64/x64"
25+ ${_MSVC_TOOL_DIRS}
1426)
1527if (_ML64_PATH)
1628 set (CMAKE_ASM_MASM_COMPILER "${_ML64_PATH} " )
@@ -20,8 +32,11 @@ endif()
2032
2133set (CMAKE_SYSTEM_NAME Windows)
2234
23- # Find Clang from default LLVM install locations
35+ # Find Clang - bundled with VS (preferred) or standalone LLVM install
2436find_program (CLANG_CL_PATH clang-cl
37+ HINTS
38+ "${_VS_INSTALL_PATH} /VC/Tools/Llvm/x64/bin"
39+ "$ENV{VCToolsInstallDir} /../../Llvm/x64/bin"
2540 PATHS
2641 "C:/Program Files/LLVM/bin"
2742 "C:/Program Files (x86)/LLVM/bin"
0 commit comments