cmGlobalVisualStudio7Generator.cxx 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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 *
  259. cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmLocalGenerator* parent,
  260. cmState::Snapshot snapshot)
  261. {
  262. cmLocalVisualStudio7Generator *lg =
  263. new cmLocalVisualStudio7Generator(this, parent, snapshot);
  264. return lg;
  265. }
  266. //----------------------------------------------------------------------------
  267. std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
  268. {
  269. if(!this->GeneratorPlatform.empty())
  270. {
  271. return this->GeneratorPlatform;
  272. }
  273. return this->DefaultPlatformName;
  274. }
  275. //----------------------------------------------------------------------------
  276. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  277. cmMakefile* mf)
  278. {
  279. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  280. this->GetIntelProjectVersion());
  281. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  282. }
  283. //----------------------------------------------------------------------------
  284. bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
  285. cmMakefile* mf)
  286. {
  287. if(this->GetPlatformName() == "x64")
  288. {
  289. mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
  290. }
  291. else if(this->GetPlatformName() == "Itanium")
  292. {
  293. mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
  294. }
  295. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
  296. return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
  297. }
  298. void cmGlobalVisualStudio7Generator::Generate()
  299. {
  300. // first do the superclass method
  301. this->cmGlobalVisualStudioGenerator::Generate();
  302. // Now write out the DSW
  303. this->OutputSLNFile();
  304. // If any solution or project files changed during the generation,
  305. // tell Visual Studio to reload them...
  306. if(!cmSystemTools::GetErrorOccuredFlag())
  307. {
  308. this->CallVisualStudioMacro(MacroReload);
  309. }
  310. if (!this->CMakeInstance->GetIsInTryCompile() &&
  311. this->GetName() == "Visual Studio 7")
  312. {
  313. const char* cmakeWarnVS70 =
  314. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS70");
  315. if (!cmakeWarnVS70 || !cmSystemTools::IsOff(cmakeWarnVS70))
  316. {
  317. this->CMakeInstance->IssueMessage(
  318. cmake::WARNING,
  319. "The \"Visual Studio 7\" generator is deprecated "
  320. "and will be removed in a future version of CMake."
  321. "\n"
  322. "Add CMAKE_WARN_VS70=OFF to the cache to disable this warning."
  323. );
  324. }
  325. }
  326. }
  327. void cmGlobalVisualStudio7Generator
  328. ::OutputSLNFile(cmLocalGenerator* root,
  329. std::vector<cmLocalGenerator*>& generators)
  330. {
  331. if(generators.size() == 0)
  332. {
  333. return;
  334. }
  335. this->CurrentProject = root->GetMakefile()->GetProjectName();
  336. std::string fname = root->GetMakefile()->GetCurrentBinaryDirectory();
  337. fname += "/";
  338. fname += root->GetMakefile()->GetProjectName();
  339. fname += ".sln";
  340. cmGeneratedFileStream fout(fname.c_str());
  341. fout.SetCopyIfDifferent(true);
  342. if(!fout)
  343. {
  344. return;
  345. }
  346. this->WriteSLNFile(fout, root, generators);
  347. if (fout.Close())
  348. {
  349. this->FileReplacedDuringGenerate(fname);
  350. }
  351. }
  352. // output the SLN file
  353. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  354. {
  355. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  356. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  357. {
  358. this->OutputSLNFile(it->second[0], it->second);
  359. }
  360. }
  361. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  362. std::ostream& fout,
  363. std::vector<std::string> const& configs,
  364. OrderedTargetDependSet const& projectTargets)
  365. {
  366. // loop over again and write out configurations for each target
  367. // in the solution
  368. for(OrderedTargetDependSet::const_iterator tt =
  369. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  370. {
  371. cmTarget const* target = (*tt)->Target;
  372. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  373. {
  374. continue;
  375. }
  376. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  377. if(expath)
  378. {
  379. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  380. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  381. this->WriteProjectConfigurations(
  382. fout, target->GetName().c_str(), target->GetType(),
  383. configs, allConfigurations, mapping ? mapping : "");
  384. }
  385. else
  386. {
  387. const std::set<std::string>& configsPartOfDefaultBuild =
  388. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  389. const char *vcprojName =
  390. target->GetProperty("GENERATOR_FILE_NAME");
  391. if (vcprojName)
  392. {
  393. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  394. configs, configsPartOfDefaultBuild);
  395. }
  396. }
  397. }
  398. }
  399. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  400. std::ostream& fout,
  401. cmLocalGenerator* root,
  402. OrderedTargetDependSet const& projectTargets)
  403. {
  404. VisualStudioFolders.clear();
  405. for(OrderedTargetDependSet::const_iterator tt =
  406. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  407. {
  408. cmTarget const* target = (*tt)->Target;
  409. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  410. {
  411. continue;
  412. }
  413. bool written = false;
  414. // handle external vc project files
  415. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  416. if(expath)
  417. {
  418. std::string project = target->GetName();
  419. std::string location = expath;
  420. this->WriteExternalProject(fout,
  421. project.c_str(),
  422. location.c_str(),
  423. target->GetProperty("VS_PROJECT_TYPE"),
  424. target->GetUtilities());
  425. written = true;
  426. }
  427. else
  428. {
  429. const char *vcprojName =
  430. target->GetProperty("GENERATOR_FILE_NAME");
  431. if(vcprojName)
  432. {
  433. cmMakefile* tmf = target->GetMakefile();
  434. std::string dir = tmf->GetCurrentBinaryDirectory();
  435. dir = root->Convert(dir.c_str(),
  436. cmLocalGenerator::START_OUTPUT);
  437. if(dir == ".")
  438. {
  439. dir = ""; // msbuild cannot handle ".\" prefix
  440. }
  441. this->WriteProject(fout, vcprojName, dir.c_str(),
  442. *target);
  443. written = true;
  444. }
  445. }
  446. // Create "solution folder" information from FOLDER target property
  447. //
  448. if (written && this->UseFolderProperty())
  449. {
  450. const char *targetFolder = target->GetProperty("FOLDER");
  451. if (targetFolder)
  452. {
  453. std::vector<cmsys::String> tokens =
  454. cmSystemTools::SplitString(targetFolder, '/', false);
  455. std::string cumulativePath = "";
  456. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  457. iter != tokens.end(); ++iter)
  458. {
  459. if(!iter->size())
  460. {
  461. continue;
  462. }
  463. if (cumulativePath.empty())
  464. {
  465. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  466. }
  467. else
  468. {
  469. VisualStudioFolders[cumulativePath].insert(
  470. cumulativePath + "/" + *iter);
  471. cumulativePath = cumulativePath + "/" + *iter;
  472. }
  473. }
  474. if (!cumulativePath.empty())
  475. {
  476. VisualStudioFolders[cumulativePath].insert(target->GetName());
  477. }
  478. }
  479. }
  480. }
  481. }
  482. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  483. std::ostream& fout,
  484. OrderedTargetDependSet const& projectTargets
  485. )
  486. {
  487. for(OrderedTargetDependSet::const_iterator tt =
  488. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  489. {
  490. cmTarget const* target = (*tt)->Target;
  491. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  492. {
  493. continue;
  494. }
  495. cmMakefile* mf = target->GetMakefile();
  496. const char *vcprojName =
  497. target->GetProperty("GENERATOR_FILE_NAME");
  498. if (vcprojName)
  499. {
  500. std::string dir = mf->GetCurrentSourceDirectory();
  501. this->WriteProjectDepends(fout, vcprojName,
  502. dir.c_str(), *target);
  503. }
  504. }
  505. }
  506. //----------------------------------------------------------------------------
  507. // Write a SLN file to the stream
  508. void cmGlobalVisualStudio7Generator
  509. ::WriteSLNFile(std::ostream& fout,
  510. cmLocalGenerator* root,
  511. std::vector<cmLocalGenerator*>& generators)
  512. {
  513. std::vector<std::string> configs;
  514. root->GetMakefile()->GetConfigurations(configs);
  515. // Write out the header for a SLN file
  516. this->WriteSLNHeader(fout);
  517. // Collect all targets under this root generator and the transitive
  518. // closure of their dependencies.
  519. TargetDependSet projectTargets;
  520. TargetDependSet originalTargets;
  521. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  522. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  523. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  524. bool useFolderProperty = this->UseFolderProperty();
  525. if (useFolderProperty)
  526. {
  527. this->WriteFolders(fout);
  528. }
  529. // Write out the configurations information for the solution
  530. fout << "Global\n"
  531. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  532. int c = 0;
  533. for(std::vector<std::string>::iterator i = configs.begin();
  534. i != configs.end(); ++i)
  535. {
  536. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  537. c++;
  538. }
  539. fout << "\tEndGlobalSection\n";
  540. // Write out project(target) depends
  541. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  542. this->WriteTargetDepends(fout, orderedProjectTargets);
  543. fout << "\tEndGlobalSection\n";
  544. if (useFolderProperty)
  545. {
  546. // Write out project folders
  547. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  548. this->WriteFoldersContent(fout);
  549. fout << "\tEndGlobalSection\n";
  550. }
  551. // Write out the configurations for all the targets in the project
  552. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  553. this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
  554. fout << "\tEndGlobalSection\n";
  555. // Write out global sections
  556. this->WriteSLNGlobalSections(fout, root);
  557. // Write the footer for the SLN file
  558. this->WriteSLNFooter(fout);
  559. }
  560. //----------------------------------------------------------------------------
  561. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  562. {
  563. const char *prefix = "CMAKE_FOLDER_GUID_";
  564. const std::string::size_type skip_prefix = strlen(prefix);
  565. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  566. for(std::map<std::string,std::set<std::string> >::iterator iter =
  567. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  568. {
  569. std::string fullName = iter->first;
  570. std::string guid = this->GetGUID(fullName.c_str());
  571. cmSystemTools::ReplaceString(fullName, "/", "\\");
  572. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  573. {
  574. fullName = fullName.substr(skip_prefix);
  575. }
  576. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  577. fout << "Project(\"{" <<
  578. guidProjectTypeFolder << "}\") = \"" <<
  579. nameOnly << "\", \"" <<
  580. fullName << "\", \"{" <<
  581. guid <<
  582. "}\"\nEndProject\n";
  583. }
  584. }
  585. //----------------------------------------------------------------------------
  586. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  587. {
  588. for(std::map<std::string,std::set<std::string> >::iterator iter =
  589. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  590. {
  591. std::string key(iter->first);
  592. std::string guidParent(this->GetGUID(key.c_str()));
  593. for(std::set<std::string>::iterator it = iter->second.begin();
  594. it != iter->second.end(); ++it)
  595. {
  596. std::string value(*it);
  597. std::string guid(this->GetGUID(value.c_str()));
  598. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  599. }
  600. }
  601. }
  602. //----------------------------------------------------------------------------
  603. std::string
  604. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  605. {
  606. // Convert to backslashes. Do not use ConvertToOutputPath because
  607. // we will add quoting ourselves, and we know these projects always
  608. // use windows slashes.
  609. std::string d = path;
  610. std::string::size_type pos = 0;
  611. while((pos = d.find('/', pos)) != d.npos)
  612. {
  613. d[pos++] = '\\';
  614. }
  615. return d;
  616. }
  617. // Write a dsp file into the SLN file,
  618. // Note, that dependencies from executables to
  619. // the libraries it uses are also done here
  620. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  621. const std::string& dspname,
  622. const char* dir, cmTarget 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*, cmTarget 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.size() == 0)
  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, cmTarget::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 cmPropertyMap& props = root->GetMakefile()->GetProperties();
  737. for(cmPropertyMap::const_iterator itProp = props.begin();
  738. itProp != props.end(); ++itProp)
  739. {
  740. if(itProp->first.find("VS_GLOBAL_SECTION_") == 0)
  741. {
  742. std::string sectionType;
  743. std::string name = itProp->first.substr(18);
  744. if(name.find("PRE_") == 0)
  745. {
  746. name = name.substr(4);
  747. sectionType = "preSolution";
  748. }
  749. else if(name.find("POST_") == 0)
  750. {
  751. name = name.substr(5);
  752. sectionType = "postSolution";
  753. }
  754. else
  755. continue;
  756. if(!name.empty())
  757. {
  758. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  759. extensibilityGlobalsOverridden = true;
  760. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  761. extensibilityAddInsOverridden = true;
  762. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  763. std::vector<std::string> keyValuePairs;
  764. cmSystemTools::ExpandListArgument(itProp->second.GetValue(),
  765. keyValuePairs);
  766. for(std::vector<std::string>::const_iterator itPair =
  767. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  768. {
  769. const std::string::size_type posEqual = itPair->find('=');
  770. if(posEqual != std::string::npos)
  771. {
  772. const std::string key =
  773. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  774. const std::string value =
  775. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  776. fout << "\t\t" << key << " = " << value << "\n";
  777. }
  778. }
  779. fout << "\tEndGlobalSection\n";
  780. }
  781. }
  782. }
  783. if(!extensibilityGlobalsOverridden)
  784. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  785. << "\tEndGlobalSection\n";
  786. if(!extensibilityAddInsOverridden)
  787. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  788. << "\tEndGlobalSection\n";
  789. }
  790. // Standard end of dsw file
  791. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  792. {
  793. fout << "EndGlobal\n";
  794. }
  795. // ouput standard header for dsw file
  796. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  797. {
  798. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  799. }
  800. //----------------------------------------------------------------------------
  801. std::string
  802. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget const* target)
  803. {
  804. std::vector<std::string> configs;
  805. target->GetMakefile()->GetConfigurations(configs);
  806. std::string pname = target->GetName();
  807. pname += "_UTILITY";
  808. std::string fname = target->GetMakefile()->GetCurrentBinaryDirectory();
  809. fname += "/";
  810. fname += pname;
  811. fname += ".vcproj";
  812. cmGeneratedFileStream fout(fname.c_str());
  813. fout.SetCopyIfDifferent(true);
  814. std::string guid = this->GetGUID(pname.c_str());
  815. fout <<
  816. "<?xml version=\"1.0\" encoding = \""
  817. << this->Encoding() << "\"?>\n"
  818. "<VisualStudioProject\n"
  819. "\tProjectType=\"Visual C++\"\n"
  820. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  821. "\tName=\"" << pname << "\"\n"
  822. "\tProjectGUID=\"{" << guid << "}\"\n"
  823. "\tKeyword=\"Win32Proj\">\n"
  824. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  825. "\t<Configurations>\n"
  826. ;
  827. for(std::vector<std::string>::iterator i = configs.begin();
  828. i != configs.end(); ++i)
  829. {
  830. fout <<
  831. "\t\t<Configuration\n"
  832. "\t\t\tName=\"" << *i << "|Win32\"\n"
  833. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  834. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  835. "\t\t\tConfigurationType=\"10\"\n"
  836. "\t\t\tUseOfMFC=\"0\"\n"
  837. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  838. "\t\t\tCharacterSet=\"2\">\n"
  839. "\t\t</Configuration>\n"
  840. ;
  841. }
  842. fout <<
  843. "\t</Configurations>\n"
  844. "\t<Files></Files>\n"
  845. "\t<Globals></Globals>\n"
  846. "</VisualStudioProject>\n"
  847. ;
  848. if(fout.Close())
  849. {
  850. this->FileReplacedDuringGenerate(fname);
  851. }
  852. return pname;
  853. }
  854. //----------------------------------------------------------------------------
  855. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  856. {
  857. std::string const& guidStoreName = name + "_GUID_CMAKE";
  858. if (const char* storedGUID =
  859. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  860. {
  861. return std::string(storedGUID);
  862. }
  863. // Compute a GUID that is deterministic but unique to the build tree.
  864. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  865. input += "|";
  866. input += name;
  867. cmUuid uuidGenerator;
  868. std::vector<unsigned char> uuidNamespace;
  869. uuidGenerator.StringToBinary(
  870. "ee30c4be-5192-4fb0-b335-722a2dffe760", uuidNamespace);
  871. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  872. return cmSystemTools::UpperCase(guid);
  873. }
  874. //----------------------------------------------------------------------------
  875. void cmGlobalVisualStudio7Generator
  876. ::GetDocumentation(cmDocumentationEntry& entry)
  877. {
  878. entry.Name = cmGlobalVisualStudio7Generator::GetActualName();
  879. entry.Brief = "Deprecated. Generates Visual Studio .NET 2002 project files.";
  880. }
  881. //----------------------------------------------------------------------------
  882. void
  883. cmGlobalVisualStudio7Generator
  884. ::AppendDirectoryForConfig(const std::string& prefix,
  885. const std::string& config,
  886. const std::string& suffix,
  887. std::string& dir)
  888. {
  889. if(!config.empty())
  890. {
  891. dir += prefix;
  892. dir += config;
  893. dir += suffix;
  894. }
  895. }
  896. std::set<std::string>
  897. cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  898. std::vector<std::string> const& configs,
  899. OrderedTargetDependSet const& projectTargets, cmTarget const* target)
  900. {
  901. std::set<std::string> activeConfigs;
  902. // if it is a utilitiy target then only make it part of the
  903. // default build if another target depends on it
  904. int type = target->GetType();
  905. if (type == cmTarget::GLOBAL_TARGET)
  906. {
  907. // check if INSTALL target is part of default build
  908. if(target->GetName() == "INSTALL")
  909. {
  910. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  911. for(std::vector<std::string>::const_iterator i = configs.begin();
  912. i != configs.end(); ++i)
  913. {
  914. const char* propertyValue = target->GetMakefile()
  915. ->GetDefinition("CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  916. cmGeneratorExpression ge;
  917. cmsys::auto_ptr<cmCompiledGeneratorExpression>
  918. cge = ge.Parse(propertyValue);
  919. if(cmSystemTools::IsOn(cge->Evaluate(target->GetMakefile(), *i)))
  920. {
  921. activeConfigs.insert(*i);
  922. }
  923. }
  924. }
  925. return activeConfigs;
  926. }
  927. if(type == cmTarget::UTILITY && !this->IsDependedOn(projectTargets, target))
  928. {
  929. return activeConfigs;
  930. }
  931. cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
  932. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  933. for(std::vector<std::string>::const_iterator i = configs.begin();
  934. i != configs.end(); ++i)
  935. {
  936. const char* propertyValue =
  937. gt->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  938. if(cmSystemTools::IsOff(propertyValue))
  939. {
  940. activeConfigs.insert(*i);
  941. }
  942. }
  943. return activeConfigs;
  944. }
  945. bool
  946. cmGlobalVisualStudio7Generator
  947. ::IsDependedOn(OrderedTargetDependSet const& projectTargets,
  948. cmTarget const* targetIn)
  949. {
  950. cmGeneratorTarget* gtIn = this->GetGeneratorTarget(targetIn);
  951. for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  952. l != projectTargets.end(); ++l)
  953. {
  954. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  955. if(tgtdeps.count(gtIn))
  956. {
  957. return true;
  958. }
  959. }
  960. return false;
  961. }
  962. std::string cmGlobalVisualStudio7Generator::Encoding()
  963. {
  964. std::ostringstream encoding;
  965. #ifdef CMAKE_ENCODING_UTF8
  966. encoding << "UTF-8";
  967. #else
  968. encoding << "Windows-1252";
  969. #endif
  970. return encoding.str();
  971. }