CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
Build.cpp
Go to the documentation of this file.
1
21// C++ librarries
22#include "../../headers/map.hpp"
23#include "array"
24#include "stdlib.h"
25#include "string"
26#include "vector"
27// Project headers
37/* Build.hpp - arguments */
39 // Push compiler arg if it is not an empty string
40 if (arg != std::string("")) {
41 this->compiler_args.push_back(arg);
42 }
43}
45 // Push linker arg if it is not an empty string
46 if (arg != std::string("")) {
47 this->link_args.push_back(arg);
48 }
49}
50void CBuild::Toolchain::add_define(std::string def, std::string val) {
51 // Create buffer with base of define
52 std::string tmp = "-D";
53 // Add define only if it is not empty
54 if (def != std::string("")) {
55 tmp += def;
56 // If define value is something, add it
57 if (val != std::string("")) {
58 tmp += '=';
59 tmp += val;
60 }
61 this->add_compile_arg(tmp);
62 }
63}
64void CBuild::Toolchain::add_undef(std::string def) {
65 // Create buffer with base of undefine
66 std::string tmp = "-U";
67 // Add undefine only if it is not empty
68 if (def != std::string("")) {
69 tmp += def;
70 this->add_compile_arg(tmp);
71 }
72}
73void CBuild::Toolchain::add_include(std::string inc) {
74 // Create buffer with base of include
75 std::string tmp = "-include \"";
76 // Add only if incude is not empty
77 if (inc != std::string("")) {
78 tmp += inc;
79 tmp += "\"";
80 this->add_compile_arg(tmp);
81 }
82}
84 // Create buffer with base of lib link
85 std::string tmp = "-l";
86 // Add only if lib name is not emoty
87 if (lib != std::string("")) {
88 tmp += lib;
89 this->add_link_arg(tmp);
90 }
91}
92void CBuild::Toolchain::add_library_dir(std::string inc, std::string lib) {
93 // Create buffers with base of include and link pathes
94 std::string itmp = "-I";
95 std::string ltmp = "-L";
96 // Only if two pathes not empty
97 if ((inc != std::string("")) && (lib != std::string(""))) {
98 itmp += inc;
99 ltmp += lib;
100 this->add_compile_arg(itmp);
101 this->add_link_arg(ltmp);
102 }
103}
104void CBuild::Toolchain::add_requirment(std::string task_, CBuild::stage run_stage) {
105 // Add required task only if it's id is non-empty
106 if (task_ != std::string("")) {
107 this->required.push_back_check(task_, run_stage);
108 }
109}
111 // Push all arguments for normal waning (-Wall, -Wextra but
112 // -Wno-comments)
113 this->add_compile_arg("-Wall");
114 this->add_compile_arg("-Wextra");
115 this->add_compile_arg("-Wno-comments");
116}
118 // Push all aruments needed for static anlization of code
119 this->add_compile_arg("-fanalyzer");
120 this->add_compile_arg("-Wanalyzer-too-complex");
121}
123 // Push argument for treating warning as errors
124 this->add_compile_arg("-Werror");
125}
126void CBuild::Toolchain::set_standart(std::string std_) {
127 // Only if non empty
128 if (std_ != std::string("")) {
129 // Push corectly formated stadart arg
130 this->add_compile_arg(std::string("-std=") + std_);
131 }
132}
136void CBuild::Toolchain::depends_on(std::string target) {
137 // Push target in list of dependencies
138 this->depends.push_back(target);
139}
140void CBuild::Toolchain::depends_on_project(std::string path, std::string name, std::string id,
141 std::string headers_path) {
143 dep.headers_path = headers_path;
144 dep.id = id;
145 dep.name = name;
146 dep.path = path;
147 this->project_deps.push_back(dep);
148}
150 this->add_compile_arg("-pg");
151 this->add_link_arg("-pg");
152}
154 this->version_major = version;
155}
157 this->add_compile_arg("-pthread");
158 this->add_link_arg("-pthread");
159}
161 this->pkg_config_include_entries.push_back(id);
162}
164 this->hasher = hasher;
165}
166void CBuild::Toolchain::set_name(std::string name) {
167 this->name = name;
168}
169void CBuild::Toolchain::set_id(std::string id) {
170 this->id = id;
171}
173 this->dependency_list.push_back(dep);
174}
175/* Build.hpp - files */
176void CBuild::Toolchain::add_file(std::string path) {
177 // If path is non-empty
178 if (path != std::string("")) {
179 // Create new path to file
180 CBuild::Path p;
181 p.folder = false;
182 p.path = path;
183 // Push it to list of targets for compilation
184 this->targets.push_back(p);
185 }
186}
187void CBuild::Toolchain::add_folder(std::string path) {
188 // Only if path is non-empty
189 if (path != std::string("")) {
190 // Create new path to folder
191 CBuild::Path p;
192 p.folder = true;
193 p.path = path;
194 // Push it to list of targets for compilation
195 this->targets.push_back(p);
196 }
197}
198/* Build.hpp - helper */
199std::string CBuild::Toolchain::gen_out_file(std::string file) {
200 // path to base diretory for out files
201 std::string base = CBUILD_BUILD_DIR + "/" + this->id + "/" + CBUILD_BUILD_CACHE_DIR + "/";
202 // Find dot in file name
203 unsigned long pos = file.find_last_of(".");
204 // Cut it out
205 file = file.substr(0, pos);
206 // Replace all slashes by dots
207 while (file.find("/") != std::string::npos) {
208 file.replace(file.find("/"), std::string("/").size(), ".");
209 }
210 // Add .o extension
211 file += ".o";
212 // Return full path
213 base += file;
214 return base;
215}
217 // File - object
219 std::vector<std::string> objects, filelist;
220 bool not_use_hash = false;
221 // Collect all files from directories
222 for (auto elem : this->targets) {
223 if (elem.folder) {
224 auto files = CBuild::fs::dir(elem.path);
225 for (auto file : files) {
226 filelist.push_back(CBuild::fs::normalize_relative_path(file));
227 }
228 } else {
229 filelist.push_back(CBuild::fs::normalize_relative_path(elem.path));
230 }
231 }
232 // Create objects list
233 for (auto elem : filelist) {
234 try {
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) {
238 }
239 }
240 // If we do dummy, compilation, we do force compilation, assumption based on
241 // internal CBuild structure, else get hashes
242 if (this->dummy == true) {
243 // for_recomp = filelist;
244 not_use_hash = true;
245 } else if (this->gen_file_list_for_linking) {
246 // for_recomp = filelist;
247 not_use_hash = true;
248 } else {
249 // for_recomp = CBuild::get_files(filelist, this->id);
250 for_recomp = this->hasher->get_files_for_recompilation(filelist, objects);
251 not_use_hash = false;
252 }
253 // Real force, we need to recalculate hashes here
254 if (this->force) {
255 // for_recomp = filelist;
256 not_use_hash = true;
257 }
258 // Not force
259 // if (!force_) {
260 // // For every target path
261 // for (auto elem : this->targets) {
262 // // If folder
263 // if (elem.folder) {
264 // // For every file in folder
265 // std::vector<std::string> files =
266 // CBuild::fs::dir(elem.path);
267 // for (auto file : files) {
268 // // Check if hash file exists
269 // if (!CBuild::fs::exists(
270 // this->gen_hash_file(file))) {
271 // CBuild::fs::create(
272 // {this->gen_hash_file(file)},
273 // CBuild::fs::FILE);
274 // std::ofstream f(
275 // this->gen_hash_file(file));
276 // f << "-";
277 // f.close();
278 // }
279 // // Push file only if hash is different
280 // if (!CBuild::load_hash(
281 // this->gen_hash_file(file),
282 // file)) {
283 // ret.push_back(
284 // this->cmd_str(file),
285 // this->cmd_str(
286 // this->gen_out_file(
287 // file)));
288 // }
289 // }
290 // }
291 // // If file
292 // else {
293 // std::string file = elem.path;
294 // // Check if hash file exists
295 // if (!CBuild::fs::exists(
296 // this->gen_hash_file(file))) {
297 // CBuild::fs::create(
298 // {this->gen_hash_file(file)},
299 // CBuild::fs::FILE);
300 // std::ofstream f(
301 // this->gen_hash_file(file));
302 // f << "-";
303 // f.close();
304 // }
305 // // Push file only if hash is different
306 // if (!CBuild::load_hash(
307 // this->gen_hash_file(file), file)) {
308 // ret.push_back(
309 // this->cmd_str(file),
310 // this->cmd_str(
311 // this->gen_out_file(file)));
312 // }
313 // }
314 // }
315 // }
316 // // Force
317 // else {
318 // // For every target path
319 // for (auto elem : this->targets) {
320 // // If folder
321 // if (elem.folder) {
322 // // For every file in folder
323 // std::vector<std::string> files =
324 // CBuild::fs::dir(elem.path);
325 // for (auto f : files) {
326 // // Push file
327 // ret.push_back(
328 // this->cmd_str(f),
329 // this->cmd_str(
330 // this->gen_out_file(f)));
331 // // Generate hash file
332 // if (!CBuild::fs::exists(
333 // this->gen_hash_file(f))) {
334 // CBuild::fs::create(
335 // {this->gen_hash_file(f)},
336 // CBuild::fs::FILE);
337 // std::ofstream fl(
338 // this->gen_hash_file(f));
339 // fl << "-";
340 // fl.close();
341 // }
342 // }
343 // }
344 // // If file
345 // else {
346 // // Push file
347 // ret.push_back(this->cmd_str(elem.path),
348 // this->cmd_str(this->gen_out_file(
349 // elem.path)));
350 // // Generate hash file
351 // if (!CBuild::fs::exists(
352 // this->gen_hash_file(elem.path))) {
353 // CBuild::fs::create(
354 // {this->gen_hash_file(elem.path)},
355 // CBuild::fs::FILE);
356 // std::ofstream f(
357 // this->gen_hash_file(elem.path));
358 // f << "-";
359 // f.close();
360 // }
361 // }
362 // }
363 // }
364 if (not_use_hash == true) {
365 for_recomp.clear();
366 for (size_t i = 0; i < filelist.size(); i++) {
367 for_recomp.push_back(filelist.at(i), objects.at(i));
368 }
369 }
370 for (auto elem : for_recomp) {
371 ret.push_back(this->cmd_str(elem.key), this->cmd_str(elem.data));
372 }
373 CBuild::print_full("CBuild::Build::gen_file_list() - dbg: ");
374 for (unsigned int i = 0; i < ret.size(); i++) {
375 CBuild::print_full(ret.at(i).key);
376 }
377 return ret;
378}
380 bool tmp = this->force;
381 this->force = true;
382 auto ret = this->gen_file_list(true);
383 this->force = tmp;
384 return ret;
385}
387 std::string ret = "";
388 for (auto arg : this->compiler_args) {
389 ret += arg;
390 ret += " ";
391 }
392 return ret;
393}
394std::string CBuild::Toolchain::gen_out_name(std::string executable, std::string dyn_lib,
395 std::string stat_lib) {
396 // Base path
397 std::string base = "";
398 if (!this->gen_out_name_without_base_path) {
399 base = CBUILD_BUILD_DIR + "/" + this->id + "/" + CBUILD_BUILD_OUT_DIR + "/";
400 }
401 // If name defined
402 if (this->name != std::string("")) {
403 // If this is executable add file excutable extension
404 if (this->build_type == CBuild::EXECUTABLE) {
405 base += this->name;
406 base += executable;
407 }
408 // We build lib
409 else {
410 // Push "lib" and file name
411 base += "lib";
412 base += this->name;
413 // Based on type push different file extensions
414 if (this->build_type == CBuild::DYNAMIC_LIBRARY) {
415 base += dyn_lib;
416 } else {
417 base += stat_lib;
418 }
419 }
420 }
421 // Else use id
422 else {
423 // If this is executable add file excutable extension
424 if (this->build_type == CBuild::EXECUTABLE) {
425 base += this->id;
426 base += executable;
427 }
428 // We build lib
429 else {
430 // Push "lib" and file name
431 base += "lib";
432 base += this->id;
433 // Based on type push different file extensions
434 if (this->build_type == CBuild::DYNAMIC_LIBRARY) {
435 base += dyn_lib;
436 } else {
437 base += stat_lib;
438 }
439 }
440 }
441 return this->cmd_str(base);
442}
443std::string CBuild::Toolchain::cmd_str(std::string in) {
444 // Replace all spaces with backslash and placeholder
445 while (in.find(" ") != std::string::npos) {
446 in.replace(in.find(" "), std::string(" ").size(), "\\^");
447 }
448 // Replace placeholder by real space
449 while (in.find("\\^") != std::string::npos) {
450 in.replace(in.find("\\^"), std::string("\\^").size(), "\\ ");
451 }
452 return in;
453}
455 // Init toolchain
456 if (this->id == std::string(""))
457 this->id = "null";
458 // Check all neeaded dirs and create it's if it doesnot exists
461 }
462 if (!CBuild::fs::exists(CBUILD_BUILD_DIR + "/" + this->id)) {
464 }
465 if (!CBuild::fs::exists(CBUILD_BUILD_DIR + "/" + this->id + "/" + CBUILD_BUILD_CACHE_DIR)) {
468 }
469 if (!CBuild::fs::exists(CBUILD_BUILD_DIR + "/" + this->id + "/" + CBUILD_BUILD_OUT_DIR)) {
472 }
473 if (!CBuild::fs::exists(CBUILD_BUILD_DIR + "/" + this->id + "/" + CBUILD_METADATA_FOLDER)) {
476 }
477}
478void CBuild::Toolchain::load_project_deps(std::string curr_path) {
479 for (auto elem : this->project_deps) {
480 // Generate and execute command for build dependencie
481 std::string cmd = "cd " + elem.path + " && ./CBuild.run -b " + elem.id;
483 // Copy files
484 CBuild::system("cp -r " + elem.path + "/" + CBUILD_BUILD_DIR + "/" + elem.id + "/" +
485 CBUILD_BUILD_OUT_DIR + "/*.* " + CBUILD_CACHE_DIR + "/" +
487 CBuild::system("cp -r " + elem.headers_path + "/ " + CBUILD_CACHE_DIR + "/" +
488 CBUILD_PROJECT_DEPS_HEADERS + "/" + elem.id);
489 // Add lib in dependencies
490 this->add_library_dir(CBUILD_CACHE_DIR + "/" + CBUILD_PROJECT_DEPS_HEADERS,
492 this->add_library_include(elem.name);
493 this->add_compile_arg(" -Wl,-rpath,\"\\$ORIGIN/../../../" + CBUILD_CACHE_DIR + "/" +
495 }
496}
497std::array<std::string, 3> CBuild::Toolchain::get_cmds() {
498 return std::array<std::string, 3>{this->compiler, this->linker, this->packer};
499}
501 CBuild::print("Error in compilation! Stopping compilation...", CBuild::RED);
502 exit(0xFF);
503}
504void CBuild::Toolchain::compile(std::string str) {
505 int ret = CBuild::system(str);
506 if (ret != 0) {
507 this->crash();
508 }
509}
511 if (!this->stdargs_lock) {
512 // Sometimes binaryes gcc throws error if this option is not set when linking to shared
513 // library
514 this->compiler_args.push_back("-fPIC");
515 this->link_args.push_back("-fPIC");
516 // Some standart compile and link args
517 this->add_compile_arg("-I" + CBUILD_CACHE_DIR + "/" + CBUILD_PROJECT_DEPS_HEADERS);
518 this->add_link_arg("-L" + CBUILD_CACHE_DIR + "/" + CBUILD_PROJECT_DEPS_DIR);
519 // Special link tag for dynamick libraries
520 if (this->build_type == CBuild::DYNAMIC_LIBRARY) {
521 this->link_args.push_back("-shared");
522 }
523 // For packing in deb fomat
524 if (this->build_type == CBuild::DYNAMIC_LIBRARY) {
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);
530 } else {
531 this->add_link_arg(" -Wl,-soname," + lib + std::string(".") +
532 std::to_string(this->version_major));
533 }
534 }
535 // Add link arsg for dependancy libraries
536 for (std::string id : this->depends) {
537 auto target = CBuild::Registry::GetToolchain(id, true);
538 if (target != NULL) {
539 // get lib name
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);
544 // Add lib include
545 this->add_library_include(out);
546 // Add all needed for linking to that library
547 this->add_library_dir(".", CBUILD_BUILD_DIR + "/" + target->get_id() + "/" +
549 this->add_link_arg("-Wl,-rpath,\"\\$ORIGIN/../../" + target->get_id() + "/" +
550 CBUILD_BUILD_OUT_DIR + "\"");
551 }
552 }
553 // pkg-config database search
554 for (auto pkg : this->pkg_config_include_entries) {
556 info.name = pkg;
557 if (!CBuild::get_pkg_info(&info)) {
558 this->crash();
559 }
560 this->add_link_arg(info.largs);
561 this->add_compile_arg(info.cargs);
562 }
563 // External dependencies
564 for (auto dep : this->dependency_list) {
565 this->add_link_arg(dep->largs());
566 this->add_compile_arg(dep->cargs());
567 } // Set lock
568 this->stdargs_lock = true;
569 }
570}
571/* Build.hpp - main */
572void CBuild::Toolchain::call(std::vector<std::string>* args, bool force, bool debug, bool dummy) {
573 CBuild::print("Starting " + this->id + " toolchain in build mode ", CBuild::color::RED);
574 // Load all deps
575 CBuild::print("Trying to load required dependencies...", CBuild::GREEN);
576 for (auto dep : this->dependency_list) {
577 if (dep->need_prepare()) {
578 dep->prepare();
579 }
580 }
581 // Save scratch variables
582 this->args = args;
583 this->force = force;
584 this->dummy = dummy;
585 // Debug mode of compilation
586 if (debug) {
587 this->compiler_args.push_back("-g");
588 }
589 this->stdargs();
590 // Init dirs
591 this->init();
592 // Init
593 CBuild::print("Calling tasks marked as PRE ", CBuild::color::GREEN);
594 // Call all dependencies (tasks) marked as PRE
595 for (unsigned int i = 0; i < this->required.size(); i++) {
596 auto elem = this->required.at(i);
597 if (elem.data == CBuild::PRE) {
598 CBuild::Registry::CallTask(elem.key, {});
599 }
600 }
601 CBuild::print("Calling all required toolchains ", CBuild::color::GREEN);
602 // Call all dependencies (toolchains)
603 for (std::string id : this->depends) {
604 // Call target
605 auto target = CBuild::Registry::GetToolchain(id, force);
606 if (target != NULL) {
607 target->call(args, force, debug, dummy);
608 }
609 }
610 // Does metadata checks fails with file not found error
611 bool meta_error = false;
612 // Perform some metadata checks
613 if (this->hasher->compare_and_set_output_file(this->gen_out_name()) != 0) {
614 this->force = true;
615 meta_error = true;
616 }
617 if (this->hasher->compare_and_set_cargs(this->compiler_args) != 0) {
618 this->force = true;
619 meta_error = true;
620 }
621 if (this->hasher->compare_and_set_largs(this->link_args) != 0) {
622 this->force = true;
623 meta_error = true;
624 }
625 if (this->hasher->compare_and_set_commands(this->compiler, this->linker, this->packer) != 0) {
626 this->force = true;
627 meta_error = true;
628 }
629 // 4 steps
630 if (!force)
631 CBuild::print("Using precompiled object were possible ", CBuild::color::MAGENTA);
632 CBuild::print("Running pre build tasks ", CBuild::GREEN);
633 this->pre_build();
634 CBuild::print("Running build tasks ", CBuild::GREEN);
635 CBuild::print("Now you can see compiler output", CBuild::MAGENTA);
636 this->build();
637 CBuild::print("Running post build tasks ", CBuild::GREEN);
638 this->post_build();
639 CBuild::print("Running pre link tasks ", CBuild::GREEN);
640 this->pre_link();
641 CBuild::print("Running link tasks ", CBuild::GREEN);
642 CBuild::print("Now you can see linker output", CBuild::MAGENTA);
643 // 5-th step - special linking for static libraries
644 if (this->build_type == CBuild::STATIC_LIBRARY) {
645 this->link_pack();
646 } else {
647 this->link();
648 }
649 // Last, 6-th step
650 CBuild::print("Running post link tasks ", CBuild::GREEN);
651 this->post_link();
652 if (this->build_type == CBuild::DYNAMIC_LIBRARY && this->version_major != -1) {
653 CBuild::print("Creating symlink lib<id>.so.<major>", CBuild::GREEN);
654 CBuild::system("rm -rf " + CBUILD_BUILD_DIR + "/" + this->get_id() + "/" +
655 CBUILD_BUILD_OUT_DIR + "/*.so.*");
656 this->gen_out_name_without_base_path = true;
657 CBuild::system("cd " + CBUILD_BUILD_DIR + "/" + this->get_id() + "/" +
658 CBUILD_BUILD_OUT_DIR + " && ln -s " + this->gen_out_name() + " " +
659 this->gen_out_name() + "." + std::to_string(this->version_major));
660 this->gen_out_name_without_base_path = false;
661 }
662 // If we had a metadata file not found error we need to update metadata
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);
666 }
667 CBuild::print("Calling tasks marked as POST ", CBuild::GREEN);
668 // Call all dependencies (tasks) marked as POSt
669 for (unsigned int i = 0; i < this->required.size(); i++) {
670 auto elem = this->required.at(i);
671 if (elem.data == CBuild::POST) {
672 CBuild::Registry::CallTask(elem.key, {});
673 }
674 }
675 CBuild::print("End of execution of toolchain " + this->id + " ", CBuild::RED);
676}
677void CBuild::Toolchain::run(std::vector<std::string>* args) {
678 CBuild::print("Starting \"" + ((this->name == "") ? this->id : this->name) + "\" ",
680 // Parse args
681 std::string pargs = "";
682 if (args != NULL) {
683 for (auto elem : *args) {
684 pargs += elem;
685 pargs += " ";
686 }
687 }
688 // Construct command
689 std::string cmd;
690 cmd = this->gen_out_name();
691 cmd += " ";
692 cmd += pargs;
693 // Call app
694 CBuild::print("App output (if any):", CBuild::MAGENTA);
696 CBuild::print("End of app execution", CBuild::RED);
697}
698void CBuild::Toolchain::debug(std::vector<std::string>* args, std::vector<std::string>* pargs) {
699 CBuild::print("Starting \"" + ((this->name == "") ? this->id : this->name) +
700 "\" toolchain in debug mode ",
702 // Build in debug mode
703 this->call(args, true, true);
704 CBuild::print("Running builded app with gdb ", CBuild::GREEN);
705 std::string ppargs = "";
706 if (pargs != NULL) {
707 for (auto elem : *pargs) {
708 ppargs += elem;
709 ppargs += " ";
710 }
711 }
712 // Construct command
713 std::string cmd;
714 cmd = "gdb ";
715 cmd += this->gen_out_name();
716 cmd += " ";
717 cmd += ppargs;
718 // Call gdb on app
719 CBuild::print("Now you can see gdb shell ", CBuild::MAGENTA);
721 CBuild::print("End of app execution", CBuild::RED);
722}
724 // Simple clear though shell ;)
725 CBuild::system(std::string("rm -r ") + CBUILD_BUILD_DIR + "/" + this->id);
726}
Build toolchain headers.
#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.
virtual void clear()
Clear all caches and builded app.
Definition Build.cpp:723
virtual void add_undef(std::string define)
Add new undefine (undefine previvious define)
Definition Build.cpp:64
virtual std::string get_compile_args()
Get preprocessed compile args.
Definition Build.cpp:386
virtual void set_standart(std::string std_)
Set standart for code (-std=std_)
Definition Build.cpp:126
virtual void load_project_deps(std::string curr_path)
Load all project dependencies.
Definition Build.cpp:478
virtual void set_version_major(int version)
Set major version component, used in -Wl,-soname
Definition Build.cpp:153
virtual void debug(std::vector< std::string > *args, std::vector< std::string > *pargs)
Build program in debug mode and after run gdb on it.
Definition Build.cpp:698
virtual void add_include(std::string include_path)
Add compile-time include.
Definition Build.cpp:73
virtual void run(std::vector< std::string > *args)
Run builded app.
Definition Build.cpp:677
virtual void add_compile_arg(std::string arg)
Directly add compiler argument.
Definition Build.cpp:38
void add_external_dependency(CBuild::Dependency *dep)
Add external dependency to this toolchain.
Definition Build.cpp:172
virtual void add_pkgconfig_entry(std::string id)
Add a lib, data for what need to be searched using pkg-config tool.
Definition Build.cpp:160
virtual void compile(std::string cmd)
Call compiler.
Definition Build.cpp:504
virtual void add_requirment(std::string task_, CBuild::stage run_stage=CBuild::PRE)
Add required task, that task will be executed before toolchain, it can have dependecies,...
Definition Build.cpp:104
virtual void set_id(std::string id)
Change id of this toolchain, if done after registering it can brake things.
Definition Build.cpp:169
virtual lib::map< std::string, std::string > gen_file_list_force()
Generate list of all files, that is tracked by this target.
Definition Build.cpp:379
virtual void error()
Add -Werror.
Definition Build.cpp:122
virtual void add_folder(std::string path)
Add folder to compile path, scan is not recursive.
Definition Build.cpp:187
virtual void set_name(std::string name)
Change out file name.
Definition Build.cpp:166
virtual void add_library_include(std::string library)
Add system library include, library include folder need to be in PATH.
Definition Build.cpp:83
virtual lib::map< std::string, std::string > gen_file_list(bool force)
Generate list of files that need to be compiles.
Definition Build.cpp:216
virtual void call(std::vector< std::string > *args, bool force=false, bool debug=false, bool dummy=false)
Call tollchain to execute.
Definition Build.cpp:572
virtual std::string gen_out_name(std::string executable=".run", std::string dyn_lib=".so", std::string stat_lib=".a")
Generate output file name (after linking)
Definition Build.cpp:394
virtual void set_hasher(Hash *hasher)
Set used hasher for this target.
Definition Build.cpp:163
virtual void add_define(std::string define, std::string val="")
Add new define.
Definition Build.cpp:50
std::vector< std::string > compiler_args
Compiler args (specified and generated)
Definition Build.hpp:90
virtual void add_library_dir(std::string include, std::string lib)
Add library include directory (with *.h files) and directory with library *.a and *....
Definition Build.cpp:92
virtual void add_file(std::string path)
Add file for compilation.
Definition Build.cpp:176
virtual void multithreaded_target()
Add -pthread argument.
Definition Build.cpp:156
virtual void add_link_arg(std::string arg)
Add linker arguments.
Definition Build.cpp:44
virtual void set_type(CBuild::build_type type)
Set the type of build.
Definition Build.cpp:133
virtual void stdargs()
Add standard compile and link arguments into compilation Need to be publick for some hashers to work.
Definition Build.cpp:510
virtual std::array< std::string, 3 > get_cmds()
Get all three commands from class - compile, linker and packer.
Definition Build.cpp:497
virtual std::string cmd_str(std::string in)
Replace spaces by "\ ".
Definition Build.cpp:443
virtual void set_profiling_mode()
Enable -pg for gprof.
Definition Build.cpp:149
virtual std::string gen_out_file(std::string file)
Generate output object file from input file.
Definition Build.cpp:199
virtual void init()
Initialize folder structure.
Definition Build.cpp:454
virtual void crash() __attribute__((__noreturn__))
Crash compilation, needed when gcc throws error.
Definition Build.cpp:500
virtual void warn()
Enable more warnings.
Definition Build.cpp:110
virtual void depends_on_project(std::string path, std::string name, std::string id, std::string headers_path)
Add another CBuild project as dependency.
Definition Build.cpp:140
virtual void static_analizer()
Enable static anlizer (very slow)
Definition Build.cpp:117
virtual void depends_on(std::string target)
This target depends on other target.
Definition Build.cpp:136
Simple map implementation with some stack operation added.
Definition map.hpp:79
__SIZE_TYPE__ size()
Size of map.
Definition map.hpp:275
void clear()
Erase all elements (simmilar to std::vector::clear())
Definition map.hpp:215
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.
Definition map.hpp:111
lib::mapData< _K, _D > at(__SIZE_TYPE__ i)
Array operation, get element at index.
Definition map.hpp:223
filesystem++ api
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.
Definition register.cpp:239
void CallTask(std::string name, std::vector< std::string > args)
Run tasks.
Definition register.cpp:206
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.
Definition print.cpp:70
build_type
Definition Build.hpp:55
@ EXECUTABLE
Definition Build.hpp:55
@ STATIC_LIBRARY
Definition Build.hpp:55
@ DYNAMIC_LIBRARY
Definition Build.hpp:55
int version[]
Definition CBuild.cpp:556
@ RED
Definition print.hpp:34
@ MAGENTA
Definition print.hpp:38
@ GREEN
Definition print.hpp:35
stage
Type of depencesies for toolchain.
Definition Build.hpp:54
@ PRE
Definition Build.hpp:54
@ POST
Definition Build.hpp:54
void exit(int code)
bool get_pkg_info(CBuild::package_info *package)
Get the package info from pkg-config database.
Definition pkgconfig.cpp:28
int system(std::string cmd)
Call stdlib system() and print cmd to shell.
Definition system.cpp:47
void print_full(std::string msg, color fg=CBuild::WHITE)
Print colored text to STDOUT if verbose flag is set.
Definition print.cpp:75
Optional datatype.
Definition map.hpp:29
pkg-config interface header Provides interface to pkg-config cli tool, including some parts of error ...
Custom print that support color codes.
Register any things.
Path datatype.
Definition Build.hpp:38
bool folder
Definition Build.hpp:40
std::string path
Definition Build.hpp:39
Project dependency data.
Definition Build.hpp:45
std::string headers_path
Definition Build.hpp:49
Command for compile_commands.json.
Package info struct for data for pkg-config.
Definition pkgconfig.hpp:30
std::string largs
Package link args.
Definition pkgconfig.hpp:38
std::string name
Package name.
Definition pkgconfig.hpp:34
std::string cargs
Package compile args.
Definition pkgconfig.hpp:42
Custom system() wraper.