cmGlobalVisualStudio7Generator.cxx 23 KB

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