dutow / ccf

Helper modules for CMake
1 stars 0 forks source link

Using CLang with MinGW64 on Windows #1

Open RoyiAvital opened 6 years ago

RoyiAvital commented 6 years ago

Hello,

I saw the issue Add support for Clang targeting MSVC ABI but with GNU-like command line.

I'm also trying to be able to use CLang (Based on 6.0.1) properly in Windows under 3 use cases:

  1. With MSVC Generator
    I can't achieve this since no matter what I do when -G"Visual Studio 15 2017 Win64" CMake ignore the other variables (-D CMAKE_C_COMPILER=clang-cl -D CMAKE_CXX_COMPILER=clang-cl ..) and use cl for compiling.
  2. With Ninja Generator
    If I use x64 Native Tools Command Prompt for VS 2017 I'm able, using the Ninja Generator to use Clang (cmake -G"Ninja" -D CMAKE_C_COMPILER=clang-cl.exe -D CMAKE_CXX_COMPILER=clang-cl.exe -D CMAKE_LINKER=lld-link.exe ..). Yet If I try from different CMD it won't work (Do you know which system variables are needed to configure it correctly?).
  3. With MinGW Generator
    I can't make it work with MinGW generator as, by default, clang on windows is targeting MSVC ABI and MSVC flag style. I wonder how can one configure CMake to use clang in MinGW configuration for this generator.

Any ideas on that?

Thank You.

RoyiAvital commented 6 years ago

@dutow , Any comment?

Thank You.

dutow commented 6 years ago

Hello

Sorry for the late reply. Regarding the issue you linked, I had no time to work on it on the summer - I hope to finish it in a few weeks.

For your 3 use cases:

The first should work - there is a separate toolchain setting you should pass to cmake: cmake .. -TLLVM-vs2014 -G"Visual Studio 14 2015"

For your second, I usually use it after loading the visual studio variables - you can load them in any command prompt / script easily, for example:

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall" amd64

Without this, the main issue is with the linker - but I didn't investigate the issue much, as loading the variables is easy.

3 - As far as I know, that's not possible right now, not without some changes in the mingw generator, because of the ABI difference you mentioned.

RoyiAvital commented 6 years ago

Hi,

Will (1) work if I have MSVC 2017? Namely can I do cmake -G"Visual Studio 14 2015" -T"LLVM-vs2014" .. even if I only have MSVC 2017 installed?

Regarding (3), Is there a way to prevent CMake from checking the ABI and just treat CLang as it would treat GCC just with different command (Something to set the driver of Clang to GCC)?

RoyiAvital commented 5 years ago

@dutow , Any updates regarding Clang on Windows with Cmake?

Thank You.

dutow commented 5 years ago

@RoyiAvital with 3.15, the clang++/clang format works on windows too. E.g. CC=clang CXX=clang++ cmake -G Ninja works on windows.

With 3.16, it will work even without vcvarsall (assuming the limited llvm-rc is good for your project), and for clang-cl too. You can even do this with 3.15, if you specify the RC compiler and linker manually.

For your (1) and (3) use cases, I have no updates / I'm still not using those - so if you have any issues with them, you probably should open a bug on the cmake gitlab.

Edit: but based on the cmake code, (3) should work?

RoyiAvital commented 5 years ago

We have Clang with:

clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Applications\Programming\MSYS64\mingw64\bin

And

clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:\Applications\Programming\MSYS64\mingw64\bin

Will we have support for both?