-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cpp
129 lines (104 loc) · 4.03 KB
/
build.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright 2021-2022 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "target/target.h"
#include "target/common/util.h"
#include "env/assert_fatal.h"
#include "fmt/format.h"
namespace {
constexpr const char *const kIncludeDirs = "include_dirs";
constexpr const char *const kLibDirs = "lib_dirs";
constexpr const char *const kPreprocessorFlags = "preprocessor_flags";
constexpr const char *const kCommonCompileFlags = "common_compile_flags";
constexpr const char *const kLinkFlags = "link_flags";
constexpr const char *const kPchCompileFlags = "pch_compile_flags";
constexpr const char *const kPchObjectFlags = "pch_object_flags";
constexpr const char *const kPchObjectOutput = "pch_object_output";
constexpr const char *const kAsmCompiler = "asm_compiler";
constexpr const char *const kCCompiler = "c_compiler";
constexpr const char *const kCppCompiler = "cpp_compiler";
constexpr const char *const kArchiver = "archiver";
constexpr const char *const kLinker = "linker";
} // namespace
namespace buildcc {
// * Load
// TODO, Verify things that cannot be changed
// * Compile
// Include directories dependencies
// * Link
// Library dependencies
void Target::Build() {
env::log_trace(name_, __FUNCTION__);
// PCH state
if (!user_.pchs.GetPathInfos().empty()) {
state_.PchDetected();
}
// Source - Object relation
// Source state
for (const auto &source_info : user_.sources.GetPathInfos()) {
// Set state
state_.SourceDetected(toolchain_.GetConfig().GetFileExt(source_info.path));
// Relate input source with output object
compile_object_.AddObjectData(source_info.path);
}
// Target default arguments
command_.AddDefaultArguments({
{kIncludeDirs,
internal::aggregate_with_prefix<std::vector<std::string>>(
toolchain_.GetConfig().prefix_include_dir, GetIncludeDirs())},
{kLibDirs, internal::aggregate_with_prefix<std::vector<std::string>>(
toolchain_.GetConfig().prefix_lib_dir, GetLibDirs())},
{kPreprocessorFlags, internal::aggregate(GetPreprocessorFlags())},
{kCommonCompileFlags, internal::aggregate(GetCommonCompileFlags())},
// TODO, Cache more flags here
// ASM, C and CPP flags
{kLinkFlags, internal::aggregate(GetLinkFlags())},
// Toolchain executables here
{kAsmCompiler, fmt::format("{}", fs::path(toolchain_.GetAssembler()))},
{kCCompiler, fmt::format("{}", fs::path(toolchain_.GetCCompiler()))},
{kCppCompiler, fmt::format("{}", fs::path(toolchain_.GetCppCompiler()))},
{kArchiver, fmt::format("{}", fs::path(toolchain_.GetArchiver()))},
{kLinker, fmt::format("{}", fs::path(toolchain_.GetLinker()))},
});
// Load the serialized file
(void)serialization_.LoadFromFile();
// PCH Compile
if (state_.ContainsPch()) {
command_.AddDefaultArguments({
{kPchCompileFlags, internal::aggregate(GetPchCompileFlags())},
{kPchObjectFlags, internal::aggregate(GetPchObjectFlags())},
{kPchObjectOutput, fmt::format("{}", compile_pch_.GetObjectPath())},
});
compile_pch_.CacheCompileCommand();
compile_pch_.Task();
} else {
command_.AddDefaultArguments({
{kPchCompileFlags, ""},
{kPchObjectFlags, ""},
{kPchObjectOutput, ""},
});
}
// Target State Tasks
EndTask();
// Compile Command
compile_object_.CacheCompileCommands();
compile_object_.Task();
// Link Command
link_target_.CacheLinkCommand();
link_target_.Task();
// Target dependencies
TaskDeps();
}
} // namespace buildcc