cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "windows.h" // this must be first to define GetCurrentDirectory
  11. #include "cmGlobalVisualStudio7Generator.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmLocalVisualStudio7Generator.h"
  14. #include "cmMakefile.h"
  15. #include "cmake.h"
  16. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
  17. {
  18. this->VersionId = "MSVC70";
  19. this->FindMakeProgramFile = "CMakeVS7FindMake.cmake";
  20. }
  21. void cmGlobalVisualStudio7Generator
  22. ::EnableLanguage(std::vector<std::string>const & lang,
  23. cmMakefile *mf, bool optional)
  24. {
  25. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  26. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  27. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  28. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  29. mf->AddDefinition("CMAKE_GENERATOR_FC", "ifort");
  30. this->AddPlatformDefinitions(mf);
  31. // Create list of configurations requested by user's cache, if any.
  32. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  33. this->GenerateConfigurations(mf);
  34. // if this environment variable is set, then copy it to
  35. // a static cache entry. It will be used by
  36. // cmLocalGenerator::ConstructScript, to add an extra PATH
  37. // to all custom commands. This is because the VS IDE
  38. // does not use the environment it is run in, and this allows
  39. // for running commands and using dll's that the IDE environment
  40. // does not know about.
  41. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  42. if(extraPath)
  43. {
  44. mf->AddCacheDefinition
  45. ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  46. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  47. cmCacheManager::STATIC);
  48. }
  49. }
  50. std::string cmGlobalVisualStudio7Generator
  51. ::GenerateBuildCommand(const char* makeProgram,
  52. const char *projectName,
  53. const char* additionalOptions, const char *targetName,
  54. const char* config, bool ignoreErrors, bool)
  55. {
  56. // Ingoring errors is not implemented in visual studio 6
  57. (void) ignoreErrors;
  58. // now build the test
  59. std::string makeCommand =
  60. cmSystemTools::ConvertToOutputPath(makeProgram);
  61. std::string lowerCaseCommand = makeCommand;
  62. cmSystemTools::LowerCase(lowerCaseCommand);
  63. // if there are spaces in the makeCommand, assume a full path
  64. // and convert it to a path with no spaces in it as the
  65. // RunSingleCommand does not like spaces
  66. #if defined(_WIN32) && !defined(__CYGWIN__)
  67. if(makeCommand.find(' ') != std::string::npos)
  68. {
  69. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  70. }
  71. #endif
  72. makeCommand += " ";
  73. makeCommand += projectName;
  74. makeCommand += ".sln ";
  75. bool clean = false;
  76. if ( targetName && strcmp(targetName, "clean") == 0 )
  77. {
  78. clean = true;
  79. targetName = "ALL_BUILD";
  80. }
  81. if(clean)
  82. {
  83. makeCommand += "/clean ";
  84. }
  85. else
  86. {
  87. makeCommand += "/build ";
  88. }
  89. if(config && strlen(config))
  90. {
  91. makeCommand += config;
  92. }
  93. else
  94. {
  95. makeCommand += "Debug";
  96. }
  97. makeCommand += " /project ";
  98. if (targetName && strlen(targetName))
  99. {
  100. makeCommand += targetName;
  101. }
  102. else
  103. {
  104. makeCommand += "ALL_BUILD";
  105. }
  106. if ( additionalOptions )
  107. {
  108. makeCommand += " ";
  109. makeCommand += additionalOptions;
  110. }
  111. return makeCommand;
  112. }
  113. ///! Create a local generator appropriate to this Global Generator
  114. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  115. {
  116. cmLocalVisualStudio7Generator *lg =
  117. new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS7);
  118. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  119. lg->SetGlobalGenerator(this);
  120. return lg;
  121. }
  122. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  123. {
  124. // process the configurations
  125. const char* ct
  126. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  127. if ( ct )
  128. {
  129. std::vector<std::string> argsOut;
  130. cmSystemTools::ExpandListArgument(ct, argsOut);
  131. for(std::vector<std::string>::iterator i = argsOut.begin();
  132. i != argsOut.end(); ++i)
  133. {
  134. if(std::find(this->Configurations.begin(),
  135. this->Configurations.end(),
  136. *i) == this->Configurations.end())
  137. {
  138. this->Configurations.push_back(*i);
  139. }
  140. }
  141. }
  142. // default to at least Debug and Release
  143. if(this->Configurations.size() == 0)
  144. {
  145. this->Configurations.push_back("Debug");
  146. this->Configurations.push_back("Release");
  147. }
  148. // Reset the entry to have a semi-colon separated list.
  149. std::string configs = this->Configurations[0];
  150. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  151. {
  152. configs += ";";
  153. configs += this->Configurations[i];
  154. }
  155. mf->AddCacheDefinition(
  156. "CMAKE_CONFIGURATION_TYPES",
  157. configs.c_str(),
  158. "Semicolon separated list of supported configuration types, "
  159. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  160. "anything else will be ignored.",
  161. cmCacheManager::STRING);
  162. }
  163. void cmGlobalVisualStudio7Generator::Generate()
  164. {
  165. // first do the superclass method
  166. this->cmGlobalVisualStudioGenerator::Generate();
  167. // Now write out the DSW
  168. this->OutputSLNFile();
  169. // If any solution or project files changed during the generation,
  170. // tell Visual Studio to reload them...
  171. if(!cmSystemTools::GetErrorOccuredFlag())
  172. {
  173. this->CallVisualStudioMacro(MacroReload);
  174. }
  175. }
  176. void cmGlobalVisualStudio7Generator
  177. ::OutputSLNFile(cmLocalGenerator* root,
  178. std::vector<cmLocalGenerator*>& generators)
  179. {
  180. if(generators.size() == 0)
  181. {
  182. return;
  183. }
  184. this->CurrentProject = root->GetMakefile()->GetProjectName();
  185. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  186. fname += "/";
  187. fname += root->GetMakefile()->GetProjectName();
  188. fname += ".sln";
  189. cmGeneratedFileStream fout(fname.c_str());
  190. fout.SetCopyIfDifferent(true);
  191. if(!fout)
  192. {
  193. return;
  194. }
  195. this->WriteSLNFile(fout, root, generators);
  196. if (fout.Close())
  197. {
  198. this->FileReplacedDuringGenerate(fname);
  199. }
  200. }
  201. // output the SLN file
  202. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  203. {
  204. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  205. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  206. {
  207. this->OutputSLNFile(it->second[0], it->second);
  208. }
  209. }
  210. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  211. std::ostream& fout,
  212. cmLocalGenerator* root,
  213. OrderedTargetDependSet const& projectTargets)
  214. {
  215. // loop over again and write out configurations for each target
  216. // in the solution
  217. for(OrderedTargetDependSet::const_iterator tt =
  218. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  219. {
  220. cmTarget* target = *tt;
  221. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  222. if(expath)
  223. {
  224. this->WriteProjectConfigurations(
  225. fout, target->GetName(),
  226. true, target->GetProperty("VS_PLATFORM_MAPPING"));
  227. }
  228. else
  229. {
  230. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  231. root->GetMakefile()->GetProjectName(), target);
  232. const char *vcprojName =
  233. target->GetProperty("GENERATOR_FILE_NAME");
  234. if (vcprojName)
  235. {
  236. this->WriteProjectConfigurations(fout, vcprojName,
  237. partOfDefaultBuild);
  238. }
  239. }
  240. }
  241. }
  242. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  243. std::ostream& fout,
  244. cmLocalGenerator* root,
  245. OrderedTargetDependSet const& projectTargets)
  246. {
  247. for(OrderedTargetDependSet::const_iterator tt =
  248. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  249. {
  250. cmTarget* target = *tt;
  251. bool written = false;
  252. // handle external vc project files
  253. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  254. if(expath)
  255. {
  256. std::string project = target->GetName();
  257. std::string location = expath;
  258. this->WriteExternalProject(fout,
  259. project.c_str(),
  260. location.c_str(),
  261. target->GetProperty("VS_PROJECT_TYPE"),
  262. target->GetUtilities());
  263. written = true;
  264. }
  265. else
  266. {
  267. const char *vcprojName =
  268. target->GetProperty("GENERATOR_FILE_NAME");
  269. if(vcprojName)
  270. {
  271. cmMakefile* tmf = target->GetMakefile();
  272. std::string dir = tmf->GetStartOutputDirectory();
  273. dir = root->Convert(dir.c_str(),
  274. cmLocalGenerator::START_OUTPUT);
  275. if(dir == ".")
  276. {
  277. dir = ""; // msbuild cannot handle ".\" prefix
  278. }
  279. this->WriteProject(fout, vcprojName, dir.c_str(),
  280. *target);
  281. written = true;
  282. }
  283. }
  284. // Create "solution folder" information from FOLDER target property
  285. //
  286. if (written && this->UseFolderProperty())
  287. {
  288. const char *targetFolder = target->GetProperty("FOLDER");
  289. if (targetFolder)
  290. {
  291. std::vector<cmsys::String> tokens =
  292. cmSystemTools::SplitString(targetFolder, '/', false);
  293. std::string cumulativePath = "";
  294. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  295. iter != tokens.end(); ++iter)
  296. {
  297. if(!iter->size())
  298. {
  299. continue;
  300. }
  301. if (cumulativePath.empty())
  302. {
  303. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  304. }
  305. else
  306. {
  307. VisualStudioFolders[cumulativePath].insert(
  308. cumulativePath + "/" + *iter);
  309. cumulativePath = cumulativePath + "/" + *iter;
  310. }
  311. this->CreateGUID(cumulativePath.c_str());
  312. }
  313. if (!cumulativePath.empty())
  314. {
  315. VisualStudioFolders[cumulativePath].insert(target->GetName());
  316. }
  317. }
  318. }
  319. }
  320. }
  321. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  322. std::ostream& fout,
  323. OrderedTargetDependSet const& projectTargets
  324. )
  325. {
  326. for(OrderedTargetDependSet::const_iterator tt =
  327. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  328. {
  329. cmTarget* target = *tt;
  330. cmMakefile* mf = target->GetMakefile();
  331. const char *vcprojName =
  332. target->GetProperty("GENERATOR_FILE_NAME");
  333. if (vcprojName)
  334. {
  335. std::string dir = mf->GetStartDirectory();
  336. this->WriteProjectDepends(fout, vcprojName,
  337. dir.c_str(), *target);
  338. }
  339. }
  340. }
  341. //----------------------------------------------------------------------------
  342. // Write a SLN file to the stream
  343. void cmGlobalVisualStudio7Generator
  344. ::WriteSLNFile(std::ostream& fout,
  345. cmLocalGenerator* root,
  346. std::vector<cmLocalGenerator*>& generators)
  347. {
  348. // Write out the header for a SLN file
  349. this->WriteSLNHeader(fout);
  350. // Collect all targets under this root generator and the transitive
  351. // closure of their dependencies.
  352. TargetDependSet projectTargets;
  353. TargetDependSet originalTargets;
  354. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  355. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  356. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  357. bool useFolderProperty = this->UseFolderProperty();
  358. if (useFolderProperty)
  359. {
  360. this->WriteFolders(fout);
  361. }
  362. // Write out the configurations information for the solution
  363. fout << "Global\n"
  364. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  365. int c = 0;
  366. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  367. i != this->Configurations.end(); ++i)
  368. {
  369. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  370. c++;
  371. }
  372. fout << "\tEndGlobalSection\n";
  373. // Write out project(target) depends
  374. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  375. this->WriteTargetDepends(fout, orderedProjectTargets);
  376. fout << "\tEndGlobalSection\n";
  377. if (useFolderProperty)
  378. {
  379. // Write out project folders
  380. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  381. this->WriteFoldersContent(fout);
  382. fout << "\tEndGlobalSection\n";
  383. }
  384. // Write out the configurations for all the targets in the project
  385. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  386. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  387. fout << "\tEndGlobalSection\n";
  388. // Write the footer for the SLN file
  389. this->WriteSLNFooter(fout);
  390. }
  391. //----------------------------------------------------------------------------
  392. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  393. {
  394. const char *prefix = "CMAKE_FOLDER_GUID_";
  395. const std::string::size_type skip_prefix = strlen(prefix);
  396. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  397. for(std::map<std::string,std::set<std::string> >::iterator iter =
  398. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  399. {
  400. std::string fullName = iter->first;
  401. std::string guid = this->GetGUID(fullName.c_str());
  402. cmSystemTools::ReplaceString(fullName, "/", "\\");
  403. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  404. {
  405. fullName = fullName.substr(skip_prefix);
  406. }
  407. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  408. fout << "Project(\"{" <<
  409. guidProjectTypeFolder << "}\") = \"" <<
  410. nameOnly << "\", \"" <<
  411. fullName << "\", \"{" <<
  412. guid <<
  413. "}\"\nEndProject\n";
  414. }
  415. }
  416. //----------------------------------------------------------------------------
  417. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  418. {
  419. for(std::map<std::string,std::set<std::string> >::iterator iter =
  420. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  421. {
  422. std::string key(iter->first);
  423. std::string guidParent(this->GetGUID(key.c_str()));
  424. for(std::set<std::string>::iterator it = iter->second.begin();
  425. it != iter->second.end(); ++it)
  426. {
  427. std::string value(*it);
  428. std::string guid(this->GetGUID(value.c_str()));
  429. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  430. }
  431. }
  432. }
  433. //----------------------------------------------------------------------------
  434. std::string
  435. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  436. {
  437. // Convert to backslashes. Do not use ConvertToOutputPath because
  438. // we will add quoting ourselves, and we know these projects always
  439. // use windows slashes.
  440. std::string d = path;
  441. std::string::size_type pos = 0;
  442. while((pos = d.find('/', pos)) != d.npos)
  443. {
  444. d[pos++] = '\\';
  445. }
  446. return d;
  447. }
  448. // Write a dsp file into the SLN file,
  449. // Note, that dependencies from executables to
  450. // the libraries it uses are also done here
  451. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  452. const char* dspname,
  453. const char* dir, cmTarget& target)
  454. {
  455. // check to see if this is a fortran build
  456. const char* ext = ".vcproj";
  457. const char* project =
  458. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  459. if(this->TargetIsFortranOnly(target))
  460. {
  461. ext = ".vfproj";
  462. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  463. }
  464. fout << project
  465. << dspname << "\", \""
  466. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  467. << dspname << ext << "\", \"{"
  468. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  469. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  470. if(ui != this->UtilityDepends.end())
  471. {
  472. const char* uname = ui->second.c_str();
  473. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  474. << uname << "\", \""
  475. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  476. << uname << ".vcproj" << "\", \"{"
  477. << this->GetGUID(uname) << "}\"\n"
  478. << "EndProject\n";
  479. }
  480. }
  481. // Write a dsp file into the SLN file,
  482. // Note, that dependencies from executables to
  483. // the libraries it uses are also done here
  484. void
  485. cmGlobalVisualStudio7Generator
  486. ::WriteProjectDepends(std::ostream& fout,
  487. const char* dspname,
  488. const char*, cmTarget& target)
  489. {
  490. int depcount = 0;
  491. std::string dspguid = this->GetGUID(dspname);
  492. VSDependSet const& depends = this->VSTargetDepends[&target];
  493. for(VSDependSet::const_iterator di = depends.begin();
  494. di != depends.end(); ++di)
  495. {
  496. const char* name = di->c_str();
  497. std::string guid = this->GetGUID(name);
  498. if(guid.size() == 0)
  499. {
  500. std::string m = "Target: ";
  501. m += target.GetName();
  502. m += " depends on unknown target: ";
  503. m += name;
  504. cmSystemTools::Error(m.c_str());
  505. }
  506. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  507. depcount++;
  508. }
  509. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  510. if(ui != this->UtilityDepends.end())
  511. {
  512. const char* uname = ui->second.c_str();
  513. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  514. }
  515. }
  516. // Write a dsp file into the SLN file, Note, that dependencies from
  517. // executables to the libraries it uses are also done here
  518. void cmGlobalVisualStudio7Generator
  519. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  520. bool partOfDefaultBuild,
  521. const char* platformMapping)
  522. {
  523. std::string guid = this->GetGUID(name);
  524. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  525. i != this->Configurations.end(); ++i)
  526. {
  527. fout << "\t\t{" << guid << "}." << *i
  528. << ".ActiveCfg = " << *i << "|"
  529. << (platformMapping ? platformMapping : "Win32") << "\n";
  530. if(partOfDefaultBuild)
  531. {
  532. fout << "\t\t{" << guid << "}." << *i
  533. << ".Build.0 = " << *i << "|"
  534. << (platformMapping ? platformMapping : "Win32") << "\n";
  535. }
  536. }
  537. }
  538. // Write a dsp file into the SLN file,
  539. // Note, that dependencies from executables to
  540. // the libraries it uses are also done here
  541. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  542. const char* name,
  543. const char* location,
  544. const char* typeGuid,
  545. const std::set<cmStdString>&)
  546. {
  547. std::string d = cmSystemTools::ConvertToOutputPath(location);
  548. fout << "Project("
  549. << "\"{"
  550. << (typeGuid ? typeGuid : "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942")
  551. << "}\") = \""
  552. << name << "\", \""
  553. << this->ConvertToSolutionPath(location) << "\", \"{"
  554. << this->GetGUID(name)
  555. << "}\"\n";
  556. fout << "EndProject\n";
  557. }
  558. // Standard end of dsw file
  559. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  560. {
  561. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  562. << "\tEndGlobalSection\n"
  563. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  564. << "\tEndGlobalSection\n"
  565. << "EndGlobal\n";
  566. }
  567. // ouput standard header for dsw file
  568. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  569. {
  570. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  571. }
  572. //----------------------------------------------------------------------------
  573. std::string
  574. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget* target)
  575. {
  576. std::string pname = target->GetName();
  577. pname += "_UTILITY";
  578. std::string fname = target->GetMakefile()->GetStartOutputDirectory();
  579. fname += "/";
  580. fname += pname;
  581. fname += ".vcproj";
  582. cmGeneratedFileStream fout(fname.c_str());
  583. fout.SetCopyIfDifferent(true);
  584. this->CreateGUID(pname.c_str());
  585. std::string guid = this->GetGUID(pname.c_str());
  586. fout <<
  587. "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  588. "<VisualStudioProject\n"
  589. "\tProjectType=\"Visual C++\"\n"
  590. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  591. "\tName=\"" << pname << "\"\n"
  592. "\tProjectGUID=\"{" << guid << "}\"\n"
  593. "\tKeyword=\"Win32Proj\">\n"
  594. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  595. "\t<Configurations>\n"
  596. ;
  597. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  598. i != this->Configurations.end(); ++i)
  599. {
  600. fout <<
  601. "\t\t<Configuration\n"
  602. "\t\t\tName=\"" << *i << "|Win32\"\n"
  603. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  604. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  605. "\t\t\tConfigurationType=\"10\"\n"
  606. "\t\t\tUseOfMFC=\"0\"\n"
  607. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  608. "\t\t\tCharacterSet=\"2\">\n"
  609. "\t\t</Configuration>\n"
  610. ;
  611. }
  612. fout <<
  613. "\t</Configurations>\n"
  614. "\t<Files></Files>\n"
  615. "\t<Globals></Globals>\n"
  616. "</VisualStudioProject>\n"
  617. ;
  618. if(fout.Close())
  619. {
  620. this->FileReplacedDuringGenerate(fname);
  621. }
  622. return pname;
  623. }
  624. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  625. {
  626. std::string guidStoreName = name;
  627. guidStoreName += "_GUID_CMAKE";
  628. const char* storedGUID =
  629. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  630. if(storedGUID)
  631. {
  632. return std::string(storedGUID);
  633. }
  634. cmSystemTools::Error("Unknown Target referenced : ",
  635. name);
  636. return "";
  637. }
  638. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  639. {
  640. std::string guidStoreName = name;
  641. guidStoreName += "_GUID_CMAKE";
  642. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  643. {
  644. return;
  645. }
  646. std::string ret;
  647. UUID uid;
  648. unsigned char *uidstr;
  649. UuidCreate(&uid);
  650. UuidToString(&uid,&uidstr);
  651. ret = reinterpret_cast<char*>(uidstr);
  652. RpcStringFree(&uidstr);
  653. ret = cmSystemTools::UpperCase(ret);
  654. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  655. ret.c_str(), "Stored GUID",
  656. cmCacheManager::INTERNAL);
  657. }
  658. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  659. {
  660. return &this->Configurations;
  661. };
  662. //----------------------------------------------------------------------------
  663. void cmGlobalVisualStudio7Generator
  664. ::GetDocumentation(cmDocumentationEntry& entry) const
  665. {
  666. entry.Name = this->GetName();
  667. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  668. entry.Full = "";
  669. }
  670. //----------------------------------------------------------------------------
  671. void
  672. cmGlobalVisualStudio7Generator
  673. ::AppendDirectoryForConfig(const char* prefix,
  674. const char* config,
  675. const char* suffix,
  676. std::string& dir)
  677. {
  678. if(config)
  679. {
  680. dir += prefix;
  681. dir += config;
  682. dir += suffix;
  683. }
  684. }
  685. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  686. cmTarget* target)
  687. {
  688. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  689. {
  690. return false;
  691. }
  692. // if it is a utilitiy target then only make it part of the
  693. // default build if another target depends on it
  694. int type = target->GetType();
  695. if (type == cmTarget::GLOBAL_TARGET)
  696. {
  697. return false;
  698. }
  699. if(type == cmTarget::UTILITY)
  700. {
  701. return this->IsDependedOn(project, target);
  702. }
  703. // default is to be part of the build
  704. return true;
  705. }
  706. //----------------------------------------------------------------------------
  707. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  708. {
  709. // Precompiled header and related options. Note that the
  710. // UsePrecompiledHeader entries are marked as "Continue" so that the
  711. // corresponding PrecompiledHeaderThrough entry can be found.
  712. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  713. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  714. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  715. cmVS7FlagTable::UserValueRequired},
  716. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  717. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  718. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  719. cmVS7FlagTable::UserValueRequired},
  720. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "TRUE", 0},
  721. // Exception handling mode. If no entries match, it will be FALSE.
  722. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  723. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  724. // The EHa option does not have an IDE setting. Let it go to false,
  725. // and have EHa passed on the command line by leaving out the table
  726. // entry.
  727. {0,0,0,0,0}
  728. };
  729. cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  730. {
  731. return cmVS7ExtraFlagTable;
  732. }