Exemple #1
0
    def _find_include_directories(self, include_directories):
        env_dirs = self._env_include_directories()
        if not self.find_includes:
            return tools.unique(self._env_include_directories() + include_directories)
        all_found = True
        for include in self.find_includes:
            all_found = any(
                path.exists(dir_, include) for dir_ in env_dirs
            )
            tools.debug("Search '%s':" % include, all_found)
            if not all_found: break

        if all_found:
            tools.debug("Include directories for", self.name, "found in env variables")
            return env_dirs
        tools.debug("Include directories for", self.name, "not found in env variables")
        results = []
        include_directories += env_dirs
        for p in self.prefixes:
            include_directories.append(path.join(p, 'include'))
        if self.use_system_paths:
            include_directories += self.include_system_paths()
        tools.debug("Search include directories for library", self.name)

        dirs = []
        for directory_name in self.include_directory_names:
            dirs.extend(path.join(dir_, directory_name) for dir_ in include_directories)
        include_directories = tools.unique(dirs)

        for include in self.find_includes:
            dirname, basename = path.split(include)
            name, ext = path.splitext(basename)
            found = False
            for dir_ in include_directories:
                tools.debug("Searching '%s' in directory '%s'" % (include, dir_))
                files = tools.find_files(
                    working_directory = path.join(dir_, dirname),
                    name = name,
                    extensions = [ext],
                    recursive = False,
                )
                if files:
                    found = True
                    tools.verbose("Found %s header '%s' in '%s'" % (self.name, include, dir_))
                    results.append(dir_)
                    break
            if not found:
                tools.fatal(
                    "Cannot find include file '%s' for library %s:" % (include, self.name),
                    "\t* Set 'include_directories' when creating the library",
                    "\t* Set the environment variable '%s_INCLUDE_DIRECTORY'" % self.name.upper(),
                    "\t* Set the environment variable '%s_INCLUDE_DIRECTORIES'" % self.name.upper(),
                    "\t* Set the environment variable '%s_PREFIX'" % self.name.upper(),
                    "\t* Set the environment variable '%s_PREFIXES'" % self.name.upper(),
                    "\t* Set the environment variable 'PREFIX'",
                    "\t* Set the environment variable 'PREFIXES'",
                    sep='\n'
                )
        return results
Exemple #2
0
    def _set_directories_and_files(self, directories):
        dirs = self._env_directories()
        files = self._env_files()

        if dirs and files:
            self.directories = dirs
            self.files = files
            tools.debug("Found %s library directories and files from environment" % self.name)
            return
        else:
            self.directories = []
            self.files = []

        tools.debug("Searching %s library directories and files" % self.name)
        dirs.extend(directories)
        if self.macosx_framework:
            dirs.extend(path.join(p, 'Library', 'Frameworks') for p in self.prefixes)
        else:
            dirs.extend(path.join(p, 'lib') for p in self.prefixes)
        if self.use_system_paths:
            dirs.extend(self.library_system_paths())

        if self.macosx_framework:
            dirs = (path.join(dir_, self.name + '.framework', 'lib') for dir_ in dirs)

        dirs = list(path.clean(d) for d in tools.unique(dirs) if path.exists(d))

        if self.binary_file_names is not None:
            names = self.binary_file_names
        else:
            names = [self.name]

        extensions_list = []
        if self.macosx_framework:
            extensions_list = [None]
        if self.shared is not None:
            extensions_list = [
                (
                    self.shared,
                    self.compiler.library_extensions(
                        self.shared,
                        for_linker = True,
                    )
                )
            ]
        else:
            extensions_list = [
                (
                    self.preferred_shared,
                    self.compiler.library_extensions(self.preferred_shared, for_linker = True)
                ),
                (
                    not self.preferred_shared,
                    self.compiler.library_extensions(not self.preferred_shared, for_linker = True)
                ),
            ]

        for name in names:
            files = []
            for shared, extensions in extensions_list:
                for dir_ in dirs:
                    files.extend(self._find_files(dir_, name, extensions))
                    if files and self.only_one_binary_file:
                        if self.shared is None:
                            self.shared = shared
                        files = files[:1]
                        tools.debug("Stopping search for %s library files." % name)
                        break
                if files:
                    break # do not mix shared and non shared extensions


            if not files:
                    tools.fatal(
                        "Cannot find %s library files:" % self.name,
                        "\t* Set 'directories' when creating the library",
                        "\t* Set the environment variable '%s_DIRECTORY'" % self.name.upper(),
                        "\t* Set the environment variable '%s_DIRECTORIES'" % self.name.upper(),
                        "\t* Set the environment variable '%s_PREFIX'" % self.name.upper(),
                        "\t* Set the environment variable '%s_PREFIXES'" % self.name.upper(),
                        "\t* Set the environment variable 'PREFIX'",
                        "\t* Set the environment variable 'PREFIXES'",
                        "NOTE: Directories checked: %s" % ', '.join(dirs),
                        sep='\n'
                    )
            else:
                self.files.extend(files)
                self.directories.extend(path.dirname(f) for f in files)