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. 14
      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;
CMake::CMake(const boost::filesystem::path &path, bool find_project_root_path) {
if(!find_project_root_path) {
project_path=path;
return;
}
CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) {
for(auto &line: filesystem::read_lines(cmake_path)) {
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;
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;
}
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;
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;
}
bool CMake::create_default_build(bool force) {
bool CMake::create_default_build(const boost::filesystem::path &project_path, bool force) {
if(project_path.empty())
return false;
if(!boost::filesystem::exists(project_path/"CMakeLists.txt"))
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())
return false;
if(!boost::filesystem::exists(default_build_path)) {
@ -140,14 +135,14 @@ bool CMake::create_default_build(bool force) {
return false;
}
bool CMake::create_debug_build() {
bool CMake::create_debug_build(const boost::filesystem::path &project_path) {
if(project_path.empty())
return false;
if(!boost::filesystem::exists(project_path/"CMakeLists.txt"))
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())
return false;
if(!boost::filesystem::exists(debug_build_path)) {

10
src/cmake.h

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

14
src/directories.cc

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

5
src/directories.h

@ -5,11 +5,11 @@
#include <vector>
#include <string>
#include "boost/filesystem.hpp"
#include "cmake.h"
#include <thread>
#include <mutex>
#include <atomic>
#include "dispatcher.h"
#include <unordered_map>
class Directories : public Gtk::TreeView {
public:
@ -40,9 +40,8 @@ public:
void select(const boost::filesystem::path &path);
std::function<void(const boost::filesystem::path &path)> on_row_activated;
std::unique_ptr<CMake> cmake;
boost::filesystem::path current_path;
boost::filesystem::path project_path;
private:
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);
boost::filesystem::path project_path;
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()+'/')
project_path=directories.project_path;
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.cmake->project_path;
else {
project_path=file_path.parent_path();
CMake cmake(project_path, true);
CMake cmake(project_path);
if(cmake.project_path!="") {
project_path=cmake.project_path;
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")) {
CMake(project_path).create_default_build();
CMake::create_default_build(project_path);
source_views.emplace_back(new Source::ClangView(file_path, project_path, language));
}
else
@ -249,19 +249,19 @@ bool Notebook::save(int page) {
boost::filesystem::path project_path;
if(view->file_path.filename()=="CMakeLists.txt") {
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(CMake(directories.project_path).create_default_build(true))
project_path=directories.project_path;
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::create_default_build(directories.cmake->project_path, true))
project_path=directories.cmake->project_path;
}
else {
CMake cmake(view->file_path.parent_path(), true);
if(cmake.create_default_build(true))
CMake cmake(view->file_path.parent_path());
if(CMake::create_default_build(cmake.project_path, true))
project_path=cmake.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))
CMake(project_path).create_debug_build();
CMake::create_debug_build(project_path);
for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
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;
if(path.empty())
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())
return nullptr;
if(!cmake->create_default_build())
if(!CMake::create_default_build(cmake->project_path))
return nullptr;
return cmake;
}
@ -96,7 +96,7 @@ std::pair<std::string, std::string> Project::Clang::get_run_arguments() {
return {"", ""};
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;
if(run_arguments_it!=run_arguments.end())
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();
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()) {
size_t pos=executable.find(project_path);
size_t pos=executable.find(project_path.string());
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);
}
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};
@ -125,7 +126,7 @@ void Project::Clang::compile() {
if(!cmake)
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())
return;
compiling=true;
@ -141,7 +142,7 @@ void Project::Clang::compile_and_run() {
return;
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())
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();
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()) {
size_t pos=executable.find(project_path);
size_t pos=executable.find(project_path.string());
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);
}
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};
@ -214,10 +216,10 @@ void Project::Clang::debug_start() {
return;
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())
return;
if(!cmake->create_debug_build())
if(!CMake::create_debug_build(project_path))
return;
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() {
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);
std::vector<clang::CompileCommand> cmds = commands.get_commands();
std::vector<std::string> arguments;

Loading…
Cancel
Save