-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize cpp target generation (#203)
Signed-off-by: msclock <[email protected]>
- Loading branch information
Showing
40 changed files
with
208 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,4 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "compile_export.hpp" | ||
|
||
namespace compile { | ||
namespace info { | ||
/** | ||
* \brief Get compile version string | ||
* \return The distribution compile version provided. | ||
*/ | ||
std::string_view COMPILE_EXPORT version() noexcept; | ||
|
||
/** | ||
* \return A bool represents if it is debug distribution. | ||
*/ | ||
bool COMPILE_EXPORT is_debug() noexcept; | ||
} // namespace info | ||
} // namespace compile | ||
#include "distribution.hpp" | ||
#include "git.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "compile_export.hpp" | ||
|
||
namespace compile { | ||
namespace distribution { | ||
/** | ||
* \return A bool represents if it is debug distribution. | ||
*/ | ||
bool COMPILE_EXPORT is_debug() noexcept; | ||
} // namespace distribution | ||
} // namespace compile |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "distribution.hpp" | ||
|
||
namespace compile { | ||
namespace distribution { | ||
bool is_debug() noexcept { | ||
#ifdef _DEBUG | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
} // namespace distribution | ||
} // namespace compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
include(GoogleTest) | ||
|
||
file(GLOB files "*.cpp") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#include <gtest/gtest.h> | ||
#include "compile.hpp" | ||
|
||
TEST(info, version) { | ||
const auto version = compile::info::version(); | ||
EXPECT_FALSE(version.empty()); | ||
TEST(compile, version) { | ||
const auto version = git_ProjectVersion(); | ||
EXPECT_STRNE(version, ""); | ||
} | ||
|
||
TEST(info, distribution) { | ||
const auto is_debug = compile::info::is_debug(); | ||
TEST(compile, distribution) { | ||
const auto is_debug = compile::distribution::is_debug(); | ||
#ifdef _DEBUG | ||
GTEST_ASSERT_TRUE(is_debug); | ||
EXPECT_TRUE(is_debug); | ||
#else | ||
GTEST_ASSERT_FALSE(is_debug); | ||
EXPECT_FALSE(is_debug); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
namespace exe { | ||
namespace distribution { | ||
inline bool is_debug() noexcept { | ||
#ifdef _DEBUG | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
} // namespace distribution | ||
} // namespace exe |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "distribution.hpp" | ||
#include "git.h" | ||
#include "helpers.hpp" | ||
|
||
int main() { | ||
spdlog::info("Get a returned value: {} ; Version: {}", exe::helpers::some_fun(), git::ProjectVersion()); | ||
spdlog::info("Build Version: {}", git::ProjectVersion()); | ||
spdlog::info("Distribution Type: {}", exe::distribution::is_debug() ? "Debug" : "Release"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
include(GoogleTest) | ||
|
||
file(GLOB files "*.cpp") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <gtest/gtest.h> | ||
#include "distribution.hpp" | ||
#include "git.h" | ||
|
||
TEST(exe, version) { | ||
const auto version = git_ProjectVersion(); | ||
EXPECT_STRNE(version, ""); | ||
} | ||
|
||
TEST(exe, distribution) { | ||
const auto is_debug = exe::distribution::is_debug(); | ||
#ifdef _DEBUG | ||
EXPECT_TRUE(is_debug); | ||
#else | ||
EXPECT_FALSE(is_debug); | ||
#endif | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
namespace header { | ||
namespace distribution { | ||
inline bool is_debug() noexcept { | ||
#ifdef _DEBUG | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
} // namespace distribution | ||
} // namespace header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,4 @@ | ||
#pragma once | ||
|
||
#include <spdlog/spdlog.h> | ||
#include "distribution.hpp" | ||
#include "git.h" | ||
|
||
namespace header { | ||
namespace common { | ||
inline int some_fun() { | ||
spdlog::info("{}", git::ProjectVersion()); | ||
return 0; | ||
} | ||
|
||
const std::string_view const_string() { | ||
spdlog::info("Calling {}", __FUNCTION__); | ||
return "This is a header_only only const string"; | ||
} | ||
} // namespace common | ||
} // namespace header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
include(GoogleTest) | ||
|
||
file(GLOB files "*.cpp") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
#include <gtest/gtest.h> | ||
#include "header/header.hpp" | ||
|
||
TEST(common, some_fun) { | ||
const auto fun_ret = header::common::some_fun(); | ||
GTEST_ASSERT_EQ(0, fun_ret); | ||
TEST(header, version) { | ||
const auto version = git_ProjectVersion(); | ||
EXPECT_STRNE(version, ""); | ||
} | ||
|
||
TEST(common, const_string) { | ||
const auto fun_ret = header::common::const_string(); | ||
GTEST_ASSERT_GT(fun_ret.size(), 0); | ||
TEST(header, distribution) { | ||
const auto is_debug = header::distribution::is_debug(); | ||
#ifdef _DEBUG | ||
EXPECT_TRUE(is_debug); | ||
#else | ||
EXPECT_FALSE(is_debug); | ||
#endif | ||
} |
4 changes: 2 additions & 2 deletions
4
...ate/src/[% if compile_target != '' %]{{ compile_target }}[% endif %]/CMakeLists.txt.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
... if compile_target != '' %]{{ compile_target }}[% endif %]/include/distribution.hpp.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "{{ compile_target }}_export.hpp" | ||
|
||
namespace {{ compile_target }} { | ||
namespace distribution { | ||
/** | ||
* \return A bool represents if it is debug distribution. | ||
*/ | ||
bool {{ compile_target|upper }}_EXPORT is_debug() noexcept; | ||
} // namespace distribution | ||
} // namespace {{ compile_target }} |
19 changes: 2 additions & 17 deletions
19
...ile_target != '' %]{{ compile_target }}[% endif %]/include/{{ compile_target }}.hpp.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,4 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "{{ compile_target }}_export.hpp" | ||
|
||
namespace {{ compile_target }} { | ||
namespace info { | ||
/** | ||
* \brief Get {{ compile_target }} version string | ||
* \return The distribution {{ compile_target }} version provided. | ||
*/ | ||
std::string_view {{ compile_target|upper }}_EXPORT version() noexcept; | ||
|
||
/** | ||
* \return A bool represents if it is debug distribution. | ||
*/ | ||
bool {{ compile_target|upper }}_EXPORT is_debug() noexcept; | ||
} // namespace info | ||
} // namespace {{ compile_target }} | ||
#include "distribution.hpp" | ||
#include "git.h" |
13 changes: 13 additions & 0 deletions
13
...c/[% if compile_target != '' %]{{ compile_target }}[% endif %]/src/distribution.cpp.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "distribution.hpp" | ||
|
||
namespace {{ compile_target }} { | ||
namespace distribution { | ||
bool is_debug() noexcept { | ||
#ifdef _DEBUG | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
} // namespace distribution | ||
} // namespace {{ compile_target }} |
20 changes: 0 additions & 20 deletions
20
...compile_target != '' %]{{ compile_target }}[% endif %]/src/{{ compile_target }}.cpp.jinja
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...c/[% if compile_target != '' %]{{ compile_target }}[% endif %]/tests/CMakeLists.txt.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
include(GoogleTest) | ||
|
||
file(GLOB files "*.cpp") | ||
|
14 changes: 7 additions & 7 deletions
14
..._target != '' %]{{ compile_target }}[% endif %]/tests/test_{{ compile_target }}.cpp.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#include <gtest/gtest.h> | ||
#include "{{ compile_target }}.hpp" | ||
|
||
TEST(info, version) { | ||
const auto version = {{ compile_target }}::info::version(); | ||
EXPECT_FALSE(version.empty()); | ||
TEST({{ compile_target }}, version) { | ||
const auto version = git_ProjectVersion(); | ||
EXPECT_STRNE(version, ""); | ||
} | ||
|
||
TEST(info, distribution) { | ||
const auto is_debug = {{ compile_target }}::info::is_debug(); | ||
TEST({{ compile_target }}, distribution) { | ||
const auto is_debug = {{ compile_target }}::distribution::is_debug(); | ||
#ifdef _DEBUG | ||
GTEST_ASSERT_TRUE(is_debug); | ||
EXPECT_TRUE(is_debug); | ||
#else | ||
GTEST_ASSERT_FALSE(is_debug); | ||
EXPECT_FALSE(is_debug); | ||
#endif | ||
} |
4 changes: 2 additions & 2 deletions
4
template/src/[% if exe_target != '' %]{{ exe_target }}[% endif %]/CMakeLists.txt.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.