Skip to content

Commit 652c032

Browse files
committed
Add static functions to extract the current project informations
1 parent 8e9bd0c commit 652c032

7 files changed

Lines changed: 258 additions & 2 deletions

File tree

‎ElementsExamples/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ elements_add_library(ElementsOther src/lib/other/*.cpp
3030
# CppProgramExample is the executable name
3131
# src/Program/ProgramExample.cpp is the source file
3232
elements_add_executable(CppProgramExample src/program/ProgramExample.cpp
33-
INCLUDE_DIRS Boost ElementsExamples
34-
LINK_LIBRARIES Boost ElementsExamples)
33+
INCLUDE_DIRS Boost ElementsExamples ElementsOther
34+
LINK_LIBRARIES Boost ElementsExamples ElementsOther)
3535

3636
elements_add_executable(ElementsSimpleProgramExample src/program/SimpleProgramExample.cpp
3737
INCLUDE_DIRS Boost ElementsExamples
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file printProject.h
3+
*
4+
* @date May 14, 2020
5+
* @author hubert
6+
*
7+
* @copyright 2012-2020 Euclid Science Ground Segment
8+
*
9+
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
10+
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
11+
* any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15+
* details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
*/
21+
22+
/**
23+
* @addtogroup ElementsExamples ElementsExamples
24+
* @{
25+
*/
26+
27+
#ifndef ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_PRINTPROJECT_H_
28+
#define ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_PRINTPROJECT_H_
29+
30+
#include "ElementsKernel/Export.h"
31+
32+
namespace Elements {
33+
namespace Examples {
34+
35+
ELEMENTS_API void printProject();
36+
37+
} // namespace Examples
38+
} // namespace Elements
39+
40+
#endif // ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_PRINTPROJECT_H_
41+
42+
/**@}*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file printProject.cpp
3+
*
4+
* @date May 14, 2020
5+
* @author Hubert Degaudenzi
6+
*
7+
* @copyright 2012-2020 Euclid Science Ground Segment
8+
*
9+
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
10+
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
11+
* any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15+
* details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
*/
21+
22+
#include <iostream>
23+
24+
#include "ElementsKernel/Project.h" // for Project
25+
26+
#include "ElementsExamples/printProject.h"
27+
28+
29+
namespace Elements {
30+
namespace Examples {
31+
32+
void printProject() {
33+
std::cout << Project() << std::endl;
34+
}
35+
36+
} // namespace Examples
37+
} // namespace Elements

‎ElementsExamples/src/program/ProgramExample.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
#include "ElementsKernel/ProgramHeaders.h" // for including all Program/related headers
3333
#include "ElementsKernel/ThisModule.h" // for getThisExecutableInfo
34+
#include "ElementsKernel/Project.h" // for Project
3435

3536
#include "ElementsExamples/functionExample.h"
37+
#include "ElementsExamples/printProject.h"
3638

3739

3840
using std::map;
@@ -236,6 +238,12 @@ class ProgramExample: public Program {
236238

237239
myLocalLogTestFunc();
238240

241+
printProject();
242+
243+
log.info() << Project();
244+
log.info() << "Project Name: " << Project::name();
245+
log.info() << "Project Version: " << Project::versionString();
246+
239247
log.info("#");
240248
log.info("Exiting mainMethod()");
241249
return ExitCode::OK;

‎ElementsKernel/CMakeLists.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ elements_add_unit_test(Exception tests/src/Exception_test.cpp
142142
EXECUTABLE Exception_test
143143
LINK_LIBRARIES ElementsKernel TYPE Boost)
144144

145+
#-----------------------
146+
# Project_test
147+
elements_add_unit_test(Project tests/src/Project_test.cpp
148+
EXECUTABLE Project_test
149+
LINK_LIBRARIES ElementsKernel TYPE Boost)
150+
151+
145152
#-----------------------
146153
# OpenMP_test
147154
if(ELEMENTS_PARALLEL AND OPENMP_FOUND)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @file ElementsKernel/Project.h
3+
* @brief Defines tools to describe the current project
4+
* @date May 14, 2020
5+
* @author Hubert Degaudenzi
6+
*
7+
* @copyright 2012-2020 Euclid Science Ground Segment
8+
*
9+
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
10+
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
11+
* any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15+
* details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
*/
21+
22+
/**
23+
* @addtogroup ElementsKernel ElementsKernel
24+
* @{
25+
*/
26+
27+
28+
#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_PROJECT_H_
29+
#define ELEMENTSKERNEL_ELEMENTSKERNEL_PROJECT_H_
30+
31+
#include <string> // for string
32+
#include <vector> // for vector
33+
#include <cstdint> // for uing_least64_t
34+
#include <iostream> // for ostream
35+
#include <algorithm> // for for_each
36+
37+
#include "ThisProject.h" // local project constants generated
38+
// by the build system
39+
40+
namespace Elements {
41+
42+
struct Project {
43+
static inline std::string name() {
44+
return THIS_PROJECT_NAME_STRING;
45+
}
46+
47+
static inline std::string versionString() {
48+
return THIS_PROJECT_VERSION_STRING;
49+
}
50+
static inline std::uint_least64_t version() {
51+
return THIS_PROJECT_VERSION;
52+
}
53+
static inline std::uint_least64_t majorVersion() {
54+
return THIS_PROJECT_MAJOR_VERSION;
55+
}
56+
static inline std::uint_least64_t minorVersion() {
57+
return THIS_PROJECT_MINOR_VERSION;
58+
}
59+
static inline std::uint_least64_t patchVersion() {
60+
return THIS_PROJECT_PATCH_VERSION;
61+
}
62+
static inline std::string originalVersion() {
63+
return THIS_PROJECT_ORIGINAL_VERSION;
64+
}
65+
static inline std::string vcsVersion() {
66+
return THIS_PROJECT_VCS_VERSION;
67+
}
68+
69+
static inline std::string installLocation() {
70+
return THIS_PROJECT_INSTALL_LOCATION_STRING;
71+
}
72+
static inline bool useSoVersion() {
73+
return THIS_PROJECT_USE_SOVERSION;
74+
}
75+
static inline std::string installPrefix() {
76+
return CMAKE_INSTALL_PREFIX_STRING;
77+
}
78+
static inline std::vector<std::string> searchDirectories() {
79+
return THIS_PROJECT_SEARCH_DIRS;
80+
}
81+
82+
83+
};
84+
85+
inline std::ostream& operator<<(std::ostream& stream, const Project& p) {
86+
stream << "Name: " << p.name() << std::endl;
87+
stream << "Version String: " << p.versionString() << std::endl;
88+
stream << "Version: " << p.version() << std::endl;
89+
stream << "Major Version: " << p.majorVersion() << std::endl;
90+
stream << "Minor Version: " << p.minorVersion() << std::endl;
91+
stream << "Patch Version: " << p.patchVersion() << std::endl;
92+
stream << "Original Version: " << p.originalVersion() << std::endl;
93+
stream << "VCS Version: " << p.vcsVersion() << std::endl;
94+
stream << "Install Location: " << p.installLocation() << std::endl;
95+
stream << "Use So Version: " << p.useSoVersion() << std::endl;
96+
stream << "Install Prefix: " << p.installPrefix() << std::endl;
97+
stream << "Search Directories: ";
98+
99+
for (const auto& d : p.searchDirectories()) {
100+
stream << d << " ";
101+
}
102+
103+
return stream;
104+
}
105+
106+
} // namespace Elements
107+
108+
#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_PROJECT_H_
109+
110+
/**@}*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file Project_test.cpp
3+
*
4+
* @date May 14, 2020
5+
* @author Hubert Degaudenzi
6+
*
7+
* @copyright 2012-2020 Euclid Science Ground Segment
8+
*
9+
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
10+
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
11+
* any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15+
* details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
*/
21+
22+
#include "ElementsKernel/Project.h" // for Project
23+
24+
#include <iostream>
25+
#include <boost/test/unit_test.hpp>
26+
27+
namespace Elements {
28+
29+
//-----------------------------------------------------------------------------
30+
//-----------------------------------------------------------------------------
31+
//
32+
// Begin of the Boost tests
33+
//
34+
//-----------------------------------------------------------------------------
35+
36+
BOOST_AUTO_TEST_SUITE(Project_test)
37+
38+
//-----------------------------------------------------------------------------
39+
40+
BOOST_AUTO_TEST_CASE(Info_test) {
41+
BOOST_CHECK(Project::name() == "Elements");
42+
}
43+
44+
BOOST_AUTO_TEST_SUITE_END()
45+
46+
//-----------------------------------------------------------------------------
47+
//
48+
// End of the Boost tests
49+
//
50+
//-----------------------------------------------------------------------------
51+
52+
} // namespace Elements

0 commit comments

Comments
 (0)