diff options
Diffstat (limited to 'Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in')
-rw-r--r-- | Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in new file mode 100644 index 0000000..3183bc0 --- /dev/null +++ b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in @@ -0,0 +1,54 @@ +#include <cmSystemTools.h> +#include "cmsys/Encoding.hxx" +#include <string> + +#define RETVAL @_retval@ + +int main(int ac, char** av) +{ + cmsys::Encoding::CommandLineArguments args = + cmsys::Encoding::CommandLineArguments::Main(ac, av); + int argc = args.argc(); + const char* const* argv = args.argv(); + + std::string exename = argv[0]; + std::string logarg; + bool nextarg = false; + + if (exename.find("valgrind") != std::string::npos) { + logarg = "--log-file="; + } else if (exename.find("purify") != std::string::npos) { +#ifdef _WIN32 + logarg = "/SAVETEXTDATA="; +#else + logarg = "-log-file="; +#endif + } else if (exename.find("BC") != std::string::npos) { + nextarg = true; + logarg = "/X"; + } + + if (!logarg.empty()) { + std::string logfile; + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + if (arg.find(logarg) == 0) { + if (nextarg) { + if (i == argc - 1) { + return 1; // invalid command line + } + logfile = argv[i + 1]; + } else { + logfile = arg.substr(logarg.length()); + } + // keep searching, it may be overridden later to provoke an error + } + } + + if (!logfile.empty()) { + cmSystemTools::Touch(logfile, true); + } + } + + return RETVAL; +} |