cmGlobalVisualStudio7Generator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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 "cmGeneratedFileStream.h"
  16. #include "cmMakefile.h"
  17. #include "cmake.h"
  18. #include "windows.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. {
  39. // now build the test
  40. std::string makeCommand =
  41. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  42. if(makeCommand.size() == 0)
  43. {
  44. cmSystemTools::Error(
  45. "Generator cannot find the appropriate make command.");
  46. return 1;
  47. }
  48. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  49. std::string lowerCaseCommand = makeCommand;
  50. cmSystemTools::LowerCase(lowerCaseCommand);
  51. /**
  52. * Run an executable command and put the stdout in output.
  53. */
  54. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  55. cmSystemTools::ChangeDirectory(bindir);
  56. // if there are spaces in the makeCommand, assume a full path
  57. // and convert it to a path with no spaces in it as the
  58. // RunSingleCommand does not like spaces
  59. #if defined(_WIN32) && !defined(__CYGWIN__)
  60. if(makeCommand.find(' ') != std::string::npos)
  61. {
  62. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  63. }
  64. #endif
  65. makeCommand += " ";
  66. makeCommand += projectName;
  67. makeCommand += ".sln /build ";
  68. if ( m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION") )
  69. {
  70. makeCommand +=
  71. m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  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. #undef GetCurrentDirectory
  290. std::string homedir = root->GetMakefile()->GetCurrentDirectory();
  291. homedir += "/";
  292. bool doneAllBuild = false;
  293. bool doneRunTests = false;
  294. bool doneInstall = false;
  295. // For each cmMakefile, create a VCProj for it, and
  296. // add it to this SLN file
  297. unsigned int i;
  298. for(i = 0; i < generators.size(); ++i)
  299. {
  300. if(this->IsExcluded(root, generators[i]))
  301. {
  302. continue;
  303. }
  304. cmMakefile* mf = generators[i]->GetMakefile();
  305. // Get the source directory from the makefile
  306. std::string dir = mf->GetStartDirectory();
  307. // remove the home directory and / from the source directory
  308. // this gives a relative path
  309. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  310. // Get the list of create dsp files names from the cmVCProjWriter, more
  311. // than one dsp could have been created per input CMakeLists.txt file
  312. // for each target
  313. std::vector<std::string> dspnames =
  314. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  315. ->GetCreatedProjectNames();
  316. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  317. cmTargets::iterator l = tgts.begin();
  318. for(std::vector<std::string>::iterator si = dspnames.begin();
  319. l != tgts.end(); ++l)
  320. {
  321. // special handling for the current makefile
  322. if(mf == generators[0]->GetMakefile())
  323. {
  324. dir = "."; // no subdirectory for project generated
  325. // if this is the special ALL_BUILD utility, then
  326. // make it depend on every other non UTILITY project.
  327. // This is done by adding the names to the GetUtilities
  328. // vector on the makefile
  329. if(l->first == "ALL_BUILD" && !doneAllBuild)
  330. {
  331. unsigned int j;
  332. for(j = 0; j < generators.size(); ++j)
  333. {
  334. const cmTargets &atgts =
  335. generators[j]->GetMakefile()->GetTargets();
  336. for(cmTargets::const_iterator al = atgts.begin();
  337. al != atgts.end(); ++al)
  338. {
  339. if (al->second.IsInAll())
  340. {
  341. if (al->second.GetType() == cmTarget::UTILITY)
  342. {
  343. l->second.AddUtility(al->first.c_str());
  344. }
  345. else
  346. {
  347. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. // Write the project into the SLN file
  355. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  356. {
  357. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  358. // dodgy use of the cmCustomCommand's members to store the
  359. // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
  360. std::vector<std::string> stuff = cc.GetDepends();
  361. std::vector<std::string> depends;
  362. depends.push_back(cc.GetOutput());
  363. this->WriteExternalProject(fout, stuff[0].c_str(),
  364. stuff[1].c_str(), depends);
  365. ++si;
  366. }
  367. else
  368. {
  369. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  370. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  371. {
  372. bool skip = false;
  373. if(l->first == "ALL_BUILD" )
  374. {
  375. if(doneAllBuild)
  376. {
  377. skip = true;
  378. }
  379. else
  380. {
  381. doneAllBuild = true;
  382. }
  383. }
  384. if(l->first == "INSTALL")
  385. {
  386. if(doneInstall)
  387. {
  388. skip = true;
  389. }
  390. else
  391. {
  392. doneInstall = true;
  393. }
  394. }
  395. if(l->first == "RUN_TESTS")
  396. {
  397. if(doneRunTests)
  398. {
  399. skip = true;
  400. }
  401. else
  402. {
  403. doneRunTests = true;
  404. }
  405. }
  406. if(!skip)
  407. {
  408. this->WriteProject(fout, si->c_str(), dir.c_str(),l->second);
  409. }
  410. ++si;
  411. }
  412. }
  413. }
  414. }
  415. fout << "Global\n"
  416. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  417. int c = 0;
  418. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  419. i != m_Configurations.end(); ++i)
  420. {
  421. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  422. c++;
  423. }
  424. fout << "\tEndGlobalSection\n"
  425. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  426. // loop over again and compute the depends
  427. for(i = 0; i < generators.size(); ++i)
  428. {
  429. cmMakefile* mf = generators[i]->GetMakefile();
  430. cmLocalVisualStudio7Generator* pg =
  431. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  432. // Get the list of create dsp files names from the cmVCProjWriter, more
  433. // than one dsp could have been created per input CMakeLists.txt file
  434. // for each target
  435. std::vector<std::string> dspnames =
  436. pg->GetCreatedProjectNames();
  437. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  438. cmTargets::iterator l = tgts.begin();
  439. std::string dir = mf->GetStartDirectory();
  440. for(std::vector<std::string>::iterator si = dspnames.begin();
  441. l != tgts.end() && si != dspnames.end(); ++l)
  442. {
  443. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  444. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  445. {
  446. this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),l->second);
  447. ++si;
  448. }
  449. }
  450. }
  451. fout << "\tEndGlobalSection\n";
  452. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  453. // loop over again and compute the depends
  454. for(i = 0; i < generators.size(); ++i)
  455. {
  456. cmMakefile* mf = generators[i]->GetMakefile();
  457. cmLocalVisualStudio7Generator* pg =
  458. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  459. // Get the list of create dsp files names from the cmVCProjWriter, more
  460. // than one dsp could have been created per input CMakeLists.txt file
  461. // for each target
  462. std::vector<std::string> dspnames =
  463. pg->GetCreatedProjectNames();
  464. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  465. cmTargets::iterator l = tgts.begin();
  466. std::string dir = mf->GetStartDirectory();
  467. for(std::vector<std::string>::iterator si = dspnames.begin();
  468. l != tgts.end() && si != dspnames.end(); ++l)
  469. {
  470. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  471. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  472. {
  473. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  474. ++si;
  475. }
  476. }
  477. }
  478. fout << "\tEndGlobalSection\n";
  479. // Write the footer for the SLN file
  480. this->WriteSLNFooter(fout);
  481. }
  482. // Write a dsp file into the SLN file,
  483. // Note, that dependencies from executables to
  484. // the libraries it uses are also done here
  485. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  486. const char* dspname,
  487. const char* dir,
  488. const cmTarget&)
  489. {
  490. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  491. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  492. << dspname << "\", \""
  493. << d << "\\" << dspname << ".vcproj\", \"{"
  494. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  495. }
  496. // Write a dsp file into the SLN file,
  497. // Note, that dependencies from executables to
  498. // the libraries it uses are also done here
  499. void cmGlobalVisualStudio7Generator::WriteProjectDepends(std::ostream& fout,
  500. const char* dspname,
  501. const char* ,
  502. const cmTarget& target
  503. )
  504. {
  505. int depcount = 0;
  506. // insert Begin Project Dependency Project_Dep_Name project stuff here
  507. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  508. {
  509. cmTarget::LinkLibraries::const_iterator j, jend;
  510. j = target.GetLinkLibraries().begin();
  511. jend = target.GetLinkLibraries().end();
  512. for(;j!= jend; ++j)
  513. {
  514. if(j->first != dspname)
  515. {
  516. // is the library part of this SLN ? If so add dependency
  517. std::string libPath = j->first + "_CMAKE_PATH";
  518. const char* cacheValue
  519. = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
  520. if(cacheValue && *cacheValue)
  521. {
  522. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  523. << this->GetGUID(j->first.c_str()) << "}\n";
  524. depcount++;
  525. }
  526. }
  527. }
  528. }
  529. std::set<cmStdString>::const_iterator i, end;
  530. // write utility dependencies.
  531. i = target.GetUtilities().begin();
  532. end = target.GetUtilities().end();
  533. for(;i!= end; ++i)
  534. {
  535. if(*i != dspname)
  536. {
  537. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  538. << this->GetGUID(i->c_str()) << "}\n";
  539. depcount++;
  540. }
  541. }
  542. }
  543. // Write a dsp file into the SLN file,
  544. // Note, that dependencies from executables to
  545. // the libraries it uses are also done here
  546. void
  547. cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout,
  548. const char* name,
  549. bool in_all_build)
  550. {
  551. std::string guid = this->GetGUID(name);
  552. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  553. i != m_Configurations.end(); ++i)
  554. {
  555. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  556. if (in_all_build)
  557. {
  558. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  559. }
  560. }
  561. }
  562. // Write a dsp file into the SLN file,
  563. // Note, that dependencies from executables to
  564. // the libraries it uses are also done here
  565. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  566. const char* name,
  567. const char* location,
  568. const std::vector<std::string>& )
  569. {
  570. std::string d = cmSystemTools::ConvertToOutputPath(location);
  571. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  572. << name << "\", \""
  573. << d << "\", \"{"
  574. << this->GetGUID(name) << "}\"\nEndProject\n";
  575. }
  576. // Standard end of dsw file
  577. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  578. {
  579. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  580. << "\tEndGlobalSection\n"
  581. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  582. << "\tEndGlobalSection\n"
  583. << "EndGlobal\n";
  584. }
  585. // ouput standard header for dsw file
  586. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  587. {
  588. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  589. }
  590. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  591. {
  592. std::string guidStoreName = name;
  593. guidStoreName += "_GUID_CMAKE";
  594. const char* storedGUID = m_CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  595. if(storedGUID)
  596. {
  597. return std::string(storedGUID);
  598. }
  599. cmSystemTools::Error("Internal CMake Error, Could not find GUID for target: ",
  600. name);
  601. return guidStoreName;
  602. }
  603. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  604. {
  605. std::string guidStoreName = name;
  606. guidStoreName += "_GUID_CMAKE";
  607. if(m_CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  608. {
  609. return;
  610. }
  611. std::string ret;
  612. UUID uid;
  613. unsigned char *uidstr;
  614. UuidCreate(&uid);
  615. UuidToString(&uid,&uidstr);
  616. ret = reinterpret_cast<char*>(uidstr);
  617. RpcStringFree(&uidstr);
  618. ret = cmSystemTools::UpperCase(ret);
  619. m_CMakeInstance->AddCacheEntry(guidStoreName.c_str(), ret.c_str(), "Stored GUID",
  620. cmCacheManager::INTERNAL);
  621. }
  622. void cmGlobalVisualStudio7Generator::LocalGenerate()
  623. {
  624. this->cmGlobalGenerator::LocalGenerate();
  625. }
  626. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  627. {
  628. return &m_Configurations;
  629. };
  630. //----------------------------------------------------------------------------
  631. void cmGlobalVisualStudio7Generator::GetDocumentation(cmDocumentationEntry& entry) const
  632. {
  633. entry.name = this->GetName();
  634. entry.brief = "Generates Visual Studio .NET 2002 project files.";
  635. entry.full = "";
  636. }
  637. // populate the m_SubProjectMap
  638. void cmGlobalVisualStudio7Generator::CollectSubprojects()
  639. {
  640. unsigned int i;
  641. for(i = 0; i < m_LocalGenerators.size(); ++i)
  642. {
  643. std::string name = m_LocalGenerators[i]->GetMakefile()->GetProjectName();
  644. m_SubProjectMap[name].push_back(m_LocalGenerators[i]);
  645. std::vector<std::string> const& pprojects
  646. = m_LocalGenerators[i]->GetMakefile()->GetParentProjects();
  647. for(unsigned int k =0; k < pprojects.size(); ++k)
  648. {
  649. m_SubProjectMap[pprojects[k]].push_back(m_LocalGenerators[i]);
  650. }
  651. }
  652. }
  653. // make sure "special" targets have GUID's
  654. void cmGlobalVisualStudio7Generator::Configure()
  655. {
  656. cmGlobalGenerator::Configure();
  657. this->CreateGUID("ALL_BUILD");
  658. this->CreateGUID("INSTALL");
  659. this->CreateGUID("RUN_TESTS");
  660. }