cmLocalGenerator.cxx 117 KB

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