[cmake-developers] [PATCH SET] Support of Clang/C2 compiler

Mariusz Pluciński plucinski.mariusz at gmail.com
Sat Feb 27 09:38:16 EST 2016


Hello,

About three months ago, Microsoft has released Visual Studio 2015 Update 1
with an interesting feature - the preview version of "Clang with Microsoft
CodeGen" (a.k.a. Clang/C2). It is a separate compiler, built from frontend
of Clang and backend of Microsoft's C++ compiler (known as C2). One of
advantages of this compiler over cl.exe is full support of C++14 and GNU
extensions. I thought, it would be interesting to make it usable with CMake.

Basically, to switch the compiler one needs to select appropriate toolset -
"c140_clang_3_7". CMake already has support of toolsets, so it's already
possible to generate VS project with the following command:

> cmake.exe -G "Visual Studio 14 2015" -T "v140_clang_3_7" <src dir>

Unfortunately, as this toolset is a bit different, it requires some
different settings in the project file than these used with cl.exe
compiler. This is what I am trying to fix with my patches.

Following is the list of patches with descriptions:

1. kwsys: fix build on VS Clang/C2 toolset
Makes it possible to build CMake itself with Clang/C2. This compiler does
not support inline assembly in the cl.exe format.

2. CMakeDetermineCompilerId: allow to detect clang.exe bundled with Visual
Studio
CMAKE_C(XX)?_COMPILER variables should point to clang.exe instead of cl.exe

3. Visual Studio: in Clang/C2 toolset, setup correct compiler settings
clang.exe takes most of options in clang/gcc-compatible format instead of
cl.exe format.

4. Clang testable features: don't enable
cxx_decltype_incomplete_return_type in MSVC simluation mode
This feature does not work. Honestly, I am not sure about the reason - may
be the bug in the compiler.

5. Visual Studio 14: support of <CppLanguageStandard> tag in project files
Projects using Clang/C2 use this tag to control language standard version.

6. Tests: fix AliasTarget building on Clang/C2
Clang in C++98 mode is unable to parse some of headers bundled with MSVC,
so using C++11 is necessary.

7. Tests: fix Module.GenerateExportHeader building on Clang/C2
Clang/C2 uses gcc attributes syntax for deprecations, but uses cl.exe
syntax for dllimports/exports.
Also, includes same fix as in patch 6.

8. Tests: fix Module.WriteCompilerDetectionHeader building on Clang/C2
Visual Studio does not handle this test very well. Not sure why.

9. Tests: fix Complex building on Clang/C2
Same as in patch 6.

10. Tests: fix complexOneConfig building on Clang/C2
Same as in patch 6.

11. Tests: do not build ExternalProjectLocal/TutorialStep5 when path is too
long
This toolset uses a bit longer names of some files, which may cause full
path size to exceed 256 characters.

12. Tests: fix Plugin building on Clang/C2
Same as in patch 6.

13. Tests: fix PDBDirectoryAndName on Clang/C2
Clang/C2 does not generate pdb files for static libraries. Note that
debugging information is not lost - they're put into the .lib itself, and
when the binary is created, they seem to be extracted and placed into
binary's own pdb file.

14. Tests: do not build PrecompiledHeader on Clang/C2
Precompiled headers are not (yet?) supported in this compiler.

15. Tests: disable VSMidl on Clang/C2
I don't know why this test fails.


As you can see, most of the changes are tests adjustments. In case of
patches 8 and 15 I cannot provide good explanations on why these tests are
failing - all suggestions are welcome!

What can be guessed from the list of patches, I have successfully compiled
CMake itself, and got all tests passing. Checked with aforementioned VS
version, on Windows Server 2012. Patches are attached, they apply on top of
"next" branch (d7b1a40b0f039ed46522d5c9f3c7c421833ba32c).

I would highly appreciate any feedback or review!

Best Regards
Mariusz Plucinski


PS For anybody who would like to run it: the precondition is to install
Visual Studio 2015 Update 1 with "Clang with Microsoft CodeGen".
Information about this process and more information about the feature
itself are available in Visual C++ Team Blog on MSDN:
https://blogs.msdn.microsoft.com/vcblog/2015/12/04/clang-with-microsoft-codegen-in-vs-2015-update-1/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-kwsys-fix-build-on-VS-Clang-C2-toolset.patch
Type: application/octet-stream
Size: 1026 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0015.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-CMakeDetermineCompilerId-allow-to-detect-clang.exe-b.patch
Type: application/octet-stream
Size: 1033 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0016.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Visual-Studio-in-Clang-C2-toolset-setup-correct-comp.patch
Type: application/octet-stream
Size: 4972 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0017.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Clang-testable-features-don-t-enable-cxx_decltype_in.patch
Type: application/octet-stream
Size: 1427 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0018.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Visual-Studio-14-support-of-CppLanguageStandard-tag-.patch
Type: application/octet-stream
Size: 1440 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0019.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Tests-fix-AliasTarget-building-on-Clang-C2.patch
Type: application/octet-stream
Size: 1092 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0020.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-Tests-fix-Module.GenerateExportHeader-building-on-Cl.patch
Type: application/octet-stream
Size: 4597 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0021.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-Tests-fix-Module.WriteCompilerDetectionHeader-buildi.patch
Type: application/octet-stream
Size: 1086 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0022.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-Tests-fix-Complex-building-on-Clang-C2.patch
Type: application/octet-stream
Size: 1071 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0023.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0010-Tests-fix-complexOneConfig-building-on-Clang-C2.patch
Type: application/octet-stream
Size: 1112 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0024.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0011-Tests-do-not-build-ExternalProjectLocal-TutorialStep.patch
Type: application/octet-stream
Size: 1275 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0025.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0012-Tests-fix-Plugin-building-on-Clang-C2.patch
Type: application/octet-stream
Size: 1124 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0026.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0013-Tests-fix-PDBDirectoryAndName-on-Clang-C2.patch
Type: application/octet-stream
Size: 1167 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0027.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0014-Tests-do-not-build-PrecompiledHeader-on-Clang-C2.patch
Type: application/octet-stream
Size: 914 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0028.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0015-Tests-disable-VSMidl-on-Clang-C2.patch
Type: application/octet-stream
Size: 1607 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160227/c81cb9e5/attachment-0029.obj>


More information about the cmake-developers mailing list