CMakeCommandLineInfo.cpp 3.2 KB

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