Creación de una aplicación x86 con CMake, Ninja y Clang en Windows x64

Quiero construir una aplicación de Windows x86 en mi máquina Windows x64.

Uso CMake, Ninja, clang-cl, lld-link y VS Build Tools 2017 con las siguientes CMakeLists

cmake_minimum_required(VERSION 3.9)
project(Test CXX)

add_library(TestLib STATIC "")
target_include_directories(TestLib
  PUBLIC
TestLib/inc
)
target_sources(TestLib
  PRIVATE
    TestLib/src/Flop.cpp
    TestLib/src/testClass.cpp
)

add_executable(Test "")
target_sources(Test
  PRIVATE
    src/main.cpp
)
target_link_libraries(Test
  TestLib
)

Mi configuración funciona bien para aplicaciones x64. Inicializo el entorno de compilación convcvars64 y llame a cmake con

cmake -G Ninja -DCMAKE_CXX_COMPILER:PATH="C:\MeineProgramme\LLVM\bin\clang-cl.exe" -DCMAKE_LINKER:PATH="C:\MeineProgramme\LLVM\bin\lld-link.exe"

Esto da como resultado archivos de compilación ninja perfectamente bien y produce un ejecutable funcional.

Si quiero compilar una aplicación x86, CMake falla al detectar el entorno de compilación. Inicializo el entorno de compilación convcvars32 ovcvarsamd64_x86 y use el mismo comando que el anterior para invocar CMake. Esto produce errores durante la detección del entorno de compilación.

El registro de errores de CMake tiene el siguiente contenido

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MeineProgramme/LLVM/bin/clang-cl.exe 
Build flags: 
Id flags:  

The output was:
1120
LINK : error LNK2001: Nicht aufgelöstes externes Symbol "mainCRTStartup".
C:\MeineProgramme\Visual_Studio\2017\BuildTools\VC\Tools\MSVC\14.11.25503\lib\x86\libcmt.lib : warning LNK4272:Bibliothekcomputertyp "x86" steht in Konflikt mit dem Zielcomputertyp "x64"
CMakeCXXCompilerId.exe : fatal error LNK1120: 1 nicht aufgelöste Externe
clang-cl.exe: error: linker command failed with exit code 1120 (use -v to see invocation)


Determining if the CXX compiler works failed with the following output:
Change Dir: D:/Dateien/Downloads/Test/build/CMakeFiles/CMakeTmp

Run Build Command:"C:/MeineProgramme/Ninja/bin/ninja.exe" "cmTC_e2ed5"
[1/2] Building CXX object CMakeFiles\cmTC_e2ed5.dir\testCXXCompiler.cxx.obj

[2/2] Linking CXX executable cmTC_e2ed5.exe

FAILED: cmTC_e2ed5.exe 

cmd.exe /C "cd . && C:\MeineProgramme\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_e2ed5.dir --manifests  -- C:\MeineProgramme\LLVM\bin\lld-link.exe /nologo CMakeFiles\cmTC_e2ed5.dir\testCXXCompiler.cxx.obj  /out:cmTC_e2ed5.exe /implib:cmTC_e2ed5.lib /pdb:cmTC_e2ed5.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."

LINK Pass 1: command "C:\MeineProgramme\LLVM\bin\lld-link.exe /nologo CMakeFiles\cmTC_e2ed5.dir\testCXXCompiler.cxx.obj /out:cmTC_e2ed5.exe /implib:cmTC_e2ed5.lib /pdb:cmTC_e2ed5.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_e2ed5.dir/intermediate.manifest CMakeFiles\cmTC_e2ed5.dir/manifest.res" failed (exit code 1) with the following output:
C:\MeineProgramme\LLVM\bin\lld-link.exe: warning: <root>: undefined symbol: mainCRTStartup

error: link failed

ninja: build stopped: subcommand failed.

Según tengo entendido, el problema es que CMake pasa/machine:x64 al enlazador.

¿Qué modificaciones debo hacer a la invocación de CMake o las CMakeLists para resolver este problema?

Cualquier ayuda es muy apreciada. Gracias chicos :-)

Respuestas a la pregunta(1)

Su respuesta a la pregunta