Skip to content

Commit

Permalink
App: let CommandSystemInformation support registration of library info
Browse files Browse the repository at this point in the history
Relates to GitHub #210
  • Loading branch information
HuguesDelorme committed Jul 25, 2023
1 parent ef4f7da commit a6be154
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/app/command_system_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#endif

#include <thread>
#include <vector>

namespace Mayo {

Expand Down Expand Up @@ -128,6 +129,17 @@ QTextStream& operator<<(QTextStream& str, std::string_view sv)
const char indent[] = " ";
const char indentx2[] = " ";

struct LibraryInfo {
std::string name;
std::string data;
};

std::vector<LibraryInfo>& getLibraryInfos()
{
static std::vector<LibraryInfo> vec;
return vec;
}

} // namespace

static void dumpOpenGlInfo(QTextStream& str)
Expand Down Expand Up @@ -211,10 +223,9 @@ QString CommandSystemInformation::data()
// OpenCascade version
ostr << '\n' << "OpenCascade(build): " << OCC_VERSION_STRING_EXT << '\n';

// gmio version
#ifdef HAVE_GMIO
ostr << '\n' << "gmio(build): " << GMIO_VERSION_STR << '\n';
#endif
// Other registered libraries
for (const LibraryInfo& libInfo : getLibraryInfos())
ostr << '\n' << to_QString(libInfo.name) << ": " << to_QString(libInfo.data) << '\n';

// I/O supported formats
{
Expand Down Expand Up @@ -410,4 +421,12 @@ QString CommandSystemInformation::data()
return strSysInfo;
}

void CommandSystemInformation::addLibraryInfo(std::string_view libName, std::string_view data)
{
if (!libName.empty() && !data.empty()) {
LibraryInfo libInfo{ std::string(libName), std::string(data) };
getLibraryInfos().push_back(std::move(libInfo));
}
}

} // namespace Mayo
1 change: 1 addition & 0 deletions src/app/commands_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CommandSystemInformation : public Command {
void execute() override;

static QString data();
static void addLibraryInfo(std::string_view libName, std::string_view data);

static constexpr std::string_view Name = "system-info";
};
Expand Down
3 changes: 3 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ static int runApp(QCoreApplication* qtApp)
appModule->properties()->IO_bindParameters(ioSystem);
appModule->properties()->retranslate();

// Register library infos
CommandSystemInformation::addLibraryInfo(IO::GmioLib::strName, IO::GmioLib::strVersion);

// Process CLI
if (args.showSystemInformation) {
CommandSystemInformation cmdSysInfo(nullptr);
Expand Down
16 changes: 16 additions & 0 deletions src/io_gmio/io_gmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

#include "../base/io_writer.h"
#include "../base/property.h"

#ifdef HAVE_GMIO
# include <gmio_core/version.h>
#endif

#include <memory>

namespace Mayo {
Expand All @@ -29,5 +34,16 @@ class GmioFactoryWriter : public FactoryWriter {
}
};

struct GmioLib {
static constexpr char strName[] = "gmio(build)";
static constexpr char strVersion[] =
#ifdef HAVE_GMIO
GMIO_VERSION_STR
#else
""
#endif
;
};

} // namespace IO
} // namespace Mayo

0 comments on commit a6be154

Please sign in to comment.