def context(self): # build_type (Release, Debug, etc) is only defined for single-config generators generator = self._toolchain.generator generator_platform = self._get_generator_platform(generator) toolset = self._get_toolset(generator) compiler = self._conanfile.settings.get_safe("compiler") # TODO: Check if really necessary now that conanvcvars is used if (generator is not None and "Ninja" in generator and ("Visual" in compiler or compiler == "msvc")): compiler = "cl" else: compiler = None # compiler defined by default build_type = self._conanfile.settings.get_safe("build_type") build_type = build_type if not is_multi_configuration(generator) else None system_name, system_version, system_processor = self._get_cross_build() return {"compiler": compiler, "toolset": toolset, "generator_platform": generator_platform, "build_type": build_type, "cmake_system_name": system_name, "cmake_system_version": system_version, "cmake_system_processor": system_processor}
def context(self): # build_type (Release, Debug, etc) is only defined for single-config generators generator = self._toolchain.generator generator_platform = self._get_generator_platform(generator) toolset = self._get_toolset(generator) compiler, compiler_cpp, compiler_rc = self._get_compiler(generator) build_type = self._conanfile.settings.get_safe("build_type") build_type = build_type if not is_multi_configuration( generator) else None system_name, system_version, system_processor = self._get_cross_build() return { "compiler": compiler, "compiler_rc": compiler_rc, "compiler_cpp": compiler_cpp, "toolset": toolset, "generator_platform": generator_platform, "build_type": build_type, "cmake_system_name": system_name, "cmake_system_version": system_version, "cmake_system_processor": system_processor }
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 test(self, build_type=None, target=None, output_on_failure=False): if self._conanfile.conf["tools.build:skip_test"]: return if not target: is_multi = is_multi_configuration(self._generator) target = "RUN_TESTS" if is_multi else "test" self._build(build_type=build_type, target=target)
def _contents(conanfile, toolchain_file, cache_variables, generator): ret = {"version": 3, "cmakeMinimumRequired": {"major": 3, "minor": 15, "patch": 0}, "configurePresets": [], "buildPresets": [], "testPresets": [] } multiconfig = is_multi_configuration(generator) ret["buildPresets"].append(_add_build_preset(conanfile, multiconfig)) _conf = _add_configure_preset(conanfile, generator, cache_variables, toolchain_file, multiconfig) ret["configurePresets"].append(_conf) return ret
def test(self, build_type=None, target=None, output_on_failure=False): if not self._conanfile.should_test: return if not target: is_multi = is_multi_configuration(self._generator) target = "RUN_TESTS" if is_multi else "test" env = {'CTEST_OUTPUT_ON_FAILURE': '1' if output_on_failure else '0'} if self._parallel: env['CTEST_PARALLEL_LEVEL'] = str(cpu_count(self._conanfile.output)) with tools.environment_append(env): self._build(build_type=build_type, target=target)
def write_cmake_presets(conanfile, toolchain_file, generator): cache_variables = {} if platform.system() == "Windows" and generator == "MinGW Makefiles": cache_variables["CMAKE_SH"] = "CMAKE_SH-NOTFOUND" cmake_make_program = conanfile.conf.get("tools.gnu:make_program", default=None) if cmake_make_program: cmake_make_program = cmake_make_program.replace("\\", "/") cache_variables["CMAKE_MAKE_PROGRAM"] = cmake_make_program cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW" preset_path = os.path.join(conanfile.generators_folder, "CMakePresets.json") multiconfig = is_multi_configuration(generator) if os.path.exists(preset_path): # We append the new configuration making sure that we don't overwrite it data = json.loads(load(preset_path)) if multiconfig: new_build_preset_name = _build_preset_name(conanfile) already_exist = any([b["name"] for b in data["buildPresets"] if b["name"] == new_build_preset_name]) if not already_exist: data["buildPresets"].append(_add_build_preset(conanfile, multiconfig)) else: new_configure_preset_name = _configure_preset_name(conanfile, multiconfig) already_exist = any([c["name"] for c in data["configurePresets"] if c["name"] == new_configure_preset_name]) if not already_exist: conf_preset = _add_configure_preset(conanfile, generator, cache_variables, toolchain_file, multiconfig) data["configurePresets"].append(conf_preset) data["buildPresets"].append(_add_build_preset(conanfile, multiconfig)) else: data = _contents(conanfile, toolchain_file, cache_variables, generator) data = json.dumps(data, indent=4) save(preset_path, data) # Try to save the CMakeUserPresets.json if layout declared and CMakeLists.txt found if conanfile.source_folder and conanfile.source_folder != conanfile.generators_folder: if os.path.exists(os.path.join(conanfile.source_folder, "CMakeLists.txt")): user_presets_path = os.path.join(conanfile.source_folder, "CMakeUserPresets.json") if not os.path.exists(user_presets_path): data = {"version": 4, "include": [preset_path]} else: data = json.loads(load(user_presets_path)) # Clear the folders that have been deleted data["include"] = [i for i in data["include"] if os.path.exists(i)] if preset_path not in data["include"]: data["include"].append(preset_path) data = json.dumps(data, indent=4) save(user_presets_path, data)
def __init__(self, conanfile, generator=None, generator_platform=None, build_type=None, toolset=None, parallel=True): super(CMakeGenericToolchain, self).__init__(conanfile) self.fpic = self._deduce_fpic() self.vs_static_runtime = self._deduce_vs_static_runtime() self.parallel = parallel self.generator = generator or get_generator(self._conanfile) self.generator_platform = (generator_platform or get_generator_platform( self._conanfile.settings, self.generator)) self.toolset = toolset or get_toolset(self._conanfile.settings, self.generator) if (self.generator is not None and "Ninja" in self.generator and "Visual" in self._conanfile.settings.compiler): self.compiler = "cl" else: self.compiler = None # compiler defined by default try: self._build_shared_libs = "ON" if self._conanfile.options.shared else "OFF" except ConanException: self._build_shared_libs = None self.set_libcxx, self.glibcxx = self._get_libcxx() self.parallel = None if parallel: if self.generator and "Visual Studio" in self.generator: self.parallel = "/MP%s" % cpu_count( output=self._conanfile.output) self.cppstd, self.cppstd_extensions = self._cppstd() self.skip_rpath = True if self._conanfile.settings.get_safe( "os") == "Macos" else False self.architecture = self._get_architecture() # TODO: I would want to have here the path to the compiler too build_type = build_type or self._conanfile.settings.get_safe( "build_type") self.build_type = build_type if not is_multi_configuration( self.generator) else None
def test(self, build_type=None, target=None, cli_args=None, build_tool_args=None): if self._conanfile.conf.get("tools.build:skip_test", check_type=bool): return if not target: is_multi = is_multi_configuration(self._generator) target = "RUN_TESTS" if is_multi else "test" self._build(build_type=build_type, target=target, cli_args=cli_args, build_tool_args=build_tool_args)
def __init__(self, conanfile, generator=None, build_folder=None, parallel=True, msbuild_verbosity="minimal"): _validate_recipe(conanfile) # assert generator is None, "'generator' is handled by the toolchain" self._generator = generator or get_generator(conanfile) self._is_multiconfiguration = is_multi_configuration(self._generator) # Store a reference to useful data self._conanfile = conanfile self._parallel = parallel self._msbuild_verbosity = msbuild_verbosity self._build_folder = build_folder self._cmake_program = "cmake" # Path to CMake should be handled by environment
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 context(self): # build_type (Release, Debug, etc) is only defined for single-config generators generator = self._toolchain.generator generator_platform = self._get_generator_platform(generator) toolset = self._get_toolset(generator) # TODO: Check if really necessary now that conanvcvars is used if (generator is not None and "Ninja" in generator and "Visual" in self._conanfile.settings.compiler): compiler = "cl" else: compiler = None # compiler defined by default build_type = self._conanfile.settings.get_safe("build_type") build_type = build_type if not is_multi_configuration( generator) else None return { "compiler": compiler, "toolset": toolset, "generator_platform": generator_platform, "build_type": build_type }