From 7f09cb9e3615ef6918568a9dead1d851ef7b9d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20Miks=CC=8Ca?= Date: Wed, 24 Apr 2019 19:44:57 +0200 Subject: [PATCH 1/3] when determining whether generator contains platform, use information about generator, as well as information about compiler --- conans/client/build/cmake.py | 2 +- conans/client/build/cmake_flags.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 8cc518673c7..0c2b2b47884 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -50,7 +50,7 @@ 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) - self.generator_platform = generator_platform or get_generator_platform(conanfile.settings) + self.generator_platform = generator_platform or get_generator_platform(conanfile.settings, self.generator) if not self.generator: self._conanfile.output.warn("CMake generator could not be deduced from settings") self.parallel = parallel diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py index a83668c629b..8da8c318da2 100644 --- a/conans/client/build/cmake_flags.py +++ b/conans/client/build/cmake_flags.py @@ -66,7 +66,7 @@ def get_generator(settings): return "Unix Makefiles" -def get_generator_platform(settings): +def get_generator_platform(settings, generator: str): if "CONAN_CMAKE_GENERATOR_PLATFORM" in os.environ: return os.environ["CONAN_CMAKE_GENERATOR_PLATFORM"] @@ -74,7 +74,7 @@ def get_generator_platform(settings): arch = settings.get_safe("arch") compiler_version = settings.get_safe("compiler.version") - if compiler == "Visual Studio" and Version(compiler_version) >= "16": + if compiler == "Visual Studio" and Version(compiler_version) >= "16" and generator.find('Visual Studio') != -1: return {"x86": "Win32", "x86_64": "x64", "armv7": "ARM", From f4000338b8cc387e9757d2c4665a175093d0642f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20Miks=CC=8Ca?= Date: Wed, 24 Apr 2019 19:53:13 +0200 Subject: [PATCH 2/3] python2 compatibility --- conans/client/build/cmake_flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py index 8da8c318da2..dac50061373 100644 --- a/conans/client/build/cmake_flags.py +++ b/conans/client/build/cmake_flags.py @@ -66,7 +66,7 @@ def get_generator(settings): return "Unix Makefiles" -def get_generator_platform(settings, generator: str): +def get_generator_platform(settings, generator): if "CONAN_CMAKE_GENERATOR_PLATFORM" in os.environ: return os.environ["CONAN_CMAKE_GENERATOR_PLATFORM"] From b9c67a0035f3485729b2bc6de4105a171fb060c7 Mon Sep 17 00:00:00 2001 From: Luis Martinez de Bartolome Date: Thu, 25 Apr 2019 09:41:55 +0200 Subject: [PATCH 3/3] Added test and pep8 --- conans/client/build/cmake.py | 3 ++- conans/client/build/cmake_flags.py | 3 ++- .../test/unittests/client/build/cmake_test.py | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 0c2b2b47884..d11e398f32d 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -50,7 +50,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) - self.generator_platform = generator_platform or get_generator_platform(conanfile.settings, self.generator) + self.generator_platform = generator_platform or get_generator_platform(conanfile.settings, + self.generator) if not self.generator: self._conanfile.output.warn("CMake generator could not be deduced from settings") self.parallel = parallel diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py index dac50061373..ca51ca5add4 100644 --- a/conans/client/build/cmake_flags.py +++ b/conans/client/build/cmake_flags.py @@ -74,7 +74,8 @@ def get_generator_platform(settings, generator): arch = settings.get_safe("arch") compiler_version = settings.get_safe("compiler.version") - if compiler == "Visual Studio" and Version(compiler_version) >= "16" and generator.find('Visual Studio') != -1: + if compiler == "Visual Studio" and Version(compiler_version) >= "16" \ + and "Visual" in generator: return {"x86": "Win32", "x86_64": "x64", "armv7": "ARM", diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py index b4da96c1381..aad5b683355 100644 --- a/conans/test/unittests/client/build/cmake_test.py +++ b/conans/test/unittests/client/build/cmake_test.py @@ -249,7 +249,7 @@ def cmake_generator_platform_vs2017_test(self, arch, generator): ('x86_64', 'x64'), ('armv7', 'ARM'), ('armv8', 'ARM64')]) - def cmake_generator_platform_vs2019_test(self, arch, platform): + def cmake_generator_platform_vs2019_test(self, arch, pf): settings = Settings.loads(default_settings_yml) settings.os = "Windows" settings.compiler = "Visual Studio" @@ -260,7 +260,21 @@ def cmake_generator_platform_vs2019_test(self, arch, platform): conan_file.settings = settings cmake = CMake(conan_file) - self.assertIn('-G "Visual Studio 16 2019" -A "%s"' % platform, cmake.command_line) + self.assertIn('-G "Visual Studio 16 2019" -A "%s"' % pf, cmake.command_line) + + def cmake_generator_platform_vs2019_with_ninja_test(self): + settings = Settings.loads(default_settings_yml) + settings.os = "Windows" + settings.compiler = "Visual Studio" + settings.compiler.version = "16" + settings.arch = "x86_64" + + conan_file = ConanFileMock() + conan_file.settings = settings + + cmake = CMake(conan_file, generator="Ninja") + self.assertIn('-G "Ninja"', cmake.command_line) + self.assertNotIn("-A", cmake.command_line) @parameterized.expand([('arm',), ('ppc',),