cmGlobalVisualStudio7Generator.cxx 30 KB

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