diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index 2080d12e..b450aa4d 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -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 @@ -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 diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index 34cd5646..eaae6721 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -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 @@ -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 diff --git a/buildcc/lib/target/include/target/api/flag_api.h b/buildcc/lib/target/include/target/api/flag_api.h new file mode 100644 index 00000000..576a7159 --- /dev/null +++ b/buildcc/lib/target/include/target/api/flag_api.h @@ -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 + +namespace buildcc::base { + +template 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 diff --git a/buildcc/lib/target/include/target/api/pch_api.h b/buildcc/lib/target/include/target/api/pch_api.h index 345574b0..1a7bc027 100644 --- a/buildcc/lib/target/include/target/api/pch_api.h +++ b/buildcc/lib/target/include/target/api/pch_api.h @@ -37,4 +37,4 @@ template class PchApi { } // namespace buildcc::base -#endif \ No newline at end of file +#endif diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index dcd2a9e5..3473fefc 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -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" @@ -73,7 +74,8 @@ class Target : public BuilderInterface, public SourceApi, public IncludeApi, public LibApi, - public PchApi { + public PchApi, + public FlagApi { public: explicit Target(const std::string &name, TargetType type, @@ -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); @@ -229,6 +221,7 @@ class Target : public BuilderInterface, friend class IncludeApi; friend class LibApi; friend class PchApi; + friend class FlagApi; private: void Initialize(); diff --git a/buildcc/lib/target/src/api/flag_api.cpp b/buildcc/lib/target/src/api/flag_api.cpp new file mode 100644 index 00000000..0609ee47 --- /dev/null +++ b/buildcc/lib/target/src/api/flag_api.cpp @@ -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 +void FlagApi::AddPreprocessorFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_preprocessor_flags.insert(flag); +} +template +void FlagApi::AddCommonCompileFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_common_compile_flags.insert(flag); +} +template +void FlagApi::AddPchCompileFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_pch_compile_flags.insert(flag); +} +template +void FlagApi::AddPchObjectFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_pch_object_flags.insert(flag); +} +template +void FlagApi::AddAsmCompileFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_asm_compile_flags.insert(flag); +} +template +void FlagApi::AddCCompileFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_c_compile_flags.insert(flag); +} +template +void FlagApi::AddCppCompileFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_cpp_compile_flags.insert(flag); +} +template void FlagApi::AddLinkFlag(const std::string &flag) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_link_flags.insert(flag); +} + +template class FlagApi; + +} // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/pch_api.cpp b/buildcc/lib/target/src/api/pch_api.cpp index e439259e..115e2d6f 100644 --- a/buildcc/lib/target/src/api/pch_api.cpp +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -45,4 +45,4 @@ void PchApi::AddPch(const fs::path &relative_filename, template class PchApi; -} // namespace buildcc::base \ No newline at end of file +} // namespace buildcc::base diff --git a/buildcc/lib/target/src/target/README.md b/buildcc/lib/target/src/target/README.md index 27f90dba..717c6c65 100644 --- a/buildcc/lib/target/src/target/README.md +++ b/buildcc/lib/target/src/target/README.md @@ -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 diff --git a/buildcc/lib/target/src/target/flags.cpp b/buildcc/lib/target/src/target/flags.cpp deleted file mode 100644 index 7e5d6a47..00000000 --- a/buildcc/lib/target/src/target/flags.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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/target.h" - -namespace buildcc::base { - -void Target::AddPreprocessorFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_preprocessor_flags.insert(flag); -} -void Target::AddCommonCompileFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_common_compile_flags.insert(flag); -} -void Target::AddPchCompileFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_pch_compile_flags.insert(flag); -} -void Target::AddPchObjectFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_pch_object_flags.insert(flag); -} -void Target::AddAsmCompileFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_asm_compile_flags.insert(flag); -} -void Target::AddCCompileFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_c_compile_flags.insert(flag); -} -void Target::AddCppCompileFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_cpp_compile_flags.insert(flag); -} -void Target::AddLinkFlag(const std::string &flag) { - state_.ExpectsUnlock(); - storer_.current_link_flags.insert(flag); -} - -} // namespace buildcc::base