zufuliu / llvm-utils

LLVM/Clang toolsets for Visual Studio 2022, 2019, 2017, 2015, 2013, 2012 and 2010.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support for Visual studio build tools

nolange opened this issue · comments

Hello,

I would like to use LLVM without the Visual Studio IDE (either cmdline or other editors).
They tend to be hard to find, but the toolset is available standalone Visual Studio 2019 Build Tools.

What I effectively had to do was replace the detection in the install script with:

SET VCT_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\Platforms
IF EXIST "!VCT_PATH!" CALL :SUB_VS2019 "!VCT_PATH!"

this lets me use CMake for Projects by using

"%ProgramFiles%\CMake\bin\cmake.exe" -G"Visual Studio 16 2019" -A x64 -T "LLVM_v142" SOURCEDIR

PS. is it possible to pass target properties to CMake ? like using ldd-link and llvm-rc?

lld-link, llvm-lib and llvm-rc can be enabled by change following properties to true:

in LLVM.Common.props or generated project file.

<UseClangCl>true</UseClangCl>
<UseLldLink>false</UseLldLink>
<UseLlvmLib>false</UseLlvmLib>
<UseLlvmRc>false</UseLlvmRc>

UseClangCl

for BuildTools, can you test whether following script works or not? it's based on microsoft/vswhere#22 (comment)

@rem Visual Studio 2019 Build Tools
FOR /f "delims=" %%A IN ('"%VSWHERE%" -products "Microsoft.VisualStudio.Product.BuildTools" -property installationPath -prerelease -version [16.0^,17.0^)') DO (
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v160\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2019 "!VCT_PATH!"
	@rem Visual C++ 2017 v141 toolset
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v150\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2017 "!VCT_PATH!" 2019
)

its very strange, the tool would output the right string, but the script will complain that 'C:\Program' is not recognized as an internal or external command, operable program or batch file.

It does work as intended if I remove the quotes around Microsoft.VisualStudio.Product.BuildTools

H:\>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"  -products "Microsoft.VisualStudio.Product.BuildTools" -property installationPath -prerelease -version [16.0^,17.0^)
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools

lld-link, llvm-lib and llvm-rc can be enabled by change following properties to true:

in LLVM.Common.props or generated project file.

<UseClangCl>true</UseClangCl>
<UseLldLink>false</UseLldLink>
<UseLlvmLib>false</UseLlvmLib>
<UseLlvmRc>false</UseLlvmRc>

UseClangCl

Ok, so i need to either do that globally or use a GUI that I dont have?
Probably A missing feature in CMake to be able to set target props?

its very strange, the tool would output the right string, but the script will complain that 'C:\Program' is not recognized as an internal or external command, operable program or batch file.

It does work as intended if I remove the quotes around Microsoft.VisualStudio.Product.BuildTools

H:\>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"  -products "Microsoft.VisualStudio.Product.BuildTools" -property installationPath -prerelease -version [16.0^,17.0^)
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools

Thanks for the testing, I means add the script into https://github.com/zufuliu/llvm-utils/blob/master/VS2017/install.bat#L24 (before IF %SUCCESS% == 0)

@rem Visual Studio 2019 Build Tools
FOR /f "delims=" %%A IN ('"%VSWHERE%" -products "Microsoft.VisualStudio.Product.BuildTools" -property installationPath -prerelease -version [16.0^,17.0^)') DO (
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v160\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2019 "!VCT_PATH!"
	@rem Visual C++ 2017 v141 toolset
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v150\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2017 "!VCT_PATH!" 2019
)

Yes i did that. But it only works if I remove the quotes, maybe the CMD processor dies something stupid like matching the last double quote?
You should get the same error msg

@rem Visual Studio 2019 Build Tools
FOR /f "delims=" %%A IN ('"%VSWHERE%" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath -prerelease -version [16.0^,17.0^)') DO (
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v160\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2019 "!VCT_PATH!"
	@rem Visual C++ 2017 v141 toolset
	SET VCT_PATH=%%A\MSBuild\Microsoft\VC\v150\Platforms
	IF EXIST "!VCT_PATH!" CALL :SUB_VS2017 "!VCT_PATH!" 2019
)

Tested other product ids from https://docs.microsoft.com/en-us/visualstudio/install/workload-and-component-ids, without quotes indeed works, committed changes to install.bat as 59932b8.

For CMake, you can changed LLVM.Common.props locally, and test whether lld-link, llvm-lib and llvm-rc works for you projects. unlike clang-cl, these tools are not very compatible with corresponding msvc tools, or not works as expected (e.g. LTO with MSBuild VC project not works).

Thanks