cmGlobalVisualStudio7Generator.cxx 24 KB

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