Skip to content

Commit 5849316

Browse files
committed
Revamps project structure.
1 parent 9c1818e commit 5849316

11 files changed

+202
-185
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#ifndef BUILD_VERSION_UTILS_H
2+
#define BUILD_VERSION_UTILS_H
3+
4+
#if __has_include("version_info.hpp")
5+
#include "version_info.hpp"
6+
#else
7+
// Define custom macros if the header file doesn't exist
8+
#define VERSION_MAJOR 0
9+
#define VERSION_MINOR 1
10+
#define VERSION_PATCH 0
11+
#define BUILD_INDEX 0
12+
#define REPO_INDEX "aaaaaaaa"
13+
#endif
14+
15+
#if __has_include("module_name.hpp")
16+
#include "module_name.hpp"
17+
#else
18+
#define MODULE_NAME "module-template"
19+
#endif
20+
21+
#include <string>
22+
23+
/**
24+
* @brief Implements functions that help with general information
25+
* about the build of the application.
26+
*
27+
*/
28+
namespace build_info
29+
{
30+
/**
31+
* @brief Returns the name of
32+
* the app/module/library.
33+
*
34+
* @return std::string
35+
*/
36+
inline std::string get_app_name()
37+
{
38+
return std::string(MODULE_NAME);
39+
}
40+
41+
/**
42+
* @brief Get the compiler information used to
43+
* build the module where the function is called
44+
* from.
45+
*
46+
* @return std::string
47+
*/
48+
inline std::string get_compiler_info()
49+
{
50+
// Compiler name
51+
#ifdef __clang__
52+
std::string compilerName = "Clang";
53+
#elif defined(__INTEL_LLVM_COMPILER)
54+
std::string compilerName = "Intel DPC++";
55+
#elif defined(__INTEL_COMPILER)
56+
std::string compilerName = "Intel C++ Classic";
57+
#elif defined(__GNUC__)
58+
std::string compilerName = "GCC (GNU Compiler Collection)";
59+
#elif defined(_MSC_VER)
60+
std::string compilerName = "Microsoft Visual C++";
61+
#else
62+
std::string compilerName = "Unknown Compiler";
63+
#endif
64+
65+
// Compiler version
66+
#ifdef __clang__
67+
std::string compilerVersion = __clang_version__;
68+
#elif defined(__INTEL_LLVM_COMPILER)
69+
long long v = __INTEL_LLVM_COMPILER;
70+
71+
long long vmajor = v / 1'000'000;
72+
long long va = v % 1'000'000;
73+
74+
long long vminor = va / 1000;
75+
long long vv = va % 1000;
76+
77+
std::string compilerVersion = std::to_string(vmajor) + std::string(".") + std::to_string(vminor) + std::string(".") + std::to_string(vv);
78+
#elif defined(__INTEL_COMPILER)
79+
long long v = __INTEL_COMPILER;
80+
81+
long long vmajor = v / 100;
82+
long long vminor = v % 100;
83+
84+
std::string compilerVersion = std::to_string(vmajor) + std::string(".") + std::to_string(vminor);
85+
#elif defined(__GNUC__)
86+
std::string compilerVersion = std::to_string(__GNUC__) + "." +
87+
std::to_string(__GNUC_MINOR__) + "." +
88+
std::to_string(__GNUC_PATCHLEVEL__);
89+
#elif defined(_MSC_VER)
90+
// https://devblogs.microsoft.com/oldnewthing/20221219-00/?p=107601
91+
long long v = _MSC_FULL_VER;
92+
93+
long long vmajor = v / 10000000;
94+
long long va = v % 10000000;
95+
96+
long long vminor = va / 100000;
97+
long long vv = va % 100000;
98+
99+
//std::string compilerVersion = std::to_string(_MSC_FULL_VER);
100+
std::string compilerVersion = std::to_string(vmajor) + std::string(".") + std::to_string(vminor) + std::string(".") + std::to_string(vv);
101+
#else
102+
std::string compilerVersion = "Unknown Version";
103+
#endif
104+
105+
return compilerName + std::string(" :: ") + compilerVersion;
106+
}
107+
108+
/**
109+
* @brief Get the build date & time of the module
110+
* where the function is called from.
111+
*
112+
* @return std::string
113+
*/
114+
inline std::string get_build_date_time()
115+
{
116+
117+
std::string compileDate = __DATE__;
118+
std::string compileTime = __TIME__;
119+
120+
// Creating the formatted date and time string
121+
std::string compileDateTime = compileDate + ", " + compileTime;
122+
123+
return compileDateTime;
124+
}
125+
126+
/**
127+
* @brief Get the Nvidia CUDA version used to build
128+
* the module where the function is called from.
129+
*
130+
* @return CUDA version as a string.
131+
*/
132+
inline std::string get_nvidia_cuda_version()
133+
{
134+
#ifdef __NVCC__
135+
return std::string("CUDA") + " :: " +
136+
std::to_string(__CUDACC_VER_MAJOR__) + "." +
137+
std::to_string(__CUDACC_VER_MINOR__) + "." +
138+
std::to_string(__CUDACC_VER_BUILD__);
139+
#else
140+
return std::string("CUDA not used");
141+
#endif
142+
}
143+
144+
/**
145+
* @brief Get the version number for
146+
* the module/app/library being built.
147+
*
148+
* Follows Semantic versioning https://semver.org/
149+
*
150+
* @return Version as string, formatted as MAJOR.MINOR.PATCH+INDEX.REPO_INDEX
151+
*/
152+
inline std::string get_version()
153+
{
154+
std::string version = std::to_string(VERSION_MAJOR) + "." +
155+
std::to_string(VERSION_MINOR) + "." +
156+
std::to_string(VERSION_PATCH) + "+" +
157+
std::to_string(BUILD_INDEX) + "." +
158+
std::string(REPO_INDEX);
159+
160+
return version;
161+
}
162+
}
163+
164+
#endif // BUILD_VERSION_UTILS_H
File renamed without changes.
File renamed without changes.

include/build_version_utils.h

-147
This file was deleted.

include/hardware_info_utils.h renamed to include/hardware_info_utilities/hardware_info_utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef HARDWARE_INFO_UTILS_H
22
#define HARDWARE_INFO_UTILS_H
33

4-
#include "string_utils.h"
4+
#include "string_utilities/string_utils.hpp"
55

66
#include <string>
77
#include <stdexcept>

include/string_utils.h renamed to include/string_utilities/string_utils.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define STRING_UTILS_H
33

44
#include <algorithm>
5-
//#include <cctype>
65
#include <string>
76
#include <unordered_set>
87
#include <iomanip>

include/runtime_utils.h renamed to include/time_utilities/time_utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <chrono>
55
#include <string>
66

7-
namespace rtu
7+
namespace timeutil
88
{
99
/**
1010
* @brief A structure to facilitate measuring performance of parts

0 commit comments

Comments
 (0)