Browse Source

Added automated cmake processing for all cmake files in Project::on_save

merge-requests/365/head
eidheim 10 years ago
parent
commit
117857f937
  1. 11
      src/filesystem.cc
  2. 1
      src/filesystem.h
  3. 32
      src/project.cc

11
src/filesystem.cc

@ -169,3 +169,14 @@ bool filesystem::file_in_path(const boost::filesystem::path &file_path, const bo
return std::equal(path.begin(), path.end(), file_path.begin());
}
boost::filesystem::path filesystem::find_file_in_path_parents(const std::string &file_name, const boost::filesystem::path &path) {
auto current_path=path;
while(true) {
auto test_path=current_path/file_name;
if(boost::filesystem::exists(test_path))
return test_path;
if(current_path==current_path.root_directory())
return boost::filesystem::path();
current_path=current_path.parent_path();
}
}

1
src/filesystem.h

@ -30,5 +30,6 @@ public:
static std::string unescape(const std::string &argument);
static bool file_in_path(const boost::filesystem::path &file_path, const boost::filesystem::path &path);
static boost::filesystem::path find_file_in_path_parents(const std::string &file_name, const boost::filesystem::path &path);
};
#endif // JUCI_FILESYSTEM_H_

32
src/project.cc

@ -39,18 +39,26 @@ void Project::on_save(int page) {
if(page>=Notebook::get().size())
return;
auto view=Notebook::get().get_view(page);
if(view->file_path.filename()=="CMakeLists.txt") {
auto build=get_build(view->file_path);
if(dynamic_cast<CMake*>(build.get())) {
build->update_default_build(true);
if(boost::filesystem::exists(build->get_debug_build_path()))
build->update_debug_build(true);
for(int c=0;c<Notebook::get().size();c++) {
auto source_view=Notebook::get().get_view(c);
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(filesystem::file_in_path(source_clang_view->file_path, build->project_path))
source_clang_view->full_reparse_needed=true;
if(view->language && view->language->get_id()=="cmake") {
boost::filesystem::path cmake_path;
if(view->file_path.filename()=="CMakeLists.txt")
cmake_path=view->file_path;
else
cmake_path=filesystem::find_file_in_path_parents("CMakeLists.txt", view->file_path.parent_path());
if(!cmake_path.empty()) {
auto build=get_build(cmake_path);
if(dynamic_cast<CMake*>(build.get())) {
build->update_default_build(true);
if(boost::filesystem::exists(build->get_debug_build_path()))
build->update_debug_build(true);
for(int c=0;c<Notebook::get().size();c++) {
auto source_view=Notebook::get().get_view(c);
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(filesystem::file_in_path(source_clang_view->file_path, build->project_path))
source_clang_view->full_reparse_needed=true;
}
}
}
}

Loading…
Cancel
Save