cmGlobalVisualStudio7Generator.cxx 22 KB

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