Browse Source

Add a project.default_build_system and generate new project files based on build system

merge-requests/398/head
Shankar Giri 7 years ago
parent
commit
1b97e3e893
  1. 1
      src/config.cc
  2. 1
      src/config.h
  3. 38
      src/window.cc

1
src/config.cc

@ -190,6 +190,7 @@ void Config::read(const boost::property_tree::ptree &cfg) {
theme.variant = cfg.get<std::string>("gtk_theme.variant"); theme.variant = cfg.get<std::string>("gtk_theme.variant");
theme.font = cfg.get<std::string>("gtk_theme.font"); theme.font = cfg.get<std::string>("gtk_theme.font");
project.default_build_system = cfg.get<std::string>("project.default_build_system");
project.default_build_path = cfg.get<std::string>("project.default_build_path"); project.default_build_path = cfg.get<std::string>("project.default_build_path");
project.debug_build_path = cfg.get<std::string>("project.debug_build_path"); project.debug_build_path = cfg.get<std::string>("project.debug_build_path");
project.cmake.command = cfg.get<std::string>("project.cmake.command"); project.cmake.command = cfg.get<std::string>("project.cmake.command");

1
src/config.h

@ -40,6 +40,7 @@ public:
std::string compile_command; std::string compile_command;
}; };
std::string default_build_system;
std::string default_build_path; std::string default_build_path;
std::string debug_build_path; std::string debug_build_path;
CMake cmake; CMake cmake;

38
src/window.cc

@ -267,11 +267,21 @@ void Window::set_menu_actions() {
if(chr == ' ') if(chr == ' ')
chr = '_'; chr = '_';
} }
auto cmakelists_path = project_path / "CMakeLists.txt"; boost::filesystem::path buildsys_path;
std::string buildsys;
// Depending on default_build_system, generate build configuration
if(Config::get().project.default_build_system == "cmake") {
buildsys_path = project_path / "CMakeLists.txt";
buildsys = "cmake_minimum_required(VERSION 2.8)\n\nproject(" + project_name + ")\n\nset(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra\")\n\nadd_executable(" + project_name + " main.c)\n";
}
else if(Config::get().project.default_build_system == "meson") {
buildsys_path = project_path / "meson.build";
buildsys = "project('" + project_name + "', 'c')\nexecutable('" + project_name + "', 'main.c')\n";
}
auto c_main_path = project_path / "main.c"; auto c_main_path = project_path / "main.c";
auto clang_format_path = project_path / ".clang-format"; auto clang_format_path = project_path / ".clang-format";
if(boost::filesystem::exists(cmakelists_path)) { if(boost::filesystem::exists(buildsys_path)) {
Terminal::get().print("Error: " + cmakelists_path.string() + " already exists.\n", true); Terminal::get().print("Error: " + buildsys_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(c_main_path)) { if(boost::filesystem::exists(c_main_path)) {
@ -282,10 +292,9 @@ void Window::set_menu_actions() {
Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true); Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true);
return; return;
} }
std::string cmakelists = "cmake_minimum_required(VERSION 2.8)\n\nproject(" + project_name + ")\n\nset(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra\")\n\nadd_executable(" + project_name + " main.c)\n";
std::string c_main = "#include <stdio.h>\n\nint main() {\n printf(\"Hello World!\\n\");\n}\n"; std::string c_main = "#include <stdio.h>\n\nint main() {\n printf(\"Hello World!\\n\");\n}\n";
std::string clang_format = "IndentWidth: 2\nAccessModifierOffset: -2\nUseTab: Never\nColumnLimit: 0\n"; std::string clang_format = "IndentWidth: 2\nAccessModifierOffset: -2\nUseTab: Never\nColumnLimit: 0\n";
if(filesystem::write(cmakelists_path, cmakelists) && filesystem::write(c_main_path, c_main) && filesystem::write(clang_format_path, clang_format)) { if(filesystem::write(buildsys_path, buildsys) && filesystem::write(c_main_path, c_main) && filesystem::write(clang_format_path, clang_format)) {
Directories::get().open(project_path); Directories::get().open(project_path);
Notebook::get().open(c_main_path); Notebook::get().open(c_main_path);
Directories::get().update(); Directories::get().update();
@ -303,11 +312,21 @@ void Window::set_menu_actions() {
if(chr == ' ') if(chr == ' ')
chr = '_'; chr = '_';
} }
auto cmakelists_path = project_path / "CMakeLists.txt"; boost::filesystem::path buildsys_path;
std::string buildsys;
// Depending on default_build_system, generate build configuration
if(Config::get().project.default_build_system == "cmake") {
buildsys_path = project_path / "CMakeLists.txt";
buildsys = "cmake_minimum_required(VERSION 2.8)\n\nproject(" + project_name + ")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra\")\n\nadd_executable(" + project_name + " main.cpp)\n";
}
else if(Config::get().project.default_build_system == "meson") {
buildsys_path = project_path / "meson.build";
buildsys = "project('" + project_name + "', 'cpp')\nexecutable('" + project_name + "', 'main.cpp')\n";
}
auto cpp_main_path = project_path / "main.cpp"; auto cpp_main_path = project_path / "main.cpp";
auto clang_format_path = project_path / ".clang-format"; auto clang_format_path = project_path / ".clang-format";
if(boost::filesystem::exists(cmakelists_path)) { if(boost::filesystem::exists(buildsys_path)) {
Terminal::get().print("Error: " + cmakelists_path.string() + " already exists.\n", true); Terminal::get().print("Error: " + buildsys_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(cpp_main_path)) { if(boost::filesystem::exists(cpp_main_path)) {
@ -318,10 +337,9 @@ void Window::set_menu_actions() {
Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true); Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true);
return; return;
} }
std::string cmakelists = "cmake_minimum_required(VERSION 2.8)\n\nproject(" + project_name + ")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra\")\n\nadd_executable(" + project_name + " main.cpp)\n";
std::string cpp_main = "#include <iostream>\n\nint main() {\n std::cout << \"Hello World!\\n\";\n}\n"; std::string cpp_main = "#include <iostream>\n\nint main() {\n std::cout << \"Hello World!\\n\";\n}\n";
std::string clang_format = "IndentWidth: 2\nAccessModifierOffset: -2\nUseTab: Never\nColumnLimit: 0\nNamespaceIndentation: All\n"; std::string clang_format = "IndentWidth: 2\nAccessModifierOffset: -2\nUseTab: Never\nColumnLimit: 0\nNamespaceIndentation: All\n";
if(filesystem::write(cmakelists_path, cmakelists) && filesystem::write(cpp_main_path, cpp_main) && filesystem::write(clang_format_path, clang_format)) { if(filesystem::write(buildsys_path, buildsys) && filesystem::write(cpp_main_path, cpp_main) && filesystem::write(clang_format_path, clang_format)) {
Directories::get().open(project_path); Directories::get().open(project_path);
Notebook::get().open(cpp_main_path); Notebook::get().open(cpp_main_path);
Directories::get().update(); Directories::get().update();

Loading…
Cancel
Save