premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

Clang in Visual Studio 2019 #1461

Closed nickclark2016 closed 4 years ago

nickclark2016 commented 4 years ago

What problem will this solve? Currently, using clang in Visual Studio can be a hassle with Premake. The toolset specification to use Clang with VS projects is not intuitive to determine. I suggest that the clang toolset value should alias to the correct toolset to use for Visual Studio.

What might be a solution? Currently, an llvm-vs* option exists in Premake. This works for VS2017 with the LLVM Compiler Toolchain Extension, but the Clang toolchain is suppoted out of the box with VS 2019. Thus, the developers of the extension have recommended to use that rather than the extension, which does not work in VS 2019. In order to effectively unify setting the toolset to clang across modules, I would suggest the following:

Module Toolset Value Value in Files
VS 2017 llvm-vs2017 LLVM-vs2017
VS 2019 clang ClangCL

However, this proposed solution could break any code that is dependent upon clang setting a certain value in Visual Studio's project files.

What other alternatives have you already considered? Currently, I get this working by adding msc-ClangCL as the toolset, which aliases to Visual Studio's LLVM (clang-cl) toolset option. However, this is not desirable as I would prefer to be able to set the toolset across the all modules in my project as clang.

Anything else we should know? By doing something like this, it would reduce the amount of code needed to set the toolset for cross-platform projects which use different modules, e.g. a project that uses VS on Windows and gmake/gmake2 on Linux. If this is something worthwhile, I have free time to develop a solution for this.

starkos commented 4 years ago

It sounds like you have far more experience with this than I do. If you'd like to run with it, I'd be happy to assist with getting the changes approved and merged. I'm not super concerned with breaking compatibility for a good cause so long as we do the best we can to minimize the pain.

nickclark2016 commented 4 years ago

Sounds good. I've verified a build locally on my Linux machine and verified functionality there. I'll test a build out on Windows a bit later today and verify functionality, then I'll submit a PR.

greenkalx commented 4 years ago

There's a problem with VS2019 where it expects 'ClangCL' with mixed case. Premake lowercases this in src/_premake_init.lua. I removed this lowercasing and rebuilt premake. Without this fix, the General project properties do not open in VS.

Also, I wanted to use latest LLVM instead of the one included with VS2019, which was LLVM 8, but may be LLVM 10 now with VS2019 updates? I made an override to the "globals" function to set LLVMInstallDir. https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/

greenkalx commented 4 years ago

I have toolset set to "msc-ClangCL" at my workspace level, which sets it on all included projects within the workspace.

nickclark2016 commented 4 years ago

Thanks for the info!

nickclark2016 commented 4 years ago

@starkos closing since the PR was merged.