cmLocalVisualStudio7Generator.cxx 80 KB

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