cmGlobalVisualStudio7Generator.cxx 34 KB

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