Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit 112fe55

Browse files
committed
Added support for the Meson Build System
1 parent 715997a commit 112fe55

24 files changed

+545
-63
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required (VERSION 2.8.8)
22

33
project(juci)
4-
set(JUCI_VERSION "1.2.2")
4+
set(JUCI_VERSION "1.2.2.1")
55

66
set(CPACK_PACKAGE_NAME "jucipp")
77
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <[email protected]>")

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ towards libclang with speed, stability, and ease of use in mind.
1414
* C++ warnings and errors on the fly
1515
* C++ Fix-its
1616
* Debug integration, both local and remote, through lldb
17-
* Automated CMake processing, including support for external libraries
17+
* Supports the following build systems:
18+
* CMake
19+
* Meson
1820
* Git support through libgit2
1921
* Fast C++ autocompletion
2022
* Keyword and buffer autocompletion for other file types

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ set(project_files
2222
#Files used both in ../src and ../tests
2323
set(project_shared_files
2424
cmake.cc
25+
compile_commands.cc
2526
ctags.cc
2627
dispatcher.cc
2728
filesystem.cc
2829
git.cc
30+
meson.cc
2931
project_build.cc
3032
source.cc
3133
source_clang.cc

src/cmake.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool CMake::update_default_build(const boost::filesystem::path &default_build_pa
5555

5656
auto compile_commands_path=default_build_path/"compile_commands.json";
5757
Dialog::Message message("Creating/updating default build");
58-
auto exit_status=Terminal::get().process(Config::get().project.cmake_command+" "+
58+
auto exit_status=Terminal::get().process(Config::get().project.cmake.command+' '+
5959
filesystem::escape_argument(project_path)+" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path);
6060
message.hide();
6161
if(exit_status==EXIT_SUCCESS) {
@@ -102,7 +102,7 @@ bool CMake::update_debug_build(const boost::filesystem::path &debug_build_path,
102102
return true;
103103

104104
Dialog::Message message("Creating/updating debug build");
105-
auto exit_status=Terminal::get().process(Config::get().project.cmake_command+" "+
105+
auto exit_status=Terminal::get().process(Config::get().project.cmake.command+' '+
106106
filesystem::escape_argument(project_path)+" -DCMAKE_BUILD_TYPE=Debug", debug_build_path);
107107
message.hide();
108108
if(exit_status==EXIT_SUCCESS)

src/cmake.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ class CMake {
99
public:
1010
CMake(const boost::filesystem::path &path);
1111
boost::filesystem::path project_path;
12-
std::vector<boost::filesystem::path> paths;
1312

1413
bool update_default_build(const boost::filesystem::path &default_build_path, bool force=false);
1514
bool update_debug_build(const boost::filesystem::path &debug_build_path, bool force=false);
1615

1716
boost::filesystem::path get_executable(const boost::filesystem::path &file_path);
18-
19-
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > get_functions_parameters(const std::string &name);
2017
private:
18+
std::vector<boost::filesystem::path> paths;
2119
std::vector<std::string> files;
2220
std::unordered_map<std::string, std::string> variables;
2321
void read_files();
@@ -28,6 +26,7 @@ class CMake {
2826
void parse_variable_parameters(std::string &data);
2927
void parse();
3028
std::vector<std::string> get_function_parameters(std::string &data);
29+
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > get_functions_parameters(const std::string &name);
3130
bool parsed=false;
3231
};
3332
#endif //JUCI_CMAKE_H_

src/compile_commands.cc

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "compile_commands.h"
2+
#include <boost/property_tree/json_parser.hpp>
3+
4+
std::vector<std::string> CompileCommands::Command::paramter_values(const std::string &paramter_name) const {
5+
std::vector<std::string> parameter_values;
6+
7+
bool found_argument=false;
8+
for(auto &parameter: parameters) {
9+
if(found_argument) {
10+
parameter_values.emplace_back(parameter);
11+
found_argument=false;
12+
}
13+
else if(parameter==paramter_name)
14+
found_argument=true;
15+
}
16+
17+
return parameter_values;
18+
}
19+
20+
CompileCommands::CompileCommands(const boost::filesystem::path &build_path) {
21+
try {
22+
boost::property_tree::ptree root_pt;
23+
boost::property_tree::json_parser::read_json((build_path/"compile_commands.json").string(), root_pt);
24+
25+
auto commands_pt=root_pt.get_child("");
26+
for(auto &command: commands_pt) {
27+
boost::filesystem::path directory=command.second.get<std::string>("directory");
28+
auto parameters_str=command.second.get<std::string>("command");
29+
boost::filesystem::path file=command.second.get<std::string>("file");
30+
31+
std::vector<std::string> parameters;
32+
bool backslash=false;
33+
bool single_quote=false;
34+
bool double_quote=false;
35+
size_t parameter_start_pos=-1;
36+
size_t parameter_size=0;
37+
auto add_parameter=[&parameters, &parameters_str, &parameter_start_pos, &parameter_size] {
38+
auto parameter=parameters_str.substr(parameter_start_pos, parameter_size);
39+
// Remove escaping
40+
for(size_t c=0;c<parameter.size()-1;++c) {
41+
if(parameter[c]=='\\')
42+
parameter.replace(c, 2, std::string()+parameter[c+1]);
43+
}
44+
parameters.emplace_back(parameter);
45+
};
46+
for(size_t c=0;c<parameters_str.size();++c) {
47+
if(backslash)
48+
backslash=false;
49+
else if(parameters_str[c]=='\\')
50+
backslash=true;
51+
else if((parameters_str[c]==' ' || parameters_str[c]=='\t') && !backslash && !single_quote && !double_quote) {
52+
if(parameter_start_pos!=static_cast<size_t>(-1)) {
53+
add_parameter();
54+
parameter_start_pos=-1;
55+
parameter_size=0;
56+
}
57+
continue;
58+
}
59+
else if(parameters_str[c]=='\'' && !backslash && !double_quote) {
60+
single_quote=!single_quote;
61+
continue;
62+
}
63+
else if(parameters_str[c]=='\"' && !backslash && !single_quote) {
64+
double_quote=!double_quote;
65+
continue;
66+
}
67+
68+
if(parameter_start_pos==static_cast<size_t>(-1))
69+
parameter_start_pos=c;
70+
++parameter_size;
71+
}
72+
if(parameter_start_pos!=static_cast<size_t>(-1))
73+
add_parameter();
74+
75+
commands.emplace_back(Command{directory, parameters, boost::filesystem::absolute(file, build_path)});
76+
}
77+
}
78+
catch(...) {}
79+
}

src/compile_commands.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef JUCI_COMPILE_COMMANDS_H_
2+
#define JUCI_COMPILE_COMMANDS_H_
3+
4+
#include <boost/filesystem.hpp>
5+
#include <vector>
6+
#include <string>
7+
8+
class CompileCommands {
9+
public:
10+
class Command {
11+
public:
12+
boost::filesystem::path directory;
13+
std::vector<std::string> parameters;
14+
boost::filesystem::path file;
15+
16+
std::vector<std::string> paramter_values(const std::string &parameter_name) const;
17+
};
18+
19+
CompileCommands(const boost::filesystem::path &build_path);
20+
std::vector<Command> commands;
21+
};
22+
23+
#endif // JUCI_COMPILE_COMMANDS_H_

src/config.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ void Config::retrieve_config() {
9090

9191
project.default_build_path=cfg.get<std::string>("project.default_build_path");
9292
project.debug_build_path=cfg.get<std::string>("project.debug_build_path");
93-
project.make_command=cfg.get<std::string>("project.make_command");
94-
project.cmake_command=cfg.get<std::string>("project.cmake_command");
93+
project.cmake.command=cfg.get<std::string>("project.cmake.command");
94+
project.cmake.compile_command=cfg.get<std::string>("project.cmake.compile_command");
95+
project.meson.command=cfg.get<std::string>("project.meson.command");
96+
project.meson.compile_command=cfg.get<std::string>("project.meson.compile_command");
9597
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run");
9698
project.clear_terminal_on_compile=cfg.get<bool>("project.clear_terminal_on_compile");
9799
project.ctags_command=cfg.get<std::string>("project.ctags_command");

src/config.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ class Config {
3636

3737
class Project {
3838
public:
39+
class CMake {
40+
public:
41+
std::string command;
42+
std::string compile_command;
43+
};
44+
class Meson {
45+
public:
46+
std::string command;
47+
std::string compile_command;
48+
};
49+
3950
std::string default_build_path;
4051
std::string debug_build_path;
41-
std::string cmake_command;
42-
std::string make_command;
52+
CMake cmake;
53+
Meson meson;
4354
bool save_on_compile_or_run;
4455
bool clear_terminal_on_compile;
4556
std::string ctags_command;

src/files.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,29 @@ R"RAW(
156156
"default_build_path_comment": "Use <project_directory_name> to insert the project top level directory name",
157157
"default_build_path": "./build",
158158
"debug_build_path_comment": "Use <project_directory_name> to insert the project top level directory name, and <default_build_path> to insert your default_build_path setting.",
159-
"debug_build_path": "<default_build_path>/debug",)RAW"
159+
"debug_build_path": "<default_build_path>/debug",
160+
"cmake": {)RAW"
160161
#ifdef _WIN32
161162
R"RAW(
162-
"cmake_command": "cmake -G\"MSYS Makefiles\"",)RAW"
163+
"command": "cmake -G\"MSYS Makefiles\"",)RAW"
163164
#else
164165
R"RAW(
165-
"cmake_command": "cmake",)RAW"
166+
"command": "cmake",)RAW"
166167
#endif
167168
R"RAW(
168-
"make_command": "cmake --build .",
169+
"compile_command": "cmake --build ."
170+
},
171+
"meson": {)RAW"
172+
#ifdef __APPLE__
173+
R"RAW(
174+
"command": "meson.py",)RAW"
175+
#else
176+
R"RAW(
177+
"command": "meson",)RAW"
178+
#endif
179+
R"RAW(
180+
"compile_command": "ninja"
181+
},
169182
"save_on_compile_or_run": true,
170183
"clear_terminal_on_compile": true,
171184
"ctags_command": "ctags"

0 commit comments

Comments
 (0)