CMakeCommandLineInfo.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // CMakeCommandLineInfo.cpp : command line arguments
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeCommandLineInfo.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. ///////////////////////////////////////////////////////////////
  11. // CMakeCommandLineInfo
  12. CMakeCommandLineInfo::CMakeCommandLineInfo()
  13. {
  14. this->m_WhereSource = _T("");
  15. this->m_WhereBuild = _T("");
  16. this->m_AdvancedValues = FALSE;
  17. this->m_GeneratorChoiceString = _T("");
  18. this->m_LastUnknownParameter = _T("");
  19. // Find the path to the CMakeSetup executable.
  20. char fname[4096];
  21. ::GetModuleFileName(0, fname, 4096);
  22. m_Argv0 = fname;
  23. }
  24. CMakeCommandLineInfo::~CMakeCommandLineInfo()
  25. {
  26. }
  27. int CMakeCommandLineInfo::GetBoolValue(const CString& v) {
  28. CString value = v;
  29. value.MakeLower();
  30. if (value == "1" ||
  31. value == "on" ||
  32. value == "true" ||
  33. value == "yes")
  34. {
  35. return 1;
  36. }
  37. else if (value == "0" ||
  38. value == "off" ||
  39. value == "false" ||
  40. value == "no")
  41. {
  42. return -1;
  43. }
  44. return 0;
  45. }
  46. ///////////////////////////////////////////////////////////////
  47. // Parse param
  48. void CMakeCommandLineInfo::ParseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
  49. {
  50. // Construct the full name of the argument.
  51. cmStdString param = lpszParam;
  52. cmStdString value;
  53. if(bFlag)
  54. {
  55. // Since bFlag is set, either a - or a / was removed from the
  56. // parameter value. Assume it was a - unless the second character
  57. // was a / which indicates a network path argument.
  58. if(param.length() > 0 && param[0] == '/')
  59. {
  60. value = "/";
  61. }
  62. else
  63. {
  64. value = "-";
  65. }
  66. }
  67. value += param;
  68. // Add the argument and reset the argv table in case strings were
  69. // moved.
  70. m_Arguments.push_back(value);
  71. m_Argv.clear();
  72. m_Argv.push_back(m_Argv0.c_str());
  73. for(unsigned int i=0; i < m_Arguments.size(); ++i)
  74. {
  75. m_Argv.push_back(m_Arguments[i].c_str());
  76. }
  77. // Look for known flags.
  78. if(!bFlag)
  79. {
  80. this->m_LastUnknownParameter = lpszParam;
  81. }
  82. else
  83. {
  84. CString sParam(lpszParam);
  85. // Single letter valued flag like /B=value or /B:value
  86. CString value;
  87. if (sParam[1] == '=' || sParam[1] == ':')
  88. {
  89. value = sParam.Right(sParam.GetLength() - 2);
  90. }
  91. else
  92. {
  93. value = sParam.Right(sParam.GetLength()-1);
  94. }
  95. int res;
  96. switch (sParam[0])
  97. {
  98. case 'A':
  99. res = CMakeCommandLineInfo::GetBoolValue(value);
  100. if (res == 1)
  101. {
  102. this->m_AdvancedValues = TRUE;
  103. }
  104. else if (res == -1)
  105. {
  106. this->m_AdvancedValues = FALSE;
  107. }
  108. break;
  109. case 'B':
  110. this->m_WhereBuild = value;
  111. break;
  112. case 'G':
  113. this->m_GeneratorChoiceString = value;
  114. break;
  115. case 'H':
  116. this->m_WhereSource = value;
  117. break;
  118. }
  119. }
  120. // Call the base class to ensure proper command line processing
  121. CCommandLineInfo::ParseParam(lpszParam, bFlag, bLast);
  122. }