CMake uses wrong compiler for detection.
MikuAuahDark opened this issue · comments
D:\Data\Development\HonokaMiku5>cmake -Bbuild -H. -A x64 -T LLVM_v120
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.17763.
-- The C compiler identification is Clang 8.0.0
-- The CXX compiler identification is Clang 8.0.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Data/Development/HonokaMiku5/build
At first, it shows correctly that the compiler identification is "Clang 8.0.0", but then it uses cl.exe
to detect whetever the compiler is working. This doesn't happen when using "LLVM Compiler Toolchain" addon.
D:\Data\Development\HonokaMiku5>cmake -Bbuild -H. -A x64 -T llvm
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.17763.
-- The C compiler identification is Clang 8.0.0
-- The CXX compiler identification is Clang 8.0.0
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Data/Development/HonokaMiku5/build
But in my case I need to use VS2013 toolchain because my cl.exe
for VS2013 actually broken due to "Use unicode UTF-8 for worldwide language support" in Windows 10 and I have no plans to turn that feature back off.
I found two generated projects CompilerIdC and CompilerIdCXX in build/CMakeFiles// are different.
official llvm:
<PostBuildEvent>
<Command>echo CMAKE_C_COMPILER=$(ClangClExecutable)</Command>
</PostBuildEvent>
<PostBuildEvent>
<Command>echo CMAKE_CXX_COMPILER=$(ClangClExecutable)</Command>
</PostBuildEvent>
LLVM_vxyz:
<PostBuildEvent>
<Command>for %%i in (cl.exe) do %40echo CMAKE_C_COMPILER=%%~$PATH:i</Command>
</PostBuildEvent>
<PostBuildEvent>
<Command>for %%i in (cl.exe) do %40echo CMAKE_CXX_COMPILER=%%~$PATH:i</Command>
</PostBuildEvent>
Which was caused by cmake/share/version/Modules/CMakeDetermineCompilerId.cmake
Change
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm]$")
set(id_cl_var "ClangClExecutable")
to (adding (_v[0-9]+(_xp)?)?
)
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$")
set(id_cl_var "ClangClExecutable")
every thing works.
Edit: change to (_v[0-9]+(_xp)?)?
to support LLVM_vxxx_xp toolset.
So this more like CMake problem. Would it be good to pass this issue to CMake repository?
This was fixed (expected in CMake 3.15.0) at https://gitlab.kitware.com/cmake/cmake/merge_requests/3281
Nice, thank you very much.
The fix is available in CMake 3.15.0 now.
https://cmake.org/download/