Browse Source

Revert "CMake cleanup"

This reverts commit 3ed9daccf3.
merge-requests/365/head
eidheim 10 years ago
parent
commit
7e34cebded
  1. 19
      src/cmake.cc
  2. 10
      src/cmake.h
  3. 12
      src/directories.cc
  4. 5
      src/directories.h
  5. 22
      src/notebook.cc
  6. 32
      src/project.cc
  7. 2
      src/source_clang.cc

19
src/cmake.cc

@ -7,12 +7,7 @@
std::unordered_set<std::string> CMake::debug_build_needed; std::unordered_set<std::string> CMake::debug_build_needed;
CMake::CMake(const boost::filesystem::path &path, bool find_project_root_path) { CMake::CMake(const boost::filesystem::path &path) {
if(!find_project_root_path) {
project_path=path;
return;
}
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) { const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) {
for(auto &line: filesystem::read_lines(cmake_path)) { for(auto &line: filesystem::read_lines(cmake_path)) {
const boost::regex project_regex("^ *project *\\(.*$"); const boost::regex project_regex("^ *project *\\(.*$");
@ -40,7 +35,7 @@ CMake::CMake(const boost::filesystem::path &path, bool find_project_root_path) {
} }
} }
boost::filesystem::path CMake::get_default_build_path() { boost::filesystem::path CMake::get_default_build_path(const boost::filesystem::path &project_path) {
boost::filesystem::path default_build_path=Config::get().project.default_build_path; boost::filesystem::path default_build_path=Config::get().project.default_build_path;
const std::string path_variable_project_directory_name="<project_directory_name>"; const std::string path_variable_project_directory_name="<project_directory_name>";
@ -60,7 +55,7 @@ boost::filesystem::path CMake::get_default_build_path() {
return default_build_path; return default_build_path;
} }
boost::filesystem::path CMake::get_debug_build_path() { boost::filesystem::path CMake::get_debug_build_path(const boost::filesystem::path &project_path) {
boost::filesystem::path debug_build_path=Config::get().project.debug_build_path; boost::filesystem::path debug_build_path=Config::get().project.debug_build_path;
const std::string path_variable_project_directory_name="<project_directory_name>"; const std::string path_variable_project_directory_name="<project_directory_name>";
@ -91,14 +86,14 @@ boost::filesystem::path CMake::get_debug_build_path() {
return debug_build_path; return debug_build_path;
} }
bool CMake::create_default_build(bool force) { bool CMake::create_default_build(const boost::filesystem::path &project_path, bool force) {
if(project_path.empty()) if(project_path.empty())
return false; return false;
if(!boost::filesystem::exists(project_path/"CMakeLists.txt")) if(!boost::filesystem::exists(project_path/"CMakeLists.txt"))
return false; return false;
auto default_build_path=get_default_build_path(); auto default_build_path=get_default_build_path(project_path);
if(default_build_path.empty()) if(default_build_path.empty())
return false; return false;
if(!boost::filesystem::exists(default_build_path)) { if(!boost::filesystem::exists(default_build_path)) {
@ -140,14 +135,14 @@ bool CMake::create_default_build(bool force) {
return false; return false;
} }
bool CMake::create_debug_build() { bool CMake::create_debug_build(const boost::filesystem::path &project_path) {
if(project_path.empty()) if(project_path.empty())
return false; return false;
if(!boost::filesystem::exists(project_path/"CMakeLists.txt")) if(!boost::filesystem::exists(project_path/"CMakeLists.txt"))
return false; return false;
auto debug_build_path=get_debug_build_path(); auto debug_build_path=get_debug_build_path(project_path);
if(debug_build_path.empty()) if(debug_build_path.empty())
return false; return false;
if(!boost::filesystem::exists(debug_build_path)) { if(!boost::filesystem::exists(debug_build_path)) {

10
src/cmake.h

@ -7,14 +7,14 @@
class CMake { class CMake {
public: public:
CMake(const boost::filesystem::path &path, bool find_project_root_path=false); CMake(const boost::filesystem::path &path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
std::vector<boost::filesystem::path> paths; std::vector<boost::filesystem::path> paths;
boost::filesystem::path get_default_build_path(); static boost::filesystem::path get_default_build_path(const boost::filesystem::path &project_path);
boost::filesystem::path get_debug_build_path(); static boost::filesystem::path get_debug_build_path(const boost::filesystem::path &project_path);
bool create_default_build(bool force=false); static bool create_default_build(const boost::filesystem::path &project_path, bool force=false);
bool create_debug_build(); static bool create_debug_build(const boost::filesystem::path &project_path);
boost::filesystem::path get_executable(const boost::filesystem::path &file_path); boost::filesystem::path get_executable(const boost::filesystem::path &file_path);

12
src/directories.cc

@ -3,7 +3,6 @@
#include <algorithm> #include <algorithm>
#include <unordered_set> #include <unordered_set>
#include "source.h" #include "source.h"
#include "cmake.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -132,12 +131,11 @@ void Directories::open(const boost::filesystem::path& dir_path) {
update_paths.clear(); update_paths.clear();
update_mutex.unlock(); update_mutex.unlock();
auto cmake=CMake(dir_path, true); cmake=std::unique_ptr<CMake>(new CMake(dir_path));
cmake.create_default_build(); CMake::create_default_build(cmake->project_path);
project_path=cmake.project_path; auto project=cmake->get_functions_parameters("project");
auto project_name=cmake.get_functions_parameters("project"); if(project.size()>0 && project[0].second.size()>0) {
if(project_name.size()>0 && project_name[0].second.size()>0) { auto title=project[0].second[0];
auto title=project_name[0].second[0];
//TODO: report that set_title does not handle '_' correctly? //TODO: report that set_title does not handle '_' correctly?
size_t pos=0; size_t pos=0;
while((pos=title.find('_', pos))!=std::string::npos) { while((pos=title.find('_', pos))!=std::string::npos) {

5
src/directories.h

@ -5,11 +5,11 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "boost/filesystem.hpp" #include "boost/filesystem.hpp"
#include "cmake.h"
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <atomic> #include <atomic>
#include "dispatcher.h" #include "dispatcher.h"
#include <unordered_map>
class Directories : public Gtk::TreeView { class Directories : public Gtk::TreeView {
public: public:
@ -40,9 +40,8 @@ public:
void select(const boost::filesystem::path &path); void select(const boost::filesystem::path &path);
std::function<void(const boost::filesystem::path &path)> on_row_activated; std::function<void(const boost::filesystem::path &path)> on_row_activated;
std::unique_ptr<CMake> cmake;
boost::filesystem::path current_path; boost::filesystem::path current_path;
boost::filesystem::path project_path;
private: private:
void add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row); void add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row);

22
src/notebook.cc

@ -99,18 +99,18 @@ void Notebook::open(const boost::filesystem::path &file_path) {
auto language=Source::guess_language(file_path); auto language=Source::guess_language(file_path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
auto &directories=Directories::get(); auto &directories=Directories::get();
if(!directories.project_path.empty() && file_path.generic_string().substr(0, directories.project_path.generic_string().size()+1)==directories.project_path.generic_string()+'/') if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/')
project_path=directories.project_path; project_path=directories.cmake->project_path;
else { else {
project_path=file_path.parent_path(); project_path=file_path.parent_path();
CMake cmake(project_path, true); CMake cmake(project_path);
if(cmake.project_path!="") { if(cmake.project_path!="") {
project_path=cmake.project_path; project_path=cmake.project_path;
Terminal::get().print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n"); Terminal::get().print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n");
} }
} }
if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
CMake(project_path).create_default_build(); CMake::create_default_build(project_path);
source_views.emplace_back(new Source::ClangView(file_path, project_path, language)); source_views.emplace_back(new Source::ClangView(file_path, project_path, language));
} }
else else
@ -249,19 +249,19 @@ bool Notebook::save(int page) {
boost::filesystem::path project_path; boost::filesystem::path project_path;
if(view->file_path.filename()=="CMakeLists.txt") { if(view->file_path.filename()=="CMakeLists.txt") {
auto &directories=Directories::get(); auto &directories=Directories::get();
if(!directories.project_path.empty() && view->file_path.generic_string().substr(0, directories.project_path.generic_string().size()+1)==directories.project_path.generic_string()+'/') { if(directories.cmake && directories.cmake->project_path!="" && view->file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') {
if(CMake(directories.project_path).create_default_build(true)) if(CMake::create_default_build(directories.cmake->project_path, true))
project_path=directories.project_path; project_path=directories.cmake->project_path;
} }
else { else {
CMake cmake(view->file_path.parent_path(), true); CMake cmake(view->file_path.parent_path());
if(cmake.create_default_build(true)) if(CMake::create_default_build(cmake.project_path, true))
project_path=cmake.project_path; project_path=cmake.project_path;
} }
if(project_path!="") { if(project_path!="") {
auto debug_project_path=CMake(project_path).get_debug_build_path(); auto debug_project_path=CMake::get_debug_build_path(project_path);
if(!debug_project_path.empty() && boost::filesystem::exists(debug_project_path)) if(!debug_project_path.empty() && boost::filesystem::exists(debug_project_path))
CMake(project_path).create_debug_build(); CMake::create_debug_build(project_path);
for(auto source_view: source_views) { for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) { if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(project_path==source_clang_view->project_path) if(project_path==source_clang_view->project_path)

32
src/project.cc

@ -82,10 +82,10 @@ std::unique_ptr<CMake> Project::Clang::get_cmake() {
path=Directories::get().current_path; path=Directories::get().current_path;
if(path.empty()) if(path.empty())
return nullptr; return nullptr;
auto cmake=std::unique_ptr<CMake>(new CMake(path, true)); auto cmake=std::unique_ptr<CMake>(new CMake(path));
if(cmake->project_path.empty()) if(cmake->project_path.empty())
return nullptr; return nullptr;
if(!cmake->create_default_build()) if(!CMake::create_default_build(cmake->project_path))
return nullptr; return nullptr;
return cmake; return cmake;
} }
@ -96,7 +96,7 @@ std::pair<std::string, std::string> Project::Clang::get_run_arguments() {
return {"", ""}; return {"", ""};
auto project_path=cmake->project_path.string(); auto project_path=cmake->project_path.string();
auto run_arguments_it=run_arguments.find(cmake->project_path.string()); auto run_arguments_it=run_arguments.find(project_path);
std::string arguments; std::string arguments;
if(run_arguments_it!=run_arguments.end()) if(run_arguments_it!=run_arguments.end())
arguments=run_arguments_it->second; arguments=run_arguments_it->second;
@ -105,16 +105,17 @@ std::pair<std::string, std::string> Project::Clang::get_run_arguments() {
auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string();
if(executable!="") { if(executable!="") {
auto build_path=cmake->get_default_build_path(); auto project_path=cmake->project_path;
auto build_path=CMake::get_default_build_path(project_path);
if(!build_path.empty()) { if(!build_path.empty()) {
size_t pos=executable.find(project_path); size_t pos=executable.find(project_path.string());
if(pos!=std::string::npos) if(pos!=std::string::npos)
executable.replace(pos, project_path.size(), build_path.string()); executable.replace(pos, project_path.string().size(), build_path.string());
} }
arguments=filesystem::escape_argument(executable); arguments=filesystem::escape_argument(executable);
} }
else else
arguments=filesystem::escape_argument(cmake->get_default_build_path()); arguments=filesystem::escape_argument(CMake::get_default_build_path(cmake->project_path));
} }
return {project_path, arguments}; return {project_path, arguments};
@ -125,7 +126,7 @@ void Project::Clang::compile() {
if(!cmake) if(!cmake)
return; return;
auto default_build_path=cmake->get_default_build_path(); auto default_build_path=CMake::get_default_build_path(cmake->project_path);
if(default_build_path.empty()) if(default_build_path.empty())
return; return;
compiling=true; compiling=true;
@ -141,7 +142,7 @@ void Project::Clang::compile_and_run() {
return; return;
auto project_path=cmake->project_path; auto project_path=cmake->project_path;
auto default_build_path=cmake->get_default_build_path(); auto default_build_path=CMake::get_default_build_path(project_path);
if(default_build_path.empty()) if(default_build_path.empty())
return; return;
@ -193,16 +194,17 @@ std::pair<std::string, std::string> Project::Clang::debug_get_run_arguments() {
auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string();
if(executable!="") { if(executable!="") {
auto build_path=cmake->get_debug_build_path(); auto project_path=cmake->project_path;
auto build_path=CMake::get_debug_build_path(project_path);
if(!build_path.empty()) { if(!build_path.empty()) {
size_t pos=executable.find(project_path); size_t pos=executable.find(project_path.string());
if(pos!=std::string::npos) if(pos!=std::string::npos)
executable.replace(pos, project_path.size(), build_path.string()); executable.replace(pos, project_path.string().size(), build_path.string());
} }
arguments=filesystem::escape_argument(executable); arguments=filesystem::escape_argument(executable);
} }
else else
arguments=filesystem::escape_argument(cmake->get_debug_build_path()); arguments=filesystem::escape_argument(CMake::get_debug_build_path(cmake->project_path));
} }
return {project_path, arguments}; return {project_path, arguments};
@ -214,10 +216,10 @@ void Project::Clang::debug_start() {
return; return;
auto project_path=cmake->project_path; auto project_path=cmake->project_path;
auto debug_build_path=cmake->get_debug_build_path(); auto debug_build_path=CMake::get_debug_build_path(project_path);
if(debug_build_path.empty()) if(debug_build_path.empty())
return; return;
if(!cmake->create_debug_build()) if(!CMake::create_debug_build(project_path))
return; return;
auto run_arguments_it=debug_run_arguments.find(project_path.string()); auto run_arguments_it=debug_run_arguments.find(project_path.string());

2
src/source_clang.cc

@ -178,7 +178,7 @@ void Source::ClangViewParse::soft_reparse() {
} }
std::vector<std::string> Source::ClangViewParse::get_compilation_commands() { std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
clang::CompilationDatabase db(CMake(project_path).get_default_build_path().string()); clang::CompilationDatabase db(CMake::get_default_build_path(project_path).string());
clang::CompileCommands commands(file_path.string(), db); clang::CompileCommands commands(file_path.string(), db);
std::vector<clang::CompileCommand> cmds = commands.get_commands(); std::vector<clang::CompileCommand> cmds = commands.get_commands();
std::vector<std::string> arguments; std::vector<std::string> arguments;

Loading…
Cancel
Save