Skip to content

Commit c17cd32

Browse files
authored
[CRTP] Target Flags API (#153)
1 parent 04b79f1 commit c17cd32

File tree

9 files changed

+136
-77
lines changed

9 files changed

+136
-77
lines changed

buildcc/lib/target/cmake/mock_target.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_library(mock_target STATIC
1212
src/api/include_api.cpp
1313
src/api/lib_api.cpp
1414
src/api/pch_api.cpp
15+
src/api/flag_api.cpp
1516

1617
# Generator
1718
src/generator/generator_loader.cpp
@@ -32,7 +33,6 @@ add_library(mock_target STATIC
3233
src/target/target_loader.cpp
3334
src/target/target_storer.cpp
3435

35-
src/target/flags.cpp
3636
src/target/additional_deps.cpp
3737

3838
src/target/build.cpp

buildcc/lib/target/cmake/target.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ set(TARGET_SRCS
2323
src/api/include_api.cpp
2424
src/api/lib_api.cpp
2525
src/api/pch_api.cpp
26+
src/api/flag_api.cpp
2627
include/target/api/copy_api.h
2728
include/target/api/source_api.h
2829
include/target/api/include_api.h
2930
include/target/api/lib_api.h
3031
include/target/api/pch_api.h
32+
include/target/api/flag_api.h
3133

3234
# Generator
3335
src/generator/generator_loader.cpp
@@ -54,7 +56,6 @@ set(TARGET_SRCS
5456
include/target/target_storer.h
5557
include/target/target.h
5658

57-
src/target/flags.cpp
5859
src/target/additional_deps.cpp
5960

6061
src/target/recheck_states.cpp
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2021 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TARGET_API_FLAG_API_H_
18+
#define TARGET_API_FLAG_API_H_
19+
20+
#include <string>
21+
22+
namespace buildcc::base {
23+
24+
template <typename T> class FlagApi {
25+
public:
26+
void AddPreprocessorFlag(const std::string &flag);
27+
void AddCommonCompileFlag(const std::string &flag);
28+
void AddPchCompileFlag(const std::string &flag);
29+
void AddPchObjectFlag(const std::string &flag);
30+
void AddAsmCompileFlag(const std::string &flag);
31+
void AddCCompileFlag(const std::string &flag);
32+
void AddCppCompileFlag(const std::string &flag);
33+
void AddLinkFlag(const std::string &flag);
34+
};
35+
36+
} // namespace buildcc::base
37+
38+
#endif

buildcc/lib/target/include/target/api/pch_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ template <typename T> class PchApi {
3737

3838
} // namespace buildcc::base
3939

40-
#endif
40+
#endif

buildcc/lib/target/include/target/target.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
// API
4040
#include "target/api/copy_api.h"
41+
#include "target/api/flag_api.h"
4142
#include "target/api/include_api.h"
4243
#include "target/api/lib_api.h"
4344
#include "target/api/pch_api.h"
@@ -73,7 +74,8 @@ class Target : public BuilderInterface,
7374
public SourceApi<Target>,
7475
public IncludeApi<Target>,
7576
public LibApi<Target>,
76-
public PchApi<Target> {
77+
public PchApi<Target>,
78+
public FlagApi<Target> {
7779

7880
public:
7981
explicit Target(const std::string &name, TargetType type,
@@ -95,16 +97,6 @@ class Target : public BuilderInterface,
9597

9698
// Setters
9799

98-
// * Flags
99-
void AddPreprocessorFlag(const std::string &flag);
100-
void AddCommonCompileFlag(const std::string &flag);
101-
void AddPchCompileFlag(const std::string &flag);
102-
void AddPchObjectFlag(const std::string &flag);
103-
void AddAsmCompileFlag(const std::string &flag);
104-
void AddCCompileFlag(const std::string &flag);
105-
void AddCppCompileFlag(const std::string &flag);
106-
void AddLinkFlag(const std::string &flag);
107-
108100
// * Rebuild
109101
void AddCompileDependency(const fs::path &relative_path);
110102
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
@@ -229,6 +221,7 @@ class Target : public BuilderInterface,
229221
friend class IncludeApi<Target>;
230222
friend class LibApi<Target>;
231223
friend class PchApi<Target>;
224+
friend class FlagApi<Target>;
232225

233226
private:
234227
void Initialize();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2021 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "target/api/flag_api.h"
18+
19+
#include "target/target.h"
20+
21+
namespace buildcc::base {
22+
23+
template <typename T>
24+
void FlagApi<T>::AddPreprocessorFlag(const std::string &flag) {
25+
T &t = static_cast<T &>(*this);
26+
27+
t.state_.ExpectsUnlock();
28+
t.storer_.current_preprocessor_flags.insert(flag);
29+
}
30+
template <typename T>
31+
void FlagApi<T>::AddCommonCompileFlag(const std::string &flag) {
32+
T &t = static_cast<T &>(*this);
33+
34+
t.state_.ExpectsUnlock();
35+
t.storer_.current_common_compile_flags.insert(flag);
36+
}
37+
template <typename T>
38+
void FlagApi<T>::AddPchCompileFlag(const std::string &flag) {
39+
T &t = static_cast<T &>(*this);
40+
41+
t.state_.ExpectsUnlock();
42+
t.storer_.current_pch_compile_flags.insert(flag);
43+
}
44+
template <typename T>
45+
void FlagApi<T>::AddPchObjectFlag(const std::string &flag) {
46+
T &t = static_cast<T &>(*this);
47+
48+
t.state_.ExpectsUnlock();
49+
t.storer_.current_pch_object_flags.insert(flag);
50+
}
51+
template <typename T>
52+
void FlagApi<T>::AddAsmCompileFlag(const std::string &flag) {
53+
T &t = static_cast<T &>(*this);
54+
55+
t.state_.ExpectsUnlock();
56+
t.storer_.current_asm_compile_flags.insert(flag);
57+
}
58+
template <typename T>
59+
void FlagApi<T>::AddCCompileFlag(const std::string &flag) {
60+
T &t = static_cast<T &>(*this);
61+
62+
t.state_.ExpectsUnlock();
63+
t.storer_.current_c_compile_flags.insert(flag);
64+
}
65+
template <typename T>
66+
void FlagApi<T>::AddCppCompileFlag(const std::string &flag) {
67+
T &t = static_cast<T &>(*this);
68+
69+
t.state_.ExpectsUnlock();
70+
t.storer_.current_cpp_compile_flags.insert(flag);
71+
}
72+
template <typename T> void FlagApi<T>::AddLinkFlag(const std::string &flag) {
73+
T &t = static_cast<T &>(*this);
74+
75+
t.state_.ExpectsUnlock();
76+
t.storer_.current_link_flags.insert(flag);
77+
}
78+
79+
template class FlagApi<Target>;
80+
81+
} // namespace buildcc::base

buildcc/lib/target/src/api/pch_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ void PchApi<T>::AddPch(const fs::path &relative_filename,
4545

4646
template class PchApi<Target>;
4747

48-
} // namespace buildcc::base
48+
} // namespace buildcc::base

buildcc/lib/target/src/target/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ Check the `include/target/api` and `src/api` folder
2626
- `lib_api`
2727
- [x] PCH
2828
- `pch_api`
29-
- [ ] Flags
29+
- [x] Flags
30+
- `flag_api`
31+
- PreprocessorFlags
32+
- CommonCompileFlags
33+
- AsmCompileFlags
34+
- CCompileFlags
35+
- CppCompileFlag
36+
- LinkFlags
3037
- [ ] Rebuild Deps
3138
- [ ] Getters
3239
- [ ] Target Info
3340

3441
## Inputs to Target
3542

36-
- [x] `flags.cpp`
37-
- PreprocessorFlags
38-
- CommonCompileFlags
39-
- AsmCompileFlags
40-
- CCompileFlags
41-
- CppCompileFlag
42-
- LinkFlags
4343
- [x] `additional_deps.cpp`
4444
- PreCompileHeader dependencies
4545
- Compile dependencies

buildcc/lib/target/src/target/flags.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)