CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
clang.hpp
Go to the documentation of this file.
1
21#ifndef CBUILD_CLANG_TOOLCHAIN
22#define CBUILD_CLANG_TOOLCHAIN
23// Project files
24#include "../CBuild_defs.hpp"
26#include "./Build.hpp"
27// Code
28namespace CBuild {
29template <CBuild::HashImpl hash = CBuild::CBuildHashV2> class CLANG : public CBuild::Toolchain {
30 public:
36 CLANG(std::string id) {
37 this->id = id;
38 this->name = "";
39 this->linker = "clang";
40 this->compiler = "clang";
41 this->packer = "ar cr";
42 this->add_link_arg("-Wl,-z,origin");
43 this->add_link_arg(" -Wl,-rpath,\"\\$ORIGIN\"");
44 this->hasher = new hash(this->id);
45 }
52 CLANG(std::string id, std::string name) {
53 this->id = id;
54 this->name = name;
55 this->linker = "clang";
56 this->compiler = "clang";
57 this->packer = "ar cr";
58 this->add_link_arg("-Wl,-z,origin");
59 this->add_link_arg(" -Wl,-rpath,\"\\$ORIGIN\"");
60 this->hasher = new hash(this->id);
61 }
62
63 protected:
64 // For docs see g++.hpp
65 void build() override {
66 std::string args;
67 for (auto elem : this->compiler_args) {
68 args += elem;
69 args += " ";
70 }
71 auto files = this->gen_file_list(this->force);
72 std::vector<std::string> hash_files;
73 if (files.size() > 0) {
74 for (unsigned int i = 0; i < files.size(); i++) {
75 std::string cmd = this->compiler + " -c ";
76 cmd += files.at(i).key;
77 cmd += " ";
78 cmd += args;
79 cmd += " -o ";
80 cmd += files.at(i).data;
81 // CBuild::print(cmd.c_str(), CBuild::BLUE);
82 this->compile(cmd);
83 }
84 }
85 }
86 void link() override {
87 std::string args;
88 for (auto elem : this->link_args) {
89 args += elem;
90 args += " ";
91 }
92 // Get files
93 this->gen_file_list_for_linking = true;
94 auto files = this->gen_file_list(true);
95 this->gen_file_list_for_linking = false;
96 std::string flist;
97 for (unsigned int i = 0; i < files.size(); i++) {
98 flist += files.at(i).data;
99 flist += " ";
100 }
101 if (files.size() > 0) {
102 std::string cmd = this->linker + " ";
103 cmd += flist;
104 cmd += " ";
105 cmd += args;
106 cmd += " ";
107 cmd += " -o ";
108 cmd += this->gen_out_name();
109 // CBuild::print(cmd.c_str(), CBuild::BLUE);
110 this->compile(cmd);
111 }
112 }
113 void link_pack() override {
114 std::string args;
115 for (auto elem : this->link_args) {
116 args += elem;
117 args += " ";
118 }
119 this->gen_file_list_for_linking = true;
120 auto files = this->gen_file_list(true);
121 this->gen_file_list_for_linking = false;
122 std::string flist;
123 for (unsigned int i = 0; i < files.size(); i++) {
124 flist += files.at(i).data;
125 flist += " ";
126 }
127 if (files.size() > 0) {
128 std::string cmd = this->packer + " ";
129 cmd += this->gen_out_name();
130 cmd += " ";
131 cmd += flist;
132 cmd += " ";
133 // CBuild::print(cmd.c_str(), CBuild::BLUE);
134 this->compile(cmd);
135 }
136 }
137};
138} // namespace CBuild
139#endif // CBUILD_CLANG_TOOLCHAIN
Build toolchain headers.
Improved CBuild hasher.
void build() override
Build.
Definition clang.hpp:65
CLANG(std::string id)
Construct a new CLANG object.
Definition clang.hpp:36
void link_pack() override
Linking for static libraries.
Definition clang.hpp:113
CLANG(std::string id, std::string name)
Construct a new CLANG object.
Definition clang.hpp:52
void link() override
Linking.
Definition clang.hpp:86
Toolchain class.
Definition Build.hpp:65
bool force
Force argument (scratch variable)
Definition Build.hpp:153
std::string packer
ar command for packing static libraries
Definition Build.hpp:106
Hash * hasher
Hasher used here.
Definition Build.hpp:138
virtual void compile(std::string cmd)
Call compiler.
Definition Build.cpp:504
std::string name
Name of output, if undefined (""), for id is used for binary name.
Definition Build.hpp:70
std::vector< std::string > link_args
Linker args (specified and generated)
Definition Build.hpp:94
bool gen_file_list_for_linking
Generate file list for linking - force and no changes to hashes.
Definition Build.hpp:130
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
std::string id
Must be initialized in derived classes.
Definition Build.hpp:74
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
std::vector< std::string > compiler_args
Compiler args (specified and generated)
Definition Build.hpp:90
virtual void add_link_arg(std::string arg)
Add linker arguments.
Definition Build.cpp:44
std::string linker
Linker command.
Definition Build.hpp:102
std::string compiler
Compiler command.
Definition Build.hpp:98
std::vector< std::string > * args
Argument pointer (scratch variable)
Definition Build.hpp:149
Filebuffer for CBuild ecosystem.
Definition Build.hpp:34
uint64_t hash(std::string str)
FNV-1a hashing function for std::string.
Definition hash.cpp:218
Command for compile_commands.json.