Skip to content

[BUG] CMake 3.21 + NDK r23 sets MINGW=1 in CMake #1581

Closed
@jheydebrand

Description

@jheydebrand

Description

Observed behaviour:
When using CMake 3.21 with NDK r23 the compiler detection performed by CMake identifies NDK's Clang toolchain as MINGW.
This causes failures during the subsequent build because MINGW=1 implies that the Windows platform is targeted which means
Windows specific files and libraries might be included into the build.

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.21.0)

project(NewAndroidCMakeRepro LANGUAGES C CXX)

if(DEFINED MINGW)
    message(STATUS "MINGW defined")
endif()
message(STATUS "MINGW=${MINGW}")
message(STATUS "CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")

# find_program(git git REQUIRED)


$ cat tc.txt
set(ANDROID_CPP_FEATURES rtti exceptions)
set(ANDROID_ABI arm64-v8a)
set(ANDROID_STL c++_shared)
set(ANDROID_NATIVE_API_LEVEL 27)

# Needed for find_program(git) because Android is the only CMake platform which explicitly sets this to OFF
# Only required when ANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH 1)

# Force compiler ID detection to build for the target instead of the host and thus avoid MINGW=1 on Windows host
# Mismatching these flags with ANDROID_NATIVE_API_LEVEL and ANDROID_ABI might be really bad...
#set(CMAKE_CXX_FLAGS "--target=armv7-none-linux-androideabi16")
#set(CMAKE_C_FLAGS "--target=armv7-none-linux-androideabi16")

# Legacy toolchain does not cause MINGW=1 even in the absence of the CMAKE_<LANG>_FLAGS from above
#set(ANDROID_USE_LEGACY_TOOLCHAIN_FILE 1)

include("/path/to/ndk/23.0.7599858/build/cmake/android.toolchain.cmake")


$ cmake.exe  -GNinja -DCMAKE_TOOLCHAIN_FILE=tc.txt -S . -B .
-- Android: Targeting API '27' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 12.0.5
-- The CXX compiler identification is Clang 12.0.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /path/to/ndk/23.0.7599858/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /path/to/ndk/23.0.7599858/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- MINGW defined
-- MINGW=1
-- CMAKE_SYSTEM_NAME=Android
-- Configuring done
-- Generating done
-- Build files have been written to: ./build

Expected behaviour:
The MINGW variable is not defined in CMake.

The expected behaviour can be restored either by setting ANDROID_USE_LEGACY_TOOLCHAIN_FILE=1 or by manipulating CMAKE_<LANG>_FLAGS in tc.txt.

Environment Details

  • cmake version 3.21.1; CMake suite maintained and supported by Kitware (kitware.com/cmake).
  • Windows 10 Host system (Build 19042.631)
  • NDK Version 23.0.7599858
  • ABI (arm64-v8a) and API level (27) do not seem to matter

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions