profile support
This commit is contained in:
parent
f32bf63c98
commit
2bb469b26f
16
HConfig
16
HConfig
|
@ -1,13 +1,17 @@
|
|||
grbc_want_version("1.0")
|
||||
grbc_ext("GRBC_EXT_pkg_config")
|
||||
grbc_ext("GRBC_EXT_profiles")
|
||||
|
||||
local grbc_pkg_config_ext = grbc_library(LibraryConfig.new({
|
||||
name = "libgrbc_pkg_config",
|
||||
grbc_set_profile("release")
|
||||
|
||||
local grbc_extensions = grbc_library(LibraryConfig.new({
|
||||
name = "libgrbc_extensions",
|
||||
language_type = LanguageType.Cpp,
|
||||
files = {
|
||||
grbc_file("src/ext_pkg_config.cc")
|
||||
grbc_file("src/ext_pkg_config.cc"),
|
||||
grbc_file("src/ext_profiles.cc")
|
||||
},
|
||||
lib_type = LibraryType.Shared,
|
||||
lib_type = LibraryType.Static,
|
||||
|
||||
requirements = {},
|
||||
compile_flags = {},
|
||||
|
@ -19,7 +23,7 @@ local grbc_pkg_config_ext = grbc_library(LibraryConfig.new({
|
|||
},
|
||||
|
||||
package_config = PackageConfig.new({
|
||||
name = "libgrbc_pkg_config",
|
||||
name = "libgrbc_extensions",
|
||||
libraries = {},
|
||||
include_dirs = {
|
||||
grbc_file("include"),
|
||||
|
@ -76,7 +80,7 @@ local grbc_exe = grbc_executable(ExecutableConfig.new({
|
|||
requirements = {
|
||||
grbc_pkg_config("lua"),
|
||||
grbc_pkg("libgrbc"),
|
||||
grbc_pkg("libgrbc_pkg_config")
|
||||
grbc_pkg("libgrbc_extensions")
|
||||
},
|
||||
compile_flags = {
|
||||
},
|
||||
|
|
17
build.ninja
17
build.ninja
|
@ -43,13 +43,16 @@ rule archive
|
|||
## Compile: src/ext_pkg_config.cc ##
|
||||
|
||||
build $builddir/src/ext_pkg_config.o: cxx src/ext_pkg_config.cc
|
||||
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
||||
|
||||
## Link: libgrbc_pkg_config.so ##
|
||||
## Compile: src/ext_profiles.cc ##
|
||||
|
||||
build $builddir/libgrbc_pkg_config.so: link_cxx $builddir/src/ext_pkg_config.o
|
||||
p_linker_flags = -shared -Lbuild -Wl,-rpath,build:.
|
||||
p_cflags =
|
||||
build $builddir/src/ext_profiles.o: cxx src/ext_profiles.cc
|
||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
||||
|
||||
## Link: libgrbc_extensions.a ##
|
||||
|
||||
build $builddir/libgrbc_extensions.a: archive $builddir/src/ext_pkg_config.o $builddir/src/ext_profiles.o
|
||||
|
||||
## Compile: src/file.cc ##
|
||||
|
||||
|
@ -107,7 +110,7 @@ build $builddir/src/main.o: cxx src/main.cc
|
|||
|
||||
## Link: grbc ##
|
||||
|
||||
build $builddir/grbc: link_cxx $builddir/src/main.o | $builddir/libgrbc.a $builddir/libgrbc_pkg_config.so
|
||||
p_linker_flags = -llua -lm -ldl build/libgrbc.a build/libgrbc_pkg_config.so -Lbuild -Wl,-rpath,build:.
|
||||
build $builddir/grbc: link_cxx $builddir/src/main.o | $builddir/libgrbc.a $builddir/libgrbc_extensions.a
|
||||
p_linker_flags = -llua -lm -ldl build/libgrbc.a build/libgrbc_extensions.a -O3 -Lbuild -Wl,-rpath,build:.
|
||||
p_cflags =
|
||||
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
[
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/file.o -MF build/src/file.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/file.cc -o build/src/file.o",
|
||||
"file": "src/file.cc",
|
||||
"output": "build/src/file.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/ninja.o -MF build/src/ninja.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/ninja.cc -o build/src/ninja.o",
|
||||
"file": "src/ninja.cc",
|
||||
"output": "build/src/ninja.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/platform.o -MF build/src/platform.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/platform.cc -o build/src/platform.o",
|
||||
"file": "src/platform.cc",
|
||||
"output": "build/src/platform.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/target_exe.o -MF build/src/target_exe.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/target_exe.cc -o build/src/target_exe.o",
|
||||
"file": "src/target_exe.cc",
|
||||
"output": "build/src/target_exe.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/utils.o -MF build/src/utils.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/utils.cc -o build/src/utils.o",
|
||||
"file": "src/utils.cc",
|
||||
"output": "build/src/utils.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/generator.o -MF build/src/generator.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/generator.cc -o build/src/generator.o",
|
||||
"file": "src/generator.cc",
|
||||
"output": "build/src/generator.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/target_lib.o -MF build/src/target_lib.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/target_lib.cc -o build/src/target_lib.o",
|
||||
"file": "src/target_lib.cc",
|
||||
"output": "build/src/target_lib.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/package.o -MF build/src/package.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/package.cc -o build/src/package.o",
|
||||
"file": "src/package.cc",
|
||||
"output": "build/src/package.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/ext.o -MF build/src/ext.o.d -fPIC -Iinclude -Ivendor/sol2/include -c src/ext.cc -o build/src/ext.o",
|
||||
"file": "src/ext.cc",
|
||||
"output": "build/src/ext.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -o build/libgrbc.so build/src/file.o build/src/ninja.o build/src/platform.o build/src/target_exe.o build/src/utils.o build/src/generator.o build/src/target_lib.o build/src/package.o build/src/ext.o -shared -Lbuild -Wl,-rpath,build:. ",
|
||||
"file": "build/src/file.o",
|
||||
"output": "build/libgrbc.so"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/main.o -MF build/src/main.o.d -Iinclude -Ivendor/sol2/include -c src/main.cc -o build/src/main.o",
|
||||
"file": "src/main.cc",
|
||||
"output": "build/src/main.o"
|
||||
},
|
||||
{
|
||||
"directory": "/home/interfiber/dev/grbc",
|
||||
"command": "/usr/lib64/ccache/g++ -o build/grbc build/src/main.o -llua -lm -ldl build/libgrbc.so -Lbuild -Wl,-rpath,build:. ",
|
||||
"file": "build/src/main.o",
|
||||
"output": "build/grbc"
|
||||
}
|
||||
]
|
|
@ -3,11 +3,13 @@
|
|||
#include <string>
|
||||
|
||||
#define GRBC_EXT_pkg_config_NAME "GRBC_EXT_pkg_config"
|
||||
#define GRBC_EXT_profiles_NAME "GRBC_EXT_profiles"
|
||||
|
||||
typedef void (*EXT_HookInit)(sol::state &lua);
|
||||
|
||||
struct Extension {
|
||||
std::string name;
|
||||
bool loaded = false;
|
||||
|
||||
EXT_HookInit hook_init = nullptr;
|
||||
};
|
14
include/grbc/ext_profiles.h
Normal file
14
include/grbc/ext_profiles.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
#include "grbc/ext.h"
|
||||
|
||||
struct Profile {
|
||||
std::string name;
|
||||
|
||||
std::vector<std::string> compiler_flags;
|
||||
std::vector<std::string> linker_flags;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the grbc profiles extension
|
||||
*/
|
||||
Extension grbc_profiles();
|
|
@ -252,3 +252,5 @@ bool grbc_has_ext(const std::string &extension_id);
|
|||
|
||||
std::string grbc_platform_file(PlatformType platform_type,
|
||||
const std::string &file_name);
|
||||
|
||||
bool grbc_is_ext_loaded(const std::string &extension_name);
|
|
@ -18,8 +18,8 @@ struct GState {
|
|||
|
||||
std::vector<Extension> extensions;
|
||||
|
||||
std::string global_compiler_flags = " ";
|
||||
std::string global_linker_flags = " ";
|
||||
std::string global_compiler_flags = "";
|
||||
std::string global_linker_flags = "";
|
||||
|
||||
std::string ninja_output;
|
||||
|
||||
|
|
|
@ -6,10 +6,14 @@ Extensions are built into the grbc executable, and are loaded at runtime as need
|
|||
|
||||
## Extension list
|
||||
* GRBC_EXT_pkg_config
|
||||
* GRBC_EXT_profiles
|
||||
* GRBC_EXT_cmake [NOSUPPORT]
|
||||
|
||||
## GRBC_EXT_pkg_config
|
||||
Pkg config support. UNIX only
|
||||
|
||||
## GRBC_EXT_profiles
|
||||
Support for compiler profiles, eg: Debug, ReleaseWithDebugSymbols, Release, etc
|
||||
|
||||
## GRBC_EXT_cmake
|
||||
CMake interop support
|
|
@ -43,6 +43,9 @@ If the current platform is equal to platform then return the file path, otherwis
|
|||
## [X] grbc_has_ext(extension_name: String) -> Boolean
|
||||
Check if the given extension is supported
|
||||
|
||||
## [X] grbc_is_ext_loaded(extension_name: String) -> Boolean
|
||||
Check if the given extension is loaded
|
||||
|
||||
## [X] grbc_ext(extension_name: String) -> Void
|
||||
Load the given extension into the script
|
||||
|
||||
|
|
12
src/ext.cc
12
src/ext.cc
|
@ -28,8 +28,20 @@ void grbc_ext(const std::string &extension_id) {
|
|||
|
||||
ext.hook_init(GState::get().lua);
|
||||
|
||||
ext.loaded = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
grbc_exception("Failed to find extension with name: " + extension_id);
|
||||
}
|
||||
|
||||
bool grbc_is_ext_loaded(const std::string &extension_name) {
|
||||
|
||||
for (auto &ext : GState::get().extensions) {
|
||||
if (ext.name == extension_name && ext.loaded)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -49,7 +49,7 @@ Package EXT_pkg_config_get_pkg(const std::string &name) {
|
|||
void grbc_pkg_config_init(sol::state &state) {
|
||||
state.set("grbc_pkg_config", EXT_pkg_config_get_pkg);
|
||||
|
||||
log_msg("pkg-config supported loaded!");
|
||||
log_msg("pkg-config support loaded!");
|
||||
}
|
||||
|
||||
Extension grbc_pkg_config() {
|
||||
|
|
77
src/ext_profiles.cc
Normal file
77
src/ext_profiles.cc
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include "grbc/ext_profiles.h"
|
||||
#include "grbc/ext.h"
|
||||
#include "grbc/helpers.h"
|
||||
#include "grbc/spec.h"
|
||||
#include "grbc/state.h"
|
||||
|
||||
std::vector<Profile> &EXT_profiles_get_profiles() {
|
||||
static std::vector<Profile> profiles{};
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
Profile *EXT_profiles_get_current_profile() {
|
||||
static Profile profile{};
|
||||
|
||||
return &profile;
|
||||
}
|
||||
|
||||
void EXT_profiles_set(const std::string &profile_id) {
|
||||
for (auto &profile : EXT_profiles_get_profiles()) {
|
||||
if (profile.name != profile_id)
|
||||
continue;
|
||||
|
||||
*EXT_profiles_get_current_profile() = profile;
|
||||
|
||||
log_msg(("set current profile to: " + profile_id).c_str());
|
||||
|
||||
// Maybe warn the user about this?
|
||||
GState::get().global_compiler_flags = " ";
|
||||
GState::get().global_linker_flags = " ";
|
||||
|
||||
for (auto &linker_flag : profile.linker_flags) {
|
||||
GState::get().global_linker_flags += linker_flag + " ";
|
||||
}
|
||||
|
||||
for (auto &compiler_flag : profile.compiler_flags) {
|
||||
GState::get().global_compiler_flags += compiler_flag + " ";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
grbc_exception("Failed to locate profile with name: " + profile_id);
|
||||
}
|
||||
|
||||
void grbc_profiles_init(sol::state &lua) {
|
||||
// Set default profiles
|
||||
Profile debug_profile{};
|
||||
debug_profile.name = "debug";
|
||||
debug_profile.compiler_flags = {"-g", "-O1"};
|
||||
|
||||
Profile release_with_debug_symbols_profile{};
|
||||
release_with_debug_symbols_profile.name = "release_with_debug_symbols";
|
||||
release_with_debug_symbols_profile.compiler_flags = {"-g", "-O3"};
|
||||
|
||||
Profile release_profile{};
|
||||
release_profile.name = "release";
|
||||
release_profile.linker_flags = {"-O3"};
|
||||
|
||||
EXT_profiles_get_profiles().push_back(debug_profile);
|
||||
EXT_profiles_get_profiles().push_back(release_with_debug_symbols_profile);
|
||||
EXT_profiles_get_profiles().push_back(release_profile);
|
||||
|
||||
EXT_profiles_set("debug"); // Always use debug as the default profile
|
||||
|
||||
lua.set("grbc_set_profile", EXT_profiles_set);
|
||||
|
||||
log_msg("profile support loaded!");
|
||||
}
|
||||
|
||||
Extension grbc_profiles() {
|
||||
Extension ext{};
|
||||
ext.name = GRBC_EXT_profiles_NAME;
|
||||
ext.hook_init = grbc_profiles_init;
|
||||
|
||||
return ext;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "grbc/ext_pkg_config.h"
|
||||
#include "grbc/ext_profiles.h"
|
||||
#include "grbc/state.h"
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
|
@ -105,6 +106,7 @@ int main() {
|
|||
lua.set("grbc_ext", grbc_ext);
|
||||
lua.set("grbc_has_ext", grbc_has_ext);
|
||||
lua.set("grbc_platform_file", grbc_platform_file);
|
||||
lua.set("grbc_is_ext_loaded", grbc_is_ext_loaded);
|
||||
|
||||
// Load generators
|
||||
|
||||
|
@ -117,6 +119,8 @@ int main() {
|
|||
grbc_register_ext(grbc_pkg_config());
|
||||
#endif
|
||||
|
||||
grbc_register_ext(grbc_profiles());
|
||||
|
||||
// Detect platform
|
||||
log_msg("autodetecting platform...");
|
||||
|
||||
|
|
Loading…
Reference in a new issue