Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert CMake default generator on Windows #4509

Merged
2 changes: 2 additions & 0 deletions conans/client/build/cmake.py
Expand Up @@ -45,6 +45,8 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True,
self._cmake_program = os.getenv("CONAN_CMAKE_PROGRAM") or cmake_program or "cmake"

self.generator = generator or get_generator(conanfile.settings)
if not self.generator:
self._conanfile.output.warn("CMake generator could not be deduced from settings")
self.parallel = parallel
# Initialize definitions (won't be updated if conanfile or any of these variables change)
builder = CMakeDefinitionsBuilder(self._conanfile,
Expand Down
5 changes: 4 additions & 1 deletion conans/client/build/cmake_flags.py
Expand Up @@ -36,7 +36,8 @@ def get_generator(settings):

if not compiler or not compiler_version or not arch:
if os_build == "Windows":
return "MinGW Makefiles"
logger.warning("CMake generator could not be deduced from settings")
return None
return "Unix Makefiles"

if compiler == "Visual Studio":
Expand Down Expand Up @@ -64,6 +65,8 @@ def get_generator(settings):


def is_multi_configuration(generator):
if not generator:
return False
return "Visual" in generator or "Xcode" in generator


Expand Down
38 changes: 38 additions & 0 deletions conans/test/functional/build_helpers/cmake_flags_test.py
@@ -1,10 +1,12 @@
import os
import platform
import unittest
from textwrap import dedent

from nose.plugins.attrib import attr
from parameterized.parameterized import parameterized

from conans import load
from conans.client.build.cmake import CMake
from conans.model.version import Version
from conans.test.utils.tools import TestClient
Expand Down Expand Up @@ -431,3 +433,39 @@ def build(self):
client.save({"CMakeLists.txt": tmp, "conanfile.py": conanfile}, clean_first=True)
client.run("create . user/channel -o MyLib:fPIC=True")
self.assertNotIn("Conan: Adjusting fPIC flag", client.out)

def header_only_generator_test(self):
""" Test cmake.install() is possible although Generetaor could not be deduced from
settings
"""
conanfile = dedent("""
from conans import ConanFile, CMake

class TestConan(ConanFile):
name = "kk"
version = "1.0"
exports = "*"

def package(self):
cmake = CMake(self)
self.output.info("Configure command: %s" % cmake.command_line)
cmake.configure()
cmake.install()
""")
cmakelists = dedent("""
cmake_minimum_required(VERSION 3.3)
project(test)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
""")
client = TestClient()
client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmakelists, "include/file.h": ""})
client.run("create . danimtb/testing")
if platform.system() == "Windows":
self.assertIn("WARN: CMake generator could not be deduced from settings", client.out)
self.assertIn('Configure command: -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="ON" '
'-DCMAKE_INSTALL_PREFIX=', client.out)
else:
self.assertIn('Configure command: -G "Unix Makefiles" -DCONAN_EXPORTED="1" '
'-DCONAN_IN_LOCAL_CACHE="ON" -DCMAKE_INSTALL_PREFIX=', client.out)
12 changes: 8 additions & 4 deletions conans/test/functional/generators/cmake_generator_test.py
Expand Up @@ -52,16 +52,20 @@ def _check_build_generator(self, os_build, generator):
client.run("install . -p my_profile")
client.run("build .")

self.assertIn('cmake -G "{}"'.format(generator), client.out)
self.assertTrue(os.path.isfile(os.path.join(client.current_folder, "Makefile")))
if generator:
self.assertIn('cmake -G "{}"'.format(generator), client.out)
self.assertTrue(os.path.isfile(os.path.join(client.current_folder, "Makefile")))
else:
self.assertNotIn("cmake -G", client.out)
self.assertFalse(os.path.isfile(os.path.join(client.current_folder, "Makefile")))

@unittest.skipUnless(tools.os_info.is_linux, "Compilation with real gcc needed")
def test_cmake_default_generator_linux(self):
self._check_build_generator("Linux", "Unix Makefiles")

@unittest.skipUnless(tools.os_info.is_windows, "MinGW is only supported on Windows")
@unittest.skipUnless(tools.os_info.is_windows, "Windows does not support default compiler")
def test_cmake_default_generator_windows(self):
self._check_build_generator("Windows", "MinGW Makefiles")
self._check_build_generator("Windows", None)

@unittest.skipUnless(tools.os_info.is_macos, "Compilation with real clang is needed")
def test_cmake_default_generator_osx(self):
Expand Down
15 changes: 13 additions & 2 deletions conans/test/unittests/client/build/cmake_test.py
Expand Up @@ -17,7 +17,7 @@
from conans.model.build_info import CppInfo, DepsCppInfo
from conans.model.ref import ConanFileReference
from conans.model.settings import Settings
from conans.test.utils.conanfile import ConanFileMock
from conans.test.utils.conanfile import ConanFileMock, MockSettings
from conans.test.utils.test_files import temp_folder
from conans.util.files import load, save

Expand Down Expand Up @@ -1037,7 +1037,7 @@ def instance_with_os_build(os_build):
self.assertEquals(cmake.generator, "Unix Makefiles")

cmake = instance_with_os_build("Windows")
self.assertEquals(cmake.generator, "MinGW Makefiles")
self.assertEquals(cmake.generator, None)

with tools.environment_append({"CONAN_CMAKE_GENERATOR": "MyCoolGenerator"}):
cmake = instance_with_os_build("Windows")
Expand Down Expand Up @@ -1231,3 +1231,14 @@ def test_ctest_variables(self):
self.assertEquals(conanfile.captured_env["CTEST_OUTPUT_ON_FAILURE"], "1")
self.assertEquals(conanfile.captured_env["CTEST_PARALLEL_LEVEL"], "666")

def test_unkown_generator_does_not_raise(self):
# https://github.com/conan-io/conan/issues/4265
settings = MockSettings({"os_build": "Windows", "compiler": "random",
"compiler.version": "15", "build_type": "Release"})
conanfile = ConanFileMock()
conanfile.settings = settings
cmake = CMake(conanfile)
self.assertIsNone(cmake.generator)
self.assertIn("WARN: CMake generator could not be deduced from settings", conanfile.output)
cmake.configure()
cmake.build()