cmGlobalVisualStudio7Generator.cxx 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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->CMakeInstance->GetIsInTryCompile() &&
  310. this->GetName() == "Visual Studio 7")
  311. {
  312. const char* cmakeWarnVS70 =
  313. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS70");
  314. if (!cmakeWarnVS70 || !cmSystemTools::IsOff(cmakeWarnVS70))
  315. {
  316. this->CMakeInstance->IssueMessage(
  317. cmake::WARNING,
  318. "The \"Visual Studio 7\" generator is deprecated "
  319. "and will be removed in a future version of CMake."
  320. "\n"
  321. "Add CMAKE_WARN_VS70=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. // Write a SLN file to the stream
  507. void cmGlobalVisualStudio7Generator
  508. ::WriteSLNFile(std::ostream& fout,
  509. cmLocalGenerator* root,
  510. std::vector<cmLocalGenerator*>& generators)
  511. {
  512. std::vector<std::string> configs;
  513. root->GetMakefile()->GetConfigurations(configs);
  514. // Write out the header for a SLN file
  515. this->WriteSLNHeader(fout);
  516. // Collect all targets under this root generator and the transitive
  517. // closure of their dependencies.
  518. TargetDependSet projectTargets;
  519. TargetDependSet originalTargets;
  520. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  521. OrderedTargetDependSet orderedProjectTargets(projectTargets, "ALL_BUILD");
  522. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  523. bool useFolderProperty = this->UseFolderProperty();
  524. if (useFolderProperty)
  525. {
  526. this->WriteFolders(fout);
  527. }
  528. // Write out the configurations information for the solution
  529. fout << "Global\n"
  530. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  531. int c = 0;
  532. for(std::vector<std::string>::iterator i = configs.begin();
  533. i != configs.end(); ++i)
  534. {
  535. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  536. c++;
  537. }
  538. fout << "\tEndGlobalSection\n";
  539. // Write out project(target) depends
  540. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  541. this->WriteTargetDepends(fout, orderedProjectTargets);
  542. fout << "\tEndGlobalSection\n";
  543. if (useFolderProperty)
  544. {
  545. // Write out project folders
  546. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  547. this->WriteFoldersContent(fout);
  548. fout << "\tEndGlobalSection\n";
  549. }
  550. // Write out the configurations for all the targets in the project
  551. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  552. this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
  553. fout << "\tEndGlobalSection\n";
  554. // Write out global sections
  555. this->WriteSLNGlobalSections(fout, root);
  556. // Write the footer for the SLN file
  557. this->WriteSLNFooter(fout);
  558. }
  559. //----------------------------------------------------------------------------
  560. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  561. {
  562. const char *prefix = "CMAKE_FOLDER_GUID_";
  563. const std::string::size_type skip_prefix = strlen(prefix);
  564. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  565. for(std::map<std::string,std::set<std::string> >::iterator iter =
  566. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  567. {
  568. std::string fullName = iter->first;
  569. std::string guid = this->GetGUID(fullName.c_str());
  570. cmSystemTools::ReplaceString(fullName, "/", "\\");
  571. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  572. {
  573. fullName = fullName.substr(skip_prefix);
  574. }
  575. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  576. fout << "Project(\"{" <<
  577. guidProjectTypeFolder << "}\") = \"" <<
  578. nameOnly << "\", \"" <<
  579. fullName << "\", \"{" <<
  580. guid <<
  581. "}\"\nEndProject\n";
  582. }
  583. }
  584. //----------------------------------------------------------------------------
  585. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  586. {
  587. for(std::map<std::string,std::set<std::string> >::iterator iter =
  588. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  589. {
  590. std::string key(iter->first);
  591. std::string guidParent(this->GetGUID(key.c_str()));
  592. for(std::set<std::string>::iterator it = iter->second.begin();
  593. it != iter->second.end(); ++it)
  594. {
  595. std::string value(*it);
  596. std::string guid(this->GetGUID(value.c_str()));
  597. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  598. }
  599. }
  600. }
  601. //----------------------------------------------------------------------------
  602. std::string
  603. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  604. {
  605. // Convert to backslashes. Do not use ConvertToOutputPath because
  606. // we will add quoting ourselves, and we know these projects always
  607. // use windows slashes.
  608. std::string d = path;
  609. std::string::size_type pos = 0;
  610. while((pos = d.find('/', pos)) != d.npos)
  611. {
  612. d[pos++] = '\\';
  613. }
  614. return d;
  615. }
  616. // Write a dsp file into the SLN file,
  617. // Note, that dependencies from executables to
  618. // the libraries it uses are also done here
  619. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  620. const std::string& dspname,
  621. const char* dir,
  622. cmGeneratorTarget const* target)
  623. {
  624. // check to see if this is a fortran build
  625. const char* ext = ".vcproj";
  626. const char* project =
  627. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  628. if(this->TargetIsFortranOnly(target))
  629. {
  630. ext = ".vfproj";
  631. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  632. }
  633. fout << project
  634. << dspname << "\", \""
  635. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  636. << dspname << ext << "\", \"{"
  637. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  638. UtilityDependsMap::iterator ui = this->UtilityDepends.find(target);
  639. if(ui != this->UtilityDepends.end())
  640. {
  641. const char* uname = ui->second.c_str();
  642. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  643. << uname << "\", \""
  644. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  645. << uname << ".vcproj" << "\", \"{"
  646. << this->GetGUID(uname) << "}\"\n"
  647. << "EndProject\n";
  648. }
  649. }
  650. // Write a dsp file into the SLN file,
  651. // Note, that dependencies from executables to
  652. // the libraries it uses are also done here
  653. void
  654. cmGlobalVisualStudio7Generator
  655. ::WriteProjectDepends(std::ostream& fout,
  656. const std::string& dspname,
  657. const char*, cmGeneratorTarget const* target)
  658. {
  659. int depcount = 0;
  660. std::string dspguid = this->GetGUID(dspname);
  661. VSDependSet const& depends = this->VSTargetDepends[target];
  662. for(VSDependSet::const_iterator di = depends.begin();
  663. di != depends.end(); ++di)
  664. {
  665. const char* name = di->c_str();
  666. std::string guid = this->GetGUID(name);
  667. if(guid.empty())
  668. {
  669. std::string m = "Target: ";
  670. m += target->GetName();
  671. m += " depends on unknown target: ";
  672. m += name;
  673. cmSystemTools::Error(m.c_str());
  674. }
  675. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  676. depcount++;
  677. }
  678. UtilityDependsMap::iterator ui = this->UtilityDepends.find(target);
  679. if(ui != this->UtilityDepends.end())
  680. {
  681. const char* uname = ui->second.c_str();
  682. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  683. }
  684. }
  685. // Write a dsp file into the SLN file, Note, that dependencies from
  686. // executables to the libraries it uses are also done here
  687. void cmGlobalVisualStudio7Generator
  688. ::WriteProjectConfigurations(
  689. std::ostream& fout, const std::string& name, cmState::TargetType,
  690. std::vector<std::string> const& configs,
  691. const std::set<std::string>& configsPartOfDefaultBuild,
  692. const std::string& platformMapping)
  693. {
  694. const std::string& platformName =
  695. !platformMapping.empty() ? platformMapping : this->GetPlatformName();
  696. std::string guid = this->GetGUID(name);
  697. for(std::vector<std::string>::const_iterator i = configs.begin();
  698. i != configs.end(); ++i)
  699. {
  700. fout << "\t\t{" << guid << "}." << *i
  701. << ".ActiveCfg = " << *i << "|" << platformName << "\n";
  702. std::set<std::string>::const_iterator
  703. ci = configsPartOfDefaultBuild.find(*i);
  704. if(!(ci == configsPartOfDefaultBuild.end()))
  705. {
  706. fout << "\t\t{" << guid << "}." << *i
  707. << ".Build.0 = " << *i << "|" << platformName << "\n";
  708. }
  709. }
  710. }
  711. // Write a dsp file into the SLN file,
  712. // Note, that dependencies from executables to
  713. // the libraries it uses are also done here
  714. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  715. const std::string& name,
  716. const char* location,
  717. const char* typeGuid,
  718. const std::set<std::string>&)
  719. {
  720. fout << "Project("
  721. << "\"{"
  722. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  723. << "}\") = \""
  724. << name << "\", \""
  725. << this->ConvertToSolutionPath(location) << "\", \"{"
  726. << this->GetGUID(name)
  727. << "}\"\n";
  728. fout << "EndProject\n";
  729. }
  730. void cmGlobalVisualStudio7Generator
  731. ::WriteSLNGlobalSections(std::ostream& fout,
  732. cmLocalGenerator* root)
  733. {
  734. bool extensibilityGlobalsOverridden = false;
  735. bool extensibilityAddInsOverridden = false;
  736. const std::vector<std::string> propKeys =
  737. root->GetMakefile()->GetPropertyKeys();
  738. for(std::vector<std::string>::const_iterator it = propKeys.begin();
  739. it != propKeys.end(); ++it)
  740. {
  741. if(it->find("VS_GLOBAL_SECTION_") == 0)
  742. {
  743. std::string sectionType;
  744. std::string name = it->substr(18);
  745. if(name.find("PRE_") == 0)
  746. {
  747. name = name.substr(4);
  748. sectionType = "preSolution";
  749. }
  750. else if(name.find("POST_") == 0)
  751. {
  752. name = name.substr(5);
  753. sectionType = "postSolution";
  754. }
  755. else
  756. continue;
  757. if(!name.empty())
  758. {
  759. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  760. extensibilityGlobalsOverridden = true;
  761. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  762. extensibilityAddInsOverridden = true;
  763. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  764. std::vector<std::string> keyValuePairs;
  765. cmSystemTools::ExpandListArgument(
  766. root->GetMakefile()->GetProperty(it->c_str()),
  767. keyValuePairs);
  768. for(std::vector<std::string>::const_iterator itPair =
  769. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  770. {
  771. const std::string::size_type posEqual = itPair->find('=');
  772. if(posEqual != std::string::npos)
  773. {
  774. const std::string key =
  775. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  776. const std::string value =
  777. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  778. fout << "\t\t" << key << " = " << value << "\n";
  779. }
  780. }
  781. fout << "\tEndGlobalSection\n";
  782. }
  783. }
  784. }
  785. if(!extensibilityGlobalsOverridden)
  786. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  787. << "\tEndGlobalSection\n";
  788. if(!extensibilityAddInsOverridden)
  789. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  790. << "\tEndGlobalSection\n";
  791. }
  792. // Standard end of dsw file
  793. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  794. {
  795. fout << "EndGlobal\n";
  796. }
  797. // ouput standard header for dsw file
  798. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  799. {
  800. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  801. }
  802. //----------------------------------------------------------------------------
  803. std::string
  804. cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  805. cmGeneratorTarget const* target)
  806. {
  807. std::vector<std::string> configs;
  808. target->Target->GetMakefile()->GetConfigurations(configs);
  809. std::string pname = target->GetName();
  810. pname += "_UTILITY";
  811. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  812. fname += "/";
  813. fname += pname;
  814. fname += ".vcproj";
  815. cmGeneratedFileStream fout(fname.c_str());
  816. fout.SetCopyIfDifferent(true);
  817. std::string guid = this->GetGUID(pname.c_str());
  818. fout <<
  819. "<?xml version=\"1.0\" encoding = \""
  820. << this->Encoding() << "\"?>\n"
  821. "<VisualStudioProject\n"
  822. "\tProjectType=\"Visual C++\"\n"
  823. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  824. "\tName=\"" << pname << "\"\n"
  825. "\tProjectGUID=\"{" << guid << "}\"\n"
  826. "\tKeyword=\"Win32Proj\">\n"
  827. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  828. "\t<Configurations>\n"
  829. ;
  830. for(std::vector<std::string>::iterator i = configs.begin();
  831. i != configs.end(); ++i)
  832. {
  833. fout <<
  834. "\t\t<Configuration\n"
  835. "\t\t\tName=\"" << *i << "|Win32\"\n"
  836. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  837. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  838. "\t\t\tConfigurationType=\"10\"\n"
  839. "\t\t\tUseOfMFC=\"0\"\n"
  840. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  841. "\t\t\tCharacterSet=\"2\">\n"
  842. "\t\t</Configuration>\n"
  843. ;
  844. }
  845. fout <<
  846. "\t</Configurations>\n"
  847. "\t<Files></Files>\n"
  848. "\t<Globals></Globals>\n"
  849. "</VisualStudioProject>\n"
  850. ;
  851. if(fout.Close())
  852. {
  853. this->FileReplacedDuringGenerate(fname);
  854. }
  855. return pname;
  856. }
  857. //----------------------------------------------------------------------------
  858. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  859. {
  860. std::string const& guidStoreName = name + "_GUID_CMAKE";
  861. if (const char* storedGUID =
  862. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  863. {
  864. return std::string(storedGUID);
  865. }
  866. // Compute a GUID that is deterministic but unique to the build tree.
  867. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  868. input += "|";
  869. input += name;
  870. cmUuid uuidGenerator;
  871. std::vector<unsigned char> uuidNamespace;
  872. uuidGenerator.StringToBinary(
  873. "ee30c4be-5192-4fb0-b335-722a2dffe760", uuidNamespace);
  874. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  875. return cmSystemTools::UpperCase(guid);
  876. }
  877. //----------------------------------------------------------------------------
  878. void cmGlobalVisualStudio7Generator
  879. ::GetDocumentation(cmDocumentationEntry& entry)
  880. {
  881. entry.Name = cmGlobalVisualStudio7Generator::GetActualName();
  882. entry.Brief = "Deprecated. Generates Visual Studio .NET 2002 project files.";
  883. }
  884. //----------------------------------------------------------------------------
  885. void
  886. cmGlobalVisualStudio7Generator
  887. ::AppendDirectoryForConfig(const std::string& prefix,
  888. const std::string& config,
  889. const std::string& suffix,
  890. std::string& dir)
  891. {
  892. if(!config.empty())
  893. {
  894. dir += prefix;
  895. dir += config;
  896. dir += suffix;
  897. }
  898. }
  899. std::set<std::string>
  900. cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  901. std::vector<std::string> const& configs,
  902. OrderedTargetDependSet const& projectTargets,
  903. cmGeneratorTarget const* target)
  904. {
  905. std::set<std::string> activeConfigs;
  906. // if it is a utilitiy target then only make it part of the
  907. // default build if another target depends on it
  908. int type = target->GetType();
  909. if (type == cmState::GLOBAL_TARGET)
  910. {
  911. // check if INSTALL target is part of default build
  912. if(target->GetName() == "INSTALL")
  913. {
  914. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  915. for(std::vector<std::string>::const_iterator i = configs.begin();
  916. i != configs.end(); ++i)
  917. {
  918. const char* propertyValue = target->Target->GetMakefile()
  919. ->GetDefinition("CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  920. cmGeneratorExpression ge;
  921. cmsys::auto_ptr<cmCompiledGeneratorExpression>
  922. cge = ge.Parse(propertyValue);
  923. if(cmSystemTools::IsOn(cge->Evaluate(target->GetLocalGenerator(),
  924. *i)))
  925. {
  926. activeConfigs.insert(*i);
  927. }
  928. }
  929. }
  930. return activeConfigs;
  931. }
  932. if(type == cmState::UTILITY && !this->IsDependedOn(projectTargets, target))
  933. {
  934. return activeConfigs;
  935. }
  936. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  937. for(std::vector<std::string>::const_iterator i = configs.begin();
  938. i != configs.end(); ++i)
  939. {
  940. const char* propertyValue =
  941. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  942. if(cmSystemTools::IsOff(propertyValue))
  943. {
  944. activeConfigs.insert(*i);
  945. }
  946. }
  947. return activeConfigs;
  948. }
  949. bool
  950. cmGlobalVisualStudio7Generator
  951. ::IsDependedOn(OrderedTargetDependSet const& projectTargets,
  952. cmGeneratorTarget const* gtIn)
  953. {
  954. for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  955. l != projectTargets.end(); ++l)
  956. {
  957. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  958. if(tgtdeps.count(gtIn))
  959. {
  960. return true;
  961. }
  962. }
  963. return false;
  964. }
  965. std::string cmGlobalVisualStudio7Generator::Encoding()
  966. {
  967. std::ostringstream encoding;
  968. #ifdef CMAKE_ENCODING_UTF8
  969. encoding << "UTF-8";
  970. #else
  971. encoding << "Windows-1252";
  972. #endif
  973. return encoding.str();
  974. }