-
-void ObjectFile::find_dependencies()
-{
- vector<FileTarget *> headers;
- find_dependencies(source, headers);
- for(FileTarget *h: headers)
- if(!any_equals(depends, static_cast<Target *>(h)))
- {
- add_dependency(*h);
- if(h->get_real_target()->is_buildable())
- h->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
- }
-}
-
-void ObjectFile::find_dependencies(FileTarget &tgt, vector<FileTarget *> &headers)
-{
- tgt.prepare();
-
- FileTarget *rtgt = tgt.get_real_target();
- Dependencies deps_to_add = rtgt->get_transitive_dependencies();
- if(rtgt!=&tgt)
- {
- FS::Path inst_dir = rtgt->get_component()->get_install_map().get_install_location(*rtgt);
- /* The target has been displaced by installing it. Displace any
- dependencies that come from the same package as well. */
- const SourcePackage *tpkg = rtgt->get_package();
- for(Target *&d: deps_to_add)
- {
- FileTarget *file = dynamic_cast<FileTarget *>(d);
- if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0)
- {
- const Component *tcomp = file->get_component();
- FS::Path dep_inst = tcomp->get_install_map().get_install_location(*file);
- FS::Path displaced = FS::dirname(tgt.get_path())/FS::relative(dep_inst, inst_dir)/FS::basename(file->get_path());
- d = builder.get_vfs().get_target(displaced);
- if(!d)
- {
- /* If the target was in an overlay directory and the displaced
- dependency is not found, try removing the overlay from the path. */
- string last_dir = FS::basename(FS::dirname(displaced));
- if(any_equals(tcomp->get_overlays(), last_dir))
- {
- displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
- d = builder.get_vfs().get_target(displaced);
- }
- }
- }
- }
- }
-
- for(Target *d: deps_to_add)
- if(FileTarget *file = dynamic_cast<FileTarget *>(d))
- {
- auto i = lower_bound(headers, file);
- if(i==headers.end() || *i!=file)
- {
- headers.insert(i, file);
- find_dependencies(*file, headers);
- }
- }
-}