def single_pc_file_contents(self, name, cpp_info, comp_requires_gennames, is_component=False): prefix_path = cpp_info.rootpath.replace("\\", "/") lines = ['prefix=%s' % prefix_path] libdir_vars = [] dir_lines, varnames = self._generate_dir_lines(prefix_path, "libdir", cpp_info.lib_paths) if dir_lines: libdir_vars = varnames lines.extend(dir_lines) includedir_vars = [] dir_lines, varnames = self._generate_dir_lines(prefix_path, "includedir", cpp_info.include_paths) if dir_lines: includedir_vars = varnames lines.extend(dir_lines) lines.append("") lines.append("Name: %s" % name) description = cpp_info.description or "Conan package: %s" % name lines.append("Description: %s" % description) lines.append("Version: %s" % cpp_info.version) libdirs_flags = ["-L${%s}" % name for name in libdir_vars] libnames_flags = ["-l%s " % name for name in (cpp_info.libs + cpp_info.system_libs)] shared_flags = cpp_info.sharedlinkflags + cpp_info.exelinkflags os_build, _ = get_build_os_arch(self.conanfile) if not hasattr(self.conanfile, 'settings_build'): os_build = os_build or self.conanfile.settings.get_safe("os") rpaths = rpath_flags(self.conanfile.settings, os_build, ["${%s}" % libdir for libdir in libdir_vars]) frameworks = format_frameworks(cpp_info.frameworks, self.conanfile.settings) framework_paths = format_framework_paths(cpp_info.framework_paths, self.conanfile.settings) lines.append("Libs: %s" % _concat_if_not_empty([libdirs_flags, libnames_flags, shared_flags, rpaths, frameworks, framework_paths])) include_dirs_flags = ["-I${%s}" % name for name in includedir_vars] lines.append("Cflags: %s" % _concat_if_not_empty( [include_dirs_flags, cpp_info.cxxflags, cpp_info.cflags, ["-D%s" % d for d in cpp_info.defines]])) if comp_requires_gennames: if is_component: pkg_config_names = comp_requires_gennames else: pkg_config_names = [] for public_dep in cpp_info.public_deps: name = self.deps_build_info[public_dep].get_name(PkgConfigGenerator.name) pkg_config_names.append(name) public_deps = " ".join(pkg_config_names) lines.append("Requires: %s" % public_deps) return "\n".join(lines) + "\n"
def _configure_link_flags(self): """Not the -L""" ret = copy.copy(self._deps_cpp_info.sharedlinkflags) ret.extend(self._deps_cpp_info.exelinkflags) ret.extend( format_frameworks(self._deps_cpp_info.frameworks, self._conanfile.settings)) ret.extend( format_framework_paths(self._deps_cpp_info.framework_paths, self._conanfile.settings)) arch_flag = architecture_flag(self._conanfile.settings) if arch_flag: ret.append(arch_flag) sysf = sysroot_flag(self._deps_cpp_info.sysroot, self._conanfile.settings, win_bash=self._win_bash, subsystem=self.subsystem) if sysf: ret.append(sysf) if self._include_rpath_flags: os_build, _ = get_build_os_arch(self._conanfile) if not hasattr(self._conanfile, 'settings_build'): os_build = os_build or self._os ret.extend( rpath_flags(self._conanfile.settings, os_build, self._deps_cpp_info.lib_paths)) return ret
def _get_build_os_arch(self): if hasattr(self._conanfile, 'settings_build'): os_build, arch_build = get_build_os_arch(self._conanfile) else: # FIXME: Why not use 'os_build' and 'arch_build' from conanfile.settings? os_build = detected_os() or platform.system() arch_build = detected_architecture() or platform.machine() return arch_build, os_build
def _pc_file_content(self, name, cpp_info, requires_gennames): version = cpp_info.get_property("component_version") or cpp_info.version prefix_path = cpp_info.rootpath.replace("\\", "/") lines = ['prefix=%s' % prefix_path] libdir_vars = [] dir_lines, varnames = self._generate_dir_lines(prefix_path, "libdir", cpp_info.lib_paths) if dir_lines: libdir_vars = varnames lines.extend(dir_lines) includedir_vars = [] dir_lines, varnames = self._generate_dir_lines(prefix_path, "includedir", cpp_info.include_paths) if dir_lines: includedir_vars = varnames lines.extend(dir_lines) pkg_config_custom_content = cpp_info.get_property("pkg_config_custom_content") if pkg_config_custom_content: lines.append(pkg_config_custom_content) lines.append("") lines.append("Name: %s" % name) description = cpp_info.description or "Conan package: %s" % name lines.append("Description: %s" % description) lines.append("Version: %s" % version) libdirs_flags = ['-L"${%s}"' % name for name in libdir_vars] libnames_flags = ["-l%s " % name for name in (cpp_info.libs + cpp_info.system_libs)] shared_flags = cpp_info.sharedlinkflags + cpp_info.exelinkflags os_build, _ = get_build_os_arch(self.conanfile) if not hasattr(self.conanfile, 'settings_build'): os_build = os_build or self.conanfile.settings.get_safe("os") rpaths = rpath_flags(self.conanfile.settings, os_build, ["${%s}" % libdir for libdir in libdir_vars]) frameworks = format_frameworks(cpp_info.frameworks, self.conanfile.settings) framework_paths = format_framework_paths(cpp_info.framework_paths, self.conanfile.settings) lines.append("Libs: %s" % _concat_if_not_empty([libdirs_flags, libnames_flags, shared_flags, rpaths, frameworks, framework_paths])) include_dirs_flags = ['-I"${%s}"' % name for name in includedir_vars] lines.append("Cflags: %s" % _concat_if_not_empty( [include_dirs_flags, [flag.replace('"', '\\"') for flag in cpp_info.cxxflags], [flag.replace('"', '\\"') for flag in cpp_info.cflags], ["-D%s" % d.replace('"', '\\"') for d in cpp_info.defines]])) if requires_gennames: public_deps = " ".join(requires_gennames) lines.append("Requires: %s" % public_deps) return "\n".join(lines) + "\n"
def content(self): """With compiler_args you can invoke your compiler: $ gcc main.c @conanbuildinfo.args -o main $ clang main.c @conanbuildinfo.args -o main $ cl /EHsc main.c @conanbuildinfo.args """ flags = [] flags.extend(format_defines(self._deps_build_info.defines)) flags.extend(format_include_paths(self._deps_build_info.include_paths, compiler=self.compiler)) flags.extend(self._deps_build_info.cxxflags) flags.extend(self._deps_build_info.cflags) arch_flag = architecture_flag(arch=self.conanfile.settings.get_safe("arch"), os=self.conanfile.settings.get_safe("os"), compiler=self.compiler) if arch_flag: flags.append(arch_flag) build_type = self.conanfile.settings.get_safe("build_type") btfs = build_type_flags(compiler=self.compiler, build_type=build_type, vs_toolset=self.conanfile.settings.get_safe("compiler.toolset")) if btfs: flags.extend(btfs) btd = build_type_define(build_type=build_type) if btd: flags.extend(format_defines([btd])) if self.compiler == "Visual Studio": runtime = visual_runtime(self.conanfile.settings.get_safe("compiler.runtime")) if runtime: flags.append(runtime) # Necessary in the "cl" invocation before specify the rest of linker flags flags.append(visual_linker_option_separator) os_build, _ = get_build_os_arch(self.conanfile) if not hasattr(self.conanfile, 'settings_build'): os_build = os_build or self.conanfile.settings.get_safe("os") flags.extend(rpath_flags(os_build, self.compiler, self._deps_build_info.lib_paths)) flags.extend(format_library_paths(self._deps_build_info.lib_paths, compiler=self.compiler)) flags.extend(format_libraries(self._deps_build_info.libs, compiler=self.compiler)) flags.extend(format_libraries(self._deps_build_info.system_libs, compiler=self.compiler)) flags.extend(self._deps_build_info.sharedlinkflags) flags.extend(self._deps_build_info.exelinkflags) flags.extend(self._libcxx_flags()) flags.extend(format_frameworks(self._deps_build_info.frameworks, compiler=self.compiler)) flags.extend(format_framework_paths(self._deps_build_info.framework_paths, compiler=self.compiler)) flags.append(cppstd_flag(self.conanfile.settings)) sysrf = sysroot_flag(self._deps_build_info.sysroot, compiler=self.compiler) if sysrf: flags.append(sysrf) return " ".join(flag for flag in flags if flag)
def _get_host_build_target_flags(self): """Based on google search for build/host triplets, it could need a lot and complex verification""" if self._os_target and self._arch_target: try: target = get_gnu_triplet(self._os_target, self._arch_target, self._compiler) except ConanException as exc: self._conanfile.output.warn(str(exc)) target = None else: target = None if hasattr(self._conanfile, 'settings_build'): os_build, arch_build = get_build_os_arch(self._conanfile) else: # FIXME: Why not use 'os_build' and 'arch_build' from conanfile.settings? os_build = detected_os() or platform.system() arch_build = detected_architecture() or platform.machine() if os_build is None or arch_build is None or self._arch is None or self._os is None: return False, False, target if not cross_building(self._conanfile, os_build, arch_build): return False, False, target try: build = get_gnu_triplet(os_build, arch_build, self._compiler) except ConanException as exc: self._conanfile.output.warn(str(exc)) build = None try: host = get_gnu_triplet(self._os, self._arch, self._compiler) except ConanException as exc: self._conanfile.output.warn(str(exc)) host = None return build, host, target
def vcvars_command(conanfile=None, arch=None, compiler_version=None, force=False, vcvars_ver=None, winsdk_version=None, output=None, settings=None): # Handle input arguments (backwards compatibility with 'settings' as first argument) # TODO: This can be promoted to a decorator pattern for any function if conanfile and settings: raise ConanException( "Do not set both arguments, 'conanfile' and 'settings'," " to call 'vcvars_command' function") from conans.model.conan_file import ConanFile if conanfile and not isinstance(conanfile, ConanFile): return vcvars_command(settings=conanfile, arch=arch, compiler_version=compiler_version, force=force, vcvars_ver=vcvars_ver, winsdk_version=winsdk_version, output=output) if settings: warnings.warn( "argument 'settings' has been deprecated, use 'conanfile' instead") if not conanfile: # TODO: If Conan is using 'profile_build' here we don't have any information about it, # we are falling back to the old behavior (which is probably wrong here) conanfile = namedtuple('_ConanFile', ['settings'])(settings) del settings # Here starts the actual implementation for this function output = default_output(output, 'conans.client.tools.win.vcvars_command') arch_setting = arch or conanfile.settings.get_safe("arch") compiler = conanfile.settings.get_safe("compiler") compiler_base = conanfile.settings.get_safe("compiler.base") if compiler == 'Visual Studio': compiler_version = compiler_version or conanfile.settings.get_safe( "compiler.version") elif compiler_base == "Visual Studio": compiler_version = compiler_version or conanfile.settings.get_safe( "compiler.base.version") else: # vcvars might be still needed for other compilers, e.g. clang-cl or Intel C++, # as they might be using Microsoft STL and other tools # (e.g. resource compiler, manifest tool, etc) # in this case, use the latest Visual Studio available on the machine last_version = latest_vs_version_installed(output=output) compiler_version = compiler_version or last_version os_setting = conanfile.settings.get_safe("os") if not compiler_version: raise ConanException( "compiler.version setting required for vcvars not defined") # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx vcvars_arch = None arch_setting = arch_setting or 'x86_64' _, settings_arch_build = get_build_os_arch(conanfile) arch_build = settings_arch_build if not hasattr(conanfile, 'settings_build'): arch_build = arch_build or detected_architecture() if os_setting == 'WindowsCE': vcvars_arch = "x86" elif arch_build == 'x86_64': # Only uses x64 tooling if arch_build explicitly defines it, otherwise # Keep the VS default, which is x86 toolset # This will probably be changed in conan 2.0 if ((settings_arch_build or os.getenv("PreferredToolArchitecture") == "x64") and int(compiler_version) >= 12): x86_cross = "amd64_x86" else: x86_cross = "x86" vcvars_arch = { 'x86': x86_cross, 'x86_64': 'amd64', 'armv7': 'amd64_arm', 'armv8': 'amd64_arm64' }.get(arch_setting) elif arch_build == 'x86': vcvars_arch = { 'x86': 'x86', 'x86_64': 'x86_amd64', 'armv7': 'x86_arm', 'armv8': 'x86_arm64' }.get(arch_setting) if not vcvars_arch: raise ConanException('unsupported architecture %s' % arch_setting) existing_version = os.environ.get("VisualStudioVersion") if existing_version: command = ["echo Conan:vcvars already set"] existing_version = existing_version.split(".")[0] if existing_version != compiler_version: message = "Visual environment already set to %s\n " \ "Current settings visual version: %s" % (existing_version, compiler_version) if not force: raise ConanException("Error, %s" % message) else: output.warn(message) else: vs_path = vs_installation_path(str(compiler_version)) if not vs_path or not os.path.isdir(vs_path): raise ConanException( "VS non-existing installation: Visual Studio %s" % str(compiler_version)) else: if int(compiler_version) > 14: vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") command = [ 'set "VSCMD_START_DIR=%%CD%%" && ' 'call "%s" %s' % (vcvars_path, vcvars_arch) ] else: vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat") command = ['call "%s" %s' % (vcvars_path, vcvars_arch)] if int(compiler_version) >= 14: if winsdk_version: command.append(winsdk_version) if vcvars_ver: command.append("-vcvars_ver=%s" % vcvars_ver) if os_setting == 'WindowsStore': os_version_setting = conanfile.settings.get_safe("os.version") if os_version_setting == '8.1': winsdk_version = winsdk_version or "8.1" command.append('store %s' % winsdk_version) elif os_version_setting == '10.0': winsdk_version = winsdk_version or find_windows_10_sdk() if not winsdk_version: raise ConanException( "cross-compiling for WindowsStore 10 (UWP), " "but Windows 10 SDK wasn't found") command.append('store %s' % winsdk_version) else: raise ConanException('unsupported Windows Store version %s' % os_version_setting) return " ".join(command)