Skip to content

Ninja: Path to compiler uses forward slashes with launcher

Robert Dailey requested to merge rcdailey/cmake:ccache-compiler-path-fix into release

When using MINGW64's ccache on Windows with absolute paths to the compiler that the NDK cmake toolchain sets, you get the following:

C:/msys64/usr/bin/ccache.exe C:\android\android-ndk-r17b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi --gcc-toolchain=C:/android/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/android/android-ndk-r17b/sysroot  -DANDROID -IE:/code/frontend2/source/Core/ThirdParty/uri/source/src -IE:/code/frontend2/source/Core/ThirdParty/uri/source/include -isystem C:/android/android-ndk-r17b/sources/cxx-stl/llvm-libc++/include -isystem C:/android/android-ndk-r17b/sources/android/support/include -isystem C:/android/android-ndk-r17b/sources/cxx-stl/llvm-libc++abi/include -isystem C:/android/android-ndk-r17b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11  -Qunused-arguments -std=c++11 -Os -DNDEBUG    -Wno-inconsistent-missing-override -MD -MT Core/ThirdParty/uri/source/src/CMakeFiles/network-uri.dir/uri.cpp.o -MF Core\ThirdParty\uri\source\src\CMakeFiles\network-uri.dir\uri.cpp.o.d -o Core/ThirdParty/uri/source/src/CMakeFiles/network-uri.dir/uri.cpp.o -c E:/code/frontend2/source/Core/ThirdParty/uri/source/src/uri.cpp
ccache: error: Could not find compiler "C:\android\android-ndk-r17b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe" in PATH

The culprit is that backslashes are used in the path to clang. When you convert these to forward slashes, it works fine:

C:/msys64/usr/bin/ccache.exe C:/android/android-ndk-r17b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe --target=armv7-none-linux-androideabi --gcc-toolchain=C:/android/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/android/android-ndk-r17b/sysroot  -DANDROID -IE:/code/frontend2/source/Core/ThirdParty/uri/source/src -IE:/code/frontend2/source/Core/ThirdParty/uri/source/include -isystem C:/android/android-ndk-r17b/sources/cxx-stl/llvm-libc++/include -isystem C:/android/android-ndk-r17b/sources/android/support/include -isystem C:/android/android-ndk-r17b/sources/cxx-stl/llvm-libc++abi/include -isystem C:/android/android-ndk-r17b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11  -Qunused-arguments -std=c++11 -Os -DNDEBUG    -Wno-inconsistent-missing-override -MD -MT Core/ThirdParty/uri/source/src/CMakeFiles/network-uri.dir/uri.cpp.o -MF Core\ThirdParty\uri\source\src\CMakeFiles\network-uri.dir\uri.cpp.o.d -o Core/ThirdParty/uri/source/src/CMakeFiles/network-uri.dir/uri.cpp.o -c E:/code/frontend2/source/Core/ThirdParty/uri/source/src/uri.cpp

Corresponding launcher setting code in CMake:

find_program( CCACHE ccache )
if( CCACHE AND NOT WIN32 )
    message( STATUS "Using ccache: ${CCACHE}" )
    set( ENV{CCACHE_BASEDIR} ${CMAKE_BINARY_DIR} )
    set( CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} )
    set( CMAKE_C_COMPILER_LAUNCHER ${CCACHE} )
endif()

The fix here is to use "REPORT" formatting for CMAKE_<LANG>_COMPILER when the variable is expanded, instead of "SHELL" (since the compiler is not being invoked in a shell context in this case).

I'm almost 100% sure you guys won't like my fix, because I did a straightforward change just to get it working. I verified that my code changes fix the problem, but I'm not sure what the real ideal fix would be. Looking for feedback.

Edited by Robert Dailey

Merge request reports