cmake 3.12 check_ipo_supported generates syntax error in msys2 due to Windows paths
I'm getting this syntax error just trying to call check_ipo_supported(RESULT HAS_LTO_SUPPORT)
:
CMake Error at C:/MSYS64/mingw64/share/cmake-3.12/Modules/CheckIPOSupported.cmake:65 (set): Syntax error in cmake code at
C:/MSYS64/mingw64/share/cmake-3.12/Modules/CheckIPOSupported.cmake:73
when parsing string
Change Dir: C:/MSYS64/home/nephatrine/repos/nxbuild/build/CMakeFiles/_CMakeLTOTest-CXX/bin
This completely brings project generation to a halt. It looks like this is because the resulting ${output}
contains a Windows-style path with single backslashes. Here's some of the problematic parts of the output with Ninja generation (which always fails because cmake isn't removing libfoo.a for some reason:
[3/4] Linking CXX static library libfoo.a
FAILED: libfoo.a
cmd.exe /C "cd . && C:\MSYS64\mingw64\bin\cmake.exe -E remove libfoo.a && "C:/MSYS64/mingw64/bin/gcc-ar.exe" cr libfoo.a CMakeFiles/foo.dir/foo.cpp.obj && "C:/MSYS64/mingw64/bin/gcc-ranlib.exe" libfoo.a && cd ."
C:/MSYS64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ranlib.exe: unable to rename 'libfoo.a'; reason: File exists
and then here with "MSYS Makefiles" which only fails when using clang instead of gcc since clang needs ld.gold for LTO:
C:\MSYS64\mingw64\bin\ld: CMakeFiles/boo.dir/objects.a: member CMakeFiles/boo.dir/objects.a(main.cpp.obj) in archive is not an object
In both instances there are unescaped backslashes and so CMake is choking and rather than just setting the RESULT to false, it completely stops generation. I don't mind that much that check_ipo_supported is failing (though with Ninja at least there is clearly another issue somewhere) but it shouldn't terminate CMake like that.