cmGlobalVisualStudioGenerator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalVisualStudioGenerator.h"
  11. #include "cmCallVisualStudioMacro.h"
  12. #include "cmLocalGenerator.h"
  13. #include "cmMakefile.h"
  14. #include "cmTarget.h"
  15. //----------------------------------------------------------------------------
  16. cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator()
  17. {
  18. }
  19. //----------------------------------------------------------------------------
  20. cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator()
  21. {
  22. }
  23. //----------------------------------------------------------------------------
  24. std::string cmGlobalVisualStudioGenerator::GetRegistryBase()
  25. {
  26. std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\";
  27. key += this->GetIDEVersion();
  28. return key;
  29. }
  30. //----------------------------------------------------------------------------
  31. void cmGlobalVisualStudioGenerator::Generate()
  32. {
  33. // Add a special target that depends on ALL projects for easy build
  34. // of one configuration only.
  35. const char* no_working_dir = 0;
  36. std::vector<std::string> no_depends;
  37. cmCustomCommandLines no_commands;
  38. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  39. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  40. {
  41. std::vector<cmLocalGenerator*>& gen = it->second;
  42. // add the ALL_BUILD to the first local generator of each project
  43. if(gen.size())
  44. {
  45. // Use no actual command lines so that the target itself is not
  46. // considered always out of date.
  47. cmTarget* allBuild =
  48. gen[0]->GetMakefile()->
  49. AddUtilityCommand("ALL_BUILD", true, no_working_dir,
  50. no_depends, no_commands, false,
  51. "Build all projects");
  52. #if 0
  53. // Can't activate this code because we want ALL_BUILD
  54. // selected as the default "startup project" when first
  55. // opened in Visual Studio... And if it's nested in a
  56. // folder, then that doesn't happen.
  57. //
  58. // Organize in the "predefined targets" folder:
  59. //
  60. if (this->UseFolderProperty())
  61. {
  62. allBuild->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  63. }
  64. #endif
  65. // Now make all targets depend on the ALL_BUILD target
  66. cmTargets targets;
  67. for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
  68. i != gen.end(); ++i)
  69. {
  70. cmTargets& targets = (*i)->GetMakefile()->GetTargets();
  71. for(cmTargets::iterator t = targets.begin();
  72. t != targets.end(); ++t)
  73. {
  74. if(!this->IsExcluded(gen[0], t->second))
  75. {
  76. allBuild->AddUtility(t->second.GetName());
  77. }
  78. }
  79. }
  80. }
  81. }
  82. // Configure CMake Visual Studio macros, for this user on this version
  83. // of Visual Studio.
  84. this->ConfigureCMakeVisualStudioMacros();
  85. // Run all the local generators.
  86. this->cmGlobalGenerator::Generate();
  87. }
  88. //----------------------------------------------------------------------------
  89. bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
  90. const std::string& regKeyBase,
  91. std::string& nextAvailableSubKeyName);
  92. void RegisterVisualStudioMacros(const std::string& macrosFile,
  93. const std::string& regKeyBase);
  94. //----------------------------------------------------------------------------
  95. #define CMAKE_VSMACROS_FILENAME \
  96. "CMakeVSMacros2.vsmacros"
  97. #define CMAKE_VSMACROS_RELOAD_MACRONAME \
  98. "Macros.CMakeVSMacros2.Macros.ReloadProjects"
  99. #define CMAKE_VSMACROS_STOP_MACRONAME \
  100. "Macros.CMakeVSMacros2.Macros.StopBuild"
  101. //----------------------------------------------------------------------------
  102. void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
  103. {
  104. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  105. std::string dir = this->GetUserMacrosDirectory();
  106. if (mf != 0 && dir != "")
  107. {
  108. std::string src = mf->GetRequiredDefinition("CMAKE_ROOT");
  109. src += "/Templates/" CMAKE_VSMACROS_FILENAME;
  110. std::string dst = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
  111. // Copy the macros file to the user directory only if the
  112. // destination does not exist or the source location is newer.
  113. // This will allow the user to edit the macros for development
  114. // purposes but newer versions distributed with CMake will replace
  115. // older versions in user directories.
  116. int res;
  117. if(!cmSystemTools::FileTimeCompare(src.c_str(), dst.c_str(), &res) ||
  118. res > 0)
  119. {
  120. if (!cmSystemTools::CopyFileAlways(src.c_str(), dst.c_str()))
  121. {
  122. std::ostringstream oss;
  123. oss << "Could not copy from: " << src << std::endl;
  124. oss << " to: " << dst << std::endl;
  125. cmSystemTools::Message(oss.str().c_str(), "Warning");
  126. }
  127. }
  128. RegisterVisualStudioMacros(dst, this->GetUserMacrosRegKeyBase());
  129. }
  130. }
  131. //----------------------------------------------------------------------------
  132. void
  133. cmGlobalVisualStudioGenerator
  134. ::CallVisualStudioMacro(MacroName m,
  135. const char* vsSolutionFile)
  136. {
  137. // If any solution or project files changed during the generation,
  138. // tell Visual Studio to reload them...
  139. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  140. std::string dir = this->GetUserMacrosDirectory();
  141. // Only really try to call the macro if:
  142. // - mf is non-NULL
  143. // - there is a UserMacrosDirectory
  144. // - the CMake vsmacros file exists
  145. // - the CMake vsmacros file is registered
  146. // - there were .sln/.vcproj files changed during generation
  147. //
  148. if (mf != 0 && dir != "")
  149. {
  150. std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
  151. std::string nextSubkeyName;
  152. if (cmSystemTools::FileExists(macrosFile.c_str()) &&
  153. IsVisualStudioMacrosFileRegistered(macrosFile,
  154. this->GetUserMacrosRegKeyBase(), nextSubkeyName)
  155. )
  156. {
  157. std::string topLevelSlnName;
  158. if(vsSolutionFile)
  159. {
  160. topLevelSlnName = vsSolutionFile;
  161. }
  162. else
  163. {
  164. topLevelSlnName = mf->GetStartOutputDirectory();
  165. topLevelSlnName += "/";
  166. topLevelSlnName += mf->GetProjectName();
  167. topLevelSlnName += ".sln";
  168. }
  169. if(m == MacroReload)
  170. {
  171. std::vector<std::string> filenames;
  172. this->GetFilesReplacedDuringGenerate(filenames);
  173. if (filenames.size() > 0)
  174. {
  175. // Convert vector to semi-colon delimited string of filenames:
  176. std::string projects;
  177. std::vector<std::string>::iterator it = filenames.begin();
  178. if (it != filenames.end())
  179. {
  180. projects = *it;
  181. ++it;
  182. }
  183. for (; it != filenames.end(); ++it)
  184. {
  185. projects += ";";
  186. projects += *it;
  187. }
  188. cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
  189. CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
  190. this->GetCMakeInstance()->GetDebugOutput());
  191. }
  192. }
  193. else if(m == MacroStop)
  194. {
  195. cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
  196. CMAKE_VSMACROS_STOP_MACRONAME, "",
  197. this->GetCMakeInstance()->GetDebugOutput());
  198. }
  199. }
  200. }
  201. }
  202. //----------------------------------------------------------------------------
  203. std::string cmGlobalVisualStudioGenerator::GetUserMacrosDirectory()
  204. {
  205. return "";
  206. }
  207. //----------------------------------------------------------------------------
  208. std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
  209. {
  210. return "";
  211. }
  212. //----------------------------------------------------------------------------
  213. bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
  214. {
  215. if(!this->cmGlobalGenerator::ComputeTargetDepends())
  216. {
  217. return false;
  218. }
  219. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  220. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  221. {
  222. std::vector<cmLocalGenerator*>& gen = it->second;
  223. for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
  224. i != gen.end(); ++i)
  225. {
  226. cmTargets& targets = (*i)->GetMakefile()->GetTargets();
  227. for(cmTargets::iterator ti = targets.begin();
  228. ti != targets.end(); ++ti)
  229. {
  230. this->ComputeVSTargetDepends(ti->second);
  231. }
  232. }
  233. }
  234. return true;
  235. }
  236. //----------------------------------------------------------------------------
  237. void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
  238. {
  239. if(this->VSTargetDepends.find(&target) != this->VSTargetDepends.end())
  240. {
  241. return;
  242. }
  243. VSDependSet& vsTargetDepend = this->VSTargetDepends[&target];
  244. if(target.GetType() != cmTarget::STATIC_LIBRARY)
  245. {
  246. cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
  247. for(cmTarget::LinkLibraryVectorType::const_iterator j = libs.begin();
  248. j != libs.end(); ++j)
  249. {
  250. if(j->first != target.GetName() &&
  251. this->FindTarget(0, j->first.c_str()))
  252. {
  253. vsTargetDepend.insert(j->first);
  254. }
  255. }
  256. }
  257. std::set<cmStdString> const& utils = target.GetUtilities();
  258. for(std::set<cmStdString>::const_iterator i = utils.begin();
  259. i != utils.end(); ++i)
  260. {
  261. if(*i != target.GetName())
  262. {
  263. std::string name = this->GetUtilityForTarget(target, i->c_str());
  264. vsTargetDepend.insert(name);
  265. }
  266. }
  267. }
  268. //----------------------------------------------------------------------------
  269. bool cmGlobalVisualStudioGenerator::CheckTargetLinks(cmTarget& target,
  270. const char* name)
  271. {
  272. // Return whether the given target links to a target with the given name.
  273. if(target.GetType() == cmTarget::STATIC_LIBRARY)
  274. {
  275. // Static libraries never link to anything.
  276. return false;
  277. }
  278. cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
  279. for(cmTarget::LinkLibraryVectorType::const_iterator i = libs.begin();
  280. i != libs.end(); ++i)
  281. {
  282. if(i->first == name)
  283. {
  284. return true;
  285. }
  286. }
  287. return false;
  288. }
  289. //----------------------------------------------------------------------------
  290. std::string cmGlobalVisualStudioGenerator::GetUtilityDepend(cmTarget* target)
  291. {
  292. UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
  293. if(i == this->UtilityDepends.end())
  294. {
  295. std::string name = this->WriteUtilityDepend(target);
  296. UtilityDependsMap::value_type entry(target, name);
  297. i = this->UtilityDepends.insert(entry).first;
  298. }
  299. return i->second;
  300. }
  301. //----------------------------------------------------------------------------
  302. std::string
  303. cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
  304. const char* name)
  305. {
  306. if(!this->VSLinksDependencies())
  307. {
  308. return name;
  309. }
  310. // Possibly depend on an intermediate utility target to avoid
  311. // linking.
  312. if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  313. target.GetType() == cmTarget::SHARED_LIBRARY ||
  314. target.GetType() == cmTarget::MODULE_LIBRARY ||
  315. target.GetType() == cmTarget::EXECUTABLE)
  316. {
  317. // The depender is a target that links.
  318. if(cmTarget* depTarget = this->FindTarget(0, name))
  319. {
  320. if(depTarget->GetType() == cmTarget::STATIC_LIBRARY ||
  321. depTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  322. depTarget->GetType() == cmTarget::MODULE_LIBRARY)
  323. {
  324. // This utility dependency will cause an attempt to link. If
  325. // the depender does not already link the dependee we need an
  326. // intermediate target.
  327. if(!this->CheckTargetLinks(target, name))
  328. {
  329. return this->GetUtilityDepend(depTarget);
  330. }
  331. }
  332. }
  333. }
  334. // No special case. Just use the original dependency name.
  335. return name;
  336. }
  337. //----------------------------------------------------------------------------
  338. #include <windows.h>
  339. //----------------------------------------------------------------------------
  340. bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
  341. const std::string& regKeyBase,
  342. std::string& nextAvailableSubKeyName)
  343. {
  344. bool macrosRegistered = false;
  345. std::string s1;
  346. std::string s2;
  347. // Make lowercase local copies, convert to Unix slashes, and
  348. // see if the resulting strings are the same:
  349. s1 = cmSystemTools::LowerCase(macrosFile);
  350. cmSystemTools::ConvertToUnixSlashes(s1);
  351. std::string keyname;
  352. HKEY hkey = NULL;
  353. LONG result = ERROR_SUCCESS;
  354. DWORD index = 0;
  355. keyname = regKeyBase + "\\OtherProjects7";
  356. hkey = NULL;
  357. result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(),
  358. 0, KEY_READ, &hkey);
  359. if (ERROR_SUCCESS == result)
  360. {
  361. // Iterate the subkeys and look for the values of interest in each subkey:
  362. CHAR subkeyname[256];
  363. DWORD cch_subkeyname = sizeof(subkeyname)/sizeof(subkeyname[0]);
  364. CHAR keyclass[256];
  365. DWORD cch_keyclass = sizeof(keyclass)/sizeof(keyclass[0]);
  366. FILETIME lastWriteTime;
  367. lastWriteTime.dwHighDateTime = 0;
  368. lastWriteTime.dwLowDateTime = 0;
  369. while (ERROR_SUCCESS == RegEnumKeyEx(hkey, index, subkeyname,
  370. &cch_subkeyname,
  371. 0, keyclass, &cch_keyclass, &lastWriteTime))
  372. {
  373. // Open the subkey and query the values of interest:
  374. HKEY hsubkey = NULL;
  375. result = RegOpenKeyEx(hkey, subkeyname, 0, KEY_READ, &hsubkey);
  376. if (ERROR_SUCCESS == result)
  377. {
  378. DWORD valueType = REG_SZ;
  379. CHAR data1[256];
  380. DWORD cch_data1 = sizeof(data1)/sizeof(data1[0]);
  381. RegQueryValueEx(hsubkey, "Path", 0, &valueType,
  382. (LPBYTE) &data1[0], &cch_data1);
  383. DWORD data2 = 0;
  384. DWORD cch_data2 = sizeof(data2);
  385. RegQueryValueEx(hsubkey, "Security", 0, &valueType,
  386. (LPBYTE) &data2, &cch_data2);
  387. DWORD data3 = 0;
  388. DWORD cch_data3 = sizeof(data3);
  389. RegQueryValueEx(hsubkey, "StorageFormat", 0, &valueType,
  390. (LPBYTE) &data3, &cch_data3);
  391. s2 = cmSystemTools::LowerCase(data1);
  392. cmSystemTools::ConvertToUnixSlashes(s2);
  393. if (s2 == s1)
  394. {
  395. macrosRegistered = true;
  396. }
  397. std::string fullname(data1);
  398. std::string filename;
  399. std::string filepath;
  400. std::string filepathname;
  401. std::string filepathpath;
  402. if (cmSystemTools::FileExists(fullname.c_str()))
  403. {
  404. filename = cmSystemTools::GetFilenameName(fullname);
  405. filepath = cmSystemTools::GetFilenamePath(fullname);
  406. filepathname = cmSystemTools::GetFilenameName(filepath);
  407. filepathpath = cmSystemTools::GetFilenamePath(filepath);
  408. }
  409. //std::cout << keyname << "\\" << subkeyname << ":" << std::endl;
  410. //std::cout << " Path: " << data1 << std::endl;
  411. //std::cout << " Security: " << data2 << std::endl;
  412. //std::cout << " StorageFormat: " << data3 << std::endl;
  413. //std::cout << " filename: " << filename << std::endl;
  414. //std::cout << " filepath: " << filepath << std::endl;
  415. //std::cout << " filepathname: " << filepathname << std::endl;
  416. //std::cout << " filepathpath: " << filepathpath << std::endl;
  417. //std::cout << std::endl;
  418. RegCloseKey(hsubkey);
  419. }
  420. else
  421. {
  422. std::cout << "error opening subkey: " << subkeyname << std::endl;
  423. std::cout << std::endl;
  424. }
  425. ++index;
  426. cch_subkeyname = sizeof(subkeyname)/sizeof(subkeyname[0]);
  427. cch_keyclass = sizeof(keyclass)/sizeof(keyclass[0]);
  428. lastWriteTime.dwHighDateTime = 0;
  429. lastWriteTime.dwLowDateTime = 0;
  430. }
  431. RegCloseKey(hkey);
  432. }
  433. else
  434. {
  435. std::cout << "error opening key: " << keyname << std::endl;
  436. std::cout << std::endl;
  437. }
  438. // Pass back next available sub key name, assuming sub keys always
  439. // follow the expected naming scheme. Expected naming scheme is that
  440. // the subkeys of OtherProjects7 is 0 to n-1, so it's ok to use "n"
  441. // as the name of the next subkey.
  442. std::ostringstream ossNext;
  443. ossNext << index;
  444. nextAvailableSubKeyName = ossNext.str();
  445. keyname = regKeyBase + "\\RecordingProject7";
  446. hkey = NULL;
  447. result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(),
  448. 0, KEY_READ, &hkey);
  449. if (ERROR_SUCCESS == result)
  450. {
  451. DWORD valueType = REG_SZ;
  452. CHAR data1[256];
  453. DWORD cch_data1 = sizeof(data1)/sizeof(data1[0]);
  454. RegQueryValueEx(hkey, "Path", 0, &valueType,
  455. (LPBYTE) &data1[0], &cch_data1);
  456. DWORD data2 = 0;
  457. DWORD cch_data2 = sizeof(data2);
  458. RegQueryValueEx(hkey, "Security", 0, &valueType,
  459. (LPBYTE) &data2, &cch_data2);
  460. DWORD data3 = 0;
  461. DWORD cch_data3 = sizeof(data3);
  462. RegQueryValueEx(hkey, "StorageFormat", 0, &valueType,
  463. (LPBYTE) &data3, &cch_data3);
  464. s2 = cmSystemTools::LowerCase(data1);
  465. cmSystemTools::ConvertToUnixSlashes(s2);
  466. if (s2 == s1)
  467. {
  468. macrosRegistered = true;
  469. }
  470. //std::cout << keyname << ":" << std::endl;
  471. //std::cout << " Path: " << data1 << std::endl;
  472. //std::cout << " Security: " << data2 << std::endl;
  473. //std::cout << " StorageFormat: " << data3 << std::endl;
  474. //std::cout << std::endl;
  475. RegCloseKey(hkey);
  476. }
  477. else
  478. {
  479. std::cout << "error opening key: " << keyname << std::endl;
  480. std::cout << std::endl;
  481. }
  482. return macrosRegistered;
  483. }
  484. //----------------------------------------------------------------------------
  485. void WriteVSMacrosFileRegistryEntry(
  486. const std::string& nextAvailableSubKeyName,
  487. const std::string& macrosFile,
  488. const std::string& regKeyBase)
  489. {
  490. std::string keyname = regKeyBase + "\\OtherProjects7";
  491. HKEY hkey = NULL;
  492. LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(), 0,
  493. KEY_READ|KEY_WRITE, &hkey);
  494. if (ERROR_SUCCESS == result)
  495. {
  496. // Create the subkey and set the values of interest:
  497. HKEY hsubkey = NULL;
  498. result = RegCreateKeyEx(hkey, nextAvailableSubKeyName.c_str(), 0, "", 0,
  499. KEY_READ|KEY_WRITE, 0, &hsubkey, 0);
  500. if (ERROR_SUCCESS == result)
  501. {
  502. DWORD dw = 0;
  503. std::string s(macrosFile);
  504. cmSystemTools::ReplaceString(s, "/", "\\");
  505. result = RegSetValueEx(hsubkey, "Path", 0, REG_SZ, (LPBYTE) s.c_str(),
  506. static_cast<DWORD>(strlen(s.c_str()) + 1));
  507. if (ERROR_SUCCESS != result)
  508. {
  509. std::cout << "error result 1: " << result << std::endl;
  510. std::cout << std::endl;
  511. }
  512. // Security value is always "1" for sample macros files (seems to be "2"
  513. // if you put the file somewhere outside the standard VSMacros folder)
  514. dw = 1;
  515. result = RegSetValueEx(hsubkey, "Security",
  516. 0, REG_DWORD, (LPBYTE) &dw, sizeof(DWORD));
  517. if (ERROR_SUCCESS != result)
  518. {
  519. std::cout << "error result 2: " << result << std::endl;
  520. std::cout << std::endl;
  521. }
  522. // StorageFormat value is always "0" for sample macros files
  523. dw = 0;
  524. result = RegSetValueEx(hsubkey, "StorageFormat",
  525. 0, REG_DWORD, (LPBYTE) &dw, sizeof(DWORD));
  526. if (ERROR_SUCCESS != result)
  527. {
  528. std::cout << "error result 3: " << result << std::endl;
  529. std::cout << std::endl;
  530. }
  531. RegCloseKey(hsubkey);
  532. }
  533. else
  534. {
  535. std::cout << "error creating subkey: "
  536. << nextAvailableSubKeyName << std::endl;
  537. std::cout << std::endl;
  538. }
  539. RegCloseKey(hkey);
  540. }
  541. else
  542. {
  543. std::cout << "error opening key: " << keyname << std::endl;
  544. std::cout << std::endl;
  545. }
  546. }
  547. //----------------------------------------------------------------------------
  548. void RegisterVisualStudioMacros(const std::string& macrosFile,
  549. const std::string& regKeyBase)
  550. {
  551. bool macrosRegistered;
  552. std::string nextAvailableSubKeyName;
  553. macrosRegistered = IsVisualStudioMacrosFileRegistered(macrosFile,
  554. regKeyBase, nextAvailableSubKeyName);
  555. if (!macrosRegistered)
  556. {
  557. int count = cmCallVisualStudioMacro::
  558. GetNumberOfRunningVisualStudioInstances("ALL");
  559. // Only register the macros file if there are *no* instances of Visual
  560. // Studio running. If we register it while one is running, first, it has
  561. // no effect on the running instance; second, and worse, Visual Studio
  562. // removes our newly added registration entry when it quits. Instead,
  563. // emit a warning asking the user to exit all running Visual Studio
  564. // instances...
  565. //
  566. if (0 != count)
  567. {
  568. std::ostringstream oss;
  569. oss << "Could not register CMake's Visual Studio macros file '"
  570. << CMAKE_VSMACROS_FILENAME "' while Visual Studio is running."
  571. << " Please exit all running instances of Visual Studio before"
  572. << " continuing." << std::endl
  573. << std::endl
  574. << "CMake needs to register Visual Studio macros when its macros"
  575. << " file is updated or when it detects that its current macros file"
  576. << " is no longer registered with Visual Studio."
  577. << std::endl;
  578. cmSystemTools::Message(oss.str().c_str(), "Warning");
  579. // Count them again now that the warning is over. In the case of a GUI
  580. // warning, the user may have gone to close Visual Studio and then come
  581. // back to the CMake GUI and clicked ok on the above warning. If so,
  582. // then register the macros *now* if the count is *now* 0...
  583. //
  584. count = cmCallVisualStudioMacro::
  585. GetNumberOfRunningVisualStudioInstances("ALL");
  586. // Also re-get the nextAvailableSubKeyName in case Visual Studio
  587. // wrote out new registered macros information as it was exiting:
  588. //
  589. if (0 == count)
  590. {
  591. IsVisualStudioMacrosFileRegistered(macrosFile, regKeyBase,
  592. nextAvailableSubKeyName);
  593. }
  594. }
  595. // Do another if check - 'count' may have changed inside the above if:
  596. //
  597. if (0 == count)
  598. {
  599. WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile,
  600. regKeyBase);
  601. }
  602. }
  603. }
  604. bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget& target)
  605. {
  606. // check to see if this is a fortran build
  607. std::set<cmStdString> languages;
  608. target.GetLanguages(languages);
  609. if(languages.size() == 1)
  610. {
  611. if(*languages.begin() == "Fortran")
  612. {
  613. return true;
  614. }
  615. }
  616. return false;
  617. }
  618. //----------------------------------------------------------------------------
  619. bool
  620. cmGlobalVisualStudioGenerator::TargetCompare
  621. ::operator()(cmTarget const* l, cmTarget const* r) const
  622. {
  623. // Make sure ALL_BUILD is first so it is the default active project.
  624. if(strcmp(r->GetName(), "ALL_BUILD") == 0)
  625. {
  626. return false;
  627. }
  628. if(strcmp(l->GetName(), "ALL_BUILD") == 0)
  629. {
  630. return true;
  631. }
  632. return strcmp(l->GetName(), r->GetName()) < 0;
  633. }
  634. //----------------------------------------------------------------------------
  635. cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  636. ::OrderedTargetDependSet(cmGlobalGenerator::TargetDependSet const& targets)
  637. {
  638. for(cmGlobalGenerator::TargetDependSet::const_iterator ti =
  639. targets.begin(); ti != targets.end(); ++ti)
  640. {
  641. this->insert(*ti);
  642. }
  643. }