extension work + static library linking
This commit is contained in:
parent
ffa0f40652
commit
b6ee9d0dc3
20 changed files with 568 additions and 131 deletions
81
src/target_lib.cc
Normal file
81
src/target_lib.cc
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "grbc/generator.h"
|
||||
#include "grbc/spec.h"
|
||||
#include "grbc/state.h"
|
||||
|
||||
TargetInfo grbc_library(const LibraryConfig &library_config) {
|
||||
TargetInfo target_config{};
|
||||
|
||||
std::string lib_name = library_config.name;
|
||||
lib_name += grbc_get_lib_extension(library_config.lib_type);
|
||||
|
||||
std::string compiler_args;
|
||||
std::string linker_args;
|
||||
|
||||
for (auto &package : library_config.requirements) {
|
||||
compiler_args += package.compiler_flags + " ";
|
||||
linker_args += package.linker_flags + " ";
|
||||
}
|
||||
|
||||
for (auto &linker_arg : library_config.linker_flags) {
|
||||
linker_args += linker_arg + " ";
|
||||
}
|
||||
|
||||
for (auto &compiler_arg : library_config.compile_flags) {
|
||||
compiler_args += compiler_arg + " ";
|
||||
}
|
||||
|
||||
// Include directories
|
||||
|
||||
compiler_args += grbc_include_dirs_to_cflags(library_config.include_dirs);
|
||||
|
||||
GeneratorTarget target{};
|
||||
|
||||
std::vector<std::string> object_files;
|
||||
|
||||
for (auto &src_file : library_config.files) {
|
||||
GeneratorCompileCommand compile_cmd{};
|
||||
compile_cmd.source_file = src_file;
|
||||
compile_cmd.object_file = grbc_object_file(src_file);
|
||||
compile_cmd.compiler_flags = compiler_args;
|
||||
compile_cmd.language_type = library_config.language_type;
|
||||
|
||||
object_files.push_back(compile_cmd.object_file);
|
||||
|
||||
target.compile_commands.push_back(compile_cmd);
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
if (!pkg_cfg.name.empty()) {
|
||||
GState::get().packages.insert(
|
||||
{pkg_cfg.name, grbc_bake_package_config(pkg_cfg)});
|
||||
}
|
||||
|
||||
GeneratorLinkTargetCommand link_target{};
|
||||
|
||||
if (library_config.lib_type == LibraryType_Shared) {
|
||||
link_target.target_type = GeneratorTargetType_SharedLibrary;
|
||||
} else {
|
||||
link_target.target_type = GeneratorTargetType_StaticLibrary;
|
||||
}
|
||||
|
||||
link_target.object_files = object_files;
|
||||
link_target.linker_flags = linker_args;
|
||||
link_target.output_name = lib_name;
|
||||
|
||||
target.link_target_commands.push_back(link_target);
|
||||
|
||||
GState::get().targets.push_back(target);
|
||||
|
||||
return target_config;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue