cmLocalVisualStudio7Generator.cxx 79 KB

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