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_CLANGXX_TOOLCHAIN
22#define CBUILD_CLANGXX_TOOLCHAIN
23// Project files
24#include "../CBuild_defs.hpp"
26#include "Build.hpp"
27// Code
28namespace CBuild {
29template <CBuild::HashImpl hash = CBuild::CBuildHashV2> class CLANGXX : public CBuild::Toolchain {
30 public:
36 CLANGXX(std::string id) {
37 // Set id of toolchain and assign executables constants
38 this->id = id;
39 this->name = "";
40 this->linker = "clang++";
41 this->compiler = "clang++";
42 this->packer = "ar cr";
43 this->add_link_arg("-Wl,-z,origin");
44 this->add_link_arg(" -Wl,-rpath,\"\\$ORIGIN\"");
45 this->add_link_arg("-lstdc++");
46 this->hasher = new hash(this->id);
47 }
54 CLANGXX(std::string id, std::string name) {
55 // Set id and name of toolchain and assign executables constants
56 this->id = id;
57 this->name = name;
58 this->linker = "clang++";
59 this->compiler = "clang++";
60 this->packer = "ar cr";
61 this->add_link_arg("-Wl,-z,origin");
62 this->add_link_arg(" -Wl,-rpath,\"\\$ORIGIN\"");
63 this->add_link_arg("-lstdc++");
64 this->hasher = new hash(this->id);
65 }
66
67 protected:
68 void build() override {
69 // Get all args
70 std::string args;
71 for (auto elem : this->compiler_args) {
72 args += elem;
73 args += " ";
74 }
75 // Get all files
76 auto files = this->gen_file_list(this->force);
77 if (files.size() > 0) {
78 // Compile file by file
79 for (unsigned int i = 0; i < files.size(); i++) {
80 // Construct command
81 std::string cmd = this->compiler + " -c ";
82 cmd += files.at(i).key;
83 cmd += " ";
84 cmd += args;
85 cmd += " -o ";
86 cmd += files.at(i).data;
87 // Execute command
88 this->compile(cmd);
89 }
90 }
91 }
92 void link() override {
93 // Get args
94 std::string args;
95 for (auto elem : this->link_args) {
96 args += elem;
97 args += " ";
98 }
99 // Get files
100 this->gen_file_list_for_linking = true;
101 auto files = this->gen_file_list(true);
102 this->gen_file_list_for_linking = false;
103 std::string flist;
104 for (unsigned int i = 0; i < files.size(); i++) {
105 flist += files.at(i).data;
106 flist += " ";
107 }
108 if (files.size() > 0) {
109 // Construct command
110 std::string cmd = this->linker + " ";
111 cmd += flist;
112 cmd += " ";
113 cmd += args;
114 cmd += " ";
115 cmd += " -o ";
116 cmd += this->gen_out_name();
117 // Call command
118 // CBuild::print(cmd.c_str(), CBuild::color::BLUE);
119 this->compile(cmd);
120 }
121 }
122 void link_pack() override {
123 // Get args
124 std::string args;
125 for (auto elem : this->link_args) {
126 args += elem;
127 args += " ";
128 }
129 // Get all files
130 this->gen_file_list_for_linking = true;
131 auto files = this->gen_file_list(true);
132 this->gen_file_list_for_linking = false;
133 std::string flist;
134 for (unsigned int i = 0; i < files.size(); i++) {
135 flist += files.at(i).data;
136 flist += " ";
137 }
138 if (files.size() > 0) {
139 // Construct command
140 std::string cmd = this->packer + " ";
141 cmd += this->gen_out_name();
142 cmd += " ";
143 cmd += flist;
144 cmd += " ";
145 // Call command
146 // CBuild::print(cmd.c_str(), CBuild::color::BLUE);
147 this->compile(cmd);
148 }
149 }
150};
151} // namespace CBuild
152#endif // CBUILD_CLANGXX_TOOLCHAIN
Build toolchain headers.
Improved CBuild hasher.
void build() override
Build.
Definition clang++.hpp:68
void link() override
Linking.
Definition clang++.hpp:92
CLANGXX(std::string id)
Construct a new CLANGXX object.
Definition clang++.hpp:36
CLANGXX(std::string id, std::string name)
Construct a new CLANGXX object.
Definition clang++.hpp:54
void link_pack() override
Linking for static libraries.
Definition clang++.hpp:122
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.