command-line option support + switch compiler profile on command line

This commit is contained in:
Hunter 2024-09-29 16:35:45 -04:00
parent dfcf57aae1
commit 816dcbe118
12 changed files with 359 additions and 155 deletions

View file

@ -48,3 +48,7 @@ up
up up
up up
q q
q
q
r gen -compiler_profile release
q

View file

@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.28)
project(grbc) project(grbc)
message(${CMAKE_CXX_FLAGS_RELEASE})
add_subdirectory("vendor/sol2") add_subdirectory("vendor/sol2")
include_directories("include") include_directories("include")

View file

@ -2,8 +2,6 @@ grbc_want_version("1.0")
grbc_ext("GRBC_EXT_pkg_config") grbc_ext("GRBC_EXT_pkg_config")
grbc_ext("GRBC_EXT_profiles") grbc_ext("GRBC_EXT_profiles")
grbc_set_profile("release")
local grbc_extensions = grbc_library(LibraryConfig.new({ local grbc_extensions = grbc_library(LibraryConfig.new({
name = "libgrbc_extensions", name = "libgrbc_extensions",
language_type = LanguageType.Cpp, language_type = LanguageType.Cpp,
@ -47,7 +45,8 @@ local grbc_lib = grbc_library(LibraryConfig.new({
grbc_file("src/target_lib.cc"), grbc_file("src/target_lib.cc"),
grbc_file("src/package.cc"), grbc_file("src/package.cc"),
grbc_file("src/ext.cc"), grbc_file("src/ext.cc"),
grbc_file("src/task.cc") grbc_file("src/task.cc"),
grbc_file("src/options.cc")
}, },
lib_type = LibraryType.Static, lib_type = LibraryType.Static,

View file

@ -1,5 +1,5 @@
### GENERATED BY THE GRBC BUILT-IN NINJA GENERATOR ### ### GENERATED BY THE GRBC BUILT-IN NINJA GENERATOR ###
### GENERATED ON: 1727637831 ### ### GENERATED ON: 1727642123 ###
## Default variables ## ## Default variables ##
@ -44,12 +44,12 @@ rule archive
## Compile: src/ext_pkg_config.cc ## ## Compile: src/ext_pkg_config.cc ##
build $builddir/src/ext_pkg_config.o: cxx src/ext_pkg_config.cc build $builddir/src/ext_pkg_config.o: cxx src/ext_pkg_config.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/ext_profiles.cc ## ## Compile: src/ext_profiles.cc ##
build $builddir/src/ext_profiles.o: cxx src/ext_profiles.cc build $builddir/src/ext_profiles.o: cxx src/ext_profiles.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Link: libgrbc_extensions.a ## ## Link: libgrbc_extensions.a ##
@ -58,67 +58,72 @@ build $builddir/libgrbc_extensions.a: archive $builddir/src/ext_pkg_config.o $bu
## Compile: src/file.cc ## ## Compile: src/file.cc ##
build $builddir/src/file.o: cxx src/file.cc build $builddir/src/file.o: cxx src/file.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/ninja.cc ## ## Compile: src/ninja.cc ##
build $builddir/src/ninja.o: cxx src/ninja.cc build $builddir/src/ninja.o: cxx src/ninja.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/platform.cc ## ## Compile: src/platform.cc ##
build $builddir/src/platform.o: cxx src/platform.cc build $builddir/src/platform.o: cxx src/platform.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/target_exe.cc ## ## Compile: src/target_exe.cc ##
build $builddir/src/target_exe.o: cxx src/target_exe.cc build $builddir/src/target_exe.o: cxx src/target_exe.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/utils.cc ## ## Compile: src/utils.cc ##
build $builddir/src/utils.o: cxx src/utils.cc build $builddir/src/utils.o: cxx src/utils.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/generator.cc ## ## Compile: src/generator.cc ##
build $builddir/src/generator.o: cxx src/generator.cc build $builddir/src/generator.o: cxx src/generator.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/target_lib.cc ## ## Compile: src/target_lib.cc ##
build $builddir/src/target_lib.o: cxx src/target_lib.cc build $builddir/src/target_lib.o: cxx src/target_lib.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/package.cc ## ## Compile: src/package.cc ##
build $builddir/src/package.o: cxx src/package.cc build $builddir/src/package.o: cxx src/package.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/ext.cc ## ## Compile: src/ext.cc ##
build $builddir/src/ext.o: cxx src/ext.cc build $builddir/src/ext.o: cxx src/ext.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/task.cc ## ## Compile: src/task.cc ##
build $builddir/src/task.o: cxx src/task.cc build $builddir/src/task.o: cxx src/task.cc
p_cflags = -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Compile: src/options.cc ##
build $builddir/src/options.o: cxx src/options.cc
p_cflags = -Iinclude -Ivendor/sol2/include -g -O1
## Link: libgrbc.a ## ## Link: libgrbc.a ##
build $builddir/libgrbc.a: archive $builddir/src/file.o $builddir/src/ninja.o $builddir/src/platform.o $builddir/src/target_exe.o $builddir/src/utils.o $builddir/src/generator.o $builddir/src/target_lib.o $builddir/src/package.o $builddir/src/ext.o $builddir/src/task.o build $builddir/libgrbc.a: archive $builddir/src/file.o $builddir/src/ninja.o $builddir/src/platform.o $builddir/src/target_exe.o $builddir/src/utils.o $builddir/src/generator.o $builddir/src/target_lib.o $builddir/src/package.o $builddir/src/ext.o $builddir/src/task.o $builddir/src/options.o
## Compile: src/main.cc ## ## Compile: src/main.cc ##
build $builddir/src/main.o: cxx src/main.cc build $builddir/src/main.o: cxx src/main.cc
p_cflags = -Iinclude -Ivendor/sol2/include -Iinclude -Ivendor/sol2/include p_cflags = -Iinclude -Ivendor/sol2/include -Iinclude -Ivendor/sol2/include -g -O1
## Link: grbc ## ## Link: grbc ##
build $builddir/grbc: link_cxx $builddir/src/main.o | $builddir/libgrbc.a $builddir/libgrbc_extensions.a 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_linker_flags = -llua -lm -ldl build/libgrbc.a build/libgrbc_extensions.a -Lbuild -Wl,-rpath,build:.
p_cflags = p_cflags = -g -O1
## clean ## ## clean ##
rule clean_task rule clean_task

110
compile_commands.json Normal file
View file

@ -0,0 +1,110 @@
[
{
"directory": "/home/interfiber/dev/grbc",
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/ext_pkg_config.o -MF build/src/ext_pkg_config.o.d -Iinclude -Ivendor/sol2/include -c src/ext_pkg_config.cc -o build/src/ext_pkg_config.o",
"file": "src/ext_pkg_config.cc",
"output": "build/src/ext_pkg_config.o"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/ext_profiles.o -MF build/src/ext_profiles.o.d -Iinclude -Ivendor/sol2/include -c src/ext_profiles.cc -o build/src/ext_profiles.o",
"file": "src/ext_profiles.cc",
"output": "build/src/ext_profiles.o"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "rm -f build/libgrbc_extensions.a; ar crs build/libgrbc_extensions.a build/src/ext_pkg_config.o build/src/ext_profiles.o",
"file": "build/src/ext_pkg_config.o",
"output": "build/libgrbc_extensions.a"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/file.o -MF build/src/file.o.d -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 -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 -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 -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 -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 -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 -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 -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 -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++ -MMD -MT build/src/task.o -MF build/src/task.o.d -Iinclude -Ivendor/sol2/include -c src/task.cc -o build/src/task.o",
"file": "src/task.cc",
"output": "build/src/task.o"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "/usr/lib64/ccache/g++ -MMD -MT build/src/options.o -MF build/src/options.o.d -Iinclude -Ivendor/sol2/include -c src/options.cc -o build/src/options.o",
"file": "src/options.cc",
"output": "build/src/options.o"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "rm -f build/libgrbc.a; ar crs build/libgrbc.a 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 build/src/task.o build/src/options.o",
"file": "build/src/file.o",
"output": "build/libgrbc.a"
},
{
"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 -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.a build/libgrbc_extensions.a -O3 -DNDEBUG -Lbuild -Wl,-rpath,build:. ",
"file": "build/src/main.o",
"output": "build/grbc"
},
{
"directory": "/home/interfiber/dev/grbc",
"command": "",
"file": "build/libgrbc_extensions.a",
"output": "all"
}
]

View file

@ -273,3 +273,7 @@ std::string grbc_platform_file(PlatformType platform_type,
bool grbc_is_ext_loaded(const std::string &extension_name); bool grbc_is_ext_loaded(const std::string &extension_name);
void grbc_task(const TaskConfig &config); void grbc_task(const TaskConfig &config);
bool grbc_has_option(const std::string &option_name);
std::string grbc_get_option(const std::string &option_name);

View file

@ -2,31 +2,34 @@
#include "grbc/ext.h" #include "grbc/ext.h"
#include "grbc/generator.h" #include "grbc/generator.h"
#include "grbc/spec.h" #include "grbc/spec.h"
#include <map>
#include <sol/sol.hpp> #include <sol/sol.hpp>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
struct GState { struct GState {
Platform current_platform{}; Platform current_platform{};
sol::state lua; sol::state lua;
std::vector<GeneratorTask> tasks; std::vector<GeneratorTask> tasks;
std::vector<GeneratorTarget> targets; std::vector<GeneratorTarget> targets;
std::vector<Generator> generators; std::vector<Generator> generators;
std::unordered_map<std::string, Package> packages; std::map<std::string, std::string> options;
std::vector<Extension> extensions; std::unordered_map<std::string, Package> packages;
std::string global_compiler_flags = ""; std::vector<Extension> extensions;
std::string global_linker_flags = " ";
std::string ninja_output; std::string global_compiler_flags = "";
std::string global_linker_flags = " ";
static GState& get() { std::string ninja_output;
static GState state{};
return state; static GState &get() {
} static GState state{};
return state;
}
}; };

View file

@ -84,3 +84,9 @@ Convert a PackageConfig into a Package
## [X] grbc_task(config: TaskConfig) -> Void ## [X] grbc_task(config: TaskConfig) -> Void
Create a task and add it to the build script Create a task and add it to the build script
## [X] grbc_has_option(option_name: String) -> Boolean
Check if the given option was set on the command line
## [X] grbc_get_option(option_name: String) -> String
Get the value of an option

View file

@ -51,17 +51,21 @@ void grbc_profiles_init(sol::state &lua) {
Profile release_with_debug_symbols_profile{}; Profile release_with_debug_symbols_profile{};
release_with_debug_symbols_profile.name = "release_with_debug_symbols"; release_with_debug_symbols_profile.name = "release_with_debug_symbols";
release_with_debug_symbols_profile.compiler_flags = {"-g", "-O3"}; release_with_debug_symbols_profile.compiler_flags = {"-g", "-O3", "-DNDEBUG"};
Profile release_profile{}; Profile release_profile{};
release_profile.name = "release"; release_profile.name = "release";
release_profile.linker_flags = {"-O3"}; release_profile.linker_flags = {"-O3", "-DNDEBUG"};
EXT_profiles_get_profiles().push_back(debug_profile); 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_with_debug_symbols_profile);
EXT_profiles_get_profiles().push_back(release_profile); EXT_profiles_get_profiles().push_back(release_profile);
EXT_profiles_set("debug"); // Always use debug as the default profile if (!grbc_has_option("compiler_profile")) {
EXT_profiles_set("debug"); // Always use debug as the default profile
} else {
EXT_profiles_set(grbc_get_option("compiler_profile"));
}
lua.set("grbc_set_profile", EXT_profiles_set); lua.set("grbc_set_profile", EXT_profiles_set);

View file

@ -1,155 +1,196 @@
#include "grbc/ext_pkg_config.h" #include "grbc/ext_pkg_config.h"
#include "grbc/ext_profiles.h" #include "grbc/ext_profiles.h"
#include "grbc/state.h"
#include <sol/raii.hpp>
#include <sol/table.hpp>
#define SOL_ALL_SAFETIES_ON 1
#include "grbc/helpers.h" #include "grbc/helpers.h"
#include "grbc/spec.h" #include "grbc/spec.h"
#include "grbc/state.h"
#include <cstdlib>
#include <map>
#include <sol/raii.hpp>
#include <sol/sol.hpp> #include <sol/sol.hpp>
#include <sol/table.hpp>
int main() { void print_help() {
log_msg("opening lua libraries..."); printf("GRBC - Graphite Build Configurator\n");
printf("Author: Interfiber <webmaster@interfiber.dev>\n");
printf("Commands:\n");
printf(" gen - Generate build configuration from HConfig\n");
}
auto &lua = GState::get().lua; int main(int argc, char **argv) {
if (argc == 1) {
print_help();
lua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::string, std::exit(EXIT_FAILURE);
sol::lib::io, sol::lib::package, sol::lib::math); }
log_msg("setting up runtime..."); std::map<std::string, std::string> options;
// TargetInfo for (int i = 0; i < argc; i++) {
lua.new_usertype<TargetInfo>("TargetInfo", "name", &TargetInfo::name); std::string arg = argv[i];
// PackageConfig if (arg[0] == '-' && i + 1 < argc) {
lua.new_usertype<PackageConfig>( if (std::string(argv[i + 1]).empty()) continue;
"PackageConfig", sol::constructors<PackageConfig(sol::table)>(), "name",
&PackageConfig::name, "libraries", &PackageConfig::libraries,
"include_dirs", &PackageConfig::include_dirs, "compile_flags",
&PackageConfig::compile_flags, "linker_flags",
&PackageConfig::linker_flags);
// GlobalConfig arg.erase(arg.begin());
lua.new_usertype<GlobalConfig>("GlobalConfig", "engine_version",
&GlobalConfig::engine_version, "architecture",
&GlobalConfig::architecture, "target_config",
&GlobalConfig::platform_config);
// Platform options.insert({ arg, std::string(argv[i + 1]) });
lua.new_usertype<Platform>("Platform", "name", &Platform::name,
"cxx_compiler", &Platform::cxx_compiler,
"cc_compiler", &Platform::cc_compiler,
"platform_type", &Platform::platform_type,
"is_64bit", &Platform::is_64bit);
// PlatformType log_msg(("found option: " + arg + " = " + std::string(argv[i + 1])).c_str());
lua.new_enum<PlatformType>("PlatformType", {{"Win32", PlatformType_Win32}, }
{"Linux", PlatformType_Linux}}); }
// LanguageType GState::get().options = options;
lua.new_enum<LanguageType>(
"LanguageType", {{"Cpp", LanguageType_CPP}, {"C", LanguageType_C}});
// LibraryType if (std::string(argv[1]) == "gen") {
lua.new_enum<LibraryType>("LibraryType", {{"Static", LibraryType_Static}, log_msg("running grbc generator...");
{"Shared", LibraryType_Shared}});
// ExecutableConfig log_msg("opening lua libraries...");
lua.new_usertype<ExecutableConfig>(
"ExecutableConfig", sol::constructors<ExecutableConfig(sol::table)>(),
"name", &ExecutableConfig::name, "files", &ExecutableConfig::files,
"requirements", &ExecutableConfig::requirements, "compile_flags",
&ExecutableConfig::compile_flags, "linker_flags",
&ExecutableConfig::linker_flags, "include_dirs",
&ExecutableConfig::include_dirs, "language_type",
&ExecutableConfig::language_type);
// LibraryConfig auto &lua = GState::get().lua;
lua.new_usertype<LibraryConfig>(
"LibraryConfig", sol::constructors<LibraryConfig(sol::table)>(), "name",
&LibraryConfig::name, "files", &LibraryConfig::files, "requirements",
&LibraryConfig::requirements, "compile_flags",
&LibraryConfig::compile_flags, "linker_flags",
&LibraryConfig::linker_flags, "include_dirs",
&LibraryConfig::include_dirs, "language_type",
&LibraryConfig::language_type, "lib_type", &LibraryConfig::lib_type,
"package_config", &LibraryConfig::package_config);
// Package lua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::string,
lua.new_usertype<Package>("Package", sol::constructors<Package(sol::table)>(), sol::lib::io, sol::lib::package, sol::lib::math);
"name", &Package::name, "compiler_flags",
&Package::compiler_flags, "linker_flags",
&Package::linker_flags);
// TaskConfig log_msg("setting up runtime...");
lua.new_usertype<TaskConfig>(
"TaskConfig", sol::constructors<TaskConfig(sol::table)>(), "name",
&TaskConfig::name, "task_id", &TaskConfig::task_id, "shell_script",
&TaskConfig::shell_script);
lua.set("grbc_want_version", grbc_want_version); // TargetInfo
lua.set("grbc_exception", grbc_exception); lua.new_usertype<TargetInfo>("TargetInfo", "name", &TargetInfo::name);
lua.set("grbc_get_config", grbc_get_config);
lua.set("grbc_file", grbc_file);
lua.set("grbc_executable", grbc_executable);
lua.set("grbc_library", grbc_library);
lua.set("grbc_load_platform", grbc_load_platform);
lua.set("grbc_set_platform", grbc_set_platform);
lua.set("grbc_find_compiler", grbc_find_compiler);
lua.set("grbc_build", grbc_build);
lua.set("grbc_replace_string", grbc_replace_string);
lua.set("grbc_object_file", grbc_object_file);
lua.set("grbc_include_dirs_to_clflags", grbc_include_dirs_to_cflags);
lua.set("grbc_log", grbc_log);
lua.set("grbc_is_32bit", grbc_is_32bit);
lua.set("grbc_is_64bit", grbc_is_64bit);
lua.set("grbc_is_linux", grbc_is_linux);
lua.set("grbc_is_win32", grbc_is_win32);
lua.set("grbc_get_platform", grbc_get_platform);
lua.set("grbc_compiler_define", grbc_compiler_define);
lua.set("grbc_get_lib_extension", grbc_get_lib_extension);
lua.set("grbc_bake_package_config", grbc_bake_package_config);
lua.set("grbc_pkg", grbc_pkg);
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);
lua.set("grbc_task", grbc_task);
// Load generators // PackageConfig
lua.new_usertype<PackageConfig>(
"PackageConfig", sol::constructors<PackageConfig(sol::table)>(), "name",
&PackageConfig::name, "libraries", &PackageConfig::libraries,
"include_dirs", &PackageConfig::include_dirs, "compile_flags",
&PackageConfig::compile_flags, "linker_flags",
&PackageConfig::linker_flags);
GState::get().generators.push_back( // GlobalConfig
{.name = "ninja", .func = ninja_generator}); lua.new_usertype<GlobalConfig>(
"GlobalConfig", "engine_version", &GlobalConfig::engine_version,
"architecture", &GlobalConfig::architecture, "target_config",
&GlobalConfig::platform_config);
// Load default extensions // Platform
lua.new_usertype<Platform>("Platform", "name", &Platform::name,
"cxx_compiler", &Platform::cxx_compiler,
"cc_compiler", &Platform::cc_compiler,
"platform_type", &Platform::platform_type,
"is_64bit", &Platform::is_64bit);
// PlatformType
lua.new_enum<PlatformType>("PlatformType", {{"Win32", PlatformType_Win32},
{"Linux", PlatformType_Linux}});
// LanguageType
lua.new_enum<LanguageType>(
"LanguageType", {{"Cpp", LanguageType_CPP}, {"C", LanguageType_C}});
// LibraryType
lua.new_enum<LibraryType>("LibraryType", {{"Static", LibraryType_Static},
{"Shared", LibraryType_Shared}});
// ExecutableConfig
lua.new_usertype<ExecutableConfig>(
"ExecutableConfig", sol::constructors<ExecutableConfig(sol::table)>(),
"name", &ExecutableConfig::name, "files", &ExecutableConfig::files,
"requirements", &ExecutableConfig::requirements, "compile_flags",
&ExecutableConfig::compile_flags, "linker_flags",
&ExecutableConfig::linker_flags, "include_dirs",
&ExecutableConfig::include_dirs, "language_type",
&ExecutableConfig::language_type);
// LibraryConfig
lua.new_usertype<LibraryConfig>(
"LibraryConfig", sol::constructors<LibraryConfig(sol::table)>(), "name",
&LibraryConfig::name, "files", &LibraryConfig::files, "requirements",
&LibraryConfig::requirements, "compile_flags",
&LibraryConfig::compile_flags, "linker_flags",
&LibraryConfig::linker_flags, "include_dirs",
&LibraryConfig::include_dirs, "language_type",
&LibraryConfig::language_type, "lib_type", &LibraryConfig::lib_type,
"package_config", &LibraryConfig::package_config);
// Package
lua.new_usertype<Package>(
"Package", sol::constructors<Package(sol::table)>(), "name",
&Package::name, "compiler_flags", &Package::compiler_flags,
"linker_flags", &Package::linker_flags);
// TaskConfig
lua.new_usertype<TaskConfig>(
"TaskConfig", sol::constructors<TaskConfig(sol::table)>(), "name",
&TaskConfig::name, "task_id", &TaskConfig::task_id, "shell_script",
&TaskConfig::shell_script);
lua.set("grbc_want_version", grbc_want_version);
lua.set("grbc_exception", grbc_exception);
lua.set("grbc_get_config", grbc_get_config);
lua.set("grbc_file", grbc_file);
lua.set("grbc_executable", grbc_executable);
lua.set("grbc_library", grbc_library);
lua.set("grbc_load_platform", grbc_load_platform);
lua.set("grbc_set_platform", grbc_set_platform);
lua.set("grbc_find_compiler", grbc_find_compiler);
lua.set("grbc_build", grbc_build);
lua.set("grbc_replace_string", grbc_replace_string);
lua.set("grbc_object_file", grbc_object_file);
lua.set("grbc_include_dirs_to_clflags", grbc_include_dirs_to_cflags);
lua.set("grbc_log", grbc_log);
lua.set("grbc_is_32bit", grbc_is_32bit);
lua.set("grbc_is_64bit", grbc_is_64bit);
lua.set("grbc_is_linux", grbc_is_linux);
lua.set("grbc_is_win32", grbc_is_win32);
lua.set("grbc_get_platform", grbc_get_platform);
lua.set("grbc_compiler_define", grbc_compiler_define);
lua.set("grbc_get_lib_extension", grbc_get_lib_extension);
lua.set("grbc_bake_package_config", grbc_bake_package_config);
lua.set("grbc_pkg", grbc_pkg);
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);
lua.set("grbc_task", grbc_task);
lua.set("grbc_has_option", grbc_has_option);
lua.set("grbc_get_option", grbc_get_option);
// Load generators
GState::get().generators.push_back(
{.name = "ninja", .func = ninja_generator});
// Load default extensions
#if !defined(_WIN32) #if !defined(_WIN32)
grbc_register_ext(grbc_pkg_config()); grbc_register_ext(grbc_pkg_config());
#endif #endif
grbc_register_ext(grbc_profiles()); grbc_register_ext(grbc_profiles());
// Detect platform // Detect platform
log_msg("autodetecting platform..."); log_msg("autodetecting platform...");
#if defined(WIN32) #if defined(WIN32)
GState::get().current_platform.platform_type = PlatformType_Win32; GState::get().current_platform.platform_type = PlatformType_Win32;
GState::get().current_platform.name = "Windows"; GState::get().current_platform.name = "Windows";
#elif defined(__linux__) #elif defined(__linux__)
GState::get().current_platform.platform_type = PlatformType_Linux; GState::get().current_platform.platform_type = PlatformType_Linux;
GState::get().current_platform.name = "Linux"; GState::get().current_platform.name = "Linux";
#endif #endif
#if defined(ENVIRONMENT32) #if defined(ENVIRONMENT32)
GState::get().current_platform.is_64bit = false; GState::get().current_platform.is_64bit = false;
#endif #endif
// Default compiler is g++ // Default compiler is g++
GState::get().current_platform.cc_compiler = grbc_find_compiler("gcc"); GState::get().current_platform.cc_compiler = grbc_find_compiler("gcc");
GState::get().current_platform.cxx_compiler = grbc_find_compiler("g++"); GState::get().current_platform.cxx_compiler = grbc_find_compiler("g++");
log_msg("loading HConfig..."); log_msg("loading HConfig...");
lua.script_file("HConfig"); lua.script_file("HConfig");
} else {
printf("unknown command\n");
std::exit(EXIT_FAILURE);
}
} }

22
src/options.cc Normal file
View file

@ -0,0 +1,22 @@
#include "grbc/spec.h"
#include "grbc/state.h"
bool grbc_has_option(const std::string &option_name) {
for (auto &k : GState::get().options) {
if (k.first == option_name)
return true;
}
return false;
}
std::string grbc_get_option(const std::string &option_name) {
for (auto &k : GState::get().options) {
if (k.first == option_name)
return k.second;
}
grbc_exception("Failed to find option with name '" + option_name + "'");
return "";
}

View file

@ -5,6 +5,10 @@
TargetInfo grbc_library(const LibraryConfig &library_config) { TargetInfo grbc_library(const LibraryConfig &library_config) {
TargetInfo target_config{}; TargetInfo target_config{};
if (library_config.name[0] != 'l' && library_config.name[1] != 'i' && library_config.name[2] != 'b') {
grbc_exception("library names are mandated to start with 'lib'");
}
std::string lib_name = library_config.name; std::string lib_name = library_config.name;
lib_name += grbc_get_lib_extension(library_config.lib_type); lib_name += grbc_get_lib_extension(library_config.lib_type);