Repository: conan-io/conan

Issue:
Disable conan checking compiler comes after compiler if statement in conanbuildinfo
In the conanbuildinfo.cmake file created in the build folder, the function `conan_check_compiler` the check for `CONAN_DISABLE_CHECK_COMPILER `comes after a check for `if(NOT DEFINED CMAKE_CXX_COMPILER_ID)` as shown in this extract:
``` cmake
function(conan_check_compiler)
    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()
    if(CONAN_DISABLE_CHECK_COMPILER)
        message(STATUS "WARN: Disabled conan compiler checks")
        return()
    endif()
    ...
```

In CMake setting `project(myproj LANGUAGE NONE)` results in this evaluating to FATAL_ERROR regardless if `CONAN_DISABLE_CHECK_COMPILER` is defined or not.

Is there something I'm overlooking or is it a bug?


Discussion:
The idea was that the compiler should be there, and CMake should have either a CXX or a C compiler to build the project.

But yes, I think that the disabling of the check should have higher priority, and it shouldn't fail for those scenarios that the project language is not defined, lets try to change it.

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
@@ -397,6 +397,10 @@ def generate_targets_section(dependencies):
 endfunction()
 
 function(conan_check_compiler)
+    if(CONAN_DISABLE_CHECK_COMPILER)
+        conan_message(STATUS "WARN: Disabled conan compiler checks")
+        return()
+    endif()
     if(NOT DEFINED CMAKE_CXX_COMPILER_ID)
         if(DEFINED CMAKE_C_COMPILER_ID)
             conan_message(STATUS "This project seems to be plain C, using '${CMAKE_C_COMPILER_ID}' compiler")
@@ -406,10 +410,6 @@ def generate_targets_section(dependencies):
             message(FATAL_ERROR "This project seems to be plain C, but no compiler defined")
         endif()
     endif()
-    if(CONAN_DISABLE_CHECK_COMPILER)
-        conan_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
         conan_message(STATUS "*** WARN: CMake was not able to identify a C or C++ compiler ***")


Test patch:
diff --git a/conans/test/functional/generators/cmake_test.py b/conans/test/functional/generators/cmake_test.py
--- a/conans/test/functional/generators/cmake_test.py
+++ b/conans/test/functional/generators/cmake_test.py
@@ -9,6 +9,32 @@
 
 class CMakeGeneratorTest(unittest.TestCase):
 
+    def test_no_check_compiler(self):
+        # https://github.com/conan-io/conan/issues/4268
+        file_content = '''from conans import ConanFile, CMake
+
+class ConanFileToolsTest(ConanFile):
+    generators = "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+    '''
+
+        cmakelists = '''cmake_minimum_required(VERSION 2.8)
+PROJECT(conanzlib LANGUAGES NONE)
+set(CONAN_DISABLE_CHECK_COMPILER TRUE)
+
+include(conanbuildinfo.cmake)
+CONAN_BASIC_SETUP()
+'''
+        client = TestClient()
+        client.save({"conanfile.py": file_content,
+                     "CMakeLists.txt": cmakelists})
+
+        client.run('install .')
+        client.run('build .')
+
     @attr('slow')
     def no_output_test(self):
         client = TestClient()
diff --git a/conans/test/functional/old/libcxx_setting_test.py b/conans/test/functional/old/libcxx_setting_test.py
--- a/conans/test/functional/old/libcxx_setting_test.py
+++ b/conans/test/functional/old/libcxx_setting_test.py
@@ -39,15 +39,9 @@ def package(self):
 '''
 
 
-def nowintest(func):
-    if platform.system() == "Windows":
-        func.__test__ = False
-    return func
-
-
 class LibcxxSettingTest(unittest.TestCase):
 
-    @nowintest
+    @unittest.skipIf(platform.system() == "Windows", "Not in Windows")
     def test_declared_stdlib_and_passed(self):
         client = TestClient()
         client.save({"conanfile.py": file_content,