Skip to content

Commit

Permalink
- set the default CMake generator and toolset for Intel C++
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed May 7, 2020
1 parent d1869e1 commit cdc4bad
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion conans/client/build/cmake.py
Expand Up @@ -73,7 +73,7 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True,
self.definitions = builder.get_definitions()
self.definitions["CONAN_EXPORTED"] = "1"

self.toolset = toolset or get_toolset(self._settings)
self.toolset = toolset or get_toolset(self._settings, self.generator)
self.build_dir = None
self.msbuild_verbosity = os.getenv("CONAN_MSBUILD_VERBOSITY") or msbuild_verbosity

Expand Down
28 changes: 21 additions & 7 deletions conans/client/build/cmake_flags.py
Expand Up @@ -18,11 +18,19 @@
cmake_in_local_cache_var_name = "CONAN_IN_LOCAL_CACHE"


def get_toolset(settings):
if settings.get_safe("compiler") == "Visual Studio":
def get_toolset(settings, generator):
compiler = settings.get_safe("compiler")
compiler_base = settings.get_safe("compiler.base")
if compiler == "Visual Studio":
subs_toolset = settings.get_safe("compiler.toolset")
if subs_toolset:
return subs_toolset
elif compiler == "intel" and compiler_base == "Visual Studio" and "Visual" in generator:
compiler_version = settings.get_safe("compiler.version")
if compiler_version:
compiler_version = compiler_version if "." in compiler_version else \
"%s.0" % compiler_version
return "Intel C++ Compiler " + compiler_version
return None


Expand All @@ -32,8 +40,10 @@ def get_generator(conanfile):
return os.environ["CONAN_CMAKE_GENERATOR"]

compiler = conanfile.settings.get_safe("compiler")
compiler_base = conanfile.settings.get_safe("compiler.base")
arch = conanfile.settings.get_safe("arch")
compiler_version =conanfile. settings.get_safe("compiler.version")
compiler_version = conanfile.settings.get_safe("compiler.version")
compiler_base_version = conanfile.settings.get_safe("compiler.base.version")
os_build, _, _, _ = get_cross_building_settings(conanfile)

if not compiler or not compiler_version or not arch:
Expand All @@ -42,15 +52,16 @@ def get_generator(conanfile):
return None
return "Unix Makefiles"

if compiler == "Visual Studio":
if compiler == "Visual Studio" or compiler_base == "Visual Studio":
version = compiler_base_version or compiler_version
_visuals = {'8': '8 2005',
'9': '9 2008',
'10': '10 2010',
'11': '11 2012',
'12': '12 2013',
'14': '14 2015',
'15': '15 2017',
'16': '16 2019'}.get(compiler_version, "UnknownVersion %s" % compiler_version)
'16': '16 2019'}.get(version, "UnknownVersion %s" % version)
base = "Visual Studio %s" % _visuals
return base

Expand All @@ -67,12 +78,14 @@ def get_generator_platform(settings, generator):
return os.environ["CONAN_CMAKE_GENERATOR_PLATFORM"]

compiler = settings.get_safe("compiler")
compiler_base = settings.get_safe("compiler.base")
arch = settings.get_safe("arch")

if settings.get_safe("os") == "WindowsCE":
return settings.get_safe("os.platform")

if compiler == "Visual Studio" and generator and "Visual" in generator:
if (compiler == "Visual Studio" or compiler_base == "Visual Studio") and \
generator and "Visual" in generator:
return {"x86": "Win32",
"x86_64": "x64",
"armv7": "ARM",
Expand Down Expand Up @@ -268,6 +281,7 @@ def _get_make_program_definition(self):
def get_definitions(self):

compiler = self._ss("compiler")
compiler_base = self._ss("compiler.base")
compiler_version = self._ss("compiler.version")
arch = self._ss("arch")
os_ = self._ss("os")
Expand Down Expand Up @@ -295,7 +309,7 @@ def get_definitions(self):
definitions["CONAN_COMPILER_VERSION"] = str(compiler_version)

# C, CXX, LINK FLAGS
if compiler == "Visual Studio":
if compiler == "Visual Studio" or compiler_base == "Visual Studio":
if self._parallel:
flag = parallel_compiler_cl_flag(output=self._output)
definitions['CONAN_CXX_FLAGS'] = flag
Expand Down
34 changes: 34 additions & 0 deletions conans/test/unittests/client/build/cmake_test.py
Expand Up @@ -189,6 +189,40 @@ def cmake_generator_test(self):
cmake = CMake(conanfile)
self.assertIn('-G "My CMake Generator"', cmake.command_line)

def cmake_generator_intel_test(self):
settings = Settings.loads(get_default_settings_yml())
settings.os = "Windows"
settings.compiler = "intel"
settings.compiler.version = "19"
settings.compiler.base = "Visual Studio"
settings.compiler.base.version = "15"
settings.arch = "x86_64"

conanfile = ConanFileMock()
conanfile.settings = settings

cmake = CMake(conanfile)
self.assertIn('-G "Visual Studio 15 2017" -A "x64"', cmake.command_line)
self.assertIn('-T "Intel C++ Compiler 19.0', cmake.command_line)

def cmake_custom_generator_intel_test(self):
settings = Settings.loads(get_default_settings_yml())
settings.os = "Windows"
settings.compiler = "intel"
settings.compiler.version = "19"
settings.compiler.base = "Visual Studio"
settings.compiler.base.version = "15"
settings.arch = "x86_64"

conanfile = ConanFileMock()
conanfile.settings = settings

with tools.environment_append({"CONAN_CMAKE_GENERATOR": "My CMake Generator"}):
cmake = CMake(conanfile)
self.assertIn('-G "My CMake Generator"', cmake.command_line)
self.assertNotIn('-G "Visual Studio 15 2017" -A "x64"', cmake.command_line)
self.assertNotIn('-T "Intel C++ Compiler 19.0', cmake.command_line)

def cmake_generator_platform_test(self):
conanfile = ConanFileMock()
conanfile.settings = Settings()
Expand Down

0 comments on commit cdc4bad

Please sign in to comment.