From 5d67732c43cacf69efe5264733332123f1f029b7 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 18 Mar 2022 20:04:45 +0100 Subject: [PATCH] (#9790) boost: compiler=msvc support + bump dependencies * bump dependencies * ConanInvalidCondifuration in validate() only * support compiler=msvc in profile * use conan.tools.files.rename --- recipes/boost/all/conanfile.py | 69 ++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/recipes/boost/all/conanfile.py b/recipes/boost/all/conanfile.py index a9481364f5fed..85c334ad9bdb8 100644 --- a/recipes/boost/all/conanfile.py +++ b/recipes/boost/all/conanfile.py @@ -1,6 +1,6 @@ -from conans import ConanFile -from conans import tools -from conans.tools import Version, cppstd_flag +from conan.tools.files import rename +from conan.tools.microsoft import msvc_runtime_flag +from conans import ConanFile, tools from conans.errors import ConanException, ConanInvalidConfiguration import glob @@ -221,7 +221,7 @@ def _bcp_dir(self): @property def _is_msvc(self): - return self.settings.compiler == "Visual Studio" + return str(self.settings.compiler) in ["Visual Studio", "msvc"] @property def _is_clang_cl(self): @@ -354,9 +354,6 @@ def configure(self): if self.options.without_locale: del self.options.i18n_backend_iconv del self.options.i18n_backend_icu - else: - if self.options.i18n_backend_iconv == "off" and not self.options.i18n_backend_icu and not self._is_windows_platform: - raise ConanInvalidConfiguration("Boost.Locale library needs either iconv or ICU library to be built on non windows platforms") if not self.options.without_python: if not self.options.python_version: @@ -365,10 +362,7 @@ def configure(self): else: del self.options.python_buildid - if self._stacktrace_addr2line_available: - if os.path.abspath(str(self.options.addr2line_location)) != str(self.options.addr2line_location): - raise ConanInvalidConfiguration("addr2line_location must be an absolute path to addr2line") - else: + if not self._stacktrace_addr2line_available: del self.options.addr2line_location if self.options.get_safe("without_stacktrace", True): @@ -390,9 +384,18 @@ def validate(self): if not self.options.get_safe("without_{}".format(lib)): raise ConanInvalidConfiguration("Boost '{}' library requires multi threading".format(lib)) - if self.settings.compiler == "Visual Studio" and self._shared: - if "MT" in str(self.settings.compiler.runtime): - raise ConanInvalidConfiguration("Boost can not be built as shared library with MT runtime.") + if self._is_msvc and self._shared and "MT" in msvc_runtime_flag(self): + raise ConanInvalidConfiguration("Boost can not be built as shared library with MT runtime.") + + if not self.options.without_locale and self.options.i18n_backend_iconv == "off" and \ + not self.options.i18n_backend_icu and not self._is_windows_platform: + raise ConanInvalidConfiguration( + "Boost.Locale library needs either iconv or ICU library to be built on non windows platforms" + ) + + if self._stacktrace_addr2line_available: + if os.path.abspath(str(self.options.addr2line_location)) != str(self.options.addr2line_location): + raise ConanInvalidConfiguration("addr2line_location must be an absolute path to addr2line") # Check, when a boost module is enabled, whether the boost modules it depends on are enabled as well. for mod_name, mod_deps in self._dependencies["dependencies"].items(): @@ -443,10 +446,6 @@ def validate(self): if tools.Version(self.settings.compiler.version) < min_compiler_version: raise ConanInvalidConfiguration("Boost.Math requires (boost:)cppstd>=11 (current one is lower)") - def build_requirements(self): - if not self.options.header_only: - self.build_requires("b2/4.7.1") - def _with_dependency(self, dependency): """ Return true when dependency is required according to the dependencies-x.y.z.yml file @@ -493,12 +492,12 @@ def requirements(self): if self._with_lzma: self.requires("xz_utils/5.2.5") if self._with_zstd: - self.requires("zstd/1.5.0") + self.requires("zstd/1.5.2") if self._with_stacktrace_backtrace: self.requires("libbacktrace/cci.20210118") if self._with_icu: - self.requires("icu/68.2") + self.requires("icu/70.1") if self._with_iconv: self.requires("libiconv/1.16") @@ -517,6 +516,10 @@ def package_id(self): else: self.info.options.python_version = self._python_version + def build_requirements(self): + if not self.options.header_only: + self.build_requires("b2/4.8.0") + def source(self): tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) @@ -978,8 +981,8 @@ def add_defines(library): add_defines("zstd") if self._is_msvc: - flags.append("runtime-link=%s" % ("static" if "MT" in str(self.settings.compiler.runtime) else "shared")) - flags.append("runtime-debugging=%s" % ("on" if "d" in str(self.settings.compiler.runtime) else "off")) + flags.append("runtime-link=%s" % ("static" if "MT" in msvc_runtime_flag(self) else "shared")) + flags.append("runtime-debugging=%s" % ("on" if "d" in msvc_runtime_flag(self) else "off")) # For details https://boostorg.github.io/build/manual/master/index.html flags.append("threading=%s" % ("single" if not self.options.multithreading else "multi" )) @@ -998,7 +1001,7 @@ def add_defines(library): flags.append("toolset=%s" % self._toolset) if self.settings.get_safe("compiler.cppstd"): - flags.append("cxxflags=%s" % cppstd_flag(self.settings)) + flags.append("cxxflags=%s" % tools.cppstd_flag(self.settings)) # LDFLAGS link_flags = [] @@ -1011,7 +1014,7 @@ def add_defines(library): if self.settings.build_type == "RelWithDebInfo": if self.settings.compiler == "gcc" or "clang" in str(self.settings.compiler): cxx_flags.append("-g") - elif self.settings.compiler == "Visual Studio": + elif self._is_msvc: cxx_flags.append("/Z7") @@ -1068,7 +1071,7 @@ def add_defines(library): flags.append("-sICU_PATH={}".format(self.deps_cpp_info["icu"].rootpath)) if not self.options["icu"].shared: # Using ICU_OPTS to pass ICU system libraries is not possible due to Boost.Regex disallowing it. - if self.settings.compiler == "Visual Studio": + if self._is_msvc: icu_ldflags = " ".join("{}.lib".format(l) for l in self.deps_cpp_info["icu"].system_libs) else: icu_ldflags = " ".join("-l{}".format(l) for l in self.deps_cpp_info["icu"].system_libs) @@ -1255,7 +1258,7 @@ def _toolset_version(self): @property def _toolset(self): if self._is_msvc: - return "clang-win" if self.settings.compiler.toolset == "ClangCL" else "msvc" + return "clang-win" if self.settings.compiler.get_safe("toolset") == "ClangCL" else "msvc" elif self.settings.os == "Windows" and self.settings.compiler == "clang": return "clang-win" elif self.settings.os == "Emscripten" and self.settings.compiler == "clang": @@ -1292,15 +1295,17 @@ def _toolset_tag(self): "apple-clang": "", "msvc": "vc", "Visual Studio": "vc", + "msvc": "vc", }.get(str(self.settings.compiler), str(self.settings.compiler)) if (self.settings.compiler, self.settings.os) == ("gcc", "Windows"): compiler = "mgw" os_ = "" if self.settings.os == "Macos": os_ = "darwin" - toolset_version = str(tools.Version(self.settings.compiler.version).major) - if str(self.settings.compiler) in ("msvc", "Visual Studio"): + if self._is_msvc: toolset_version = self._toolset_version.replace(".", "") + else: + toolset_version = str(tools.Version(self.settings.compiler.version).major) toolset_parts = [compiler, os_] toolset_tag = "-".join(part for part in toolset_parts if part) + toolset_version @@ -1336,7 +1341,7 @@ def package(self): if dll_pdbs: tools.mkdir(os.path.join(self.package_folder, "bin")) for bin_file in dll_pdbs: - tools.rename(bin_file, os.path.join(self.package_folder, "bin", os.path.basename(bin_file))) + rename(self, bin_file, os.path.join(self.package_folder, "bin", os.path.basename(bin_file))) tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb") @@ -1474,8 +1479,8 @@ def package_info(self): } if self._is_msvc: # FIXME: mingw? # FIXME: add 'y' when using cpython cci package and when python is built in debug mode - static_runtime_key = "s" if "MT" in str(self.settings.compiler.runtime) else "" - debug_runtime_key = "g" if "d" in str(self.settings.compiler.runtime) else "" + static_runtime_key = "s" if "MT" in msvc_runtime_flag(self) else "" + debug_runtime_key = "g" if "d" in msvc_runtime_flag(self) else "" debug_key = "d" if self.settings.build_type == "Debug" else "" abi = static_runtime_key + debug_runtime_key + debug_key if abi: @@ -1505,7 +1510,7 @@ def package_info(self): def add_libprefix(n): """ On MSVC, static libraries are built with a 'lib' prefix. Some libraries do not support shared, so are always built as a static library. """ libprefix = "" - if self.settings.compiler == "Visual Studio" and (not self._shared or n in self._dependencies["static_only"]): + if self._is_msvc and (not self._shared or n in self._dependencies["static_only"]): libprefix = "lib" return libprefix + n