Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[CRTP] Target Flags API #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildcc/lib/target/cmake/mock_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_library(mock_target STATIC
src/api/include_api.cpp
src/api/lib_api.cpp
src/api/pch_api.cpp
src/api/flag_api.cpp

# Generator
src/generator/generator_loader.cpp
Expand All @@ -32,7 +33,6 @@ add_library(mock_target STATIC
src/target/target_loader.cpp
src/target/target_storer.cpp

src/target/flags.cpp
src/target/additional_deps.cpp

src/target/build.cpp
Expand Down
3 changes: 2 additions & 1 deletion buildcc/lib/target/cmake/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ set(TARGET_SRCS
src/api/include_api.cpp
src/api/lib_api.cpp
src/api/pch_api.cpp
src/api/flag_api.cpp
include/target/api/copy_api.h
include/target/api/source_api.h
include/target/api/include_api.h
include/target/api/lib_api.h
include/target/api/pch_api.h
include/target/api/flag_api.h

# Generator
src/generator/generator_loader.cpp
Expand All @@ -54,7 +56,6 @@ set(TARGET_SRCS
include/target/target_storer.h
include/target/target.h

src/target/flags.cpp
src/target/additional_deps.cpp

src/target/recheck_states.cpp
Expand Down
38 changes: 38 additions & 0 deletions buildcc/lib/target/include/target/api/flag_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 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.
*/

#ifndef TARGET_API_FLAG_API_H_
#define TARGET_API_FLAG_API_H_

#include <string>

namespace buildcc::base {

template <typename T> class FlagApi {
public:
void AddPreprocessorFlag(const std::string &flag);
void AddCommonCompileFlag(const std::string &flag);
void AddPchCompileFlag(const std::string &flag);
void AddPchObjectFlag(const std::string &flag);
void AddAsmCompileFlag(const std::string &flag);
void AddCCompileFlag(const std::string &flag);
void AddCppCompileFlag(const std::string &flag);
void AddLinkFlag(const std::string &flag);
};

} // namespace buildcc::base

#endif
2 changes: 1 addition & 1 deletion buildcc/lib/target/include/target/api/pch_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ template <typename T> class PchApi {

} // namespace buildcc::base

#endif
#endif
15 changes: 4 additions & 11 deletions buildcc/lib/target/include/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

// API
#include "target/api/copy_api.h"
#include "target/api/flag_api.h"
#include "target/api/include_api.h"
#include "target/api/lib_api.h"
#include "target/api/pch_api.h"
Expand Down Expand Up @@ -73,7 +74,8 @@ class Target : public BuilderInterface,
public SourceApi<Target>,
public IncludeApi<Target>,
public LibApi<Target>,
public PchApi<Target> {
public PchApi<Target>,
public FlagApi<Target> {

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

// Setters

// * Flags
void AddPreprocessorFlag(const std::string &flag);
void AddCommonCompileFlag(const std::string &flag);
void AddPchCompileFlag(const std::string &flag);
void AddPchObjectFlag(const std::string &flag);
void AddAsmCompileFlag(const std::string &flag);
void AddCCompileFlag(const std::string &flag);
void AddCppCompileFlag(const std::string &flag);
void AddLinkFlag(const std::string &flag);

// * Rebuild
void AddCompileDependency(const fs::path &relative_path);
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
Expand Down Expand Up @@ -229,6 +221,7 @@ class Target : public BuilderInterface,
friend class IncludeApi<Target>;
friend class LibApi<Target>;
friend class PchApi<Target>;
friend class FlagApi<Target>;

private:
void Initialize();
Expand Down
81 changes: 81 additions & 0 deletions buildcc/lib/target/src/api/flag_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2021 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/api/flag_api.h"

#include "target/target.h"

namespace buildcc::base {

template <typename T>
void FlagApi<T>::AddPreprocessorFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_preprocessor_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddCommonCompileFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_common_compile_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddPchCompileFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_pch_compile_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddPchObjectFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_pch_object_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddAsmCompileFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_asm_compile_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddCCompileFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_c_compile_flags.insert(flag);
}
template <typename T>
void FlagApi<T>::AddCppCompileFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_cpp_compile_flags.insert(flag);
}
template <typename T> void FlagApi<T>::AddLinkFlag(const std::string &flag) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_link_flags.insert(flag);
}

template class FlagApi<Target>;

} // namespace buildcc::base
2 changes: 1 addition & 1 deletion buildcc/lib/target/src/api/pch_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ void PchApi<T>::AddPch(const fs::path &relative_filename,

template class PchApi<Target>;

} // namespace buildcc::base
} // namespace buildcc::base
16 changes: 8 additions & 8 deletions buildcc/lib/target/src/target/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ Check the `include/target/api` and `src/api` folder
- `lib_api`
- [x] PCH
- `pch_api`
- [ ] Flags
- [x] Flags
- `flag_api`
- PreprocessorFlags
- CommonCompileFlags
- AsmCompileFlags
- CCompileFlags
- CppCompileFlag
- LinkFlags
- [ ] Rebuild Deps
- [ ] Getters
- [ ] Target Info

## Inputs to Target

- [x] `flags.cpp`
- PreprocessorFlags
- CommonCompileFlags
- AsmCompileFlags
- CCompileFlags
- CppCompileFlag
- LinkFlags
- [x] `additional_deps.cpp`
- PreCompileHeader dependencies
- Compile dependencies
Expand Down
54 changes: 0 additions & 54 deletions buildcc/lib/target/src/target/flags.cpp

This file was deleted.