def _write_config_toolchain(self, config_filename): def format_macro(key, value): return '%s=%s' % (key, value) if value is not None else key toolchain_file = 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> <ResourceCompile> <PreprocessorDefinitions> {};%(PreprocessorDefinitions) </PreprocessorDefinitions> </ResourceCompile> </ItemDefinitionGroup> <PropertyGroup Label="Configuration"> <PlatformToolset>{}</PlatformToolset> </PropertyGroup> </Project> """) preprocessor_definitions = ";".join([ format_macro(k, v) for k, v in self.preprocessor_definitions.items() ]) cppstd = "stdcpp%s" % self.cppstd if self.cppstd else "" runtime_library = self.runtime_library toolset = self.toolset compile_options = self._conanfile.conf.get( "tools.microsoft.msbuildtoolchain:compile_options", default={}, check_type=dict) self.compile_options.update(compile_options) parallel = "" njobs = build_jobs(self._conanfile) if njobs: parallel = "".join([ "\n <MultiProcessorCompilation>True</MultiProcessorCompilation>", "\n <ProcessorNumber>{}</ProcessorNumber>".format(njobs) ]) compile_options = "".join("\n <{k}>{v}</{k}>".format(k=k, v=v) for k, v in self.compile_options.items()) config_props = toolchain_file.format(preprocessor_definitions, runtime_library, cppstd, parallel, compile_options, preprocessor_definitions, toolset) config_filepath = os.path.join(self._conanfile.generators_folder, config_filename) self._conanfile.output.info("MSBuildToolchain created %s" % config_filename) save(config_filepath, config_props)
def build(self, target=None): cmd = 'meson compile -C "{}"'.format(self._build_dir) njobs = build_jobs(self._conanfile) if njobs: cmd += " -j{}".format(njobs) if target: cmd += " {}".format(target) self._conanfile.output.info("Meson build cmd: {}".format(cmd)) self._conanfile.run(cmd)
def context(self): # TODO: Check this conf compiler = self._conanfile.settings.get_safe("compiler") if compiler not in ("Visual Studio", "msvc") or "Visual" not in self._toolchain.generator: return jobs = build_jobs(self._conanfile) if jobs: return {"parallel": jobs}
def make(self, target=None): make_program = self._conanfile.conf.get( "tools.gnu:make_program", default="mingw32-make" if self._use_win_mingw() else "make") str_args = self._make_args jobs = "" if "-j" not in str_args and "nmake" not in make_program.lower(): njobs = build_jobs(self._conanfile) if njobs: jobs = "-j{}".format(njobs) command = join_arguments([make_program, target, str_args, jobs]) self._conanfile.run(command)
def _cmake_cmd_line_args(conanfile, generator): args = [] if not generator: return args # Arguments related to parallel njobs = build_jobs(conanfile) if njobs and ("Makefiles" in generator or "Ninja" in generator) and "NMake" not in generator: args.append("-j{}".format(njobs)) maxcpucount = conanfile.conf["tools.microsoft.msbuild:max_cpu_count"] if maxcpucount and "Visual Studio" in generator: args.append("/m:{}".format(njobs)) # Arguments for verbosity if "Visual Studio" in generator: verbosity = msbuild_verbosity_cmd_line_arg(conanfile) if verbosity: args.append(verbosity) return args
def context_config_toolchain(self): def format_macro(key, value): return '%s=%s' % (key, value) if value is not None else key cxxflags, cflags, defines, sharedlinkflags, exelinkflags = self._get_extra_flags() preprocessor_definitions = "".join(["%s;" % format_macro(k, v) for k, v in self.preprocessor_definitions.items()]) defines = preprocessor_definitions + "".join("%s;" % d for d in defines) self.cxxflags.extend(cxxflags) self.cflags.extend(cflags) self.ldflags.extend(sharedlinkflags + exelinkflags) cppstd = "stdcpp%s" % self.cppstd if self.cppstd else "" runtime_library = self.runtime_library toolset = self.toolset compile_options = self._conanfile.conf.get("tools.microsoft.msbuildtoolchain:compile_options", default={}, check_type=dict) self.compile_options.update(compile_options) parallel = "" njobs = build_jobs(self._conanfile) if njobs: parallel = "".join( ["\n <MultiProcessorCompilation>True</MultiProcessorCompilation>", "\n <ProcessorNumber>{}</ProcessorNumber>".format(njobs)]) compile_options = "".join("\n <{k}>{v}</{k}>".format(k=k, v=v) for k, v in self.compile_options.items()) return { 'defines': defines, 'compiler_flags': " ".join(self.cxxflags + self.cflags), 'linker_flags': " ".join(self.ldflags), "cppstd": cppstd, "runtime_library": runtime_library, "toolset": toolset, "compile_options": compile_options, "parallel": parallel }