40 if (
arg != std::string(
"")) {
46 if (
arg != std::string(
"")) {
47 this->link_args.push_back(
arg);
52 std::string tmp =
"-D";
54 if (def != std::string(
"")) {
57 if (val != std::string(
"")) {
61 this->add_compile_arg(tmp);
66 std::string tmp =
"-U";
68 if (def != std::string(
"")) {
70 this->add_compile_arg(tmp);
75 std::string tmp =
"-include \"";
77 if (inc != std::string(
"")) {
80 this->add_compile_arg(tmp);
85 std::string tmp =
"-l";
87 if (
lib != std::string(
"")) {
89 this->add_link_arg(tmp);
94 std::string itmp =
"-I";
95 std::string ltmp =
"-L";
97 if ((inc != std::string(
"")) && (
lib != std::string(
""))) {
100 this->add_compile_arg(itmp);
101 this->add_link_arg(ltmp);
106 if (task_ != std::string(
"")) {
107 this->required.push_back_check(task_, run_stage);
113 this->add_compile_arg(
"-Wall");
114 this->add_compile_arg(
"-Wextra");
115 this->add_compile_arg(
"-Wno-comments");
119 this->add_compile_arg(
"-fanalyzer");
120 this->add_compile_arg(
"-Wanalyzer-too-complex");
124 this->add_compile_arg(
"-Werror");
128 if (std_ != std::string(
"")) {
130 this->add_compile_arg(std::string(
"-std=") + std_);
138 this->depends.push_back(target);
141 std::string headers_path) {
147 this->project_deps.push_back(dep);
150 this->add_compile_arg(
"-pg");
151 this->add_link_arg(
"-pg");
157 this->add_compile_arg(
"-pthread");
158 this->add_link_arg(
"-pthread");
161 this->pkg_config_include_entries.push_back(
id);
164 this->hasher = hasher;
173 this->dependency_list.push_back(dep);
178 if (path != std::string(
"")) {
184 this->targets.push_back(p);
189 if (path != std::string(
"")) {
195 this->targets.push_back(p);
203 unsigned long pos = file.find_last_of(
".");
205 file = file.substr(0, pos);
207 while (file.find(
"/") != std::string::npos) {
208 file.replace(file.find(
"/"), std::string(
"/").size(),
".");
219 std::vector<std::string> objects, filelist;
220 bool not_use_hash =
false;
222 for (
auto elem : this->targets) {
225 for (
auto file : files) {
233 for (
auto elem : filelist) {
235 for_recomp.
push_back(elem, this->gen_out_file(elem));
236 objects.push_back(this->gen_out_file(elem));
237 }
catch (std::exception& e) {
242 if (this->dummy ==
true) {
245 }
else if (this->gen_file_list_for_linking) {
250 for_recomp = this->hasher->get_files_for_recompilation(filelist, objects);
251 not_use_hash =
false;
364 if (not_use_hash ==
true) {
366 for (
size_t i = 0; i < filelist.size(); i++) {
367 for_recomp.
push_back(filelist.at(i), objects.at(i));
370 for (
auto elem : for_recomp) {
371 ret.
push_back(this->cmd_str(elem.key), this->cmd_str(elem.data));
374 for (
unsigned int i = 0; i < ret.
size(); i++) {
380 bool tmp = this->force;
382 auto ret = this->gen_file_list(
true);
387 std::string ret =
"";
388 for (
auto arg : this->compiler_args) {
395 std::string stat_lib) {
397 std::string base =
"";
398 if (!this->gen_out_name_without_base_path) {
402 if (this->name != std::string(
"")) {
441 return this->cmd_str(base);
445 while (in.find(
" ") != std::string::npos) {
446 in.replace(in.find(
" "), std::string(
" ").size(),
"\\^");
449 while (in.find(
"\\^") != std::string::npos) {
450 in.replace(in.find(
"\\^"), std::string(
"\\^").size(),
"\\ ");
456 if (this->
id == std::string(
""))
479 for (
auto elem : this->project_deps) {
481 std::string
cmd =
"cd " + elem.path +
" && ./CBuild.run -b " + elem.id;
492 this->add_library_include(elem.name);
493 this->add_compile_arg(
" -Wl,-rpath,\"\\$ORIGIN/../../../" +
CBUILD_CACHE_DIR +
"/" +
498 return std::array<std::string, 3>{this->compiler, this->linker, this->packer};
511 if (!this->stdargs_lock) {
514 this->compiler_args.push_back(
"-fPIC");
515 this->link_args.push_back(
"-fPIC");
521 this->link_args.push_back(
"-shared");
525 std::string
lib = this->gen_out_name();
526 int pos =
lib.find_last_of(
'/');
527 lib =
lib.substr(pos + 1);
528 if (this->version_major < 0) {
529 this->add_link_arg(
" -Wl,-soname," +
lib);
531 this->add_link_arg(
" -Wl,-soname," +
lib + std::string(
".") +
532 std::to_string(this->version_major));
536 for (std::string
id : this->depends) {
538 if (target != NULL) {
540 auto out_path = target->gen_out_name();
541 unsigned int end_slash = out_path.find_last_of(
'/');
542 unsigned int end_dot = out_path.find_last_of(
'.');
543 std::string out = out_path.substr(end_slash + 4, end_dot - end_slash - 4);
545 this->add_library_include(out);
547 this->add_library_dir(
".",
CBUILD_BUILD_DIR +
"/" + target->get_id() +
"/" +
549 this->add_link_arg(
"-Wl,-rpath,\"\\$ORIGIN/../../" + target->get_id() +
"/" +
554 for (
auto pkg : this->pkg_config_include_entries) {
560 this->add_link_arg(info.
largs);
561 this->add_compile_arg(info.
cargs);
564 for (
auto dep : this->dependency_list) {
565 this->add_link_arg(dep->largs());
566 this->add_compile_arg(dep->cargs());
568 this->stdargs_lock =
true;
576 for (
auto dep : this->dependency_list) {
577 if (dep->need_prepare()) {
587 this->compiler_args.push_back(
"-g");
595 for (
unsigned int i = 0; i < this->required.size(); i++) {
596 auto elem = this->required.at(i);
603 for (std::string
id : this->depends) {
606 if (target != NULL) {
607 target->call(args, force, debug, dummy);
611 bool meta_error =
false;
613 if (this->hasher->compare_and_set_output_file(this->gen_out_name()) != 0) {
617 if (this->hasher->compare_and_set_cargs(this->compiler_args) != 0) {
621 if (this->hasher->compare_and_set_largs(this->link_args) != 0) {
625 if (this->hasher->compare_and_set_commands(this->compiler, this->linker, this->packer) != 0) {
656 this->gen_out_name_without_base_path =
true;
659 this->gen_out_name() +
"." + std::to_string(this->version_major));
660 this->gen_out_name_without_base_path =
false;
663 if (meta_error ==
true) {
664 this->hasher->set_target_meta(this->compiler_args, this->link_args, this->gen_out_name(),
665 this->compiler, this->linker, this->packer);
669 for (
unsigned int i = 0; i < this->required.size(); i++) {
670 auto elem = this->required.at(i);
678 CBuild::print(
"Starting \"" + ((this->name ==
"") ? this->
id : this->name) +
"\" ",
681 std::string pargs =
"";
683 for (
auto elem : *args) {
690 cmd = this->gen_out_name();
699 CBuild::print(
"Starting \"" + ((this->name ==
"") ? this->
id : this->name) +
700 "\" toolchain in debug mode ",
703 this->call(args,
true,
true);
705 std::string ppargs =
"";
707 for (
auto elem : *pargs) {
715 cmd += this->gen_out_name();
#define CBUILD_BUILD_OUT_DIR
Build out in build/toolchain.
#define CBUILD_PROJECT_DEPS_DIR
For other included project, in cache dir.
#define CBUILD_BUILD_CACHE_DIR
Object cache in build/toolchain.
#define CBUILD_METADATA_FOLDER
Metadata folder for targets.
#define CBUILD_CACHE_DIR
Cache directory of CBuild.
#define CBUILD_PROJECT_DEPS_HEADERS
For other included project, in cache dir.
#define CBUILD_BUILD_DIR
Build directory of CBuild.
Build metadata config file.
Simple map implementation with some stack operation added.
__SIZE_TYPE__ size()
Size of map.
void clear()
Erase all elements (simmilar to std::vector::clear())
void push_back(lib::mapData< _K, _D > element)
Push new element to map, stack operation ! Dangerous not perform chak if this elemnt exists in map.
lib::mapData< _K, _D > at(__SIZE_TYPE__ i)
Array operation, get element at index.
Hasher base class and some helper functions This file implements some helper funtions,...
Custom implementation of map datatype.
CBuild::Toolchain * GetToolchain(std::string name, bool force=false)
Get the registered toolchain.
void CallTask(std::string name, std::vector< std::string > args)
Run tasks.
bool exists(std::string path)
Check if file exists.
bool create(std::vector< std::string > paths, CBuild::fs::type what)
Create element.
std::string normalize_relative_path(std::string path, std::string base_path="")
Get absolute path to file using relative path and base path.
@ DIR
Alias for DIRECTORY.
std::vector< std::string > dir(std::string path, std::string search)
Search files using provided regex.
void print(std::string msg, color fg=CBuild::WHITE)
Print colored text to STDOUT.
stage
Type of depencesies for toolchain.
bool get_pkg_info(CBuild::package_info *package)
Get the package info from pkg-config database.
int system(std::string cmd)
Call stdlib system() and print cmd to shell.
void print_full(std::string msg, color fg=CBuild::WHITE)
Print colored text to STDOUT if verbose flag is set.
pkg-config interface header Provides interface to pkg-config cli tool, including some parts of error ...
Custom print that support color codes.
Command for compile_commands.json.
Package info struct for data for pkg-config.
std::string largs
Package link args.
std::string name
Package name.
std::string cargs
Package compile args.