diff --git a/src/cmake.cc b/src/cmake.cc index 21d6960..8e79f4f 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -115,8 +115,8 @@ bool CMake::create_compile_commands(const boost::filesystem::path &project_path) return false; auto compile_commands_path=default_build_path/"compile_commands.json"; Dialog::Message message("Creating "+compile_commands_path.string()); - auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" "+ - project_path.string()+" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path); + auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" \""+ + project_path.string()+"\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path); message.hide(); if(exit_status==EXIT_SUCCESS) { #ifdef _WIN32 //Temporary fix to MSYS2's libclang @@ -145,8 +145,8 @@ bool CMake::create_debug_build(const boost::filesystem::path &project_path) { std::unique_ptr message; if(!boost::filesystem::exists(debug_build_path/"CMakeCache.txt")) message=std::unique_ptr(new Dialog::Message("Creating debug build")); - auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" "+ - project_path.string()+" -DCMAKE_BUILD_TYPE=Debug", debug_build_path); + auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" \""+ + project_path.string()+"\" -DCMAKE_BUILD_TYPE=Debug", debug_build_path); if(message) message->hide(); if(exit_status==EXIT_SUCCESS) diff --git a/src/window.cc b/src/window.cc index 876f1e8..e1a95a4 100644 --- a/src/window.cc +++ b/src/window.cc @@ -178,6 +178,21 @@ std::unique_ptr Window::get_cmake() { return std::unique_ptr(new CMake(path)); } +void Window::escape_executable(std::string &executable) { + bool backslash=false; + for(auto it=executable.begin();it!=executable.end();) { + if(*it=='\\' && !backslash) + backslash=true; + else if(backslash) + backslash=false; + else if(*it==' ') { + it=executable.insert(it, '\\'); + it++; + } + it++; + } +} + void Window::configure() { Config::get().load(); auto style_context = Gtk::StyleContext::create(); @@ -580,20 +595,18 @@ void Window::set_menu_actions() { CMake cmake(cmake_path); if(cmake.project_path.empty()) return; - auto executable_path=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:""); + auto executable=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"").string(); - if(executable_path!="") { + if(executable!="") { auto project_path=cmake.project_path; auto default_build_path=CMake::get_default_build_path(project_path); if(!default_build_path.empty()) { - auto executable_path_string=executable_path.string(); - size_t pos=executable_path_string.find(project_path.string()); - if(pos!=std::string::npos) { - executable_path_string.replace(pos, project_path.string().size(), default_build_path.string()); - executable_path=executable_path_string; - } + size_t pos=executable.find(project_path.string()); + if(pos!=std::string::npos) + executable.replace(pos, project_path.string().size(), default_build_path.string()); + escape_executable(executable); } - run_arguments=executable_path.string(); + run_arguments=executable; } } @@ -601,7 +614,7 @@ void Window::set_menu_actions() { entry_box.labels.emplace_back(); auto label_it=entry_box.labels.begin(); label_it->update=[label_it](int state, const std::string& message){ - label_it->set_text("testing"); + label_it->set_text("Leave empty to let juCi++ deduce executable"); }; label_it->update(0, ""); entry_box.entries.emplace_back(run_arguments, [this, project_path](const std::string& content){ @@ -650,6 +663,7 @@ void Window::set_menu_actions() { size_t pos=command.find(project_path.string()); if(pos!=std::string::npos) command.replace(pos, project_path.string().size(), default_build_path.string()); + escape_executable(command); } compiling=true; @@ -761,6 +775,7 @@ void Window::set_menu_actions() { size_t pos=command.find(project_path.string()); if(pos!=std::string::npos) command.replace(pos, project_path.string().size(), debug_build_path.string()); + escape_executable(command); //} auto breakpoints=std::make_shared > >(); diff --git a/src/window.h b/src/window.h index 0174918..342b40a 100644 --- a/src/window.h +++ b/src/window.h @@ -47,6 +47,7 @@ private: Glib::Dispatcher debug_update_status; std::unique_ptr get_cmake(); + void escape_executable(std::string &executable); std::unordered_map project_run_arguments; std::unordered_map debug_run_arguments;