• Michael Maltese's avatar
    Don't manually set CMAKE_C_COMPILER_ID in toolchain file · 15909f20
    Michael Maltese authored
    Bug: https://github.com/android-ndk/ndk/issues/222 : CMake toolchain
    file's `CMAKE_CXX_COMPILER_ID_RUN=true` breaks compiler feature
    detection
    Bug: https://github.com/android-ndk/ndk/issues/253 : cmake toolchain
    file does not set CMAKE_CXX_COMPILER_VERSION
    Bug: https://gitlab.kitware.com/cmake/cmake/issues/16587 : Adding
    "-march=" to flags breaks determining compiler ID when cross-compiling
    with Clang
    
    The current comment reads:
    
    > Clang can fail to compile if CMake doesn't correctly supply the target
    > and external toolchain, but to do so, CMake needs to already know
    > that the compiler is clang. Tell CMake that the compiler is really
    > clang, but don't use CMakeForceCompiler, since we still want
    > compile checks. We only want to skip the compiler ID detection
    > step.
    
    The issue arises in CMakeDetermineCompilerId.cmake, which passes along
    user-specified flags like `-march=armv5te` but not the specified
    compiler target. On Clang, this fails, since the validity of `-march`
    depends on the current target.
    
    I've filed a bug for CMake to fix this (allow determining the compiler
    ID without using user flags). In the meantime, I think a more robust
    solution than overriding CMAKE_CXX_COMPILER_ID_RUN is to run the
    compiler ID checks before passing along any flags. The
    CMakeDetermineCCompiler.cmake and CMakeDetermineCXXCompiler.cmake
    modules are not marked for internal-use-only, and this method takes a
    more proactive approach to the problem.
    
    Change-Id: I2c250ebc2999b3f251417a9e3730b5e093e446d1
    15909f20
android.toolchain.cmake 24.9 KB