Mixing cl.exe and clang-cl.exe within a CMake

1 week ago 4
ARTICLE AD BOX

I have a cmake C++ project being compiled on Windows, using vcpkg in manifest mode. I am in process of switching from MSVC default cl.exe compiler to MSVC clang-based clang-cl.exe. I managed to do it for vcpkg dependencies by using Neumann-A's triplets (github.com/Neumann-A/my-vcpkg-triplets). I also managed to fall back to cl.exe for few dependencies that didn't want to cooperate with clang.

Now I am doing it for my own code.

The problem is, that there are few, platform-dependent cpp files that clang-cl.exe cannot process. For example, I have a file that includes:

#include <windows.h> ... //some other includes #include <ehdata.h>

and I get an error like this:

In file included from C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include/ehdata_values.h:11: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include/ehdata_forceinclude.h(192,26): error: unknown type name '_ThrowInfo'; did you mean 'ThrowInfo'? void* pExceptionObject, _ThrowInfo* pThrowInfo) noexcept(false); ^ C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include/ehdata_forceinclude.h(182,3): note: 'ThrowInfo' declared here } ThrowInfo; ^

I don't think I can fix these few cpp files. What I would like to do instead, is to instruct cmake to use a regular cl.exe in those few cases.

To my knowledge clang-cl.exe and cl.exe, coming from the same MSVC bundle are ABI compatible and this shouldn't be a problem. However, CMake is not designed for that kind of mixing of compilers; the compiler is usually set up in configuration instead.

When I asked in few other places, I get a response that I am doing it wrong, and the problem is wrong... but I don't see a way to do it right?

Read Entire Article