cmLocalVisualStudio7Generator.cxx 79 KB

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