cmLocalGenerator.cxx 113 KB

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