diff --git a/src/filesystem.cc b/src/filesystem.cc index ec2ca87..d83ca13 100644 --- a/src/filesystem.cc +++ b/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(); + } +} diff --git a/src/filesystem.h b/src/filesystem.h index 1326ab9..74a82aa 100644 --- a/src/filesystem.h +++ b/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_ diff --git a/src/project.cc b/src/project.cc index 443fcb7..c224d6c 100644 --- a/src/project.cc +++ b/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(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(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(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(source_view)) { + if(filesystem::file_in_path(source_clang_view->file_path, build->project_path)) + source_clang_view->full_reparse_needed=true; + } } } }