def _config(self, filename, name, namespace, version, public_deps_names):
        # Builds the XXXConfig.cmake file for one package

        # The common macros
        macros_and_functions = "\n".join([
            CMakeFindPackageCommonMacros.conan_message,
            CMakeFindPackageCommonMacros.apple_frameworks_macro,
            CMakeFindPackageCommonMacros.conan_package_library_targets,
        ])

        # Define the targets properties
        targets_props = self.target_properties.render(
            name=name, namespace=namespace, configs=self.configurations)
        # Add build modules
        build_modules_block = self.build_modules.render(
            name=name, configs=self.configurations)
        # The find_dependencies_block
        find_dependencies_block = ""
        if public_deps_names:
            # Here we are generating only Config files, so do not search for FindXXX modules
            find_dependencies_block = find_transitive_dependencies(
                public_deps_names, find_modules=False)

        tmp = self.config_template.format(
            name=name,
            version=version,
            filename=filename,
            target_props_block=targets_props,
            build_modules_block=build_modules_block,
            find_dependencies_block=find_dependencies_block,
            macros_and_functions=macros_and_functions)
        return tmp
Esempio n. 2
0
    def _find_for_dep(self, name, cpp_info):
        # The common macros
        macros_and_functions = "\n".join([
            CMakeFindPackageCommonMacros.conan_message,
            CMakeFindPackageCommonMacros.apple_frameworks_macro,
            CMakeFindPackageCommonMacros.conan_package_library_targets,
        ])

        # compose the cpp_info with its "debug" or "release" specific config
        dep_cpp_info = cpp_info
        build_type = self.conanfile.settings.get_safe("build_type")
        if build_type:
            dep_cpp_info = extend(dep_cpp_info, build_type.lower())

        # The find_libraries_block, all variables for the package, and creation of targets
        public_deps_names = [
            self.deps_build_info[dep].get_name("cmake_find_package")
            for dep in dep_cpp_info.public_deps
        ]
        deps_names = ";".join(
            ["{n}::{n}".format(n=n) for n in public_deps_names])

        deps = DepsCppCmake(dep_cpp_info)
        find_libraries_block = target_template.format(name=name,
                                                      deps=deps,
                                                      build_type_suffix="",
                                                      deps_names=deps_names)

        # The find_transitive_dependencies block
        find_dependencies_block = ""
        if dep_cpp_info.public_deps:
            # Here we are generating FindXXX, so find_modules=True
            f = find_transitive_dependencies(public_deps_names,
                                             find_modules=True)
            # proper indentation
            find_dependencies_block = ''.join("        " +
                                              line if line.strip() else line
                                              for line in f.splitlines(True))

        tmp = self.find_template.format(
            name=name,
            version=dep_cpp_info.version,
            find_libraries_block=find_libraries_block,
            find_dependencies_block=find_dependencies_block,
            macros_and_functions=macros_and_functions)
        return tmp
Esempio n. 3
0
    def _find_for_dep(self, pkg_name, pkg_findname, pkg_filename, cpp_info):
        # return the content of the FindXXX.cmake file for the package "pkg_name"
        self._validate_components(cpp_info)

        public_deps = self.get_public_deps(cpp_info)
        deps_names = ';'.join(["{}::{}".format(*self._get_require_name(*it)) for it in public_deps])
        pkg_public_deps_filenames = [self._get_filename(self.deps_build_info[it[0]]) for it in
                                     public_deps]

        pkg_version = cpp_info.version
        if cpp_info.components:
            components = self._get_components(pkg_name, cpp_info)
            # Note these are in reversed order, from more dependent to less dependent
            pkg_components = " ".join(["{p}::{c}".format(p=pkg_findname, c=comp_findname) for
                                       comp_findname, _ in reversed(components)])
            pkg_info = DepsCppCmake(cpp_info)
            global_target_variables = target_template.format(name=pkg_findname, deps=pkg_info,
                                                             build_type_suffix="",
                                                             deps_names=deps_names)
            return self.find_components_tpl.render(
                pkg_name=pkg_findname,
                pkg_filename=pkg_filename,
                pkg_version=pkg_version,
                pkg_components=pkg_components,
                global_target_variables=global_target_variables,
                pkg_public_deps_filenames=pkg_public_deps_filenames,
                components=components,
                conan_message=CMakeFindPackageCommonMacros.conan_message,
                conan_find_apple_frameworks=CMakeFindPackageCommonMacros.apple_frameworks_macro,
                conan_package_library_targets=CMakeFindPackageCommonMacros.conan_package_library_targets)
        else:
            # The common macros
            macros_and_functions = "\n".join([
                CMakeFindPackageCommonMacros.conan_message,
                CMakeFindPackageCommonMacros.apple_frameworks_macro,
                CMakeFindPackageCommonMacros.conan_package_library_targets,
            ])

            # compose the cpp_info with its "debug" or "release" specific config
            dep_cpp_info = cpp_info
            build_type = self.conanfile.settings.get_safe("build_type")
            if build_type:
                dep_cpp_info = extend(dep_cpp_info, build_type.lower())

            # The find_libraries_block, all variables for the package, and creation of targets
            deps = DepsCppCmake(dep_cpp_info)
            find_libraries_block = target_template.format(name=pkg_findname, deps=deps,
                                                          build_type_suffix="",
                                                          deps_names=deps_names)

            # The find_transitive_dependencies block
            find_dependencies_block = ""
            if pkg_public_deps_filenames:
                # Here we are generating FindXXX, so find_modules=True
                f = find_transitive_dependencies(pkg_public_deps_filenames, find_modules=True)
                # proper indentation
                find_dependencies_block = ''.join("        " + line if line.strip() else line
                                                  for line in f.splitlines(True))

            return self.find_template.format(name=pkg_findname, version=pkg_version,
                                             filename=pkg_filename,
                                             find_libraries_block=find_libraries_block,
                                             find_dependencies_block=find_dependencies_block,
                                             macros_and_functions=macros_and_functions)