diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index 36c6ebc9..2080d12e 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -11,6 +11,7 @@ add_library(mock_target STATIC src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp + src/api/pch_api.cpp # Generator src/generator/generator_loader.cpp @@ -31,7 +32,6 @@ add_library(mock_target STATIC src/target/target_loader.cpp src/target/target_storer.cpp - src/target/pch.cpp src/target/flags.cpp src/target/additional_deps.cpp diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index 7ee43969..34cd5646 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -22,10 +22,12 @@ set(TARGET_SRCS src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp + src/api/pch_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 # Generator src/generator/generator_loader.cpp @@ -52,7 +54,6 @@ set(TARGET_SRCS include/target/target_storer.h include/target/target.h - src/target/pch.cpp src/target/flags.cpp src/target/additional_deps.cpp diff --git a/buildcc/lib/target/include/target/api/lib_api.h b/buildcc/lib/target/include/target/api/lib_api.h index 1566bf10..c787a4bb 100644 --- a/buildcc/lib/target/include/target/api/lib_api.h +++ b/buildcc/lib/target/include/target/api/lib_api.h @@ -24,6 +24,8 @@ namespace fs = std::filesystem; namespace buildcc::base { +class Target; + // Requires // - TargetStorer // - TargetState @@ -31,7 +33,7 @@ namespace buildcc::base { // T::GetTargetPath template class LibApi { public: - void AddLibDep(const T &lib_dep); + void AddLibDep(const Target &lib_dep); void AddLibDep(const std::string &lib_dep); void AddLibDir(const fs::path &relative_lib_dir); diff --git a/buildcc/lib/target/include/target/api/pch_api.h b/buildcc/lib/target/include/target/api/pch_api.h new file mode 100644 index 00000000..345574b0 --- /dev/null +++ b/buildcc/lib/target/include/target/api/pch_api.h @@ -0,0 +1,40 @@ +/* + * 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_PCH_API_H_ +#define TARGET_API_PCH_API_H_ + +#include + +namespace fs = std::filesystem; + +namespace buildcc::base { + +// Requires +// - TargetStorer +// - TargetState +// - TargetConfig +// - TargetEnv +template class PchApi { +public: + void AddPch(const fs::path &relative_filename, + const fs::path &relative_to_target_path = ""); + void AddPchAbsolute(const fs::path &absolute_filepath); +}; + +} // namespace buildcc::base + +#endif \ No newline at end of file diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 1124e39d..dcd2a9e5 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -40,6 +40,7 @@ #include "target/api/copy_api.h" #include "target/api/include_api.h" #include "target/api/lib_api.h" +#include "target/api/pch_api.h" #include "target/api/source_api.h" // Friend @@ -71,7 +72,8 @@ class Target : public BuilderInterface, public CopyApi, public SourceApi, public IncludeApi, - public LibApi { + public LibApi, + public PchApi { public: explicit Target(const std::string &name, TargetType type, @@ -93,11 +95,6 @@ class Target : public BuilderInterface, // Setters - // PCH - void AddPch(const fs::path &relative_filename, - const fs::path &relative_to_target_path = ""); - void AddPchAbsolute(const fs::path &absolute_filepath); - // * Flags void AddPreprocessorFlag(const std::string &flag); void AddCommonCompileFlag(const std::string &flag); @@ -231,6 +228,7 @@ class Target : public BuilderInterface, friend class SourceApi; friend class IncludeApi; friend class LibApi; + friend class PchApi; private: void Initialize(); diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp index e8e1bfaa..290f93b8 100644 --- a/buildcc/lib/target/src/api/lib_api.cpp +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -36,7 +36,7 @@ void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { t.storer_.current_lib_dirs.insert(absolute_lib_dir); } -template void LibApi::AddLibDep(const T &lib_dep) { +template void LibApi::AddLibDep(const Target &lib_dep) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); diff --git a/buildcc/lib/target/src/target/pch.cpp b/buildcc/lib/target/src/api/pch_api.cpp similarity index 58% rename from buildcc/lib/target/src/target/pch.cpp rename to buildcc/lib/target/src/api/pch_api.cpp index 4683e513..e439259e 100644 --- a/buildcc/lib/target/src/target/pch.cpp +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -14,29 +14,35 @@ * limitations under the License. */ +#include "target/api/pch_api.h" + #include "target/target.h" namespace buildcc::base { -void Target::AddPchAbsolute(const fs::path &absolute_filepath) { - state_.ExpectsUnlock(); - env::assert_fatal(config_.IsValidHeader(absolute_filepath), - fmt::format("{} does not have a valid header extension", - absolute_filepath)); +template +void PchApi::AddPchAbsolute(const fs::path &absolute_filepath) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.config_.ExpectsValidHeader(absolute_filepath); const fs::path absolute_pch = fs::path(absolute_filepath).make_preferred(); - storer_.current_pch_files.user.insert(absolute_pch); + t.storer_.current_pch_files.user.insert(absolute_pch); } -void Target::AddPch(const fs::path &relative_filename, - const fs::path &relative_to_target_path) { - env::log_trace(name_, __FUNCTION__); +template +void PchApi::AddPch(const fs::path &relative_filename, + const fs::path &relative_to_target_path) { + T &t = static_cast(*this); // Compute the absolute source path fs::path absolute_pch = - GetTargetRootDir() / relative_to_target_path / relative_filename; + t.env_.GetTargetRootDir() / relative_to_target_path / relative_filename; AddPchAbsolute(absolute_pch); } -} // namespace buildcc::base +template class PchApi; + +} // namespace buildcc::base \ No newline at end of file diff --git a/buildcc/lib/target/src/target/README.md b/buildcc/lib/target/src/target/README.md index 3633ab0f..27f90dba 100644 --- a/buildcc/lib/target/src/target/README.md +++ b/buildcc/lib/target/src/target/README.md @@ -24,7 +24,8 @@ Check the `include/target/api` and `src/api` folder - `include_api` - [x] Lib and Lib Dir - `lib_api` -- [ ] PCH +- [x] PCH + - `pch_api` - [ ] Flags - [ ] Rebuild Deps - [ ] Getters @@ -32,8 +33,6 @@ Check the `include/target/api` and `src/api` folder ## Inputs to Target -- [x] `pch.cpp` - - Precompile Header files - [x] `flags.cpp` - PreprocessorFlags - CommonCompileFlags