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_catalyst(arch): profile = textwrap.dedent(""" include(default) [settings] os = Macos os.version = 13.0 os.sdk = macosx os.subsystem = catalyst os.subsystem.ios_version = 13.1 arch = {arch} """).format(arch=arch) t = TestClient() hello_h = gen_function_h(name="hello") hello_cpp = gen_function_cpp(name="hello") main_cpp = textwrap.dedent(""" #include "hello.h" #include <TargetConditionals.h> #include <iostream> int main() { #if TARGET_OS_MACCATALYST std::cout << "running catalyst " << __IPHONE_OS_VERSION_MIN_REQUIRED << std::endl; #else #error "not building for Apple Catalyst" #endif } """) t.save({ "Makefile": makefile, "hello.h": hello_h, "hello.cpp": hello_cpp, "app.cpp": main_cpp, "conanfile.py": conanfile_py, "profile": profile }) t.run("install . --profile:host=profile --profile:build=default") t.run("build .") libhello = os.path.join(t.current_folder, "libhello.a") app = os.path.join(t.current_folder, "app") assert os.path.isfile(libhello) assert os.path.isfile(app) expected_arch = to_apple_arch(arch) t.run_command('lipo -info "%s"' % libhello) assert "architecture: %s" % expected_arch in t.out t.run_command('lipo -info "%s"' % app) assert "architecture: %s" % expected_arch in t.out if arch == "x86_64": t.run_command('"%s"' % app) assert "running catalyst 130100" in t.out
def _xcconfig_settings_filename(settings): arch = settings.get_safe("arch") architecture = to_apple_arch(arch) or arch props = [("configuration", settings.get_safe("build_type")), ("architecture", architecture), ("sdk name", settings.get_safe("os.sdk")), ("sdk version", settings.get_safe("os.sdk_version"))] name = "".join("_{}".format(v) for _, v in props if v is not None and v) return _format_name(name)
def __init__(self, conanfile): self._conanfile = conanfile self.configuration = conanfile.settings.get_safe("build_type") arch = conanfile.settings.get_safe("arch") self.architecture = to_apple_arch(arch) or arch self.os_version = conanfile.settings.get_safe("os.version") self.sdk = conanfile.settings.get_safe("os.sdk") self.sdk_version = conanfile.settings.get_safe("os.sdk_version") check_using_build_profile(self._conanfile)
def __init__(self, conanfile, namespace=None): self._conanfile = conanfile self._namespace = namespace build_type = self._conanfile.settings.get_safe("build_type") self.configure_args = [] self.make_args = [] self.default_configure_install_args = False # TODO: compiler.runtime for Visual studio? # defines self.ndebug = None if build_type in ['Release', 'RelWithDebInfo', 'MinSizeRel']: self.ndebug = "NDEBUG" self.gcc_cxx11_abi = self._cxx11_abi_define() self.defines = [] # cxxflags, cflags self.cxxflags = [] self.cflags = [] self.ldflags = [] self.libcxx = self._libcxx() self.fpic = self._conanfile.options.get_safe("fPIC") self.cppstd = cppstd_flag(self._conanfile.settings) self.arch_flag = architecture_flag(self._conanfile.settings) # TODO: This is also covering compilers like Visual Studio, necessary to test it (&remove?) self.build_type_flags = build_type_flags(self._conanfile.settings) # Cross build self._host = None self._build = None self._target = None self.apple_arch_flag = self.apple_isysroot_flag = None self.apple_min_version_flag = apple_min_version_flag(self._conanfile) if cross_building(self._conanfile): os_build, arch_build, os_host, arch_host = get_cross_building_settings( self._conanfile) self._host = _get_gnu_triplet(os_host, arch_host) self._build = _get_gnu_triplet(os_build, arch_build) # Apple Stuff if os_build == "Macos": sdk_path = apple_sdk_path(conanfile) apple_arch = to_apple_arch( self._conanfile.settings.get_safe("arch")) # https://man.archlinux.org/man/clang.1.en#Target_Selection_Options self.apple_arch_flag = "-arch {}".format( apple_arch) if apple_arch else None # -isysroot makes all includes for your library relative to the build directory self.apple_isysroot_flag = "-isysroot {}".format( sdk_path) if sdk_path else None check_using_build_profile(self._conanfile)
def __init__(self, conanfile): self._conanfile = conanfile self.configuration = conanfile.settings.get_safe("build_type") arch = conanfile.settings.get_safe("arch") self.architecture = to_apple_arch(arch) or arch # TODO: check if it makes sense to add a subsetting for sdk version # related to: https://github.com/conan-io/conan/issues/9608 self.os_version = conanfile.settings.get_safe("os.version") check_using_build_profile(self._conanfile)
def _xcconfig_conditional(settings): sdk_condition = "*" arch = settings.get_safe("arch") architecture = to_apple_arch(arch) or arch if settings.get_safe("os.sdk"): sdk_condition = "{}{}".format( settings.get_safe("os.sdk"), settings.get_safe("os.sdk_version") or "*") return "[config={}][arch={}][sdk={}]".format( settings.get_safe("build_type"), architecture, sdk_condition)
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 test_makefile_arch(config): arch, os_, os_version = config profile = textwrap.dedent(""" include(default) [settings] os = {os} os.version = {os_version} arch = {arch} """).format(os=os_, arch=arch, os_version=os_version) t = TestClient() hello_h = gen_function_h(name="hello") hello_cpp = gen_function_cpp(name="hello") main_cpp = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) t.save({ "Makefile": makefile, "hello.h": hello_h, "hello.cpp": hello_cpp, "app.cpp": main_cpp, "conanfile.py": conanfile_py, "profile": profile }) t.run("install . --profile:host=profile --profile:build=default") t.run("build .") libhello = os.path.join(t.current_folder, "libhello.a") app = os.path.join(t.current_folder, "app") assert os.path.isfile(libhello) assert os.path.isfile(app) expected_arch = to_apple_arch(arch) t.run_command('lipo -info "%s"' % libhello) assert "architecture: %s" % expected_arch in t.out t.run_command('lipo -info "%s"' % app) assert "architecture: %s" % expected_arch in t.out
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 _get_cross_build(self): user_toolchain = self._conanfile.conf.get( "tools.cmake.cmaketoolchain:user_toolchain") if user_toolchain is not None: return None, None, None # Will be provided by user_toolchain system_name = self._conanfile.conf.get( "tools.cmake.cmaketoolchain:system_name") system_version = self._conanfile.conf.get( "tools.cmake.cmaketoolchain:system_version") system_processor = self._conanfile.conf.get( "tools.cmake.cmaketoolchain:system_processor") if hasattr(self._conanfile, "settings_build"): os_host = self._conanfile.settings.get_safe("os") arch_host = self._conanfile.settings.get_safe("arch") if system_name is None: # Try to deduce _system_version = None _system_processor = None if self._is_apple_cross_building(): # cross-build in Macos also for M1 system_name = {'Macos': 'Darwin'}.get(os_host, os_host) # CMAKE_SYSTEM_VERSION for Apple sets the sdk version, not the os version _system_version = self._conanfile.settings.get_safe( "os.sdk_version") _system_processor = to_apple_arch(arch_host) elif os_host != 'Android': system_name = self._get_generic_system_name() _system_version = self._conanfile.settings.get_safe( "os.version") _system_processor = arch_host if system_name is not None and system_version is None: system_version = _system_version if system_name is not None and system_processor is None: system_processor = _system_processor return system_name, system_version, system_processor
def __init__(self, conanfile): self._conanfile = conanfile arch = conanfile.settings.get_safe("arch") self.architecture = to_apple_arch(arch) or arch self.configuration = conanfile.settings.build_type self.sdk = conanfile.settings.get_safe("os.sdk") self.sdk_version = conanfile.settings.get_safe("os.sdk_version") self.libcxx = conanfile.settings.get_safe("compiler.libcxx") self.os_version = conanfile.settings.get_safe("os.version") self._global_defines = self._conanfile.conf.get("tools.build:defines", default=[], check_type=list) self._global_cxxflags = self._conanfile.conf.get( "tools.build:cxxflags", default=[], check_type=list) self._global_cflags = self._conanfile.conf.get("tools.build:cflags", default=[], check_type=list) sharedlinkflags = self._conanfile.conf.get( "tools.build:sharedlinkflags", default=[], check_type=list) exelinkflags = self._conanfile.conf.get("tools.build:exelinkflags", default=[], check_type=list) self._global_ldflags = sharedlinkflags + exelinkflags check_using_build_profile(self._conanfile)
def __init__(self, conanfile): self._conanfile = conanfile self._build_type = conanfile.settings.get_safe("build_type") self._arch = to_apple_arch(conanfile.settings.get_safe("arch")) self._sdk = conanfile.settings.get_safe("os.sdk") or "" self._sdk_version = conanfile.settings.get_safe("os.sdk_version") or ""