cmServerProtocol.cxx 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmServerProtocol.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmExternalMakefileProjectGenerator.h"
  6. #include "cmFileMonitor.h"
  7. #include "cmGeneratorExpression.h"
  8. #include "cmGeneratorTarget.h"
  9. #include "cmGlobalGenerator.h"
  10. #include "cmLinkLineComputer.h"
  11. #include "cmListFileCache.h"
  12. #include "cmLocalGenerator.h"
  13. #include "cmMakefile.h"
  14. #include "cmServer.h"
  15. #include "cmServerDictionary.h"
  16. #include "cmSourceFile.h"
  17. #include "cmState.h"
  18. #include "cmStateDirectory.h"
  19. #include "cmStateSnapshot.h"
  20. #include "cmStateTypes.h"
  21. #include "cmSystemTools.h"
  22. #include "cmTarget.h"
  23. #include "cm_uv.h"
  24. #include "cmake.h"
  25. #include <algorithm>
  26. #include <cassert>
  27. #include <cstddef>
  28. #include <functional>
  29. #include <limits>
  30. #include <map>
  31. #include <set>
  32. #include <string>
  33. #include <unordered_map>
  34. #include <vector>
  35. // Get rid of some windows macros:
  36. #undef max
  37. namespace {
  38. std::vector<std::string> getConfigurations(const cmake* cm)
  39. {
  40. std::vector<std::string> configurations;
  41. auto makefiles = cm->GetGlobalGenerator()->GetMakefiles();
  42. if (makefiles.empty()) {
  43. return configurations;
  44. }
  45. makefiles[0]->GetConfigurations(configurations);
  46. if (configurations.empty()) {
  47. configurations.push_back("");
  48. }
  49. return configurations;
  50. }
  51. bool hasString(const Json::Value& v, const std::string& s)
  52. {
  53. return !v.isNull() &&
  54. std::any_of(v.begin(), v.end(),
  55. [s](const Json::Value& i) { return i.asString() == s; });
  56. }
  57. template <class T>
  58. Json::Value fromStringList(const T& in)
  59. {
  60. Json::Value result = Json::arrayValue;
  61. for (const std::string& i : in) {
  62. result.append(i);
  63. }
  64. return result;
  65. }
  66. std::vector<std::string> toStringList(const Json::Value& in)
  67. {
  68. std::vector<std::string> result;
  69. for (const auto& it : in) {
  70. result.push_back(it.asString());
  71. }
  72. return result;
  73. }
  74. void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir,
  75. const std::string& buildDir,
  76. std::vector<std::string>* internalFiles,
  77. std::vector<std::string>* explicitFiles,
  78. std::vector<std::string>* tmpFiles)
  79. {
  80. const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/';
  81. std::vector<cmMakefile*> const& makefiles = gg->GetMakefiles();
  82. for (auto it = makefiles.begin(); it != makefiles.end(); ++it) {
  83. const std::vector<std::string> listFiles = (*it)->GetListFiles();
  84. for (auto jt = listFiles.begin(); jt != listFiles.end(); ++jt) {
  85. const std::string startOfFile = jt->substr(0, cmakeRootDir.size());
  86. const bool isInternal = (startOfFile == cmakeRootDir);
  87. const bool isTemporary = !isInternal && (jt->find(buildDir + '/') == 0);
  88. std::string toAdd = *jt;
  89. if (!sourceDir.empty()) {
  90. const std::string& relative =
  91. cmSystemTools::RelativePath(sourceDir.c_str(), jt->c_str());
  92. if (toAdd.size() > relative.size()) {
  93. toAdd = relative;
  94. }
  95. }
  96. if (isInternal) {
  97. if (internalFiles) {
  98. internalFiles->push_back(toAdd);
  99. }
  100. } else {
  101. if (isTemporary) {
  102. if (tmpFiles) {
  103. tmpFiles->push_back(toAdd);
  104. }
  105. } else {
  106. if (explicitFiles) {
  107. explicitFiles->push_back(toAdd);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. } // namespace
  115. cmServerRequest::cmServerRequest(cmServer* server, const std::string& t,
  116. const std::string& c, const Json::Value& d)
  117. : Type(t)
  118. , Cookie(c)
  119. , Data(d)
  120. , m_Server(server)
  121. {
  122. }
  123. void cmServerRequest::ReportProgress(int min, int current, int max,
  124. const std::string& message) const
  125. {
  126. this->m_Server->WriteProgress(*this, min, current, max, message);
  127. }
  128. void cmServerRequest::ReportMessage(const std::string& message,
  129. const std::string& title) const
  130. {
  131. m_Server->WriteMessage(*this, message, title);
  132. }
  133. cmServerResponse cmServerRequest::Reply(const Json::Value& data) const
  134. {
  135. cmServerResponse response(*this);
  136. response.SetData(data);
  137. return response;
  138. }
  139. cmServerResponse cmServerRequest::ReportError(const std::string& message) const
  140. {
  141. cmServerResponse response(*this);
  142. response.SetError(message);
  143. return response;
  144. }
  145. cmServerResponse::cmServerResponse(const cmServerRequest& request)
  146. : Type(request.Type)
  147. , Cookie(request.Cookie)
  148. {
  149. }
  150. void cmServerResponse::SetData(const Json::Value& data)
  151. {
  152. assert(this->m_Payload == PAYLOAD_UNKNOWN);
  153. if (!data[kCOOKIE_KEY].isNull() || !data[kTYPE_KEY].isNull()) {
  154. this->SetError("Response contains cookie or type field.");
  155. return;
  156. }
  157. this->m_Payload = PAYLOAD_DATA;
  158. this->m_Data = data;
  159. }
  160. void cmServerResponse::SetError(const std::string& message)
  161. {
  162. assert(this->m_Payload == PAYLOAD_UNKNOWN);
  163. this->m_Payload = PAYLOAD_ERROR;
  164. this->m_ErrorMessage = message;
  165. }
  166. bool cmServerResponse::IsComplete() const
  167. {
  168. return this->m_Payload != PAYLOAD_UNKNOWN;
  169. }
  170. bool cmServerResponse::IsError() const
  171. {
  172. assert(this->m_Payload != PAYLOAD_UNKNOWN);
  173. return this->m_Payload == PAYLOAD_ERROR;
  174. }
  175. std::string cmServerResponse::ErrorMessage() const
  176. {
  177. if (this->m_Payload == PAYLOAD_ERROR) {
  178. return this->m_ErrorMessage;
  179. }
  180. return std::string();
  181. }
  182. Json::Value cmServerResponse::Data() const
  183. {
  184. assert(this->m_Payload != PAYLOAD_UNKNOWN);
  185. return this->m_Data;
  186. }
  187. bool cmServerProtocol::Activate(cmServer* server,
  188. const cmServerRequest& request,
  189. std::string* errorMessage)
  190. {
  191. assert(server);
  192. this->m_Server = server;
  193. this->m_CMakeInstance = std::make_unique<cmake>(cmake::RoleProject);
  194. const bool result = this->DoActivate(request, errorMessage);
  195. if (!result) {
  196. this->m_CMakeInstance = CM_NULLPTR;
  197. }
  198. return result;
  199. }
  200. cmFileMonitor* cmServerProtocol::FileMonitor() const
  201. {
  202. return this->m_Server ? this->m_Server->FileMonitor() : nullptr;
  203. }
  204. void cmServerProtocol::SendSignal(const std::string& name,
  205. const Json::Value& data) const
  206. {
  207. if (this->m_Server) {
  208. this->m_Server->WriteSignal(name, data);
  209. }
  210. }
  211. cmake* cmServerProtocol::CMakeInstance() const
  212. {
  213. return this->m_CMakeInstance.get();
  214. }
  215. bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/,
  216. std::string* /*errorMessage*/)
  217. {
  218. return true;
  219. }
  220. std::pair<int, int> cmServerProtocol1::ProtocolVersion() const
  221. {
  222. return std::make_pair(1, 1);
  223. }
  224. static void setErrorMessage(std::string* errorMessage, const std::string& text)
  225. {
  226. if (errorMessage) {
  227. *errorMessage = text;
  228. }
  229. }
  230. static bool testHomeDirectory(cmState* state, std::string& value,
  231. std::string* errorMessage)
  232. {
  233. const std::string cachedValue =
  234. std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"));
  235. const std::string suffix = "/CMakeLists.txt";
  236. const std::string cachedValueCML = cachedValue + suffix;
  237. const std::string valueCML = value + suffix;
  238. if (!cmSystemTools::SameFile(valueCML, cachedValueCML)) {
  239. setErrorMessage(errorMessage,
  240. std::string("\"CMAKE_HOME_DIRECTORY\" is set but "
  241. "incompatible with configured "
  242. "source directory value."));
  243. return false;
  244. }
  245. if (value.empty()) {
  246. value = cachedValue;
  247. }
  248. return true;
  249. }
  250. static bool testValue(cmState* state, const std::string& key,
  251. std::string& value, const std::string& keyDescription,
  252. std::string* errorMessage)
  253. {
  254. const std::string cachedValue = std::string(state->GetCacheEntryValue(key));
  255. if (!cachedValue.empty() && !value.empty() && cachedValue != value) {
  256. setErrorMessage(errorMessage, std::string("\"") + key +
  257. "\" is set but incompatible with configured " +
  258. keyDescription + " value.");
  259. return false;
  260. }
  261. if (value.empty()) {
  262. value = cachedValue;
  263. }
  264. return true;
  265. }
  266. bool cmServerProtocol1::DoActivate(const cmServerRequest& request,
  267. std::string* errorMessage)
  268. {
  269. std::string sourceDirectory = request.Data[kSOURCE_DIRECTORY_KEY].asString();
  270. const std::string buildDirectory =
  271. request.Data[kBUILD_DIRECTORY_KEY].asString();
  272. std::string generator = request.Data[kGENERATOR_KEY].asString();
  273. std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString();
  274. std::string toolset = request.Data[kTOOLSET_KEY].asString();
  275. std::string platform = request.Data[kPLATFORM_KEY].asString();
  276. if (buildDirectory.empty()) {
  277. setErrorMessage(errorMessage, std::string("\"") + kBUILD_DIRECTORY_KEY +
  278. "\" is missing.");
  279. return false;
  280. }
  281. cmake* cm = CMakeInstance();
  282. if (cmSystemTools::PathExists(buildDirectory)) {
  283. if (!cmSystemTools::FileIsDirectory(buildDirectory)) {
  284. setErrorMessage(errorMessage, std::string("\"") + kBUILD_DIRECTORY_KEY +
  285. "\" exists but is not a directory.");
  286. return false;
  287. }
  288. const std::string cachePath = cm->FindCacheFile(buildDirectory);
  289. if (cm->LoadCache(cachePath)) {
  290. cmState* state = cm->GetState();
  291. // Check generator:
  292. if (!testValue(state, "CMAKE_GENERATOR", generator, "generator",
  293. errorMessage)) {
  294. return false;
  295. }
  296. // check extra generator:
  297. if (!testValue(state, "CMAKE_EXTRA_GENERATOR", extraGenerator,
  298. "extra generator", errorMessage)) {
  299. return false;
  300. }
  301. // check sourcedir:
  302. if (!testHomeDirectory(state, sourceDirectory, errorMessage)) {
  303. return false;
  304. }
  305. // check toolset:
  306. if (!testValue(state, "CMAKE_GENERATOR_TOOLSET", toolset, "toolset",
  307. errorMessage)) {
  308. return false;
  309. }
  310. // check platform:
  311. if (!testValue(state, "CMAKE_GENERATOR_PLATFORM", platform, "platform",
  312. errorMessage)) {
  313. return false;
  314. }
  315. }
  316. }
  317. if (sourceDirectory.empty()) {
  318. setErrorMessage(errorMessage, std::string("\"") + kSOURCE_DIRECTORY_KEY +
  319. "\" is unset but required.");
  320. return false;
  321. }
  322. if (!cmSystemTools::FileIsDirectory(sourceDirectory)) {
  323. setErrorMessage(errorMessage, std::string("\"") + kSOURCE_DIRECTORY_KEY +
  324. "\" is not a directory.");
  325. return false;
  326. }
  327. if (generator.empty()) {
  328. setErrorMessage(errorMessage, std::string("\"") + kGENERATOR_KEY +
  329. "\" is unset but required.");
  330. return false;
  331. }
  332. std::vector<cmake::GeneratorInfo> generators;
  333. cm->GetRegisteredGenerators(generators);
  334. auto baseIt = std::find_if(generators.begin(), generators.end(),
  335. [&generator](const cmake::GeneratorInfo& info) {
  336. return info.name == generator;
  337. });
  338. if (baseIt == generators.end()) {
  339. setErrorMessage(errorMessage, std::string("Generator \"") + generator +
  340. "\" not supported.");
  341. return false;
  342. }
  343. auto extraIt = std::find_if(
  344. generators.begin(), generators.end(),
  345. [&generator, &extraGenerator](const cmake::GeneratorInfo& info) {
  346. return info.baseName == generator && info.extraName == extraGenerator;
  347. });
  348. if (extraIt == generators.end()) {
  349. setErrorMessage(errorMessage,
  350. std::string("The combination of generator \"" + generator +
  351. "\" and extra generator \"" + extraGenerator +
  352. "\" is not supported."));
  353. return false;
  354. }
  355. if (!extraIt->supportsToolset && !toolset.empty()) {
  356. setErrorMessage(errorMessage,
  357. std::string("Toolset was provided but is not supported by "
  358. "the requested generator."));
  359. return false;
  360. }
  361. if (!extraIt->supportsPlatform && !platform.empty()) {
  362. setErrorMessage(errorMessage,
  363. std::string("Platform was provided but is not supported "
  364. "by the requested generator."));
  365. return false;
  366. }
  367. this->GeneratorInfo =
  368. GeneratorInformation(generator, extraGenerator, toolset, platform,
  369. sourceDirectory, buildDirectory);
  370. this->m_State = STATE_ACTIVE;
  371. return true;
  372. }
  373. void cmServerProtocol1::HandleCMakeFileChanges(const std::string& path,
  374. int event, int status)
  375. {
  376. assert(status == 0);
  377. static_cast<void>(status);
  378. if (!m_isDirty) {
  379. m_isDirty = true;
  380. SendSignal(kDIRTY_SIGNAL, Json::objectValue);
  381. }
  382. Json::Value obj = Json::objectValue;
  383. obj[kPATH_KEY] = path;
  384. Json::Value properties = Json::arrayValue;
  385. if (event & UV_RENAME) {
  386. properties.append(kRENAME_PROPERTY_VALUE);
  387. }
  388. if (event & UV_CHANGE) {
  389. properties.append(kCHANGE_PROPERTY_VALUE);
  390. }
  391. obj[kPROPERTIES_KEY] = properties;
  392. SendSignal(kFILE_CHANGE_SIGNAL, obj);
  393. }
  394. const cmServerResponse cmServerProtocol1::Process(
  395. const cmServerRequest& request)
  396. {
  397. assert(this->m_State >= STATE_ACTIVE);
  398. if (request.Type == kCACHE_TYPE) {
  399. return this->ProcessCache(request);
  400. }
  401. if (request.Type == kCMAKE_INPUTS_TYPE) {
  402. return this->ProcessCMakeInputs(request);
  403. }
  404. if (request.Type == kCODE_MODEL_TYPE) {
  405. return this->ProcessCodeModel(request);
  406. }
  407. if (request.Type == kCOMPUTE_TYPE) {
  408. return this->ProcessCompute(request);
  409. }
  410. if (request.Type == kCONFIGURE_TYPE) {
  411. return this->ProcessConfigure(request);
  412. }
  413. if (request.Type == kFILESYSTEM_WATCHERS_TYPE) {
  414. return this->ProcessFileSystemWatchers(request);
  415. }
  416. if (request.Type == kGLOBAL_SETTINGS_TYPE) {
  417. return this->ProcessGlobalSettings(request);
  418. }
  419. if (request.Type == kSET_GLOBAL_SETTINGS_TYPE) {
  420. return this->ProcessSetGlobalSettings(request);
  421. }
  422. return request.ReportError("Unknown command!");
  423. }
  424. bool cmServerProtocol1::IsExperimental() const
  425. {
  426. return true;
  427. }
  428. cmServerResponse cmServerProtocol1::ProcessCache(
  429. const cmServerRequest& request)
  430. {
  431. if (this->m_State < STATE_CONFIGURED) {
  432. return request.ReportError("This project was not configured yet.");
  433. }
  434. cmState* state = this->CMakeInstance()->GetState();
  435. Json::Value result = Json::objectValue;
  436. std::vector<std::string> allKeys = state->GetCacheEntryKeys();
  437. Json::Value list = Json::arrayValue;
  438. std::vector<std::string> keys = toStringList(request.Data[kKEYS_KEY]);
  439. if (keys.empty()) {
  440. keys = allKeys;
  441. } else {
  442. for (const auto& i : keys) {
  443. if (std::find(allKeys.begin(), allKeys.end(), i) == allKeys.end()) {
  444. return request.ReportError("Key \"" + i + "\" not found in cache.");
  445. }
  446. }
  447. }
  448. std::sort(keys.begin(), keys.end());
  449. for (const auto& key : keys) {
  450. Json::Value entry = Json::objectValue;
  451. entry[kKEY_KEY] = key;
  452. entry[kTYPE_KEY] =
  453. cmState::CacheEntryTypeToString(state->GetCacheEntryType(key));
  454. entry[kVALUE_KEY] = state->GetCacheEntryValue(key);
  455. Json::Value props = Json::objectValue;
  456. bool haveProperties = false;
  457. for (const auto& prop : state->GetCacheEntryPropertyList(key)) {
  458. haveProperties = true;
  459. props[prop] = state->GetCacheEntryProperty(key, prop);
  460. }
  461. if (haveProperties) {
  462. entry[kPROPERTIES_KEY] = props;
  463. }
  464. list.append(entry);
  465. }
  466. result[kCACHE_KEY] = list;
  467. return request.Reply(result);
  468. }
  469. cmServerResponse cmServerProtocol1::ProcessCMakeInputs(
  470. const cmServerRequest& request)
  471. {
  472. if (this->m_State < STATE_CONFIGURED) {
  473. return request.ReportError("This instance was not yet configured.");
  474. }
  475. const cmake* cm = this->CMakeInstance();
  476. const cmGlobalGenerator* gg = cm->GetGlobalGenerator();
  477. const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot();
  478. const std::string buildDir = cm->GetHomeOutputDirectory();
  479. const std::string sourceDir = cm->GetHomeDirectory();
  480. Json::Value result = Json::objectValue;
  481. result[kSOURCE_DIRECTORY_KEY] = sourceDir;
  482. result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir;
  483. std::vector<std::string> internalFiles;
  484. std::vector<std::string> explicitFiles;
  485. std::vector<std::string> tmpFiles;
  486. getCMakeInputs(gg, sourceDir, buildDir, &internalFiles, &explicitFiles,
  487. &tmpFiles);
  488. Json::Value array = Json::arrayValue;
  489. Json::Value tmp = Json::objectValue;
  490. tmp[kIS_CMAKE_KEY] = true;
  491. tmp[kIS_TEMPORARY_KEY] = false;
  492. tmp[kSOURCES_KEY] = fromStringList(internalFiles);
  493. array.append(tmp);
  494. tmp = Json::objectValue;
  495. tmp[kIS_CMAKE_KEY] = false;
  496. tmp[kIS_TEMPORARY_KEY] = false;
  497. tmp[kSOURCES_KEY] = fromStringList(explicitFiles);
  498. array.append(tmp);
  499. tmp = Json::objectValue;
  500. tmp[kIS_CMAKE_KEY] = false;
  501. tmp[kIS_TEMPORARY_KEY] = true;
  502. tmp[kSOURCES_KEY] = fromStringList(tmpFiles);
  503. array.append(tmp);
  504. result[kBUILD_FILES_KEY] = array;
  505. return request.Reply(result);
  506. }
  507. class LanguageData
  508. {
  509. public:
  510. bool operator==(const LanguageData& other) const;
  511. void SetDefines(const std::set<std::string>& defines);
  512. bool IsGenerated = false;
  513. std::string Language;
  514. std::string Flags;
  515. std::vector<std::string> Defines;
  516. std::vector<std::pair<std::string, bool> > IncludePathList;
  517. };
  518. bool LanguageData::operator==(const LanguageData& other) const
  519. {
  520. return Language == other.Language && Defines == other.Defines &&
  521. Flags == other.Flags && IncludePathList == other.IncludePathList &&
  522. IsGenerated == other.IsGenerated;
  523. }
  524. void LanguageData::SetDefines(const std::set<std::string>& defines)
  525. {
  526. std::vector<std::string> result;
  527. for (const auto& i : defines) {
  528. result.push_back(i);
  529. }
  530. std::sort(result.begin(), result.end());
  531. Defines = result;
  532. }
  533. namespace std {
  534. template <>
  535. struct hash<LanguageData>
  536. {
  537. std::size_t operator()(const LanguageData& in) const
  538. {
  539. using std::hash;
  540. size_t result =
  541. hash<std::string>()(in.Language) ^ hash<std::string>()(in.Flags);
  542. for (const auto& i : in.IncludePathList) {
  543. result = result ^ (hash<std::string>()(i.first) ^
  544. (i.second ? std::numeric_limits<size_t>::max() : 0));
  545. }
  546. for (const auto& i : in.Defines) {
  547. result = result ^ hash<std::string>()(i);
  548. }
  549. result =
  550. result ^ (in.IsGenerated ? std::numeric_limits<size_t>::max() : 0);
  551. return result;
  552. }
  553. };
  554. } // namespace std
  555. static Json::Value DumpSourceFileGroup(const LanguageData& data,
  556. const std::vector<std::string>& files,
  557. const std::string& baseDir)
  558. {
  559. Json::Value result = Json::objectValue;
  560. if (!data.Language.empty()) {
  561. result[kLANGUAGE_KEY] = data.Language;
  562. if (!data.Flags.empty()) {
  563. result[kCOMPILE_FLAGS_KEY] = data.Flags;
  564. }
  565. if (!data.IncludePathList.empty()) {
  566. Json::Value includes = Json::arrayValue;
  567. for (const auto& i : data.IncludePathList) {
  568. Json::Value tmp = Json::objectValue;
  569. tmp[kPATH_KEY] = i.first;
  570. if (i.second) {
  571. tmp[kIS_SYSTEM_KEY] = i.second;
  572. }
  573. includes.append(tmp);
  574. }
  575. result[kINCLUDE_PATH_KEY] = includes;
  576. }
  577. if (!data.Defines.empty()) {
  578. result[kDEFINES_KEY] = fromStringList(data.Defines);
  579. }
  580. }
  581. result[kIS_GENERATED_KEY] = data.IsGenerated;
  582. Json::Value sourcesValue = Json::arrayValue;
  583. for (const auto& i : files) {
  584. const std::string relPath =
  585. cmSystemTools::RelativePath(baseDir.c_str(), i.c_str());
  586. sourcesValue.append(relPath.size() < i.size() ? relPath : i);
  587. }
  588. result[kSOURCES_KEY] = sourcesValue;
  589. return result;
  590. }
  591. static Json::Value DumpSourceFilesList(
  592. cmGeneratorTarget* target, const std::string& config,
  593. const std::map<std::string, LanguageData>& languageDataMap)
  594. {
  595. // Collect sourcefile groups:
  596. std::vector<cmSourceFile*> files;
  597. target->GetSourceFiles(files, config);
  598. std::unordered_map<LanguageData, std::vector<std::string> > fileGroups;
  599. for (cmSourceFile* file : files) {
  600. LanguageData fileData;
  601. fileData.Language = file->GetLanguage();
  602. if (!fileData.Language.empty()) {
  603. const LanguageData& ld = languageDataMap.at(fileData.Language);
  604. cmLocalGenerator* lg = target->GetLocalGenerator();
  605. std::string compileFlags = ld.Flags;
  606. if (const char* cflags = file->GetProperty("COMPILE_FLAGS")) {
  607. cmGeneratorExpression ge;
  608. auto cge = ge.Parse(cflags);
  609. const char* processed =
  610. cge->Evaluate(target->GetLocalGenerator(), config);
  611. lg->AppendFlags(compileFlags, processed);
  612. }
  613. fileData.Flags = compileFlags;
  614. fileData.IncludePathList = ld.IncludePathList;
  615. std::set<std::string> defines;
  616. lg->AppendDefines(defines, file->GetProperty("COMPILE_DEFINITIONS"));
  617. const std::string defPropName =
  618. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  619. lg->AppendDefines(defines, file->GetProperty(defPropName));
  620. defines.insert(ld.Defines.begin(), ld.Defines.end());
  621. fileData.SetDefines(defines);
  622. }
  623. fileData.IsGenerated = file->GetPropertyAsBool("GENERATED");
  624. std::vector<std::string>& groupFileList = fileGroups[fileData];
  625. groupFileList.push_back(file->GetFullPath());
  626. }
  627. const std::string baseDir = target->Makefile->GetCurrentSourceDirectory();
  628. Json::Value result = Json::arrayValue;
  629. for (auto it = fileGroups.begin(); it != fileGroups.end(); ++it) {
  630. Json::Value group = DumpSourceFileGroup(it->first, it->second, baseDir);
  631. if (!group.isNull()) {
  632. result.append(group);
  633. }
  634. }
  635. return result;
  636. }
  637. static Json::Value DumpBacktrace(const cmListFileBacktrace& backtrace)
  638. {
  639. Json::Value result = Json::arrayValue;
  640. cmListFileBacktrace backtraceCopy = backtrace;
  641. while (!backtraceCopy.Top().FilePath.empty()) {
  642. Json::Value entry = Json::objectValue;
  643. entry[kPATH_KEY] = backtraceCopy.Top().FilePath;
  644. if (backtraceCopy.Top().Line) {
  645. entry[kLINE_NUMBER_KEY] = (int)backtraceCopy.Top().Line;
  646. }
  647. if (!backtraceCopy.Top().Name.empty()) {
  648. entry[kNAME_KEY] = backtraceCopy.Top().Name;
  649. }
  650. result.append(std::move(entry));
  651. backtraceCopy = backtraceCopy.Pop();
  652. }
  653. return result;
  654. }
  655. static void DumpBacktraceRange(Json::Value& result, const std::string& type,
  656. const cmBacktraceRange& range)
  657. {
  658. for (const auto& bt : range) {
  659. Json::Value obj = Json::objectValue;
  660. obj[kTYPE_KEY] = type;
  661. obj[kBACKTRACE_KEY] = DumpBacktrace(bt);
  662. result.append(obj);
  663. }
  664. }
  665. static Json::Value DumpTarget(cmGeneratorTarget* target,
  666. const std::string& config)
  667. {
  668. cmLocalGenerator* lg = target->GetLocalGenerator();
  669. const cmState* state = lg->GetState();
  670. const cmStateEnums::TargetType type = target->GetType();
  671. const std::string typeName = state->GetTargetTypeName(type);
  672. Json::Value ttl = Json::arrayValue;
  673. ttl.append("EXECUTABLE");
  674. ttl.append("STATIC_LIBRARY");
  675. ttl.append("SHARED_LIBRARY");
  676. ttl.append("MODULE_LIBRARY");
  677. ttl.append("OBJECT_LIBRARY");
  678. ttl.append("UTILITY");
  679. ttl.append("INTERFACE_LIBRARY");
  680. if (!hasString(ttl, typeName) || target->IsImported()) {
  681. return Json::Value();
  682. }
  683. Json::Value result = Json::objectValue;
  684. result[kNAME_KEY] = target->GetName();
  685. result[kTYPE_KEY] = typeName;
  686. result[kSOURCE_DIRECTORY_KEY] = lg->GetCurrentSourceDirectory();
  687. result[kBUILD_DIRECTORY_KEY] = lg->GetCurrentBinaryDirectory();
  688. if (type == cmStateEnums::INTERFACE_LIBRARY) {
  689. return result;
  690. }
  691. result[kFULL_NAME_KEY] = target->GetFullName(config);
  692. Json::Value crossRefs = Json::objectValue;
  693. crossRefs[kBACKTRACE_KEY] = DumpBacktrace(target->Target->GetBacktrace());
  694. Json::Value statements = Json::arrayValue;
  695. DumpBacktraceRange(statements, "target_compile_definitions",
  696. target->Target->GetCompileDefinitionsBacktraces());
  697. DumpBacktraceRange(statements, "target_include_directories",
  698. target->Target->GetIncludeDirectoriesBacktraces());
  699. DumpBacktraceRange(statements, "target_compile_options",
  700. target->Target->GetCompileOptionsBacktraces());
  701. DumpBacktraceRange(statements, "target_link_libraries",
  702. target->Target->GetLinkImplementationBacktraces());
  703. crossRefs[kRELATED_STATEMENTS_KEY] = std::move(statements);
  704. result[kTARGET_CROSS_REFERENCES_KEY] = std::move(crossRefs);
  705. if (target->HaveWellDefinedOutputFiles()) {
  706. Json::Value artifacts = Json::arrayValue;
  707. artifacts.append(
  708. target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact));
  709. if (target->IsDLLPlatform()) {
  710. artifacts.append(
  711. target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
  712. const cmGeneratorTarget::OutputInfo* output =
  713. target->GetOutputInfo(config);
  714. if (output && !output->PdbDir.empty()) {
  715. artifacts.append(output->PdbDir + '/' + target->GetPDBName(config));
  716. }
  717. }
  718. result[kARTIFACTS_KEY] = artifacts;
  719. result[kLINKER_LANGUAGE_KEY] = target->GetLinkerLanguage(config);
  720. std::string linkLibs;
  721. std::string linkFlags;
  722. std::string linkLanguageFlags;
  723. std::string frameworkPath;
  724. std::string linkPath;
  725. cmLinkLineComputer linkLineComputer(lg,
  726. lg->GetStateSnapshot().GetDirectory());
  727. lg->GetTargetFlags(&linkLineComputer, config, linkLibs, linkLanguageFlags,
  728. linkFlags, frameworkPath, linkPath, target);
  729. linkLibs = cmSystemTools::TrimWhitespace(linkLibs);
  730. linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
  731. linkLanguageFlags = cmSystemTools::TrimWhitespace(linkLanguageFlags);
  732. frameworkPath = cmSystemTools::TrimWhitespace(frameworkPath);
  733. linkPath = cmSystemTools::TrimWhitespace(linkPath);
  734. if (!cmSystemTools::TrimWhitespace(linkLibs).empty()) {
  735. result[kLINK_LIBRARIES_KEY] = linkLibs;
  736. }
  737. if (!cmSystemTools::TrimWhitespace(linkFlags).empty()) {
  738. result[kLINK_FLAGS_KEY] = linkFlags;
  739. }
  740. if (!cmSystemTools::TrimWhitespace(linkLanguageFlags).empty()) {
  741. result[kLINK_LANGUAGE_FLAGS_KEY] = linkLanguageFlags;
  742. }
  743. if (!frameworkPath.empty()) {
  744. result[kFRAMEWORK_PATH_KEY] = frameworkPath;
  745. }
  746. if (!linkPath.empty()) {
  747. result[kLINK_PATH_KEY] = linkPath;
  748. }
  749. const std::string sysroot =
  750. lg->GetMakefile()->GetSafeDefinition("CMAKE_SYSROOT");
  751. if (!sysroot.empty()) {
  752. result[kSYSROOT_KEY] = sysroot;
  753. }
  754. }
  755. std::set<std::string> languages;
  756. target->GetLanguages(languages, config);
  757. std::map<std::string, LanguageData> languageDataMap;
  758. for (const auto& lang : languages) {
  759. LanguageData& ld = languageDataMap[lang];
  760. ld.Language = lang;
  761. lg->GetTargetCompileFlags(target, config, lang, ld.Flags);
  762. std::set<std::string> defines;
  763. lg->GetTargetDefines(target, config, lang, defines);
  764. ld.SetDefines(defines);
  765. std::vector<std::string> includePathList;
  766. lg->GetIncludeDirectories(includePathList, target, lang, config, true);
  767. for (auto i : includePathList) {
  768. ld.IncludePathList.push_back(
  769. std::make_pair(i, target->IsSystemIncludeDirectory(i, config)));
  770. }
  771. }
  772. Json::Value sourceGroupsValue =
  773. DumpSourceFilesList(target, config, languageDataMap);
  774. if (!sourceGroupsValue.empty()) {
  775. result[kFILE_GROUPS_KEY] = sourceGroupsValue;
  776. }
  777. return result;
  778. }
  779. static Json::Value DumpTargetsList(
  780. const std::vector<cmLocalGenerator*>& generators, const std::string& config)
  781. {
  782. Json::Value result = Json::arrayValue;
  783. std::vector<cmGeneratorTarget*> targetList;
  784. for (const auto& lgIt : generators) {
  785. auto list = lgIt->GetGeneratorTargets();
  786. targetList.insert(targetList.end(), list.begin(), list.end());
  787. }
  788. std::sort(targetList.begin(), targetList.end());
  789. for (cmGeneratorTarget* target : targetList) {
  790. Json::Value tmp = DumpTarget(target, config);
  791. if (!tmp.isNull()) {
  792. result.append(tmp);
  793. }
  794. }
  795. return result;
  796. }
  797. static Json::Value DumpProjectList(const cmake* cm, std::string const& config)
  798. {
  799. Json::Value result = Json::arrayValue;
  800. auto globalGen = cm->GetGlobalGenerator();
  801. for (const auto& projectIt : globalGen->GetProjectMap()) {
  802. Json::Value pObj = Json::objectValue;
  803. pObj[kNAME_KEY] = projectIt.first;
  804. // All Projects must have at least one local generator
  805. assert(!projectIt.second.empty());
  806. const cmLocalGenerator* lg = projectIt.second.at(0);
  807. // Project structure information:
  808. const cmMakefile* mf = lg->GetMakefile();
  809. pObj[kSOURCE_DIRECTORY_KEY] = mf->GetCurrentSourceDirectory();
  810. pObj[kBUILD_DIRECTORY_KEY] = mf->GetCurrentBinaryDirectory();
  811. pObj[kTARGETS_KEY] = DumpTargetsList(projectIt.second, config);
  812. result.append(pObj);
  813. }
  814. return result;
  815. }
  816. static Json::Value DumpConfiguration(const cmake* cm,
  817. const std::string& config)
  818. {
  819. Json::Value result = Json::objectValue;
  820. result[kNAME_KEY] = config;
  821. result[kPROJECTS_KEY] = DumpProjectList(cm, config);
  822. return result;
  823. }
  824. static Json::Value DumpConfigurationsList(const cmake* cm)
  825. {
  826. Json::Value result = Json::arrayValue;
  827. for (const std::string& c : getConfigurations(cm)) {
  828. result.append(DumpConfiguration(cm, c));
  829. }
  830. return result;
  831. }
  832. cmServerResponse cmServerProtocol1::ProcessCodeModel(
  833. const cmServerRequest& request)
  834. {
  835. if (this->m_State != STATE_COMPUTED) {
  836. return request.ReportError("No build system was generated yet.");
  837. }
  838. Json::Value result = Json::objectValue;
  839. result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(this->CMakeInstance());
  840. return request.Reply(result);
  841. }
  842. cmServerResponse cmServerProtocol1::ProcessCompute(
  843. const cmServerRequest& request)
  844. {
  845. if (this->m_State > STATE_CONFIGURED) {
  846. return request.ReportError("This build system was already generated.");
  847. }
  848. if (this->m_State < STATE_CONFIGURED) {
  849. return request.ReportError("This project was not configured yet.");
  850. }
  851. cmake* cm = this->CMakeInstance();
  852. int ret = cm->Generate();
  853. if (ret < 0) {
  854. return request.ReportError("Failed to compute build system.");
  855. }
  856. m_State = STATE_COMPUTED;
  857. return request.Reply(Json::Value());
  858. }
  859. cmServerResponse cmServerProtocol1::ProcessConfigure(
  860. const cmServerRequest& request)
  861. {
  862. if (this->m_State == STATE_INACTIVE) {
  863. return request.ReportError("This instance is inactive.");
  864. }
  865. FileMonitor()->StopMonitoring();
  866. std::string errorMessage;
  867. cmake* cm = this->CMakeInstance();
  868. this->GeneratorInfo.SetupGenerator(cm, &errorMessage);
  869. if (!errorMessage.empty()) {
  870. return request.ReportError(errorMessage);
  871. }
  872. // Make sure the types of cacheArguments matches (if given):
  873. std::vector<std::string> cacheArgs = { "unused" };
  874. bool cacheArgumentsError = false;
  875. const Json::Value passedArgs = request.Data[kCACHE_ARGUMENTS_KEY];
  876. if (!passedArgs.isNull()) {
  877. if (passedArgs.isString()) {
  878. cacheArgs.push_back(passedArgs.asString());
  879. } else if (passedArgs.isArray()) {
  880. for (auto i = passedArgs.begin(); i != passedArgs.end(); ++i) {
  881. if (!i->isString()) {
  882. cacheArgumentsError = true;
  883. break;
  884. }
  885. cacheArgs.push_back(i->asString());
  886. }
  887. } else {
  888. cacheArgumentsError = true;
  889. }
  890. }
  891. if (cacheArgumentsError) {
  892. request.ReportError(
  893. "cacheArguments must be unset, a string or an array of strings.");
  894. }
  895. std::string sourceDir = cm->GetHomeDirectory();
  896. const std::string buildDir = cm->GetHomeOutputDirectory();
  897. cmGlobalGenerator* gg = cm->GetGlobalGenerator();
  898. if (buildDir.empty()) {
  899. return request.ReportError("No build directory set via Handshake.");
  900. }
  901. if (cm->LoadCache(buildDir)) {
  902. // build directory has been set up before
  903. const char* cachedSourceDir =
  904. cm->GetState()->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
  905. if (!cachedSourceDir) {
  906. return request.ReportError("No CMAKE_HOME_DIRECTORY found in cache.");
  907. }
  908. if (sourceDir.empty()) {
  909. sourceDir = std::string(cachedSourceDir);
  910. cm->SetHomeDirectory(sourceDir);
  911. }
  912. const char* cachedGenerator =
  913. cm->GetState()->GetInitializedCacheValue("CMAKE_GENERATOR");
  914. if (cachedGenerator) {
  915. if (gg && gg->GetName() != cachedGenerator) {
  916. return request.ReportError("Configured generator does not match with "
  917. "CMAKE_GENERATOR found in cache.");
  918. }
  919. }
  920. } else {
  921. // build directory has not been set up before
  922. if (sourceDir.empty()) {
  923. return request.ReportError("No sourceDirectory set via "
  924. "setGlobalSettings and no cache found in "
  925. "buildDirectory.");
  926. }
  927. }
  928. cmSystemTools::ResetErrorOccuredFlag(); // Reset error state
  929. if (cm->AddCMakePaths() != 1) {
  930. return request.ReportError("Failed to set CMake paths.");
  931. }
  932. if (!cm->SetCacheArgs(cacheArgs)) {
  933. return request.ReportError("cacheArguments could not be set.");
  934. }
  935. int ret = cm->Configure();
  936. if (ret < 0) {
  937. return request.ReportError("Configuration failed.");
  938. }
  939. std::vector<std::string> toWatchList;
  940. getCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, nullptr);
  941. FileMonitor()->MonitorPaths(toWatchList,
  942. [this](const std::string& p, int e, int s) {
  943. this->HandleCMakeFileChanges(p, e, s);
  944. });
  945. m_State = STATE_CONFIGURED;
  946. m_isDirty = false;
  947. return request.Reply(Json::Value());
  948. }
  949. cmServerResponse cmServerProtocol1::ProcessGlobalSettings(
  950. const cmServerRequest& request)
  951. {
  952. cmake* cm = this->CMakeInstance();
  953. Json::Value obj = Json::objectValue;
  954. // Capabilities information:
  955. obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson(true);
  956. obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput();
  957. obj[kTRACE_KEY] = cm->GetTrace();
  958. obj[kTRACE_EXPAND_KEY] = cm->GetTraceExpand();
  959. obj[kWARN_UNINITIALIZED_KEY] = cm->GetWarnUninitialized();
  960. obj[kWARN_UNUSED_KEY] = cm->GetWarnUnused();
  961. obj[kWARN_UNUSED_CLI_KEY] = cm->GetWarnUnusedCli();
  962. obj[kCHECK_SYSTEM_VARS_KEY] = cm->GetCheckSystemVars();
  963. obj[kSOURCE_DIRECTORY_KEY] = this->GeneratorInfo.SourceDirectory;
  964. obj[kBUILD_DIRECTORY_KEY] = this->GeneratorInfo.BuildDirectory;
  965. // Currently used generator:
  966. obj[kGENERATOR_KEY] = this->GeneratorInfo.GeneratorName;
  967. obj[kEXTRA_GENERATOR_KEY] = this->GeneratorInfo.ExtraGeneratorName;
  968. return request.Reply(obj);
  969. }
  970. static void setBool(const cmServerRequest& request, const std::string& key,
  971. std::function<void(bool)> const& setter)
  972. {
  973. if (request.Data[key].isNull()) {
  974. return;
  975. }
  976. setter(request.Data[key].asBool());
  977. }
  978. cmServerResponse cmServerProtocol1::ProcessSetGlobalSettings(
  979. const cmServerRequest& request)
  980. {
  981. const std::vector<std::string> boolValues = {
  982. kDEBUG_OUTPUT_KEY, kTRACE_KEY, kTRACE_EXPAND_KEY,
  983. kWARN_UNINITIALIZED_KEY, kWARN_UNUSED_KEY, kWARN_UNUSED_CLI_KEY,
  984. kCHECK_SYSTEM_VARS_KEY
  985. };
  986. for (const auto& i : boolValues) {
  987. if (!request.Data[i].isNull() && !request.Data[i].isBool()) {
  988. return request.ReportError("\"" + i +
  989. "\" must be unset or a bool value.");
  990. }
  991. }
  992. cmake* cm = this->CMakeInstance();
  993. setBool(request, kDEBUG_OUTPUT_KEY,
  994. [cm](bool e) { cm->SetDebugOutputOn(e); });
  995. setBool(request, kTRACE_KEY, [cm](bool e) { cm->SetTrace(e); });
  996. setBool(request, kTRACE_EXPAND_KEY, [cm](bool e) { cm->SetTraceExpand(e); });
  997. setBool(request, kWARN_UNINITIALIZED_KEY,
  998. [cm](bool e) { cm->SetWarnUninitialized(e); });
  999. setBool(request, kWARN_UNUSED_KEY, [cm](bool e) { cm->SetWarnUnused(e); });
  1000. setBool(request, kWARN_UNUSED_CLI_KEY,
  1001. [cm](bool e) { cm->SetWarnUnusedCli(e); });
  1002. setBool(request, kCHECK_SYSTEM_VARS_KEY,
  1003. [cm](bool e) { cm->SetCheckSystemVars(e); });
  1004. return request.Reply(Json::Value());
  1005. }
  1006. cmServerResponse cmServerProtocol1::ProcessFileSystemWatchers(
  1007. const cmServerRequest& request)
  1008. {
  1009. const cmFileMonitor* const fm = FileMonitor();
  1010. Json::Value result = Json::objectValue;
  1011. Json::Value files = Json::arrayValue;
  1012. for (const auto& f : fm->WatchedFiles()) {
  1013. files.append(f);
  1014. }
  1015. Json::Value directories = Json::arrayValue;
  1016. for (const auto& d : fm->WatchedDirectories()) {
  1017. directories.append(d);
  1018. }
  1019. result[kWATCHED_FILES_KEY] = files;
  1020. result[kWATCHED_DIRECTORIES_KEY] = directories;
  1021. return request.Reply(result);
  1022. }
  1023. cmServerProtocol1::GeneratorInformation::GeneratorInformation(
  1024. const std::string& generatorName, const std::string& extraGeneratorName,
  1025. const std::string& toolset, const std::string& platform,
  1026. const std::string& sourceDirectory, const std::string& buildDirectory)
  1027. : GeneratorName(generatorName)
  1028. , ExtraGeneratorName(extraGeneratorName)
  1029. , Toolset(toolset)
  1030. , Platform(platform)
  1031. , SourceDirectory(sourceDirectory)
  1032. , BuildDirectory(buildDirectory)
  1033. {
  1034. }
  1035. void cmServerProtocol1::GeneratorInformation::SetupGenerator(
  1036. cmake* cm, std::string* errorMessage)
  1037. {
  1038. const std::string fullGeneratorName =
  1039. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
  1040. GeneratorName, ExtraGeneratorName);
  1041. cm->SetHomeDirectory(SourceDirectory);
  1042. cm->SetHomeOutputDirectory(BuildDirectory);
  1043. cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName);
  1044. if (!gg) {
  1045. setErrorMessage(
  1046. errorMessage,
  1047. std::string("Could not set up the requested combination of \"") +
  1048. kGENERATOR_KEY + "\" and \"" + kEXTRA_GENERATOR_KEY + "\"");
  1049. return;
  1050. }
  1051. cm->SetGlobalGenerator(gg);
  1052. cm->SetGeneratorToolset(Toolset);
  1053. cm->SetGeneratorPlatform(Platform);
  1054. }