cmGeneratorTarget.cxx 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include <cmsys/hash_set.hxx>
  26. #define UNORDERED_SET cmsys::hash_set
  27. #else
  28. #define UNORDERED_SET std::set
  29. #endif
  30. //----------------------------------------------------------------------------
  31. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  32. cmGeneratorTarget const* target, cmake *cm)
  33. {
  34. if(!badObjLib.empty())
  35. {
  36. std::ostringstream e;
  37. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  38. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  39. i != badObjLib.end(); ++i)
  40. {
  41. e << " " << (*i)->GetLocation().GetName() << "\n";
  42. }
  43. e << "but may contain only sources that compile, header files, and "
  44. "other files that would not affect linking of a normal library.";
  45. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  46. target->Target->GetBacktrace());
  47. }
  48. }
  49. struct ObjectSourcesTag {};
  50. struct CustomCommandsTag {};
  51. struct ExtraSourcesTag {};
  52. struct HeaderSourcesTag {};
  53. struct ExternalObjectsTag {};
  54. struct IDLSourcesTag {};
  55. struct ResxTag {};
  56. struct ModuleDefinitionFileTag {};
  57. struct AppManifestTag{};
  58. struct CertificatesTag{};
  59. struct XamlTag{};
  60. template<typename Tag, typename OtherTag>
  61. struct IsSameTag
  62. {
  63. enum {
  64. Result = false
  65. };
  66. };
  67. template<typename Tag>
  68. struct IsSameTag<Tag, Tag>
  69. {
  70. enum {
  71. Result = true
  72. };
  73. };
  74. template<bool>
  75. struct DoAccept
  76. {
  77. template <typename T> static void Do(T&, cmSourceFile*) {}
  78. };
  79. template<>
  80. struct DoAccept<true>
  81. {
  82. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  83. {
  84. files.push_back(f);
  85. }
  86. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  87. {
  88. // Build and save the name of the corresponding .h file
  89. // This relationship will be used later when building the project files.
  90. // Both names would have been auto generated from Visual Studio
  91. // where the user supplied the file name and Visual Studio
  92. // appended the suffix.
  93. std::string resx = f->GetFullPath();
  94. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  95. data.ExpectedResxHeaders.insert(hFileName);
  96. data.ResxSources.push_back(f);
  97. }
  98. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  99. {
  100. // Build and save the name of the corresponding .h and .cpp file
  101. // This relationship will be used later when building the project files.
  102. // Both names would have been auto generated from Visual Studio
  103. // where the user supplied the file name and Visual Studio
  104. // appended the suffix.
  105. std::string xaml = f->GetFullPath();
  106. std::string hFileName = xaml + ".h";
  107. std::string cppFileName = xaml + ".cpp";
  108. data.ExpectedXamlHeaders.insert(hFileName);
  109. data.ExpectedXamlSources.insert(cppFileName);
  110. data.XamlSources.push_back(f);
  111. }
  112. static void Do(std::string& data, cmSourceFile* f)
  113. {
  114. data = f->GetFullPath();
  115. }
  116. };
  117. //----------------------------------------------------------------------------
  118. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  119. struct TagVisitor
  120. {
  121. DataType& Data;
  122. std::vector<cmSourceFile*> BadObjLibFiles;
  123. cmGeneratorTarget const* Target;
  124. cmGlobalGenerator *GlobalGenerator;
  125. cmsys::RegularExpression Header;
  126. bool IsObjLib;
  127. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  128. : Data(data), Target(target),
  129. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  130. Header(CM_HEADER_REGEX),
  131. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  132. {
  133. }
  134. ~TagVisitor()
  135. {
  136. reportBadObjLib(this->BadObjLibFiles, this->Target,
  137. this->GlobalGenerator->GetCMakeInstance());
  138. }
  139. void Accept(cmSourceFile *sf)
  140. {
  141. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  142. if(sf->GetCustomCommand())
  143. {
  144. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  145. }
  146. else if(this->Target->GetType() == cmTarget::UTILITY)
  147. {
  148. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  149. }
  150. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  151. {
  152. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  153. }
  154. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  155. {
  156. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  157. if(this->IsObjLib)
  158. {
  159. this->BadObjLibFiles.push_back(sf);
  160. }
  161. }
  162. else if(!sf->GetLanguage().empty())
  163. {
  164. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  165. }
  166. else if(ext == "def")
  167. {
  168. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  169. sf);
  170. if(this->IsObjLib)
  171. {
  172. this->BadObjLibFiles.push_back(sf);
  173. }
  174. }
  175. else if(ext == "idl")
  176. {
  177. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  178. if(this->IsObjLib)
  179. {
  180. this->BadObjLibFiles.push_back(sf);
  181. }
  182. }
  183. else if(ext == "resx")
  184. {
  185. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  186. }
  187. else if (ext == "appxmanifest")
  188. {
  189. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  190. }
  191. else if (ext == "pfx")
  192. {
  193. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  194. }
  195. else if (ext == "xaml")
  196. {
  197. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  198. }
  199. else if(this->Header.find(sf->GetFullPath().c_str()))
  200. {
  201. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  202. }
  203. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  204. {
  205. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  206. }
  207. else
  208. {
  209. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  210. }
  211. }
  212. };
  213. //----------------------------------------------------------------------------
  214. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  215. : Target(t),
  216. SourceFileFlagsConstructed(false),
  217. PolicyWarnedCMP0022(false)
  218. {
  219. this->Makefile = this->Target->GetMakefile();
  220. this->LocalGenerator = lg;
  221. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  222. }
  223. cmGeneratorTarget::~cmGeneratorTarget()
  224. {
  225. cmDeleteAll(this->LinkInformation);
  226. this->LinkInformation.clear();
  227. }
  228. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  229. {
  230. return this->LocalGenerator;
  231. }
  232. //----------------------------------------------------------------------------
  233. int cmGeneratorTarget::GetType() const
  234. {
  235. return this->Target->GetType();
  236. }
  237. //----------------------------------------------------------------------------
  238. std::string cmGeneratorTarget::GetName() const
  239. {
  240. return this->Target->GetName();
  241. }
  242. //----------------------------------------------------------------------------
  243. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  244. {
  245. return this->Target->GetProperty(prop);
  246. }
  247. //----------------------------------------------------------------------------
  248. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  249. bool implib) const
  250. {
  251. // Lookup/compute/cache the output name for this configuration.
  252. OutputNameKey key(config, implib);
  253. cmGeneratorTarget::OutputNameMapType::iterator i =
  254. this->OutputNameMap.find(key);
  255. if(i == this->OutputNameMap.end())
  256. {
  257. // Add empty name in map to detect potential recursion.
  258. OutputNameMapType::value_type entry(key, "");
  259. i = this->OutputNameMap.insert(entry).first;
  260. // Compute output name.
  261. std::vector<std::string> props;
  262. std::string type = this->Target->GetOutputTargetType(implib);
  263. std::string configUpper = cmSystemTools::UpperCase(config);
  264. if(!type.empty() && !configUpper.empty())
  265. {
  266. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  267. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  268. }
  269. if(!type.empty())
  270. {
  271. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  272. props.push_back(type + "_OUTPUT_NAME");
  273. }
  274. if(!configUpper.empty())
  275. {
  276. // OUTPUT_NAME_<CONFIG>
  277. props.push_back("OUTPUT_NAME_" + configUpper);
  278. // <CONFIG>_OUTPUT_NAME
  279. props.push_back(configUpper + "_OUTPUT_NAME");
  280. }
  281. // OUTPUT_NAME
  282. props.push_back("OUTPUT_NAME");
  283. std::string outName;
  284. for(std::vector<std::string>::const_iterator it = props.begin();
  285. it != props.end(); ++it)
  286. {
  287. if (const char* outNameProp = this->Target->GetProperty(*it))
  288. {
  289. outName = outNameProp;
  290. break;
  291. }
  292. }
  293. if(outName.empty())
  294. {
  295. outName = this->GetName();
  296. }
  297. // Now evaluate genex and update the previously-prepared map entry.
  298. cmGeneratorExpression ge;
  299. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  300. i->second = cge->Evaluate(this->Makefile, config);
  301. }
  302. else if(i->second.empty())
  303. {
  304. // An empty map entry indicates we have been called recursively
  305. // from the above block.
  306. this->Makefile->GetCMakeInstance()->IssueMessage(
  307. cmake::FATAL_ERROR,
  308. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  309. this->Target->GetBacktrace());
  310. }
  311. return i->second;
  312. }
  313. //----------------------------------------------------------------------------
  314. std::vector<cmSourceFile*> const*
  315. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  316. {
  317. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  318. if(i != this->SourceEntries.end())
  319. {
  320. return &i->second.Depends;
  321. }
  322. return 0;
  323. }
  324. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  325. const std::string& config,
  326. cmTarget *headTarget,
  327. cmGeneratorExpressionDAGChecker *dagChecker,
  328. std::vector<std::string>& result,
  329. bool excludeImported)
  330. {
  331. if (const char* dirs =
  332. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  333. {
  334. cmGeneratorExpression ge;
  335. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  336. ->Evaluate(mf,
  337. config, false, headTarget,
  338. depTgt, dagChecker), result);
  339. }
  340. if (!depTgt->IsImported() || excludeImported)
  341. {
  342. return;
  343. }
  344. if (const char* dirs =
  345. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  346. {
  347. cmGeneratorExpression ge;
  348. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  349. ->Evaluate(mf,
  350. config, false, headTarget,
  351. depTgt, dagChecker), result);
  352. }
  353. }
  354. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  355. { \
  356. std::vector<cmSourceFile*> sourceFiles; \
  357. this->Target->GetSourceFiles(sourceFiles, config); \
  358. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  359. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  360. si != sourceFiles.end(); ++si) \
  361. { \
  362. visitor.Accept(*si); \
  363. } \
  364. } \
  365. #define IMPLEMENT_VISIT(DATA) \
  366. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  367. #define EMPTY
  368. #define COMMA ,
  369. //----------------------------------------------------------------------------
  370. void
  371. cmGeneratorTarget
  372. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  373. const std::string& config) const
  374. {
  375. IMPLEMENT_VISIT(ObjectSources);
  376. if (!this->Objects.empty())
  377. {
  378. return;
  379. }
  380. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  381. it != data.end(); ++it)
  382. {
  383. this->Objects[*it];
  384. }
  385. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  386. }
  387. void cmGeneratorTarget::ComputeObjectMapping()
  388. {
  389. if(!this->Objects.empty())
  390. {
  391. return;
  392. }
  393. std::vector<std::string> configs;
  394. this->Makefile->GetConfigurations(configs);
  395. if (configs.empty())
  396. {
  397. configs.push_back("");
  398. }
  399. for(std::vector<std::string>::const_iterator ci = configs.begin();
  400. ci != configs.end(); ++ci)
  401. {
  402. std::vector<cmSourceFile const*> sourceFiles;
  403. this->GetObjectSources(sourceFiles, *ci);
  404. }
  405. }
  406. //----------------------------------------------------------------------------
  407. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  408. const std::string& config) const
  409. {
  410. if(!config.empty())
  411. {
  412. std::string featureConfig = feature;
  413. featureConfig += "_";
  414. featureConfig += cmSystemTools::UpperCase(config);
  415. if(const char* value = this->Target->GetProperty(featureConfig))
  416. {
  417. return value;
  418. }
  419. }
  420. if(const char* value = this->Target->GetProperty(feature))
  421. {
  422. return value;
  423. }
  424. return this->LocalGenerator->GetFeature(feature, config);
  425. }
  426. //----------------------------------------------------------------------------
  427. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  428. const std::string& config) const
  429. {
  430. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  431. }
  432. //----------------------------------------------------------------------------
  433. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  434. {
  435. this->ComputeObjectMapping();
  436. return this->Objects[file];
  437. }
  438. //----------------------------------------------------------------------------
  439. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  440. {
  441. this->ExplicitObjectName.insert(sf);
  442. }
  443. //----------------------------------------------------------------------------
  444. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  445. {
  446. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  447. std::set<cmSourceFile const*>::const_iterator it
  448. = this->ExplicitObjectName.find(file);
  449. return it != this->ExplicitObjectName.end();
  450. }
  451. //----------------------------------------------------------------------------
  452. void cmGeneratorTarget
  453. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  454. const std::string& config) const
  455. {
  456. IMPLEMENT_VISIT(IDLSources);
  457. }
  458. //----------------------------------------------------------------------------
  459. void
  460. cmGeneratorTarget
  461. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  462. const std::string& config) const
  463. {
  464. IMPLEMENT_VISIT(HeaderSources);
  465. }
  466. //----------------------------------------------------------------------------
  467. void cmGeneratorTarget
  468. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  469. const std::string& config) const
  470. {
  471. IMPLEMENT_VISIT(ExtraSources);
  472. }
  473. //----------------------------------------------------------------------------
  474. void
  475. cmGeneratorTarget
  476. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  477. const std::string& config) const
  478. {
  479. IMPLEMENT_VISIT(CustomCommands);
  480. }
  481. //----------------------------------------------------------------------------
  482. void
  483. cmGeneratorTarget
  484. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  485. const std::string& config) const
  486. {
  487. IMPLEMENT_VISIT(ExternalObjects);
  488. }
  489. //----------------------------------------------------------------------------
  490. void
  491. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  492. const std::string& config) const
  493. {
  494. ResxData data;
  495. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  496. srcs = data.ExpectedResxHeaders;
  497. }
  498. //----------------------------------------------------------------------------
  499. void cmGeneratorTarget
  500. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  501. const std::string& config) const
  502. {
  503. ResxData data;
  504. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  505. srcs = data.ResxSources;
  506. }
  507. //----------------------------------------------------------------------------
  508. void
  509. cmGeneratorTarget
  510. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  511. const std::string& config) const
  512. {
  513. IMPLEMENT_VISIT(AppManifest);
  514. }
  515. //----------------------------------------------------------------------------
  516. void
  517. cmGeneratorTarget
  518. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  519. const std::string& config) const
  520. {
  521. IMPLEMENT_VISIT(Certificates);
  522. }
  523. //----------------------------------------------------------------------------
  524. void
  525. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  526. const std::string& config) const
  527. {
  528. XamlData data;
  529. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  530. headers = data.ExpectedXamlHeaders;
  531. }
  532. //----------------------------------------------------------------------------
  533. void
  534. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  535. const std::string& config) const
  536. {
  537. XamlData data;
  538. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  539. srcs = data.ExpectedXamlSources;
  540. }
  541. //----------------------------------------------------------------------------
  542. void cmGeneratorTarget
  543. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  544. const std::string& config) const
  545. {
  546. XamlData data;
  547. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  548. srcs = data.XamlSources;
  549. }
  550. //----------------------------------------------------------------------------
  551. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  552. {
  553. static std::string location;
  554. if (this->Target->IsImported())
  555. {
  556. location = this->Target->ImportedGetFullPath(config, false);
  557. }
  558. else
  559. {
  560. location = this->GetFullPath(config, false);
  561. }
  562. return location.c_str();
  563. }
  564. bool cmGeneratorTarget::IsImported() const
  565. {
  566. return this->Target->IsImported();
  567. }
  568. //----------------------------------------------------------------------------
  569. const char* cmGeneratorTarget::GetLocationForBuild() const
  570. {
  571. static std::string location;
  572. if(this->IsImported())
  573. {
  574. location = this->Target->ImportedGetFullPath("", false);
  575. return location.c_str();
  576. }
  577. // Now handle the deprecated build-time configuration location.
  578. location = this->Target->GetDirectory();
  579. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  580. if(cfgid && strcmp(cfgid, ".") != 0)
  581. {
  582. location += "/";
  583. location += cfgid;
  584. }
  585. if(this->Target->IsAppBundleOnApple())
  586. {
  587. std::string macdir = this->BuildMacContentDirectory("", "",
  588. false);
  589. if(!macdir.empty())
  590. {
  591. location += "/";
  592. location += macdir;
  593. }
  594. }
  595. location += "/";
  596. location += this->GetFullName("", false);
  597. return location.c_str();
  598. }
  599. //----------------------------------------------------------------------------
  600. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  601. const std::string& config) const
  602. {
  603. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  604. std::string config_upper;
  605. if(!config.empty())
  606. {
  607. config_upper = cmSystemTools::UpperCase(config);
  608. }
  609. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  610. IncludeCacheType::const_iterator iter =
  611. this->SystemIncludesCache.find(config_upper);
  612. if (iter == this->SystemIncludesCache.end())
  613. {
  614. cmGeneratorExpressionDAGChecker dagChecker(
  615. this->GetName(),
  616. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  617. bool excludeImported
  618. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  619. std::vector<std::string> result;
  620. for (std::set<std::string>::const_iterator
  621. it = this->Target->GetSystemIncludeDirectories().begin();
  622. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  623. {
  624. cmGeneratorExpression ge;
  625. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  626. ->Evaluate(this->Makefile,
  627. config, false, this->Target,
  628. &dagChecker), result);
  629. }
  630. std::vector<cmTarget const*> const& deps =
  631. this->GetLinkImplementationClosure(config);
  632. for(std::vector<cmTarget const*>::const_iterator
  633. li = deps.begin(), le = deps.end(); li != le; ++li)
  634. {
  635. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  636. &dagChecker, result, excludeImported);
  637. }
  638. std::set<std::string> unique;
  639. for(std::vector<std::string>::iterator li = result.begin();
  640. li != result.end(); ++li)
  641. {
  642. cmSystemTools::ConvertToUnixSlashes(*li);
  643. unique.insert(*li);
  644. }
  645. result.clear();
  646. result.insert(result.end(), unique.begin(), unique.end());
  647. IncludeCacheType::value_type entry(config_upper, result);
  648. iter = this->SystemIncludesCache.insert(entry).first;
  649. }
  650. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  651. }
  652. //----------------------------------------------------------------------------
  653. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  654. {
  655. return this->Target->GetPropertyAsBool(prop);
  656. }
  657. //----------------------------------------------------------------------------
  658. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  659. const std::string& config) const
  660. {
  661. this->Target->GetSourceFiles(files, config);
  662. }
  663. //----------------------------------------------------------------------------
  664. std::string
  665. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  666. {
  667. std::string prefix;
  668. std::string base;
  669. std::string suffix;
  670. this->GetFullNameInternal(config, false, prefix, base, suffix);
  671. // Check for a per-configuration output directory target property.
  672. std::string configUpper = cmSystemTools::UpperCase(config);
  673. std::string configProp = "COMPILE_PDB_NAME_";
  674. configProp += configUpper;
  675. const char* config_name = this->Target->GetProperty(configProp);
  676. if(config_name && *config_name)
  677. {
  678. return prefix + config_name + ".pdb";
  679. }
  680. const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
  681. if(name && *name)
  682. {
  683. return prefix + name + ".pdb";
  684. }
  685. return "";
  686. }
  687. //----------------------------------------------------------------------------
  688. std::string
  689. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  690. {
  691. std::string dir = this->GetCompilePDBDirectory(config);
  692. std::string name = this->GetCompilePDBName(config);
  693. if(dir.empty() && !name.empty())
  694. {
  695. dir = this->Target->GetPDBDirectory(config);
  696. }
  697. if(!dir.empty())
  698. {
  699. dir += "/";
  700. }
  701. return dir + name;
  702. }
  703. //----------------------------------------------------------------------------
  704. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  705. {
  706. // soname is supported only for shared libraries and modules,
  707. // and then only when the platform supports an soname flag.
  708. return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
  709. !this->GetPropertyAsBool("NO_SONAME") &&
  710. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  711. }
  712. //----------------------------------------------------------------------------
  713. bool
  714. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  715. {
  716. // Only executables and shared libraries can have an rpath and may
  717. // need relinking.
  718. if(this->GetType() != cmTarget::EXECUTABLE &&
  719. this->GetType() != cmTarget::SHARED_LIBRARY &&
  720. this->GetType() != cmTarget::MODULE_LIBRARY)
  721. {
  722. return false;
  723. }
  724. // If there is no install location this target will not be installed
  725. // and therefore does not need relinking.
  726. if(!this->Target->GetHaveInstallRule())
  727. {
  728. return false;
  729. }
  730. // If skipping all rpaths completely then no relinking is needed.
  731. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  732. {
  733. return false;
  734. }
  735. // If building with the install-tree rpath no relinking is needed.
  736. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  737. {
  738. return false;
  739. }
  740. // If chrpath is going to be used no relinking is needed.
  741. if(this->IsChrpathUsed(config))
  742. {
  743. return false;
  744. }
  745. // Check for rpath support on this platform.
  746. std::string ll = this->GetLinkerLanguage(config);
  747. if(!ll.empty())
  748. {
  749. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  750. flagVar += ll;
  751. flagVar += "_FLAG";
  752. if(!this->Makefile->IsSet(flagVar))
  753. {
  754. // There is no rpath support on this platform so nothing needs
  755. // relinking.
  756. return false;
  757. }
  758. }
  759. else
  760. {
  761. // No linker language is known. This error will be reported by
  762. // other code.
  763. return false;
  764. }
  765. // If either a build or install tree rpath is set then the rpath
  766. // will likely change between the build tree and install tree and
  767. // this target must be relinked.
  768. return this->Target->HaveBuildTreeRPATH(config)
  769. || this->Target->HaveInstallTreeRPATH();
  770. }
  771. //----------------------------------------------------------------------------
  772. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  773. {
  774. // Only certain target types have an rpath.
  775. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  776. this->GetType() == cmTarget::MODULE_LIBRARY ||
  777. this->GetType() == cmTarget::EXECUTABLE))
  778. {
  779. return false;
  780. }
  781. // If the target will not be installed we do not need to change its
  782. // rpath.
  783. if(!this->Target->GetHaveInstallRule())
  784. {
  785. return false;
  786. }
  787. // Skip chrpath if skipping rpath altogether.
  788. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  789. {
  790. return false;
  791. }
  792. // Skip chrpath if it does not need to be changed at install time.
  793. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  794. {
  795. return false;
  796. }
  797. // Allow the user to disable builtin chrpath explicitly.
  798. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  799. {
  800. return false;
  801. }
  802. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  803. {
  804. return true;
  805. }
  806. #if defined(CMAKE_USE_ELF_PARSER)
  807. // Enable if the rpath flag uses a separator and the target uses ELF
  808. // binaries.
  809. std::string ll = this->GetLinkerLanguage(config);
  810. if(!ll.empty())
  811. {
  812. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  813. sepVar += ll;
  814. sepVar += "_FLAG_SEP";
  815. const char* sep = this->Makefile->GetDefinition(sepVar);
  816. if(sep && *sep)
  817. {
  818. // TODO: Add ELF check to ABI detection and get rid of
  819. // CMAKE_EXECUTABLE_FORMAT.
  820. if(const char* fmt =
  821. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  822. {
  823. return strcmp(fmt, "ELF") == 0;
  824. }
  825. }
  826. }
  827. #endif
  828. static_cast<void>(config);
  829. return false;
  830. }
  831. //----------------------------------------------------------------------------
  832. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  833. {
  834. if(this->Target->IsImported())
  835. {
  836. // Lookup the imported soname.
  837. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  838. {
  839. if(info->NoSOName)
  840. {
  841. // The imported library has no builtin soname so the name
  842. // searched at runtime will be just the filename.
  843. return cmSystemTools::GetFilenameName(info->Location);
  844. }
  845. else
  846. {
  847. // Use the soname given if any.
  848. if(info->SOName.find("@rpath/") == 0)
  849. {
  850. return info->SOName.substr(6);
  851. }
  852. return info->SOName;
  853. }
  854. }
  855. else
  856. {
  857. return "";
  858. }
  859. }
  860. else
  861. {
  862. // Compute the soname that will be built.
  863. std::string name;
  864. std::string soName;
  865. std::string realName;
  866. std::string impName;
  867. std::string pdbName;
  868. this->GetLibraryNames(name, soName, realName,
  869. impName, pdbName, config);
  870. return soName;
  871. }
  872. }
  873. //----------------------------------------------------------------------------
  874. std::string
  875. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  876. bool contentOnly) const
  877. {
  878. std::string fpath = this->GetFullName(config, false);
  879. fpath += ".app";
  880. if(!this->Makefile->PlatformIsAppleIos())
  881. {
  882. fpath += "/Contents";
  883. if(!contentOnly)
  884. fpath += "/MacOS";
  885. }
  886. return fpath;
  887. }
  888. //----------------------------------------------------------------------------
  889. bool cmGeneratorTarget::IsBundleOnApple() const
  890. {
  891. return this->Target->IsFrameworkOnApple()
  892. || this->Target->IsAppBundleOnApple()
  893. || this->Target->IsCFBundleOnApple();
  894. }
  895. //----------------------------------------------------------------------------
  896. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  897. bool contentOnly) const
  898. {
  899. std::string fpath;
  900. fpath += this->GetOutputName(config, false);
  901. fpath += ".";
  902. const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
  903. if (!ext)
  904. {
  905. if (this->Target->IsXCTestOnApple())
  906. {
  907. ext = "xctest";
  908. }
  909. else
  910. {
  911. ext = "bundle";
  912. }
  913. }
  914. fpath += ext;
  915. if(!this->Makefile->PlatformIsAppleIos())
  916. {
  917. fpath += "/Contents";
  918. if(!contentOnly)
  919. fpath += "/MacOS";
  920. }
  921. return fpath;
  922. }
  923. //----------------------------------------------------------------------------
  924. std::string
  925. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  926. bool rootDir) const
  927. {
  928. std::string fpath;
  929. fpath += this->GetOutputName(config, false);
  930. fpath += ".framework";
  931. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  932. {
  933. fpath += "/Versions/";
  934. fpath += this->Target->GetFrameworkVersion();
  935. }
  936. return fpath;
  937. }
  938. //----------------------------------------------------------------------------
  939. std::string
  940. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  941. {
  942. if(this->Target->IsImported())
  943. {
  944. return this->Target->GetFullNameImported(config, implib);
  945. }
  946. else
  947. {
  948. return this->GetFullNameInternal(config, implib);
  949. }
  950. }
  951. //----------------------------------------------------------------------------
  952. std::string
  953. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  954. const std::string& config) const
  955. {
  956. // If building directly for installation then the build tree install_name
  957. // is the same as the install tree.
  958. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  959. {
  960. return this->GetInstallNameDirForInstallTree();
  961. }
  962. // Use the build tree directory for the target.
  963. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  964. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  965. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  966. {
  967. std::string dir;
  968. if(this->Target->MacOSXRpathInstallNameDirDefault())
  969. {
  970. dir = "@rpath";
  971. }
  972. else
  973. {
  974. dir = this->Target->GetDirectory(config);
  975. }
  976. dir += "/";
  977. return dir;
  978. }
  979. else
  980. {
  981. return "";
  982. }
  983. }
  984. //----------------------------------------------------------------------------
  985. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  986. {
  987. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  988. {
  989. std::string dir;
  990. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  991. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  992. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  993. {
  994. if(install_name_dir && *install_name_dir)
  995. {
  996. dir = install_name_dir;
  997. dir += "/";
  998. }
  999. }
  1000. if(!install_name_dir)
  1001. {
  1002. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1003. {
  1004. dir = "@rpath/";
  1005. }
  1006. }
  1007. return dir;
  1008. }
  1009. else
  1010. {
  1011. return "";
  1012. }
  1013. }
  1014. //----------------------------------------------------------------------------
  1015. class cmTargetCollectLinkLanguages
  1016. {
  1017. public:
  1018. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1019. const std::string& config,
  1020. UNORDERED_SET<std::string>& languages,
  1021. cmTarget const* head):
  1022. Config(config), Languages(languages), HeadTarget(head),
  1023. Makefile(target->Target->GetMakefile()), Target(target)
  1024. { this->Visited.insert(target->Target); }
  1025. void Visit(cmLinkItem const& item)
  1026. {
  1027. if(!item.Target)
  1028. {
  1029. if(item.find("::") != std::string::npos)
  1030. {
  1031. bool noMessage = false;
  1032. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1033. std::stringstream e;
  1034. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1035. {
  1036. case cmPolicies::WARN:
  1037. {
  1038. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1039. messageType = cmake::AUTHOR_WARNING;
  1040. }
  1041. break;
  1042. case cmPolicies::OLD:
  1043. noMessage = true;
  1044. case cmPolicies::REQUIRED_IF_USED:
  1045. case cmPolicies::REQUIRED_ALWAYS:
  1046. case cmPolicies::NEW:
  1047. // Issue the fatal message.
  1048. break;
  1049. }
  1050. if(!noMessage)
  1051. {
  1052. e << "Target \"" << this->Target->GetName()
  1053. << "\" links to target \"" << item
  1054. << "\" but the target was not found. Perhaps a find_package() "
  1055. "call is missing for an IMPORTED target, or an ALIAS target is "
  1056. "missing?";
  1057. this->Makefile->GetCMakeInstance()->IssueMessage(
  1058. messageType, e.str(), this->Target->Target->GetBacktrace());
  1059. }
  1060. }
  1061. return;
  1062. }
  1063. if(!this->Visited.insert(item.Target).second)
  1064. {
  1065. return;
  1066. }
  1067. cmGeneratorTarget* gtgt =
  1068. this->Target->GetLocalGenerator()->GetGlobalGenerator()
  1069. ->GetGeneratorTarget(item.Target);
  1070. cmLinkInterface const* iface =
  1071. gtgt->GetLinkInterface(this->Config, this->HeadTarget);
  1072. if(!iface) { return; }
  1073. for(std::vector<std::string>::const_iterator
  1074. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1075. {
  1076. this->Languages.insert(*li);
  1077. }
  1078. for(std::vector<cmLinkItem>::const_iterator
  1079. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1080. {
  1081. this->Visit(*li);
  1082. }
  1083. }
  1084. private:
  1085. std::string Config;
  1086. UNORDERED_SET<std::string>& Languages;
  1087. cmTarget const* HeadTarget;
  1088. cmMakefile* Makefile;
  1089. const cmGeneratorTarget* Target;
  1090. std::set<cmTarget const*> Visited;
  1091. };
  1092. //----------------------------------------------------------------------------
  1093. cmGeneratorTarget::LinkClosure const*
  1094. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1095. {
  1096. std::string key(cmSystemTools::UpperCase(config));
  1097. LinkClosureMapType::iterator
  1098. i = this->LinkClosureMap.find(key);
  1099. if(i == this->LinkClosureMap.end())
  1100. {
  1101. LinkClosure lc;
  1102. this->ComputeLinkClosure(config, lc);
  1103. LinkClosureMapType::value_type entry(key, lc);
  1104. i = this->LinkClosureMap.insert(entry).first;
  1105. }
  1106. return &i->second;
  1107. }
  1108. //----------------------------------------------------------------------------
  1109. class cmTargetSelectLinker
  1110. {
  1111. int Preference;
  1112. cmGeneratorTarget const* Target;
  1113. cmMakefile* Makefile;
  1114. cmGlobalGenerator* GG;
  1115. std::set<std::string> Preferred;
  1116. public:
  1117. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1118. : Preference(0), Target(target)
  1119. {
  1120. this->Makefile = this->Target->Makefile;
  1121. this->GG = this->Makefile->GetGlobalGenerator();
  1122. }
  1123. void Consider(const char* lang)
  1124. {
  1125. int preference = this->GG->GetLinkerPreference(lang);
  1126. if(preference > this->Preference)
  1127. {
  1128. this->Preference = preference;
  1129. this->Preferred.clear();
  1130. }
  1131. if(preference == this->Preference)
  1132. {
  1133. this->Preferred.insert(lang);
  1134. }
  1135. }
  1136. std::string Choose()
  1137. {
  1138. if(this->Preferred.empty())
  1139. {
  1140. return "";
  1141. }
  1142. else if(this->Preferred.size() > 1)
  1143. {
  1144. std::stringstream e;
  1145. e << "Target " << this->Target->GetName()
  1146. << " contains multiple languages with the highest linker preference"
  1147. << " (" << this->Preference << "):\n";
  1148. for(std::set<std::string>::const_iterator
  1149. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1150. {
  1151. e << " " << *li << "\n";
  1152. }
  1153. e << "Set the LINKER_LANGUAGE property for this target.";
  1154. cmake* cm = this->Makefile->GetCMakeInstance();
  1155. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1156. this->Target->Target->GetBacktrace());
  1157. }
  1158. return *this->Preferred.begin();
  1159. }
  1160. };
  1161. //----------------------------------------------------------------------------
  1162. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1163. LinkClosure& lc) const
  1164. {
  1165. // Get languages built in this target.
  1166. UNORDERED_SET<std::string> languages;
  1167. cmTarget::LinkImplementation const* impl =
  1168. this->Target->GetLinkImplementation(config);
  1169. assert(impl);
  1170. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1171. li != impl->Languages.end(); ++li)
  1172. {
  1173. languages.insert(*li);
  1174. }
  1175. // Add interface languages from linked targets.
  1176. cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
  1177. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1178. li != impl->Libraries.end(); ++li)
  1179. {
  1180. cll.Visit(*li);
  1181. }
  1182. // Store the transitive closure of languages.
  1183. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1184. li != languages.end(); ++li)
  1185. {
  1186. lc.Languages.push_back(*li);
  1187. }
  1188. // Choose the language whose linker should be used.
  1189. if(this->GetProperty("HAS_CXX"))
  1190. {
  1191. lc.LinkerLanguage = "CXX";
  1192. }
  1193. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1194. {
  1195. lc.LinkerLanguage = linkerLang;
  1196. }
  1197. else
  1198. {
  1199. // Find the language with the highest preference value.
  1200. cmTargetSelectLinker tsl(this);
  1201. // First select from the languages compiled directly in this target.
  1202. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1203. li != impl->Languages.end(); ++li)
  1204. {
  1205. tsl.Consider(li->c_str());
  1206. }
  1207. // Now consider languages that propagate from linked targets.
  1208. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1209. sit != languages.end(); ++sit)
  1210. {
  1211. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1212. if(this->Makefile->IsOn(propagates))
  1213. {
  1214. tsl.Consider(sit->c_str());
  1215. }
  1216. }
  1217. lc.LinkerLanguage = tsl.Choose();
  1218. }
  1219. }
  1220. //----------------------------------------------------------------------------
  1221. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1222. std::string& base,
  1223. std::string& suffix,
  1224. const std::string& config,
  1225. bool implib) const
  1226. {
  1227. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1228. }
  1229. //----------------------------------------------------------------------------
  1230. std::string
  1231. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1232. const std::string& config,
  1233. bool contentOnly) const
  1234. {
  1235. std::string fpath = base;
  1236. if(this->Target->IsAppBundleOnApple())
  1237. {
  1238. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1239. }
  1240. if(this->Target->IsFrameworkOnApple())
  1241. {
  1242. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1243. }
  1244. if(this->Target->IsCFBundleOnApple())
  1245. {
  1246. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1247. }
  1248. return fpath;
  1249. }
  1250. //----------------------------------------------------------------------------
  1251. std::string
  1252. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1253. bool implib) const
  1254. {
  1255. // Start with the output directory for the target.
  1256. std::string fpath = this->Target->GetDirectory(config, implib);
  1257. fpath += "/";
  1258. bool contentOnly = true;
  1259. if(this->Target->IsFrameworkOnApple())
  1260. {
  1261. // additional files with a framework go into the version specific
  1262. // directory
  1263. contentOnly = false;
  1264. }
  1265. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1266. return fpath;
  1267. }
  1268. //----------------------------------------------------------------------------
  1269. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1270. const std::string& config) const
  1271. {
  1272. // There is no compile information for imported targets.
  1273. if(this->IsImported())
  1274. {
  1275. return 0;
  1276. }
  1277. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  1278. {
  1279. std::string msg = "cmTarget::GetCompileInfo called for ";
  1280. msg += this->GetName();
  1281. msg += " which has type ";
  1282. msg += cmTarget::GetTargetTypeName(this->Target->GetType());
  1283. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1284. return 0;
  1285. }
  1286. // Lookup/compute/cache the compile information for this configuration.
  1287. std::string config_upper;
  1288. if(!config.empty())
  1289. {
  1290. config_upper = cmSystemTools::UpperCase(config);
  1291. }
  1292. CompileInfoMapType::const_iterator i =
  1293. this->CompileInfoMap.find(config_upper);
  1294. if(i == this->CompileInfoMap.end())
  1295. {
  1296. CompileInfo info;
  1297. this->Target
  1298. ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1299. CompileInfoMapType::value_type entry(config_upper, info);
  1300. i = this->CompileInfoMap.insert(entry).first;
  1301. }
  1302. return &i->second;
  1303. }
  1304. //----------------------------------------------------------------------------
  1305. std::string
  1306. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1307. {
  1308. std::string data;
  1309. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1310. return data;
  1311. }
  1312. //----------------------------------------------------------------------------
  1313. void
  1314. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1315. const std::string &config) const
  1316. {
  1317. std::vector<cmSourceFile const*> objectFiles;
  1318. this->GetExternalObjects(objectFiles, config);
  1319. std::vector<cmTarget*> objectLibraries;
  1320. for(std::vector<cmSourceFile const*>::const_iterator
  1321. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1322. {
  1323. std::string objLib = (*it)->GetObjectLibrary();
  1324. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  1325. {
  1326. objectLibraries.push_back(tgt);
  1327. }
  1328. }
  1329. std::vector<cmTarget*>::const_iterator end
  1330. = cmRemoveDuplicates(objectLibraries);
  1331. for(std::vector<cmTarget*>::const_iterator
  1332. ti = objectLibraries.begin();
  1333. ti != end; ++ti)
  1334. {
  1335. cmTarget* objLib = *ti;
  1336. cmGeneratorTarget* ogt =
  1337. this->GlobalGenerator->GetGeneratorTarget(objLib);
  1338. std::vector<cmSourceFile const*> objectSources;
  1339. ogt->GetObjectSources(objectSources, config);
  1340. for(std::vector<cmSourceFile const*>::const_iterator
  1341. si = objectSources.begin();
  1342. si != objectSources.end(); ++si)
  1343. {
  1344. std::string obj = ogt->ObjectDirectory;
  1345. obj += ogt->Objects[*si];
  1346. objs.push_back(obj);
  1347. }
  1348. }
  1349. }
  1350. //----------------------------------------------------------------------------
  1351. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1352. const std::string& config) const
  1353. {
  1354. const char *prop
  1355. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1356. config);
  1357. if (!prop)
  1358. {
  1359. return;
  1360. }
  1361. cmGeneratorExpression ge;
  1362. cmGeneratorExpressionDAGChecker dagChecker(
  1363. this->GetName(),
  1364. "AUTOUIC_OPTIONS", 0, 0);
  1365. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1366. ->Evaluate(this->Makefile,
  1367. config,
  1368. false,
  1369. this->Target,
  1370. &dagChecker),
  1371. result);
  1372. }
  1373. //----------------------------------------------------------------------------
  1374. void processILibs(const std::string& config,
  1375. cmTarget const* headTarget,
  1376. cmLinkItem const& item,
  1377. cmGlobalGenerator* gg,
  1378. std::vector<cmTarget const*>& tgts,
  1379. std::set<cmTarget const*>& emitted)
  1380. {
  1381. if (item.Target && emitted.insert(item.Target).second)
  1382. {
  1383. tgts.push_back(item.Target);
  1384. cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target);
  1385. if(cmLinkInterfaceLibraries const* iface =
  1386. gt->GetLinkInterfaceLibraries(config, headTarget, true))
  1387. {
  1388. for(std::vector<cmLinkItem>::const_iterator
  1389. it = iface->Libraries.begin();
  1390. it != iface->Libraries.end(); ++it)
  1391. {
  1392. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1393. }
  1394. }
  1395. }
  1396. }
  1397. //----------------------------------------------------------------------------
  1398. const std::vector<const cmTarget*>&
  1399. cmGeneratorTarget::GetLinkImplementationClosure(
  1400. const std::string& config) const
  1401. {
  1402. LinkImplClosure& tgts =
  1403. this->LinkImplClosureMap[config];
  1404. if(!tgts.Done)
  1405. {
  1406. tgts.Done = true;
  1407. std::set<cmTarget const*> emitted;
  1408. cmLinkImplementationLibraries const* impl
  1409. = this->Target->GetLinkImplementationLibraries(config);
  1410. for(std::vector<cmLinkImplItem>::const_iterator
  1411. it = impl->Libraries.begin();
  1412. it != impl->Libraries.end(); ++it)
  1413. {
  1414. processILibs(config, this->Target, *it,
  1415. this->LocalGenerator->GetGlobalGenerator(),
  1416. tgts , emitted);
  1417. }
  1418. }
  1419. return tgts;
  1420. }
  1421. //----------------------------------------------------------------------------
  1422. class cmTargetTraceDependencies
  1423. {
  1424. public:
  1425. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1426. void Trace();
  1427. private:
  1428. cmTarget* Target;
  1429. cmGeneratorTarget* GeneratorTarget;
  1430. cmMakefile* Makefile;
  1431. cmGlobalGenerator const* GlobalGenerator;
  1432. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1433. SourceEntry* CurrentEntry;
  1434. std::queue<cmSourceFile*> SourceQueue;
  1435. std::set<cmSourceFile*> SourcesQueued;
  1436. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1437. NameMapType NameMap;
  1438. std::vector<std::string> NewSources;
  1439. void QueueSource(cmSourceFile* sf);
  1440. void FollowName(std::string const& name);
  1441. void FollowNames(std::vector<std::string> const& names);
  1442. bool IsUtility(std::string const& dep);
  1443. void CheckCustomCommand(cmCustomCommand const& cc);
  1444. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1445. void FollowCommandDepends(cmCustomCommand const& cc,
  1446. const std::string& config,
  1447. std::set<std::string>& emitted);
  1448. };
  1449. //----------------------------------------------------------------------------
  1450. cmTargetTraceDependencies
  1451. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  1452. Target(target->Target), GeneratorTarget(target)
  1453. {
  1454. // Convenience.
  1455. this->Makefile = this->Target->GetMakefile();
  1456. this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
  1457. this->CurrentEntry = 0;
  1458. // Queue all the source files already specified for the target.
  1459. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1460. {
  1461. std::vector<std::string> configs;
  1462. this->Makefile->GetConfigurations(configs);
  1463. if (configs.empty())
  1464. {
  1465. configs.push_back("");
  1466. }
  1467. std::set<cmSourceFile*> emitted;
  1468. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1469. ci != configs.end(); ++ci)
  1470. {
  1471. std::vector<cmSourceFile*> sources;
  1472. this->Target->GetSourceFiles(sources, *ci);
  1473. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1474. si != sources.end(); ++si)
  1475. {
  1476. cmSourceFile* sf = *si;
  1477. const std::set<cmTarget const*> tgts =
  1478. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1479. if (tgts.find(this->Target) != tgts.end())
  1480. {
  1481. std::ostringstream e;
  1482. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1483. << "\"\ndepends on the sources of a target it is used in. This "
  1484. "is a dependency loop and is not allowed.";
  1485. this->GeneratorTarget
  1486. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1487. return;
  1488. }
  1489. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  1490. {
  1491. this->SourceQueue.push(sf);
  1492. }
  1493. }
  1494. }
  1495. }
  1496. // Queue pre-build, pre-link, and post-build rule dependencies.
  1497. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1498. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1499. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1500. }
  1501. //----------------------------------------------------------------------------
  1502. void cmTargetTraceDependencies::Trace()
  1503. {
  1504. // Process one dependency at a time until the queue is empty.
  1505. while(!this->SourceQueue.empty())
  1506. {
  1507. // Get the next source from the queue.
  1508. cmSourceFile* sf = this->SourceQueue.front();
  1509. this->SourceQueue.pop();
  1510. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  1511. // Queue dependencies added explicitly by the user.
  1512. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1513. {
  1514. std::vector<std::string> objDeps;
  1515. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1516. for(std::vector<std::string>::iterator odi = objDeps.begin();
  1517. odi != objDeps.end(); ++odi)
  1518. {
  1519. if (cmSystemTools::FileIsFullPath(*odi))
  1520. {
  1521. *odi = cmSystemTools::CollapseFullPath(*odi);
  1522. }
  1523. }
  1524. this->FollowNames(objDeps);
  1525. }
  1526. // Queue the source needed to generate this file, if any.
  1527. this->FollowName(sf->GetFullPath());
  1528. // Queue dependencies added programatically by commands.
  1529. this->FollowNames(sf->GetDepends());
  1530. // Queue custom command dependencies.
  1531. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1532. {
  1533. this->CheckCustomCommand(*cc);
  1534. }
  1535. }
  1536. this->CurrentEntry = 0;
  1537. this->Target->AddTracedSources(this->NewSources);
  1538. }
  1539. //----------------------------------------------------------------------------
  1540. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1541. {
  1542. if(this->SourcesQueued.insert(sf).second)
  1543. {
  1544. this->SourceQueue.push(sf);
  1545. // Make sure this file is in the target at the end.
  1546. this->NewSources.push_back(sf->GetFullPath());
  1547. }
  1548. }
  1549. //----------------------------------------------------------------------------
  1550. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1551. {
  1552. NameMapType::iterator i = this->NameMap.find(name);
  1553. if(i == this->NameMap.end())
  1554. {
  1555. // Check if we know how to generate this file.
  1556. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1557. NameMapType::value_type entry(name, sf);
  1558. i = this->NameMap.insert(entry).first;
  1559. }
  1560. if(cmSourceFile* sf = i->second)
  1561. {
  1562. // Record the dependency we just followed.
  1563. if(this->CurrentEntry)
  1564. {
  1565. this->CurrentEntry->Depends.push_back(sf);
  1566. }
  1567. this->QueueSource(sf);
  1568. }
  1569. }
  1570. //----------------------------------------------------------------------------
  1571. void
  1572. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1573. {
  1574. for(std::vector<std::string>::const_iterator i = names.begin();
  1575. i != names.end(); ++i)
  1576. {
  1577. this->FollowName(*i);
  1578. }
  1579. }
  1580. //----------------------------------------------------------------------------
  1581. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1582. {
  1583. // Dependencies on targets (utilities) are supposed to be named by
  1584. // just the target name. However for compatibility we support
  1585. // naming the output file generated by the target (assuming there is
  1586. // no output-name property which old code would not have set). In
  1587. // that case the target name will be the file basename of the
  1588. // dependency.
  1589. std::string util = cmSystemTools::GetFilenameName(dep);
  1590. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1591. {
  1592. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1593. }
  1594. // Check for a target with this name.
  1595. if(cmGeneratorTarget* t
  1596. = this->Makefile->FindGeneratorTargetToUse(util))
  1597. {
  1598. // If we find the target and the dep was given as a full path,
  1599. // then make sure it was not a full path to something else, and
  1600. // the fact that the name matched a target was just a coincidence.
  1601. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1602. {
  1603. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1604. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1605. {
  1606. // This is really only for compatibility so we do not need to
  1607. // worry about configuration names and output names.
  1608. std::string tLocation = t->GetLocationForBuild();
  1609. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1610. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1611. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1612. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1613. if(depLocation == tLocation)
  1614. {
  1615. this->Target->AddUtility(util);
  1616. return true;
  1617. }
  1618. }
  1619. }
  1620. else
  1621. {
  1622. // The original name of the dependency was not a full path. It
  1623. // must name a target, so add the target-level dependency.
  1624. this->Target->AddUtility(util);
  1625. return true;
  1626. }
  1627. }
  1628. // The dependency does not name a target built in this project.
  1629. return false;
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. void
  1633. cmTargetTraceDependencies
  1634. ::CheckCustomCommand(cmCustomCommand const& cc)
  1635. {
  1636. // Transform command names that reference targets built in this
  1637. // project to corresponding target-level dependencies.
  1638. cmGeneratorExpression ge(cc.GetBacktrace());
  1639. // Add target-level dependencies referenced by generator expressions.
  1640. std::set<cmTarget*> targets;
  1641. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1642. cit != cc.GetCommandLines().end(); ++cit)
  1643. {
  1644. std::string const& command = *cit->begin();
  1645. // Check for a target with this name.
  1646. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1647. {
  1648. if(t->GetType() == cmTarget::EXECUTABLE)
  1649. {
  1650. // The command refers to an executable target built in
  1651. // this project. Add the target-level dependency to make
  1652. // sure the executable is up to date before this custom
  1653. // command possibly runs.
  1654. this->Target->AddUtility(command);
  1655. }
  1656. }
  1657. // Check for target references in generator expressions.
  1658. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1659. cli != cit->end(); ++cli)
  1660. {
  1661. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1662. = ge.Parse(*cli);
  1663. cge->Evaluate(this->Makefile, "", true);
  1664. std::set<cmTarget*> geTargets = cge->GetTargets();
  1665. targets.insert(geTargets.begin(), geTargets.end());
  1666. }
  1667. }
  1668. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1669. ti != targets.end(); ++ti)
  1670. {
  1671. this->Target->AddUtility((*ti)->GetName());
  1672. }
  1673. // Queue the custom command dependencies.
  1674. std::vector<std::string> configs;
  1675. std::set<std::string> emitted;
  1676. this->Makefile->GetConfigurations(configs);
  1677. if (configs.empty())
  1678. {
  1679. configs.push_back("");
  1680. }
  1681. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1682. ci != configs.end(); ++ci)
  1683. {
  1684. this->FollowCommandDepends(cc, *ci, emitted);
  1685. }
  1686. }
  1687. //----------------------------------------------------------------------------
  1688. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1689. const std::string& config,
  1690. std::set<std::string>& emitted)
  1691. {
  1692. cmCustomCommandGenerator ccg(cc, config,
  1693. this->GeneratorTarget->LocalGenerator);
  1694. const std::vector<std::string>& depends = ccg.GetDepends();
  1695. for(std::vector<std::string>::const_iterator di = depends.begin();
  1696. di != depends.end(); ++di)
  1697. {
  1698. std::string const& dep = *di;
  1699. if(emitted.insert(dep).second)
  1700. {
  1701. if(!this->IsUtility(dep))
  1702. {
  1703. // The dependency does not name a target and may be a file we
  1704. // know how to generate. Queue it.
  1705. this->FollowName(dep);
  1706. }
  1707. }
  1708. }
  1709. }
  1710. //----------------------------------------------------------------------------
  1711. void
  1712. cmTargetTraceDependencies
  1713. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1714. {
  1715. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1716. cli != commands.end(); ++cli)
  1717. {
  1718. this->CheckCustomCommand(*cli);
  1719. }
  1720. }
  1721. //----------------------------------------------------------------------------
  1722. void cmGeneratorTarget::TraceDependencies()
  1723. {
  1724. // CMake-generated targets have no dependencies to trace. Normally tracing
  1725. // would find nothing anyway, but when building CMake itself the "install"
  1726. // target command ends up referencing the "cmake" target but we do not
  1727. // really want the dependency because "install" depend on "all" anyway.
  1728. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1729. {
  1730. return;
  1731. }
  1732. // Use a helper object to trace the dependencies.
  1733. cmTargetTraceDependencies tracer(this);
  1734. tracer.Trace();
  1735. }
  1736. std::string
  1737. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  1738. {
  1739. if(CompileInfo const* info = this->GetCompileInfo(config))
  1740. {
  1741. return info->CompilePdbDir;
  1742. }
  1743. return "";
  1744. }
  1745. //----------------------------------------------------------------------------
  1746. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1747. std::vector<std::string>& archVec) const
  1748. {
  1749. const char* archs = 0;
  1750. if(!config.empty())
  1751. {
  1752. std::string defVarName = "OSX_ARCHITECTURES_";
  1753. defVarName += cmSystemTools::UpperCase(config);
  1754. archs = this->Target->GetProperty(defVarName);
  1755. }
  1756. if(!archs)
  1757. {
  1758. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1759. }
  1760. if(archs)
  1761. {
  1762. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1763. }
  1764. }
  1765. //----------------------------------------------------------------------------
  1766. std::string
  1767. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1768. std::string const& config) const
  1769. {
  1770. switch(this->GetType())
  1771. {
  1772. case cmTarget::STATIC_LIBRARY:
  1773. {
  1774. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1775. if(this->GetFeatureAsBool(
  1776. "INTERPROCEDURAL_OPTIMIZATION", config))
  1777. {
  1778. std::string varIPO = var + "_IPO";
  1779. if(this->Makefile->GetDefinition(varIPO))
  1780. {
  1781. return varIPO;
  1782. }
  1783. }
  1784. return var;
  1785. }
  1786. case cmTarget::SHARED_LIBRARY:
  1787. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1788. case cmTarget::MODULE_LIBRARY:
  1789. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1790. case cmTarget::EXECUTABLE:
  1791. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1792. default:
  1793. break;
  1794. }
  1795. return "";
  1796. }
  1797. //----------------------------------------------------------------------------
  1798. std::vector<std::string>
  1799. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1800. const std::string& lang) const
  1801. {
  1802. return this->Target->GetIncludeDirectories(config, lang);
  1803. }
  1804. //----------------------------------------------------------------------------
  1805. void cmGeneratorTarget::GenerateTargetManifest(
  1806. const std::string& config) const
  1807. {
  1808. if (this->Target->IsImported())
  1809. {
  1810. return;
  1811. }
  1812. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  1813. // Get the names.
  1814. std::string name;
  1815. std::string soName;
  1816. std::string realName;
  1817. std::string impName;
  1818. std::string pdbName;
  1819. if(this->GetType() == cmTarget::EXECUTABLE)
  1820. {
  1821. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1822. }
  1823. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1824. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1825. this->GetType() == cmTarget::MODULE_LIBRARY)
  1826. {
  1827. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  1828. config);
  1829. }
  1830. else
  1831. {
  1832. return;
  1833. }
  1834. // Get the directory.
  1835. std::string dir = this->Target->GetDirectory(config, false);
  1836. // Add each name.
  1837. std::string f;
  1838. if(!name.empty())
  1839. {
  1840. f = dir;
  1841. f += "/";
  1842. f += name;
  1843. gg->AddToManifest(f);
  1844. }
  1845. if(!soName.empty())
  1846. {
  1847. f = dir;
  1848. f += "/";
  1849. f += soName;
  1850. gg->AddToManifest(f);
  1851. }
  1852. if(!realName.empty())
  1853. {
  1854. f = dir;
  1855. f += "/";
  1856. f += realName;
  1857. gg->AddToManifest(f);
  1858. }
  1859. if(!pdbName.empty())
  1860. {
  1861. f = dir;
  1862. f += "/";
  1863. f += pdbName;
  1864. gg->AddToManifest(f);
  1865. }
  1866. if(!impName.empty())
  1867. {
  1868. f = this->Target->GetDirectory(config, true);
  1869. f += "/";
  1870. f += impName;
  1871. gg->AddToManifest(f);
  1872. }
  1873. }
  1874. //----------------------------------------------------------------------------
  1875. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1876. bool implib, bool realname) const
  1877. {
  1878. if(this->Target->IsImported())
  1879. {
  1880. return this->Target->ImportedGetFullPath(config, implib);
  1881. }
  1882. else
  1883. {
  1884. return this->NormalGetFullPath(config, implib, realname);
  1885. }
  1886. }
  1887. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1888. bool implib,
  1889. bool realname) const
  1890. {
  1891. std::string fpath = this->Target->GetDirectory(config, implib);
  1892. fpath += "/";
  1893. if(this->Target->IsAppBundleOnApple())
  1894. {
  1895. fpath = this->BuildMacContentDirectory(fpath, config, false);
  1896. fpath += "/";
  1897. }
  1898. // Add the full name of the target.
  1899. if(implib)
  1900. {
  1901. fpath += this->GetFullName(config, true);
  1902. }
  1903. else if(realname)
  1904. {
  1905. fpath += this->NormalGetRealName(config);
  1906. }
  1907. else
  1908. {
  1909. fpath += this->GetFullName(config, false);
  1910. }
  1911. return fpath;
  1912. }
  1913. //----------------------------------------------------------------------------
  1914. std::string
  1915. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1916. {
  1917. // This should not be called for imported targets.
  1918. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1919. // enforcement of the limited imported target API.
  1920. if(this->Target->IsImported())
  1921. {
  1922. std::string msg = "NormalGetRealName called on imported target: ";
  1923. msg += this->GetName();
  1924. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1925. }
  1926. if(this->GetType() == cmTarget::EXECUTABLE)
  1927. {
  1928. // Compute the real name that will be built.
  1929. std::string name;
  1930. std::string realName;
  1931. std::string impName;
  1932. std::string pdbName;
  1933. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1934. return realName;
  1935. }
  1936. else
  1937. {
  1938. // Compute the real name that will be built.
  1939. std::string name;
  1940. std::string soName;
  1941. std::string realName;
  1942. std::string impName;
  1943. std::string pdbName;
  1944. this->GetLibraryNames(name, soName, realName,
  1945. impName, pdbName, config);
  1946. return realName;
  1947. }
  1948. }
  1949. //----------------------------------------------------------------------------
  1950. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  1951. std::string& soName,
  1952. std::string& realName,
  1953. std::string& impName,
  1954. std::string& pdbName,
  1955. const std::string& config) const
  1956. {
  1957. // This should not be called for imported targets.
  1958. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1959. // enforcement of the limited imported target API.
  1960. if(this->Target->IsImported())
  1961. {
  1962. std::string msg = "GetLibraryNames called on imported target: ";
  1963. msg += this->GetName();
  1964. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  1965. msg);
  1966. return;
  1967. }
  1968. // Check for library version properties.
  1969. const char* version = this->GetProperty("VERSION");
  1970. const char* soversion = this->GetProperty("SOVERSION");
  1971. if(!this->HasSOName(config) ||
  1972. this->Target->IsFrameworkOnApple())
  1973. {
  1974. // Versioning is supported only for shared libraries and modules,
  1975. // and then only when the platform supports an soname flag.
  1976. version = 0;
  1977. soversion = 0;
  1978. }
  1979. if(version && !soversion)
  1980. {
  1981. // The soversion must be set if the library version is set. Use
  1982. // the library version as the soversion.
  1983. soversion = version;
  1984. }
  1985. if(!version && soversion)
  1986. {
  1987. // Use the soversion as the library version.
  1988. version = soversion;
  1989. }
  1990. // Get the components of the library name.
  1991. std::string prefix;
  1992. std::string base;
  1993. std::string suffix;
  1994. this->GetFullNameInternal(config, false, prefix, base, suffix);
  1995. // The library name.
  1996. name = prefix+base+suffix;
  1997. if(this->Target->IsFrameworkOnApple())
  1998. {
  1999. realName = prefix;
  2000. if(!this->Makefile->PlatformIsAppleIos())
  2001. {
  2002. realName += "Versions/";
  2003. realName += this->Target->GetFrameworkVersion();
  2004. realName += "/";
  2005. }
  2006. realName += base;
  2007. soName = realName;
  2008. }
  2009. else
  2010. {
  2011. // The library's soname.
  2012. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  2013. name, soversion);
  2014. // The library's real name on disk.
  2015. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  2016. name, version);
  2017. }
  2018. // The import library name.
  2019. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2020. this->GetType() == cmTarget::MODULE_LIBRARY)
  2021. {
  2022. impName = this->GetFullNameInternal(config, true);
  2023. }
  2024. else
  2025. {
  2026. impName = "";
  2027. }
  2028. // The program database file name.
  2029. pdbName = this->GetPDBName(config);
  2030. }
  2031. //----------------------------------------------------------------------------
  2032. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2033. std::string& realName,
  2034. std::string& impName,
  2035. std::string& pdbName,
  2036. const std::string& config) const
  2037. {
  2038. // This should not be called for imported targets.
  2039. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2040. // enforcement of the limited imported target API.
  2041. if(this->Target->IsImported())
  2042. {
  2043. std::string msg =
  2044. "GetExecutableNames called on imported target: ";
  2045. msg += this->GetName();
  2046. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2047. }
  2048. // This versioning is supported only for executables and then only
  2049. // when the platform supports symbolic links.
  2050. #if defined(_WIN32) && !defined(__CYGWIN__)
  2051. const char* version = 0;
  2052. #else
  2053. // Check for executable version properties.
  2054. const char* version = this->GetProperty("VERSION");
  2055. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2056. {
  2057. version = 0;
  2058. }
  2059. #endif
  2060. // Get the components of the executable name.
  2061. std::string prefix;
  2062. std::string base;
  2063. std::string suffix;
  2064. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2065. // The executable name.
  2066. name = prefix+base+suffix;
  2067. // The executable's real name on disk.
  2068. #if defined(__CYGWIN__)
  2069. realName = prefix+base;
  2070. #else
  2071. realName = name;
  2072. #endif
  2073. if(version)
  2074. {
  2075. realName += "-";
  2076. realName += version;
  2077. }
  2078. #if defined(__CYGWIN__)
  2079. realName += suffix;
  2080. #endif
  2081. // The import library name.
  2082. impName = this->GetFullNameInternal(config, true);
  2083. // The program database file name.
  2084. pdbName = this->GetPDBName(config);
  2085. }
  2086. //----------------------------------------------------------------------------
  2087. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2088. bool implib) const
  2089. {
  2090. std::string prefix;
  2091. std::string base;
  2092. std::string suffix;
  2093. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2094. return prefix+base+suffix;
  2095. }
  2096. //----------------------------------------------------------------------------
  2097. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2098. bool implib,
  2099. std::string& outPrefix,
  2100. std::string& outBase,
  2101. std::string& outSuffix) const
  2102. {
  2103. // Use just the target name for non-main target types.
  2104. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2105. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2106. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2107. this->GetType() != cmTarget::EXECUTABLE)
  2108. {
  2109. outPrefix = "";
  2110. outBase = this->GetName();
  2111. outSuffix = "";
  2112. return;
  2113. }
  2114. // Return an empty name for the import library if this platform
  2115. // does not support import libraries.
  2116. if(implib &&
  2117. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2118. {
  2119. outPrefix = "";
  2120. outBase = "";
  2121. outSuffix = "";
  2122. return;
  2123. }
  2124. // The implib option is only allowed for shared libraries, module
  2125. // libraries, and executables.
  2126. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2127. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2128. this->GetType() != cmTarget::EXECUTABLE)
  2129. {
  2130. implib = false;
  2131. }
  2132. // Compute the full name for main target types.
  2133. const char* targetPrefix = (implib
  2134. ? this->GetProperty("IMPORT_PREFIX")
  2135. : this->GetProperty("PREFIX"));
  2136. const char* targetSuffix = (implib
  2137. ? this->GetProperty("IMPORT_SUFFIX")
  2138. : this->GetProperty("SUFFIX"));
  2139. const char* configPostfix = 0;
  2140. if(!config.empty())
  2141. {
  2142. std::string configProp = cmSystemTools::UpperCase(config);
  2143. configProp += "_POSTFIX";
  2144. configPostfix = this->GetProperty(configProp);
  2145. // Mac application bundles and frameworks have no postfix.
  2146. if(configPostfix &&
  2147. (this->Target->IsAppBundleOnApple()
  2148. || this->Target->IsFrameworkOnApple()))
  2149. {
  2150. configPostfix = 0;
  2151. }
  2152. }
  2153. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2154. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2155. // Check for language-specific default prefix and suffix.
  2156. std::string ll = this->GetLinkerLanguage(config);
  2157. if(!ll.empty())
  2158. {
  2159. if(!targetSuffix && suffixVar && *suffixVar)
  2160. {
  2161. std::string langSuff = suffixVar + std::string("_") + ll;
  2162. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2163. }
  2164. if(!targetPrefix && prefixVar && *prefixVar)
  2165. {
  2166. std::string langPrefix = prefixVar + std::string("_") + ll;
  2167. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2168. }
  2169. }
  2170. // if there is no prefix on the target use the cmake definition
  2171. if(!targetPrefix && prefixVar)
  2172. {
  2173. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2174. }
  2175. // if there is no suffix on the target use the cmake definition
  2176. if(!targetSuffix && suffixVar)
  2177. {
  2178. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2179. }
  2180. // frameworks have directory prefix but no suffix
  2181. std::string fw_prefix;
  2182. if(this->Target->IsFrameworkOnApple())
  2183. {
  2184. fw_prefix = this->GetOutputName(config, false);
  2185. fw_prefix += ".framework/";
  2186. targetPrefix = fw_prefix.c_str();
  2187. targetSuffix = 0;
  2188. }
  2189. if(this->Target->IsCFBundleOnApple())
  2190. {
  2191. fw_prefix = this->GetCFBundleDirectory(config, false);
  2192. fw_prefix += "/";
  2193. targetPrefix = fw_prefix.c_str();
  2194. targetSuffix = 0;
  2195. }
  2196. // Begin the final name with the prefix.
  2197. outPrefix = targetPrefix?targetPrefix:"";
  2198. // Append the target name or property-specified name.
  2199. outBase += this->GetOutputName(config, implib);
  2200. // Append the per-configuration postfix.
  2201. outBase += configPostfix?configPostfix:"";
  2202. // Name shared libraries with their version number on some platforms.
  2203. if(const char* soversion = this->GetProperty("SOVERSION"))
  2204. {
  2205. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2206. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2207. {
  2208. outBase += "-";
  2209. outBase += soversion;
  2210. }
  2211. }
  2212. // Append the suffix.
  2213. outSuffix = targetSuffix?targetSuffix:"";
  2214. }
  2215. //----------------------------------------------------------------------------
  2216. std::string
  2217. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  2218. {
  2219. return this->GetLinkClosure(config)->LinkerLanguage;
  2220. }
  2221. //----------------------------------------------------------------------------
  2222. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2223. {
  2224. std::string prefix;
  2225. std::string base;
  2226. std::string suffix;
  2227. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2228. std::vector<std::string> props;
  2229. std::string configUpper =
  2230. cmSystemTools::UpperCase(config);
  2231. if(!configUpper.empty())
  2232. {
  2233. // PDB_NAME_<CONFIG>
  2234. props.push_back("PDB_NAME_" + configUpper);
  2235. }
  2236. // PDB_NAME
  2237. props.push_back("PDB_NAME");
  2238. for(std::vector<std::string>::const_iterator i = props.begin();
  2239. i != props.end(); ++i)
  2240. {
  2241. if(const char* outName = this->GetProperty(*i))
  2242. {
  2243. base = outName;
  2244. break;
  2245. }
  2246. }
  2247. return prefix+base+".pdb";
  2248. }
  2249. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  2250. cmTarget const* t2) const
  2251. {
  2252. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2253. if (nameResult == 0)
  2254. {
  2255. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  2256. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  2257. }
  2258. return nameResult < 0;
  2259. }
  2260. //----------------------------------------------------------------------------
  2261. struct cmGeneratorTarget::SourceFileFlags
  2262. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2263. {
  2264. struct SourceFileFlags flags;
  2265. this->ConstructSourceFileFlags();
  2266. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  2267. this->SourceFlagsMap.find(sf);
  2268. if(si != this->SourceFlagsMap.end())
  2269. {
  2270. flags = si->second;
  2271. }
  2272. else
  2273. {
  2274. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  2275. // were not listed in one of the other lists.
  2276. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  2277. {
  2278. flags.MacFolder = location;
  2279. if(strcmp(location, "Resources") == 0)
  2280. {
  2281. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2282. }
  2283. else
  2284. {
  2285. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  2286. }
  2287. }
  2288. }
  2289. return flags;
  2290. }
  2291. //----------------------------------------------------------------------------
  2292. void cmGeneratorTarget::ConstructSourceFileFlags() const
  2293. {
  2294. if(this->SourceFileFlagsConstructed)
  2295. {
  2296. return;
  2297. }
  2298. this->SourceFileFlagsConstructed = true;
  2299. // Process public headers to mark the source files.
  2300. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  2301. {
  2302. std::vector<std::string> relFiles;
  2303. cmSystemTools::ExpandListArgument(files, relFiles);
  2304. for(std::vector<std::string>::iterator it = relFiles.begin();
  2305. it != relFiles.end(); ++it)
  2306. {
  2307. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2308. {
  2309. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2310. flags.MacFolder = "Headers";
  2311. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  2312. }
  2313. }
  2314. }
  2315. // Process private headers after public headers so that they take
  2316. // precedence if a file is listed in both.
  2317. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  2318. {
  2319. std::vector<std::string> relFiles;
  2320. cmSystemTools::ExpandListArgument(files, relFiles);
  2321. for(std::vector<std::string>::iterator it = relFiles.begin();
  2322. it != relFiles.end(); ++it)
  2323. {
  2324. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2325. {
  2326. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2327. flags.MacFolder = "PrivateHeaders";
  2328. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  2329. }
  2330. }
  2331. }
  2332. // Mark sources listed as resources.
  2333. if(const char* files = this->Target->GetProperty("RESOURCE"))
  2334. {
  2335. std::vector<std::string> relFiles;
  2336. cmSystemTools::ExpandListArgument(files, relFiles);
  2337. for(std::vector<std::string>::iterator it = relFiles.begin();
  2338. it != relFiles.end(); ++it)
  2339. {
  2340. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2341. {
  2342. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2343. flags.MacFolder = "Resources";
  2344. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. //----------------------------------------------------------------------------
  2350. const cmGeneratorTarget::CompatibleInterfacesBase&
  2351. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  2352. {
  2353. cmGeneratorTarget::CompatibleInterfaces& compat =
  2354. this->CompatibleInterfacesMap[config];
  2355. if(!compat.Done)
  2356. {
  2357. compat.Done = true;
  2358. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  2359. compat.PropsString.insert("AUTOUIC_OPTIONS");
  2360. std::vector<cmTarget const*> const& deps =
  2361. this->GetLinkImplementationClosure(config);
  2362. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  2363. li != deps.end(); ++li)
  2364. {
  2365. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  2366. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  2367. { \
  2368. std::vector<std::string> props; \
  2369. cmSystemTools::ExpandListArgument(prop, props); \
  2370. compat.Props##x.insert(props.begin(), props.end()); \
  2371. }
  2372. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  2373. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  2374. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  2375. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  2376. #undef CM_READ_COMPATIBLE_INTERFACE
  2377. }
  2378. }
  2379. return compat;
  2380. }
  2381. //----------------------------------------------------------------------------
  2382. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  2383. const std::string &p, const std::string& config) const
  2384. {
  2385. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2386. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2387. {
  2388. return false;
  2389. }
  2390. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  2391. }
  2392. //----------------------------------------------------------------------------
  2393. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  2394. const std::string &p, const std::string& config) const
  2395. {
  2396. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2397. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2398. {
  2399. return false;
  2400. }
  2401. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  2402. }
  2403. //----------------------------------------------------------------------------
  2404. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  2405. const std::string &p, const std::string& config) const
  2406. {
  2407. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2408. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2409. {
  2410. return false;
  2411. }
  2412. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  2413. }
  2414. //----------------------------------------------------------------------------
  2415. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  2416. const std::string &p, const std::string& config) const
  2417. {
  2418. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2419. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2420. {
  2421. return false;
  2422. }
  2423. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  2424. }
  2425. enum CompatibleType
  2426. {
  2427. BoolType,
  2428. StringType,
  2429. NumberMinType,
  2430. NumberMaxType
  2431. };
  2432. template<typename PropertyType>
  2433. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2434. const std::string& prop,
  2435. const std::string& config,
  2436. CompatibleType,
  2437. PropertyType *);
  2438. template<>
  2439. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2440. const std::string& prop,
  2441. const std::string& config,
  2442. CompatibleType, bool *)
  2443. {
  2444. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  2445. }
  2446. template<>
  2447. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2448. const std::string& prop,
  2449. const std::string& config,
  2450. CompatibleType t,
  2451. const char **)
  2452. {
  2453. switch(t)
  2454. {
  2455. case BoolType:
  2456. assert(0 && "String compatibility check function called for boolean");
  2457. return 0;
  2458. case StringType:
  2459. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  2460. case NumberMinType:
  2461. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  2462. case NumberMaxType:
  2463. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  2464. }
  2465. assert(0 && "Unreachable!");
  2466. return 0;
  2467. }
  2468. //----------------------------------------------------------------------------
  2469. template<typename PropertyType>
  2470. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  2471. cmTarget const* dependee,
  2472. const std::string& propName,
  2473. std::set<std::string> &emitted,
  2474. const std::string& config,
  2475. CompatibleType t,
  2476. PropertyType *)
  2477. {
  2478. const char *prop = dependee->GetProperty(propName);
  2479. if (!prop)
  2480. {
  2481. return;
  2482. }
  2483. std::vector<std::string> props;
  2484. cmSystemTools::ExpandListArgument(prop, props);
  2485. std::string pdir =
  2486. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  2487. pdir += "/Help/prop_tgt/";
  2488. for(std::vector<std::string>::iterator pi = props.begin();
  2489. pi != props.end(); ++pi)
  2490. {
  2491. std::string pname = cmSystemTools::HelpFileName(*pi);
  2492. std::string pfile = pdir + pname + ".rst";
  2493. if(cmSystemTools::FileExists(pfile.c_str(), true))
  2494. {
  2495. std::ostringstream e;
  2496. e << "Target \"" << dependee->GetName() << "\" has property \""
  2497. << *pi << "\" listed in its " << propName << " property. "
  2498. "This is not allowed. Only user-defined properties may appear "
  2499. "listed in the " << propName << " property.";
  2500. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  2501. return;
  2502. }
  2503. if(emitted.insert(*pi).second)
  2504. {
  2505. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  2506. t, 0);
  2507. if (cmSystemTools::GetErrorOccuredFlag())
  2508. {
  2509. return;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. static std::string intersect(const std::set<std::string> &s1,
  2515. const std::set<std::string> &s2)
  2516. {
  2517. std::set<std::string> intersect;
  2518. std::set_intersection(s1.begin(),s1.end(),
  2519. s2.begin(),s2.end(),
  2520. std::inserter(intersect,intersect.begin()));
  2521. if (!intersect.empty())
  2522. {
  2523. return *intersect.begin();
  2524. }
  2525. return "";
  2526. }
  2527. static std::string intersect(const std::set<std::string> &s1,
  2528. const std::set<std::string> &s2,
  2529. const std::set<std::string> &s3)
  2530. {
  2531. std::string result;
  2532. result = intersect(s1, s2);
  2533. if (!result.empty())
  2534. return result;
  2535. result = intersect(s1, s3);
  2536. if (!result.empty())
  2537. return result;
  2538. return intersect(s2, s3);
  2539. }
  2540. static std::string intersect(const std::set<std::string> &s1,
  2541. const std::set<std::string> &s2,
  2542. const std::set<std::string> &s3,
  2543. const std::set<std::string> &s4)
  2544. {
  2545. std::string result;
  2546. result = intersect(s1, s2);
  2547. if (!result.empty())
  2548. return result;
  2549. result = intersect(s1, s3);
  2550. if (!result.empty())
  2551. return result;
  2552. result = intersect(s1, s4);
  2553. if (!result.empty())
  2554. return result;
  2555. return intersect(s2, s3, s4);
  2556. }
  2557. //----------------------------------------------------------------------------
  2558. void cmGeneratorTarget::CheckPropertyCompatibility(
  2559. cmComputeLinkInformation *info, const std::string& config) const
  2560. {
  2561. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  2562. std::set<std::string> emittedBools;
  2563. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  2564. std::set<std::string> emittedStrings;
  2565. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  2566. std::set<std::string> emittedMinNumbers;
  2567. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  2568. std::set<std::string> emittedMaxNumbers;
  2569. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  2570. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  2571. deps.begin(); li != deps.end(); ++li)
  2572. {
  2573. if (!li->Target)
  2574. {
  2575. continue;
  2576. }
  2577. checkPropertyConsistency<bool>(this, li->Target,
  2578. strBool,
  2579. emittedBools, config, BoolType, 0);
  2580. if (cmSystemTools::GetErrorOccuredFlag())
  2581. {
  2582. return;
  2583. }
  2584. checkPropertyConsistency<const char *>(this, li->Target,
  2585. strString,
  2586. emittedStrings, config,
  2587. StringType, 0);
  2588. if (cmSystemTools::GetErrorOccuredFlag())
  2589. {
  2590. return;
  2591. }
  2592. checkPropertyConsistency<const char *>(this, li->Target,
  2593. strNumMin,
  2594. emittedMinNumbers, config,
  2595. NumberMinType, 0);
  2596. if (cmSystemTools::GetErrorOccuredFlag())
  2597. {
  2598. return;
  2599. }
  2600. checkPropertyConsistency<const char *>(this, li->Target,
  2601. strNumMax,
  2602. emittedMaxNumbers, config,
  2603. NumberMaxType, 0);
  2604. if (cmSystemTools::GetErrorOccuredFlag())
  2605. {
  2606. return;
  2607. }
  2608. }
  2609. std::string prop = intersect(emittedBools,
  2610. emittedStrings,
  2611. emittedMinNumbers,
  2612. emittedMaxNumbers);
  2613. if (!prop.empty())
  2614. {
  2615. // Use a sorted std::vector to keep the error message sorted.
  2616. std::vector<std::string> props;
  2617. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  2618. if (i != emittedBools.end())
  2619. {
  2620. props.push_back(strBool);
  2621. }
  2622. i = emittedStrings.find(prop);
  2623. if (i != emittedStrings.end())
  2624. {
  2625. props.push_back(strString);
  2626. }
  2627. i = emittedMinNumbers.find(prop);
  2628. if (i != emittedMinNumbers.end())
  2629. {
  2630. props.push_back(strNumMin);
  2631. }
  2632. i = emittedMaxNumbers.find(prop);
  2633. if (i != emittedMaxNumbers.end())
  2634. {
  2635. props.push_back(strNumMax);
  2636. }
  2637. std::sort(props.begin(), props.end());
  2638. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  2639. propsString += " and the " + props.back();
  2640. std::ostringstream e;
  2641. e << "Property \"" << prop << "\" appears in both the "
  2642. << propsString <<
  2643. " property in the dependencies of target \"" << this->GetName() <<
  2644. "\". This is not allowed. A property may only require compatibility "
  2645. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  2646. "string interpretation, but not a mixture.";
  2647. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  2648. }
  2649. }
  2650. //----------------------------------------------------------------------------
  2651. std::string compatibilityType(CompatibleType t)
  2652. {
  2653. switch(t)
  2654. {
  2655. case BoolType:
  2656. return "Boolean compatibility";
  2657. case StringType:
  2658. return "String compatibility";
  2659. case NumberMaxType:
  2660. return "Numeric maximum compatibility";
  2661. case NumberMinType:
  2662. return "Numeric minimum compatibility";
  2663. }
  2664. assert(0 && "Unreachable!");
  2665. return "";
  2666. }
  2667. //----------------------------------------------------------------------------
  2668. std::string compatibilityAgree(CompatibleType t, bool dominant)
  2669. {
  2670. switch(t)
  2671. {
  2672. case BoolType:
  2673. case StringType:
  2674. return dominant ? "(Disagree)\n" : "(Agree)\n";
  2675. case NumberMaxType:
  2676. case NumberMinType:
  2677. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  2678. }
  2679. assert(0 && "Unreachable!");
  2680. return "";
  2681. }
  2682. //----------------------------------------------------------------------------
  2683. template<typename PropertyType>
  2684. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  2685. //----------------------------------------------------------------------------
  2686. template<>
  2687. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  2688. {
  2689. return tgt->GetPropertyAsBool(prop);
  2690. }
  2691. //----------------------------------------------------------------------------
  2692. template<>
  2693. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  2694. const std::string& prop)
  2695. {
  2696. return tgt->GetProperty(prop);
  2697. }
  2698. template<typename PropertyType>
  2699. std::string valueAsString(PropertyType);
  2700. template<>
  2701. std::string valueAsString<bool>(bool value)
  2702. {
  2703. return value ? "TRUE" : "FALSE";
  2704. }
  2705. template<>
  2706. std::string valueAsString<const char*>(const char* value)
  2707. {
  2708. return value ? value : "(unset)";
  2709. }
  2710. template<typename PropertyType>
  2711. PropertyType impliedValue(PropertyType);
  2712. template<>
  2713. bool impliedValue<bool>(bool)
  2714. {
  2715. return false;
  2716. }
  2717. template<>
  2718. const char* impliedValue<const char*>(const char*)
  2719. {
  2720. return "";
  2721. }
  2722. //----------------------------------------------------------------------------
  2723. template<typename PropertyType>
  2724. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  2725. PropertyType rhs,
  2726. CompatibleType t);
  2727. //----------------------------------------------------------------------------
  2728. template<>
  2729. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  2730. CompatibleType)
  2731. {
  2732. return std::make_pair(lhs == rhs, lhs);
  2733. }
  2734. //----------------------------------------------------------------------------
  2735. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  2736. const char *rhs)
  2737. {
  2738. const bool b = strcmp(lhs, rhs) == 0;
  2739. return std::make_pair(b, b ? lhs : 0);
  2740. }
  2741. //----------------------------------------------------------------------------
  2742. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  2743. const char *rhs,
  2744. CompatibleType t)
  2745. {
  2746. char *pEnd;
  2747. const char* const null_ptr = 0;
  2748. long lnum = strtol(lhs, &pEnd, 0);
  2749. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  2750. {
  2751. return std::pair<bool, const char*>(false, null_ptr);
  2752. }
  2753. long rnum = strtol(rhs, &pEnd, 0);
  2754. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  2755. {
  2756. return std::pair<bool, const char*>(false, null_ptr);
  2757. }
  2758. if (t == NumberMaxType)
  2759. {
  2760. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  2761. }
  2762. else
  2763. {
  2764. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  2765. }
  2766. }
  2767. //----------------------------------------------------------------------------
  2768. template<>
  2769. std::pair<bool, const char*> consistentProperty(const char *lhs,
  2770. const char *rhs,
  2771. CompatibleType t)
  2772. {
  2773. if (!lhs && !rhs)
  2774. {
  2775. return std::make_pair(true, lhs);
  2776. }
  2777. if (!lhs)
  2778. {
  2779. return std::make_pair(true, rhs);
  2780. }
  2781. if (!rhs)
  2782. {
  2783. return std::make_pair(true, lhs);
  2784. }
  2785. const char* const null_ptr = 0;
  2786. switch(t)
  2787. {
  2788. case BoolType:
  2789. assert(0 && "consistentProperty for strings called with BoolType");
  2790. return std::pair<bool, const char*>(false, null_ptr);
  2791. case StringType:
  2792. return consistentStringProperty(lhs, rhs);
  2793. case NumberMinType:
  2794. case NumberMaxType:
  2795. return consistentNumberProperty(lhs, rhs, t);
  2796. }
  2797. assert(0 && "Unreachable!");
  2798. return std::pair<bool, const char*>(false, null_ptr);
  2799. }
  2800. //----------------------------------------------------------------------------
  2801. template<typename PropertyType>
  2802. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  2803. const std::string &p,
  2804. const std::string& config,
  2805. const char *defaultValue,
  2806. CompatibleType t,
  2807. PropertyType *)
  2808. {
  2809. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  2810. const bool explicitlySet = tgt->Target->GetProperties()
  2811. .find(p)
  2812. != tgt->Target->GetProperties().end();
  2813. const bool impliedByUse =
  2814. tgt->Target->IsNullImpliedByLinkLibraries(p);
  2815. assert((impliedByUse ^ explicitlySet)
  2816. || (!impliedByUse && !explicitlySet));
  2817. std::vector<cmTarget const*> const& deps =
  2818. tgt->GetLinkImplementationClosure(config);
  2819. if(deps.empty())
  2820. {
  2821. return propContent;
  2822. }
  2823. bool propInitialized = explicitlySet;
  2824. std::string report = " * Target \"";
  2825. report += tgt->GetName();
  2826. if (explicitlySet)
  2827. {
  2828. report += "\" has property content \"";
  2829. report += valueAsString<PropertyType>(propContent);
  2830. report += "\"\n";
  2831. }
  2832. else if (impliedByUse)
  2833. {
  2834. report += "\" property is implied by use.\n";
  2835. }
  2836. else
  2837. {
  2838. report += "\" property not set.\n";
  2839. }
  2840. std::string interfaceProperty = "INTERFACE_" + p;
  2841. for(std::vector<cmTarget const*>::const_iterator li =
  2842. deps.begin();
  2843. li != deps.end(); ++li)
  2844. {
  2845. // An error should be reported if one dependency
  2846. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  2847. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  2848. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  2849. // with a dependency.
  2850. cmTarget const* theTarget = *li;
  2851. const bool ifaceIsSet = theTarget->GetProperties()
  2852. .find(interfaceProperty)
  2853. != theTarget->GetProperties().end();
  2854. PropertyType ifacePropContent =
  2855. getTypedProperty<PropertyType>(theTarget,
  2856. interfaceProperty);
  2857. std::string reportEntry;
  2858. if (ifaceIsSet)
  2859. {
  2860. reportEntry += " * Target \"";
  2861. reportEntry += theTarget->GetName();
  2862. reportEntry += "\" property value \"";
  2863. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  2864. reportEntry += "\" ";
  2865. }
  2866. if (explicitlySet)
  2867. {
  2868. if (ifaceIsSet)
  2869. {
  2870. std::pair<bool, PropertyType> consistent =
  2871. consistentProperty(propContent,
  2872. ifacePropContent, t);
  2873. report += reportEntry;
  2874. report += compatibilityAgree(t, propContent != consistent.second);
  2875. if (!consistent.first)
  2876. {
  2877. std::ostringstream e;
  2878. e << "Property " << p << " on target \""
  2879. << tgt->GetName() << "\" does\nnot match the "
  2880. "INTERFACE_" << p << " property requirement\nof "
  2881. "dependency \"" << theTarget->GetName() << "\".\n";
  2882. cmSystemTools::Error(e.str().c_str());
  2883. break;
  2884. }
  2885. else
  2886. {
  2887. propContent = consistent.second;
  2888. continue;
  2889. }
  2890. }
  2891. else
  2892. {
  2893. // Explicitly set on target and not set in iface. Can't disagree.
  2894. continue;
  2895. }
  2896. }
  2897. else if (impliedByUse)
  2898. {
  2899. propContent = impliedValue<PropertyType>(propContent);
  2900. if (ifaceIsSet)
  2901. {
  2902. std::pair<bool, PropertyType> consistent =
  2903. consistentProperty(propContent,
  2904. ifacePropContent, t);
  2905. report += reportEntry;
  2906. report += compatibilityAgree(t, propContent != consistent.second);
  2907. if (!consistent.first)
  2908. {
  2909. std::ostringstream e;
  2910. e << "Property " << p << " on target \""
  2911. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  2912. << " because it was used to determine the link libraries\n"
  2913. "already. The INTERFACE_" << p << " property on\ndependency \""
  2914. << theTarget->GetName() << "\" is in conflict.\n";
  2915. cmSystemTools::Error(e.str().c_str());
  2916. break;
  2917. }
  2918. else
  2919. {
  2920. propContent = consistent.second;
  2921. continue;
  2922. }
  2923. }
  2924. else
  2925. {
  2926. // Implicitly set on target and not set in iface. Can't disagree.
  2927. continue;
  2928. }
  2929. }
  2930. else
  2931. {
  2932. if (ifaceIsSet)
  2933. {
  2934. if (propInitialized)
  2935. {
  2936. std::pair<bool, PropertyType> consistent =
  2937. consistentProperty(propContent,
  2938. ifacePropContent, t);
  2939. report += reportEntry;
  2940. report += compatibilityAgree(t, propContent != consistent.second);
  2941. if (!consistent.first)
  2942. {
  2943. std::ostringstream e;
  2944. e << "The INTERFACE_" << p << " property of \""
  2945. << theTarget->GetName() << "\" does\nnot agree with the value "
  2946. "of " << p << " already determined\nfor \""
  2947. << tgt->GetName() << "\".\n";
  2948. cmSystemTools::Error(e.str().c_str());
  2949. break;
  2950. }
  2951. else
  2952. {
  2953. propContent = consistent.second;
  2954. continue;
  2955. }
  2956. }
  2957. else
  2958. {
  2959. report += reportEntry + "(Interface set)\n";
  2960. propContent = ifacePropContent;
  2961. propInitialized = true;
  2962. }
  2963. }
  2964. else
  2965. {
  2966. // Not set. Nothing to agree on.
  2967. continue;
  2968. }
  2969. }
  2970. }
  2971. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  2972. report, compatibilityType(t));
  2973. return propContent;
  2974. }
  2975. //----------------------------------------------------------------------------
  2976. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  2977. const std::string &p, const std::string& config) const
  2978. {
  2979. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  2980. "FALSE",
  2981. BoolType, 0);
  2982. }
  2983. //----------------------------------------------------------------------------
  2984. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  2985. const std::string &p,
  2986. const std::string& config) const
  2987. {
  2988. return checkInterfacePropertyCompatibility<const char *>(this,
  2989. p,
  2990. config,
  2991. "empty",
  2992. StringType, 0);
  2993. }
  2994. //----------------------------------------------------------------------------
  2995. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  2996. const std::string &p,
  2997. const std::string& config) const
  2998. {
  2999. return checkInterfacePropertyCompatibility<const char *>(this,
  3000. p,
  3001. config,
  3002. "empty",
  3003. NumberMinType, 0);
  3004. }
  3005. //----------------------------------------------------------------------------
  3006. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3007. const std::string &p,
  3008. const std::string& config) const
  3009. {
  3010. return checkInterfacePropertyCompatibility<const char *>(this,
  3011. p,
  3012. config,
  3013. "empty",
  3014. NumberMaxType, 0);
  3015. }
  3016. //----------------------------------------------------------------------------
  3017. cmComputeLinkInformation*
  3018. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  3019. {
  3020. // Lookup any existing information for this configuration.
  3021. std::string key(cmSystemTools::UpperCase(config));
  3022. cmTargetLinkInformationMap::iterator
  3023. i = this->LinkInformation.find(key);
  3024. if(i == this->LinkInformation.end())
  3025. {
  3026. // Compute information for this configuration.
  3027. cmComputeLinkInformation* info =
  3028. new cmComputeLinkInformation(this, config);
  3029. if(!info || !info->Compute())
  3030. {
  3031. delete info;
  3032. info = 0;
  3033. }
  3034. // Store the information for this configuration.
  3035. cmTargetLinkInformationMap::value_type entry(key, info);
  3036. i = this->LinkInformation.insert(entry).first;
  3037. if (info)
  3038. {
  3039. this->CheckPropertyCompatibility(info, config);
  3040. }
  3041. }
  3042. return i->second;
  3043. }
  3044. //----------------------------------------------------------------------------
  3045. void
  3046. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  3047. const std::string &result,
  3048. const std::string &report,
  3049. const std::string &compatibilityType) const
  3050. {
  3051. std::vector<std::string> debugProperties;
  3052. const char *debugProp = this->Target->GetMakefile()
  3053. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  3054. if (debugProp)
  3055. {
  3056. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3057. }
  3058. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  3059. && std::find(debugProperties.begin(),
  3060. debugProperties.end(),
  3061. p)
  3062. != debugProperties.end();
  3063. if (this->Target->GetMakefile()->IsConfigured())
  3064. {
  3065. this->DebugCompatiblePropertiesDone[p] = true;
  3066. }
  3067. if (!debugOrigin)
  3068. {
  3069. return;
  3070. }
  3071. std::string areport = compatibilityType;
  3072. areport += std::string(" of property \"") + p + "\" for target \"";
  3073. areport += std::string(this->GetName());
  3074. areport += "\" (result: \"";
  3075. areport += result;
  3076. areport += "\"):\n" + report;
  3077. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3078. }
  3079. //----------------------------------------------------------------------------
  3080. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3081. std::vector<cmLinkItem>& items) const
  3082. {
  3083. for(std::vector<std::string>::const_iterator i = names.begin();
  3084. i != names.end(); ++i)
  3085. {
  3086. std::string name = this->Target->CheckCMP0004(*i);
  3087. if(name == this->GetName() || name.empty())
  3088. {
  3089. continue;
  3090. }
  3091. items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
  3092. }
  3093. }
  3094. //----------------------------------------------------------------------------
  3095. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  3096. std::string const& value,
  3097. std::string const& config,
  3098. cmTarget const* headTarget,
  3099. bool usage_requirements_only,
  3100. std::vector<cmLinkItem>& items,
  3101. bool& hadHeadSensitiveCondition) const
  3102. {
  3103. cmGeneratorExpression ge;
  3104. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3105. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3106. // link dependencies that are otherwise excluded from usage requirements.
  3107. if(usage_requirements_only)
  3108. {
  3109. dagChecker.SetTransitivePropertiesOnly();
  3110. }
  3111. std::vector<std::string> libs;
  3112. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3113. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3114. this->Makefile,
  3115. config,
  3116. false,
  3117. headTarget,
  3118. this->Target, &dagChecker), libs);
  3119. this->LookupLinkItems(libs, items);
  3120. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3121. }
  3122. //----------------------------------------------------------------------------
  3123. cmLinkInterface const*
  3124. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  3125. cmTarget const* head) const
  3126. {
  3127. // Imported targets have their own link interface.
  3128. if(this->IsImported())
  3129. {
  3130. return this->GetImportLinkInterface(config, head, false);
  3131. }
  3132. // Link interfaces are not supported for executables that do not
  3133. // export symbols.
  3134. if(this->GetType() == cmTarget::EXECUTABLE &&
  3135. !this->Target->IsExecutableWithExports())
  3136. {
  3137. return 0;
  3138. }
  3139. // Lookup any existing link interface for this configuration.
  3140. cmHeadToLinkInterfaceMap& hm =
  3141. this->GetHeadToLinkInterfaceMap(config);
  3142. // If the link interface does not depend on the head target
  3143. // then return the one we computed first.
  3144. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3145. {
  3146. return &hm.begin()->second;
  3147. }
  3148. cmOptionalLinkInterface& iface = hm[head];
  3149. if(!iface.LibrariesDone)
  3150. {
  3151. iface.LibrariesDone = true;
  3152. this->ComputeLinkInterfaceLibraries(
  3153. config, iface, head, false);
  3154. }
  3155. if(!iface.AllDone)
  3156. {
  3157. iface.AllDone = true;
  3158. if(iface.Exists)
  3159. {
  3160. this->ComputeLinkInterface(config, iface, head);
  3161. }
  3162. }
  3163. return iface.Exists? &iface : 0;
  3164. }
  3165. //----------------------------------------------------------------------------
  3166. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  3167. cmOptionalLinkInterface &iface,
  3168. cmTarget const* headTarget) const
  3169. {
  3170. if(iface.ExplicitLibraries)
  3171. {
  3172. if(this->GetType() == cmTarget::SHARED_LIBRARY
  3173. || this->GetType() == cmTarget::STATIC_LIBRARY
  3174. || this->GetType() == cmTarget::INTERFACE_LIBRARY)
  3175. {
  3176. // Shared libraries may have runtime implementation dependencies
  3177. // on other shared libraries that are not in the interface.
  3178. UNORDERED_SET<std::string> emitted;
  3179. for(std::vector<cmLinkItem>::const_iterator
  3180. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3181. {
  3182. emitted.insert(*li);
  3183. }
  3184. if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
  3185. {
  3186. cmTarget::LinkImplementation const* impl =
  3187. this->Target->GetLinkImplementation(config);
  3188. for(std::vector<cmLinkImplItem>::const_iterator
  3189. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3190. {
  3191. if(emitted.insert(*li).second)
  3192. {
  3193. if(li->Target)
  3194. {
  3195. // This is a runtime dependency on another shared library.
  3196. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  3197. {
  3198. iface.SharedDeps.push_back(*li);
  3199. }
  3200. }
  3201. else
  3202. {
  3203. // TODO: Recognize shared library file names. Perhaps this
  3204. // should be moved to cmComputeLinkInformation, but that creates
  3205. // a chicken-and-egg problem since this list is needed for its
  3206. // construction.
  3207. }
  3208. }
  3209. }
  3210. }
  3211. }
  3212. }
  3213. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3214. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3215. {
  3216. // The link implementation is the default link interface.
  3217. cmLinkImplementationLibraries const*
  3218. impl = this->Target->GetLinkImplementationLibrariesInternal(config,
  3219. headTarget);
  3220. iface.ImplementationIsInterface = true;
  3221. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3222. }
  3223. if(this->Target->LinkLanguagePropagatesToDependents())
  3224. {
  3225. // Targets using this archive need its language runtime libraries.
  3226. if(cmTarget::LinkImplementation const* impl =
  3227. this->Target->GetLinkImplementation(config))
  3228. {
  3229. iface.Languages = impl->Languages;
  3230. }
  3231. }
  3232. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3233. {
  3234. // Construct the property name suffix for this configuration.
  3235. std::string suffix = "_";
  3236. if(!config.empty())
  3237. {
  3238. suffix += cmSystemTools::UpperCase(config);
  3239. }
  3240. else
  3241. {
  3242. suffix += "NOCONFIG";
  3243. }
  3244. // How many repetitions are needed if this library has cyclic
  3245. // dependencies?
  3246. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3247. propName += suffix;
  3248. if(const char* config_reps = this->GetProperty(propName))
  3249. {
  3250. sscanf(config_reps, "%u", &iface.Multiplicity);
  3251. }
  3252. else if(const char* reps =
  3253. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  3254. {
  3255. sscanf(reps, "%u", &iface.Multiplicity);
  3256. }
  3257. }
  3258. }
  3259. //----------------------------------------------------------------------------
  3260. const cmLinkInterfaceLibraries *
  3261. cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
  3262. cmTarget const* head,
  3263. bool usage_requirements_only) const
  3264. {
  3265. // Imported targets have their own link interface.
  3266. if(this->IsImported())
  3267. {
  3268. return this->GetImportLinkInterface(config, head,
  3269. usage_requirements_only);
  3270. }
  3271. // Link interfaces are not supported for executables that do not
  3272. // export symbols.
  3273. if(this->GetType() == cmTarget::EXECUTABLE &&
  3274. !this->Target->IsExecutableWithExports())
  3275. {
  3276. return 0;
  3277. }
  3278. // Lookup any existing link interface for this configuration.
  3279. std::string CONFIG = cmSystemTools::UpperCase(config);
  3280. cmHeadToLinkInterfaceMap& hm =
  3281. (usage_requirements_only ?
  3282. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3283. this->GetHeadToLinkInterfaceMap(config));
  3284. // If the link interface does not depend on the head target
  3285. // then return the one we computed first.
  3286. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3287. {
  3288. return &hm.begin()->second;
  3289. }
  3290. cmOptionalLinkInterface& iface = hm[head];
  3291. if(!iface.LibrariesDone)
  3292. {
  3293. iface.LibrariesDone = true;
  3294. this->ComputeLinkInterfaceLibraries(
  3295. config, iface, head, usage_requirements_only);
  3296. }
  3297. return iface.Exists? &iface : 0;
  3298. }
  3299. //----------------------------------------------------------------------------
  3300. void
  3301. cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  3302. const std::string& config,
  3303. cmOptionalLinkInterface& iface,
  3304. cmTarget const* headTarget,
  3305. bool usage_requirements_only) const
  3306. {
  3307. // Construct the property name suffix for this configuration.
  3308. std::string suffix = "_";
  3309. if(!config.empty())
  3310. {
  3311. suffix += cmSystemTools::UpperCase(config);
  3312. }
  3313. else
  3314. {
  3315. suffix += "NOCONFIG";
  3316. }
  3317. // An explicit list of interface libraries may be set for shared
  3318. // libraries and executables that export symbols.
  3319. const char* explicitLibraries = 0;
  3320. std::string linkIfaceProp;
  3321. if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  3322. this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  3323. {
  3324. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  3325. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  3326. explicitLibraries = this->GetProperty(linkIfaceProp);
  3327. }
  3328. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3329. this->Target->IsExecutableWithExports())
  3330. {
  3331. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  3332. // shared lib or executable.
  3333. // Lookup the per-configuration property.
  3334. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3335. linkIfaceProp += suffix;
  3336. explicitLibraries = this->GetProperty(linkIfaceProp);
  3337. // If not set, try the generic property.
  3338. if(!explicitLibraries)
  3339. {
  3340. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3341. explicitLibraries = this->GetProperty(linkIfaceProp);
  3342. }
  3343. }
  3344. if(explicitLibraries &&
  3345. this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3346. !this->PolicyWarnedCMP0022)
  3347. {
  3348. // Compare the explicitly set old link interface properties to the
  3349. // preferred new link interface property one and warn if different.
  3350. const char* newExplicitLibraries =
  3351. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  3352. if (newExplicitLibraries
  3353. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  3354. {
  3355. std::ostringstream w;
  3356. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3357. "Target \"" << this->GetName() << "\" has an "
  3358. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  3359. linkIfaceProp << " properties."
  3360. "\n"
  3361. "INTERFACE_LINK_LIBRARIES:\n"
  3362. " " << newExplicitLibraries << "\n" <<
  3363. linkIfaceProp << ":\n"
  3364. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  3365. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3366. this->PolicyWarnedCMP0022 = true;
  3367. }
  3368. }
  3369. // There is no implicit link interface for executables or modules
  3370. // so if none was explicitly set then there is no link interface.
  3371. if(!explicitLibraries &&
  3372. (this->GetType() == cmTarget::EXECUTABLE ||
  3373. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  3374. {
  3375. return;
  3376. }
  3377. iface.Exists = true;
  3378. iface.ExplicitLibraries = explicitLibraries;
  3379. if(explicitLibraries)
  3380. {
  3381. // The interface libraries have been explicitly set.
  3382. this->ExpandLinkItems(linkIfaceProp, explicitLibraries,
  3383. config,
  3384. headTarget, usage_requirements_only,
  3385. iface.Libraries,
  3386. iface.HadHeadSensitiveCondition);
  3387. }
  3388. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3389. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3390. // If CMP0022 is NEW then the plain tll signature sets the
  3391. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  3392. // cleared the property explicitly and we should not fall back
  3393. // to the link implementation.
  3394. {
  3395. // The link implementation is the default link interface.
  3396. cmLinkImplementationLibraries const* impl =
  3397. this->Target->GetLinkImplementationLibrariesInternal(config,
  3398. headTarget);
  3399. iface.Libraries.insert(iface.Libraries.end(),
  3400. impl->Libraries.begin(), impl->Libraries.end());
  3401. if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3402. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  3403. {
  3404. // Compare the link implementation fallback link interface to the
  3405. // preferred new link interface property and warn if different.
  3406. std::vector<cmLinkItem> ifaceLibs;
  3407. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  3408. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  3409. {
  3410. bool hadHeadSensitiveConditionDummy = false;
  3411. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  3412. headTarget, usage_requirements_only,
  3413. ifaceLibs, hadHeadSensitiveConditionDummy);
  3414. }
  3415. if (ifaceLibs != iface.Libraries)
  3416. {
  3417. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  3418. std::string newLibraries = cmJoin(ifaceLibs, ";");
  3419. if(oldLibraries.empty())
  3420. { oldLibraries = "(empty)"; }
  3421. if(newLibraries.empty())
  3422. { newLibraries = "(empty)"; }
  3423. std::ostringstream w;
  3424. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3425. "Target \"" << this->GetName() << "\" has an "
  3426. "INTERFACE_LINK_LIBRARIES property. "
  3427. "This should be preferred as the source of the link interface "
  3428. "for this library but because CMP0022 is not set CMake is "
  3429. "ignoring the property and using the link implementation "
  3430. "as the link interface instead."
  3431. "\n"
  3432. "INTERFACE_LINK_LIBRARIES:\n"
  3433. " " << newLibraries << "\n"
  3434. "Link implementation:\n"
  3435. " " << oldLibraries << "\n";
  3436. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3437. this->PolicyWarnedCMP0022 = true;
  3438. }
  3439. }
  3440. }
  3441. }
  3442. //----------------------------------------------------------------------------
  3443. const cmLinkInterface *
  3444. cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
  3445. cmTarget const* headTarget,
  3446. bool usage_requirements_only) const
  3447. {
  3448. cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config);
  3449. if(!info)
  3450. {
  3451. return 0;
  3452. }
  3453. std::string CONFIG = cmSystemTools::UpperCase(config);
  3454. cmHeadToLinkInterfaceMap& hm =
  3455. (usage_requirements_only ?
  3456. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3457. this->GetHeadToLinkInterfaceMap(config));
  3458. // If the link interface does not depend on the head target
  3459. // then return the one we computed first.
  3460. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3461. {
  3462. return &hm.begin()->second;
  3463. }
  3464. cmOptionalLinkInterface& iface = hm[headTarget];
  3465. if(!iface.AllDone)
  3466. {
  3467. iface.AllDone = true;
  3468. iface.Multiplicity = info->Multiplicity;
  3469. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  3470. this->ExpandLinkItems(info->LibrariesProp, info->Libraries,
  3471. config,
  3472. headTarget, usage_requirements_only,
  3473. iface.Libraries,
  3474. iface.HadHeadSensitiveCondition);
  3475. std::vector<std::string> deps;
  3476. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  3477. this->LookupLinkItems(deps, iface.SharedDeps);
  3478. }
  3479. return &iface;
  3480. }
  3481. cmHeadToLinkInterfaceMap&
  3482. cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
  3483. {
  3484. std::string CONFIG = cmSystemTools::UpperCase(config);
  3485. return this->LinkInterfaceMap[CONFIG];
  3486. }
  3487. cmHeadToLinkInterfaceMap&
  3488. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  3489. const std::string &config) const
  3490. {
  3491. std::string CONFIG = cmSystemTools::UpperCase(config);
  3492. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  3493. }