cmLocalVisualStudio7Generator.cxx 79 KB

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