exe_common.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef EXE_COMMON_H
  2. #define EXE_COMMON_H
  3. #include <cstdlib>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. inline int runRealExe(const int argc, char** argv)
  8. {
  9. std::vector<std::string> args;
  10. std::string realMocPath;
  11. std::string const pathArg = "EXE_PATH=";
  12. std::string cmd;
  13. if (argc > 1) {
  14. for (int i = 1; i < argc; ++i) {
  15. std::string const arg = argv[i];
  16. if (arg.find(pathArg) != std::string::npos) {
  17. realMocPath = arg.substr(pathArg.length());
  18. // if EXE_PATH contains spaces, wrap it in quotes
  19. if (realMocPath.find(" ") != std::string::npos) {
  20. realMocPath = "\"" + realMocPath + "\"";
  21. }
  22. } else {
  23. args.push_back(arg);
  24. }
  25. }
  26. }
  27. #ifdef _WIN32
  28. cmd += "cmd /C \"";
  29. #endif
  30. cmd += realMocPath + " ";
  31. for (auto arg : args) {
  32. // if arg contains spaces, wrap it in quotes
  33. if (arg.find(' ') != std::string::npos) {
  34. cmd += " \"" + arg + "\"";
  35. } else {
  36. cmd += " " + arg;
  37. }
  38. }
  39. #ifdef _WIN32
  40. cmd += "\"";
  41. #endif
  42. std::cout << "Running real exe:" << cmd << std::endl;
  43. return std::system(cmd.c_str());
  44. }
  45. #endif