cmLocalGenerator.cxx 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282
  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 "cmLocalGenerator.h"
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmInstallGenerator.h"
  15. #include "cmInstallFilesGenerator.h"
  16. #include "cmInstallScriptGenerator.h"
  17. #include "cmInstallTargetGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmSourceFile.h"
  20. #include "cmTest.h"
  21. #include "cmTestGenerator.h"
  22. #include "cmVersion.h"
  23. #include "cmake.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. # define CM_LG_ENCODE_OBJECT_NAMES
  26. # include <cmsys/MD5.h>
  27. #endif
  28. #include <cmsys/System.h>
  29. #include <ctype.h> // for isalpha
  30. #include <assert.h>
  31. #if defined(__HAIKU__)
  32. #include <StorageKit.h>
  33. #endif
  34. cmLocalGenerator::cmLocalGenerator()
  35. {
  36. this->Makefile = 0; // moved to after set on global
  37. this->Parent = 0;
  38. this->WindowsShell = false;
  39. this->WindowsVSIDE = false;
  40. this->WatcomWMake = false;
  41. this->MinGWMake = false;
  42. this->NMake = false;
  43. this->MSYSShell = false;
  44. this->LinkScriptShell = false;
  45. this->IgnoreLibPrefix = false;
  46. this->UseRelativePaths = false;
  47. this->Configured = false;
  48. this->EmitUniversalBinaryFlags = true;
  49. this->IsMakefileGenerator = false;
  50. this->RelativePathsConfigured = false;
  51. this->PathConversionsSetup = false;
  52. this->BackwardsCompatibility = 0;
  53. this->BackwardsCompatibilityFinal = false;
  54. }
  55. cmLocalGenerator::~cmLocalGenerator()
  56. {
  57. delete this->Makefile;
  58. }
  59. //----------------------------------------------------------------------------
  60. class cmLocalGeneratorCurrent
  61. {
  62. cmGlobalGenerator* GG;
  63. cmLocalGenerator* LG;
  64. public:
  65. cmLocalGeneratorCurrent(cmLocalGenerator* lg)
  66. {
  67. this->GG = lg->GetGlobalGenerator();
  68. this->LG = this->GG->GetCurrentLocalGenerator();
  69. this->GG->SetCurrentLocalGenerator(lg);
  70. }
  71. ~cmLocalGeneratorCurrent()
  72. {
  73. this->GG->SetCurrentLocalGenerator(this->LG);
  74. }
  75. };
  76. //----------------------------------------------------------------------------
  77. void cmLocalGenerator::Configure()
  78. {
  79. // Manage the global generator's current local generator.
  80. cmLocalGeneratorCurrent clg(this);
  81. static_cast<void>(clg);
  82. // make sure the CMakeFiles dir is there
  83. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  84. filesDir += cmake::GetCMakeFilesDirectory();
  85. cmSystemTools::MakeDirectory(filesDir.c_str());
  86. // find & read the list file
  87. this->ReadInputFile();
  88. // at the end of the ReadListFile handle any old style subdirs
  89. // first get all the subdirectories
  90. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  91. // for each subdir recurse
  92. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  93. for (; sdi != subdirs.end(); ++sdi)
  94. {
  95. if (!(*sdi)->Configured)
  96. {
  97. this->Makefile->ConfigureSubDirectory(*sdi);
  98. }
  99. }
  100. // Check whether relative paths should be used for optionally
  101. // relative paths.
  102. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  103. this->ComputeObjectMaxPath();
  104. this->Configured = true;
  105. }
  106. //----------------------------------------------------------------------------
  107. void cmLocalGenerator::ComputeObjectMaxPath()
  108. {
  109. // Choose a maximum object file name length.
  110. #if defined(_WIN32) || defined(__CYGWIN__)
  111. this->ObjectPathMax = 250;
  112. #else
  113. this->ObjectPathMax = 1000;
  114. #endif
  115. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  116. if(plen && *plen)
  117. {
  118. unsigned int pmax;
  119. if(sscanf(plen, "%u", &pmax) == 1)
  120. {
  121. if(pmax >= 128)
  122. {
  123. this->ObjectPathMax = pmax;
  124. }
  125. else
  126. {
  127. cmOStringStream w;
  128. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  129. << ", which is less than the minimum of 128. "
  130. << "The value will be ignored.";
  131. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  132. }
  133. }
  134. else
  135. {
  136. cmOStringStream w;
  137. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  138. << "\", which fails to parse as a positive integer. "
  139. << "The value will be ignored.";
  140. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  141. }
  142. }
  143. this->ObjectMaxPathViolations.clear();
  144. }
  145. //----------------------------------------------------------------------------
  146. void cmLocalGenerator::ReadInputFile()
  147. {
  148. // Look for the CMakeLists.txt file.
  149. std::string currentStart = this->Makefile->GetStartDirectory();
  150. currentStart += "/CMakeLists.txt";
  151. if(cmSystemTools::FileExists(currentStart.c_str(), true))
  152. {
  153. this->Makefile->ReadListFile(currentStart.c_str());
  154. return;
  155. }
  156. if(!this->Parent)
  157. {
  158. return;
  159. }
  160. // The file is missing. Check policy CMP0014.
  161. cmMakefile* mf = this->Parent->GetMakefile();
  162. cmOStringStream e;
  163. e << "The source directory\n"
  164. << " " << this->Makefile->GetStartDirectory() << "\n"
  165. << "does not contain a CMakeLists.txt file.";
  166. switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
  167. {
  168. case cmPolicies::WARN:
  169. // Print the warning.
  170. e << "\n"
  171. << "CMake does not support this case but it used "
  172. << "to work accidentally and is being allowed for "
  173. << "compatibility."
  174. << "\n"
  175. << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
  176. mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  177. case cmPolicies::OLD:
  178. // OLD behavior does not warn.
  179. return;
  180. case cmPolicies::REQUIRED_IF_USED:
  181. case cmPolicies::REQUIRED_ALWAYS:
  182. e << "\n"
  183. << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
  184. case cmPolicies::NEW:
  185. // NEW behavior prints the error.
  186. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  187. break;
  188. }
  189. }
  190. void cmLocalGenerator::SetupPathConversions()
  191. {
  192. // Setup the current output directory components for use by
  193. // Convert
  194. std::string outdir;
  195. outdir =
  196. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  197. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  198. outdir =
  199. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  200. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  201. outdir = cmSystemTools::CollapseFullPath
  202. (this->Makefile->GetHomeOutputDirectory());
  203. cmSystemTools::SplitPath(outdir.c_str(),
  204. this->HomeOutputDirectoryComponents);
  205. outdir = cmSystemTools::CollapseFullPath
  206. (this->Makefile->GetStartOutputDirectory());
  207. cmSystemTools::SplitPath(outdir.c_str(),
  208. this->StartOutputDirectoryComponents);
  209. }
  210. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  211. {
  212. this->GlobalGenerator = gg;
  213. this->Makefile = new cmMakefile;
  214. this->Makefile->SetLocalGenerator(this);
  215. // setup the home directories
  216. this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
  217. this->Makefile->SetHomeDirectory(
  218. gg->GetCMakeInstance()->GetHomeDirectory());
  219. this->Makefile->SetHomeOutputDirectory(
  220. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  221. }
  222. void cmLocalGenerator::ConfigureFinalPass()
  223. {
  224. this->Makefile->ConfigureFinalPass();
  225. }
  226. void cmLocalGenerator::TraceDependencies()
  227. {
  228. // Generate the rule files for each target.
  229. cmTargets& targets = this->Makefile->GetTargets();
  230. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  231. {
  232. const char* projectFilename = 0;
  233. if (this->IsMakefileGenerator == false) // only use of this variable
  234. {
  235. projectFilename = t->second.GetName();
  236. }
  237. t->second.TraceDependencies(projectFilename);
  238. }
  239. }
  240. void cmLocalGenerator::GenerateTestFiles()
  241. {
  242. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  243. {
  244. return;
  245. }
  246. // Compute the set of configurations.
  247. std::vector<std::string> configurationTypes;
  248. const char* config =
  249. this->Makefile->GetConfigurations(configurationTypes, false);
  250. std::string file = this->Makefile->GetStartOutputDirectory();
  251. file += "/";
  252. file += "CTestTestfile.cmake";
  253. cmGeneratedFileStream fout(file.c_str());
  254. fout.SetCopyIfDifferent(true);
  255. fout << "# CMake generated Testfile for " << std::endl
  256. << "# Source directory: "
  257. << this->Makefile->GetStartDirectory() << std::endl
  258. << "# Build directory: "
  259. << this->Makefile->GetStartOutputDirectory() << std::endl
  260. << "# " << std::endl
  261. << "# This file includes the relevent testing commands "
  262. << "required for " << std::endl
  263. << "# testing this directory and lists subdirectories to "
  264. << "be tested as well." << std::endl;
  265. const char* testIncludeFile =
  266. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  267. if ( testIncludeFile )
  268. {
  269. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  270. }
  271. // Ask each test generator to write its code.
  272. std::vector<cmTestGenerator*> const&
  273. testers = this->Makefile->GetTestGenerators();
  274. for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  275. gi != testers.end(); ++gi)
  276. {
  277. (*gi)->Generate(fout, config, configurationTypes);
  278. }
  279. if ( this->Children.size())
  280. {
  281. size_t i;
  282. for(i = 0; i < this->Children.size(); ++i)
  283. {
  284. fout << "SUBDIRS(";
  285. std::string outP =
  286. this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  287. fout << this->Convert(outP.c_str(),START_OUTPUT);
  288. fout << ")" << std::endl;
  289. }
  290. }
  291. }
  292. //----------------------------------------------------------------------------
  293. void cmLocalGenerator::GenerateInstallRules()
  294. {
  295. // Compute the install prefix.
  296. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  297. #if defined(_WIN32) && !defined(__CYGWIN__)
  298. std::string prefix_win32;
  299. if(!prefix)
  300. {
  301. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  302. {
  303. prefix_win32 = "C:";
  304. }
  305. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  306. if(project_name && project_name[0])
  307. {
  308. prefix_win32 += "/Program Files/";
  309. prefix_win32 += project_name;
  310. }
  311. else
  312. {
  313. prefix_win32 += "/InstalledCMakeProject";
  314. }
  315. prefix = prefix_win32.c_str();
  316. }
  317. #elif defined(__HAIKU__)
  318. if (!prefix)
  319. {
  320. BPath dir;
  321. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  322. {
  323. prefix = dir.Path();
  324. }
  325. else
  326. {
  327. prefix = "/boot/common";
  328. }
  329. }
  330. #else
  331. if (!prefix)
  332. {
  333. prefix = "/usr/local";
  334. }
  335. #endif
  336. // Compute the set of configurations.
  337. std::vector<std::string> configurationTypes;
  338. const char* config =
  339. this->Makefile->GetConfigurations(configurationTypes, false);
  340. // Choose a default install configuration.
  341. const char* default_config = config;
  342. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  343. "RELWITHDEBINFO", "DEBUG", 0};
  344. for(const char** c = default_order; *c && !default_config; ++c)
  345. {
  346. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  347. i != configurationTypes.end(); ++i)
  348. {
  349. if(cmSystemTools::UpperCase(*i) == *c)
  350. {
  351. default_config = i->c_str();
  352. }
  353. }
  354. }
  355. if(!default_config && !configurationTypes.empty())
  356. {
  357. default_config = configurationTypes[0].c_str();
  358. }
  359. if(!default_config)
  360. {
  361. default_config = "Release";
  362. }
  363. // Create the install script file.
  364. std::string file = this->Makefile->GetStartOutputDirectory();
  365. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  366. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  367. cmSystemTools::ConvertToUnixSlashes(file);
  368. cmSystemTools::ConvertToUnixSlashes(homedir);
  369. cmSystemTools::ConvertToUnixSlashes(currdir);
  370. int toplevel_install = 0;
  371. if ( currdir == homedir )
  372. {
  373. toplevel_install = 1;
  374. }
  375. file += "/cmake_install.cmake";
  376. cmGeneratedFileStream fout(file.c_str());
  377. fout.SetCopyIfDifferent(true);
  378. // Write the header.
  379. fout << "# Install script for directory: "
  380. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  381. fout << "# Set the install prefix" << std::endl
  382. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  383. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  384. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  385. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  386. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  387. << std::endl;
  388. // Write support code for generating per-configuration install rules.
  389. fout <<
  390. "# Set the install configuration name.\n"
  391. "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  392. " IF(BUILD_TYPE)\n"
  393. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  394. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  395. " ELSE(BUILD_TYPE)\n"
  396. " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  397. " ENDIF(BUILD_TYPE)\n"
  398. " MESSAGE(STATUS \"Install configuration: "
  399. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  400. "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  401. "\n";
  402. // Write support code for dealing with component-specific installs.
  403. fout <<
  404. "# Set the component getting installed.\n"
  405. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  406. " IF(COMPONENT)\n"
  407. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  408. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  409. " ELSE(COMPONENT)\n"
  410. " SET(CMAKE_INSTALL_COMPONENT)\n"
  411. " ENDIF(COMPONENT)\n"
  412. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  413. "\n";
  414. // Copy user-specified install options to the install code.
  415. if(const char* so_no_exe =
  416. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  417. {
  418. fout <<
  419. "# Install shared libraries without execute permission?\n"
  420. "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  421. " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  422. "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  423. "\n";
  424. }
  425. // Ask each install generator to write its code.
  426. std::vector<cmInstallGenerator*> const& installers =
  427. this->Makefile->GetInstallGenerators();
  428. for(std::vector<cmInstallGenerator*>::const_iterator
  429. gi = installers.begin();
  430. gi != installers.end(); ++gi)
  431. {
  432. (*gi)->Generate(fout, config, configurationTypes);
  433. }
  434. // Write rules from old-style specification stored in targets.
  435. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  436. // Include install scripts from subdirectories.
  437. if(!this->Children.empty())
  438. {
  439. fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  440. fout << " # Include the install script for each subdirectory.\n";
  441. for(std::vector<cmLocalGenerator*>::const_iterator
  442. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  443. {
  444. if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  445. {
  446. std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
  447. cmSystemTools::ConvertToUnixSlashes(odir);
  448. fout << " INCLUDE(\"" << odir.c_str()
  449. << "/cmake_install.cmake\")" << std::endl;
  450. }
  451. }
  452. fout << "\n";
  453. fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
  454. }
  455. // Record the install manifest.
  456. if ( toplevel_install )
  457. {
  458. fout <<
  459. "IF(CMAKE_INSTALL_COMPONENT)\n"
  460. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  461. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  462. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  463. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  464. "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
  465. fout
  466. << "FILE(WRITE \""
  467. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  468. << "\"\")" << std::endl;
  469. fout
  470. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  471. << " FILE(APPEND \""
  472. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  473. << "\"${file}\\n\")" << std::endl
  474. << "ENDFOREACH(file)" << std::endl;
  475. }
  476. }
  477. //----------------------------------------------------------------------------
  478. void cmLocalGenerator::GenerateTargetManifest()
  479. {
  480. // Collect the set of configuration types.
  481. std::vector<std::string> configNames;
  482. this->Makefile->GetConfigurations(configNames);
  483. // Add our targets to the manifest for each configuration.
  484. cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
  485. for(cmGeneratorTargetsType::iterator t = targets.begin();
  486. t != targets.end(); ++t)
  487. {
  488. cmGeneratorTarget& target = *t->second;
  489. if(configNames.empty())
  490. {
  491. target.GenerateTargetManifest(0);
  492. }
  493. else
  494. {
  495. for(std::vector<std::string>::iterator ci = configNames.begin();
  496. ci != configNames.end(); ++ci)
  497. {
  498. const char* config = ci->c_str();
  499. target.GenerateTargetManifest(config);
  500. }
  501. }
  502. }
  503. }
  504. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  505. const char* lang,
  506. cmSourceFile& source,
  507. cmTarget& target)
  508. {
  509. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  510. objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
  511. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  512. std::string sourceFile =
  513. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  514. std::string varString = "CMAKE_";
  515. varString += lang;
  516. varString += "_COMPILE_OBJECT";
  517. std::vector<std::string> rules;
  518. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  519. varString = "CMAKE_";
  520. varString += lang;
  521. varString += "_FLAGS";
  522. std::string flags;
  523. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  524. flags += " ";
  525. {
  526. std::vector<std::string> includes;
  527. this->GetIncludeDirectories(includes, &target, lang);
  528. flags += this->GetIncludeFlags(includes, lang);
  529. }
  530. flags += this->Makefile->GetDefineFlags();
  531. // Construct the command lines.
  532. cmCustomCommandLines commandLines;
  533. std::vector<std::string> commands;
  534. cmSystemTools::ExpandList(rules, commands);
  535. cmLocalGenerator::RuleVariables vars;
  536. vars.Language = lang;
  537. vars.Source = sourceFile.c_str();
  538. vars.Object = objectFile.c_str();
  539. vars.ObjectDir = objectDir.c_str();
  540. vars.Flags = flags.c_str();
  541. for(std::vector<std::string>::iterator i = commands.begin();
  542. i != commands.end(); ++i)
  543. {
  544. // Expand the full command line string.
  545. this->ExpandRuleVariables(*i, vars);
  546. // Parse the string to get the custom command line.
  547. cmCustomCommandLine commandLine;
  548. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  549. for(std::vector<cmStdString>::iterator a = cmd.begin();
  550. a != cmd.end(); ++a)
  551. {
  552. commandLine.push_back(*a);
  553. }
  554. // Store this command line.
  555. commandLines.push_back(commandLine);
  556. }
  557. // Check for extra object-file dependencies.
  558. std::vector<std::string> depends;
  559. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  560. if(additionalDeps)
  561. {
  562. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  563. }
  564. // Generate a meaningful comment for the command.
  565. std::string comment = "Building ";
  566. comment += lang;
  567. comment += " object ";
  568. comment += this->Convert(ofname, START_OUTPUT);
  569. // Add the custom command to build the object file.
  570. this->Makefile->AddCustomCommandToOutput(
  571. ofname,
  572. depends,
  573. source.GetFullPath().c_str(),
  574. commandLines,
  575. comment.c_str(),
  576. this->Makefile->GetStartOutputDirectory()
  577. );
  578. }
  579. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  580. {
  581. cmStdString objs;
  582. std::vector<std::string> objVector;
  583. // Add all the sources outputs to the depends of the target
  584. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  585. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  586. i != classes.end(); ++i)
  587. {
  588. cmSourceFile* sf = *i;
  589. if(!sf->GetCustomCommand() &&
  590. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  591. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  592. {
  593. std::string dir_max;
  594. dir_max += this->Makefile->GetCurrentOutputDirectory();
  595. dir_max += "/";
  596. std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
  597. if(!obj.empty())
  598. {
  599. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  600. ofname += "/";
  601. ofname += obj;
  602. objVector.push_back(ofname);
  603. this->AddCustomCommandToCreateObject(ofname.c_str(),
  604. llang, *(*i), target);
  605. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  606. objs += " ";
  607. }
  608. }
  609. }
  610. std::string createRule = "CMAKE_";
  611. createRule += llang;
  612. createRule += target.GetCreateRuleVariable();
  613. std::string targetName = target.GetFullName();
  614. // Executable :
  615. // Shared Library:
  616. // Static Library:
  617. // Shared Module:
  618. std::string linkLibs; // should be set
  619. std::string flags; // should be set
  620. std::string linkFlags; // should be set
  621. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  622. cmLocalGenerator::RuleVariables vars;
  623. vars.Language = llang;
  624. vars.Objects = objs.c_str();
  625. vars.ObjectDir = ".";
  626. vars.Target = targetName.c_str();
  627. vars.LinkLibraries = linkLibs.c_str();
  628. vars.Flags = flags.c_str();
  629. vars.LinkFlags = linkFlags.c_str();
  630. std::string langFlags;
  631. this->AddLanguageFlags(langFlags, llang, 0);
  632. this->AddArchitectureFlags(langFlags, &target, llang, 0);
  633. vars.LanguageCompileFlags = langFlags.c_str();
  634. cmCustomCommandLines commandLines;
  635. std::vector<std::string> rules;
  636. rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
  637. std::vector<std::string> commands;
  638. cmSystemTools::ExpandList(rules, commands);
  639. for(std::vector<std::string>::iterator i = commands.begin();
  640. i != commands.end(); ++i)
  641. {
  642. // Expand the full command line string.
  643. this->ExpandRuleVariables(*i, vars);
  644. // Parse the string to get the custom command line.
  645. cmCustomCommandLine commandLine;
  646. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  647. for(std::vector<cmStdString>::iterator a = cmd.begin();
  648. a != cmd.end(); ++a)
  649. {
  650. commandLine.push_back(*a);
  651. }
  652. // Store this command line.
  653. commandLines.push_back(commandLine);
  654. }
  655. std::string targetFullPath = target.GetFullPath();
  656. // Generate a meaningful comment for the command.
  657. std::string comment = "Linking ";
  658. comment += llang;
  659. comment += " target ";
  660. comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
  661. this->Makefile->AddCustomCommandToOutput(
  662. targetFullPath.c_str(),
  663. objVector,
  664. 0,
  665. commandLines,
  666. comment.c_str(),
  667. this->Makefile->GetStartOutputDirectory()
  668. );
  669. target.AddSourceFile
  670. (this->Makefile->GetSource(targetFullPath.c_str()));
  671. }
  672. void cmLocalGenerator
  673. ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  674. {
  675. cmTargets &tgts = this->Makefile->GetTargets();
  676. for(cmTargets::iterator l = tgts.begin();
  677. l != tgts.end(); l++)
  678. {
  679. cmTarget& target = l->second;
  680. switch(target.GetType())
  681. {
  682. case cmTarget::STATIC_LIBRARY:
  683. case cmTarget::SHARED_LIBRARY:
  684. case cmTarget::MODULE_LIBRARY:
  685. case cmTarget::EXECUTABLE:
  686. {
  687. const char* llang = target.GetLinkerLanguage();
  688. if(!llang)
  689. {
  690. cmSystemTools::Error
  691. ("CMake can not determine linker language for target:",
  692. target.GetName());
  693. return;
  694. }
  695. // if the language is not in the set lang then create custom
  696. // commands to build the target
  697. if(lang.count(llang) == 0)
  698. {
  699. this->AddBuildTargetRule(llang, target);
  700. }
  701. }
  702. break;
  703. default:
  704. break;
  705. }
  706. }
  707. }
  708. // List of variables that are replaced when
  709. // rules are expanced. These variables are
  710. // replaced in the form <var> with GetSafeDefinition(var).
  711. // ${LANG} is replaced in the variable first with all enabled
  712. // languages.
  713. static const char* ruleReplaceVars[] =
  714. {
  715. "CMAKE_${LANG}_COMPILER",
  716. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  717. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  718. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  719. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  720. "CMAKE_${LANG}_LINK_FLAGS",
  721. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  722. "CMAKE_${LANG}_ARCHIVE",
  723. "CMAKE_AR",
  724. "CMAKE_CURRENT_SOURCE_DIR",
  725. "CMAKE_CURRENT_BINARY_DIR",
  726. "CMAKE_RANLIB",
  727. "CMAKE_LINKER",
  728. 0
  729. };
  730. std::string
  731. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  732. const RuleVariables& replaceValues)
  733. {
  734. if(replaceValues.LinkFlags)
  735. {
  736. if(variable == "LINK_FLAGS")
  737. {
  738. return replaceValues.LinkFlags;
  739. }
  740. }
  741. if(replaceValues.Flags)
  742. {
  743. if(variable == "FLAGS")
  744. {
  745. return replaceValues.Flags;
  746. }
  747. }
  748. if(replaceValues.Source)
  749. {
  750. if(variable == "SOURCE")
  751. {
  752. return replaceValues.Source;
  753. }
  754. }
  755. if(replaceValues.PreprocessedSource)
  756. {
  757. if(variable == "PREPROCESSED_SOURCE")
  758. {
  759. return replaceValues.PreprocessedSource;
  760. }
  761. }
  762. if(replaceValues.AssemblySource)
  763. {
  764. if(variable == "ASSEMBLY_SOURCE")
  765. {
  766. return replaceValues.AssemblySource;
  767. }
  768. }
  769. if(replaceValues.Object)
  770. {
  771. if(variable == "OBJECT")
  772. {
  773. return replaceValues.Object;
  774. }
  775. }
  776. if(replaceValues.ObjectDir)
  777. {
  778. if(variable == "OBJECT_DIR")
  779. {
  780. return replaceValues.ObjectDir;
  781. }
  782. }
  783. if(replaceValues.Objects)
  784. {
  785. if(variable == "OBJECTS")
  786. {
  787. return replaceValues.Objects;
  788. }
  789. }
  790. if(replaceValues.ObjectsQuoted)
  791. {
  792. if(variable == "OBJECTS_QUOTED")
  793. {
  794. return replaceValues.ObjectsQuoted;
  795. }
  796. }
  797. if(replaceValues.Defines && variable == "DEFINES")
  798. {
  799. return replaceValues.Defines;
  800. }
  801. if(replaceValues.TargetPDB )
  802. {
  803. if(variable == "TARGET_PDB")
  804. {
  805. return replaceValues.TargetPDB;
  806. }
  807. }
  808. if(replaceValues.DependencyFile )
  809. {
  810. if(variable == "DEP_FILE")
  811. {
  812. return replaceValues.DependencyFile;
  813. }
  814. }
  815. if(replaceValues.Target)
  816. {
  817. if(variable == "TARGET_QUOTED")
  818. {
  819. std::string targetQuoted = replaceValues.Target;
  820. if(targetQuoted.size() && targetQuoted[0] != '\"')
  821. {
  822. targetQuoted = '\"';
  823. targetQuoted += replaceValues.Target;
  824. targetQuoted += '\"';
  825. }
  826. return targetQuoted;
  827. }
  828. if(variable == "TARGET_UNQUOTED")
  829. {
  830. std::string unquoted = replaceValues.Target;
  831. std::string::size_type sz = unquoted.size();
  832. if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
  833. {
  834. unquoted = unquoted.substr(1, sz-2);
  835. }
  836. return unquoted;
  837. }
  838. if(replaceValues.LanguageCompileFlags)
  839. {
  840. if(variable == "LANGUAGE_COMPILE_FLAGS")
  841. {
  842. return replaceValues.LanguageCompileFlags;
  843. }
  844. }
  845. if(replaceValues.Target)
  846. {
  847. if(variable == "TARGET")
  848. {
  849. return replaceValues.Target;
  850. }
  851. }
  852. if(variable == "TARGET_IMPLIB")
  853. {
  854. return this->TargetImplib;
  855. }
  856. if(variable == "TARGET_VERSION_MAJOR")
  857. {
  858. if(replaceValues.TargetVersionMajor)
  859. {
  860. return replaceValues.TargetVersionMajor;
  861. }
  862. else
  863. {
  864. return "0";
  865. }
  866. }
  867. if(variable == "TARGET_VERSION_MINOR")
  868. {
  869. if(replaceValues.TargetVersionMinor)
  870. {
  871. return replaceValues.TargetVersionMinor;
  872. }
  873. else
  874. {
  875. return "0";
  876. }
  877. }
  878. if(replaceValues.Target)
  879. {
  880. if(variable == "TARGET_BASE")
  881. {
  882. // Strip the last extension off the target name.
  883. std::string targetBase = replaceValues.Target;
  884. std::string::size_type pos = targetBase.rfind(".");
  885. if(pos != targetBase.npos)
  886. {
  887. return targetBase.substr(0, pos);
  888. }
  889. else
  890. {
  891. return targetBase;
  892. }
  893. }
  894. }
  895. }
  896. if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  897. variable == "TARGET_INSTALLNAME_DIR")
  898. {
  899. // All these variables depend on TargetSOName
  900. if(replaceValues.TargetSOName)
  901. {
  902. if(variable == "TARGET_SONAME")
  903. {
  904. return replaceValues.TargetSOName;
  905. }
  906. if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
  907. {
  908. return replaceValues.SONameFlag;
  909. }
  910. if(replaceValues.TargetInstallNameDir &&
  911. variable == "TARGET_INSTALLNAME_DIR")
  912. {
  913. return replaceValues.TargetInstallNameDir;
  914. }
  915. }
  916. return "";
  917. }
  918. if(replaceValues.LinkLibraries)
  919. {
  920. if(variable == "LINK_LIBRARIES")
  921. {
  922. return replaceValues.LinkLibraries;
  923. }
  924. }
  925. if(replaceValues.Language)
  926. {
  927. if(variable == "LANGUAGE")
  928. {
  929. return replaceValues.Language;
  930. }
  931. }
  932. if(replaceValues.CMTarget)
  933. {
  934. if(variable == "TARGET_NAME")
  935. {
  936. return replaceValues.CMTarget->GetName();
  937. }
  938. if(variable == "TARGET_TYPE")
  939. {
  940. return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
  941. }
  942. }
  943. if(replaceValues.Output)
  944. {
  945. if(variable == "OUTPUT")
  946. {
  947. return replaceValues.Output;
  948. }
  949. }
  950. if(variable == "CMAKE_COMMAND")
  951. {
  952. const char* cmcommand =
  953. this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  954. return this->Convert(cmcommand, FULL, SHELL);
  955. }
  956. std::vector<std::string> enabledLanguages;
  957. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  958. // loop over language specific replace variables
  959. int pos = 0;
  960. while(ruleReplaceVars[pos])
  961. {
  962. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  963. i != enabledLanguages.end(); ++i)
  964. {
  965. const char* lang = i->c_str();
  966. std::string actualReplace = ruleReplaceVars[pos];
  967. // If this is the compiler then look for the extra variable
  968. // _COMPILER_ARG1 which must be the first argument to the compiler
  969. const char* compilerArg1 = 0;
  970. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  971. {
  972. std::string arg1 = actualReplace + "_ARG1";
  973. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  974. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  975. }
  976. if(actualReplace.find("${LANG}") != actualReplace.npos)
  977. {
  978. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  979. }
  980. if(actualReplace == variable)
  981. {
  982. std::string replace =
  983. this->Makefile->GetSafeDefinition(variable.c_str());
  984. // if the variable is not a FLAG then treat it like a path
  985. if(variable.find("_FLAG") == variable.npos)
  986. {
  987. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  988. // if there is a required first argument to the compiler add it
  989. // to the compiler string
  990. if(compilerArg1)
  991. {
  992. ret += " ";
  993. ret += compilerArg1;
  994. }
  995. return ret;
  996. }
  997. return replace;
  998. }
  999. }
  1000. pos++;
  1001. }
  1002. return variable;
  1003. }
  1004. void
  1005. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  1006. const RuleVariables& replaceValues)
  1007. {
  1008. std::vector<std::string> enabledLanguages;
  1009. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  1010. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  1011. replaceValues.RuleLauncher);
  1012. std::string::size_type start = s.find('<');
  1013. // no variables to expand
  1014. if(start == s.npos)
  1015. {
  1016. return;
  1017. }
  1018. std::string::size_type pos = 0;
  1019. std::string expandedInput;
  1020. while(start != s.npos && start < s.size()-2)
  1021. {
  1022. std::string::size_type end = s.find('>', start);
  1023. // if we find a < with no > we are done
  1024. if(end == s.npos)
  1025. {
  1026. return;
  1027. }
  1028. char c = s[start+1];
  1029. // if the next char after the < is not A-Za-z then
  1030. // skip it and try to find the next < in the string
  1031. if(!isalpha(c))
  1032. {
  1033. start = s.find('<', start+1);
  1034. }
  1035. else
  1036. {
  1037. // extract the var
  1038. std::string var = s.substr(start+1, end - start-1);
  1039. std::string replace = this->ExpandRuleVariable(var,
  1040. replaceValues);
  1041. expandedInput += s.substr(pos, start-pos);
  1042. expandedInput += replace;
  1043. // move to next one
  1044. start = s.find('<', start+var.size()+2);
  1045. pos = end+1;
  1046. }
  1047. }
  1048. // add the rest of the input
  1049. expandedInput += s.substr(pos, s.size()-pos);
  1050. s = expandedInput;
  1051. }
  1052. //----------------------------------------------------------------------------
  1053. const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
  1054. const char* prop)
  1055. {
  1056. if(target)
  1057. {
  1058. return target->GetProperty(prop);
  1059. }
  1060. else
  1061. {
  1062. return this->Makefile->GetProperty(prop);
  1063. }
  1064. }
  1065. //----------------------------------------------------------------------------
  1066. void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
  1067. const char* prop)
  1068. {
  1069. if(const char* val = this->GetRuleLauncher(target, prop))
  1070. {
  1071. cmOStringStream wrapped;
  1072. wrapped << val << " " << s;
  1073. s = wrapped.str();
  1074. }
  1075. }
  1076. //----------------------------------------------------------------------------
  1077. std::string
  1078. cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
  1079. std::string const& result)
  1080. {
  1081. // If this is a windows shell, the result has a space, and the path
  1082. // already exists, we can use a short-path to reference it without a
  1083. // space.
  1084. if(this->WindowsShell && result.find(' ') != result.npos &&
  1085. cmSystemTools::FileExists(remote))
  1086. {
  1087. std::string tmp;
  1088. if(cmSystemTools::GetShortPath(remote, tmp))
  1089. {
  1090. return this->Convert(tmp.c_str(), NONE, SHELL, true);
  1091. }
  1092. }
  1093. // Otherwise, leave it unchanged.
  1094. return result;
  1095. }
  1096. //----------------------------------------------------------------------------
  1097. std::string
  1098. cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
  1099. RelativeRoot local)
  1100. {
  1101. // Perform standard conversion.
  1102. std::string result = this->Convert(remote, local, SHELL, true);
  1103. // Consider short-path.
  1104. return this->ConvertToOutputForExistingCommon(remote, result);
  1105. }
  1106. //----------------------------------------------------------------------------
  1107. std::string
  1108. cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
  1109. const char* local)
  1110. {
  1111. // Perform standard conversion.
  1112. std::string result = this->Convert(remote, local, SHELL, true);
  1113. // Consider short-path.
  1114. const char* remotePath = this->GetRelativeRootPath(remote);
  1115. return this->ConvertToOutputForExistingCommon(remotePath, result);
  1116. }
  1117. //----------------------------------------------------------------------------
  1118. std::string
  1119. cmLocalGenerator::ConvertToIncludeReference(std::string const& path)
  1120. {
  1121. return this->ConvertToOutputForExisting(path.c_str());
  1122. }
  1123. //----------------------------------------------------------------------------
  1124. std::string cmLocalGenerator::GetIncludeFlags(
  1125. const std::vector<std::string> &includes,
  1126. const char* lang, bool forResponseFile)
  1127. {
  1128. if(!lang)
  1129. {
  1130. return "";
  1131. }
  1132. cmOStringStream includeFlags;
  1133. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  1134. flagVar += lang;
  1135. const char* includeFlag =
  1136. this->Makefile->GetSafeDefinition(flagVar.c_str());
  1137. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  1138. flagVar += lang;
  1139. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  1140. bool quotePaths = false;
  1141. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  1142. {
  1143. quotePaths = true;
  1144. }
  1145. bool repeatFlag = true;
  1146. // should the include flag be repeated like ie. -IA -IB
  1147. if(!sep)
  1148. {
  1149. sep = " ";
  1150. }
  1151. else
  1152. {
  1153. // if there is a separator then the flag is not repeated but is only
  1154. // given once i.e. -classpath a:b:c
  1155. repeatFlag = false;
  1156. }
  1157. // Support special system include flag if it is available and the
  1158. // normal flag is repeated for each directory.
  1159. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1160. sysFlagVar += lang;
  1161. const char* sysIncludeFlag = 0;
  1162. if(repeatFlag)
  1163. {
  1164. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
  1165. }
  1166. bool flagUsed = false;
  1167. std::set<cmStdString> emitted;
  1168. #ifdef __APPLE__
  1169. emitted.insert("/System/Library/Frameworks");
  1170. #endif
  1171. std::vector<std::string>::const_iterator i;
  1172. for(i = includes.begin(); i != includes.end(); ++i)
  1173. {
  1174. if(this->Makefile->IsOn("APPLE")
  1175. && cmSystemTools::IsPathToFramework(i->c_str()))
  1176. {
  1177. std::string frameworkDir = *i;
  1178. frameworkDir += "/../";
  1179. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1180. if(emitted.insert(frameworkDir).second)
  1181. {
  1182. OutputFormat format = forResponseFile? RESPONSE : SHELL;
  1183. includeFlags
  1184. << "-F" << this->Convert(frameworkDir.c_str(),
  1185. START_OUTPUT, format, true)
  1186. << " ";
  1187. }
  1188. continue;
  1189. }
  1190. std::string include = *i;
  1191. if(!flagUsed || repeatFlag)
  1192. {
  1193. if(sysIncludeFlag &&
  1194. this->Makefile->IsSystemIncludeDirectory(i->c_str()))
  1195. {
  1196. includeFlags << sysIncludeFlag;
  1197. }
  1198. else
  1199. {
  1200. includeFlags << includeFlag;
  1201. }
  1202. flagUsed = true;
  1203. }
  1204. std::string includePath;
  1205. if(forResponseFile)
  1206. {
  1207. includePath = this->Convert(i->c_str(), START_OUTPUT,
  1208. RESPONSE, true);
  1209. }
  1210. else
  1211. {
  1212. includePath = this->ConvertToIncludeReference(*i);
  1213. }
  1214. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1215. {
  1216. includeFlags << "\"";
  1217. }
  1218. includeFlags << includePath;
  1219. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1220. {
  1221. includeFlags << "\"";
  1222. }
  1223. includeFlags << sep;
  1224. }
  1225. std::string flags = includeFlags.str();
  1226. // remove trailing separators
  1227. if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
  1228. {
  1229. flags[flags.size()-1] = ' ';
  1230. }
  1231. return flags;
  1232. }
  1233. //----------------------------------------------------------------------------
  1234. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1235. cmTarget* target,
  1236. const char* lang)
  1237. {
  1238. // Need to decide whether to automatically include the source and
  1239. // binary directories at the beginning of the include path.
  1240. bool includeSourceDir = false;
  1241. bool includeBinaryDir = false;
  1242. // When automatic include directories are requested for a build then
  1243. // include the source and binary directories at the beginning of the
  1244. // include path to approximate include file behavior for an
  1245. // in-source build. This does not account for the case of a source
  1246. // file in a subdirectory of the current source directory but we
  1247. // cannot fix this because not all native build tools support
  1248. // per-source-file include paths.
  1249. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1250. {
  1251. includeSourceDir = true;
  1252. includeBinaryDir = true;
  1253. }
  1254. // CMake versions below 2.0 would add the source tree to the -I path
  1255. // automatically. Preserve compatibility.
  1256. if(this->NeedBackwardsCompatibility(1,9))
  1257. {
  1258. includeSourceDir = true;
  1259. }
  1260. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  1261. // not set the backwards compatibility level automatically.
  1262. const char* vtkSourceDir =
  1263. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  1264. if(vtkSourceDir)
  1265. {
  1266. const char* vtk_major =
  1267. this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  1268. const char* vtk_minor =
  1269. this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  1270. vtk_major = vtk_major? vtk_major : "4";
  1271. vtk_minor = vtk_minor? vtk_minor : "4";
  1272. int vmajor = 0;
  1273. int vminor = 0;
  1274. if(sscanf(vtk_major, "%d", &vmajor) &&
  1275. sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
  1276. {
  1277. includeSourceDir = true;
  1278. }
  1279. }
  1280. // Do not repeat an include path.
  1281. std::set<cmStdString> emitted;
  1282. // Store the automatic include paths.
  1283. if(includeBinaryDir)
  1284. {
  1285. if(emitted.find(
  1286. this->Makefile->GetStartOutputDirectory()) == emitted.end())
  1287. {
  1288. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  1289. emitted.insert(this->Makefile->GetStartOutputDirectory());
  1290. }
  1291. }
  1292. if(includeSourceDir)
  1293. {
  1294. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  1295. {
  1296. dirs.push_back(this->Makefile->GetStartDirectory());
  1297. emitted.insert(this->Makefile->GetStartDirectory());
  1298. }
  1299. }
  1300. // Load implicit include directories for this language.
  1301. std::string impDirVar = "CMAKE_";
  1302. impDirVar += lang;
  1303. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1304. if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
  1305. {
  1306. std::vector<std::string> impDirVec;
  1307. cmSystemTools::ExpandListArgument(value, impDirVec);
  1308. for(std::vector<std::string>::const_iterator i = impDirVec.begin();
  1309. i != impDirVec.end(); ++i)
  1310. {
  1311. emitted.insert(*i);
  1312. }
  1313. }
  1314. // Get the target-specific include directories.
  1315. std::vector<std::string> includes;
  1316. if(target)
  1317. {
  1318. includes = target->GetIncludeDirectories();
  1319. }
  1320. // Support putting all the in-project include directories first if
  1321. // it is requested by the project.
  1322. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1323. {
  1324. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1325. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1326. for(std::vector<std::string>::const_iterator i = includes.begin();
  1327. i != includes.end(); ++i)
  1328. {
  1329. // Emit this directory only if it is a subdirectory of the
  1330. // top-level source or binary tree.
  1331. if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
  1332. cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
  1333. cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
  1334. cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
  1335. {
  1336. if(emitted.insert(*i).second)
  1337. {
  1338. dirs.push_back(*i);
  1339. }
  1340. }
  1341. }
  1342. }
  1343. // Construct the final ordered include directory list.
  1344. for(std::vector<std::string>::const_iterator i = includes.begin();
  1345. i != includes.end(); ++i)
  1346. {
  1347. if(emitted.insert(*i).second)
  1348. {
  1349. dirs.push_back(*i);
  1350. }
  1351. }
  1352. }
  1353. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1354. std::string& flags,
  1355. std::string& linkFlags,
  1356. cmTarget& target)
  1357. {
  1358. std::string buildType =
  1359. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1360. buildType = cmSystemTools::UpperCase(buildType);
  1361. const char* libraryLinkVariable =
  1362. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1363. switch(target.GetType())
  1364. {
  1365. case cmTarget::STATIC_LIBRARY:
  1366. {
  1367. const char* targetLinkFlags =
  1368. target.GetProperty("STATIC_LIBRARY_FLAGS");
  1369. if(targetLinkFlags)
  1370. {
  1371. linkFlags += targetLinkFlags;
  1372. linkFlags += " ";
  1373. }
  1374. if(!buildType.empty())
  1375. {
  1376. std::string build = "STATIC_LIBRARY_FLAGS_";
  1377. build += buildType;
  1378. targetLinkFlags = target.GetProperty(build.c_str());
  1379. if(targetLinkFlags)
  1380. {
  1381. linkFlags += targetLinkFlags;
  1382. linkFlags += " ";
  1383. }
  1384. }
  1385. }
  1386. break;
  1387. case cmTarget::MODULE_LIBRARY:
  1388. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1389. case cmTarget::SHARED_LIBRARY:
  1390. {
  1391. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1392. linkFlags += " ";
  1393. if(!buildType.empty())
  1394. {
  1395. std::string build = libraryLinkVariable;
  1396. build += "_";
  1397. build += buildType;
  1398. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1399. linkFlags += " ";
  1400. }
  1401. if(this->Makefile->IsOn("WIN32") &&
  1402. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1403. {
  1404. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1405. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1406. i != sources.end(); ++i)
  1407. {
  1408. cmSourceFile* sf = *i;
  1409. if(sf->GetExtension() == "def")
  1410. {
  1411. linkFlags +=
  1412. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1413. linkFlags += this->Convert(sf->GetFullPath().c_str(),
  1414. FULL, SHELL);
  1415. linkFlags += " ";
  1416. }
  1417. }
  1418. }
  1419. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1420. if(targetLinkFlags)
  1421. {
  1422. linkFlags += targetLinkFlags;
  1423. linkFlags += " ";
  1424. }
  1425. if(!buildType.empty())
  1426. {
  1427. std::string configLinkFlags = "LINK_FLAGS_";
  1428. configLinkFlags += buildType;
  1429. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1430. if(targetLinkFlags)
  1431. {
  1432. linkFlags += targetLinkFlags;
  1433. linkFlags += " ";
  1434. }
  1435. }
  1436. cmOStringStream linklibsStr;
  1437. this->OutputLinkLibraries(linklibsStr, target, false);
  1438. linkLibs = linklibsStr.str();
  1439. }
  1440. break;
  1441. case cmTarget::EXECUTABLE:
  1442. {
  1443. linkFlags +=
  1444. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1445. linkFlags += " ";
  1446. if(!buildType.empty())
  1447. {
  1448. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1449. build += buildType;
  1450. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1451. linkFlags += " ";
  1452. }
  1453. const char* linkLanguage = target.GetLinkerLanguage();
  1454. if(!linkLanguage)
  1455. {
  1456. cmSystemTools::Error
  1457. ("CMake can not determine linker language for target:",
  1458. target.GetName());
  1459. return;
  1460. }
  1461. this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
  1462. cmOStringStream linklibs;
  1463. this->OutputLinkLibraries(linklibs, target, false);
  1464. linkLibs = linklibs.str();
  1465. if(cmSystemTools::IsOn
  1466. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1467. {
  1468. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1469. + linkLanguage + std::string("_FLAGS");
  1470. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1471. linkFlags += " ";
  1472. }
  1473. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1474. {
  1475. linkFlags +=
  1476. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1477. linkFlags += " ";
  1478. }
  1479. else
  1480. {
  1481. linkFlags +=
  1482. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1483. linkFlags += " ";
  1484. }
  1485. if (target.IsExecutableWithExports())
  1486. {
  1487. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1488. exportFlagVar += linkLanguage;
  1489. exportFlagVar += "_FLAG";
  1490. linkFlags +=
  1491. this->Makefile->GetSafeDefinition(exportFlagVar.c_str());
  1492. linkFlags += " ";
  1493. }
  1494. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1495. if(targetLinkFlags)
  1496. {
  1497. linkFlags += targetLinkFlags;
  1498. linkFlags += " ";
  1499. }
  1500. if(!buildType.empty())
  1501. {
  1502. std::string configLinkFlags = "LINK_FLAGS_";
  1503. configLinkFlags += buildType;
  1504. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1505. if(targetLinkFlags)
  1506. {
  1507. linkFlags += targetLinkFlags;
  1508. linkFlags += " ";
  1509. }
  1510. }
  1511. }
  1512. break;
  1513. default:
  1514. break;
  1515. }
  1516. }
  1517. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
  1518. {
  1519. #if defined(_WIN32) && !defined(__CYGWIN__)
  1520. // Work-ardound command line parsing limitations in MSVC 6.0 and
  1521. // Watcom.
  1522. if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
  1523. {
  1524. // Search for the last space.
  1525. std::string::size_type pos = lib.rfind(' ');
  1526. if(pos != lib.npos)
  1527. {
  1528. // Find the slash after the last space, if any.
  1529. pos = lib.find('/', pos);
  1530. // Convert the portion of the path with a space to a short path.
  1531. std::string sp;
  1532. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1533. {
  1534. // Append the rest of the path with no space.
  1535. sp += lib.substr(pos);
  1536. // Convert to an output path.
  1537. return this->Convert(sp.c_str(), NONE, SHELL);
  1538. }
  1539. }
  1540. }
  1541. #endif
  1542. // Normal behavior.
  1543. return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
  1544. }
  1545. /**
  1546. * Output the linking rules on a command line. For executables,
  1547. * targetLibrary should be a NULL pointer. For libraries, it should point
  1548. * to the name of the library. This will not link a library against itself.
  1549. */
  1550. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1551. cmTarget& tgt,
  1552. bool relink)
  1553. {
  1554. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1555. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1556. if(!pcli)
  1557. {
  1558. return;
  1559. }
  1560. cmComputeLinkInformation& cli = *pcli;
  1561. // Collect library linking flags command line options.
  1562. std::string linkLibs;
  1563. const char* linkLanguage = cli.GetLinkLanguage();
  1564. std::string libPathFlag =
  1565. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1566. std::string libPathTerminator =
  1567. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1568. // Flags to link an executable to shared libraries.
  1569. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1570. linkFlagsVar += linkLanguage;
  1571. linkFlagsVar += "_FLAGS";
  1572. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1573. {
  1574. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1575. linkLibs += " ";
  1576. }
  1577. // Append the framework search path flags.
  1578. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1579. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1580. fdi != fwDirs.end(); ++fdi)
  1581. {
  1582. linkLibs += "-F";
  1583. linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
  1584. linkLibs += " ";
  1585. }
  1586. // Append the library search path flags.
  1587. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1588. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1589. libDir != libDirs.end(); ++libDir)
  1590. {
  1591. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1592. linkLibs += libPathFlag;
  1593. linkLibs += libpath;
  1594. linkLibs += libPathTerminator;
  1595. linkLibs += " ";
  1596. }
  1597. // Append the link items.
  1598. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1599. ItemVector const& items = cli.GetItems();
  1600. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1601. {
  1602. if(li->IsPath)
  1603. {
  1604. linkLibs += this->ConvertToLinkReference(li->Value);
  1605. }
  1606. else
  1607. {
  1608. linkLibs += li->Value;
  1609. }
  1610. linkLibs += " ";
  1611. }
  1612. // Write the library flags to the build rule.
  1613. fout << linkLibs;
  1614. // Get the RPATH entries.
  1615. std::vector<std::string> runtimeDirs;
  1616. cli.GetRPath(runtimeDirs, relink);
  1617. // Check what kind of rpath flags to use.
  1618. if(cli.GetRuntimeSep().empty())
  1619. {
  1620. // Each rpath entry gets its own option ("-R a -R b -R c")
  1621. std::string rpath;
  1622. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1623. ri != runtimeDirs.end(); ++ri)
  1624. {
  1625. rpath += cli.GetRuntimeFlag();
  1626. rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
  1627. rpath += " ";
  1628. }
  1629. fout << rpath;
  1630. }
  1631. else
  1632. {
  1633. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1634. std::string rpath = cli.GetRPathString(relink);
  1635. // Store the rpath option in the stream.
  1636. if(!rpath.empty())
  1637. {
  1638. fout << cli.GetRuntimeFlag();
  1639. fout << this->EscapeForShell(rpath.c_str(), true);
  1640. fout << " ";
  1641. }
  1642. }
  1643. // Add the linker runtime search path if any.
  1644. std::string rpath_link = cli.GetRPathLinkString();
  1645. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1646. {
  1647. fout << cli.GetRPathLinkFlag();
  1648. fout << this->EscapeForShell(rpath_link.c_str(), true);
  1649. fout << " ";
  1650. }
  1651. // Add standard libraries for this language.
  1652. std::string standardLibsVar = "CMAKE_";
  1653. standardLibsVar += cli.GetLinkLanguage();
  1654. standardLibsVar += "_STANDARD_LIBRARIES";
  1655. if(const char* stdLibs =
  1656. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1657. {
  1658. fout << stdLibs << " ";
  1659. }
  1660. }
  1661. //----------------------------------------------------------------------------
  1662. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1663. cmTarget* target,
  1664. const char *lang,
  1665. const char* config)
  1666. {
  1667. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1668. if(!this->Makefile->IsOn("APPLE"))
  1669. {
  1670. return;
  1671. }
  1672. if(this->EmitUniversalBinaryFlags)
  1673. {
  1674. std::vector<std::string> archs;
  1675. target->GetAppleArchs(config, archs);
  1676. const char* sysroot =
  1677. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1678. const char* sysrootDefault =
  1679. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
  1680. const char* deploymentTarget =
  1681. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1682. std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
  1683. bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str());
  1684. std::string deploymentTargetFlagVar =
  1685. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1686. const char* deploymentTargetFlag =
  1687. this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
  1688. bool flagsUsed = false;
  1689. if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
  1690. {
  1691. // if there is more than one arch add the -arch and
  1692. // -isysroot flags, or if there is one arch flag, but
  1693. // it is not the default -arch flag for the system, then
  1694. // add it. Otherwize do not add -arch and -isysroot
  1695. if(archs[0] != "")
  1696. {
  1697. for( std::vector<std::string>::iterator i = archs.begin();
  1698. i != archs.end(); ++i)
  1699. {
  1700. flags += " -arch ";
  1701. flags += *i;
  1702. }
  1703. if(hasIsysroot)
  1704. {
  1705. flags += " -isysroot ";
  1706. flags += sysroot;
  1707. }
  1708. flagsUsed = true;
  1709. }
  1710. }
  1711. if(!flagsUsed && sysroot && sysrootDefault &&
  1712. strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot)
  1713. {
  1714. flags += " -isysroot ";
  1715. flags += sysroot;
  1716. }
  1717. if (deploymentTargetFlag && *deploymentTargetFlag &&
  1718. deploymentTarget && *deploymentTarget)
  1719. {
  1720. flags += " ";
  1721. flags += deploymentTargetFlag;
  1722. flags += deploymentTarget;
  1723. }
  1724. }
  1725. }
  1726. //----------------------------------------------------------------------------
  1727. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1728. const char* lang,
  1729. const char* config)
  1730. {
  1731. // Add language-specific flags.
  1732. std::string flagsVar = "CMAKE_";
  1733. flagsVar += lang;
  1734. flagsVar += "_FLAGS";
  1735. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1736. }
  1737. //----------------------------------------------------------------------------
  1738. bool cmLocalGenerator::GetRealDependency(const char* inName,
  1739. const char* config,
  1740. std::string& dep)
  1741. {
  1742. // Older CMake code may specify the dependency using the target
  1743. // output file rather than the target name. Such code would have
  1744. // been written before there was support for target properties that
  1745. // modify the name so stripping down to just the file name should
  1746. // produce the target name in this case.
  1747. std::string name = cmSystemTools::GetFilenameName(inName);
  1748. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1749. {
  1750. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1751. }
  1752. // Look for a CMake target with the given name.
  1753. if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
  1754. {
  1755. // make sure it is not just a coincidence that the target name
  1756. // found is part of the inName
  1757. if(cmSystemTools::FileIsFullPath(inName))
  1758. {
  1759. std::string tLocation;
  1760. if(target->GetType() >= cmTarget::EXECUTABLE &&
  1761. target->GetType() <= cmTarget::MODULE_LIBRARY)
  1762. {
  1763. tLocation = target->GetLocation(config);
  1764. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1765. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1766. }
  1767. std::string depLocation = cmSystemTools::GetFilenamePath(
  1768. std::string(inName));
  1769. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1770. if(depLocation != tLocation)
  1771. {
  1772. // it is a full path to a depend that has the same name
  1773. // as a target but is in a different location so do not use
  1774. // the target as the depend
  1775. dep = inName;
  1776. return true;
  1777. }
  1778. }
  1779. switch (target->GetType())
  1780. {
  1781. case cmTarget::EXECUTABLE:
  1782. case cmTarget::STATIC_LIBRARY:
  1783. case cmTarget::SHARED_LIBRARY:
  1784. case cmTarget::MODULE_LIBRARY:
  1785. case cmTarget::UNKNOWN_LIBRARY:
  1786. dep = target->GetLocation(config);
  1787. return true;
  1788. case cmTarget::OBJECT_LIBRARY:
  1789. // An object library has no single file on which to depend.
  1790. // This was listed to get the target-level dependency.
  1791. return false;
  1792. case cmTarget::UTILITY:
  1793. case cmTarget::GLOBAL_TARGET:
  1794. // A utility target has no file on which to depend. This was listed
  1795. // only to get the target-level dependency.
  1796. return false;
  1797. }
  1798. }
  1799. // The name was not that of a CMake target. It must name a file.
  1800. if(cmSystemTools::FileIsFullPath(inName))
  1801. {
  1802. // This is a full path. Return it as given.
  1803. dep = inName;
  1804. return true;
  1805. }
  1806. // Check for a source file in this directory that matches the
  1807. // dependency.
  1808. if(cmSourceFile* sf = this->Makefile->GetSource(inName))
  1809. {
  1810. dep = sf->GetFullPath();
  1811. return true;
  1812. }
  1813. // Treat the name as relative to the source directory in which it
  1814. // was given.
  1815. dep = this->Makefile->GetCurrentDirectory();
  1816. dep += "/";
  1817. dep += inName;
  1818. return true;
  1819. }
  1820. //----------------------------------------------------------------------------
  1821. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1822. const char* lang,
  1823. bool shared)
  1824. {
  1825. std::string flagsVar;
  1826. // Add flags for dealing with shared libraries for this language.
  1827. if(shared)
  1828. {
  1829. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1830. flagsVar += lang;
  1831. flagsVar += "_FLAGS";
  1832. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1833. }
  1834. }
  1835. //----------------------------------------------------------------------------
  1836. void cmLocalGenerator::AddCMP0018Flags(std::string &flags, cmTarget* target,
  1837. std::string const& lang)
  1838. {
  1839. int targetType = target->GetType();
  1840. bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
  1841. (targetType == cmTarget::MODULE_LIBRARY));
  1842. if (this->GetShouldUseOldFlags(shared, lang))
  1843. {
  1844. this->AddSharedFlags(flags, lang.c_str(), shared);
  1845. }
  1846. else
  1847. {
  1848. // Add position independendent flags, if needed.
  1849. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
  1850. {
  1851. this->AddPositionIndependentFlags(flags, lang, targetType);
  1852. }
  1853. if (shared)
  1854. {
  1855. this->AppendFeatureOptions(flags, lang.c_str(), "DLL");
  1856. }
  1857. }
  1858. }
  1859. //----------------------------------------------------------------------------
  1860. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  1861. const std::string &lang) const
  1862. {
  1863. std::string originalFlags =
  1864. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  1865. if (shared)
  1866. {
  1867. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  1868. flagsVar += lang;
  1869. flagsVar += "_FLAGS";
  1870. const char* flags =
  1871. this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1872. if (flags && flags != originalFlags)
  1873. {
  1874. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
  1875. {
  1876. case cmPolicies::WARN:
  1877. {
  1878. cmOStringStream e;
  1879. e << "Variable " << flagsVar << " has been modified. CMake "
  1880. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  1881. "shared libraries and will use the " << flagsVar << " variable "
  1882. "instead. This may cause errors if the original content of "
  1883. << flagsVar << " was removed.\n"
  1884. << this->Makefile->GetPolicies()->GetPolicyWarning(
  1885. cmPolicies::CMP0018);
  1886. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  1887. // fall through to OLD behaviour
  1888. }
  1889. case cmPolicies::OLD:
  1890. return true;
  1891. case cmPolicies::REQUIRED_IF_USED:
  1892. case cmPolicies::REQUIRED_ALWAYS:
  1893. case cmPolicies::NEW:
  1894. default:
  1895. return false;
  1896. }
  1897. }
  1898. }
  1899. return false;
  1900. }
  1901. //----------------------------------------------------------------------------
  1902. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  1903. std::string const& lang,
  1904. int targetType)
  1905. {
  1906. const char* picFlags = 0;
  1907. if(targetType == cmTarget::EXECUTABLE)
  1908. {
  1909. std::string flagsVar = "CMAKE_";
  1910. flagsVar += lang;
  1911. flagsVar += "_COMPILE_OPTIONS_PIE";
  1912. picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1913. }
  1914. if (!picFlags)
  1915. {
  1916. std::string flagsVar = "CMAKE_";
  1917. flagsVar += lang;
  1918. flagsVar += "_COMPILE_OPTIONS_PIC";
  1919. picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1920. }
  1921. if (picFlags)
  1922. {
  1923. std::vector<std::string> options;
  1924. cmSystemTools::ExpandListArgument(picFlags, options);
  1925. for(std::vector<std::string>::const_iterator oi = options.begin();
  1926. oi != options.end(); ++oi)
  1927. {
  1928. this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
  1929. }
  1930. }
  1931. }
  1932. //----------------------------------------------------------------------------
  1933. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1934. const char* var,
  1935. const char* config)
  1936. {
  1937. // Add the flags from the variable itself.
  1938. std::string flagsVar = var;
  1939. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1940. // Add the flags from the build-type specific variable.
  1941. if(config && *config)
  1942. {
  1943. flagsVar += "_";
  1944. flagsVar += cmSystemTools::UpperCase(config);
  1945. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1946. }
  1947. }
  1948. //----------------------------------------------------------------------------
  1949. void cmLocalGenerator::AppendFlags(std::string& flags,
  1950. const char* newFlags)
  1951. {
  1952. if(newFlags && *newFlags)
  1953. {
  1954. std::string newf = newFlags;
  1955. if(flags.size())
  1956. {
  1957. flags += " ";
  1958. }
  1959. flags += newFlags;
  1960. }
  1961. }
  1962. //----------------------------------------------------------------------------
  1963. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  1964. const char* defines_list)
  1965. {
  1966. // Short-circuit if there are no definitions.
  1967. if(!defines_list)
  1968. {
  1969. return;
  1970. }
  1971. // Expand the list of definitions.
  1972. std::vector<std::string> defines_vec;
  1973. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1974. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  1975. di != defines_vec.end(); ++di)
  1976. {
  1977. // Skip unsupported definitions.
  1978. if(!this->CheckDefinition(*di))
  1979. {
  1980. continue;
  1981. }
  1982. defines.insert(*di);
  1983. }
  1984. }
  1985. //----------------------------------------------------------------------------
  1986. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  1987. std::string &definesString,
  1988. const char* lang)
  1989. {
  1990. // Lookup the define flag for the current language.
  1991. std::string dflag = "-D";
  1992. if(lang)
  1993. {
  1994. std::string defineFlagVar = "CMAKE_";
  1995. defineFlagVar += lang;
  1996. defineFlagVar += "_DEFINE_FLAG";
  1997. const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
  1998. if(df && *df)
  1999. {
  2000. dflag = df;
  2001. }
  2002. }
  2003. std::set<std::string>::const_iterator defineIt = defines.begin();
  2004. const std::set<std::string>::const_iterator defineEnd = defines.end();
  2005. const char* itemSeparator = definesString.empty() ? "" : " ";
  2006. for( ; defineIt != defineEnd; ++defineIt)
  2007. {
  2008. // Append the definition with proper escaping.
  2009. std::string def = dflag;
  2010. if(this->WatcomWMake)
  2011. {
  2012. // The Watcom compiler does its own command line parsing instead
  2013. // of using the windows shell rules. Definitions are one of
  2014. // -DNAME
  2015. // -DNAME=<cpp-token>
  2016. // -DNAME="c-string with spaces and other characters(?@#$)"
  2017. //
  2018. // Watcom will properly parse each of these cases from the
  2019. // command line without any escapes. However we still have to
  2020. // get the '$' and '#' characters through WMake as '$$' and
  2021. // '$#'.
  2022. for(const char* c = defineIt->c_str(); *c; ++c)
  2023. {
  2024. if(*c == '$' || *c == '#')
  2025. {
  2026. def += '$';
  2027. }
  2028. def += *c;
  2029. }
  2030. }
  2031. else
  2032. {
  2033. // Make the definition appear properly on the command line. Use
  2034. // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
  2035. std::string::size_type eq = defineIt->find("=");
  2036. def += defineIt->substr(0, eq);
  2037. if(eq != defineIt->npos)
  2038. {
  2039. def += "=";
  2040. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  2041. }
  2042. }
  2043. definesString += itemSeparator;
  2044. itemSeparator = " ";
  2045. definesString += def;
  2046. }
  2047. }
  2048. //----------------------------------------------------------------------------
  2049. void cmLocalGenerator::AppendFeatureOptions(
  2050. std::string& flags, const char* lang, const char* feature)
  2051. {
  2052. std::string optVar = "CMAKE_";
  2053. optVar += lang;
  2054. optVar += "_COMPILE_OPTIONS_";
  2055. optVar += feature;
  2056. if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str()))
  2057. {
  2058. std::vector<std::string> options;
  2059. cmSystemTools::ExpandListArgument(optionList, options);
  2060. for(std::vector<std::string>::const_iterator oi = options.begin();
  2061. oi != options.end(); ++oi)
  2062. {
  2063. this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
  2064. }
  2065. }
  2066. }
  2067. //----------------------------------------------------------------------------
  2068. std::string
  2069. cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
  2070. const char* default_comment)
  2071. {
  2072. // Check for a comment provided with the command.
  2073. if(cc.GetComment())
  2074. {
  2075. return cc.GetComment();
  2076. }
  2077. // Construct a reasonable default comment if possible.
  2078. if(!cc.GetOutputs().empty())
  2079. {
  2080. std::string comment;
  2081. comment = "Generating ";
  2082. const char* sep = "";
  2083. for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
  2084. o != cc.GetOutputs().end(); ++o)
  2085. {
  2086. comment += sep;
  2087. comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
  2088. sep = ", ";
  2089. }
  2090. return comment;
  2091. }
  2092. // Otherwise use the provided default.
  2093. return default_comment;
  2094. }
  2095. //----------------------------------------------------------------------------
  2096. std::string
  2097. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  2098. {
  2099. return this->Convert(remote, START_OUTPUT, SHELL, true);
  2100. }
  2101. //----------------------------------------------------------------------------
  2102. const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
  2103. {
  2104. switch (relroot)
  2105. {
  2106. case HOME: return this->Makefile->GetHomeDirectory();
  2107. case START: return this->Makefile->GetStartDirectory();
  2108. case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
  2109. case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
  2110. default: break;
  2111. }
  2112. return 0;
  2113. }
  2114. //----------------------------------------------------------------------------
  2115. std::string cmLocalGenerator::Convert(const char* source,
  2116. RelativeRoot relative,
  2117. OutputFormat output,
  2118. bool optional)
  2119. {
  2120. // Make sure the relative path conversion components are set.
  2121. if(!this->PathConversionsSetup)
  2122. {
  2123. this->SetupPathConversions();
  2124. this->PathConversionsSetup = true;
  2125. }
  2126. // Convert the path to a relative path.
  2127. std::string result = source;
  2128. if (!optional || this->UseRelativePaths)
  2129. {
  2130. switch (relative)
  2131. {
  2132. case HOME:
  2133. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2134. result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
  2135. result.c_str());
  2136. break;
  2137. case START:
  2138. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2139. result = this->ConvertToRelativePath(this->StartDirectoryComponents,
  2140. result.c_str());
  2141. break;
  2142. case HOME_OUTPUT:
  2143. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2144. result =
  2145. this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
  2146. result.c_str());
  2147. break;
  2148. case START_OUTPUT:
  2149. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2150. result =
  2151. this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
  2152. result.c_str());
  2153. break;
  2154. case FULL:
  2155. result = cmSystemTools::CollapseFullPath(result.c_str());
  2156. break;
  2157. case NONE:
  2158. break;
  2159. }
  2160. }
  2161. return this->ConvertToOutputFormat(result.c_str(), output);
  2162. }
  2163. //----------------------------------------------------------------------------
  2164. std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
  2165. OutputFormat output)
  2166. {
  2167. std::string result = source;
  2168. // Convert it to an output path.
  2169. if (output == MAKEFILE)
  2170. {
  2171. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  2172. }
  2173. else if( output == SHELL)
  2174. {
  2175. // For the MSYS shell convert drive letters to posix paths, so
  2176. // that c:/some/path becomes /c/some/path. This is needed to
  2177. // avoid problems with the shell path translation.
  2178. if(this->MSYSShell && !this->LinkScriptShell)
  2179. {
  2180. if(result.size() > 2 && result[1] == ':')
  2181. {
  2182. result[1] = result[0];
  2183. result[0] = '/';
  2184. }
  2185. }
  2186. if(this->WindowsShell)
  2187. {
  2188. std::string::size_type pos = 0;
  2189. while((pos = result.find('/', pos)) != std::string::npos)
  2190. {
  2191. result[pos] = '\\';
  2192. pos++;
  2193. }
  2194. }
  2195. result = this->EscapeForShell(result.c_str(), true, false);
  2196. }
  2197. else if(output == RESPONSE)
  2198. {
  2199. result = this->EscapeForShell(result.c_str(), false, false);
  2200. }
  2201. return result;
  2202. }
  2203. //----------------------------------------------------------------------------
  2204. std::string cmLocalGenerator::Convert(RelativeRoot remote,
  2205. const char* local,
  2206. OutputFormat output,
  2207. bool optional)
  2208. {
  2209. const char* remotePath = this->GetRelativeRootPath(remote);
  2210. // The relative root must have a path (i.e. not FULL or NONE)
  2211. assert(remotePath != 0);
  2212. if(local && (!optional || this->UseRelativePaths))
  2213. {
  2214. std::vector<std::string> components;
  2215. cmSystemTools::SplitPath(local, components);
  2216. std::string result = this->ConvertToRelativePath(components, remotePath);
  2217. return this->ConvertToOutputFormat(result.c_str(), output);
  2218. }
  2219. else
  2220. {
  2221. return this->ConvertToOutputFormat(remotePath, output);
  2222. }
  2223. }
  2224. //----------------------------------------------------------------------------
  2225. std::string cmLocalGenerator::FindRelativePathTopSource()
  2226. {
  2227. // Relative path conversion within a single tree managed by CMake is
  2228. // safe. We can use our parent relative path top if and only if
  2229. // this is a subdirectory of that top.
  2230. if(cmLocalGenerator* parent = this->GetParent())
  2231. {
  2232. std::string parentTop = parent->FindRelativePathTopSource();
  2233. if(cmSystemTools::IsSubDirectory(
  2234. this->Makefile->GetStartDirectory(), parentTop.c_str()))
  2235. {
  2236. return parentTop;
  2237. }
  2238. }
  2239. // Otherwise this directory itself is the new top.
  2240. return this->Makefile->GetStartDirectory();
  2241. }
  2242. //----------------------------------------------------------------------------
  2243. std::string cmLocalGenerator::FindRelativePathTopBinary()
  2244. {
  2245. // Relative path conversion within a single tree managed by CMake is
  2246. // safe. We can use our parent relative path top if and only if
  2247. // this is a subdirectory of that top.
  2248. if(cmLocalGenerator* parent = this->GetParent())
  2249. {
  2250. std::string parentTop = parent->FindRelativePathTopBinary();
  2251. if(cmSystemTools::IsSubDirectory(
  2252. this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
  2253. {
  2254. return parentTop;
  2255. }
  2256. }
  2257. // Otherwise this directory itself is the new top.
  2258. return this->Makefile->GetStartOutputDirectory();
  2259. }
  2260. //----------------------------------------------------------------------------
  2261. void cmLocalGenerator::ConfigureRelativePaths()
  2262. {
  2263. // Relative path conversion inside the source tree is not used to
  2264. // construct relative paths passed to build tools so it is safe to
  2265. // even when the source is a network path.
  2266. std::string source = this->FindRelativePathTopSource();
  2267. this->RelativePathTopSource = source;
  2268. // The current working directory on Windows cannot be a network
  2269. // path. Therefore relative paths cannot work when the binary tree
  2270. // is a network path.
  2271. std::string binary = this->FindRelativePathTopBinary();
  2272. if(binary.size() < 2 || binary.substr(0, 2) != "//")
  2273. {
  2274. this->RelativePathTopBinary = binary;
  2275. }
  2276. else
  2277. {
  2278. this->RelativePathTopBinary = "";
  2279. }
  2280. }
  2281. //----------------------------------------------------------------------------
  2282. static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
  2283. {
  2284. return (cmSystemTools::ComparePath(a, b) ||
  2285. cmSystemTools::IsSubDirectory(a, b));
  2286. }
  2287. //----------------------------------------------------------------------------
  2288. std::string
  2289. cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
  2290. const char* in_remote, bool force)
  2291. {
  2292. // The path should never be quoted.
  2293. assert(in_remote[0] != '\"');
  2294. // The local path should never have a trailing slash.
  2295. assert(local.size() > 0 && !(local[local.size()-1] == ""));
  2296. // If the path is already relative then just return the path.
  2297. if(!cmSystemTools::FileIsFullPath(in_remote))
  2298. {
  2299. return in_remote;
  2300. }
  2301. // Make sure relative path conversion is configured.
  2302. if(!this->RelativePathsConfigured)
  2303. {
  2304. this->ConfigureRelativePaths();
  2305. this->RelativePathsConfigured = true;
  2306. }
  2307. if(!force)
  2308. {
  2309. // Skip conversion if the path and local are not both in the source
  2310. // or both in the binary tree.
  2311. std::string local_path = cmSystemTools::JoinPath(local);
  2312. if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
  2313. this->RelativePathTopBinary.c_str()) &&
  2314. cmLocalGeneratorNotAbove(in_remote,
  2315. this->RelativePathTopBinary.c_str())) ||
  2316. (cmLocalGeneratorNotAbove(local_path.c_str(),
  2317. this->RelativePathTopSource.c_str()) &&
  2318. cmLocalGeneratorNotAbove(in_remote,
  2319. this->RelativePathTopSource.c_str()))))
  2320. {
  2321. return in_remote;
  2322. }
  2323. }
  2324. // Identify the longest shared path component between the remote
  2325. // path and the local path.
  2326. std::vector<std::string> remote;
  2327. cmSystemTools::SplitPath(in_remote, remote);
  2328. unsigned int common=0;
  2329. while(common < remote.size() &&
  2330. common < local.size() &&
  2331. cmSystemTools::ComparePath(remote[common].c_str(),
  2332. local[common].c_str()))
  2333. {
  2334. ++common;
  2335. }
  2336. // If no part of the path is in common then return the full path.
  2337. if(common == 0)
  2338. {
  2339. return in_remote;
  2340. }
  2341. // If the entire path is in common then just return a ".".
  2342. if(common == remote.size() &&
  2343. common == local.size())
  2344. {
  2345. return ".";
  2346. }
  2347. // If the entire path is in common except for a trailing slash then
  2348. // just return a "./".
  2349. if(common+1 == remote.size() &&
  2350. remote[common].size() == 0 &&
  2351. common == local.size())
  2352. {
  2353. return "./";
  2354. }
  2355. // Construct the relative path.
  2356. std::string relative;
  2357. // First add enough ../ to get up to the level of the shared portion
  2358. // of the path. Leave off the trailing slash. Note that the last
  2359. // component of local will never be empty because local should never
  2360. // have a trailing slash.
  2361. for(unsigned int i=common; i < local.size(); ++i)
  2362. {
  2363. relative += "..";
  2364. if(i < local.size()-1)
  2365. {
  2366. relative += "/";
  2367. }
  2368. }
  2369. // Now add the portion of the destination path that is not included
  2370. // in the shared portion of the path. Add a slash the first time
  2371. // only if there was already something in the path. If there was a
  2372. // trailing slash in the input then the last iteration of the loop
  2373. // will add a slash followed by an empty string which will preserve
  2374. // the trailing slash in the output.
  2375. for(unsigned int i=common; i < remote.size(); ++i)
  2376. {
  2377. if(relative.size() > 0)
  2378. {
  2379. relative += "/";
  2380. }
  2381. relative += remote[i];
  2382. }
  2383. // Finally return the path.
  2384. return relative;
  2385. }
  2386. //----------------------------------------------------------------------------
  2387. void
  2388. cmLocalGenerator
  2389. ::GenerateTargetInstallRules(
  2390. std::ostream& os, const char* config,
  2391. std::vector<std::string> const& configurationTypes)
  2392. {
  2393. // Convert the old-style install specification from each target to
  2394. // an install generator and run it.
  2395. cmTargets& tgts = this->Makefile->GetTargets();
  2396. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2397. {
  2398. // Include the user-specified pre-install script for this target.
  2399. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2400. {
  2401. cmInstallScriptGenerator g(preinstall, false, 0);
  2402. g.Generate(os, config, configurationTypes);
  2403. }
  2404. // Install this target if a destination is given.
  2405. if(l->second.GetInstallPath() != "")
  2406. {
  2407. // Compute the full install destination. Note that converting
  2408. // to unix slashes also removes any trailing slash.
  2409. // We also skip over the leading slash given by the user.
  2410. std::string destination = l->second.GetInstallPath().substr(1);
  2411. cmSystemTools::ConvertToUnixSlashes(destination);
  2412. if(destination.empty())
  2413. {
  2414. destination = ".";
  2415. }
  2416. // Generate the proper install generator for this target type.
  2417. switch(l->second.GetType())
  2418. {
  2419. case cmTarget::EXECUTABLE:
  2420. case cmTarget::STATIC_LIBRARY:
  2421. case cmTarget::MODULE_LIBRARY:
  2422. {
  2423. // Use a target install generator.
  2424. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2425. g.Generate(os, config, configurationTypes);
  2426. }
  2427. break;
  2428. case cmTarget::SHARED_LIBRARY:
  2429. {
  2430. #if defined(_WIN32) || defined(__CYGWIN__)
  2431. // Special code to handle DLL. Install the import library
  2432. // to the normal destination and the DLL to the runtime
  2433. // destination.
  2434. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  2435. g1.Generate(os, config, configurationTypes);
  2436. // We also skip over the leading slash given by the user.
  2437. destination = l->second.GetRuntimeInstallPath().substr(1);
  2438. cmSystemTools::ConvertToUnixSlashes(destination);
  2439. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  2440. g2.Generate(os, config, configurationTypes);
  2441. #else
  2442. // Use a target install generator.
  2443. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2444. g.Generate(os, config, configurationTypes);
  2445. #endif
  2446. }
  2447. break;
  2448. default:
  2449. break;
  2450. }
  2451. }
  2452. // Include the user-specified post-install script for this target.
  2453. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2454. {
  2455. cmInstallScriptGenerator g(postinstall, false, 0);
  2456. g.Generate(os, config, configurationTypes);
  2457. }
  2458. }
  2459. }
  2460. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2461. static std::string cmLocalGeneratorMD5(const char* input)
  2462. {
  2463. char md5out[32];
  2464. cmsysMD5* md5 = cmsysMD5_New();
  2465. cmsysMD5_Initialize(md5);
  2466. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2467. cmsysMD5_FinalizeHex(md5, md5out);
  2468. cmsysMD5_Delete(md5);
  2469. return std::string(md5out, 32);
  2470. }
  2471. static bool
  2472. cmLocalGeneratorShortenObjectName(std::string& objName,
  2473. std::string::size_type max_len)
  2474. {
  2475. // Replace the beginning of the path portion of the object name with
  2476. // its own md5 sum.
  2477. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2478. if(pos != objName.npos)
  2479. {
  2480. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2481. md5name += objName.substr(pos);
  2482. objName = md5name;
  2483. // The object name is now short enough.
  2484. return true;
  2485. }
  2486. else
  2487. {
  2488. // The object name could not be shortened enough.
  2489. return false;
  2490. }
  2491. }
  2492. static
  2493. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2494. std::string::size_type dir_len,
  2495. std::string::size_type max_total_len)
  2496. {
  2497. // Enforce the maximum file name length if possible.
  2498. std::string::size_type max_obj_len = max_total_len;
  2499. if(dir_len < max_total_len)
  2500. {
  2501. max_obj_len = max_total_len - dir_len;
  2502. if(objName.size() > max_obj_len)
  2503. {
  2504. // The current object file name is too long. Try to shorten it.
  2505. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2506. }
  2507. else
  2508. {
  2509. // The object file name is short enough.
  2510. return true;
  2511. }
  2512. }
  2513. else
  2514. {
  2515. // The build directory in which the object will be stored is
  2516. // already too deep.
  2517. return false;
  2518. }
  2519. }
  2520. #endif
  2521. //----------------------------------------------------------------------------
  2522. std::string&
  2523. cmLocalGenerator
  2524. ::CreateSafeUniqueObjectFileName(const char* sin,
  2525. std::string const& dir_max)
  2526. {
  2527. // Look for an existing mapped name for this object file.
  2528. std::map<cmStdString,cmStdString>::iterator it =
  2529. this->UniqueObjectNamesMap.find(sin);
  2530. // If no entry exists create one.
  2531. if(it == this->UniqueObjectNamesMap.end())
  2532. {
  2533. // Start with the original name.
  2534. std::string ssin = sin;
  2535. // Avoid full paths by removing leading slashes.
  2536. std::string::size_type pos = 0;
  2537. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
  2538. {
  2539. }
  2540. ssin = ssin.substr(pos);
  2541. // Avoid full paths by removing colons.
  2542. cmSystemTools::ReplaceString(ssin, ":", "_");
  2543. // Avoid relative paths that go up the tree.
  2544. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2545. // Avoid spaces.
  2546. cmSystemTools::ReplaceString(ssin, " ", "_");
  2547. // Mangle the name if necessary.
  2548. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2549. {
  2550. bool done;
  2551. int cc = 0;
  2552. char rpstr[100];
  2553. sprintf(rpstr, "_p_");
  2554. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2555. std::string sssin = sin;
  2556. do
  2557. {
  2558. done = true;
  2559. for ( it = this->UniqueObjectNamesMap.begin();
  2560. it != this->UniqueObjectNamesMap.end();
  2561. ++ it )
  2562. {
  2563. if ( it->second == ssin )
  2564. {
  2565. done = false;
  2566. }
  2567. }
  2568. if ( done )
  2569. {
  2570. break;
  2571. }
  2572. sssin = ssin;
  2573. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2574. sprintf(rpstr, "_p%d_", cc++);
  2575. }
  2576. while ( !done );
  2577. }
  2578. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2579. if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2580. this->ObjectPathMax))
  2581. {
  2582. // Warn if this is the first time the path has been seen.
  2583. if(this->ObjectMaxPathViolations.insert(dir_max).second)
  2584. {
  2585. cmOStringStream m;
  2586. m << "The object file directory\n"
  2587. << " " << dir_max << "\n"
  2588. << "has " << dir_max.size() << " characters. "
  2589. << "The maximum full path to an object file is "
  2590. << this->ObjectPathMax << " characters "
  2591. << "(see CMAKE_OBJECT_PATH_MAX). "
  2592. << "Object file\n"
  2593. << " " << ssin << "\n"
  2594. << "cannot be safely placed under this directory. "
  2595. << "The build may not work correctly.";
  2596. this->Makefile->IssueMessage(cmake::WARNING, m.str());
  2597. }
  2598. }
  2599. #else
  2600. (void)dir_max;
  2601. #endif
  2602. // Insert the newly mapped object file name.
  2603. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  2604. it = this->UniqueObjectNamesMap.insert(e).first;
  2605. }
  2606. // Return the map entry.
  2607. return it->second;
  2608. }
  2609. //----------------------------------------------------------------------------
  2610. std::string
  2611. cmLocalGenerator
  2612. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2613. std::string const& dir_max,
  2614. bool* hasSourceExtension)
  2615. {
  2616. // Construct the object file name using the full path to the source
  2617. // file which is its only unique identification.
  2618. const char* fullPath = source.GetFullPath().c_str();
  2619. // Try referencing the source relative to the source tree.
  2620. std::string relFromSource = this->Convert(fullPath, START);
  2621. assert(!relFromSource.empty());
  2622. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2623. bool subSource = relSource && relFromSource[0] != '.';
  2624. // Try referencing the source relative to the binary tree.
  2625. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2626. assert(!relFromBinary.empty());
  2627. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2628. bool subBinary = relBinary && relFromBinary[0] != '.';
  2629. // Select a nice-looking reference to the source file to construct
  2630. // the object file name.
  2631. std::string objectName;
  2632. if((relSource && !relBinary) || (subSource && !subBinary))
  2633. {
  2634. objectName = relFromSource;
  2635. }
  2636. else if((relBinary && !relSource) || (subBinary && !subSource))
  2637. {
  2638. objectName = relFromBinary;
  2639. }
  2640. else if(relFromBinary.length() < relFromSource.length())
  2641. {
  2642. objectName = relFromBinary;
  2643. }
  2644. else
  2645. {
  2646. objectName = relFromSource;
  2647. }
  2648. // if it is still a full path check for the try compile case
  2649. // try compile never have in source sources, and should not
  2650. // have conflicting source file names in the same target
  2651. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2652. {
  2653. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2654. {
  2655. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2656. }
  2657. }
  2658. // Replace the original source file extension with the object file
  2659. // extension.
  2660. bool keptSourceExtension = true;
  2661. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2662. {
  2663. // Decide whether this language wants to replace the source
  2664. // extension with the object extension. For CMake 2.4
  2665. // compatibility do this by default.
  2666. bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
  2667. if(!replaceExt)
  2668. {
  2669. if(const char* lang = source.GetLanguage())
  2670. {
  2671. std::string repVar = "CMAKE_";
  2672. repVar += lang;
  2673. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2674. replaceExt = this->Makefile->IsOn(repVar.c_str());
  2675. }
  2676. }
  2677. // Remove the source extension if it is to be replaced.
  2678. if(replaceExt)
  2679. {
  2680. keptSourceExtension = false;
  2681. std::string::size_type dot_pos = objectName.rfind(".");
  2682. if(dot_pos != std::string::npos)
  2683. {
  2684. objectName = objectName.substr(0, dot_pos);
  2685. }
  2686. }
  2687. // Store the new extension.
  2688. objectName +=
  2689. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2690. }
  2691. if(hasSourceExtension)
  2692. {
  2693. *hasSourceExtension = keptSourceExtension;
  2694. }
  2695. // Convert to a safe name.
  2696. return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
  2697. }
  2698. //----------------------------------------------------------------------------
  2699. const char*
  2700. cmLocalGenerator
  2701. ::GetSourceFileLanguage(const cmSourceFile& source)
  2702. {
  2703. return source.GetLanguage();
  2704. }
  2705. //----------------------------------------------------------------------------
  2706. std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
  2707. {
  2708. std::string result;
  2709. #if defined(_WIN32) && !defined(__CYGWIN__)
  2710. // if there are spaces
  2711. std::string temp = str;
  2712. if (temp.find(" ") != std::string::npos &&
  2713. temp.find("\"")==std::string::npos)
  2714. {
  2715. result = "\"";
  2716. result += str;
  2717. result += "\"";
  2718. return result;
  2719. }
  2720. return str;
  2721. #else
  2722. for(const char* ch = str; *ch != '\0'; ++ch)
  2723. {
  2724. if(*ch == ' ')
  2725. {
  2726. result += '\\';
  2727. }
  2728. result += *ch;
  2729. }
  2730. return result;
  2731. #endif
  2732. }
  2733. //----------------------------------------------------------------------------
  2734. static bool cmLocalGeneratorIsShellOperator(const char* str)
  2735. {
  2736. if(strcmp(str, "<") == 0 ||
  2737. strcmp(str, ">") == 0 ||
  2738. strcmp(str, "<<") == 0 ||
  2739. strcmp(str, ">>") == 0 ||
  2740. strcmp(str, "|") == 0 ||
  2741. strcmp(str, "||") == 0 ||
  2742. strcmp(str, "&&") == 0 ||
  2743. strcmp(str, "&>") == 0 ||
  2744. strcmp(str, "1>") == 0 ||
  2745. strcmp(str, "2>") == 0 ||
  2746. strcmp(str, "2>&1") == 0 ||
  2747. strcmp(str, "1>&2") == 0)
  2748. {
  2749. return true;
  2750. }
  2751. return false;
  2752. }
  2753. //----------------------------------------------------------------------------
  2754. std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
  2755. bool forEcho)
  2756. {
  2757. // Do not escape shell operators.
  2758. if(cmLocalGeneratorIsShellOperator(str))
  2759. {
  2760. return str;
  2761. }
  2762. // Compute the flags for the target shell environment.
  2763. int flags = 0;
  2764. if(this->WindowsVSIDE)
  2765. {
  2766. flags |= cmsysSystem_Shell_Flag_VSIDE;
  2767. }
  2768. else if(!this->LinkScriptShell)
  2769. {
  2770. flags |= cmsysSystem_Shell_Flag_Make;
  2771. }
  2772. if(makeVars)
  2773. {
  2774. flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
  2775. }
  2776. if(forEcho)
  2777. {
  2778. flags |= cmsysSystem_Shell_Flag_EchoWindows;
  2779. }
  2780. if(this->WatcomWMake)
  2781. {
  2782. flags |= cmsysSystem_Shell_Flag_WatcomWMake;
  2783. }
  2784. if(this->MinGWMake)
  2785. {
  2786. flags |= cmsysSystem_Shell_Flag_MinGWMake;
  2787. }
  2788. if(this->NMake)
  2789. {
  2790. flags |= cmsysSystem_Shell_Flag_NMake;
  2791. }
  2792. // Compute the buffer size needed.
  2793. int size = (this->WindowsShell ?
  2794. cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
  2795. cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
  2796. // Compute the shell argument itself.
  2797. std::vector<char> arg(size);
  2798. if(this->WindowsShell)
  2799. {
  2800. cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
  2801. }
  2802. else
  2803. {
  2804. cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
  2805. }
  2806. return std::string(&arg[0]);
  2807. }
  2808. //----------------------------------------------------------------------------
  2809. std::string cmLocalGenerator::EscapeForCMake(const char* str)
  2810. {
  2811. // Always double-quote the argument to take care of most escapes.
  2812. std::string result = "\"";
  2813. for(const char* c = str; *c; ++c)
  2814. {
  2815. if(*c == '"')
  2816. {
  2817. // Escape the double quote to avoid ending the argument.
  2818. result += "\\\"";
  2819. }
  2820. else if(*c == '$')
  2821. {
  2822. // Escape the dollar to avoid expanding variables.
  2823. result += "\\$";
  2824. }
  2825. else if(*c == '\\')
  2826. {
  2827. // Escape the backslash to avoid other escapes.
  2828. result += "\\\\";
  2829. }
  2830. else
  2831. {
  2832. // Other characters will be parsed correctly.
  2833. result += *c;
  2834. }
  2835. }
  2836. result += "\"";
  2837. return result;
  2838. }
  2839. //----------------------------------------------------------------------------
  2840. cmLocalGenerator::FortranFormat
  2841. cmLocalGenerator::GetFortranFormat(const char* value)
  2842. {
  2843. FortranFormat format = FortranFormatNone;
  2844. if(value && *value)
  2845. {
  2846. std::vector<std::string> fmt;
  2847. cmSystemTools::ExpandListArgument(value, fmt);
  2848. for(std::vector<std::string>::iterator fi = fmt.begin();
  2849. fi != fmt.end(); ++fi)
  2850. {
  2851. if(*fi == "FIXED")
  2852. {
  2853. format = FortranFormatFixed;
  2854. }
  2855. if(*fi == "FREE")
  2856. {
  2857. format = FortranFormatFree;
  2858. }
  2859. }
  2860. }
  2861. return format;
  2862. }
  2863. //----------------------------------------------------------------------------
  2864. std::string
  2865. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2866. {
  2867. cmSystemTools::Error("GetTargetDirectory"
  2868. " called on cmLocalGenerator");
  2869. return "";
  2870. }
  2871. //----------------------------------------------------------------------------
  2872. unsigned int cmLocalGenerator::GetBackwardsCompatibility()
  2873. {
  2874. // The computed version may change until the project is fully
  2875. // configured.
  2876. if(!this->BackwardsCompatibilityFinal)
  2877. {
  2878. unsigned int major = 0;
  2879. unsigned int minor = 0;
  2880. unsigned int patch = 0;
  2881. if(const char* value
  2882. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2883. {
  2884. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2885. {
  2886. case 2: patch = 0; break;
  2887. case 1: minor = 0; patch = 0; break;
  2888. default: break;
  2889. }
  2890. }
  2891. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2892. this->BackwardsCompatibilityFinal = this->Configured;
  2893. }
  2894. return this->BackwardsCompatibility;
  2895. }
  2896. //----------------------------------------------------------------------------
  2897. bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
  2898. unsigned int minor,
  2899. unsigned int patch)
  2900. {
  2901. // Check the policy to decide whether to pay attention to this
  2902. // variable.
  2903. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
  2904. {
  2905. case cmPolicies::WARN:
  2906. // WARN is just OLD without warning because user code does not
  2907. // always affect whether this check is done.
  2908. case cmPolicies::OLD:
  2909. // Old behavior is to check the variable.
  2910. break;
  2911. case cmPolicies::NEW:
  2912. // New behavior is to ignore the variable.
  2913. return false;
  2914. case cmPolicies::REQUIRED_IF_USED:
  2915. case cmPolicies::REQUIRED_ALWAYS:
  2916. // This will never be the case because the only way to require
  2917. // the setting is to require the user to specify version policy
  2918. // 2.6 or higher. Once we add that requirement then this whole
  2919. // method can be removed anyway.
  2920. return false;
  2921. }
  2922. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2923. // equal to or lower than the given version.
  2924. unsigned int actual_compat = this->GetBackwardsCompatibility();
  2925. return (actual_compat &&
  2926. actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
  2927. }
  2928. //----------------------------------------------------------------------------
  2929. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2930. {
  2931. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2932. bool function_style = false;
  2933. for(const char* c = define.c_str(); *c && *c != '='; ++c)
  2934. {
  2935. if(*c == '(')
  2936. {
  2937. function_style = true;
  2938. break;
  2939. }
  2940. }
  2941. if(function_style)
  2942. {
  2943. cmOStringStream e;
  2944. e << "WARNING: Function-style preprocessor definitions may not be "
  2945. << "passed on the compiler command line because many compilers "
  2946. << "do not support it.\n"
  2947. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2948. << "Consider defining the macro in a (configured) header file.\n";
  2949. cmSystemTools::Message(e.str().c_str());
  2950. return false;
  2951. }
  2952. // Many compilers do not support # in the value so we disable it.
  2953. if(define.find_first_of("#") != define.npos)
  2954. {
  2955. cmOStringStream e;
  2956. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2957. << "passed on the compiler command line because many compilers "
  2958. << "do not support it.\n"
  2959. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2960. << "Consider defining the macro in a (configured) header file.\n";
  2961. cmSystemTools::Message(e.str().c_str());
  2962. return false;
  2963. }
  2964. // Assume it is supported.
  2965. return true;
  2966. }
  2967. //----------------------------------------------------------------------------
  2968. static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
  2969. {
  2970. if(const char* val = target->GetProperty(prop))
  2971. {
  2972. mf->AddDefinition(prop, val);
  2973. }
  2974. }
  2975. //----------------------------------------------------------------------------
  2976. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2977. const char* targetName,
  2978. const char* fname)
  2979. {
  2980. // Find the Info.plist template.
  2981. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2982. std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
  2983. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2984. {
  2985. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2986. if(!inMod.empty())
  2987. {
  2988. inFile = inMod;
  2989. }
  2990. }
  2991. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2992. {
  2993. cmOStringStream e;
  2994. e << "Target " << target->GetName() << " Info.plist template \""
  2995. << inFile << "\" could not be found.";
  2996. cmSystemTools::Error(e.str().c_str());
  2997. return;
  2998. }
  2999. // Convert target properties to variables in an isolated makefile
  3000. // scope to configure the file. If properties are set they will
  3001. // override user make variables. If not the configuration will fall
  3002. // back to the directory-level values set by the user.
  3003. cmMakefile* mf = this->Makefile;
  3004. mf->PushScope();
  3005. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
  3006. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  3007. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  3008. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  3009. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  3010. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  3011. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  3012. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  3013. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  3014. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  3015. mf->PopScope();
  3016. }
  3017. //----------------------------------------------------------------------------
  3018. void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
  3019. const char* targetName,
  3020. const char* fname)
  3021. {
  3022. // Find the Info.plist template.
  3023. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  3024. std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
  3025. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  3026. {
  3027. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  3028. if(!inMod.empty())
  3029. {
  3030. inFile = inMod;
  3031. }
  3032. }
  3033. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  3034. {
  3035. cmOStringStream e;
  3036. e << "Target " << target->GetName() << " Info.plist template \""
  3037. << inFile << "\" could not be found.";
  3038. cmSystemTools::Error(e.str().c_str());
  3039. return;
  3040. }
  3041. // Convert target properties to variables in an isolated makefile
  3042. // scope to configure the file. If properties are set they will
  3043. // override user make variables. If not the configuration will fall
  3044. // back to the directory-level values set by the user.
  3045. cmMakefile* mf = this->Makefile;
  3046. mf->PushScope();
  3047. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
  3048. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  3049. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  3050. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  3051. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  3052. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  3053. mf->PopScope();
  3054. }