cmLocalVisualStudio7Generator.cxx 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  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 "cmGlobalVisualStudio7Generator.h"
  11. #include "cmLocalVisualStudio7Generator.h"
  12. #include "cmXMLParser.h"
  13. #include <cm_expat.h>
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmSourceFile.h"
  17. #include "cmGeneratorTarget.h"
  18. #include "cmCustomCommandGenerator.h"
  19. #include "cmake.h"
  20. #include "cmComputeLinkInformation.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include <cmsys/System.h>
  23. #include <ctype.h> // for isspace
  24. static bool cmLVS6G_IsFAT(const char* dir);
  25. class cmLocalVisualStudio7GeneratorInternals
  26. {
  27. public:
  28. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
  29. LocalGenerator(e) {}
  30. typedef cmComputeLinkInformation::ItemVector ItemVector;
  31. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  32. void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0);
  33. private:
  34. cmLocalVisualStudio7Generator* LocalGenerator;
  35. };
  36. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  37. static void cmConvertToWindowsSlash(std::string& s)
  38. {
  39. std::string::size_type pos = 0;
  40. while((pos = s.find('/', pos)) != std::string::npos)
  41. {
  42. s[pos] = '\\';
  43. pos++;
  44. }
  45. }
  46. //----------------------------------------------------------------------------
  47. cmLocalVisualStudio7Generator
  48. ::cmLocalVisualStudio7Generator(cmGlobalGenerator* gg,
  49. cmLocalGenerator* parent,
  50. cmState::Snapshot snapshot):
  51. cmLocalVisualStudioGenerator(gg, parent, snapshot)
  52. {
  53. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  54. }
  55. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  56. {
  57. delete this->Internal;
  58. }
  59. void cmLocalVisualStudio7Generator::AddHelperCommands()
  60. {
  61. std::set<std::string> lang;
  62. lang.insert("C");
  63. lang.insert("CXX");
  64. lang.insert("RC");
  65. lang.insert("IDL");
  66. lang.insert("DEF");
  67. lang.insert("Fortran");
  68. this->CreateCustomTargetsAndCommands(lang);
  69. // Now create GUIDs for targets
  70. cmTargets &tgts = this->Makefile->GetTargets();
  71. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  72. {
  73. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  74. {
  75. continue;
  76. }
  77. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  78. if(path)
  79. {
  80. this->ReadAndStoreExternalGUID(
  81. l->second.GetName().c_str(), path);
  82. }
  83. }
  84. this->FixGlobalTargets();
  85. }
  86. void cmLocalVisualStudio7Generator::Generate()
  87. {
  88. this->WriteProjectFiles();
  89. this->WriteStampFiles();
  90. }
  91. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  92. {
  93. cmTargets &tgts = this->Makefile->GetTargets();
  94. // Create the regeneration custom rule.
  95. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  96. {
  97. // Create a rule to regenerate the build system when the target
  98. // specification source changes.
  99. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  100. {
  101. // Add the rule to targets that need it.
  102. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  103. {
  104. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  105. {
  106. l->second.AddSource(sf->GetFullPath());
  107. }
  108. }
  109. }
  110. }
  111. }
  112. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  113. {
  114. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  115. // commands for targets in which no sources are built. Add dummy
  116. // rules to force these targets to build.
  117. cmTargets &tgts = this->Makefile->GetTargets();
  118. for(cmTargets::iterator l = tgts.begin();
  119. l != tgts.end(); l++)
  120. {
  121. cmTarget& tgt = l->second;
  122. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  123. {
  124. std::vector<std::string> no_depends;
  125. cmCustomCommandLine force_command;
  126. force_command.push_back("cd");
  127. force_command.push_back(".");
  128. cmCustomCommandLines force_commands;
  129. force_commands.push_back(force_command);
  130. std::string no_main_dependency = "";
  131. std::string force = this->Makefile->GetCurrentBinaryDirectory();
  132. force += cmake::GetCMakeFilesDirectory();
  133. force += "/";
  134. force += tgt.GetName();
  135. force += "_force";
  136. if(cmSourceFile* file =
  137. this->Makefile->AddCustomCommandToOutput(
  138. force.c_str(), no_depends, no_main_dependency,
  139. force_commands, " ", 0, true))
  140. {
  141. tgt.AddSource(file->GetFullPath());
  142. }
  143. }
  144. }
  145. }
  146. // TODO
  147. // for CommandLine= need to repleace quotes with &quot
  148. // write out configurations
  149. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  150. {
  151. // If not an in source build, then create the output directory
  152. if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
  153. this->Makefile->GetHomeDirectory()) != 0)
  154. {
  155. if(!cmSystemTools::MakeDirectory
  156. (this->Makefile->GetCurrentBinaryDirectory()))
  157. {
  158. cmSystemTools::Error("Error creating directory ",
  159. this->Makefile->GetCurrentBinaryDirectory());
  160. }
  161. }
  162. // Get the set of targets in this directory.
  163. cmTargets &tgts = this->Makefile->GetTargets();
  164. // Create the project file for each target.
  165. for(cmTargets::iterator l = tgts.begin();
  166. l != tgts.end(); l++)
  167. {
  168. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  169. {
  170. continue;
  171. }
  172. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  173. // so don't build a projectfile for it
  174. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  175. {
  176. this->CreateSingleVCProj(l->first.c_str(),l->second);
  177. }
  178. }
  179. }
  180. //----------------------------------------------------------------------------
  181. void cmLocalVisualStudio7Generator::WriteStampFiles()
  182. {
  183. // Touch a timestamp file used to determine when the project file is
  184. // out of date.
  185. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  186. stampName += cmake::GetCMakeFilesDirectory();
  187. cmSystemTools::MakeDirectory(stampName.c_str());
  188. stampName += "/";
  189. stampName += "generate.stamp";
  190. cmsys::ofstream stamp(stampName.c_str());
  191. stamp << "# CMake generation timestamp file for this directory.\n";
  192. // Create a helper file so CMake can determine when it is run
  193. // through the rule created by CreateVCProjBuildRule whether it
  194. // really needs to regenerate the project. This file lists its own
  195. // dependencies. If any file listed in it is newer than itself then
  196. // CMake must rerun. Otherwise the project files are up to date and
  197. // the stamp file can just be touched.
  198. std::string depName = stampName;
  199. depName += ".depend";
  200. cmsys::ofstream depFile(depName.c_str());
  201. depFile << "# CMake generation dependency list for this directory.\n";
  202. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  203. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  204. lf != listFiles.end(); ++lf)
  205. {
  206. depFile << *lf << std::endl;
  207. }
  208. }
  209. //----------------------------------------------------------------------------
  210. void cmLocalVisualStudio7Generator
  211. ::CreateSingleVCProj(const std::string& lname, cmTarget &target)
  212. {
  213. cmGlobalVisualStudioGenerator* gg
  214. = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  215. this->FortranProject = gg->TargetIsFortranOnly(target);
  216. this->WindowsCEProject = gg->TargetsWindowsCE();
  217. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  218. cmGlobalVisualStudioGenerator::VSVersion realVersion = gg->GetVersion();
  219. if(this->FortranProject
  220. && gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS10)
  221. {
  222. gg->SetVersion(cmGlobalVisualStudioGenerator::VS9);
  223. }
  224. // add to the list of projects
  225. target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
  226. // create the dsp.cmake file
  227. std::string fname;
  228. fname = this->Makefile->GetCurrentBinaryDirectory();
  229. fname += "/";
  230. fname += lname;
  231. if(this->FortranProject)
  232. {
  233. fname += ".vfproj";
  234. }
  235. else
  236. {
  237. fname += ".vcproj";
  238. }
  239. // Generate the project file and replace it atomically with
  240. // copy-if-different. We use a separate timestamp so that the IDE
  241. // does not reload project files unnecessarily.
  242. cmGeneratedFileStream fout(fname.c_str());
  243. fout.SetCopyIfDifferent(true);
  244. this->WriteVCProjFile(fout,lname,target);
  245. if (fout.Close())
  246. {
  247. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  248. }
  249. gg->SetVersion(realVersion);
  250. }
  251. //----------------------------------------------------------------------------
  252. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  253. {
  254. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  255. stampName += "/";
  256. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  257. stampName += "generate.stamp";
  258. cmCustomCommandLine commandLine;
  259. commandLine.push_back(cmSystemTools::GetCMakeCommand());
  260. std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
  261. makefileIn += "/";
  262. makefileIn += "CMakeLists.txt";
  263. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  264. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  265. {
  266. return 0;
  267. }
  268. std::string comment = "Building Custom Rule ";
  269. comment += makefileIn;
  270. std::string args;
  271. args = "-H";
  272. args += this->Makefile->GetHomeDirectory();
  273. commandLine.push_back(args);
  274. args = "-B";
  275. args += this->Makefile->GetHomeOutputDirectory();
  276. commandLine.push_back(args);
  277. commandLine.push_back("--check-stamp-file");
  278. std::string stampFilename = this->Convert(stampName.c_str(), FULL,
  279. SHELL);
  280. commandLine.push_back(stampFilename.c_str());
  281. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  282. cmCustomCommandLines commandLines;
  283. commandLines.push_back(commandLine);
  284. const char* no_working_directory = 0;
  285. std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
  286. UNCHANGED);
  287. this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
  288. listFiles, makefileIn.c_str(),
  289. commandLines, comment.c_str(),
  290. no_working_directory, true);
  291. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  292. {
  293. return file;
  294. }
  295. else
  296. {
  297. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  298. return 0;
  299. }
  300. }
  301. void cmLocalVisualStudio7Generator::WriteConfigurations(
  302. std::ostream& fout, std::vector<std::string> const& configs,
  303. const std::string& libName, cmTarget &target
  304. )
  305. {
  306. fout << "\t<Configurations>\n";
  307. for (std::vector<std::string>::const_iterator i = configs.begin();
  308. i != configs.end(); ++i)
  309. {
  310. this->WriteConfiguration(fout, i->c_str(), libName, target);
  311. }
  312. fout << "\t</Configurations>\n";
  313. }
  314. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  315. {
  316. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  317. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  318. {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
  319. {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
  320. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  321. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  322. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  323. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  324. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  325. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  326. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  327. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  328. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  329. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  330. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  331. {"OmitFramePointers", "Oy-", "", "false", 0},
  332. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  333. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  334. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  335. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  336. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  337. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  338. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  339. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  340. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  341. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  342. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  343. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  344. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  345. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  346. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  347. {"OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0},
  348. {"OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0},
  349. {"Traceback", "traceback", "", "true", 0},
  350. {"Traceback", "notraceback", "", "false", 0},
  351. {"FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0},
  352. {"FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0},
  353. {"FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0},
  354. {"ModulePath", "module:", "", "",
  355. cmVS7FlagTable::UserValueRequired},
  356. {"LoopUnrolling", "Qunroll:", "", "",
  357. cmVS7FlagTable::UserValueRequired},
  358. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  359. cmVS7FlagTable::UserValueRequired},
  360. {"HeapArrays", "heap-arrays:", "", "",
  361. cmVS7FlagTable::UserValueRequired},
  362. {"ObjectText", "bintext:", "", "",
  363. cmVS7FlagTable::UserValueRequired},
  364. {"Parallelization", "Qparallel", "", "true", 0},
  365. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  366. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  367. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  368. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  369. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  370. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  371. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  372. {"EnableRecursion", "recursive", "", "true", 0},
  373. {"ReentrantCode", "reentrancy", "", "true", 0},
  374. // done up to Language
  375. {0,0,0,0,0}
  376. };
  377. // fill the table here currently the comment field is not used for
  378. // anything other than documentation NOTE: Make sure the longer
  379. // commandFlag comes FIRST!
  380. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  381. {
  382. // option flags (some flags map to the same option)
  383. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  384. {"BasicRuntimeChecks", "RTCsu",
  385. "Both stack and uninitialized checks", "3", 0},
  386. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  387. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  388. {"BasicRuntimeChecks", "RTC1",
  389. "Both stack and uninitialized checks", "3", 0},
  390. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  391. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  392. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  393. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  394. {"EnableEnhancedInstructionSet", "arch:SSE2",
  395. "Use sse2 instructions", "2", 0},
  396. {"EnableEnhancedInstructionSet", "arch:SSE",
  397. "Use sse instructions", "1", 0},
  398. {"FloatingPointModel", "fp:precise",
  399. "Use precise floating point model", "0", 0},
  400. {"FloatingPointModel", "fp:strict",
  401. "Use strict floating point model", "1", 0},
  402. {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
  403. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  404. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  405. {"CompileAs", "TC", "Compile as c code", "1", 0},
  406. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  407. {"Optimization", "Od", "Non Debug", "0", 0},
  408. {"Optimization", "O1", "Min Size", "1", 0},
  409. {"Optimization", "O2", "Max Speed", "2", 0},
  410. {"Optimization", "Ox", "Max Optimization", "3", 0},
  411. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  412. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  413. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  414. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  415. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  416. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  417. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  418. {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
  419. {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
  420. {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
  421. {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
  422. {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
  423. {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
  424. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  425. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  426. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  427. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  428. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  429. {"WarningLevel", "W0", "Warning level", "0", 0},
  430. {"WarningLevel", "W1", "Warning level", "1", 0},
  431. {"WarningLevel", "W2", "Warning level", "2", 0},
  432. {"WarningLevel", "W3", "Warning level", "3", 0},
  433. {"WarningLevel", "W4", "Warning level", "4", 0},
  434. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  435. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  436. // Precompiled header and related options. Note that the
  437. // UsePrecompiledHeader entries are marked as "Continue" so that the
  438. // corresponding PrecompiledHeaderThrough entry can be found.
  439. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  440. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  441. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  442. cmVS7FlagTable::UserValueRequired},
  443. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  444. cmVS7FlagTable::UserValue},
  445. // The YX and Yu options are in a per-global-generator table because
  446. // their values differ based on the VS IDE version.
  447. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  448. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
  449. {"AssemblerListingLocation", "Fa", "ASM List Location", "",
  450. cmVS7FlagTable::UserValue},
  451. {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  452. cmVS7FlagTable::UserValue},
  453. // boolean flags
  454. {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
  455. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
  456. {"Detect64BitPortabilityProblems", "Wp64",
  457. "Detect 64-bit Portability Problems", "true", 0},
  458. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  459. "true", 0},
  460. {"EnableFunctionLevelLinking", "Gy",
  461. "EnableFunctionLevelLinking", "true", 0},
  462. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
  463. {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
  464. {"ImproveFloatingPointConsistency", "Op",
  465. "ImproveFloatingPointConsistency", "true", 0},
  466. {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
  467. {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
  468. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
  469. {"RuntimeTypeInfo", "GR",
  470. "Turn on Run time type information for c++", "true", 0},
  471. {"RuntimeTypeInfo", "GR-",
  472. "Turn off Run time type information for c++", "false", 0},
  473. {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
  474. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  475. {"WholeProgramOptimization", "GL",
  476. "Enables whole program optimization", "true", 0},
  477. {"WholeProgramOptimization", "GL-",
  478. "Disables whole program optimization", "false", 0},
  479. {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
  480. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  481. {"StringPooling", "GF", "Enable StringPooling", "true", 0},
  482. {0,0,0,0,0}
  483. };
  484. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  485. {
  486. // option flags (some flags map to the same option)
  487. {"GenerateManifest", "MANIFEST:NO",
  488. "disable manifest generation", "false", 0},
  489. {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
  490. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  491. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  492. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  493. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  494. {"DataExecutionPrevention", "NXCOMPAT:NO",
  495. "Not known to work with Windows Data Execution Prevention", "1", 0},
  496. {"DataExecutionPrevention", "NXCOMPAT",
  497. "Known to work with Windows Data Execution Prevention", "2", 0},
  498. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  499. {"DelaySign", "DELAYSIGN", "", "true", 0},
  500. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  501. cmVS7FlagTable::UserValue},
  502. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  503. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  504. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  505. "true", 0},
  506. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  507. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  508. "2", 0},
  509. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  510. "1", 0},
  511. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  512. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  513. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  514. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  515. {"Profile", "PROFILE", "", "true", 0},
  516. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  517. "Image may not be rebased at load-time", "1", 0},
  518. {"RandomizedBaseAddress", "DYNAMICBASE",
  519. "Image may be rebased at load-time", "2", 0},
  520. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  521. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  522. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  523. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  524. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  525. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  526. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  527. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  528. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  529. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  530. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  531. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  532. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  533. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  534. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  535. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  536. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  537. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  538. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  539. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  540. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  541. "No assembly even if CLR information is present in objects.", "true", 0},
  542. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  543. cmVS7FlagTable::UserValue},
  544. {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
  545. {0,0,0,0,0}
  546. };
  547. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] =
  548. {
  549. {"LinkIncremental", "INCREMENTAL:NO", "link incremental",
  550. "linkIncrementalNo", 0},
  551. {"LinkIncremental", "INCREMENTAL:YES", "link incremental",
  552. "linkIncrementalYes", 0},
  553. {0,0,0,0,0}
  554. };
  555. //----------------------------------------------------------------------------
  556. // Helper class to write build event <Tool .../> elements.
  557. class cmLocalVisualStudio7Generator::EventWriter
  558. {
  559. public:
  560. EventWriter(cmLocalVisualStudio7Generator* lg,
  561. const std::string& config, std::ostream& os):
  562. LG(lg), Config(config), Stream(os), First(true) {}
  563. void Start(const char* tool)
  564. {
  565. this->First = true;
  566. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  567. }
  568. void Finish()
  569. {
  570. this->Stream << (this->First? "" : "\"") << "/>\n";
  571. }
  572. void Write(std::vector<cmCustomCommand> const& ccs)
  573. {
  574. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  575. ci != ccs.end(); ++ci)
  576. {
  577. this->Write(*ci);
  578. }
  579. }
  580. void Write(cmCustomCommand const& cc)
  581. {
  582. cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
  583. if(this->First)
  584. {
  585. const char* comment = ccg.GetComment();
  586. if(comment && *comment)
  587. {
  588. this->Stream << "\nDescription=\""
  589. << this->LG->EscapeForXML(comment) << "\"";
  590. }
  591. this->Stream << "\nCommandLine=\"";
  592. this->First = false;
  593. }
  594. else
  595. {
  596. this->Stream << this->LG->EscapeForXML("\n");
  597. }
  598. std::string script = this->LG->ConstructScript(ccg);
  599. this->Stream << this->LG->EscapeForXML(script.c_str());
  600. }
  601. private:
  602. cmLocalVisualStudio7Generator* LG;
  603. std::string Config;
  604. std::ostream& Stream;
  605. bool First;
  606. };
  607. //----------------------------------------------------------------------------
  608. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  609. const std::string& configName,
  610. const std::string& libName,
  611. cmTarget &target)
  612. {
  613. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  614. if(!mfcFlag)
  615. {
  616. mfcFlag = "0";
  617. }
  618. cmGlobalVisualStudio7Generator* gg =
  619. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  620. fout << "\t\t<Configuration\n"
  621. << "\t\t\tName=\"" << configName
  622. << "|" << gg->GetPlatformName() << "\"\n";
  623. // This is an internal type to Visual Studio, it seems that:
  624. // 4 == static library
  625. // 2 == dll
  626. // 1 == executable
  627. // 10 == utility
  628. const char* configType = "10";
  629. const char* projectType = 0;
  630. bool targetBuilds = true;
  631. switch(target.GetType())
  632. {
  633. case cmTarget::OBJECT_LIBRARY:
  634. targetBuilds = false; // no manifest tool for object library
  635. case cmTarget::STATIC_LIBRARY:
  636. projectType = "typeStaticLibrary";
  637. configType = "4";
  638. break;
  639. case cmTarget::SHARED_LIBRARY:
  640. case cmTarget::MODULE_LIBRARY:
  641. projectType = "typeDynamicLibrary";
  642. configType = "2";
  643. break;
  644. case cmTarget::EXECUTABLE:
  645. configType = "1";
  646. break;
  647. case cmTarget::UTILITY:
  648. case cmTarget::GLOBAL_TARGET:
  649. configType = "10";
  650. default:
  651. targetBuilds = false;
  652. break;
  653. }
  654. if(this->FortranProject && projectType)
  655. {
  656. configType = projectType;
  657. }
  658. std::string flags;
  659. if(strcmp(configType, "10") != 0)
  660. {
  661. const std::string& linkLanguage = (this->FortranProject?
  662. std::string("Fortran"):
  663. target.GetLinkerLanguage(configName));
  664. if(linkLanguage.empty())
  665. {
  666. cmSystemTools::Error
  667. ("CMake can not determine linker language for target: ",
  668. target.GetName().c_str());
  669. return;
  670. }
  671. if(linkLanguage == "C" || linkLanguage == "CXX"
  672. || linkLanguage == "Fortran")
  673. {
  674. std::string baseFlagVar = "CMAKE_";
  675. baseFlagVar += linkLanguage;
  676. baseFlagVar += "_FLAGS";
  677. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  678. std::string flagVar = baseFlagVar + std::string("_") +
  679. cmSystemTools::UpperCase(configName);
  680. flags += " ";
  681. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  682. }
  683. // set the correct language
  684. if(linkLanguage == "C")
  685. {
  686. flags += " /TC ";
  687. }
  688. if(linkLanguage == "CXX")
  689. {
  690. flags += " /TP ";
  691. }
  692. // Add the target-specific flags.
  693. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  694. }
  695. if(this->FortranProject)
  696. {
  697. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  698. {
  699. case FortranFormatFixed: flags += " -fixed"; break;
  700. case FortranFormatFree: flags += " -free"; break;
  701. default: break;
  702. }
  703. }
  704. // Get preprocessor definitions for this directory.
  705. std::string defineFlags = this->Makefile->GetDefineFlags();
  706. Options::Tool t = Options::Compiler;
  707. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  708. if(this->FortranProject)
  709. {
  710. t = Options::FortranCompiler;
  711. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  712. }
  713. Options targetOptions(this, t,
  714. table,
  715. gg->ExtraFlagTable);
  716. targetOptions.FixExceptionHandlingDefault();
  717. std::string asmLocation = configName + "/";
  718. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  719. targetOptions.Parse(flags.c_str());
  720. targetOptions.Parse(defineFlags.c_str());
  721. targetOptions.ParseFinish();
  722. cmGeneratorTarget* gt =
  723. this->GlobalGenerator->GetGeneratorTarget(&target);
  724. std::vector<std::string> targetDefines;
  725. target.GetCompileDefinitions(targetDefines, configName, "CXX");
  726. targetOptions.AddDefines(targetDefines);
  727. targetOptions.SetVerboseMakefile(
  728. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  729. // Add a definition for the configuration name.
  730. std::string configDefine = "CMAKE_INTDIR=\"";
  731. configDefine += configName;
  732. configDefine += "\"";
  733. targetOptions.AddDefine(configDefine);
  734. // Add the export symbol definition for shared library objects.
  735. if(const char* exportMacro = target.GetExportMacro())
  736. {
  737. targetOptions.AddDefine(exportMacro);
  738. }
  739. // The intermediate directory name consists of a directory for the
  740. // target and a subdirectory for the configuration name.
  741. std::string intermediateDir = this->GetTargetDirectory(target);
  742. intermediateDir += "/";
  743. intermediateDir += configName;
  744. if (target.GetType() < cmTarget::UTILITY)
  745. {
  746. std::string const& outDir =
  747. target.GetType() == cmTarget::OBJECT_LIBRARY?
  748. intermediateDir : target.GetDirectory(configName);
  749. fout << "\t\t\tOutputDirectory=\""
  750. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  751. }
  752. fout << "\t\t\tIntermediateDirectory=\""
  753. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  754. << "\"\n"
  755. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  756. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  757. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  758. if (this->FortranProject)
  759. {
  760. // Intel Fortran >= 15.0 uses TargetName property.
  761. std::string targetNameFull = target.GetFullName(configName);
  762. std::string targetName =
  763. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  764. std::string targetExt =
  765. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  766. fout <<
  767. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  768. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  769. ;
  770. }
  771. // If unicode is enabled change the character set to unicode, if not
  772. // then default to MBCS.
  773. if(targetOptions.UsingUnicode())
  774. {
  775. fout << "\t\t\tCharacterSet=\"1\">\n";
  776. }
  777. else if(targetOptions.UsingSBCS())
  778. {
  779. fout << "\t\t\tCharacterSet=\"0\">\n";
  780. }
  781. else
  782. {
  783. fout << "\t\t\tCharacterSet=\"2\">\n";
  784. }
  785. const char* tool = "VCCLCompilerTool";
  786. if(this->FortranProject)
  787. {
  788. tool = "VFFortranCompilerTool";
  789. }
  790. fout << "\t\t\t<Tool\n"
  791. << "\t\t\t\tName=\"" << tool << "\"\n";
  792. if(this->FortranProject)
  793. {
  794. const char* target_mod_dir =
  795. target.GetProperty("Fortran_MODULE_DIRECTORY");
  796. std::string modDir;
  797. if(target_mod_dir)
  798. {
  799. modDir = this->Convert(target_mod_dir,
  800. cmLocalGenerator::START_OUTPUT,
  801. cmLocalGenerator::UNCHANGED);
  802. }
  803. else
  804. {
  805. modDir = ".";
  806. }
  807. fout << "\t\t\t\tModulePath=\""
  808. << this->ConvertToXMLOutputPath(modDir.c_str())
  809. << "\\$(ConfigurationName)\"\n";
  810. }
  811. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  812. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  813. std::vector<std::string> includes;
  814. this->GetIncludeDirectories(includes, gt, "C", configName);
  815. std::vector<std::string>::iterator i = includes.begin();
  816. for(;i != includes.end(); ++i)
  817. {
  818. // output the include path
  819. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  820. fout << ipath << ";";
  821. // if this is fortran then output the include with
  822. // a ConfigurationName on the end of it.
  823. if(this->FortranProject)
  824. {
  825. ipath = i->c_str();
  826. ipath += "/$(ConfigurationName)";
  827. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  828. fout << ipath << ";";
  829. }
  830. }
  831. fout << "\"\n";
  832. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  833. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  834. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  835. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  836. {
  837. // Specify the compiler program database file if configured.
  838. std::string pdb = target.GetCompilePDBPath(configName);
  839. if(!pdb.empty())
  840. {
  841. fout << "\t\t\t\tProgramDataBaseFileName=\""
  842. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  843. << "\"\n";
  844. }
  845. }
  846. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  847. if(gg->IsMasmEnabled() && !this->FortranProject)
  848. {
  849. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  850. fout <<
  851. "\t\t\t<Tool\n"
  852. "\t\t\t\tName=\"MASM\"\n"
  853. "\t\t\t\tIncludePaths=\""
  854. ;
  855. const char* sep = "";
  856. for(i = includes.begin(); i != includes.end(); ++i)
  857. {
  858. std::string inc = *i;
  859. cmConvertToWindowsSlash(inc);
  860. fout << sep << this->EscapeForXML(inc);
  861. sep = ";";
  862. }
  863. fout << "\"\n";
  864. // Use same preprocessor definitions as VCCLCompilerTool.
  865. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  866. "ASM_MASM");
  867. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  868. fout <<
  869. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  870. "\t\t\t/>\n";
  871. }
  872. tool = "VCCustomBuildTool";
  873. if(this->FortranProject)
  874. {
  875. tool = "VFCustomBuildTool";
  876. }
  877. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  878. tool = "VCResourceCompilerTool";
  879. if(this->FortranProject)
  880. {
  881. tool = "VFResourceCompilerTool";
  882. }
  883. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  884. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  885. for(i = includes.begin();i != includes.end(); ++i)
  886. {
  887. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  888. fout << ipath << ";";
  889. }
  890. // add the -D flags to the RC tool
  891. fout << "\"";
  892. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  893. fout << "/>\n";
  894. tool = "VCMIDLTool";
  895. if(this->FortranProject)
  896. {
  897. tool = "VFMIDLTool";
  898. }
  899. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  900. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  901. for(i = includes.begin(); i != includes.end(); ++i)
  902. {
  903. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  904. fout << ipath << ";";
  905. }
  906. fout << "\"\n";
  907. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  908. if( gg->GetPlatformName() == "x64" )
  909. {
  910. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  911. }
  912. else if( gg->GetPlatformName() == "ia64" )
  913. {
  914. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  915. }
  916. else
  917. {
  918. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  919. }
  920. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  921. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  922. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  923. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  924. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  925. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  926. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  927. // end of <Tool Name=VCMIDLTool
  928. // Check if we need the FAT32 workaround.
  929. if(targetBuilds && this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  930. {
  931. // Check the filesystem type where the target will be written.
  932. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  933. {
  934. // Add a flag telling the manifest tool to use a workaround
  935. // for FAT32 file systems, which can cause an empty manifest
  936. // to be embedded into the resulting executable. See CMake
  937. // bug #2617.
  938. const char* manifestTool = "VCManifestTool";
  939. if(this->FortranProject)
  940. {
  941. manifestTool = "VFManifestTool";
  942. }
  943. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  944. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  945. << "\t\t\t/>\n";
  946. }
  947. }
  948. this->OutputTargetRules(fout, configName, target, libName);
  949. this->OutputBuildTool(fout, configName, target, targetOptions);
  950. fout << "\t\t</Configuration>\n";
  951. }
  952. //----------------------------------------------------------------------------
  953. std::string
  954. cmLocalVisualStudio7Generator
  955. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  956. const std::string& configName)
  957. {
  958. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  959. std::string extraLinkOptionsBuildTypeDef =
  960. rootLinkerFlags + "_" + configTypeUpper;
  961. std::string extraLinkOptionsBuildType =
  962. this->Makefile->GetRequiredDefinition
  963. (extraLinkOptionsBuildTypeDef.c_str());
  964. return extraLinkOptionsBuildType;
  965. }
  966. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  967. const std::string& configName, cmTarget &target,
  968. const Options& targetOptions)
  969. {
  970. cmGlobalVisualStudio7Generator* gg =
  971. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  972. std::string temp;
  973. std::string extraLinkOptions;
  974. if(target.GetType() == cmTarget::EXECUTABLE)
  975. {
  976. extraLinkOptions =
  977. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  978. + std::string(" ")
  979. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  980. }
  981. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  982. {
  983. extraLinkOptions =
  984. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  985. + std::string(" ")
  986. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  987. }
  988. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  989. {
  990. extraLinkOptions =
  991. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  992. + std::string(" ")
  993. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  994. }
  995. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  996. if(targetLinkFlags)
  997. {
  998. extraLinkOptions += " ";
  999. extraLinkOptions += targetLinkFlags;
  1000. }
  1001. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  1002. std::string linkFlagsConfig = "LINK_FLAGS_";
  1003. linkFlagsConfig += configTypeUpper;
  1004. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  1005. if(targetLinkFlags)
  1006. {
  1007. extraLinkOptions += " ";
  1008. extraLinkOptions += targetLinkFlags;
  1009. }
  1010. Options linkOptions(this, Options::Linker);
  1011. if(this->FortranProject)
  1012. {
  1013. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1014. }
  1015. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1016. linkOptions.Parse(extraLinkOptions.c_str());
  1017. if(!this->ModuleDefinitionFile.empty())
  1018. {
  1019. std::string defFile =
  1020. this->ConvertToOutputFormat(this->ModuleDefinitionFile, SHELL);
  1021. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1022. }
  1023. switch(target.GetType())
  1024. {
  1025. case cmTarget::UNKNOWN_LIBRARY:
  1026. break;
  1027. case cmTarget::OBJECT_LIBRARY:
  1028. {
  1029. std::string libpath = this->GetTargetDirectory(target);
  1030. libpath += "/";
  1031. libpath += configName;
  1032. libpath += "/";
  1033. libpath += target.GetName();
  1034. libpath += ".lib";
  1035. const char* tool =
  1036. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1037. fout << "\t\t\t<Tool\n"
  1038. << "\t\t\t\tName=\"" << tool << "\"\n";
  1039. fout << "\t\t\t\tOutputFile=\""
  1040. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1041. break;
  1042. }
  1043. case cmTarget::STATIC_LIBRARY:
  1044. {
  1045. std::string targetNameFull = target.GetFullName(configName);
  1046. std::string libpath = target.GetDirectory(configName);
  1047. libpath += "/";
  1048. libpath += targetNameFull;
  1049. const char* tool = "VCLibrarianTool";
  1050. if(this->FortranProject)
  1051. {
  1052. tool = "VFLibrarianTool";
  1053. }
  1054. fout << "\t\t\t<Tool\n"
  1055. << "\t\t\t\tName=\"" << tool << "\"\n";
  1056. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1057. || this->FortranProject)
  1058. {
  1059. std::ostringstream libdeps;
  1060. this->Internal->OutputObjects(libdeps, &target);
  1061. if(!libdeps.str().empty())
  1062. {
  1063. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1064. }
  1065. }
  1066. std::string libflags;
  1067. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1068. if(!libflags.empty())
  1069. {
  1070. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1071. }
  1072. fout << "\t\t\t\tOutputFile=\""
  1073. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1074. break;
  1075. }
  1076. case cmTarget::SHARED_LIBRARY:
  1077. case cmTarget::MODULE_LIBRARY:
  1078. {
  1079. std::string targetName;
  1080. std::string targetNameSO;
  1081. std::string targetNameFull;
  1082. std::string targetNameImport;
  1083. std::string targetNamePDB;
  1084. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1085. targetNameImport, targetNamePDB, configName);
  1086. // Compute the link library and directory information.
  1087. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1088. if(!pcli)
  1089. {
  1090. return;
  1091. }
  1092. cmComputeLinkInformation& cli = *pcli;
  1093. std::string linkLanguage = cli.GetLinkLanguage();
  1094. // Compute the variable name to lookup standard libraries for this
  1095. // language.
  1096. std::string standardLibsVar = "CMAKE_";
  1097. standardLibsVar += linkLanguage;
  1098. standardLibsVar += "_STANDARD_LIBRARIES";
  1099. const char* tool = "VCLinkerTool";
  1100. if(this->FortranProject)
  1101. {
  1102. tool = "VFLinkerTool";
  1103. }
  1104. fout << "\t\t\t<Tool\n"
  1105. << "\t\t\t\tName=\"" << tool << "\"\n";
  1106. if(!gg->NeedLinkLibraryDependencies(target))
  1107. {
  1108. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1109. }
  1110. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1111. // Use the NOINHERIT macro to avoid getting VS project default
  1112. // libraries which may be set by the user to something bad.
  1113. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1114. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1115. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1116. || this->FortranProject)
  1117. {
  1118. this->Internal->OutputObjects(fout, &target, " ");
  1119. }
  1120. fout << " ";
  1121. this->Internal->OutputLibraries(fout, cli.GetItems());
  1122. fout << "\"\n";
  1123. temp = target.GetDirectory(configName);
  1124. temp += "/";
  1125. temp += targetNameFull;
  1126. fout << "\t\t\t\tOutputFile=\""
  1127. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1128. this->WriteTargetVersionAttribute(fout, target);
  1129. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1130. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1131. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1132. fout << "\"\n";
  1133. temp = target.GetPDBDirectory(configName);
  1134. temp += "/";
  1135. temp += targetNamePDB;
  1136. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1137. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1138. if(targetOptions.IsDebug())
  1139. {
  1140. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1141. }
  1142. if(this->WindowsCEProject)
  1143. {
  1144. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1145. {
  1146. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1147. }
  1148. else
  1149. {
  1150. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1151. }
  1152. }
  1153. std::string stackVar = "CMAKE_";
  1154. stackVar += linkLanguage;
  1155. stackVar += "_STACK_SIZE";
  1156. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1157. if(stackVal)
  1158. {
  1159. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1160. }
  1161. temp = target.GetDirectory(configName, true);
  1162. temp += "/";
  1163. temp += targetNameImport;
  1164. fout << "\t\t\t\tImportLibrary=\""
  1165. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1166. if(this->FortranProject)
  1167. {
  1168. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1169. }
  1170. fout << "/>\n";
  1171. }
  1172. break;
  1173. case cmTarget::EXECUTABLE:
  1174. {
  1175. std::string targetName;
  1176. std::string targetNameFull;
  1177. std::string targetNameImport;
  1178. std::string targetNamePDB;
  1179. target.GetExecutableNames(targetName, targetNameFull,
  1180. targetNameImport, targetNamePDB, configName);
  1181. // Compute the link library and directory information.
  1182. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1183. if(!pcli)
  1184. {
  1185. return;
  1186. }
  1187. cmComputeLinkInformation& cli = *pcli;
  1188. std::string linkLanguage = cli.GetLinkLanguage();
  1189. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1190. // Compute the variable name to lookup standard libraries for this
  1191. // language.
  1192. std::string standardLibsVar = "CMAKE_";
  1193. standardLibsVar += linkLanguage;
  1194. standardLibsVar += "_STANDARD_LIBRARIES";
  1195. const char* tool = "VCLinkerTool";
  1196. if(this->FortranProject)
  1197. {
  1198. tool = "VFLinkerTool";
  1199. }
  1200. fout << "\t\t\t<Tool\n"
  1201. << "\t\t\t\tName=\"" << tool << "\"\n";
  1202. if(!gg->NeedLinkLibraryDependencies(target))
  1203. {
  1204. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1205. }
  1206. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1207. // Use the NOINHERIT macro to avoid getting VS project default
  1208. // libraries which may be set by the user to something bad.
  1209. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1210. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1211. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1212. || this->FortranProject)
  1213. {
  1214. this->Internal->OutputObjects(fout, &target, " ");
  1215. }
  1216. fout << " ";
  1217. this->Internal->OutputLibraries(fout, cli.GetItems());
  1218. fout << "\"\n";
  1219. temp = target.GetDirectory(configName);
  1220. temp += "/";
  1221. temp += targetNameFull;
  1222. fout << "\t\t\t\tOutputFile=\""
  1223. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1224. this->WriteTargetVersionAttribute(fout, target);
  1225. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1226. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1227. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1228. fout << "\"\n";
  1229. std::string path = this->ConvertToXMLOutputPathSingle(
  1230. target.GetPDBDirectory(configName).c_str());
  1231. fout << "\t\t\t\tProgramDatabaseFile=\""
  1232. << path << "/" << targetNamePDB
  1233. << "\"\n";
  1234. if(targetOptions.IsDebug())
  1235. {
  1236. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1237. }
  1238. if ( this->WindowsCEProject )
  1239. {
  1240. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1241. {
  1242. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1243. }
  1244. else
  1245. {
  1246. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1247. }
  1248. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1249. {
  1250. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1251. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1252. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1253. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1254. }
  1255. }
  1256. else if ( this->FortranProject )
  1257. {
  1258. fout << "\t\t\t\tSubSystem=\""
  1259. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1260. << "\"\n";
  1261. }
  1262. else
  1263. {
  1264. fout << "\t\t\t\tSubSystem=\""
  1265. << (isWin32Executable ? "2" : "1")
  1266. << "\"\n";
  1267. }
  1268. std::string stackVar = "CMAKE_";
  1269. stackVar += linkLanguage;
  1270. stackVar += "_STACK_SIZE";
  1271. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1272. if(stackVal)
  1273. {
  1274. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1275. }
  1276. temp = target.GetDirectory(configName, true);
  1277. temp += "/";
  1278. temp += targetNameImport;
  1279. fout << "\t\t\t\tImportLibrary=\""
  1280. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1281. break;
  1282. }
  1283. case cmTarget::UTILITY:
  1284. case cmTarget::GLOBAL_TARGET:
  1285. case cmTarget::INTERFACE_LIBRARY:
  1286. break;
  1287. }
  1288. }
  1289. //----------------------------------------------------------------------------
  1290. void
  1291. cmLocalVisualStudio7Generator
  1292. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1293. {
  1294. int major;
  1295. int minor;
  1296. target.GetTargetVersion(major, minor);
  1297. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1298. }
  1299. //----------------------------------------------------------------------------
  1300. void
  1301. cmLocalVisualStudio7GeneratorInternals
  1302. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1303. {
  1304. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1305. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1306. {
  1307. if(l->IsPath)
  1308. {
  1309. std::string rel = lg->Convert(l->Value.c_str(),
  1310. cmLocalGenerator::START_OUTPUT,
  1311. cmLocalGenerator::UNCHANGED);
  1312. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1313. }
  1314. else if (!l->Target
  1315. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1316. {
  1317. fout << l->Value << " ";
  1318. }
  1319. }
  1320. }
  1321. //----------------------------------------------------------------------------
  1322. void
  1323. cmLocalVisualStudio7GeneratorInternals
  1324. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1325. {
  1326. // VS < 8 does not support per-config source locations so we
  1327. // list object library content on the link line instead.
  1328. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1329. cmGeneratorTarget* gt =
  1330. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1331. std::vector<std::string> objs;
  1332. gt->UseObjectLibraries(objs, "");
  1333. const char* sep = isep? isep : "";
  1334. for(std::vector<std::string>::const_iterator
  1335. oi = objs.begin(); oi != objs.end(); ++oi)
  1336. {
  1337. std::string rel = lg->Convert(oi->c_str(),
  1338. cmLocalGenerator::START_OUTPUT,
  1339. cmLocalGenerator::UNCHANGED);
  1340. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1341. sep = " ";
  1342. }
  1343. }
  1344. //----------------------------------------------------------------------------
  1345. void
  1346. cmLocalVisualStudio7Generator
  1347. ::OutputLibraryDirectories(std::ostream& fout,
  1348. std::vector<std::string> const& dirs)
  1349. {
  1350. const char* comma = "";
  1351. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1352. d != dirs.end(); ++d)
  1353. {
  1354. // Remove any trailing slash and skip empty paths.
  1355. std::string dir = *d;
  1356. if(dir[dir.size()-1] == '/')
  1357. {
  1358. dir = dir.substr(0, dir.size()-1);
  1359. }
  1360. if(dir.empty())
  1361. {
  1362. continue;
  1363. }
  1364. // Switch to a relative path specification if it is shorter.
  1365. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1366. {
  1367. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1368. if(rel.size() < dir.size())
  1369. {
  1370. dir = rel;
  1371. }
  1372. }
  1373. // First search a configuration-specific subdirectory and then the
  1374. // original directory.
  1375. fout << comma
  1376. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1377. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1378. comma = ",";
  1379. }
  1380. }
  1381. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1382. const std::string& libName,
  1383. cmTarget &target)
  1384. {
  1385. std::vector<std::string> configs;
  1386. this->Makefile->GetConfigurations(configs);
  1387. // We may be modifying the source groups temporarily, so make a copy.
  1388. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1389. // get the classes from the source lists then add them to the groups
  1390. this->ModuleDefinitionFile = "";
  1391. std::vector<cmSourceFile*> classes;
  1392. if (!target.GetConfigCommonSourceFiles(classes))
  1393. {
  1394. return;
  1395. }
  1396. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1397. i != classes.end(); i++)
  1398. {
  1399. if (!(*i)->GetObjectLibrary().empty())
  1400. {
  1401. continue;
  1402. }
  1403. // Add the file to the list of sources.
  1404. std::string source = (*i)->GetFullPath();
  1405. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1406. {
  1407. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1408. }
  1409. cmSourceGroup* sourceGroup =
  1410. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1411. sourceGroup->AssignSource(*i);
  1412. }
  1413. // open the project
  1414. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1415. // write the configuration information
  1416. this->WriteConfigurations(fout, configs, libName, target);
  1417. fout << "\t<Files>\n";
  1418. // Loop through every source group.
  1419. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1420. {
  1421. cmSourceGroup sg = sourceGroups[i];
  1422. this->WriteGroup(&sg, target, fout, libName, configs);
  1423. }
  1424. if(this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8
  1425. && !this->FortranProject)
  1426. {
  1427. // VS >= 8 support per-config source locations so we
  1428. // list object library content as external objects.
  1429. cmGeneratorTarget* gt =
  1430. this->GlobalGenerator->GetGeneratorTarget(&target);
  1431. std::vector<std::string> objs;
  1432. gt->UseObjectLibraries(objs, "");
  1433. if(!objs.empty())
  1434. {
  1435. // TODO: Separate sub-filter for each object library used?
  1436. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1437. for(std::vector<std::string>::const_iterator
  1438. oi = objs.begin(); oi != objs.end(); ++oi)
  1439. {
  1440. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1441. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1442. }
  1443. fout << "\t\t</Filter>\n";
  1444. }
  1445. }
  1446. fout << "\t</Files>\n";
  1447. // Write the VCProj file's footer.
  1448. this->WriteVCProjFooter(fout, target);
  1449. }
  1450. struct cmLVS7GFileConfig
  1451. {
  1452. std::string ObjectName;
  1453. std::string CompileFlags;
  1454. std::string CompileDefs;
  1455. std::string CompileDefsConfig;
  1456. std::string AdditionalDeps;
  1457. bool ExcludedFromBuild;
  1458. };
  1459. class cmLocalVisualStudio7GeneratorFCInfo
  1460. {
  1461. public:
  1462. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1463. cmTarget& target,
  1464. cmSourceFile const& sf,
  1465. std::vector<std::string> const& configs);
  1466. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1467. };
  1468. cmLocalVisualStudio7GeneratorFCInfo
  1469. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1470. cmTarget& target,
  1471. cmSourceFile const& sf,
  1472. std::vector<std::string> const& configs)
  1473. {
  1474. cmGeneratorTarget* gt =
  1475. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1476. std::string objectName;
  1477. if(gt->HasExplicitObjectName(&sf))
  1478. {
  1479. objectName = gt->GetObjectName(&sf);
  1480. }
  1481. // Compute per-source, per-config information.
  1482. for(std::vector<std::string>::const_iterator i = configs.begin();
  1483. i != configs.end(); ++i)
  1484. {
  1485. std::string configUpper = cmSystemTools::UpperCase(*i);
  1486. cmLVS7GFileConfig fc;
  1487. bool needfc = false;
  1488. if(!objectName.empty())
  1489. {
  1490. fc.ObjectName = objectName;
  1491. needfc = true;
  1492. }
  1493. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1494. {
  1495. fc.CompileFlags = cflags;
  1496. needfc = true;
  1497. }
  1498. if(lg->FortranProject)
  1499. {
  1500. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1501. {
  1502. case cmLocalGenerator::FortranFormatFixed:
  1503. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1504. needfc = true;
  1505. break;
  1506. case cmLocalGenerator::FortranFormatFree:
  1507. fc.CompileFlags = "-free " + fc.CompileFlags;
  1508. needfc = true;
  1509. break;
  1510. default: break;
  1511. }
  1512. }
  1513. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1514. {
  1515. fc.CompileDefs = cdefs;
  1516. needfc = true;
  1517. }
  1518. std::string defPropName = "COMPILE_DEFINITIONS_";
  1519. defPropName += configUpper;
  1520. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1521. {
  1522. fc.CompileDefsConfig = ccdefs;
  1523. needfc = true;
  1524. }
  1525. // Check for extra object-file dependencies.
  1526. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1527. {
  1528. std::vector<std::string> depends;
  1529. cmSystemTools::ExpandListArgument(deps, depends);
  1530. const char* sep = "";
  1531. for(std::vector<std::string>::iterator j = depends.begin();
  1532. j != depends.end(); ++j)
  1533. {
  1534. fc.AdditionalDeps += sep;
  1535. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1536. sep = ";";
  1537. needfc = true;
  1538. }
  1539. }
  1540. std::string lang =
  1541. lg->GlobalGenerator->GetLanguageFromExtension
  1542. (sf.GetExtension().c_str());
  1543. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1544. const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
  1545. bool needForceLang = false;
  1546. // source file does not match its extension language
  1547. if(lang != sourceLang)
  1548. {
  1549. needForceLang = true;
  1550. lang = sourceLang;
  1551. }
  1552. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1553. // the project file
  1554. fc.ExcludedFromBuild =
  1555. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1556. if(fc.ExcludedFromBuild)
  1557. {
  1558. needfc = true;
  1559. }
  1560. // if the source file does not match the linker language
  1561. // then force c or c++
  1562. if(needForceLang || (linkLanguage != lang))
  1563. {
  1564. if(lang == "CXX")
  1565. {
  1566. // force a C++ file type
  1567. fc.CompileFlags += " /TP ";
  1568. needfc = true;
  1569. }
  1570. else if(lang == "C")
  1571. {
  1572. // force to c
  1573. fc.CompileFlags += " /TC ";
  1574. needfc = true;
  1575. }
  1576. }
  1577. if(needfc)
  1578. {
  1579. this->FileConfigMap[*i] = fc;
  1580. }
  1581. }
  1582. }
  1583. //----------------------------------------------------------------------------
  1584. std::string
  1585. cmLocalVisualStudio7Generator
  1586. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1587. {
  1588. std::vector<std::string> configs;
  1589. target.GetMakefile()->GetConfigurations(configs);
  1590. // Compute the maximum length configuration name.
  1591. std::string config_max;
  1592. for(std::vector<std::string>::iterator i = configs.begin();
  1593. i != configs.end(); ++i)
  1594. {
  1595. if(i->size() > config_max.size())
  1596. {
  1597. config_max = *i;
  1598. }
  1599. }
  1600. // Compute the maximum length full path to the intermediate
  1601. // files directory for any configuration. This is used to construct
  1602. // object file names that do not produce paths that are too long.
  1603. std::string dir_max;
  1604. dir_max += this->Makefile->GetCurrentBinaryDirectory();
  1605. dir_max += "/";
  1606. dir_max += this->GetTargetDirectory(target);
  1607. dir_max += "/";
  1608. dir_max += config_max;
  1609. dir_max += "/";
  1610. return dir_max;
  1611. }
  1612. bool cmLocalVisualStudio7Generator
  1613. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1614. std::ostream &fout, const std::string& libName,
  1615. std::vector<std::string> const& configs)
  1616. {
  1617. cmGlobalVisualStudio7Generator* gg =
  1618. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1619. const std::vector<const cmSourceFile *> &sourceFiles =
  1620. sg->GetSourceFiles();
  1621. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1622. // Write the children to temporary output.
  1623. bool hasChildrenWithSources = false;
  1624. std::ostringstream tmpOut;
  1625. for(unsigned int i=0;i<children.size();++i)
  1626. {
  1627. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1628. {
  1629. hasChildrenWithSources = true;
  1630. }
  1631. }
  1632. // If the group is empty, don't write it at all.
  1633. if(sourceFiles.empty() && !hasChildrenWithSources)
  1634. {
  1635. return false;
  1636. }
  1637. // If the group has a name, write the header.
  1638. std::string name = sg->GetName();
  1639. if(name != "")
  1640. {
  1641. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1642. }
  1643. // Loop through each source in the source group.
  1644. std::string objectName;
  1645. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1646. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1647. {
  1648. std::string source = (*sf)->GetFullPath();
  1649. FCInfo fcinfo(this, target, *(*sf), configs);
  1650. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1651. target.GetType() == cmTarget::GLOBAL_TARGET )
  1652. {
  1653. fout << "\t\t\t<File\n";
  1654. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1655. // Tell MS-Dev what the source is. If the compiler knows how to
  1656. // build it, then it will.
  1657. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1658. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1659. {
  1660. this->WriteCustomRule(fout, configs, source.c_str(),
  1661. *command, fcinfo);
  1662. }
  1663. else if(!fcinfo.FileConfigMap.empty())
  1664. {
  1665. const char* aCompilerTool = "VCCLCompilerTool";
  1666. const char* ppLang = "CXX";
  1667. if(this->FortranProject)
  1668. {
  1669. aCompilerTool = "VFFortranCompilerTool";
  1670. }
  1671. std::string const& lang = (*sf)->GetLanguage();
  1672. std::string ext = (*sf)->GetExtension();
  1673. ext = cmSystemTools::LowerCase(ext);
  1674. if(ext == "idl")
  1675. {
  1676. aCompilerTool = "VCMIDLTool";
  1677. if(this->FortranProject)
  1678. {
  1679. aCompilerTool = "VFMIDLTool";
  1680. }
  1681. }
  1682. if(ext == "rc")
  1683. {
  1684. aCompilerTool = "VCResourceCompilerTool";
  1685. ppLang = "RC";
  1686. if(this->FortranProject)
  1687. {
  1688. aCompilerTool = "VFResourceCompilerTool";
  1689. }
  1690. }
  1691. if(ext == "def")
  1692. {
  1693. aCompilerTool = "VCCustomBuildTool";
  1694. if(this->FortranProject)
  1695. {
  1696. aCompilerTool = "VFCustomBuildTool";
  1697. }
  1698. }
  1699. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1700. lang == "ASM_MASM")
  1701. {
  1702. aCompilerTool = "MASM";
  1703. }
  1704. for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
  1705. fci = fcinfo.FileConfigMap.begin();
  1706. fci != fcinfo.FileConfigMap.end(); ++fci)
  1707. {
  1708. cmLVS7GFileConfig const& fc = fci->second;
  1709. fout << "\t\t\t\t<FileConfiguration\n"
  1710. << "\t\t\t\t\tName=\"" << fci->first
  1711. << "|" << gg->GetPlatformName() << "\"";
  1712. if(fc.ExcludedFromBuild)
  1713. {
  1714. fout << " ExcludedFromBuild=\"true\"";
  1715. }
  1716. fout << ">\n";
  1717. fout << "\t\t\t\t\t<Tool\n"
  1718. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1719. if(!fc.CompileFlags.empty() ||
  1720. !fc.CompileDefs.empty() ||
  1721. !fc.CompileDefsConfig.empty())
  1722. {
  1723. Options::Tool tool = Options::Compiler;
  1724. cmVS7FlagTable const* table =
  1725. cmLocalVisualStudio7GeneratorFlagTable;
  1726. if(this->FortranProject)
  1727. {
  1728. tool = Options::FortranCompiler;
  1729. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1730. }
  1731. Options fileOptions(this, tool, table,
  1732. gg->ExtraFlagTable);
  1733. fileOptions.Parse(fc.CompileFlags.c_str());
  1734. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1735. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1736. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1737. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1738. fileOptions.OutputPreprocessorDefinitions(fout,
  1739. "\t\t\t\t\t", "\n",
  1740. ppLang);
  1741. }
  1742. if(!fc.AdditionalDeps.empty())
  1743. {
  1744. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1745. << fc.AdditionalDeps.c_str() << "\"\n";
  1746. }
  1747. if(!fc.ObjectName.empty())
  1748. {
  1749. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1750. << fc.ObjectName.c_str() << "\"\n";
  1751. }
  1752. fout << "\t\t\t\t\t/>\n"
  1753. << "\t\t\t\t</FileConfiguration>\n";
  1754. }
  1755. }
  1756. fout << "\t\t\t</File>\n";
  1757. }
  1758. }
  1759. // If the group has children with source files, write the children.
  1760. if(hasChildrenWithSources)
  1761. {
  1762. fout << tmpOut.str();
  1763. }
  1764. // If the group has a name, write the footer.
  1765. if(name != "")
  1766. {
  1767. this->WriteVCProjEndGroup(fout);
  1768. }
  1769. return true;
  1770. }
  1771. void cmLocalVisualStudio7Generator::
  1772. WriteCustomRule(std::ostream& fout,
  1773. std::vector<std::string> const& configs,
  1774. const char* source,
  1775. const cmCustomCommand& command,
  1776. FCInfo& fcinfo)
  1777. {
  1778. cmGlobalVisualStudio7Generator* gg =
  1779. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1780. // Write the rule for each configuration.
  1781. const char* compileTool = "VCCLCompilerTool";
  1782. if(this->FortranProject)
  1783. {
  1784. compileTool = "VFCLCompilerTool";
  1785. }
  1786. const char* customTool = "VCCustomBuildTool";
  1787. if(this->FortranProject)
  1788. {
  1789. customTool = "VFCustomBuildTool";
  1790. }
  1791. for (std::vector<std::string>::const_iterator i = configs.begin();
  1792. i != configs.end(); ++i)
  1793. {
  1794. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  1795. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1796. fout << "\t\t\t\t<FileConfiguration\n";
  1797. fout << "\t\t\t\t\tName=\"" << *i << "|"
  1798. << gg->GetPlatformName() << "\">\n";
  1799. if(!fc.CompileFlags.empty())
  1800. {
  1801. fout << "\t\t\t\t\t<Tool\n"
  1802. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1803. << "\t\t\t\t\tAdditionalOptions=\""
  1804. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1805. }
  1806. std::string comment = this->ConstructComment(ccg);
  1807. std::string script = this->ConstructScript(ccg);
  1808. if(this->FortranProject)
  1809. {
  1810. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1811. }
  1812. fout << "\t\t\t\t\t<Tool\n"
  1813. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1814. << "\t\t\t\t\tDescription=\""
  1815. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1816. << "\t\t\t\t\tCommandLine=\""
  1817. << this->EscapeForXML(script.c_str()) << "\"\n"
  1818. << "\t\t\t\t\tAdditionalDependencies=\"";
  1819. if(ccg.GetDepends().empty())
  1820. {
  1821. // There are no real dependencies. Produce an artificial one to
  1822. // make sure the rule runs reliably.
  1823. if(!cmSystemTools::FileExists(source))
  1824. {
  1825. cmsys::ofstream depout(source);
  1826. depout << "Artificial dependency for a custom command.\n";
  1827. }
  1828. fout << this->ConvertToXMLOutputPath(source);
  1829. }
  1830. else
  1831. {
  1832. // Write out the dependencies for the rule.
  1833. for(std::vector<std::string>::const_iterator d =
  1834. ccg.GetDepends().begin();
  1835. d != ccg.GetDepends().end();
  1836. ++d)
  1837. {
  1838. // Get the real name of the dependency in case it is a CMake target.
  1839. std::string dep;
  1840. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1841. {
  1842. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1843. << ";";
  1844. }
  1845. }
  1846. }
  1847. fout << "\"\n";
  1848. fout << "\t\t\t\t\tOutputs=\"";
  1849. if(ccg.GetOutputs().empty())
  1850. {
  1851. fout << source << "_force";
  1852. }
  1853. else
  1854. {
  1855. // Write a rule for the output generated by this command.
  1856. const char* sep = "";
  1857. for(std::vector<std::string>::const_iterator o =
  1858. ccg.GetOutputs().begin();
  1859. o != ccg.GetOutputs().end();
  1860. ++o)
  1861. {
  1862. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1863. sep = ";";
  1864. }
  1865. }
  1866. fout << "\"/>\n";
  1867. fout << "\t\t\t\t</FileConfiguration>\n";
  1868. }
  1869. }
  1870. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1871. const char* group,
  1872. const char* )
  1873. {
  1874. fout << "\t\t<Filter\n"
  1875. << "\t\t\tName=\"" << group << "\"\n"
  1876. << "\t\t\tFilter=\"\">\n";
  1877. }
  1878. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1879. {
  1880. fout << "\t\t</Filter>\n";
  1881. }
  1882. // look for custom rules on a target and collect them together
  1883. void cmLocalVisualStudio7Generator
  1884. ::OutputTargetRules(std::ostream& fout,
  1885. const std::string& configName,
  1886. cmTarget &target,
  1887. const std::string& /*libName*/)
  1888. {
  1889. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1890. {
  1891. return;
  1892. }
  1893. EventWriter event(this, configName, fout);
  1894. // Add pre-build event.
  1895. const char* tool =
  1896. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1897. event.Start(tool);
  1898. event.Write(target.GetPreBuildCommands());
  1899. event.Finish();
  1900. // Add pre-link event.
  1901. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1902. event.Start(tool);
  1903. event.Write(target.GetPreLinkCommands());
  1904. cmsys::auto_ptr<cmCustomCommand> pcc(
  1905. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1906. if(pcc.get())
  1907. {
  1908. event.Write(*pcc);
  1909. }
  1910. event.Finish();
  1911. // Add post-build event.
  1912. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1913. event.Start(tool);
  1914. event.Write(target.GetPostBuildCommands());
  1915. event.Finish();
  1916. }
  1917. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1918. cmTarget& target)
  1919. {
  1920. // if we have all the required Source code control tags
  1921. // then add that to the project
  1922. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1923. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1924. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1925. if(vsProvider && vsLocalpath && vsProjectname)
  1926. {
  1927. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1928. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1929. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1930. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1931. if(vsAuxPath)
  1932. {
  1933. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1934. }
  1935. }
  1936. }
  1937. void
  1938. cmLocalVisualStudio7Generator
  1939. ::WriteProjectStartFortran(std::ostream& fout,
  1940. const std::string& libName,
  1941. cmTarget & target)
  1942. {
  1943. cmGlobalVisualStudio7Generator* gg =
  1944. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1945. fout << "<?xml version=\"1.0\" encoding = \""
  1946. << gg->Encoding() << "\"?>\n"
  1947. << "<VisualStudioProject\n"
  1948. << "\tProjectCreator=\"Intel Fortran\"\n"
  1949. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1950. const char* keyword = target.GetProperty("VS_KEYWORD");
  1951. if(!keyword)
  1952. {
  1953. keyword = "Console Application";
  1954. }
  1955. const char* projectType = 0;
  1956. switch(target.GetType())
  1957. {
  1958. case cmTarget::STATIC_LIBRARY:
  1959. projectType = "typeStaticLibrary";
  1960. if(keyword)
  1961. {
  1962. keyword = "Static Library";
  1963. }
  1964. break;
  1965. case cmTarget::SHARED_LIBRARY:
  1966. case cmTarget::MODULE_LIBRARY:
  1967. projectType = "typeDynamicLibrary";
  1968. if(!keyword)
  1969. {
  1970. keyword = "Dll";
  1971. }
  1972. break;
  1973. case cmTarget::EXECUTABLE:
  1974. if(!keyword)
  1975. {
  1976. keyword = "Console Application";
  1977. }
  1978. projectType = 0;
  1979. break;
  1980. case cmTarget::UTILITY:
  1981. case cmTarget::GLOBAL_TARGET:
  1982. default:
  1983. break;
  1984. }
  1985. if(projectType)
  1986. {
  1987. fout << "\tProjectType=\"" << projectType << "\"\n";
  1988. }
  1989. this->WriteProjectSCC(fout, target);
  1990. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1991. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1992. << "\t<Platforms>\n"
  1993. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1994. << "\t</Platforms>\n";
  1995. }
  1996. void
  1997. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1998. const std::string& libName,
  1999. cmTarget & target,
  2000. std::vector<cmSourceGroup> &)
  2001. {
  2002. if(this->FortranProject)
  2003. {
  2004. this->WriteProjectStartFortran(fout, libName, target);
  2005. return;
  2006. }
  2007. cmGlobalVisualStudio7Generator* gg =
  2008. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2009. fout << "<?xml version=\"1.0\" encoding = \""
  2010. << gg->Encoding() << "\"?>\n"
  2011. << "<VisualStudioProject\n"
  2012. << "\tProjectType=\"Visual C++\"\n";
  2013. if(gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71)
  2014. {
  2015. fout << "\tVersion=\"7.10\"\n";
  2016. }
  2017. else
  2018. {
  2019. fout << "\tVersion=\"" << (gg->GetVersion()/10) << ".00\"\n";
  2020. }
  2021. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  2022. if(!projLabel)
  2023. {
  2024. projLabel = libName.c_str();
  2025. }
  2026. const char* keyword = target.GetProperty("VS_KEYWORD");
  2027. if(!keyword)
  2028. {
  2029. keyword = "Win32Proj";
  2030. }
  2031. fout << "\tName=\"" << projLabel << "\"\n";
  2032. if(gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  2033. {
  2034. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  2035. }
  2036. this->WriteProjectSCC(fout, target);
  2037. if(const char* targetFrameworkVersion =
  2038. target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  2039. {
  2040. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  2041. }
  2042. fout << "\tKeyword=\"" << keyword << "\">\n"
  2043. << "\t<Platforms>\n"
  2044. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2045. << "\t</Platforms>\n";
  2046. if(gg->IsMasmEnabled())
  2047. {
  2048. fout <<
  2049. "\t<ToolFiles>\n"
  2050. "\t\t<DefaultToolFile\n"
  2051. "\t\t\tFileName=\"masm.rules\"\n"
  2052. "\t\t/>\n"
  2053. "\t</ToolFiles>\n"
  2054. ;
  2055. }
  2056. }
  2057. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  2058. cmTarget &target)
  2059. {
  2060. fout << "\t<Globals>\n";
  2061. cmPropertyMap const& props = target.GetProperties();
  2062. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  2063. {
  2064. if(i->first.find("VS_GLOBAL_") == 0)
  2065. {
  2066. std::string name = i->first.substr(10);
  2067. if(name != "")
  2068. {
  2069. fout << "\t\t<Global\n"
  2070. << "\t\t\tName=\"" << name << "\"\n"
  2071. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  2072. << "\t\t/>\n";
  2073. }
  2074. }
  2075. }
  2076. fout << "\t</Globals>\n"
  2077. << "</VisualStudioProject>\n";
  2078. }
  2079. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  2080. {
  2081. std::string ret = s;
  2082. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2083. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2084. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2085. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2086. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  2087. return ret;
  2088. }
  2089. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  2090. {
  2091. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  2092. }
  2093. std::string cmLocalVisualStudio7Generator
  2094. ::ConvertToXMLOutputPath(const char* path)
  2095. {
  2096. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2097. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2098. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2099. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2100. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2101. return ret;
  2102. }
  2103. std::string cmLocalVisualStudio7Generator
  2104. ::ConvertToXMLOutputPathSingle(const char* path)
  2105. {
  2106. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2107. cmSystemTools::ReplaceString(ret, "\"", "");
  2108. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2109. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2110. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2111. return ret;
  2112. }
  2113. // This class is used to parse an existing vs 7 project
  2114. // and extract the GUID
  2115. class cmVS7XMLParser : public cmXMLParser
  2116. {
  2117. public:
  2118. virtual void EndElement(const std::string& /* name */)
  2119. {
  2120. }
  2121. virtual void StartElement(const std::string& name, const char** atts)
  2122. {
  2123. // once the GUID is found do nothing
  2124. if(this->GUID.size())
  2125. {
  2126. return;
  2127. }
  2128. int i =0;
  2129. if("VisualStudioProject" == name)
  2130. {
  2131. while(atts[i])
  2132. {
  2133. if(strcmp(atts[i], "ProjectGUID") == 0)
  2134. {
  2135. if(atts[i+1])
  2136. {
  2137. this->GUID = atts[i+1];
  2138. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2139. }
  2140. else
  2141. {
  2142. this->GUID = "";
  2143. }
  2144. return;
  2145. }
  2146. ++i;
  2147. }
  2148. }
  2149. }
  2150. int InitializeParser()
  2151. {
  2152. int ret = cmXMLParser::InitializeParser();
  2153. if(ret == 0)
  2154. {
  2155. return ret;
  2156. }
  2157. // visual studio projects have a strange encoding, but it is
  2158. // really utf-8
  2159. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2160. return 1;
  2161. }
  2162. std::string GUID;
  2163. };
  2164. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2165. const std::string& name,
  2166. const char* path)
  2167. {
  2168. cmVS7XMLParser parser;
  2169. parser.ParseFile(path);
  2170. // if we can not find a GUID then we will generate one later
  2171. if(parser.GUID.size() == 0)
  2172. {
  2173. return;
  2174. }
  2175. std::string guidStoreName = name;
  2176. guidStoreName += "_GUID_CMAKE";
  2177. // save the GUID in the cache
  2178. this->GlobalGenerator->GetCMakeInstance()->
  2179. AddCacheEntry(guidStoreName.c_str(),
  2180. parser.GUID.c_str(),
  2181. "Stored GUID",
  2182. cmState::INTERNAL);
  2183. }
  2184. //----------------------------------------------------------------------------
  2185. std::string cmLocalVisualStudio7Generator
  2186. ::GetTargetDirectory(cmTarget const& target) const
  2187. {
  2188. std::string dir;
  2189. dir += target.GetName();
  2190. dir += ".dir";
  2191. return dir;
  2192. }
  2193. //----------------------------------------------------------------------------
  2194. #include <windows.h>
  2195. static bool cmLVS6G_IsFAT(const char* dir)
  2196. {
  2197. if(dir[0] && dir[1] == ':')
  2198. {
  2199. char volRoot[4] = "_:/";
  2200. volRoot[0] = dir[0];
  2201. char fsName[16];
  2202. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2203. strstr(fsName, "FAT") != 0)
  2204. {
  2205. return true;
  2206. }
  2207. }
  2208. return false;
  2209. }