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 = True # 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) self.build_type_link_flags = build_type_link_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) self.msvc_runtime_flag = self._get_msvc_runtime_flag() if cross_building(self._conanfile): os_build, arch_build, os_host, arch_host = get_cross_building_settings(self._conanfile) compiler = self._conanfile.settings.get_safe("compiler") self._host = _get_gnu_triplet(os_host, arch_host, compiler=compiler) self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler) # 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 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.get( "tools.cmake.cmaketoolchain:find_package_prefer_config", check_type=bool) if prefer_config is False: 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 # The package_folder can be None if editable and layout(), in that case only the # host_build_paths_noroot will be populated if req.package_folder: 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) else: host_build_paths_root = [] host_build_paths_noroot.extend(p for p in cppinfo.builddirs) 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 __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()