def test_negative(self): self.assertIsNone( tools.msvs_toolset( MockSettings({ "compiler": "Visual Studio", "compiler.version": "666" })))
def test_custom(self, compiler_version, expected_toolset): settings = MockSettings({ "compiler": "Visual Studio", "compiler.version": compiler_version, "compiler.toolset": expected_toolset }) self.assertEqual(expected_toolset, tools.msvs_toolset(settings))
def __init__(self, settings): toolset = msvs_toolset(settings) if toolset is None: raise ConanException("Undefined Visual Studio version %s" % settings.get_safe("compiler.version")) self._props = [("Configuration", settings.build_type), ("Platform", {'x86': 'Win32', 'x86_64': 'x64'}.get(settings.get_safe("arch"))), ("PlatformToolset", toolset)]
def _name_condition(settings): toolset = msvs_toolset(settings) props = [("Configuration", settings.build_type), # FIXME: This probably requires mapping ARM architectures ("Platform", {'x86': 'Win32', 'x86_64': 'x64'}.get(settings.get_safe("arch"))), ("PlatformToolset", toolset)] name = "".join("_%s" % v for _, v in props) condition = " And ".join("'$(%s)' == '%s'" % (k, v) for k, v in props) return name.lower(), condition
def _write_config_toolchain(self, config_filename): def format_macro(k, value): return '%s="%s"' % (k, value) if value is not None else k runtime = self._conanfile.settings.get_safe("compiler.runtime") cppstd = self._conanfile.settings.get_safe("compiler.cppstd") toolset = msvs_toolset(self._conanfile.settings) runtime_library = { "MT": "MultiThreaded", "MTd": "MultiThreadedDebug", "MD": "MultiThreadedDLL", "MDd": "MultiThreadedDebugDLL" }.get(runtime, "") content = textwrap.dedent("""\ <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemDefinitionGroup> <ClCompile> <PreprocessorDefinitions> {};%(PreprocessorDefinitions) </PreprocessorDefinitions> <RuntimeLibrary>{}</RuntimeLibrary> <LanguageStandard>{}</LanguageStandard> </ClCompile> </ItemDefinitionGroup> <PropertyGroup Label="Configuration"> <PlatformToolset>{}</PlatformToolset> </PropertyGroup> </Project> """) preprocessor_definitions = ";".join([ format_macro(k, v) for k, v in self.preprocessor_definitions.items() ]) # It is useless to set PlatformToolset in the config file, because the conditional checks it cppstd = "stdcpp%s" % cppstd if cppstd else "" toolset = toolset or "" config_props = content.format(preprocessor_definitions, runtime_library, cppstd, toolset) config_filepath = os.path.abspath(config_filename) self._conanfile.output.info("MSBuildToolchain created %s" % config_filename) save(config_filepath, config_props)
def _library_name(self): libname = "jemalloc" if self.settings.compiler == "Visual Studio": if self.options.shared: if self.settings.build_type == "Debug": libname += "d" else: toolset = msvs_toolset(self.settings) toolset_number = "".join(c for c in toolset if c in string.digits) libname += "-vc{}-{}".format(toolset_number, self._msvc_build_type) else: if self.settings.os == "Windows": if not self.options.shared: libname += "_s" else: if not self.options.shared and self.options.fPIC: libname += "_pic" return libname
def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True, build_type=None, arch=None, parallel=True, toolset=None, platforms=None, use_env=False, properties=None, output_binary_log=None, verbosity=None): targets = targets or [] properties = properties or {} command = [] if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False): command.append('devenv "%s" /upgrade &&' % project_file) else: self._output.info("Skipped sln project upgrade") build_type = build_type or self._settings.get_safe("build_type") arch = arch or self._settings.get_safe("arch") toolset = toolset or tools.msvs_toolset(self._settings) verbosity = os.getenv("CONAN_MSBUILD_VERBOSITY") or verbosity or "minimal" if not build_type: raise ConanException("Cannot build_sln_command, build_type not defined") if not arch: raise ConanException("Cannot build_sln_command, arch not defined") command.append('msbuild "%s" /p:Configuration="%s"' % (project_file, build_type)) msvc_arch = {'x86': 'x86', 'x86_64': 'x64', 'armv7': 'ARM', 'armv8': 'ARM64'} if platforms: msvc_arch.update(platforms) msvc_arch = msvc_arch.get(str(arch)) try: sln = tools.load(project_file) pattern = re.compile(r"GlobalSection\(SolutionConfigurationPlatforms\)" r"(.*?)EndGlobalSection", re.DOTALL) solution_global = pattern.search(sln).group(1) lines = solution_global.splitlines() lines = [s.split("=")[0].strip() for s in lines] except Exception: pass # TODO: !!! what are we catching here? tools.load? .group(1)? .splitlines? else: config = "%s|%s" % (build_type, msvc_arch) if config not in "".join(lines): self._output.warn("***** The configuration %s does not exist in this solution *****" % config) self._output.warn("Use 'platforms' argument to define your architectures") if output_binary_log: msbuild_version = MSBuild.get_version(self._settings) if msbuild_version >= "15.3": # http://msbuildlog.com/ command.append('/bl' if isinstance(output_binary_log, bool) else '/bl:"%s"' % output_binary_log) else: raise ConanException("MSBuild version detected (%s) does not support " "'output_binary_log' ('/bl')" % msbuild_version) if use_env: command.append('/p:UseEnv=true') if msvc_arch: command.append('/p:Platform="%s"' % msvc_arch) if parallel: command.append('/m:%s' % cpu_count(output=self._output)) if targets: command.append("/target:%s" % ";".join(targets)) if toolset: command.append('/p:PlatformToolset="%s"' % toolset) if verbosity: command.append('/verbosity:%s' % verbosity) if props_file_path: command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path) for name, value in properties.items(): command.append('/p:%s="%s"' % (name, value)) return " ".join(command)