libraries + self building + work on extensions
This commit is contained in:
parent
b6ee9d0dc3
commit
3ddb2943bc
14 changed files with 97 additions and 39 deletions
1
src/ext.cc
Normal file
1
src/ext.cc
Normal file
|
@ -0,0 +1 @@
|
|||
#include "grbc/ext.h"
|
|
@ -5,6 +5,8 @@
|
|||
#include <fstream>
|
||||
|
||||
void grbc_build(const std::string &generator_id) {
|
||||
GState::get().global_linker_flags += "-L" + grbc_get_config().build_dir + " -Wl,-rpath," + grbc_get_config().build_dir + ":. ";
|
||||
|
||||
log_msg(("finding generator with name: " + generator_id).c_str());
|
||||
|
||||
for (auto &gen : GState::get().generators) {
|
||||
|
|
25
src/ninja.cc
25
src/ninja.cc
|
@ -74,7 +74,7 @@ ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd) {
|
|||
|
||||
result += "build $builddir/" + compile_cmd.object_file + ": " +
|
||||
compiler_rule + " " + compile_cmd.source_file + "\n";
|
||||
result += " p_cflags = " + compile_cmd.compiler_flags + "\n\n";
|
||||
result += " p_cflags = " + compile_cmd.compiler_flags + GState::get().global_compiler_flags + "\n\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ ninja_build_rule_link_lib_target(const GeneratorLinkTargetCommand &link_cmd) {
|
|||
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
||||
file_list + "\n";
|
||||
|
||||
result += " p_linker_flags = " + link_cmd.linker_flags + " -shared\n";
|
||||
result += " p_cflags = \n\n";
|
||||
result += " p_linker_flags = " + link_cmd.linker_flags + " -shared" + GState::get().global_linker_flags + "\n";
|
||||
result += " p_cflags = " + GState::get().global_compiler_flags + "\n\n";
|
||||
} else {
|
||||
result += "build $builddir/" + link_cmd.output_name + ": archive " +
|
||||
file_list + "\n\n";
|
||||
|
@ -124,12 +124,25 @@ ninja_build_rule_link_exe_target(const GeneratorLinkTargetCommand &link_cmd) {
|
|||
file_list += "$builddir/" + file + " ";
|
||||
}
|
||||
|
||||
std::string lib_list;
|
||||
|
||||
if (!link_cmd.libraries.empty()) {
|
||||
lib_list = "| ";
|
||||
for (auto &lib : link_cmd.libraries) {
|
||||
if (lib.empty()) continue;
|
||||
|
||||
lib_list += "$builddir/" + lib + " ";
|
||||
}
|
||||
|
||||
lib_list.pop_back();
|
||||
}
|
||||
|
||||
file_list.pop_back();
|
||||
|
||||
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
||||
file_list + "\n";
|
||||
result += " p_linker_flags = " + link_cmd.linker_flags + "\n";
|
||||
result += " p_cflags = \n\n";
|
||||
file_list + " " + lib_list + "\n";
|
||||
result += " p_linker_flags = " + link_cmd.linker_flags + GState::get().global_linker_flags + "\n";
|
||||
result += " p_cflags = " + GState::get().global_compiler_flags + "\n\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ Package grbc_bake_package_config(const PackageConfig &config) {
|
|||
pkg.compiler_flags += compiler_flag + " ";
|
||||
}
|
||||
|
||||
for (auto &include_dir : config.include_dirs) {
|
||||
pkg.compiler_flags += "-I" + include_dir + " ";
|
||||
}
|
||||
|
||||
// Remove trailing whitespace
|
||||
|
||||
if (pkg.compiler_flags.back() == ' ')
|
||||
|
|
|
@ -43,8 +43,8 @@ std::string grbc_find_compiler(const std::string &compiler_name) {
|
|||
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");
|
||||
return (std::filesystem::path(current_path) /
|
||||
std::filesystem::path(compiler_name + ".exe")).generic_string();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,12 @@ TargetInfo grbc_executable(const ExecutableConfig &executable_config) {
|
|||
|
||||
compiler_args += grbc_include_dirs_to_cflags(executable_config.include_dirs);
|
||||
|
||||
std::vector<std::string> libraries;
|
||||
|
||||
for (auto &lib : executable_config.requirements) {
|
||||
libraries.push_back(lib.file_name);
|
||||
}
|
||||
|
||||
GeneratorTarget target{};
|
||||
|
||||
std::vector<std::string> object_files;
|
||||
|
@ -53,6 +59,7 @@ TargetInfo grbc_executable(const ExecutableConfig &executable_config) {
|
|||
executable_link_cmd.object_files = object_files;
|
||||
executable_link_cmd.output_name = exe_name;
|
||||
executable_link_cmd.target_type = GeneratorTargetType_Executable;
|
||||
executable_link_cmd.libraries = libraries;
|
||||
|
||||
target.link_target_commands.push_back(executable_link_cmd);
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
|||
compiler_args += compiler_arg + " ";
|
||||
}
|
||||
|
||||
if (library_config.lib_type == LibraryType_Shared) {
|
||||
compiler_args += "-fPIC ";
|
||||
}
|
||||
|
||||
// Include directories
|
||||
|
||||
compiler_args += grbc_include_dirs_to_cflags(library_config.include_dirs);
|
||||
|
@ -44,21 +48,27 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
|||
target.compile_commands.push_back(compile_cmd);
|
||||
}
|
||||
|
||||
// Libraries which need to be built before us
|
||||
|
||||
std::vector<std::string> libraries;
|
||||
|
||||
for (auto &lib : library_config.requirements) {
|
||||
libraries.push_back(lib.file_name);
|
||||
}
|
||||
|
||||
// Generate package config
|
||||
PackageConfig pkg_cfg{};
|
||||
pkg_cfg.name = library_config.name;
|
||||
pkg_cfg.libraries = library_config.package_config.libraries;
|
||||
pkg_cfg.include_dirs = library_config.include_dirs;
|
||||
|
||||
if (library_config.lib_type == LibraryType_Static) {
|
||||
pkg_cfg.linker_flags.push_back(grbc_get_config().build_dir + "/" + lib_name);
|
||||
}
|
||||
|
||||
// FIXME: Shared library linker flags
|
||||
pkg_cfg.linker_flags.push_back(grbc_get_config().build_dir + "/" + lib_name);
|
||||
|
||||
if (!pkg_cfg.name.empty()) {
|
||||
GState::get().packages.insert(
|
||||
{pkg_cfg.name, grbc_bake_package_config(pkg_cfg)});
|
||||
Package pkg = grbc_bake_package_config(pkg_cfg);
|
||||
pkg.file_name = lib_name;
|
||||
|
||||
GState::get().packages.insert({pkg_cfg.name, pkg});
|
||||
}
|
||||
|
||||
GeneratorLinkTargetCommand link_target{};
|
||||
|
@ -72,6 +82,7 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
|||
link_target.object_files = object_files;
|
||||
link_target.linker_flags = linker_args;
|
||||
link_target.output_name = lib_name;
|
||||
link_target.libraries = libraries;
|
||||
|
||||
target.link_target_commands.push_back(link_target);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue