init
This commit is contained in:
commit
45c2bf9426
25 changed files with 1692 additions and 0 deletions
89
src/platform.cc
Normal file
89
src/platform.cc
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "grbc/helpers.h"
|
||||
#include "grbc/spec.h"
|
||||
#include "grbc/state.h"
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
|
||||
void grbc_set_platform(const Platform &platform) {
|
||||
GState::get().current_platform = platform;
|
||||
|
||||
if (!std::filesystem::exists(platform.cxx_compiler)) {
|
||||
grbc_exception("C++ compiler path does not exist at '" +
|
||||
platform.cxx_compiler + "'");
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(platform.cc_compiler)) {
|
||||
grbc_exception("C compiler path does not exist at '" +
|
||||
platform.cc_compiler + "'");
|
||||
}
|
||||
|
||||
log_msg("--- Platform config: ---");
|
||||
|
||||
log_msg(("C++ compiler = " + platform.cxx_compiler).c_str());
|
||||
log_msg(("C compiler = " + platform.cc_compiler).c_str());
|
||||
}
|
||||
|
||||
void grbc_load_platform(const std::string &file_path) {
|
||||
Platform platform = GState::get().lua.script_file(file_path);
|
||||
|
||||
grbc_set_platform(platform);
|
||||
}
|
||||
|
||||
std::string grbc_find_compiler(const std::string &compiler_name) {
|
||||
#if defined(WIN32)
|
||||
std::string path_var = std::getenv("Path");
|
||||
|
||||
std::vector<std::string> paths = split_string(path_var, ";");
|
||||
|
||||
for (auto ¤t_path : paths) {
|
||||
if (std::filesystem::exists(
|
||||
std::filesystem::path(current_path) /
|
||||
std::filesystem::path(compiler_name + ".exe"))) {
|
||||
return std::filesystem::path(current_path) /
|
||||
std::filesystem::path(compiler_name + ".exe");
|
||||
}
|
||||
}
|
||||
|
||||
grbc_exception("Failed to locate compiler with name '" + compiler_name + "'");
|
||||
|
||||
#elif defined(__linux__)
|
||||
std::string path_var = std::getenv("PATH");
|
||||
|
||||
std::vector<std::string> paths = split_string(path_var, ":");
|
||||
|
||||
for (auto ¤t_path : paths) {
|
||||
if (std::filesystem::exists(std::filesystem::path(current_path) /
|
||||
std::filesystem::path(compiler_name))) {
|
||||
return std::filesystem::path(current_path) /
|
||||
std::filesystem::path(compiler_name);
|
||||
}
|
||||
}
|
||||
|
||||
grbc_exception("Failed to locate compiler with name '" + compiler_name + "'");
|
||||
|
||||
#else
|
||||
#error Invalid platform for grbc_find_compiler
|
||||
#endif
|
||||
|
||||
return "NoPlatform";
|
||||
}
|
||||
|
||||
bool grbc_is_win32() {
|
||||
return grbc_get_platform() == PlatformType_Win32;
|
||||
}
|
||||
|
||||
bool grbc_is_linux() {
|
||||
return grbc_get_platform() == PlatformType_Linux;
|
||||
}
|
||||
|
||||
PlatformType grbc_get_platform() {
|
||||
return GState::get().current_platform.platform_type;
|
||||
}
|
||||
|
||||
bool grbc_is_64bit() {
|
||||
return GState::get().current_platform.is_64bit;
|
||||
}
|
||||
|
||||
bool grbc_is_32bit() {
|
||||
return !grbc_is_64bit();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue