BUG: Fix find_* search order with path suffixes
[cmake.git] / Source / MFCDialog / CMakeCommandLineInfo.cpp
blob15c5c811f3958ba3df0b3ba4aa9987ab10f8a735
1 // CMakeCommandLineInfo.cpp : command line arguments
2 //
4 #include "stdafx.h"
5 #include "CMakeCommandLineInfo.h"
6 #include "cmSystemTools.h"
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
14 ///////////////////////////////////////////////////////////////
15 // CMakeCommandLineInfo
17 CMakeCommandLineInfo::CMakeCommandLineInfo()
19 this->m_WhereSource = _T("");
20 this->m_WhereBuild = _T("");
21 this->m_AdvancedValues = FALSE;
22 this->m_GeneratorChoiceString = _T("");
23 this->m_LastUnknownParameter = _T("");
25 // Find the path to the CMakeSetup executable.
26 char fname[4096];
27 ::GetModuleFileName(0, fname, 4096);
28 m_Argv0 = fname;
29 m_Argv.push_back(m_Argv0.c_str());
32 CMakeCommandLineInfo::~CMakeCommandLineInfo()
36 int CMakeCommandLineInfo::GetBoolValue(const CString& v) {
37 CString value = v;
38 value.MakeLower();
39 if (value == "1" ||
40 value == "on" ||
41 value == "true" ||
42 value == "yes")
44 return 1;
46 else if (value == "0" ||
47 value == "off" ||
48 value == "false" ||
49 value == "no")
51 return -1;
53 return 0;
56 ///////////////////////////////////////////////////////////////
57 // Parse param
59 void CMakeCommandLineInfo::ParseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
61 // Construct the full name of the argument.
62 cmStdString param = lpszParam;
63 cmStdString value;
64 if(bFlag)
66 // Since bFlag is set, either a - or a / was removed from the
67 // parameter value. Assume it was a - unless the second character
68 // was a / which indicates a network path argument.
69 if(param.length() > 0 && param[0] == '/')
71 value = "/";
73 else
75 value = "-";
78 value += param;
80 // Add the argument and reset the argv table in case strings were
81 // moved.
82 m_Arguments.push_back(value);
83 m_Argv.clear();
84 m_Argv.push_back(m_Argv0.c_str());
85 for(unsigned int i=0; i < m_Arguments.size(); ++i)
87 m_Argv.push_back(m_Arguments[i].c_str());
90 // Look for known flags.
91 if(!bFlag)
93 this->m_LastUnknownParameter = lpszParam;
95 else
97 CString sParam(lpszParam);
98 // Single letter valued flag like /B=value or /B:value
99 CString value;
100 if (sParam[1] == '=' || sParam[1] == ':')
102 value = sParam.Right(sParam.GetLength() - 2);
104 else
106 value = sParam.Right(sParam.GetLength()-1);
108 int res;
109 switch (sParam[0])
111 case 'A':
112 res = CMakeCommandLineInfo::GetBoolValue(value);
113 if (res == 1)
115 this->m_AdvancedValues = TRUE;
117 else if (res == -1)
119 this->m_AdvancedValues = FALSE;
121 break;
122 case 'B':
124 std::string path = cmSystemTools::CollapseFullPath((const char*)value);
125 this->m_WhereBuild = path.c_str();
126 break;
128 case 'G':
129 this->m_GeneratorChoiceString = value;
130 break;
131 case 'H':
133 std::string path = cmSystemTools::CollapseFullPath((const char*)value);
134 this->m_WhereSource = path.c_str();
135 break;
140 // Call the base class to ensure proper command line processing
141 CCommandLineInfo::ParseParam(lpszParam, bFlag, bLast);