Repository: conan-io/conan

Issue:
cmake compiler check do not recognize compiler in cross build (Windows to Android)
With Conan 1.0.4, trying to build bzip2 or zlib (In Windows) with the Android toolchain described in the docs and blogpost

**Profile:**

```config
standalone_toolchain=C:/ndk/arm_21_toolchain
target_host=arm-linux-androideabi
cc_compiler=clang
cxx_compiler=clang++

[settings]
compiler=clang
compiler.version=5.0
compiler.libcxx=libc++
os=Android
os.api_level=21
arch=armv7
build_type=Release

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/sysroot
CONAN_CMAKE_SYSTEM_NAME=False
CONAN_CMAKE_GENERATOR=Unix Makefiles
PATH=[$standalone_toolchain/bin]
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
LD=$target_host-ld
STRIP=$target_host-strip
CFLAGS= -fPIC -I$standalone_toolchain/include/c++/4.9.x
CXXFLAGS= -fPIC -I$standalone_toolchain/include/c++/4.9.x
LDFLAGS=`
```

It results in the following CMake trace:

```bash
cd . && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCONAN_EXPORTED="1" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="5.0" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="C:\Users\vagrant\.conan\data\bzip2\1.0.6\conan\stable\package\9b5efed8fbf1cba00152d97f255eab56c82b3ef9" -DFPIC="ON" -Wno-dev ..
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/ndk/arm_21_toolchain/bin/arm-linux-androideabi-clang
-- Check for working C compiler: C:/ndk/arm_21_toolchain/bin/arm-linux-androideabi-clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/ndk/arm_21_toolchain/bin/arm-linux-androideabi-clang++
-- Check for working CXX compiler: C:/ndk/arm_21_toolchain/bin/arm-linux-androideabi-clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Conan: called by CMake conan helper
CMake Error at C:/Users/vagrant/.conan/data/bzip2/1.0.6/conan/stable/build/9b5efed8fbf1cba00152d97f255eab56c82b3ef9/conanbuildinfo.cmake:398 (message):
  Incorrect 'clang', is not the one detected by CMake: ''

```
So, in the `conanbuldinfo.cmake` file we are checking the existence of the cmake detected compiler like this:

```cmake
if(NOT DEFINED CMAKE_CXX_COMPILER_ID)
        if(DEFINED CMAKE_C_COMPILER_ID)
            message(STATUS "This project seems to be plain C, using '${CMAKE_C_COMPILER_ID}' compiler")
            set(CMAKE_CXX_COMPILER_ID ${CMAKE_C_COMPILER_ID})
            set(CMAKE_CXX_COMPILER_VERSION ${CMAKE_C_COMPILER_VERSION})
        else()
            message(FATAL_ERROR "This project seems to be plain C, but no compiler defined")
        endif()
endif()
```

But surprisingly it is not entering in the FATAL_ERROR, if I patch the generator code introducing this:

```cmake
    if(NOT CMAKE_CXX_COMPILER_ID AND NOT CMAKE_C_COMPILER_ID)
        return()
    endif()
``` 

So, my thoughts are:

- Are we checking somewhere if the `if(NOT DEFINED CMAKE_CXX_COMPILER_ID)` is doing something?
- Should we provide an env_var/config to disable the checks globally from a profile?


Related to #2511



Discussion:

Resolving patch:
diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py
--- a/conans/client/generators/cmake_common.py
+++ b/conans/client/generators/cmake_common.py
@@ -379,7 +379,12 @@ def generate_targets_section(dependencies):
         message(STATUS "WARN: Disabled conan compiler checks")
         return()
     endif()
-
+    if(NOT CMAKE_CXX_COMPILER_ID AND NOT CMAKE_C_COMPILER_ID)
+        # This use case happens when compiler is not identified by CMake, but the compilers are there and work
+        message(STATUS "*** WARN: CMake was not able to identify a C or C++ compiler ***")
+        message(STATUS "*** WARN: Disabling compiler checks. Please make sure your settings match your environment ***")
+        return()
+    endif()
     if(NOT DEFINED CONAN_COMPILER)
         conan_get_compiler(CONAN_COMPILER CONAN_COMPILER_VERSION)
         if(NOT DEFINED CONAN_COMPILER)


Test patch: