cmGlobalVisualStudio7Generator.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  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 "cmUuid.h"
  17. #include "cmake.h"
  18. #include <cmsys/Encoding.hxx>
  19. //----------------------------------------------------------------------------
  20. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  21. {
  22. // Precompiled header and related options. Note that the
  23. // UsePrecompiledHeader entries are marked as "Continue" so that the
  24. // corresponding PrecompiledHeaderThrough entry can be found.
  25. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  26. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  27. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  28. cmVS7FlagTable::UserValueRequired},
  29. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  30. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  31. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  32. cmVS7FlagTable::UserValueRequired},
  33. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "true", 0},
  34. // Exception handling mode. If no entries match, it will be FALSE.
  35. {"ExceptionHandling", "GX", "enable c++ exceptions", "true", 0},
  36. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "true", 0},
  37. // The EHa option does not have an IDE setting. Let it go to false,
  38. // and have EHa passed on the command line by leaving out the table
  39. // entry.
  40. {0,0,0,0,0}
  41. };
  42. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(cmake *cm,
  43. const std::string& platformName)
  44. : cmGlobalVisualStudioGenerator(cm)
  45. {
  46. this->IntelProjectVersion = 0;
  47. this->DevEnvCommandInitialized = false;
  48. this->MasmEnabled = false;
  49. if (platformName.empty())
  50. {
  51. this->DefaultPlatformName = "Win32";
  52. }
  53. else
  54. {
  55. this->DefaultPlatformName = platformName;
  56. }
  57. this->ExtraFlagTable = cmVS7ExtraFlagTable;
  58. this->Version = VS7;
  59. }
  60. cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
  61. {
  62. free(this->IntelProjectVersion);
  63. }
  64. // Package GUID of Intel Visual Fortran plugin to VS IDE
  65. #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
  66. const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
  67. {
  68. if(!this->IntelProjectVersion)
  69. {
  70. // Compute the version of the Intel plugin to the VS IDE.
  71. // If the key does not exist then use a default guess.
  72. std::string intelVersion;
  73. std::string vskey = this->GetRegistryBase();
  74. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  75. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  76. cmSystemTools::KeyWOW64_32);
  77. unsigned int intelVersionNumber = ~0u;
  78. sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
  79. if(intelVersionNumber >= 11)
  80. {
  81. // Default to latest known project file version.
  82. intelVersion = "11.0";
  83. }
  84. else if(intelVersionNumber == 10)
  85. {
  86. // Version 10.x actually uses 9.10 in project files!
  87. intelVersion = "9.10";
  88. }
  89. else
  90. {
  91. // Version <= 9: use ProductVersion from registry.
  92. }
  93. this->IntelProjectVersion = strdup(intelVersion.c_str());
  94. }
  95. return this->IntelProjectVersion;
  96. }
  97. void cmGlobalVisualStudio7Generator
  98. ::EnableLanguage(std::vector<std::string>const & lang,
  99. cmMakefile *mf, bool optional)
  100. {
  101. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  102. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  103. if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  104. {
  105. mf->AddCacheDefinition(
  106. "CMAKE_CONFIGURATION_TYPES",
  107. "Debug;Release;MinSizeRel;RelWithDebInfo",
  108. "Semicolon separated list of supported configuration types, "
  109. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  110. "anything else will be ignored.",
  111. cmState::STRING);
  112. }
  113. // Create list of configurations requested by user's cache, if any.
  114. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  115. // if this environment variable is set, then copy it to
  116. // a static cache entry. It will be used by
  117. // cmLocalGenerator::ConstructScript, to add an extra PATH
  118. // to all custom commands. This is because the VS IDE
  119. // does not use the environment it is run in, and this allows
  120. // for running commands and using dll's that the IDE environment
  121. // does not know about.
  122. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  123. if(extraPath)
  124. {
  125. mf->AddCacheDefinition
  126. ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  127. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  128. cmState::STATIC);
  129. }
  130. }
  131. //----------------------------------------------------------------------------
  132. void cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf)
  133. {
  134. this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf);
  135. mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND",
  136. this->GetDevEnvCommand().c_str());
  137. }
  138. //----------------------------------------------------------------------------
  139. std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
  140. {
  141. if(!this->DevEnvCommandInitialized)
  142. {
  143. this->DevEnvCommandInitialized = true;
  144. this->DevEnvCommand = this->FindDevEnvCommand();
  145. }
  146. return this->DevEnvCommand;
  147. }
  148. //----------------------------------------------------------------------------
  149. std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
  150. {
  151. std::string vscmd;
  152. std::string vskey = this->GetRegistryBase() + ";InstallDir";
  153. if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  154. cmSystemTools::KeyWOW64_32))
  155. {
  156. cmSystemTools::ConvertToUnixSlashes(vscmd);
  157. vscmd += "/";
  158. }
  159. vscmd += "devenv.com";
  160. return vscmd;
  161. }
  162. //----------------------------------------------------------------------------
  163. const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
  164. const char* location)
  165. {
  166. std::string extension = cmSystemTools::GetFilenameLastExtension(location);
  167. if (extension == ".vbproj")
  168. {
  169. return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
  170. }
  171. else if (extension == ".csproj")
  172. {
  173. return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  174. }
  175. else if (extension == ".fsproj")
  176. {
  177. return "F2A71F9B-5D33-465A-A702-920D77279786";
  178. }
  179. else if (extension == ".vdproj")
  180. {
  181. return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
  182. }
  183. else if (extension == ".dbproj")
  184. {
  185. return "C8D11400-126E-41CD-887F-60BD40844F9E";
  186. }
  187. else if (extension == ".wixproj")
  188. {
  189. return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
  190. }
  191. else if (extension == ".pyproj")
  192. {
  193. return "888888A0-9F3D-457C-B088-3A5042F75D52";
  194. }
  195. return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
  196. }
  197. //----------------------------------------------------------------------------
  198. void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  199. std::vector<std::string>& makeCommand,
  200. const std::string& makeProgram,
  201. const std::string& projectName,
  202. const std::string& /*projectDir*/,
  203. const std::string& targetName,
  204. const std::string& config,
  205. bool /*fast*/, bool /*verbose*/,
  206. std::vector<std::string> const& makeOptions)
  207. {
  208. // Select the caller- or user-preferred make program, else devenv.
  209. std::string makeProgramSelected =
  210. this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
  211. // Ignore the above preference if it is msbuild.
  212. // Assume any other value is either a devenv or
  213. // command-line compatible with devenv.
  214. std::string makeProgramLower = makeProgramSelected;
  215. cmSystemTools::LowerCase(makeProgramLower);
  216. if(makeProgramLower.find("msbuild") != std::string::npos)
  217. {
  218. makeProgramSelected = this->GetDevEnvCommand();
  219. }
  220. makeCommand.push_back(makeProgramSelected);
  221. makeCommand.push_back(std::string(projectName) + ".sln");
  222. std::string realTarget = targetName;
  223. bool clean = false;
  224. if ( realTarget == "clean" )
  225. {
  226. clean = true;
  227. realTarget = "ALL_BUILD";
  228. }
  229. if(clean)
  230. {
  231. makeCommand.push_back("/clean");
  232. }
  233. else
  234. {
  235. makeCommand.push_back("/build");
  236. }
  237. if(!config.empty())
  238. {
  239. makeCommand.push_back(config);
  240. }
  241. else
  242. {
  243. makeCommand.push_back("Debug");
  244. }
  245. makeCommand.push_back("/project");
  246. if (!realTarget.empty())
  247. {
  248. makeCommand.push_back(realTarget);
  249. }
  250. else
  251. {
  252. makeCommand.push_back("ALL_BUILD");
  253. }
  254. makeCommand.insert(makeCommand.end(),
  255. makeOptions.begin(), makeOptions.end());
  256. }
  257. ///! Create a local generator appropriate to this Global Generator
  258. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator(
  259. cmMakefile* mf)
  260. {
  261. cmLocalVisualStudio7Generator *lg =
  262. new cmLocalVisualStudio7Generator(this, mf);
  263. return lg;
  264. }
  265. //----------------------------------------------------------------------------
  266. std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
  267. {
  268. if(!this->GeneratorPlatform.empty())
  269. {
  270. return this->GeneratorPlatform;
  271. }
  272. return this->DefaultPlatformName;
  273. }
  274. //----------------------------------------------------------------------------
  275. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  276. cmMakefile* mf)
  277. {
  278. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  279. this->GetIntelProjectVersion());
  280. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  281. }
  282. //----------------------------------------------------------------------------
  283. bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
  284. cmMakefile* mf)
  285. {
  286. if(this->GetPlatformName() == "x64")
  287. {
  288. mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
  289. }
  290. else if(this->GetPlatformName() == "Itanium")
  291. {
  292. mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
  293. }
  294. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
  295. return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
  296. }
  297. void cmGlobalVisualStudio7Generator::Generate()
  298. {
  299. // first do the superclass method
  300. this->cmGlobalVisualStudioGenerator::Generate();
  301. // Now write out the DSW
  302. this->OutputSLNFile();
  303. // If any solution or project files changed during the generation,
  304. // tell Visual Studio to reload them...
  305. if(!cmSystemTools::GetErrorOccuredFlag())
  306. {
  307. this->CallVisualStudioMacro(MacroReload);
  308. }
  309. if (this->Version == VS71 &&
  310. !this->CMakeInstance->GetIsInTryCompile())
  311. {
  312. const char* cmakeWarnVS71 =
  313. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS71");
  314. if (!cmakeWarnVS71 || !cmSystemTools::IsOff(cmakeWarnVS71))
  315. {
  316. this->CMakeInstance->IssueMessage(
  317. cmake::WARNING,
  318. "The \"Visual Studio 7 .NET 2003\" generator is deprecated "
  319. "and will be removed in a future version of CMake."
  320. "\n"
  321. "Add CMAKE_WARN_VS71=OFF to the cache to disable this warning."
  322. );
  323. }
  324. }
  325. }
  326. void cmGlobalVisualStudio7Generator
  327. ::OutputSLNFile(cmLocalGenerator* root,
  328. std::vector<cmLocalGenerator*>& generators)
  329. {
  330. if(generators.empty())
  331. {
  332. return;
  333. }
  334. this->CurrentProject = root->GetProjectName();
  335. std::string fname = root->GetCurrentBinaryDirectory();
  336. fname += "/";
  337. fname += root->GetProjectName();
  338. fname += ".sln";
  339. cmGeneratedFileStream fout(fname.c_str());
  340. fout.SetCopyIfDifferent(true);
  341. if(!fout)
  342. {
  343. return;
  344. }
  345. this->WriteSLNFile(fout, root, generators);
  346. if (fout.Close())
  347. {
  348. this->FileReplacedDuringGenerate(fname);
  349. }
  350. }
  351. // output the SLN file
  352. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  353. {
  354. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  355. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  356. {
  357. this->OutputSLNFile(it->second[0], it->second);
  358. }
  359. }
  360. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  361. std::ostream& fout,
  362. std::vector<std::string> const& configs,
  363. OrderedTargetDependSet const& projectTargets)
  364. {
  365. // loop over again and write out configurations for each target
  366. // in the solution
  367. for(OrderedTargetDependSet::const_iterator tt =
  368. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  369. {
  370. cmGeneratorTarget const* target = *tt;
  371. if(target->GetType() == cmState::INTERFACE_LIBRARY)
  372. {
  373. continue;
  374. }
  375. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  376. if(expath)
  377. {
  378. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  379. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  380. this->WriteProjectConfigurations(
  381. fout, target->GetName().c_str(), target->GetType(),
  382. configs, allConfigurations, mapping ? mapping : "");
  383. }
  384. else
  385. {
  386. const std::set<std::string>& configsPartOfDefaultBuild =
  387. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  388. const char *vcprojName =
  389. target->GetProperty("GENERATOR_FILE_NAME");
  390. if (vcprojName)
  391. {
  392. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  393. configs, configsPartOfDefaultBuild);
  394. }
  395. }
  396. }
  397. }
  398. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  399. std::ostream& fout,
  400. cmLocalGenerator* root,
  401. OrderedTargetDependSet const& projectTargets)
  402. {
  403. VisualStudioFolders.clear();
  404. for(OrderedTargetDependSet::const_iterator tt =
  405. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  406. {
  407. cmGeneratorTarget const* target = *tt;
  408. if(target->GetType() == cmState::INTERFACE_LIBRARY)
  409. {
  410. continue;
  411. }
  412. bool written = false;
  413. // handle external vc project files
  414. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  415. if(expath)
  416. {
  417. std::string project = target->GetName();
  418. std::string location = expath;
  419. this->WriteExternalProject(fout,
  420. project.c_str(),
  421. location.c_str(),
  422. target->GetProperty("VS_PROJECT_TYPE"),
  423. target->GetUtilities());
  424. written = true;
  425. }
  426. else
  427. {
  428. const char *vcprojName =
  429. target->GetProperty("GENERATOR_FILE_NAME");
  430. if(vcprojName)
  431. {
  432. cmLocalGenerator* lg = target->GetLocalGenerator();
  433. std::string dir = lg->GetCurrentBinaryDirectory();
  434. dir = root->Convert(dir.c_str(),
  435. cmLocalGenerator::START_OUTPUT);
  436. if(dir == ".")
  437. {
  438. dir = ""; // msbuild cannot handle ".\" prefix
  439. }
  440. this->WriteProject(fout, vcprojName, dir.c_str(),
  441. target);
  442. written = true;
  443. }
  444. }
  445. // Create "solution folder" information from FOLDER target property
  446. //
  447. if (written && this->UseFolderProperty())
  448. {
  449. const char *targetFolder = target->GetProperty("FOLDER");
  450. if (targetFolder)
  451. {
  452. std::vector<cmsys::String> tokens =
  453. cmSystemTools::SplitString(targetFolder, '/', false);
  454. std::string cumulativePath = "";
  455. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  456. iter != tokens.end(); ++iter)
  457. {
  458. if(!iter->size())
  459. {
  460. continue;
  461. }
  462. if (cumulativePath.empty())
  463. {
  464. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  465. }
  466. else
  467. {
  468. VisualStudioFolders[cumulativePath].insert(
  469. cumulativePath + "/" + *iter);
  470. cumulativePath = cumulativePath + "/" + *iter;
  471. }
  472. }
  473. if (!cumulativePath.empty())
  474. {
  475. VisualStudioFolders[cumulativePath].insert(target->GetName());
  476. }
  477. }
  478. }
  479. }
  480. }
  481. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  482. std::ostream& fout,
  483. OrderedTargetDependSet const& projectTargets
  484. )
  485. {
  486. for(OrderedTargetDependSet::const_iterator tt =
  487. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  488. {
  489. cmGeneratorTarget const* target = *tt;
  490. if(target->GetType() == cmState::INTERFACE_LIBRARY)
  491. {
  492. continue;
  493. }
  494. const char *vcprojName =
  495. target->GetProperty("GENERATOR_FILE_NAME");
  496. if (vcprojName)
  497. {
  498. std::string dir = target->GetLocalGenerator()
  499. ->GetCurrentSourceDirectory();
  500. this->WriteProjectDepends(fout, vcprojName,
  501. dir.c_str(), target);
  502. }
  503. }
  504. }
  505. //----------------------------------------------------------------------------
  506. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  507. {
  508. const char *prefix = "CMAKE_FOLDER_GUID_";
  509. const std::string::size_type skip_prefix = strlen(prefix);
  510. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  511. for(std::map<std::string,std::set<std::string> >::iterator iter =
  512. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  513. {
  514. std::string fullName = iter->first;
  515. std::string guid = this->GetGUID(fullName.c_str());
  516. cmSystemTools::ReplaceString(fullName, "/", "\\");
  517. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  518. {
  519. fullName = fullName.substr(skip_prefix);
  520. }
  521. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  522. fout << "Project(\"{" <<
  523. guidProjectTypeFolder << "}\") = \"" <<
  524. nameOnly << "\", \"" <<
  525. fullName << "\", \"{" <<
  526. guid <<
  527. "}\"\nEndProject\n";
  528. }
  529. }
  530. //----------------------------------------------------------------------------
  531. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  532. {
  533. for(std::map<std::string,std::set<std::string> >::iterator iter =
  534. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  535. {
  536. std::string key(iter->first);
  537. std::string guidParent(this->GetGUID(key.c_str()));
  538. for(std::set<std::string>::iterator it = iter->second.begin();
  539. it != iter->second.end(); ++it)
  540. {
  541. std::string value(*it);
  542. std::string guid(this->GetGUID(value.c_str()));
  543. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  544. }
  545. }
  546. }
  547. //----------------------------------------------------------------------------
  548. std::string
  549. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  550. {
  551. // Convert to backslashes. Do not use ConvertToOutputPath because
  552. // we will add quoting ourselves, and we know these projects always
  553. // use windows slashes.
  554. std::string d = path;
  555. std::string::size_type pos = 0;
  556. while((pos = d.find('/', pos)) != d.npos)
  557. {
  558. d[pos++] = '\\';
  559. }
  560. return d;
  561. }
  562. void cmGlobalVisualStudio7Generator
  563. ::WriteSLNGlobalSections(std::ostream& fout,
  564. cmLocalGenerator* root)
  565. {
  566. bool extensibilityGlobalsOverridden = false;
  567. bool extensibilityAddInsOverridden = false;
  568. const std::vector<std::string> propKeys =
  569. root->GetMakefile()->GetPropertyKeys();
  570. for(std::vector<std::string>::const_iterator it = propKeys.begin();
  571. it != propKeys.end(); ++it)
  572. {
  573. if(it->find("VS_GLOBAL_SECTION_") == 0)
  574. {
  575. std::string sectionType;
  576. std::string name = it->substr(18);
  577. if(name.find("PRE_") == 0)
  578. {
  579. name = name.substr(4);
  580. sectionType = "preSolution";
  581. }
  582. else if(name.find("POST_") == 0)
  583. {
  584. name = name.substr(5);
  585. sectionType = "postSolution";
  586. }
  587. else
  588. continue;
  589. if(!name.empty())
  590. {
  591. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  592. extensibilityGlobalsOverridden = true;
  593. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  594. extensibilityAddInsOverridden = true;
  595. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  596. std::vector<std::string> keyValuePairs;
  597. cmSystemTools::ExpandListArgument(
  598. root->GetMakefile()->GetProperty(it->c_str()),
  599. keyValuePairs);
  600. for(std::vector<std::string>::const_iterator itPair =
  601. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  602. {
  603. const std::string::size_type posEqual = itPair->find('=');
  604. if(posEqual != std::string::npos)
  605. {
  606. const std::string key =
  607. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  608. const std::string value =
  609. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  610. fout << "\t\t" << key << " = " << value << "\n";
  611. }
  612. }
  613. fout << "\tEndGlobalSection\n";
  614. }
  615. }
  616. }
  617. if(!extensibilityGlobalsOverridden)
  618. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  619. << "\tEndGlobalSection\n";
  620. if(!extensibilityAddInsOverridden)
  621. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  622. << "\tEndGlobalSection\n";
  623. }
  624. // Standard end of dsw file
  625. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  626. {
  627. fout << "EndGlobal\n";
  628. }
  629. //----------------------------------------------------------------------------
  630. std::string
  631. cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  632. cmGeneratorTarget const* target)
  633. {
  634. std::vector<std::string> configs;
  635. target->Target->GetMakefile()->GetConfigurations(configs);
  636. std::string pname = target->GetName();
  637. pname += "_UTILITY";
  638. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  639. fname += "/";
  640. fname += pname;
  641. fname += ".vcproj";
  642. cmGeneratedFileStream fout(fname.c_str());
  643. fout.SetCopyIfDifferent(true);
  644. std::string guid = this->GetGUID(pname.c_str());
  645. fout <<
  646. "<?xml version=\"1.0\" encoding = \""
  647. << this->Encoding() << "\"?>\n"
  648. "<VisualStudioProject\n"
  649. "\tProjectType=\"Visual C++\"\n"
  650. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  651. "\tName=\"" << pname << "\"\n"
  652. "\tProjectGUID=\"{" << guid << "}\"\n"
  653. "\tKeyword=\"Win32Proj\">\n"
  654. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  655. "\t<Configurations>\n"
  656. ;
  657. for(std::vector<std::string>::iterator i = configs.begin();
  658. i != configs.end(); ++i)
  659. {
  660. fout <<
  661. "\t\t<Configuration\n"
  662. "\t\t\tName=\"" << *i << "|Win32\"\n"
  663. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  664. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  665. "\t\t\tConfigurationType=\"10\"\n"
  666. "\t\t\tUseOfMFC=\"0\"\n"
  667. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  668. "\t\t\tCharacterSet=\"2\">\n"
  669. "\t\t</Configuration>\n"
  670. ;
  671. }
  672. fout <<
  673. "\t</Configurations>\n"
  674. "\t<Files></Files>\n"
  675. "\t<Globals></Globals>\n"
  676. "</VisualStudioProject>\n"
  677. ;
  678. if(fout.Close())
  679. {
  680. this->FileReplacedDuringGenerate(fname);
  681. }
  682. return pname;
  683. }
  684. //----------------------------------------------------------------------------
  685. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  686. {
  687. std::string const& guidStoreName = name + "_GUID_CMAKE";
  688. if (const char* storedGUID =
  689. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  690. {
  691. return std::string(storedGUID);
  692. }
  693. // Compute a GUID that is deterministic but unique to the build tree.
  694. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  695. input += "|";
  696. input += name;
  697. cmUuid uuidGenerator;
  698. std::vector<unsigned char> uuidNamespace;
  699. uuidGenerator.StringToBinary(
  700. "ee30c4be-5192-4fb0-b335-722a2dffe760", uuidNamespace);
  701. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  702. return cmSystemTools::UpperCase(guid);
  703. }
  704. //----------------------------------------------------------------------------
  705. void
  706. cmGlobalVisualStudio7Generator
  707. ::AppendDirectoryForConfig(const std::string& prefix,
  708. const std::string& config,
  709. const std::string& suffix,
  710. std::string& dir)
  711. {
  712. if(!config.empty())
  713. {
  714. dir += prefix;
  715. dir += config;
  716. dir += suffix;
  717. }
  718. }
  719. std::set<std::string>
  720. cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  721. std::vector<std::string> const& configs,
  722. OrderedTargetDependSet const& projectTargets,
  723. cmGeneratorTarget const* target)
  724. {
  725. std::set<std::string> activeConfigs;
  726. // if it is a utilitiy target then only make it part of the
  727. // default build if another target depends on it
  728. int type = target->GetType();
  729. if (type == cmState::GLOBAL_TARGET)
  730. {
  731. // check if INSTALL target is part of default build
  732. if(target->GetName() == "INSTALL")
  733. {
  734. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  735. for(std::vector<std::string>::const_iterator i = configs.begin();
  736. i != configs.end(); ++i)
  737. {
  738. const char* propertyValue = target->Target->GetMakefile()
  739. ->GetDefinition("CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  740. cmGeneratorExpression ge;
  741. cmsys::auto_ptr<cmCompiledGeneratorExpression>
  742. cge = ge.Parse(propertyValue);
  743. if(cmSystemTools::IsOn(cge->Evaluate(target->GetLocalGenerator(),
  744. *i)))
  745. {
  746. activeConfigs.insert(*i);
  747. }
  748. }
  749. }
  750. return activeConfigs;
  751. }
  752. if(type == cmState::UTILITY && !this->IsDependedOn(projectTargets, target))
  753. {
  754. return activeConfigs;
  755. }
  756. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  757. for(std::vector<std::string>::const_iterator i = configs.begin();
  758. i != configs.end(); ++i)
  759. {
  760. const char* propertyValue =
  761. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  762. if(cmSystemTools::IsOff(propertyValue))
  763. {
  764. activeConfigs.insert(*i);
  765. }
  766. }
  767. return activeConfigs;
  768. }
  769. bool
  770. cmGlobalVisualStudio7Generator
  771. ::IsDependedOn(OrderedTargetDependSet const& projectTargets,
  772. cmGeneratorTarget const* gtIn)
  773. {
  774. for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  775. l != projectTargets.end(); ++l)
  776. {
  777. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  778. if(tgtdeps.count(gtIn))
  779. {
  780. return true;
  781. }
  782. }
  783. return false;
  784. }
  785. std::string cmGlobalVisualStudio7Generator::Encoding()
  786. {
  787. std::ostringstream encoding;
  788. #ifdef CMAKE_ENCODING_UTF8
  789. encoding << "UTF-8";
  790. #else
  791. encoding << "Windows-1252";
  792. #endif
  793. return encoding.str();
  794. }