cmGlobalVisualStudio7Generator.cxx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 "cmGeneratedFileStream.h"
  16. #include "cmLocalVisualStudio7Generator.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, bool optional)
  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, optional);
  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. // If any solution or project files changed during the generation,
  199. // tell Visual Studio to reload them...
  200. if(!cmSystemTools::GetErrorOccuredFlag())
  201. {
  202. this->CallVisualStudioMacro(MacroReload);
  203. }
  204. }
  205. void cmGlobalVisualStudio7Generator
  206. ::OutputSLNFile(cmLocalGenerator* root,
  207. std::vector<cmLocalGenerator*>& generators)
  208. {
  209. if(generators.size() == 0)
  210. {
  211. return;
  212. }
  213. this->CurrentProject = root->GetMakefile()->GetProjectName();
  214. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  215. fname += "/";
  216. fname += root->GetMakefile()->GetProjectName();
  217. fname += ".sln";
  218. cmGeneratedFileStream fout(fname.c_str());
  219. fout.SetCopyIfDifferent(true);
  220. if(!fout)
  221. {
  222. return;
  223. }
  224. this->WriteSLNFile(fout, root, generators);
  225. if (fout.Close())
  226. {
  227. this->FileReplacedDuringGenerate(fname);
  228. }
  229. }
  230. // output the SLN file
  231. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  232. {
  233. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  234. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  235. {
  236. this->OutputSLNFile(it->second[0], it->second);
  237. }
  238. }
  239. // Write a SLN file to the stream
  240. void cmGlobalVisualStudio7Generator
  241. ::WriteSLNFile(std::ostream& fout,
  242. cmLocalGenerator* root,
  243. std::vector<cmLocalGenerator*>& generators)
  244. {
  245. // Write out the header for a SLN file
  246. this->WriteSLNHeader(fout);
  247. // Get the start directory with the trailing slash
  248. std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
  249. rootdir += "/";
  250. bool doneAllBuild = false;
  251. bool doneRunTests = false;
  252. bool doneInstall = false;
  253. bool doneEditCache = false;
  254. bool doneRebuildCache = false;
  255. bool donePackage = false;
  256. // 1.
  257. // Collecte all targets in generators vector and the targets
  258. // that they depend on
  259. // 2. loop over all targets and put .vcproj reference
  260. // into .sln file. .vcproj files should already exist
  261. // from local generation step. Do not add "pulled" in .vcproj
  262. // to ALL_BUILD.
  263. // See: cmGlobalGenerator::GetTargetDepends
  264. // cmGlobalGenerator::TargetDependSet myset;
  265. // foreach t in all targets
  266. // cmGlobalGenerator::TargetDependSet const& tset = GetTargetDepends(t);
  267. // myset.insert(tset.begin(), tset.end());
  268. // foreach t in myset
  269. // t->GetMakefile()->GetLocalGenerator()->GetVCProjPath()
  270. // if t was not in original set of targets disable all for it
  271. // For each cmMakefile, create a VCProj for it, and
  272. // add it to this SLN file
  273. unsigned int i;
  274. for(i = 0; i < generators.size(); ++i)
  275. {
  276. if(this->IsExcluded(root, generators[i]))
  277. {
  278. continue;
  279. }
  280. cmMakefile* mf = generators[i]->GetMakefile();
  281. // Get the source directory from the makefile
  282. std::string dir = mf->GetStartOutputDirectory();
  283. // remove the home directory and / from the source directory
  284. // this gives a relative path
  285. cmSystemTools::ReplaceString(dir, rootdir.c_str(), "");
  286. // Get the list of create dsp files names from the cmVCProjWriter, more
  287. // than one dsp could have been created per input CMakeLists.txt file
  288. // for each target
  289. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  290. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  291. {
  292. // special handling for the current makefile
  293. if(mf == generators[0]->GetMakefile())
  294. {
  295. dir = "."; // no subdirectory for project generated
  296. // if this is the special ALL_BUILD utility, then
  297. // make it depend on every other non UTILITY project.
  298. // This is done by adding the names to the GetUtilities
  299. // vector on the makefile
  300. if(l->first == "ALL_BUILD" && !doneAllBuild)
  301. {
  302. unsigned int j;
  303. for(j = 0; j < generators.size(); ++j)
  304. {
  305. cmTargets &atgts = generators[j]->GetMakefile()->GetTargets();
  306. for(cmTargets::iterator al = atgts.begin();
  307. al != atgts.end(); ++al)
  308. {
  309. if (!al->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  310. {
  311. if (al->second.GetType() == cmTarget::UTILITY ||
  312. al->second.GetType() == cmTarget::GLOBAL_TARGET)
  313. {
  314. l->second.AddUtility(al->first.c_str());
  315. }
  316. else
  317. {
  318. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. // Write the project into the SLN file
  326. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  327. {
  328. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  329. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  330. std::string project = cmds[0][0];
  331. std::string location = cmds[0][1];
  332. this->WriteExternalProject(fout, project.c_str(),
  333. location.c_str(), cc.GetDepends());
  334. }
  335. else
  336. {
  337. bool skip = false;
  338. if(l->first == "ALL_BUILD" )
  339. {
  340. if(doneAllBuild)
  341. {
  342. skip = true;
  343. }
  344. else
  345. {
  346. doneAllBuild = true;
  347. }
  348. }
  349. if(l->first == "INSTALL")
  350. {
  351. if(doneInstall)
  352. {
  353. skip = true;
  354. }
  355. else
  356. {
  357. doneInstall = true;
  358. }
  359. }
  360. if(l->first == "RUN_TESTS")
  361. {
  362. if(doneRunTests)
  363. {
  364. skip = true;
  365. }
  366. else
  367. {
  368. doneRunTests = true;
  369. }
  370. }
  371. if(l->first == "EDIT_CACHE")
  372. {
  373. if(doneEditCache)
  374. {
  375. skip = true;
  376. }
  377. else
  378. {
  379. doneEditCache = true;
  380. }
  381. }
  382. if(l->first == "REBUILD_CACHE")
  383. {
  384. if(doneRebuildCache)
  385. {
  386. skip = true;
  387. }
  388. else
  389. {
  390. doneRebuildCache = true;
  391. }
  392. }
  393. if(l->first == "PACKAGE")
  394. {
  395. if(donePackage)
  396. {
  397. skip = true;
  398. }
  399. else
  400. {
  401. donePackage = true;
  402. }
  403. }
  404. if(!skip)
  405. {
  406. const char *dspname =
  407. l->second.GetProperty("GENERATOR_FILE_NAME");
  408. if (dspname)
  409. {
  410. this->WriteProject(fout, dspname, dir.c_str(),l->second);
  411. }
  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 = this->Configurations.begin();
  420. i != this->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. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  437. cmTargets::iterator l = tgts.begin();
  438. std::string dir = mf->GetStartDirectory();
  439. for(; l != tgts.end(); ++l)
  440. {
  441. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  442. {
  443. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  444. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  445. std::string name = cmds[0][0];
  446. std::vector<std::string> depends = cc.GetDepends();
  447. std::vector<std::string>::iterator iter;
  448. int depcount = 0;
  449. for(iter = depends.begin(); iter != depends.end(); ++iter)
  450. {
  451. std::string guid = this->GetGUID(iter->c_str());
  452. if(guid.size() == 0)
  453. {
  454. std::string m = "Target: ";
  455. m += l->first;
  456. m += " depends on unknown target: ";
  457. m += iter->c_str();
  458. cmSystemTools::Error(m.c_str());
  459. }
  460. fout << "\t\t{" << this->GetGUID(name.c_str())
  461. << "}." << depcount << " = {" << guid.c_str() << "}\n";
  462. depcount++;
  463. }
  464. }
  465. else
  466. {
  467. const char *dspname =
  468. l->second.GetProperty("GENERATOR_FILE_NAME");
  469. if (dspname)
  470. {
  471. this->WriteProjectDepends(fout, dspname,
  472. dir.c_str(), l->second);
  473. }
  474. }
  475. }
  476. }
  477. fout << "\tEndGlobalSection\n";
  478. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  479. // loop over again and compute the depends
  480. for(i = 0; i < generators.size(); ++i)
  481. {
  482. cmMakefile* mf = generators[i]->GetMakefile();
  483. cmLocalVisualStudio7Generator* pg =
  484. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  485. // Get the list of create dsp files names from the cmVCProjWriter, more
  486. // than one dsp could have been created per input CMakeLists.txt file
  487. // for each target
  488. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  489. cmTargets::iterator l = tgts.begin();
  490. std::string dir = mf->GetStartDirectory();
  491. for(; l != tgts.end(); ++l)
  492. {
  493. if(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  494. {
  495. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  496. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  497. std::string name = cmds[0][0];
  498. this->WriteProjectConfigurations(fout, name.c_str(),
  499. true);
  500. }
  501. else
  502. {
  503. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  504. root->GetMakefile()->GetProjectName(),
  505. &l->second);
  506. const char *dspname =
  507. l->second.GetProperty("GENERATOR_FILE_NAME");
  508. if (dspname)
  509. {
  510. this->WriteProjectConfigurations(fout, dspname,
  511. partOfDefaultBuild);
  512. }
  513. }
  514. }
  515. }
  516. fout << "\tEndGlobalSection\n";
  517. // Write the footer for the SLN file
  518. this->WriteSLNFooter(fout);
  519. }
  520. //----------------------------------------------------------------------------
  521. std::string
  522. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  523. {
  524. // Convert to backslashes. Do not use ConvertToOutputPath because
  525. // we will add quoting ourselves, and we know these projects always
  526. // use windows slashes.
  527. std::string d = path;
  528. std::string::size_type pos = 0;
  529. while((pos = d.find('/', pos)) != d.npos)
  530. {
  531. d[pos++] = '\\';
  532. }
  533. return d;
  534. }
  535. // Write a dsp file into the SLN file,
  536. // Note, that dependencies from executables to
  537. // the libraries it uses are also done here
  538. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  539. const char* dspname,
  540. const char* dir, cmTarget&)
  541. {
  542. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  543. << dspname << "\", \""
  544. << this->ConvertToSolutionPath(dir)
  545. << "\\" << dspname << ".vcproj\", \"{"
  546. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  547. }
  548. // Write a dsp file into the SLN file,
  549. // Note, that dependencies from executables to
  550. // the libraries it uses are also done here
  551. void
  552. cmGlobalVisualStudio7Generator
  553. ::WriteProjectDepends(std::ostream& fout,
  554. const char* dspname,
  555. const char*, cmTarget& target)
  556. {
  557. int depcount = 0;
  558. // insert Begin Project Dependency Project_Dep_Name project stuff here
  559. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  560. {
  561. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  562. j = target.GetLinkLibraries().begin();
  563. jend = target.GetLinkLibraries().end();
  564. for(;j!= jend; ++j)
  565. {
  566. if(j->first != dspname)
  567. {
  568. // is the library part of this SLN ? If so add dependency
  569. if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str()))
  570. {
  571. std::string guid = this->GetGUID(j->first.c_str());
  572. if(guid.size() == 0)
  573. {
  574. std::string m = "Target: ";
  575. m += dspname;
  576. m += " depends on unknown target: ";
  577. m += j->first.c_str();
  578. cmSystemTools::Error(m.c_str());
  579. }
  580. fout << "\t\t{" << this->GetGUID(dspname) << "}."
  581. << depcount << " = {" << guid << "}\n";
  582. depcount++;
  583. }
  584. }
  585. }
  586. }
  587. std::set<cmStdString>::const_iterator i, end;
  588. // write utility dependencies.
  589. i = target.GetUtilities().begin();
  590. end = target.GetUtilities().end();
  591. for(;i!= end; ++i)
  592. {
  593. if(*i != dspname)
  594. {
  595. std::string name = this->GetUtilityForTarget(target, i->c_str());
  596. std::string guid = this->GetGUID(name.c_str());
  597. if(guid.size() == 0)
  598. {
  599. std::string m = "Target: ";
  600. m += dspname;
  601. m += " depends on unknown target: ";
  602. m += name.c_str();
  603. cmSystemTools::Error(m.c_str());
  604. }
  605. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  606. << guid << "}\n";
  607. depcount++;
  608. }
  609. }
  610. }
  611. // Write a dsp file into the SLN file, Note, that dependencies from
  612. // executables to the libraries it uses are also done here
  613. void cmGlobalVisualStudio7Generator
  614. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  615. bool partOfDefaultBuild)
  616. {
  617. std::string guid = this->GetGUID(name);
  618. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  619. i != this->Configurations.end(); ++i)
  620. {
  621. fout << "\t\t{" << guid << "}." << *i
  622. << ".ActiveCfg = " << *i << "|Win32\n";
  623. if(partOfDefaultBuild)
  624. {
  625. fout << "\t\t{" << guid << "}." << *i
  626. << ".Build.0 = " << *i << "|Win32\n";
  627. }
  628. }
  629. }
  630. // Write a dsp file into the SLN file,
  631. // Note, that dependencies from executables to
  632. // the libraries it uses are also done here
  633. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  634. const char* name,
  635. const char* location,
  636. const std::vector<std::string>&)
  637. {
  638. std::string d = cmSystemTools::ConvertToOutputPath(location);
  639. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  640. << name << "\", \""
  641. << this->ConvertToSolutionPath(location) << "\", \"{"
  642. << this->GetGUID(name)
  643. << "}\"\n";
  644. fout << "EndProject\n";
  645. }
  646. // Standard end of dsw file
  647. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  648. {
  649. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  650. << "\tEndGlobalSection\n"
  651. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  652. << "\tEndGlobalSection\n"
  653. << "EndGlobal\n";
  654. }
  655. // ouput standard header for dsw file
  656. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  657. {
  658. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  659. }
  660. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  661. {
  662. std::string guidStoreName = name;
  663. guidStoreName += "_GUID_CMAKE";
  664. const char* storedGUID =
  665. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  666. if(storedGUID)
  667. {
  668. return std::string(storedGUID);
  669. }
  670. cmSystemTools::Error("Unknown Target referenced : ",
  671. name);
  672. return "";
  673. }
  674. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  675. {
  676. std::string guidStoreName = name;
  677. guidStoreName += "_GUID_CMAKE";
  678. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  679. {
  680. return;
  681. }
  682. std::string ret;
  683. UUID uid;
  684. unsigned char *uidstr;
  685. UuidCreate(&uid);
  686. UuidToString(&uid,&uidstr);
  687. ret = reinterpret_cast<char*>(uidstr);
  688. RpcStringFree(&uidstr);
  689. ret = cmSystemTools::UpperCase(ret);
  690. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  691. ret.c_str(), "Stored GUID",
  692. cmCacheManager::INTERNAL);
  693. }
  694. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  695. {
  696. return &this->Configurations;
  697. };
  698. //----------------------------------------------------------------------------
  699. void cmGlobalVisualStudio7Generator
  700. ::GetDocumentation(cmDocumentationEntry& entry) const
  701. {
  702. entry.Name = this->GetName();
  703. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  704. entry.Full = "";
  705. }
  706. // make sure "special" targets have GUID's
  707. void cmGlobalVisualStudio7Generator::Configure()
  708. {
  709. cmGlobalGenerator::Configure();
  710. this->CreateGUID("ALL_BUILD");
  711. this->CreateGUID("INSTALL");
  712. this->CreateGUID("RUN_TESTS");
  713. this->CreateGUID("EDIT_CACHE");
  714. this->CreateGUID("REBUILD_CACHE");
  715. this->CreateGUID("PACKAGE");
  716. }
  717. //----------------------------------------------------------------------------
  718. void
  719. cmGlobalVisualStudio7Generator
  720. ::AppendDirectoryForConfig(const char* prefix,
  721. const char* config,
  722. const char* suffix,
  723. std::string& dir)
  724. {
  725. if(config)
  726. {
  727. dir += prefix;
  728. dir += config;
  729. dir += suffix;
  730. }
  731. }
  732. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  733. cmTarget* target)
  734. {
  735. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  736. {
  737. return false;
  738. }
  739. // if it is a utilitiy target then only make it part of the
  740. // default build if another target depends on it
  741. int type = target->GetType();
  742. if (type == cmTarget::GLOBAL_TARGET)
  743. {
  744. return false;
  745. }
  746. if(type == cmTarget::UTILITY)
  747. {
  748. return this->IsDependedOn(project, target);
  749. }
  750. // default is to be part of the build
  751. return true;
  752. }
  753. //----------------------------------------------------------------------------
  754. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  755. {
  756. // Precompiled header and related options. Note that the
  757. // UsePrecompiledHeader entries are marked as "Continue" so that the
  758. // corresponding PrecompiledHeaderThrough entry can be found.
  759. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  760. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  761. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  762. cmVS7FlagTable::UserValueRequired},
  763. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  764. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  765. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  766. cmVS7FlagTable::UserValueRequired},
  767. // Exception handling mode. If no entries match, it will be FALSE.
  768. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  769. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  770. // The EHa option does not have an IDE setting. Let it go to false,
  771. // and have EHa passed on the command line by leaving out the table
  772. // entry.
  773. {0,0,0,0,0}
  774. };
  775. cmVS7FlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  776. {
  777. return cmVS7ExtraFlagTable;
  778. }