cmGlobalVisualStudio7Generator.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalVisualStudio7Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmake.h"
  17. #include "windows.h"
  18. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
  19. {
  20. m_FindMakeProgramFile = "CMakeVS7FindMake.cmake";
  21. }
  22. void cmGlobalVisualStudio7Generator::EnableLanguage(const char* lang,
  23. cmMakefile *mf)
  24. {
  25. mf->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)");
  26. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  27. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  28. // Create list of configurations requested by user's cache, if any.
  29. this->GenerateConfigurations(mf);
  30. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  31. }
  32. int cmGlobalVisualStudio7Generator::TryCompile(const char *,
  33. const char *bindir,
  34. const char *projectName,
  35. const char *targetName,
  36. std::string *output)
  37. {
  38. // now build the test
  39. std::string makeCommand =
  40. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  41. if(makeCommand.size() == 0)
  42. {
  43. cmSystemTools::Error(
  44. "Generator cannot find the appropriate make command.");
  45. return 1;
  46. }
  47. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  48. std::string lowerCaseCommand = makeCommand;
  49. cmSystemTools::LowerCase(lowerCaseCommand);
  50. /**
  51. * Run an executable command and put the stdout in output.
  52. */
  53. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  54. cmSystemTools::ChangeDirectory(bindir);
  55. // if there are spaces in the makeCommand, assume a full path
  56. // and convert it to a path with no spaces in it as the
  57. // RunSingleCommand does not like spaces
  58. #if defined(_WIN32) && !defined(__CYGWIN__)
  59. if(makeCommand.find(' ') != std::string::npos)
  60. {
  61. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  62. }
  63. #endif
  64. makeCommand += " ";
  65. makeCommand += projectName;
  66. makeCommand += ".sln /build ";
  67. if ( m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION") )
  68. {
  69. makeCommand +=
  70. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  71. }
  72. else
  73. {
  74. makeCommand += "Debug";
  75. }
  76. makeCommand += " /project ";
  77. if (targetName)
  78. {
  79. makeCommand += targetName;
  80. }
  81. else
  82. {
  83. makeCommand += "ALL_BUILD";
  84. }
  85. int retVal;
  86. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  87. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output, &retVal,
  88. 0, false, timeout))
  89. {
  90. cmSystemTools::Error("Generator: execution of devenv failed.");
  91. // return to the original directory
  92. cmSystemTools::ChangeDirectory(cwd.c_str());
  93. return 1;
  94. }
  95. cmSystemTools::ChangeDirectory(cwd.c_str());
  96. return retVal;
  97. }
  98. ///! Create a local generator appropriate to this Global Generator
  99. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  100. {
  101. cmLocalGenerator *lg = new cmLocalVisualStudio7Generator;
  102. lg->SetGlobalGenerator(this);
  103. return lg;
  104. }
  105. void cmGlobalVisualStudio7Generator::SetupTests()
  106. {
  107. std::string ctest =
  108. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  109. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  110. ctest += "/";
  111. ctest += "ctest";
  112. ctest += cmSystemTools::GetExecutableExtension();
  113. if(!cmSystemTools::FileExists(ctest.c_str()))
  114. {
  115. ctest =
  116. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  117. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  118. ctest += "/Debug/";
  119. ctest += "ctest";
  120. ctest += cmSystemTools::GetExecutableExtension();
  121. }
  122. if(!cmSystemTools::FileExists(ctest.c_str()))
  123. {
  124. ctest =
  125. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  126. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  127. ctest += "/Release/";
  128. ctest += "ctest";
  129. ctest += cmSystemTools::GetExecutableExtension();
  130. }
  131. // if we found ctest
  132. if (cmSystemTools::FileExists(ctest.c_str()))
  133. {
  134. // Create a full path filename for output Testfile
  135. std::string fname;
  136. fname = m_CMakeInstance->GetStartOutputDirectory();
  137. fname += "/";
  138. fname += "DartTestfile.txt";
  139. // If the file doesn't exist, then ENABLE_TESTING hasn't been run
  140. if (cmSystemTools::FileExists(fname.c_str()))
  141. {
  142. std::vector<std::string> srcs;
  143. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  144. for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it)
  145. {
  146. std::vector<cmLocalGenerator*>& gen = it->second;
  147. // add the ALL_BUILD to the first local generator of each project
  148. if(gen.size())
  149. {
  150. gen[0]->GetMakefile()->
  151. AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",false,srcs);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  158. {
  159. // process the configurations
  160. const char* ct
  161. = m_CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  162. if ( ct )
  163. {
  164. std::string configTypes = ct;
  165. std::string::size_type start = 0;
  166. std::string::size_type endpos = 0;
  167. while(endpos != std::string::npos)
  168. {
  169. endpos = configTypes.find_first_of(" ;", start);
  170. std::string config;
  171. std::string::size_type len;
  172. if(endpos != std::string::npos)
  173. {
  174. len = endpos - start;
  175. }
  176. else
  177. {
  178. len = configTypes.size() - start;
  179. }
  180. config = configTypes.substr(start, len);
  181. if(config == "Debug" || config == "Release" ||
  182. config == "MinSizeRel" || config == "RelWithDebInfo")
  183. {
  184. // only add unique configurations
  185. if(std::find(m_Configurations.begin(),
  186. m_Configurations.end(), config) == m_Configurations.end())
  187. {
  188. m_Configurations.push_back(config);
  189. }
  190. }
  191. else
  192. {
  193. cmSystemTools::Error(
  194. "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
  195. config.c_str(),
  196. " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
  197. }
  198. start = endpos+1;
  199. }
  200. }
  201. if(m_Configurations.size() == 0)
  202. {
  203. m_Configurations.push_back("Debug");
  204. m_Configurations.push_back("Release");
  205. }
  206. // Reset the entry to have a semi-colon separated list.
  207. std::string configs = m_Configurations[0];
  208. for(unsigned int i=1; i < m_Configurations.size(); ++i)
  209. {
  210. configs += ";";
  211. configs += m_Configurations[i];
  212. }
  213. mf->AddCacheDefinition(
  214. "CMAKE_CONFIGURATION_TYPES",
  215. configs.c_str(),
  216. "Semicolon separated list of supported configuration types, "
  217. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  218. "anything else will be ignored.",
  219. cmCacheManager::STRING);
  220. }
  221. void cmGlobalVisualStudio7Generator::Generate()
  222. {
  223. // collect sub-projects
  224. this->CollectSubprojects();
  225. // add a special target that depends on ALL projects for easy build
  226. // of Debug only
  227. std::vector<std::string> srcs;
  228. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  229. for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it)
  230. {
  231. std::vector<cmLocalGenerator*>& gen = it->second;
  232. // add the ALL_BUILD to the first local generator of each project
  233. if(gen.size())
  234. {
  235. gen[0]->GetMakefile()->
  236. AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false,srcs);
  237. std::string cmake_command =
  238. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  239. gen[0]->GetMakefile()->
  240. AddUtilityCommand("INSTALL", cmake_command.c_str(),
  241. "-DBUILD_TYPE=$(IntDir) -P cmake_install.cmake",false,srcs);
  242. }
  243. }
  244. // add the Run Tests command
  245. this->SetupTests();
  246. // first do the superclass method
  247. this->cmGlobalGenerator::Generate();
  248. // Now write out the DSW
  249. this->OutputSLNFile();
  250. }
  251. void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root,
  252. std::vector<cmLocalGenerator*>& generators)
  253. {
  254. if(generators.size() == 0)
  255. {
  256. return;
  257. }
  258. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  259. fname += "/";
  260. fname += root->GetMakefile()->GetProjectName();
  261. fname += ".sln";
  262. std::ofstream fout(fname.c_str());
  263. if(!fout)
  264. {
  265. cmSystemTools::Error("Error can not open DSW file for write: ",
  266. fname.c_str());
  267. return;
  268. }
  269. this->WriteSLNFile(fout, root, generators);
  270. }
  271. // output the SLN file
  272. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  273. {
  274. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  275. for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it)
  276. {
  277. this->OutputSLNFile(it->second[0], it->second);
  278. }
  279. }
  280. // Write a SLN file to the stream
  281. void cmGlobalVisualStudio7Generator::WriteSLNFile(std::ostream& fout,
  282. cmLocalGenerator* root,
  283. std::vector<cmLocalGenerator*>& generators)
  284. {
  285. // Write out the header for a SLN file
  286. this->WriteSLNHeader(fout);
  287. // Get the home directory with the trailing slash
  288. std::string homedir = m_CMakeInstance->GetHomeDirectory();
  289. homedir += "/";
  290. bool doneAllBuild = false;
  291. bool doneRunTests = false;
  292. bool doneInstall = false;
  293. // For each cmMakefile, create a VCProj for it, and
  294. // add it to this SLN file
  295. unsigned int i;
  296. for(i = 0; i < generators.size(); ++i)
  297. {
  298. if(this->IsExcluded(root, generators[i]))
  299. {
  300. continue;
  301. }
  302. cmMakefile* mf = generators[i]->GetMakefile();
  303. // Get the source directory from the makefile
  304. std::string dir = mf->GetStartDirectory();
  305. // remove the home directory and / from the source directory
  306. // this gives a relative path
  307. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  308. // Get the list of create dsp files names from the cmVCProjWriter, more
  309. // than one dsp could have been created per input CMakeLists.txt file
  310. // for each target
  311. std::vector<std::string> dspnames =
  312. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  313. ->GetCreatedProjectNames();
  314. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  315. cmTargets::iterator l = tgts.begin();
  316. for(std::vector<std::string>::iterator si = dspnames.begin();
  317. l != tgts.end(); ++l)
  318. {
  319. // special handling for the current makefile
  320. if(mf == generators[0]->GetMakefile())
  321. {
  322. dir = "."; // no subdirectory for project generated
  323. // if this is the special ALL_BUILD utility, then
  324. // make it depend on every other non UTILITY project.
  325. // This is done by adding the names to the GetUtilities
  326. // vector on the makefile
  327. if(l->first == "ALL_BUILD" && !doneAllBuild)
  328. {
  329. unsigned int j;
  330. for(j = 0; j < generators.size(); ++j)
  331. {
  332. const cmTargets &atgts =
  333. generators[j]->GetMakefile()->GetTargets();
  334. for(cmTargets::const_iterator al = atgts.begin();
  335. al != atgts.end(); ++al)
  336. {
  337. if (al->second.IsInAll())
  338. {
  339. if (al->second.GetType() == cmTarget::UTILITY)
  340. {
  341. l->second.AddUtility(al->first.c_str());
  342. }
  343. else
  344. {
  345. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. // Write the project into the SLN file
  353. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  354. {
  355. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  356. // dodgy use of the cmCustomCommand's members to store the
  357. // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
  358. std::vector<std::string> stuff = cc.GetDepends();
  359. std::vector<std::string> depends;
  360. depends.push_back(cc.GetOutput());
  361. this->WriteExternalProject(fout, stuff[0].c_str(),
  362. stuff[1].c_str(), depends);
  363. ++si;
  364. }
  365. else
  366. {
  367. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  368. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  369. {
  370. bool skip = false;
  371. if(l->first == "ALL_BUILD" )
  372. {
  373. if(doneAllBuild)
  374. {
  375. skip = true;
  376. }
  377. else
  378. {
  379. doneAllBuild = true;
  380. }
  381. }
  382. if(l->first == "INSTALL")
  383. {
  384. if(doneInstall)
  385. {
  386. skip = true;
  387. }
  388. else
  389. {
  390. doneInstall = true;
  391. }
  392. }
  393. if(l->first == "RUN_TESTS")
  394. {
  395. if(doneRunTests)
  396. {
  397. skip = true;
  398. }
  399. else
  400. {
  401. doneRunTests = true;
  402. }
  403. }
  404. if(!skip)
  405. {
  406. this->WriteProject(fout, si->c_str(), dir.c_str(),l->second);
  407. }
  408. ++si;
  409. }
  410. }
  411. }
  412. }
  413. fout << "Global\n"
  414. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  415. int c = 0;
  416. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  417. i != m_Configurations.end(); ++i)
  418. {
  419. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  420. c++;
  421. }
  422. fout << "\tEndGlobalSection\n"
  423. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  424. // loop over again and compute the depends
  425. for(i = 0; i < generators.size(); ++i)
  426. {
  427. cmMakefile* mf = generators[i]->GetMakefile();
  428. cmLocalVisualStudio7Generator* pg =
  429. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  430. // Get the list of create dsp files names from the cmVCProjWriter, more
  431. // than one dsp could have been created per input CMakeLists.txt file
  432. // for each target
  433. std::vector<std::string> dspnames =
  434. pg->GetCreatedProjectNames();
  435. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  436. cmTargets::iterator l = tgts.begin();
  437. std::string dir = mf->GetStartDirectory();
  438. for(std::vector<std::string>::iterator si = dspnames.begin();
  439. l != tgts.end() && si != dspnames.end(); ++l)
  440. {
  441. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  442. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  443. {
  444. this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),l->second);
  445. ++si;
  446. }
  447. }
  448. }
  449. fout << "\tEndGlobalSection\n";
  450. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  451. // loop over again and compute the depends
  452. for(i = 0; i < generators.size(); ++i)
  453. {
  454. cmMakefile* mf = generators[i]->GetMakefile();
  455. cmLocalVisualStudio7Generator* pg =
  456. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  457. // Get the list of create dsp files names from the cmVCProjWriter, more
  458. // than one dsp could have been created per input CMakeLists.txt file
  459. // for each target
  460. std::vector<std::string> dspnames =
  461. pg->GetCreatedProjectNames();
  462. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  463. cmTargets::iterator l = tgts.begin();
  464. std::string dir = mf->GetStartDirectory();
  465. for(std::vector<std::string>::iterator si = dspnames.begin();
  466. l != tgts.end() && si != dspnames.end(); ++l)
  467. {
  468. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  469. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  470. {
  471. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  472. ++si;
  473. }
  474. }
  475. }
  476. fout << "\tEndGlobalSection\n";
  477. // Write the footer for the SLN file
  478. this->WriteSLNFooter(fout);
  479. }
  480. // Write a dsp file into the SLN file,
  481. // Note, that dependencies from executables to
  482. // the libraries it uses are also done here
  483. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  484. const char* dspname,
  485. const char* dir,
  486. const cmTarget&)
  487. {
  488. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  489. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  490. << dspname << "\", \""
  491. << d << "\\" << dspname << ".vcproj\", \"{"
  492. << this->CreateGUID(dspname) << "}\"\nEndProject\n";
  493. }
  494. // Write a dsp file into the SLN file,
  495. // Note, that dependencies from executables to
  496. // the libraries it uses are also done here
  497. void cmGlobalVisualStudio7Generator::WriteProjectDepends(std::ostream& fout,
  498. const char* dspname,
  499. const char* ,
  500. const cmTarget& target
  501. )
  502. {
  503. int depcount = 0;
  504. // insert Begin Project Dependency Project_Dep_Name project stuff here
  505. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  506. {
  507. cmTarget::LinkLibraries::const_iterator j, jend;
  508. j = target.GetLinkLibraries().begin();
  509. jend = target.GetLinkLibraries().end();
  510. for(;j!= jend; ++j)
  511. {
  512. if(j->first != dspname)
  513. {
  514. // is the library part of this SLN ? If so add dependency
  515. std::string libPath = j->first + "_CMAKE_PATH";
  516. const char* cacheValue
  517. = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
  518. if(cacheValue && *cacheValue)
  519. {
  520. fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {"
  521. << this->CreateGUID(j->first.c_str()) << "}\n";
  522. depcount++;
  523. }
  524. }
  525. }
  526. }
  527. std::set<cmStdString>::const_iterator i, end;
  528. // write utility dependencies.
  529. i = target.GetUtilities().begin();
  530. end = target.GetUtilities().end();
  531. for(;i!= end; ++i)
  532. {
  533. if(*i != dspname)
  534. {
  535. fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {"
  536. << this->CreateGUID(i->c_str()) << "}\n";
  537. depcount++;
  538. }
  539. }
  540. }
  541. // Write a dsp file into the SLN file,
  542. // Note, that dependencies from executables to
  543. // the libraries it uses are also done here
  544. void
  545. cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout,
  546. const char* name,
  547. bool in_all_build)
  548. {
  549. std::string guid = this->CreateGUID(name);
  550. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  551. i != m_Configurations.end(); ++i)
  552. {
  553. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  554. if (in_all_build)
  555. {
  556. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  557. }
  558. }
  559. }
  560. // Write a dsp file into the SLN file,
  561. // Note, that dependencies from executables to
  562. // the libraries it uses are also done here
  563. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  564. const char* name,
  565. const char* location,
  566. const std::vector<std::string>& )
  567. {
  568. std::string d = cmSystemTools::ConvertToOutputPath(location);
  569. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  570. << name << "\", \""
  571. << d << "\", \"{"
  572. << this->CreateGUID(name) << "}\"\nEndProject\n";
  573. }
  574. // Standard end of dsw file
  575. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  576. {
  577. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  578. << "\tEndGlobalSection\n"
  579. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  580. << "\tEndGlobalSection\n"
  581. << "EndGlobal\n";
  582. }
  583. // ouput standard header for dsw file
  584. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  585. {
  586. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  587. }
  588. std::string cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  589. {
  590. std::map<cmStdString, cmStdString>::iterator i = m_GUIDMap.find(name);
  591. if(i != m_GUIDMap.end())
  592. {
  593. return i->second;
  594. }
  595. std::string ret;
  596. UUID uid;
  597. unsigned char *uidstr;
  598. UuidCreate(&uid);
  599. UuidToString(&uid,&uidstr);
  600. ret = reinterpret_cast<char*>(uidstr);
  601. RpcStringFree(&uidstr);
  602. ret = cmSystemTools::UpperCase(ret);
  603. m_GUIDMap[name] = ret;
  604. return ret;
  605. }
  606. void cmGlobalVisualStudio7Generator::LocalGenerate()
  607. {
  608. this->cmGlobalGenerator::LocalGenerate();
  609. }
  610. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  611. {
  612. return &m_Configurations;
  613. };
  614. //----------------------------------------------------------------------------
  615. void cmGlobalVisualStudio7Generator::GetDocumentation(cmDocumentationEntry& entry) const
  616. {
  617. entry.name = this->GetName();
  618. entry.brief = "Generates Visual Studio .NET 2002 project files.";
  619. entry.full = "";
  620. }
  621. // populate the m_SubProjectMap
  622. void cmGlobalVisualStudio7Generator::CollectSubprojects()
  623. {
  624. unsigned int i;
  625. for(i = 0; i < m_LocalGenerators.size(); ++i)
  626. {
  627. std::string name = m_LocalGenerators[i]->GetMakefile()->GetProjectName();
  628. m_SubProjectMap[name].push_back(m_LocalGenerators[i]);
  629. std::vector<std::string> const& pprojects
  630. = m_LocalGenerators[i]->GetMakefile()->GetParentProjects();
  631. for(unsigned int k =0; k < pprojects.size(); ++k)
  632. {
  633. m_SubProjectMap[pprojects[k]].push_back(m_LocalGenerators[i]);
  634. }
  635. }
  636. }