def _build(self, args=None, build_dir=None, target=None): args = args or [] build_dir = build_dir or self.build_dir or self._conanfile.build_folder if target is not None: args = ["--target", target] + args compiler_version = self._settings.get_safe("compiler.version") if self.generator and self.parallel: if ("Makefiles" in self.generator or "Ninja" in self.generator) and \ "NMake" not in self.generator: if "--" not in args: args.append("--") args.append("-j%i" % cpu_count(self._conanfile.output)) elif "Visual Studio" in self.generator and \ compiler_version and Version(compiler_version) >= "10": if "--" not in args: args.append("--") # Parallel for building projects in the solution args.append("/m:%i" % cpu_count(output=self._conanfile.output)) if self.generator and self.msbuild_verbosity: if "Visual Studio" in self.generator and \ compiler_version and Version(compiler_version) >= "10": if "--" not in args: args.append("--") args.append("/verbosity:%s" % self.msbuild_verbosity) arg_list = join_arguments([ args_to_string([build_dir]), self.build_config, args_to_string(args) ]) command = "%s --build %s" % (self._cmake_program, arg_list) self._run(command)
def _build(self, build_type=None, target=None): bf = self._conanfile.build_folder if self._build_folder: bf = os.path.join(self._conanfile.build_folder, self._build_folder) if build_type and not self._is_multiconfiguration: self._conanfile.output.error("Don't specify 'build_type' at build time for " "single-config build systems") bt = build_type or self._conanfile.settings.get_safe("build_type") if not bt: conan_v2_behavior("build_type setting should be defined.", v1_behavior=self._conanfile.output.warn) if bt and self._is_multiconfiguration: build_config = "--config %s" % bt else: build_config = "" args = [] if target is not None: args = ["--target", target] build_flags = _compute_build_flags(self._conanfile, self._generator, self._parallel, self._msbuild_verbosity) if build_flags: args += ['--'] + build_flags arg_list = [args_to_string([bf]), build_config, args_to_string(args)] command = "%s --build %s" % (self._cmake_program, join_arguments(arg_list)) self._conanfile.output.info("CMake command: %s" % command) self._conanfile.run(command)
def _build(self, build_type=None, target=None): bf = self._conanfile.build_folder is_multi = is_multi_configuration(self._generator) if build_type and not is_multi: self._conanfile.output.error( "Don't specify 'build_type' at build time for " "single-config build systems") bt = build_type or self._conanfile.settings.get_safe("build_type") if not bt: raise ConanException("build_type setting should be defined.") build_config = "--config {}".format(bt) if bt and is_multi else "" args = [] if target is not None: args = ["--target", target] cmd_line_args = _cmake_cmd_line_args(self._conanfile, self._generator) if cmd_line_args: args += ['--'] + cmd_line_args arg_list = [args_to_string([bf]), build_config, args_to_string(args)] arg_list = " ".join(filter(None, arg_list)) command = "%s --build %s" % (self._cmake_program, arg_list) self._conanfile.output.info("CMake command: %s" % command) self._conanfile.run(command)
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None, pkg_config_paths=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder if not self._conanfile.should_configure: return args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) if pkg_config_paths: pkg_env = { "PKG_CONFIG_PATH": os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) } else: # If we are using pkg_config generator automate the pcs location, otherwise it could # read wrong files set_env = "pkg_config" in self._conanfile.generators \ and "PKG_CONFIG_PATH" not in os.environ pkg_env = { "PKG_CONFIG_PATH": self._conanfile.install_folder } if set_env else None with environment_append(pkg_env): command = "cd %s && %s %s" % (args_to_string( [self.build_dir]), self._cmake_program, arg_list) if platform.system( ) == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._run(command) else: self._run(command)
def _run_ninja_targets(self, args=None, build_dir=None, targets=None): if self.backend != "ninja": raise ConanException("Build only supported with 'ninja' backend") args = args or [] build_dir = build_dir or self.build_dir or self._conanfile.build_folder arg_list = join_arguments([ '-C "%s"' % build_dir, args_to_string(args), args_to_string(targets) ]) self._run("ninja %s" % arg_list)
def _run_meson_targets(self, args=None, build_dir=None, targets=None): args = args or [] build_dir = build_dir or self.build_dir or self._conanfile.build_folder arg_list = join_arguments([ '-C "%s"' % build_dir, args_to_string(args), args_to_string(targets) ]) # FIXME: We are assuming for other backends that meson version is > 0.55.0 # so you can use new command "meson compile" command = "ninja" if self.backend == "ninja" else "meson compile" self._run("%s %s" % (command, arg_list))
def configure(self, source_folder=None): # TODO: environment? if not self._conanfile.should_configure: return source = self._conanfile.source_folder if source_folder: source = os.path.join(self._conanfile.source_folder, source_folder) build_folder = self._conanfile.build_folder if self._build_folder: build_folder = os.path.join(self._conanfile.build_folder, self._build_folder) defs = {"CMAKE_TOOLCHAIN_FILE": CMakeToolchainBase.filename} mkdir(build_folder) arg_list = join_arguments([ defs_to_string(defs), args_to_string([source]) ]) generator = '-G "{}" '.format(self._generator) if self._generator else "" command = "%s %s%s" % (self._cmake_program, generator, arg_list) is_windows_mingw = platform.system() == "Windows" and self._generator == "MinGW Makefiles" self._conanfile.output.info("CMake command: %s" % command) with chdir(build_folder): if is_windows_mingw: with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def build(self, args=None, build_dir=None, targets=None): if not self._conanfile.should_build: return if self.backend != "ninja": raise ConanException("Build only supported with 'ninja' backend") args = args or [] build_dir = build_dir or self.build_dir or self._conanfile.build_folder arg_list = join_arguments([ '-C "%s"' % build_dir, args_to_string(args), args_to_string(targets) ]) command = "ninja %s" % arg_list command = self._append_vs_if_needed(command) self._conanfile.run(command)
def _run_meson_command(self, subcommand=None, args=None, build_dir=None): args = args or [] build_dir = build_dir or self.build_dir or self._conanfile.build_folder arg_list = join_arguments( [subcommand, '-C "%s"' % build_dir, args_to_string(args)]) self._run("meson %s" % arg_list)
def install(self, build_type=None): mkdir(self._conanfile, self._conanfile.package_folder) bt = build_type or self._conanfile.settings.get_safe("build_type") if not bt: raise ConanException("build_type setting should be defined.") is_multi = is_multi_configuration(self._generator) build_config = "--config {}".format(bt) if bt and is_multi else "" pkg_folder = args_to_string( [self._conanfile.package_folder.replace("\\", "/")]) build_folder = args_to_string([self._conanfile.build_folder]) arg_list = [ "--install", build_folder, build_config, "--prefix", pkg_folder ] arg_list = " ".join(filter(None, arg_list)) command = "%s %s" % (self._cmake_program, arg_list) self._conanfile.output.info("CMake command: %s" % command) self._conanfile.run(command)
def make(self, args="", make_program=None, target=None, vars=None): if not self._conanfile.should_build: return make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program or "make" with environment_append(vars or self.vars): str_args = args_to_string(args) cpu_count_option = (("-j%s" % cpu_count(output=self._conanfile.output)) if "-j" not in str_args else None) self._conanfile.run("%s" % join_arguments([make_program, target, str_args, cpu_count_option]), win_bash=self._win_bash, subsystem=self.subsystem)
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, pkg_config_paths=None, cache_build_folder=None, build_folder=None, source_folder=None): if not self._conanfile.should_configure: return args = args or [] defs = defs or {} # overwrite default values with user's inputs self.options.update(defs) source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) if pkg_config_paths: pc_paths = os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) else: pc_paths = self._conanfile.install_folder mkdir(self.build_dir) bt = { "RelWithDebInfo": "debugoptimized", "MinSizeRel": "release", "Debug": "debug", "Release": "release" }.get(str(self.build_type), "") build_type = "--buildtype=%s" % bt arg_list = join_arguments([ "--backend=%s" % self.backend, self.flags, args_to_string(args), build_type ]) command = 'meson "%s" "%s" %s' % (source_dir, self.build_dir, arg_list) command = self._append_vs_if_needed(command) with tools.environment_append({"PKG_CONFIG_PATH": pc_paths}): self._conanfile.run(command)
def configure(self, configure_dir=None, args=None, build=None, host=None, target=None, pkg_config_paths=None, vars=None, use_default_install_dirs=True): """ :param pkg_config_paths: Optional paths to locate the *.pc files :param configure_dir: Absolute or relative path to the configure script :param args: Optional arguments to pass to configure. :param build: In which system the program will be built. "False" skips the --build flag :param host: In which system the generated program will run. "False" skips the --host flag :param target: This option is only used to build a cross-compiling toolchain. "False" skips the --target flag When the tool chain generates executable program, in which target system the program will run. http://jingfenghanmax.blogspot.com.es/2010/09/configure-with-host-target-and-build.html https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html :param use_default_install_dirs: Use or not the defaulted installation dirs """ if not self._conanfile.should_configure: return if configure_dir: configure_dir = configure_dir.rstrip("/") else: configure_dir = "." triplet_args = [] if build is not False: # Skipped by user if build or self.build: # User specified value or automatic triplet_args.append("--build=%s" % (build or self.build)) if host is not False: # Skipped by user if host or self.host: # User specified value or automatic triplet_args.append("--host=%s" % (host or self.host)) if target is not False: # Skipped by user if target or self.target: # User specified value or automatic triplet_args.append("--target=%s" % (target or self.target)) if pkg_config_paths: pkg_env = { "PKG_CONFIG_PATH": [ os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) ] } else: # If we are using pkg_config generator automate the pcs location, otherwise it could # read wrong files pkg_env = {"PKG_CONFIG_PATH": [self._conanfile.install_folder]} \ if "pkg_config" in self._conanfile.generators else {} configure_dir = self._adjust_path(configure_dir) if self._conanfile.package_folder is not None: if not args: args = [ "--prefix=%s" % self._conanfile.package_folder.replace("\\", "/") ] elif not self._is_flag_in_args("prefix", args): args.append("--prefix=%s" % self._conanfile.package_folder.replace("\\", "/")) all_flags = [ "bindir", "sbindir", "libexecdir", "libdir", "includedir", "oldincludedir", "datarootdir" ] help_output = self._configure_help_output(configure_dir) available_flags = [ flag for flag in all_flags if "--%s" % flag in help_output ] if use_default_install_dirs: for varname in ["bindir", "sbindir", "libexecdir"]: if self._valid_configure_flag(varname, args, available_flags): args.append("--%s=${prefix}/%s" % (varname, DEFAULT_BIN)) if self._valid_configure_flag("libdir", args, available_flags): args.append("--libdir=${prefix}/%s" % DEFAULT_LIB) for varname in ["includedir", "oldincludedir"]: if self._valid_configure_flag(varname, args, available_flags): args.append("--%s=${prefix}/%s" % (varname, DEFAULT_INCLUDE)) if self._valid_configure_flag("datarootdir", args, available_flags): args.append("--datarootdir=${prefix}/%s" % DEFAULT_SHARE) with environment_append(pkg_env): with environment_append(vars or self.vars): command = '%s/configure %s %s' % (configure_dir, args_to_string(args), " ".join(triplet_args)) self._conanfile.output.info("Calling:\n > %s" % command) self._conanfile.run(command, win_bash=self._win_bash, subsystem=self.subsystem)