From df71ec8b203fb23ab1c8d8da4eb4aaec550a5619 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 02:38:54 -0800 Subject: [PATCH 1/6] Update include_api.h --- buildcc/lib/target/include/target/api/include_api.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/buildcc/lib/target/include/target/api/include_api.h b/buildcc/lib/target/include/target/api/include_api.h index c4b1322b..875aa273 100644 --- a/buildcc/lib/target/include/target/api/include_api.h +++ b/buildcc/lib/target/include/target/api/include_api.h @@ -23,6 +23,11 @@ namespace fs = std::filesystem; namespace buildcc::base { +// Requires +// - TargetStorer +// - TargetState +// - TargetConfig +// - TargetEnv template class IncludeApi { public: void AddHeader(const fs::path &relative_filename, From e0e06e1fa2961146f6cb625266eb64a98338a910 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 03:00:12 -0800 Subject: [PATCH 2/6] Added lib_api --- buildcc/lib/target/cmake/mock_target.cmake | 1 + buildcc/lib/target/cmake/target.cmake | 2 + .../lib/target/include/target/api/lib_api.h | 42 ++++++++++++++ buildcc/lib/target/src/api/lib_api.cpp | 55 +++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 buildcc/lib/target/include/target/api/lib_api.h create mode 100644 buildcc/lib/target/src/api/lib_api.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index a8dadc66..b43ed67d 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -10,6 +10,7 @@ add_library(mock_target STATIC src/api/copy_api.cpp src/api/source_api.cpp src/api/include_api.cpp + src/api/lib_api.cpp # Generator src/generator/generator_loader.cpp diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index 08201eb5..0bc4968d 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -21,9 +21,11 @@ set(TARGET_SRCS src/api/copy_api.cpp src/api/source_api.cpp src/api/include_api.cpp + src/api/lib_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 # Generator src/generator/generator_loader.cpp diff --git a/buildcc/lib/target/include/target/api/lib_api.h b/buildcc/lib/target/include/target/api/lib_api.h new file mode 100644 index 00000000..1ab4348e --- /dev/null +++ b/buildcc/lib/target/include/target/api/lib_api.h @@ -0,0 +1,42 @@ +/* + * 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_LIB_API_H_ +#define TARGET_API_LIB_API_H_ + +#include +#include + +namespace fs = std::filesystem; + +namespace buildcc::base { + +// Requires +// - TargetStorer +// - TargetState +// - TargetEnv +template class LibApi { +public: + void AddLibDep(const T &lib_dep); + void AddLibDep(const std::string &lib_dep); + + void AddLibDir(const fs::path &relative_lib_dir); + void AddLibDirAbsolute(const fs::path &absolute_lib_dir); +}; + +} // namespace buildcc::base + +#endif diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp new file mode 100644 index 00000000..e8e1bfaa --- /dev/null +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -0,0 +1,55 @@ +/* + * 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/lib_api.h" + +#include "target/target.h" + +namespace buildcc::base { + +template +void LibApi::AddLibDir(const fs::path &relative_lib_dir) { + T &t = static_cast(*this); + + fs::path final_lib_dir = t.env_.GetTargetRootDir() / relative_lib_dir; + AddLibDirAbsolute(final_lib_dir); +} + +template +void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_lib_dirs.insert(absolute_lib_dir); +} + +template void LibApi::AddLibDep(const T &lib_dep) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_lib_deps.user.insert(lib_dep.GetTargetPath()); +} + +template void LibApi::AddLibDep(const std::string &lib_dep) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_external_lib_deps.insert(lib_dep); +} + +template class LibApi; + +} // namespace buildcc::base From 3debba504248e1084eafedf302fd2a15a8c2e9b8 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 03:00:36 -0800 Subject: [PATCH 3/6] Update target.h --- buildcc/lib/target/include/target/target.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 44c0a8e7..1124e39d 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -39,6 +39,7 @@ // API #include "target/api/copy_api.h" #include "target/api/include_api.h" +#include "target/api/lib_api.h" #include "target/api/source_api.h" // Friend @@ -69,7 +70,8 @@ namespace buildcc::base { class Target : public BuilderInterface, public CopyApi, public SourceApi, - public IncludeApi { + public IncludeApi, + public LibApi { public: explicit Target(const std::string &name, TargetType type, @@ -96,14 +98,6 @@ class Target : public BuilderInterface, const fs::path &relative_to_target_path = ""); void AddPchAbsolute(const fs::path &absolute_filepath); - // * Include and Lib directory - void AddLibDir(const fs::path &relative_lib_dir); - void AddLibDirAbsolute(const fs::path &absolute_lib_dir); - - // * Libraries - void AddLibDep(const Target &lib_dep); - void AddLibDep(const std::string &lib_dep); - // * Flags void AddPreprocessorFlag(const std::string &flag); void AddCommonCompileFlag(const std::string &flag); @@ -236,6 +230,7 @@ class Target : public BuilderInterface, friend class CopyApi; friend class SourceApi; friend class IncludeApi; + friend class LibApi; private: void Initialize(); From 9ff05174533ebf5cfa6819ffe3adeffc3bbe3300 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 03:03:00 -0800 Subject: [PATCH 4/6] Removed lib.cpp --- buildcc/lib/target/cmake/mock_target.cmake | 1 - buildcc/lib/target/cmake/target.cmake | 1 - buildcc/lib/target/src/target/lib.cpp | 53 ---------------------- 3 files changed, 55 deletions(-) delete mode 100644 buildcc/lib/target/src/target/lib.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index b43ed67d..36c6ebc9 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -32,7 +32,6 @@ add_library(mock_target STATIC src/target/target_storer.cpp src/target/pch.cpp - src/target/lib.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 0bc4968d..7ee43969 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -53,7 +53,6 @@ set(TARGET_SRCS include/target/target.h src/target/pch.cpp - src/target/lib.cpp src/target/flags.cpp src/target/additional_deps.cpp diff --git a/buildcc/lib/target/src/target/lib.cpp b/buildcc/lib/target/src/target/lib.cpp deleted file mode 100644 index d1c1a16b..00000000 --- a/buildcc/lib/target/src/target/lib.cpp +++ /dev/null @@ -1,53 +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" - -#include "env/assert_fatal.h" - -#include "target/util.h" - -namespace buildcc::base { - -void Target::AddLibDir(const fs::path &relative_lib_dir) { - env::log_trace(name_, __FUNCTION__); - - fs::path final_lib_dir = GetTargetRootDir() / relative_lib_dir; - AddLibDirAbsolute(final_lib_dir); -} - -void Target::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { - env::log_trace(name_, __FUNCTION__); - - state_.ExpectsUnlock(); - storer_.current_lib_dirs.insert(absolute_lib_dir); -} - -void Target::AddLibDep(const Target &lib_dep) { - env::log_trace(name_, __FUNCTION__); - - state_.ExpectsUnlock(); - storer_.current_lib_deps.user.insert(lib_dep.GetTargetPath()); -} - -void Target::AddLibDep(const std::string &lib_dep) { - env::log_trace(name_, __FUNCTION__); - - state_.ExpectsUnlock(); - storer_.current_external_lib_deps.insert(lib_dep); -} - -} // namespace buildcc::base From 9a5405421d381bf495ff880c314401d48c785813 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 03:03:06 -0800 Subject: [PATCH 5/6] Update README.md --- buildcc/lib/target/src/target/README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/buildcc/lib/target/src/target/README.md b/buildcc/lib/target/src/target/README.md index e739496a..3633ab0f 100644 --- a/buildcc/lib/target/src/target/README.md +++ b/buildcc/lib/target/src/target/README.md @@ -22,7 +22,8 @@ Check the `include/target/api` and `src/api` folder - `source_api` - [x] Header and Include Dir - `include_api` -- [ ] Lib and Lib Dir +- [x] Lib and Lib Dir + - `lib_api` - [ ] PCH - [ ] Flags - [ ] Rebuild Deps @@ -33,10 +34,6 @@ Check the `include/target/api` and `src/api` folder - [x] `pch.cpp` - Precompile Header files -- [x] `lib.cpp` - - Lib Dir - - Lib File (full path Target supplied) - - External Lib File (relative link using -l) - [x] `flags.cpp` - PreprocessorFlags - CommonCompileFlags From 5fb86212142f1c2df8a8bf6f63c4eca07ad124ad Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 03:06:48 -0800 Subject: [PATCH 6/6] Update lib_api.h --- buildcc/lib/target/include/target/api/lib_api.h | 1 + 1 file changed, 1 insertion(+) diff --git a/buildcc/lib/target/include/target/api/lib_api.h b/buildcc/lib/target/include/target/api/lib_api.h index 1ab4348e..1566bf10 100644 --- a/buildcc/lib/target/include/target/api/lib_api.h +++ b/buildcc/lib/target/include/target/api/lib_api.h @@ -28,6 +28,7 @@ namespace buildcc::base { // - TargetStorer // - TargetState // - TargetEnv +// T::GetTargetPath template class LibApi { public: void AddLibDep(const T &lib_dep);