cmServerProtocol.cxx 38 KB

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