Esempio n. 1
0
    def _pc_file_content(self, name, cpp_info, requires_gennames,
                         package_folder, version):
        prefix_path = package_folder.replace("\\", "/")
        lines = ['prefix=%s' % prefix_path]

        gnudeps_flags = GnuDepsFlags(self._conanfile, cpp_info)

        libdir_vars = []
        dir_lines, varnames = self._generate_dir_lines(prefix_path, "libdir",
                                                       cpp_info.libdirs)
        if dir_lines:
            libdir_vars = varnames
            lines.extend(dir_lines)

        includedir_vars = []
        dir_lines, varnames = self._generate_dir_lines(prefix_path,
                                                       "includedir",
                                                       cpp_info.includedirs)
        if dir_lines:
            includedir_vars = varnames
            lines.extend(dir_lines)

        pkg_config_custom_content = cpp_info.get_property(
            "pkg_config_custom_content", "PkgConfigDeps")
        if pkg_config_custom_content:
            lines.append(pkg_config_custom_content)

        lines.append("")
        lines.append("Name: %s" % name)
        description = self._conanfile.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]
        lib_paths = ["${%s}" % libdir for libdir 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

        lines.append("Libs: %s" % _concat_if_not_empty([
            libdirs_flags, libnames_flags, shared_flags,
            gnudeps_flags._rpath_flags(lib_paths), gnudeps_flags.frameworks,
            gnudeps_flags.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 requires_gennames:
            public_deps = " ".join(requires_gennames)
            lines.append("Requires: %s" % public_deps)
        return "\n".join(lines) + "\n"
Esempio n. 2
0
    def environment(self):
        # TODO: Seems we want to make this uniform, equal to other generators
        if self._environment is None:
            flags = GnuDepsFlags(self._conanfile, self._get_cpp_info())

            # cpp_flags
            cpp_flags = []
            cpp_flags.extend(flags.include_paths)
            cpp_flags.extend(flags.defines)

            # Ldflags
            ldflags = flags.sharedlinkflags
            ldflags.extend(flags.exelinkflags)
            ldflags.extend(flags.frameworks)
            ldflags.extend(flags.framework_paths)
            ldflags.extend(flags.lib_paths)

            # cflags
            cflags = flags.cflags
            cxxflags = flags.cxxflags

            srf = flags.sysroot
            if srf:
                cflags.append(srf)
                cxxflags.append(srf)
                ldflags.append(srf)

            env = Environment()
            env.append("CPPFLAGS", cpp_flags)
            env.append("LIBS", flags.libs)
            env.append("LDFLAGS", ldflags)
            env.append("CXXFLAGS", cxxflags)
            env.append("CFLAGS", cflags)
            self._environment = env
        return self._environment
Esempio n. 3
0
def get_pc_filename_and_content(conanfile,
                                dep,
                                name,
                                requires,
                                description,
                                cpp_info=None):
    package_folder = dep.package_folder
    version = dep.ref.version
    cpp_info = cpp_info or dep.cpp_info

    prefix_path = package_folder.replace("\\", "/")
    libdirs = _get_formatted_dirs(cpp_info.libdirs, prefix_path)
    includedirs = _get_formatted_dirs(cpp_info.includedirs, prefix_path)
    custom_content = cpp_info.get_property("pkg_config_custom_content")

    context = {
        "prefix_path": prefix_path,
        "libdirs": libdirs,
        "includedirs": includedirs,
        "pkg_config_custom_content": custom_content,
        "name": name,
        "description": description,
        "version": version,
        "requires": requires,
        "cpp_info": cpp_info,
        "gnudeps_flags": GnuDepsFlags(conanfile, cpp_info)
    }
    template = Template(_get_pc_file_template(),
                        trim_blocks=True,
                        lstrip_blocks=True,
                        undefined=StrictUndefined)
    return {name + ".pc": template.render(context)}
Esempio n. 4
0
    def environment(self):
        flags = GnuDepsFlags(self._conanfile, self.cpp_info)

        # cpp_flags
        cpp_flags = []
        cpp_flags.extend(flags.include_paths)
        cpp_flags.extend(flags.defines)

        # Ldflags
        ldflags = flags.sharedlinkflags
        ldflags.extend(flags.exelinkflags)
        ldflags.extend(flags.frameworks)
        ldflags.extend(flags.framework_paths)
        ldflags.extend(flags.lib_paths)
        # FIXME: Previously we had an argument "include_rpath_flags" defaulted to False
        ldflags.extend(flags.rpath_flags)

        # cflags
        cflags = flags.cflags
        cxxflags = flags.cxxflags

        srf = flags.sysroot
        if srf:
            cflags.append(srf)
            cxxflags.append(srf)
            ldflags.append(srf)

        env = Environment()
        env.append("CPPFLAGS", cpp_flags)
        env.append("LIBS", flags.libs)
        env.append("LDFLAGS", ldflags)
        env.append("CXXFLAGS", cxxflags)
        env.append("CFLAGS", cflags)
        return env
Esempio n. 5
0
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
Esempio n. 6
0
    def environment(self):
        # TODO: Seems we want to make this uniform, equal to other generators
        if self._environment is None:
            flags = GnuDepsFlags(self._conanfile, self._get_cpp_info())

            # cpp_flags
            cpp_flags = []
            cpp_flags.extend(flags.include_paths)
            cpp_flags.extend(flags.defines)

            # Ldflags
            ldflags = flags.sharedlinkflags
            ldflags.extend(flags.exelinkflags)
            ldflags.extend(flags.frameworks)
            ldflags.extend(flags.framework_paths)
            ldflags.extend(flags.lib_paths)

            ## set the rpath in Macos so that the library are found in the configure step
            if self._conanfile.settings.get_safe("os") == "Macos":
                ldflags.extend(self._rpaths_flags())

            # libs
            libs = flags.libs
            libs.extend(flags.system_libs)

            # cflags
            cflags = flags.cflags
            cxxflags = flags.cxxflags

            env = Environment()
            env.append("CPPFLAGS", cpp_flags)
            env.append("LIBS", libs)
            env.append("LDFLAGS", ldflags)
            env.append("CXXFLAGS", cxxflags)
            env.append("CFLAGS", cflags)
            self._environment = env
        return self._environment