init
This commit is contained in:
commit
45c2bf9426
25 changed files with 1692 additions and 0 deletions
46
include/grbc/generator.h
Normal file
46
include/grbc/generator.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include "grbc/spec.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct GeneratorResult {
|
||||
std::string file_name;
|
||||
std::string content;
|
||||
};
|
||||
|
||||
struct GeneratorCompileCommand {
|
||||
LanguageType language_type;
|
||||
|
||||
std::string source_file;
|
||||
std::string object_file;
|
||||
|
||||
std::string compiler_flags;
|
||||
};
|
||||
|
||||
struct GeneratorLinkExecutableCommand {
|
||||
std::vector<std::string> object_files;
|
||||
|
||||
std::string output_exe;
|
||||
|
||||
std::string linker_flags;
|
||||
};
|
||||
|
||||
struct GeneratorTarget {
|
||||
std::vector<GeneratorCompileCommand> compile_commands;
|
||||
std::vector<GeneratorLinkExecutableCommand> link_executable_commands;
|
||||
};
|
||||
|
||||
typedef GeneratorResult (*Generator_Run)();
|
||||
|
||||
struct Generator {
|
||||
/// Name of the generator, used in grbc_build(...)
|
||||
std::string name;
|
||||
|
||||
/// Function pointer for this generator
|
||||
Generator_Run func;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ninja generator main function
|
||||
*/
|
||||
GeneratorResult ninja_generator();
|
21
include/grbc/helpers.h
Normal file
21
include/grbc/helpers.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define log_msg(message) printf("> %s\n", message);
|
||||
|
||||
inline std::vector<std::string> split_string(std::string s,
|
||||
std::string delimiter) {
|
||||
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
|
||||
std::string token;
|
||||
std::vector<std::string> res;
|
||||
|
||||
while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
|
||||
token = s.substr(pos_start, pos_end - pos_start);
|
||||
pos_start = pos_end + delim_len;
|
||||
res.push_back(token);
|
||||
}
|
||||
|
||||
res.push_back(s.substr(pos_start));
|
||||
return res;
|
||||
}
|
40
include/grbc/ninja.h
Normal file
40
include/grbc/ninja.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
#include "grbc/generator.h"
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Generate the build rule for compiling c++ files
|
||||
*/
|
||||
std::string ninja_build_rule_compile_cxx();
|
||||
|
||||
/**
|
||||
* Generate the build rule for compiling c files
|
||||
*/
|
||||
std::string ninja_build_rule_compile_cc();
|
||||
|
||||
/**
|
||||
* Generate the build rule for linking c++ object files
|
||||
*/
|
||||
std::string ninja_build_rule_link_cxx();
|
||||
|
||||
/**
|
||||
* Generate the build rule for linking c object files
|
||||
*/
|
||||
std::string ninja_build_rule_link_cc();
|
||||
|
||||
/**
|
||||
* Generate a line which builds the given file
|
||||
*/
|
||||
std::string
|
||||
ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd);
|
||||
|
||||
/**
|
||||
* Default variables such as builddir
|
||||
*/
|
||||
std::string ninja_build_default_variables();
|
||||
|
||||
/**
|
||||
* Generate a line which links the given file
|
||||
*/
|
||||
std::string ninja_build_rule_link_exe_target(
|
||||
const GeneratorLinkExecutableCommand &link_cmd);
|
150
include/grbc/spec.h
Normal file
150
include/grbc/spec.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
#pragma once
|
||||
#include <sol/table.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define GRBC_VERSION "1.0"
|
||||
|
||||
enum LanguageType { LanguageType_CPP, LanguageType_C };
|
||||
|
||||
struct TargetInfo {
|
||||
/// Name of the target
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct Package {
|
||||
Package(const sol::table &table) {
|
||||
name = table.get<std::string>("name");
|
||||
compiler_flags = table.get<std::string>("compiler_flags");
|
||||
linker_flags = table.get<std::string>("linker_flags");
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
std::string compiler_flags;
|
||||
|
||||
std::string linker_flags;
|
||||
};
|
||||
|
||||
struct PackageConfig {
|
||||
std::string name;
|
||||
|
||||
std::vector<Package> libraries;
|
||||
|
||||
std::vector<std::string> include_dirs;
|
||||
|
||||
std::vector<std::string> compile_flags;
|
||||
|
||||
std::vector<std::string> linker_flags;
|
||||
};
|
||||
|
||||
enum PlatformType { PlatformType_Win32, PlatformType_Linux };
|
||||
|
||||
struct GlobalConfig {
|
||||
/// Version of the grbc executable
|
||||
std::string engine_version = GRBC_VERSION;
|
||||
|
||||
/// Architecture string
|
||||
std::string architecture;
|
||||
|
||||
/// Build directory
|
||||
std::string build_dir = "build";
|
||||
|
||||
/// System that we are targetting
|
||||
PlatformType target;
|
||||
|
||||
/// Path to the target.hcfg
|
||||
std::string target_config;
|
||||
};
|
||||
|
||||
struct ExecutableConfig {
|
||||
ExecutableConfig(const sol::table &table) {
|
||||
name = table.get<std::string>("name");
|
||||
files = table.get<std::vector<std::string>>("files");
|
||||
requirements = table.get<std::vector<Package>>("requirements");
|
||||
|
||||
compile_flags = table.get<std::vector<std::string>>("compile_flags");
|
||||
linker_flags = table.get<std::vector<std::string>>("linker_flags");
|
||||
include_dirs = table.get<std::vector<std::string>>("include_dirs");
|
||||
|
||||
language_type = table.get<LanguageType>("language_type");
|
||||
}
|
||||
|
||||
/// Name of the executable
|
||||
std::string name;
|
||||
|
||||
/// Type of language
|
||||
LanguageType language_type;
|
||||
|
||||
/// List of files to compile
|
||||
std::vector<std::string> files;
|
||||
|
||||
/// Requirments of the executable
|
||||
std::vector<Package> requirements;
|
||||
|
||||
/// Compiler flags
|
||||
std::vector<std::string> compile_flags;
|
||||
|
||||
/// Linker flags
|
||||
std::vector<std::string> linker_flags;
|
||||
|
||||
/// Include directories
|
||||
std::vector<std::string> include_dirs;
|
||||
};
|
||||
|
||||
struct Platform {
|
||||
/// Name of the platform
|
||||
std::string name;
|
||||
|
||||
/// C++ compiler
|
||||
std::string cxx_compiler;
|
||||
|
||||
/// C compiler
|
||||
std::string cc_compiler;
|
||||
|
||||
/// Is this platform 64-bit?
|
||||
bool is_64bit = true;
|
||||
|
||||
/// Type of the platform
|
||||
PlatformType platform_type;
|
||||
};
|
||||
|
||||
/// Functions
|
||||
|
||||
void grbc_want_version(const std::string &version);
|
||||
|
||||
void grbc_exception(const std::string &exception_string);
|
||||
|
||||
GlobalConfig grbc_get_config();
|
||||
|
||||
std::string grbc_file(const std::string &file_path);
|
||||
|
||||
TargetInfo grbc_executable(const ExecutableConfig &executable_config);
|
||||
|
||||
void grbc_load_platform(const std::string &file_path);
|
||||
|
||||
void grbc_set_platform(const Platform &platform);
|
||||
|
||||
std::string grbc_find_compiler(const std::string &compiler_name);
|
||||
|
||||
void grbc_build(const std::string &generator_id);
|
||||
|
||||
std::string grbc_object_file(const std::string &file_path);
|
||||
|
||||
std::string grbc_replace_string(const std::string &string, char substring,
|
||||
char replacement);
|
||||
|
||||
std::string
|
||||
grbc_include_dirs_to_cflags(const std::vector<std::string> &include_dirs);
|
||||
|
||||
void grbc_log(const std::string &message);
|
||||
|
||||
bool grbc_is_win32();
|
||||
|
||||
bool grbc_is_linux();
|
||||
|
||||
PlatformType grbc_get_platform();
|
||||
|
||||
bool grbc_is_64bit();
|
||||
|
||||
bool grbc_is_32bit();
|
21
include/grbc/state.h
Normal file
21
include/grbc/state.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#include "grbc/generator.h"
|
||||
#include "grbc/spec.h"
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
struct GState {
|
||||
Platform current_platform;
|
||||
sol::state lua;
|
||||
|
||||
std::vector<GeneratorTarget> targets;
|
||||
|
||||
std::vector<Generator> generators;
|
||||
|
||||
std::string ninja_output;
|
||||
|
||||
static GState& get() {
|
||||
static GState state{};
|
||||
|
||||
return state;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue