def generate(self): td = AutotoolsDeps(self) # remove non-existing frameworks dirs, otherwise clang complains for m in re.finditer("-F (\S+)", td.vars().get("LDFLAGS")): if not os.path.exists(m[1]): td.environment.remove("LDFLAGS", f"-F {m[1]}") if self.settings.os == "Windows": if self._is_msvc: td.environment.append("LIBS", [f"{lib}.lib" for lib in self._windows_system_libs]) else: td.environment.append("LDFLAGS", [f"-l{lib}" for lib in self._windows_system_libs]) td.generate() tc = AutotoolsToolchain(self) tc.default_configure_install_args = True tc.configure_args = ["--disable-install-doc"] if self.options.shared and not self._is_msvc: tc.configure_args.append("--enable-shared") tc.fpic = True if cross_building(self) and is_apple_os(self.settings.os): apple_arch = to_apple_arch(self.settings.arch) if apple_arch: tc.configure_args.append(f"--with-arch={apple_arch}") if self._is_msvc: # this is marked as TODO in https://github.com/conan-io/conan/blob/01f4aecbfe1a49f71f00af8f1b96b9f0174c3aad/conan/tools/gnu/autotoolstoolchain.py#L23 tc.build_type_flags.append(f"-{msvc_runtime_flag(self)}") # https://github.com/conan-io/conan/issues/10338 # remove after conan 1.45 if self.settings.build_type in ["Debug", "RelWithDebInfo"]: tc.ldflags.append("-debug") tc.build_type_flags = [f if f != "-O2" else self._msvc_optflag for f in tc.build_type_flags] tc.generate()
def test_framework_flags_only_for_apple_os(os_): """ Testing GnuDepsFlags attributes exclusively for Apple OS, frameworks and framework_paths """ # Issue: https://github.com/conan-io/conan/issues/10651 # Issue: https://github.com/conan-io/conan/issues/10640 settings = MockSettings({ "build_type": "Release", "compiler": "gcc", "compiler.version": "10.2", "os": os_, "arch": "x86_64" }) conanfile = ConanFileMock() conanfile.settings = settings cpp_info = MagicMock() cpp_info.frameworks = ["Foundation"] cpp_info.frameworkdirs = ["Framework"] gnudepsflags = GnuDepsFlags(conanfile, cpp_info) expected_framework = [] expected_framework_path = [] if is_apple_os(os_): expected_framework = ["-framework Foundation"] expected_framework_path = ["-F Framework"] assert gnudepsflags.frameworks == expected_framework assert gnudepsflags.framework_paths == expected_framework_path
def context(self): # To find the generated cmake_find_package finders # TODO: Change this for parameterized output location of CMakeDeps find_package_prefer_config = "ON" # assume ON by default if not specified in conf prefer_config = self._conanfile.conf[ "tools.cmake.cmaketoolchain:find_package_prefer_config"] if prefer_config is not None and prefer_config.lower() in ("false", "0", "off"): find_package_prefer_config = "OFF" os_ = self._conanfile.settings.get_safe("os") is_apple_ = is_apple_os(os_) # Read information from host context host_req = self._conanfile.dependencies.host.values() host_build_paths_root = [] host_build_paths_noroot = [] host_lib_paths = [] host_framework_paths = [] host_include_paths = [] for req in host_req: cppinfo = req.cpp_info.aggregated_components() # If the builddir is the package_folder, then it is the default "root" one nf = os.path.normpath(req.package_folder) host_build_paths_root.extend(p for p in cppinfo.builddirs if os.path.normpath(p) == nf) host_build_paths_noroot.extend(p for p in cppinfo.builddirs if os.path.normpath(p) != nf) host_lib_paths.extend(cppinfo.libdirs) if is_apple_: host_framework_paths.extend(cppinfo.frameworkdirs) host_include_paths.extend(cppinfo.includedirs) # Read information from build context build_req = self._conanfile.dependencies.build.values() build_build_paths = [] build_bin_paths = [] for req in build_req: cppinfo = req.cpp_info.aggregated_components() build_build_paths.extend(cppinfo.builddirs) build_bin_paths.extend(cppinfo.bindirs) return { "find_package_prefer_config": find_package_prefer_config, "generators_folder": "${CMAKE_CURRENT_LIST_DIR}", "host_build_paths_root": self._join_paths(host_build_paths_root), "host_build_paths_noroot": self._join_paths(host_build_paths_noroot), "build_build_paths": self._join_paths(build_build_paths), "cmake_program_path": self._join_paths(build_bin_paths), "cmake_library_path": self._join_paths(host_lib_paths), "cmake_framework_path": self._join_paths(host_framework_paths), "cmake_include_path": self._join_paths(host_include_paths), "is_apple": is_apple_, "cross_building": cross_building(self._conanfile), }
def _format_frameworks(self, frameworks, is_path=False): """ returns an appropriate compiler flags to link with Apple Frameworks or an empty array, if Apple Frameworks aren't supported by the given compiler """ os_ = self._conanfile.settings.get_safe("os") if not frameworks or not is_apple_os(os_): return [] # FIXME: Missing support for subsystems compiler = self._conanfile.settings.get_safe("compiler") if str(compiler) not in self._GCC_LIKE: return [] if is_path: return ["-F %s" % self._adjust_path(framework_path) for framework_path in frameworks] else: return ["-framework %s" % framework for framework in frameworks]
def _add_apple_flags(self): conanfile = self._conanfile os_ = conanfile.settings.get_safe("os") if not is_apple_os(os_): return # SDK path is mandatory for cross-building sdk_path = conanfile.conf.get("tools.apple:sdk_path") if not sdk_path and self.cross_build: raise ConanException( "You must provide a valid SDK path for cross-compilation.") # TODO: Delete this os_sdk check whenever the _guess_apple_sdk_name() function disappears os_sdk = conanfile.settings.get_safe('os.sdk') if not os_sdk and os_ != "Macos": raise ConanException( "Please, specify a suitable value for os.sdk.") arch = to_apple_arch(conanfile.settings.get_safe("arch")) # Calculating the main Apple flags deployment_target_flag = apple_min_version_flag(conanfile) sysroot_flag = "-isysroot " + sdk_path if sdk_path else "" arch_flag = "-arch " + arch if arch else "" apple_flags = {} if deployment_target_flag: flag_ = deployment_target_flag.split("=")[0] apple_flags[flag_] = deployment_target_flag if sysroot_flag: apple_flags["-isysroot"] = sysroot_flag if arch_flag: apple_flags["-arch"] = arch_flag for flag, arg_value in apple_flags.items(): v = " " + arg_value if flag not in self.c_args: self.c_args += v if flag not in self.c_link_args: self.c_link_args += v if flag not in self.cpp_args: self.cpp_args += v if flag not in self.cpp_link_args: self.cpp_link_args += v
def _resolve_apple_flags(self): if not is_apple_os(self._os): return # SDK path is mandatory for cross-building sdk_path = self._conanfile.conf.get("tools.apple:sdk_path") if not sdk_path and self.cross_build: raise ConanException( "You must provide a valid SDK path for cross-compilation.") # TODO: Delete this os_sdk check whenever the _guess_apple_sdk_name() function disappears os_sdk = self._conanfile.settings.get_safe('os.sdk') if not os_sdk and self._os != "Macos": raise ConanException( "Please, specify a suitable value for os.sdk.") # Calculating the main Apple flags arch = to_apple_arch(self._conanfile.settings.get_safe("arch")) self.apple_arch_flag = ["-arch", arch] if arch else [] self.apple_isysroot_flag = ["-isysroot", sdk_path] if sdk_path else [] self.apple_min_version_flag = [apple_min_version_flag(self._conanfile)]
def context(self): os_ = self._conanfile.settings.get_safe("os") if not is_apple_os(os_): return None arch = self._conanfile.settings.get_safe("arch") host_architecture = to_apple_arch(arch) host_os_version = self._conanfile.settings.get_safe("os.version") host_sdk_name = self._apple_sdk_name() is_debug = self._conanfile.settings.get_safe('build_type') == "Debug" # Reading some configurations to enable or disable some Xcode toolchain flags and variables # Issue related: https://github.com/conan-io/conan/issues/9448 # Based on https://github.com/leetal/ios-cmake repository enable_bitcode = self._conanfile.conf.get("tools.apple:enable_bitcode", check_type=bool) enable_arc = self._conanfile.conf.get("tools.apple:enable_arc", check_type=bool) enable_visibility = self._conanfile.conf.get( "tools.apple:enable_visibility", check_type=bool) ctxt_toolchain = { "enable_bitcode": enable_bitcode, "enable_bitcode_marker": all([enable_bitcode, is_debug]), "enable_arc": enable_arc, "enable_visibility": enable_visibility } if host_sdk_name: ctxt_toolchain["cmake_osx_sysroot"] = host_sdk_name # this is used to initialize the OSX_ARCHITECTURES property on each target as it is created if host_architecture: ctxt_toolchain["cmake_osx_architectures"] = host_architecture if host_os_version: # https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html # Despite the OSX part in the variable name(s) they apply also to other SDKs than # macOS like iOS, tvOS, or watchOS. ctxt_toolchain["cmake_osx_deployment_target"] = host_os_version return ctxt_toolchain
def _configure_cmake(self): if not self._cmake: self._cmake = CMake(self) self._cmake.definitions["DBUS_BUILD_TESTS"] = False self._cmake.definitions["DBUS_ENABLE_DOXYGEN_DOCS"] = False self._cmake.definitions["DBUS_ENABLE_XML_DOCS"] = False self._cmake.definitions["DBUS_BUILD_X11"] = self.options.get_safe( "with_x11", False) self._cmake.definitions["DBUS_WITH_GLIB"] = self.options.with_glib self._cmake.definitions["DBUS_DISABLE_ASSERT"] = is_apple_os( self.settings.os) self._cmake.definitions["DBUS_DISABLE_CHECKS"] = False # Conan does not provide an EXPAT_LIBRARIES CMake variable for the Expat library. # Define EXPAT_LIBRARIES to be the expat::expat target provided by Conan to fix linking. self._cmake.definitions["EXPAT_LIBRARIES"] = "expat::expat" self._cmake.configure(source_folder=self._source_subfolder, build_folder=self._build_subfolder) return self._cmake
def requirements(self): private = self.options.tankerlib_shared self.requires("boost/1.78.0-r4", private=private) self.requires("libressl/3.2.5", private=private) self.requires("libcurl/7.80.0-r1", private=private) if self.options.with_sqlite: self.requires("sqlpp11/0.60-r2", private=private) self.requires("sqlpp11-connector-sqlite3/0.30-r2", private=private) self.requires("mgs/0.2.1", private=private) self.requires("enum-flags/0.1a", private=private) self.requires("range-v3/0.11.0-r3", private=private) self.requires("fmt/7.1.3-r1", private=private) self.requires("gsl-lite/0.37.0", private=private) self.requires("nlohmann_json/3.10.5", private=private) self.requires("libsodium/1.0.18", private=private) self.requires("tconcurrent/0.40.0-r1", private=private) self.requires("date/3.0.0-r1", private=private) # catch2 is needed to export datastore tests self.requires("catch2/2.13.6-r1", private=private) if is_apple_os(self.settings.os): self.requires("libcxx/11.1.0-r1", private=private) if self.settings.os == "Android": self.requires("android_ndk_installer/r22b", private=private)
def __init__(self, conanfile, backend=None): self._conanfile = conanfile self._os = self._conanfile.settings.get_safe("os") # Values are kept as Python built-ins so users can modify them more easily, and they are # only converted to Meson file syntax for rendering # priority: first user conf, then recipe, last one is default "ninja" self._backend = conanfile.conf.get( "tools.meson.mesontoolchain:backend", default=backend or 'ninja') build_type = self._conanfile.settings.get_safe("build_type") self._buildtype = { "Debug": "debug", # Note, it is not "'debug'" "Release": "release", "MinSizeRel": "minsize", "RelWithDebInfo": "debugoptimized" }.get(build_type, build_type) self._b_ndebug = "true" if self._buildtype != "debug" else "false" # https://mesonbuild.com/Builtin-options.html#base-options fpic = self._conanfile.options.get_safe("fPIC") shared = self._conanfile.options.get_safe("shared") self._b_staticpic = fpic if (shared is False and fpic is not None) else None # https://mesonbuild.com/Builtin-options.html#core-options # Do not adjust "debug" if already adjusted "buildtype" self._default_library = ( "shared" if shared else "static") if shared is not None else None compiler = self._conanfile.settings.get_safe("compiler") cppstd = self._conanfile.settings.get_safe("compiler.cppstd") self._cpp_std = to_cppstd_flag(compiler, cppstd) if compiler == "Visual Studio": vscrt = self._conanfile.settings.get_safe("compiler.runtime") self._b_vscrt = str(vscrt).lower() elif compiler == "msvc": vscrt = msvc_runtime_flag(self._conanfile) self._b_vscrt = str(vscrt).lower() else: self._b_vscrt = None self.properties = {} self.project_options = { "wrap_mode": "nofallback" # https://github.com/conan-io/conan/issues/10671 } self.preprocessor_definitions = {} self.pkg_config_path = self._conanfile.generators_folder check_using_build_profile(self._conanfile) self.cross_build = {} default_comp = "" default_comp_cpp = "" if cross_building(conanfile, skip_x64_x86=True): os_build, arch_build, os_host, arch_host = get_cross_building_settings( self._conanfile) self.cross_build["build"] = to_meson_machine(os_build, arch_build) self.cross_build["host"] = to_meson_machine(os_host, arch_host) self.properties["needs_exe_wrapper"] = True if hasattr(conanfile, 'settings_target') and conanfile.settings_target: settings_target = conanfile.settings_target os_target = settings_target.get_safe("os") arch_target = settings_target.get_safe("arch") self.cross_build["target"] = to_meson_machine( os_target, arch_target) if is_apple_os( os_host): # default cross-compiler in Apple is common default_comp = "clang" default_comp_cpp = "clang++" else: if "Visual" in compiler or compiler == "msvc": default_comp = "cl" default_comp_cpp = "cl" elif "clang" in compiler: default_comp = "clang" default_comp_cpp = "clang++" elif compiler == "gcc": default_comp = "gcc" default_comp_cpp = "g++" # Read the VirtualBuildEnv to update the variables build_env = VirtualBuildEnv(self._conanfile).vars() self.c = build_env.get("CC") or default_comp self.cpp = build_env.get("CXX") or default_comp_cpp self.c_ld = build_env.get("CC_LD") or build_env.get("LD") self.cpp_ld = build_env.get("CXX_LD") or build_env.get("LD") self.ar = build_env.get("AR") self.strip = build_env.get("STRIP") self.as_ = build_env.get("AS") self.windres = build_env.get("WINDRES") self.pkgconfig = build_env.get("PKG_CONFIG") self.c_args = self._get_env_list(build_env.get("CFLAGS", [])) self.c_link_args = self._get_env_list(build_env.get("LDFLAGS", [])) self.cpp_args = self._get_env_list(build_env.get("CXXFLAGS", [])) self.cpp_link_args = self._get_env_list(build_env.get("LDFLAGS", [])) # Apple flags self.apple_arch_flag = [] self.apple_isysroot_flag = [] self.apple_min_version_flag = [] self._resolve_apple_flags() self._resolve_android_cross_compilation()