cmGlobalVisualStudio7Generator.cxx 23 KB

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