CMakeCommandLineInfo.cpp 3.3 KB

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