[cfe-dev] Not setting -fms-compatibility-version= when -fno-ms-compatibility is set
Petr Hosek via cfe-dev
cfe-dev at lists.llvm.org
Fri Feb 7 16:14:09 PST 2020
Passing --target= through CMAKE_*_FLAGS works, but it defeats the point of
using CMAKE_*_COMPILER_TARGET, which feels more idiomatic.
After reading a bit more through CMake internals, I think I can workaround
this by setting:
set(CMAKE_C_COMPILER_ID_RUN OFF)
set(CMAKE_CXX_COMPILER_ID_RUN OFF)
set(CMAKE_C_COMPILER_ID Clang)
set(CMAKE_CXX_COMPILER_ID Clang)
in the runtimes build, and then set:
set(CMAKE_C_SIMULATE_ID MSVC)
set(CMAKE_CXX_SIMULATE_ID MSVC)
when targeting *-pc-windows-msvc with Clang.
On Fri, Feb 7, 2020 at 2:26 PM Martin Storsjö <martin at martin.st> wrote:
> On Fri, 7 Feb 2020, Petr Hosek via cfe-dev wrote:
>
> > I'm trying to use Clang to cross-compile runtimes for Fuchsia on Windows.
> > The problem I'm hitting is that CMake checks the existence of _MSC_VER
> > macro, and if set it detects the compiler as "Clang with GNU-like command
> > line" which is a special mode in which CMake treats clang as clang-cl.
> This
> > breaks cross-compilation for runtimes because CMake no longer passes
> > --target= flag even if CMAKE_*_COMPILER_TARGET is set, etc. because of
> thislogic:
> https://github.com/Kitware/CMake/blob/master/Modules/Compiler/Clang.
> > cmake#L13
> > This is IMHO a bug in CMake: it shouldn't blindly assume that Clang is
> > clang-cl without first consulting other variables
> > like CMAKE_*_COMPILER_TARGET or CMAKE_SYSTEM_NAME, but I'm not sure how
> easy
> > or difficult would it be to change CMake, and even then we would have a
> > problem with rolling out new CMake version everywhere.
>
> This sounds like an issue with how CMake does compiler identification in
> mode advanced setups; I've often run into issues where I'd like to
> configure with something like CMAKE_C_COMPILER=clang
> CMAKE_C_FLAGS="-target <other-system-tuple>", but it first does all the
> compiler identification steps only with ${CMAKE_C_COMPILER} in isolation.
> This is much more straightforward with GCC like cross compilers, where one
> would have CMAKE_C_COMPILER=<other-system-tuple>-gcc. For that case iirc I
> managed it to behave correctly by using CMAKE_C_FLAGS_INIT="-target
> <other-system-tuple>", which ensures that the flag is used along with
> CMAKE_C_COMPILER even for the very first compiler identification steps.
>
> However, I'm not very proficient with CMake, I'm just fumblingly trying to
> make things work for me.
>
> // Martin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200207/85cd4bfa/attachment.html>
More information about the cfe-dev
mailing list