cmLocalGenerator.cxx 117 KB

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