dodo  0.0.1
A C++ library to create containerized Linux services
buildenv.hpp
1 #ifndef dodo_common_buildenv_hpp
2 #define dodo_common_buildenv_hpp
3 
4 #include <sstream>
5 
6 namespace dodo {
7 
8  /**
9  * Build information, generated by cmake during builds from buildenv.hpp.in.
10  *
11  * - CMAKE_CXX_COMPILER_ID GNU
12  * - CMAKE_CXX_COMPILER_VERSION 9.3.0
13  * - CMAKE_SYSTEM Linux-5.4.0-1043-azure
14  * - CMAKE_SYSTEM_PROCESSOR x86_64
15  * - PROJECT_NAME dodo
16  * - PROJECT_VERSION_STR 0.0.1
17  * - CMAKE_VERSION 3.20.0
18  * - CMAKE_BUILD_TYPE
19  */
20  class BuildEnv {
21  public:
22  /**
23  * Get the C++ compiler id, see https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html.
24  * @return CMAKE_CXX_COMPILER_ID.
25  */
26  static std::string getCompilerId() { return "GNU"; }
27 
28  /**
29  * Get the compiler version.
30  * @return CMAKE_CXX_COMPILER_VERSION.
31  */
32  static std::string getCompilerVersion() { return "9.3.0"; }
33 
34  /**
35  * Get the compiler host.
36  * @return CMAKE_SYSTEM.
37  */
38  static std::string getBuildSystem() { return "Linux-5.4.0-1043-azure"; }
39 
40  /**
41  * Get the build target / architecture.
42  * @return CMAKE_SYSTEM_PROCESSOR.
43  */
44  static std::string getBuildTarget() { return "x86_64"; }
45 
46  /**
47  * Get the project name.
48  * @return PROJECT_NAME.
49  */
50  static std::string getProjectName() { return "dodo"; }
51 
52  /**
53  * Get the project version.
54  * @return PROJECT_VERSION_STR.
55  */
56  static std::string getProjectVersion() { return "0.0.1"; }
57 
58  /**
59  * Get the project version major.
60  * @return PROJECT_VERSION_MAJOR.
61  */
62  static int getProjectVersionMajor() { return 0; }
63 
64  /**
65  * Get the project version minor.
66  * @return PROJECT_VERSION_MINOR.
67  */
68  static int getProjectVersionMinor() { return 0; }
69 
70  /**
71  * Get the project version patch.
72  * @return PROJECT_VERSION_PATCH.
73  */
74  static int getProjectVersionPatch() { return 1; }
75 
76  /**
77  * Get the cmake version.
78  * @return CMAKE_VERSION.
79  */
80  static std::string getCMakeVersion() { return "3.20.0"; }
81 
82  /**
83  * Get the build type.
84  * @return CMAKE_BUILD_TYPE.
85  */
86  static std::string getCMakeBuildType() { return ""; }
87 
88  /**
89  * Get the build date.
90  * @return __DATE__.
91  */
92  static std::string getBuildDate() { return __DATE__; }
93 
94  /**
95  * Get the build time.
96  * @return __TIME__.
97  */
98  static std::string getBuildTime() { return __TIME__; }
99 
100  /**
101  * In rare cases (examples requiring artefacts build in source checkouts), this is usefull.
102  * @return The source directory.
103  */
104  static std::string getSourceDirectory() { return "/home/runner/work/dodo/dodo/src"; }
105 
106  /**
107  * In very rare cases (examples requiring artefacts build in source checkouts), this is usefull.
108  * @return The source directory.
109  */
110  static std::string getBinaryDirectory() { return "/home/runner/work/dodo/dodo/build"; }
111 
112  /**
113  * C++ standard enum.
114  */
115  enum cppStandard {
116  stUnknown, /**< Unknown C++ standard. */
117  stPreCpp11, /**< Before C++11. */
118  stCpp11, /**< C++ 11. */
119  stCpp14, /**< C++ 14. */
120  stCpp17 /**< C++ 17. */
121  };
122 
123  /**
124  * Get the C++ standard in effect during compiling as a string.
125  * @return The cppStandard as a string.
126  */
127  static std::string getCppStandardString() {
128  switch ( getCppStandard() ) {
129  case stUnknown: return "unknown";
130  case stPreCpp11: return "before C++11";
131  case stCpp11: return "C++11";
132  case stCpp14: return "C++14";
133  case stCpp17: return "C++17";
134  default: return "invalid cppStandard";
135  }
136  };
137 
138  /**
139  * Get the C++ standard in effect during compiling.
140  * @return The cppStandard.
141  */
143  if ( __cplusplus == 199711L ) return stPreCpp11;
144  else if ( __cplusplus == 201103L ) return stCpp11;
145  else if ( __cplusplus == 201402L ) return stCpp14;
146  else if ( __cplusplus == 201703L ) return stCpp17;
147  else return stUnknown;
148  };
149 
150  /**
151  * Get a description of the build environment.
152  * @return The description.
153  */
154  static std::string getDescription() {
155  std::stringstream ss;
156  ss << "project : " << getProjectName() << " " << getProjectVersion() << std::endl;
157  ss << "C++ standard : " << getCppStandardString() << std::endl;
158  ss << "cmake version : " << getCMakeVersion() << std::endl;
159  ss << "compiler : " << getCompilerId() << " " << getCompilerVersion() << std::endl;
160  ss << "build type : " << getCMakeBuildType() << std::endl;
161  ss << "build on : " << getBuildSystem() << std::endl;
162  ss << "build date : " << getBuildDate() << " " << getBuildTime() << std::endl;
163  ss << "target arch : " << getBuildTarget() << std::endl;
164  ss << "source directory : " << getSourceDirectory() << std::endl;
165  ss << "binary directory : " << getBinaryDirectory() << std::endl;
166  return ss.str();
167  }
168  };
169 
170 }
171 
172 #endif
dodo::BuildEnv::getProjectVersionMajor
static int getProjectVersionMajor()
Get the project version major.
Definition: buildenv.hpp:62
dodo::BuildEnv::getProjectVersionPatch
static int getProjectVersionPatch()
Get the project version patch.
Definition: buildenv.hpp:74
dodo::BuildEnv::stCpp11
@ stCpp11
C++ 11.
Definition: buildenv.hpp:118
dodo::BuildEnv::getCppStandard
static cppStandard getCppStandard()
Get the C++ standard in effect during compiling.
Definition: buildenv.hpp:142
dodo::BuildEnv
Build information, generated by cmake during builds from buildenv.hpp.in.
Definition: buildenv.hpp:20
dodo::BuildEnv::getCppStandardString
static std::string getCppStandardString()
Get the C++ standard in effect during compiling as a string.
Definition: buildenv.hpp:127
dodo::BuildEnv::stUnknown
@ stUnknown
Unknown C++ standard.
Definition: buildenv.hpp:116
dodo::BuildEnv::getProjectVersionMinor
static int getProjectVersionMinor()
Get the project version minor.
Definition: buildenv.hpp:68
dodo::BuildEnv::getProjectName
static std::string getProjectName()
Get the project name.
Definition: buildenv.hpp:50
dodo::BuildEnv::getBuildTarget
static std::string getBuildTarget()
Get the build target / architecture.
Definition: buildenv.hpp:44
dodo::BuildEnv::getProjectVersion
static std::string getProjectVersion()
Get the project version.
Definition: buildenv.hpp:56
dodo
A C++ platform interface to lean Linux services tailored for containerized deployment.
Definition: application.hpp:29
dodo::BuildEnv::getCMakeVersion
static std::string getCMakeVersion()
Get the cmake version.
Definition: buildenv.hpp:80
dodo::BuildEnv::getCompilerVersion
static std::string getCompilerVersion()
Get the compiler version.
Definition: buildenv.hpp:32
dodo::BuildEnv::getBuildSystem
static std::string getBuildSystem()
Get the compiler host.
Definition: buildenv.hpp:38
dodo::BuildEnv::getBuildDate
static std::string getBuildDate()
Get the build date.
Definition: buildenv.hpp:92
dodo::BuildEnv::getCompilerId
static std::string getCompilerId()
Get the C++ compiler id, see https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID....
Definition: buildenv.hpp:26
dodo::BuildEnv::getBinaryDirectory
static std::string getBinaryDirectory()
In very rare cases (examples requiring artefacts build in source checkouts), this is usefull.
Definition: buildenv.hpp:110
dodo::BuildEnv::getSourceDirectory
static std::string getSourceDirectory()
In rare cases (examples requiring artefacts build in source checkouts), this is usefull.
Definition: buildenv.hpp:104
dodo::BuildEnv::stCpp17
@ stCpp17
C++ 17.
Definition: buildenv.hpp:120
dodo::BuildEnv::cppStandard
cppStandard
C++ standard enum.
Definition: buildenv.hpp:115
dodo::BuildEnv::getDescription
static std::string getDescription()
Get a description of the build environment.
Definition: buildenv.hpp:154
dodo::BuildEnv::getCMakeBuildType
static std::string getCMakeBuildType()
Get the build type.
Definition: buildenv.hpp:86
dodo::BuildEnv::getBuildTime
static std::string getBuildTime()
Get the build time.
Definition: buildenv.hpp:98
dodo::BuildEnv::stCpp14
@ stCpp14
C++ 14.
Definition: buildenv.hpp:119
dodo::BuildEnv::stPreCpp11
@ stPreCpp11
Before C++11.
Definition: buildenv.hpp:117