cmGlobalVisualStudio7Generator.cxx 25 KB

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