Skip to content

Commit

Permalink
getPlatformString (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitre authored Aug 24, 2024
1 parent 00ff713 commit 8c94b76
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions commandLine/src/defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define OFPROJECTGENERATOR_MAJOR_VERSION 0
#define OFPROJECTGENERATOR_MINOR_VERSION 71
#define OFPROJECTGENERATOR_MINOR_VERSION 72
#define OFPROJECTGENERATOR_PATCH_VERSION 0

#define PG_VERSION "0.71.0"
#define PG_VERSION "0.72.0"
4 changes: 2 additions & 2 deletions commandLine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ int main(int argc, char ** argv) {
bRecursive = false;
bHelpRequested = false;
bListTemplates = false;
// FIXME! problem.
targets.emplace_back(platformsToString[ofGetTargetPlatform()]);
targets.emplace_back(getPlatformString());

startTime = 0;
nProjectsUpdated = 0;
nProjectsCreated = 0;
Expand Down
60 changes: 60 additions & 0 deletions commandLine/src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,66 @@

using std::unique_ptr;

std::string execute_popen(const char* cmd) {
std::array<char, 128> buffer;
std::string result;

#ifdef _WIN32
auto pipe = _popen(cmd, "r");
#else
auto pipe = popen(cmd, "r");
#endif

if (!pipe) throw std::runtime_error("popen() failed!");

while (!feof(pipe)) {
if (fgets(buffer.data(), buffer.size(), pipe) != nullptr)
result += buffer.data();
}

#ifdef _WIN32
auto rc = _pclose(pipe);
#else
auto rc = pclose(pipe);
#endif


if (rc == EXIT_SUCCESS) { // == 0

} else if (rc == EXIT_FAILURE) { // EXIT_FAILURE is not used by all programs, maybe needs some adaptation.

}
// trim last line break
result.pop_back();
return result;
}

std::string getPlatformString() {
#ifdef __linux__
string arch = execute_popen("uname -m");
if (
arch == "armv6l" ||
arch == "armv7l" ||
arch == "aarch64"
) {
return "linux" + arch;
}
else {
return "linux64";
}
#elif defined(__WIN32__)
#if defined(__MINGW32__) || defined(__MINGW64__)
return "msys2";
#else
return "vs";
#endif
#elif defined(__APPLE_CC__)
return "osx";
#else
return {};
#endif
}

string generateUUID(const string & input){
return uuidxx::uuid::Generate().ToString(false);
}
Expand Down
4 changes: 4 additions & 0 deletions commandLine/src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "baseProject.h"
struct LibraryBinary;

std::string execute_popen(const char* cmd);

std::string getPlatformString();

namespace fs = of::filesystem;
using std::string;
using std::vector;
Expand Down

0 comments on commit 8c94b76

Please sign in to comment.