cmGlobalVisualStudio7Generator.cxx 31 KB

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