cmGeneratorTarget.cxx 171 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185
  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 "cmAlgorithms.h"
  12. #include "cmComputeLinkInformation.h"
  13. #include "cmCustomCommandGenerator.h"
  14. #include "cmGeneratorExpression.h"
  15. #include "cmGeneratorExpressionDAGChecker.h"
  16. #include "cmGlobalGenerator.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmSourceFile.h"
  20. #include "cmTarget.h"
  21. #include <queue>
  22. #include "assert.h"
  23. #include <errno.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. class cmGeneratorTarget::TargetPropertyEntry
  31. {
  32. static cmLinkImplItem NoLinkImplItem;
  33. public:
  34. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  35. cmLinkImplItem const& item = NoLinkImplItem)
  36. : ge(cge)
  37. , LinkImplItem(item)
  38. {
  39. }
  40. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  41. cmLinkImplItem const& LinkImplItem;
  42. };
  43. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  44. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  45. cmGeneratorTarget const* target, cmake* cm)
  46. {
  47. if (!badObjLib.empty()) {
  48. std::ostringstream e;
  49. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  50. for (std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  51. i != badObjLib.end(); ++i) {
  52. e << " " << (*i)->GetLocation().GetName() << "\n";
  53. }
  54. e << "but may contain only sources that compile, header files, and "
  55. "other files that would not affect linking of a normal library.";
  56. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), target->GetBacktrace());
  57. }
  58. }
  59. struct ObjectSourcesTag
  60. {
  61. };
  62. struct CustomCommandsTag
  63. {
  64. };
  65. struct ExtraSourcesTag
  66. {
  67. };
  68. struct HeaderSourcesTag
  69. {
  70. };
  71. struct ExternalObjectsTag
  72. {
  73. };
  74. struct IDLSourcesTag
  75. {
  76. };
  77. struct ResxTag
  78. {
  79. };
  80. struct ModuleDefinitionFileTag
  81. {
  82. };
  83. struct AppManifestTag
  84. {
  85. };
  86. struct ManifestsTag
  87. {
  88. };
  89. struct CertificatesTag
  90. {
  91. };
  92. struct XamlTag
  93. {
  94. };
  95. template <typename Tag, typename OtherTag>
  96. struct IsSameTag
  97. {
  98. enum
  99. {
  100. Result = false
  101. };
  102. };
  103. template <typename Tag>
  104. struct IsSameTag<Tag, Tag>
  105. {
  106. enum
  107. {
  108. Result = true
  109. };
  110. };
  111. template <bool>
  112. struct DoAccept
  113. {
  114. template <typename T>
  115. static void Do(T&, cmSourceFile*)
  116. {
  117. }
  118. };
  119. template <>
  120. struct DoAccept<true>
  121. {
  122. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  123. {
  124. files.push_back(f);
  125. }
  126. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  127. {
  128. // Build and save the name of the corresponding .h file
  129. // This relationship will be used later when building the project files.
  130. // Both names would have been auto generated from Visual Studio
  131. // where the user supplied the file name and Visual Studio
  132. // appended the suffix.
  133. std::string resx = f->GetFullPath();
  134. std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
  135. data.ExpectedResxHeaders.insert(hFileName);
  136. data.ResxSources.push_back(f);
  137. }
  138. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  139. {
  140. // Build and save the name of the corresponding .h and .cpp file
  141. // This relationship will be used later when building the project files.
  142. // Both names would have been auto generated from Visual Studio
  143. // where the user supplied the file name and Visual Studio
  144. // appended the suffix.
  145. std::string xaml = f->GetFullPath();
  146. std::string hFileName = xaml + ".h";
  147. std::string cppFileName = xaml + ".cpp";
  148. data.ExpectedXamlHeaders.insert(hFileName);
  149. data.ExpectedXamlSources.insert(cppFileName);
  150. data.XamlSources.push_back(f);
  151. }
  152. static void Do(std::string& data, cmSourceFile* f)
  153. {
  154. data = f->GetFullPath();
  155. }
  156. };
  157. template <typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  158. struct TagVisitor
  159. {
  160. DataType& Data;
  161. std::vector<cmSourceFile*> BadObjLibFiles;
  162. cmGeneratorTarget const* Target;
  163. cmGlobalGenerator* GlobalGenerator;
  164. cmsys::RegularExpression Header;
  165. bool IsObjLib;
  166. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  167. : Data(data)
  168. , Target(target)
  169. , GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator())
  170. , Header(CM_HEADER_REGEX)
  171. , IsObjLib(target->GetType() == cmState::OBJECT_LIBRARY)
  172. {
  173. }
  174. ~TagVisitor()
  175. {
  176. reportBadObjLib(this->BadObjLibFiles, this->Target,
  177. this->GlobalGenerator->GetCMakeInstance());
  178. }
  179. void Accept(cmSourceFile* sf)
  180. {
  181. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  182. if (sf->GetCustomCommand()) {
  183. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  184. } else if (this->Target->GetType() == cmState::UTILITY) {
  185. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  186. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  187. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  188. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  189. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  190. if (this->IsObjLib) {
  191. this->BadObjLibFiles.push_back(sf);
  192. }
  193. } else if (!sf->GetLanguage().empty()) {
  194. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  195. } else if (ext == "def") {
  196. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  197. sf);
  198. if (this->IsObjLib) {
  199. this->BadObjLibFiles.push_back(sf);
  200. }
  201. } else if (ext == "idl") {
  202. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  203. if (this->IsObjLib) {
  204. this->BadObjLibFiles.push_back(sf);
  205. }
  206. } else if (ext == "resx") {
  207. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  208. } else if (ext == "appxmanifest") {
  209. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  210. } else if (ext == "manifest") {
  211. DoAccept<IsSameTag<Tag, ManifestsTag>::Result>::Do(this->Data, sf);
  212. } else if (ext == "pfx") {
  213. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  214. } else if (ext == "xaml") {
  215. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  216. } else if (this->Header.find(sf->GetFullPath().c_str())) {
  217. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  218. } else if (this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str())) {
  219. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  220. } else {
  221. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  222. }
  223. }
  224. };
  225. void CreatePropertyGeneratorExpressions(
  226. cmStringRange const& entries, cmBacktraceRange const& backtraces,
  227. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  228. bool evaluateForBuildsystem = false)
  229. {
  230. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  231. for (std::vector<std::string>::const_iterator it = entries.begin();
  232. it != entries.end(); ++it, ++btIt) {
  233. cmGeneratorExpression ge(*btIt);
  234. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  235. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  236. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  237. }
  238. }
  239. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  240. : Target(t)
  241. , FortranModuleDirectoryCreated(false)
  242. , SourceFileFlagsConstructed(false)
  243. , PolicyWarnedCMP0022(false)
  244. , DebugIncludesDone(false)
  245. , DebugCompileOptionsDone(false)
  246. , DebugCompileFeaturesDone(false)
  247. , DebugCompileDefinitionsDone(false)
  248. , DebugSourcesDone(false)
  249. , LinkImplementationLanguageIsContextDependent(true)
  250. , UtilityItemsDone(false)
  251. {
  252. this->Makefile = this->Target->GetMakefile();
  253. this->LocalGenerator = lg;
  254. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  255. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  256. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  257. t->GetIncludeDirectoriesBacktraces(),
  258. this->IncludeDirectoriesEntries);
  259. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  260. t->GetCompileOptionsBacktraces(),
  261. this->CompileOptionsEntries);
  262. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  263. t->GetCompileFeaturesBacktraces(),
  264. this->CompileFeaturesEntries);
  265. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  266. t->GetCompileDefinitionsBacktraces(),
  267. this->CompileDefinitionsEntries);
  268. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  269. t->GetSourceBacktraces(),
  270. this->SourceEntries, true);
  271. this->DLLPlatform =
  272. (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
  273. this->Makefile->IsOn("MINGW"));
  274. this->PolicyMap = t->PolicyMap;
  275. }
  276. cmGeneratorTarget::~cmGeneratorTarget()
  277. {
  278. cmDeleteAll(this->IncludeDirectoriesEntries);
  279. cmDeleteAll(this->CompileOptionsEntries);
  280. cmDeleteAll(this->CompileFeaturesEntries);
  281. cmDeleteAll(this->CompileDefinitionsEntries);
  282. cmDeleteAll(this->SourceEntries);
  283. cmDeleteAll(this->LinkInformation);
  284. this->LinkInformation.clear();
  285. }
  286. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  287. {
  288. return this->LocalGenerator;
  289. }
  290. cmState::TargetType cmGeneratorTarget::GetType() const
  291. {
  292. return this->Target->GetType();
  293. }
  294. const std::string& cmGeneratorTarget::GetName() const
  295. {
  296. return this->Target->GetName();
  297. }
  298. std::string cmGeneratorTarget::GetExportName() const
  299. {
  300. const char* exportName = this->GetProperty("EXPORT_NAME");
  301. if (exportName && *exportName) {
  302. if (!cmGeneratorExpression::IsValidTargetName(exportName)) {
  303. std::ostringstream e;
  304. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  305. << this->GetName() << "\": is not valid.";
  306. cmSystemTools::Error(e.str().c_str());
  307. return "";
  308. }
  309. return exportName;
  310. }
  311. return this->GetName();
  312. }
  313. const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
  314. {
  315. return this->Target->GetProperty(prop);
  316. }
  317. const char* cmGeneratorTarget::GetOutputTargetType(bool implib) const
  318. {
  319. switch (this->GetType()) {
  320. case cmState::SHARED_LIBRARY:
  321. if (this->IsDLLPlatform()) {
  322. if (implib) {
  323. // A DLL import library is treated as an archive target.
  324. return "ARCHIVE";
  325. } else {
  326. // A DLL shared library is treated as a runtime target.
  327. return "RUNTIME";
  328. }
  329. } else {
  330. // For non-DLL platforms shared libraries are treated as
  331. // library targets.
  332. return "LIBRARY";
  333. }
  334. case cmState::STATIC_LIBRARY:
  335. // Static libraries are always treated as archive targets.
  336. return "ARCHIVE";
  337. case cmState::MODULE_LIBRARY:
  338. if (implib) {
  339. // Module libraries are always treated as library targets.
  340. return "ARCHIVE";
  341. } else {
  342. // Module import libraries are treated as archive targets.
  343. return "LIBRARY";
  344. }
  345. case cmState::EXECUTABLE:
  346. if (implib) {
  347. // Executable import libraries are treated as archive targets.
  348. return "ARCHIVE";
  349. } else {
  350. // Executables are always treated as runtime targets.
  351. return "RUNTIME";
  352. }
  353. default:
  354. break;
  355. }
  356. return "";
  357. }
  358. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  359. bool implib) const
  360. {
  361. // Lookup/compute/cache the output name for this configuration.
  362. OutputNameKey key(config, implib);
  363. cmGeneratorTarget::OutputNameMapType::iterator i =
  364. this->OutputNameMap.find(key);
  365. if (i == this->OutputNameMap.end()) {
  366. // Add empty name in map to detect potential recursion.
  367. OutputNameMapType::value_type entry(key, "");
  368. i = this->OutputNameMap.insert(entry).first;
  369. // Compute output name.
  370. std::vector<std::string> props;
  371. std::string type = this->GetOutputTargetType(implib);
  372. std::string configUpper = cmSystemTools::UpperCase(config);
  373. if (!type.empty() && !configUpper.empty()) {
  374. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  375. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  376. }
  377. if (!type.empty()) {
  378. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  379. props.push_back(type + "_OUTPUT_NAME");
  380. }
  381. if (!configUpper.empty()) {
  382. // OUTPUT_NAME_<CONFIG>
  383. props.push_back("OUTPUT_NAME_" + configUpper);
  384. // <CONFIG>_OUTPUT_NAME
  385. props.push_back(configUpper + "_OUTPUT_NAME");
  386. }
  387. // OUTPUT_NAME
  388. props.push_back("OUTPUT_NAME");
  389. std::string outName;
  390. for (std::vector<std::string>::const_iterator it = props.begin();
  391. it != props.end(); ++it) {
  392. if (const char* outNameProp = this->GetProperty(*it)) {
  393. outName = outNameProp;
  394. break;
  395. }
  396. }
  397. if (outName.empty()) {
  398. outName = this->GetName();
  399. }
  400. // Now evaluate genex and update the previously-prepared map entry.
  401. cmGeneratorExpression ge;
  402. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  403. i->second = cge->Evaluate(this->LocalGenerator, config);
  404. } else if (i->second.empty()) {
  405. // An empty map entry indicates we have been called recursively
  406. // from the above block.
  407. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  408. cmake::FATAL_ERROR,
  409. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  410. this->GetBacktrace());
  411. }
  412. return i->second;
  413. }
  414. void cmGeneratorTarget::AddSource(const std::string& src)
  415. {
  416. this->Target->AddSource(src);
  417. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  418. cmGeneratorExpression ge(lfbt);
  419. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  420. cge->SetEvaluateForBuildsystem(true);
  421. this->SourceEntries.push_back(new TargetPropertyEntry(cge));
  422. this->SourceFilesMap.clear();
  423. this->LinkImplementationLanguageIsContextDependent = true;
  424. }
  425. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  426. {
  427. this->Target->AddTracedSources(srcs);
  428. if (!srcs.empty()) {
  429. std::string srcFiles = cmJoin(srcs, ";");
  430. this->SourceFilesMap.clear();
  431. this->LinkImplementationLanguageIsContextDependent = true;
  432. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  433. cmGeneratorExpression ge(lfbt);
  434. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  435. cge->SetEvaluateForBuildsystem(true);
  436. this->SourceEntries.push_back(
  437. new cmGeneratorTarget::TargetPropertyEntry(cge));
  438. }
  439. }
  440. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  441. cmSourceFile const* sf) const
  442. {
  443. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  444. if (i != this->SourceDepends.end()) {
  445. return &i->second.Depends;
  446. }
  447. return 0;
  448. }
  449. static void handleSystemIncludesDep(
  450. cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
  451. const std::string& config, cmGeneratorTarget const* headTarget,
  452. cmGeneratorExpressionDAGChecker* dagChecker,
  453. std::vector<std::string>& result, bool excludeImported)
  454. {
  455. if (const char* dirs =
  456. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  457. cmGeneratorExpression ge;
  458. cmSystemTools::ExpandListArgument(
  459. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  460. dagChecker),
  461. result);
  462. }
  463. if (!depTgt->IsImported() || excludeImported) {
  464. return;
  465. }
  466. if (const char* dirs =
  467. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  468. cmGeneratorExpression ge;
  469. cmSystemTools::ExpandListArgument(
  470. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  471. dagChecker),
  472. result);
  473. }
  474. }
  475. /* clang-format off */
  476. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  477. { \
  478. std::vector<cmSourceFile*> sourceFiles; \
  479. this->GetSourceFiles(sourceFiles, config); \
  480. TagVisitor< DATA##Tag DATATYPE > visitor(this, data); \
  481. for (std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  482. si != sourceFiles.end(); ++si) { \
  483. visitor.Accept(*si); \
  484. } \
  485. }
  486. /* clang-format on */
  487. #define IMPLEMENT_VISIT(DATA) IMPLEMENT_VISIT_IMPL(DATA, EMPTY)
  488. #define EMPTY
  489. #define COMMA ,
  490. void cmGeneratorTarget::GetObjectSources(
  491. std::vector<cmSourceFile const*>& data, const std::string& config) const
  492. {
  493. IMPLEMENT_VISIT(ObjectSources);
  494. if (!this->Objects.empty()) {
  495. return;
  496. }
  497. for (std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  498. it != data.end(); ++it) {
  499. this->Objects[*it];
  500. }
  501. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  502. }
  503. void cmGeneratorTarget::ComputeObjectMapping()
  504. {
  505. if (!this->Objects.empty()) {
  506. return;
  507. }
  508. std::vector<std::string> configs;
  509. this->Makefile->GetConfigurations(configs);
  510. if (configs.empty()) {
  511. configs.push_back("");
  512. }
  513. for (std::vector<std::string>::const_iterator ci = configs.begin();
  514. ci != configs.end(); ++ci) {
  515. std::vector<cmSourceFile const*> sourceFiles;
  516. this->GetObjectSources(sourceFiles, *ci);
  517. }
  518. }
  519. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  520. const std::string& config) const
  521. {
  522. if (!config.empty()) {
  523. std::string featureConfig = feature;
  524. featureConfig += "_";
  525. featureConfig += cmSystemTools::UpperCase(config);
  526. if (const char* value = this->GetProperty(featureConfig)) {
  527. return value;
  528. }
  529. }
  530. if (const char* value = this->GetProperty(feature)) {
  531. return value;
  532. }
  533. return this->LocalGenerator->GetFeature(feature, config);
  534. }
  535. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  536. const std::string& config) const
  537. {
  538. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  539. }
  540. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  541. {
  542. this->ComputeObjectMapping();
  543. return this->Objects[file];
  544. }
  545. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  546. {
  547. this->ExplicitObjectName.insert(sf);
  548. }
  549. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  550. {
  551. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  552. std::set<cmSourceFile const*>::const_iterator it =
  553. this->ExplicitObjectName.find(file);
  554. return it != this->ExplicitObjectName.end();
  555. }
  556. void cmGeneratorTarget::GetIDLSources(std::vector<cmSourceFile const*>& data,
  557. const std::string& config) const
  558. {
  559. IMPLEMENT_VISIT(IDLSources);
  560. }
  561. void cmGeneratorTarget::GetHeaderSources(
  562. std::vector<cmSourceFile const*>& data, const std::string& config) const
  563. {
  564. IMPLEMENT_VISIT(HeaderSources);
  565. }
  566. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  567. const std::string& config) const
  568. {
  569. IMPLEMENT_VISIT(ExtraSources);
  570. }
  571. void cmGeneratorTarget::GetCustomCommands(
  572. std::vector<cmSourceFile const*>& data, const std::string& config) const
  573. {
  574. IMPLEMENT_VISIT(CustomCommands);
  575. }
  576. void cmGeneratorTarget::GetExternalObjects(
  577. std::vector<cmSourceFile const*>& data, const std::string& config) const
  578. {
  579. IMPLEMENT_VISIT(ExternalObjects);
  580. }
  581. void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  582. const std::string& config) const
  583. {
  584. ResxData data;
  585. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  586. srcs = data.ExpectedResxHeaders;
  587. }
  588. void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  589. const std::string& config) const
  590. {
  591. ResxData data;
  592. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  593. srcs = data.ResxSources;
  594. }
  595. void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
  596. const std::string& config) const
  597. {
  598. IMPLEMENT_VISIT(AppManifest);
  599. }
  600. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  601. const std::string& config) const
  602. {
  603. IMPLEMENT_VISIT(Manifests);
  604. }
  605. void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
  606. const std::string& config) const
  607. {
  608. IMPLEMENT_VISIT(Certificates);
  609. }
  610. void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  611. const std::string& config) const
  612. {
  613. XamlData data;
  614. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  615. headers = data.ExpectedXamlHeaders;
  616. }
  617. void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  618. const std::string& config) const
  619. {
  620. XamlData data;
  621. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  622. srcs = data.ExpectedXamlSources;
  623. }
  624. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  625. {
  626. if (!this->UtilityItemsDone) {
  627. this->UtilityItemsDone = true;
  628. std::set<std::string> const& utilities = this->GetUtilities();
  629. for (std::set<std::string>::const_iterator i = utilities.begin();
  630. i != utilities.end(); ++i) {
  631. cmGeneratorTarget* gt =
  632. this->LocalGenerator->FindGeneratorTargetToUse(*i);
  633. this->UtilityItems.insert(cmLinkItem(*i, gt));
  634. }
  635. }
  636. return this->UtilityItems;
  637. }
  638. void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  639. const std::string& config) const
  640. {
  641. XamlData data;
  642. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  643. srcs = data.XamlSources;
  644. }
  645. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  646. {
  647. static std::string location;
  648. if (this->IsImported()) {
  649. location = this->Target->ImportedGetFullPath(config, false);
  650. } else {
  651. location = this->GetFullPath(config, false);
  652. }
  653. return location.c_str();
  654. }
  655. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  656. const
  657. {
  658. return this->Target->GetPreBuildCommands();
  659. }
  660. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  661. const
  662. {
  663. return this->Target->GetPreLinkCommands();
  664. }
  665. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  666. const
  667. {
  668. return this->Target->GetPostBuildCommands();
  669. }
  670. bool cmGeneratorTarget::IsImported() const
  671. {
  672. return this->Target->IsImported();
  673. }
  674. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  675. {
  676. return this->Target->IsImportedGloballyVisible();
  677. }
  678. const char* cmGeneratorTarget::GetLocationForBuild() const
  679. {
  680. static std::string location;
  681. if (this->IsImported()) {
  682. location = this->Target->ImportedGetFullPath("", false);
  683. return location.c_str();
  684. }
  685. // Now handle the deprecated build-time configuration location.
  686. location = this->GetDirectory();
  687. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  688. if (cfgid && strcmp(cfgid, ".") != 0) {
  689. location += "/";
  690. location += cfgid;
  691. }
  692. if (this->IsAppBundleOnApple()) {
  693. std::string macdir = this->BuildMacContentDirectory("", "", false);
  694. if (!macdir.empty()) {
  695. location += "/";
  696. location += macdir;
  697. }
  698. }
  699. location += "/";
  700. location += this->GetFullName("", false);
  701. return location.c_str();
  702. }
  703. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  704. const std::string& dir, const std::string& config) const
  705. {
  706. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  707. std::string config_upper;
  708. if (!config.empty()) {
  709. config_upper = cmSystemTools::UpperCase(config);
  710. }
  711. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  712. IncludeCacheType::const_iterator iter =
  713. this->SystemIncludesCache.find(config_upper);
  714. if (iter == this->SystemIncludesCache.end()) {
  715. cmGeneratorExpressionDAGChecker dagChecker(
  716. this->GetName(), "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  717. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  718. std::vector<std::string> result;
  719. for (std::set<std::string>::const_iterator it =
  720. this->Target->GetSystemIncludeDirectories().begin();
  721. it != this->Target->GetSystemIncludeDirectories().end(); ++it) {
  722. cmGeneratorExpression ge;
  723. cmSystemTools::ExpandListArgument(
  724. ge.Parse(*it)->Evaluate(this->LocalGenerator, config, false, this,
  725. &dagChecker),
  726. result);
  727. }
  728. std::vector<cmGeneratorTarget const*> const& deps =
  729. this->GetLinkImplementationClosure(config);
  730. for (std::vector<cmGeneratorTarget const *>::const_iterator
  731. li = deps.begin(),
  732. le = deps.end();
  733. li != le; ++li) {
  734. handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
  735. &dagChecker, result, excludeImported);
  736. }
  737. std::set<std::string> unique;
  738. for (std::vector<std::string>::iterator li = result.begin();
  739. li != result.end(); ++li) {
  740. cmSystemTools::ConvertToUnixSlashes(*li);
  741. unique.insert(*li);
  742. }
  743. result.clear();
  744. result.insert(result.end(), unique.begin(), unique.end());
  745. IncludeCacheType::value_type entry(config_upper, result);
  746. iter = this->SystemIncludesCache.insert(entry).first;
  747. }
  748. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  749. }
  750. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  751. {
  752. return this->Target->GetPropertyAsBool(prop);
  753. }
  754. static void AddInterfaceEntries(
  755. cmGeneratorTarget const* thisTarget, std::string const& config,
  756. std::string const& prop,
  757. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  758. {
  759. if (cmLinkImplementationLibraries const* impl =
  760. thisTarget->GetLinkImplementationLibraries(config)) {
  761. for (std::vector<cmLinkImplItem>::const_iterator
  762. it = impl->Libraries.begin(),
  763. end = impl->Libraries.end();
  764. it != end; ++it) {
  765. if (it->Target) {
  766. std::string genex = "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  767. cmGeneratorExpression ge(it->Backtrace);
  768. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  769. cge->SetEvaluateForBuildsystem(true);
  770. entries.push_back(
  771. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  772. }
  773. }
  774. }
  775. }
  776. static bool processSources(
  777. cmGeneratorTarget const* tgt,
  778. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  779. std::vector<std::string>& srcs, UNORDERED_SET<std::string>& uniqueSrcs,
  780. cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
  781. bool debugSources)
  782. {
  783. cmMakefile* mf = tgt->Target->GetMakefile();
  784. bool contextDependent = false;
  785. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  786. it = entries.begin(),
  787. end = entries.end();
  788. it != end; ++it) {
  789. cmLinkImplItem const& item = (*it)->LinkImplItem;
  790. std::string const& targetName = item;
  791. std::vector<std::string> entrySources;
  792. cmSystemTools::ExpandListArgument(
  793. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
  794. dagChecker),
  795. entrySources);
  796. if ((*it)->ge->GetHadContextSensitiveCondition()) {
  797. contextDependent = true;
  798. }
  799. for (std::vector<std::string>::iterator i = entrySources.begin();
  800. i != entrySources.end(); ++i) {
  801. std::string& src = *i;
  802. cmSourceFile* sf = mf->GetOrCreateSource(src);
  803. std::string e;
  804. std::string fullPath = sf->GetFullPath(&e);
  805. if (fullPath.empty()) {
  806. if (!e.empty()) {
  807. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  808. cm->IssueMessage(cmake::FATAL_ERROR, e, tgt->GetBacktrace());
  809. }
  810. return contextDependent;
  811. }
  812. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str())) {
  813. std::ostringstream err;
  814. if (!targetName.empty()) {
  815. err << "Target \"" << targetName
  816. << "\" contains relative "
  817. "path in its INTERFACE_SOURCES:\n"
  818. " \""
  819. << src << "\"";
  820. } else {
  821. err << "Found relative path while evaluating sources of "
  822. "\""
  823. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  824. }
  825. tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
  826. return contextDependent;
  827. }
  828. src = fullPath;
  829. }
  830. std::string usedSources;
  831. for (std::vector<std::string>::iterator li = entrySources.begin();
  832. li != entrySources.end(); ++li) {
  833. std::string src = *li;
  834. if (uniqueSrcs.insert(src).second) {
  835. srcs.push_back(src);
  836. if (debugSources) {
  837. usedSources += " * " + src + "\n";
  838. }
  839. }
  840. }
  841. if (!usedSources.empty()) {
  842. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  843. cmake::LOG, std::string("Used sources for target ") + tgt->GetName() +
  844. ":\n" + usedSources,
  845. (*it)->ge->GetBacktrace());
  846. }
  847. }
  848. return contextDependent;
  849. }
  850. void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
  851. const std::string& config) const
  852. {
  853. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  854. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  855. // At configure-time, this method can be called as part of getting the
  856. // LOCATION property or to export() a file to be include()d. However
  857. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  858. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  859. // behavior of CMP0024 and CMP0026 only.
  860. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  861. for (cmStringRange::const_iterator i = sourceEntries.begin();
  862. i != sourceEntries.end(); ++i) {
  863. std::string const& entry = *i;
  864. std::vector<std::string> items;
  865. cmSystemTools::ExpandListArgument(entry, items);
  866. for (std::vector<std::string>::const_iterator li = items.begin();
  867. li != items.end(); ++li) {
  868. if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  869. (*li)[li->size() - 1] == '>') {
  870. continue;
  871. }
  872. files.push_back(*li);
  873. }
  874. }
  875. return;
  876. }
  877. std::vector<std::string> debugProperties;
  878. const char* debugProp =
  879. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  880. if (debugProp) {
  881. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  882. }
  883. bool debugSources = !this->DebugSourcesDone &&
  884. std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
  885. debugProperties.end();
  886. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  887. this->DebugSourcesDone = true;
  888. }
  889. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES", 0, 0);
  890. UNORDERED_SET<std::string> uniqueSrcs;
  891. bool contextDependentDirectSources =
  892. processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
  893. config, debugSources);
  894. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  895. linkInterfaceSourcesEntries;
  896. AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
  897. linkInterfaceSourcesEntries);
  898. std::vector<std::string>::size_type numFilesBefore = files.size();
  899. bool contextDependentInterfaceSources =
  900. processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
  901. &dagChecker, config, debugSources);
  902. if (!contextDependentDirectSources &&
  903. !(contextDependentInterfaceSources && numFilesBefore < files.size())) {
  904. this->LinkImplementationLanguageIsContextDependent = false;
  905. }
  906. cmDeleteAll(linkInterfaceSourcesEntries);
  907. }
  908. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  909. const std::string& config) const
  910. {
  911. // Lookup any existing link implementation for this configuration.
  912. std::string key = cmSystemTools::UpperCase(config);
  913. if (!this->LinkImplementationLanguageIsContextDependent) {
  914. files = this->SourceFilesMap.begin()->second;
  915. return;
  916. }
  917. SourceFilesMapType::iterator it = this->SourceFilesMap.find(key);
  918. if (it != this->SourceFilesMap.end()) {
  919. files = it->second;
  920. } else {
  921. std::vector<std::string> srcs;
  922. this->GetSourceFiles(srcs, config);
  923. std::set<cmSourceFile*> emitted;
  924. for (std::vector<std::string>::const_iterator i = srcs.begin();
  925. i != srcs.end(); ++i) {
  926. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  927. if (emitted.insert(sf).second) {
  928. files.push_back(sf);
  929. }
  930. }
  931. this->SourceFilesMap[key] = files;
  932. }
  933. }
  934. std::string cmGeneratorTarget::GetCompilePDBName(
  935. const std::string& config) const
  936. {
  937. std::string prefix;
  938. std::string base;
  939. std::string suffix;
  940. this->GetFullNameInternal(config, false, prefix, base, suffix);
  941. // Check for a per-configuration output directory target property.
  942. std::string configUpper = cmSystemTools::UpperCase(config);
  943. std::string configProp = "COMPILE_PDB_NAME_";
  944. configProp += configUpper;
  945. const char* config_name = this->GetProperty(configProp);
  946. if (config_name && *config_name) {
  947. return prefix + config_name + ".pdb";
  948. }
  949. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  950. if (name && *name) {
  951. return prefix + name + ".pdb";
  952. }
  953. return "";
  954. }
  955. std::string cmGeneratorTarget::GetCompilePDBPath(
  956. const std::string& config) const
  957. {
  958. std::string dir = this->GetCompilePDBDirectory(config);
  959. std::string name = this->GetCompilePDBName(config);
  960. if (dir.empty() && !name.empty()) {
  961. dir = this->GetPDBDirectory(config);
  962. }
  963. if (!dir.empty()) {
  964. dir += "/";
  965. }
  966. return dir + name;
  967. }
  968. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  969. {
  970. // soname is supported only for shared libraries and modules,
  971. // and then only when the platform supports an soname flag.
  972. return ((this->GetType() == cmState::SHARED_LIBRARY) &&
  973. !this->GetPropertyAsBool("NO_SONAME") &&
  974. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  975. }
  976. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  977. const std::string& config) const
  978. {
  979. // Only executables and shared libraries can have an rpath and may
  980. // need relinking.
  981. if (this->GetType() != cmState::EXECUTABLE &&
  982. this->GetType() != cmState::SHARED_LIBRARY &&
  983. this->GetType() != cmState::MODULE_LIBRARY) {
  984. return false;
  985. }
  986. // If there is no install location this target will not be installed
  987. // and therefore does not need relinking.
  988. if (!this->Target->GetHaveInstallRule()) {
  989. return false;
  990. }
  991. // If skipping all rpaths completely then no relinking is needed.
  992. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  993. return false;
  994. }
  995. // If building with the install-tree rpath no relinking is needed.
  996. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  997. return false;
  998. }
  999. // If chrpath is going to be used no relinking is needed.
  1000. if (this->IsChrpathUsed(config)) {
  1001. return false;
  1002. }
  1003. // Check for rpath support on this platform.
  1004. std::string ll = this->GetLinkerLanguage(config);
  1005. if (!ll.empty()) {
  1006. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1007. flagVar += ll;
  1008. flagVar += "_FLAG";
  1009. if (!this->Makefile->IsSet(flagVar)) {
  1010. // There is no rpath support on this platform so nothing needs
  1011. // relinking.
  1012. return false;
  1013. }
  1014. } else {
  1015. // No linker language is known. This error will be reported by
  1016. // other code.
  1017. return false;
  1018. }
  1019. // If either a build or install tree rpath is set then the rpath
  1020. // will likely change between the build tree and install tree and
  1021. // this target must be relinked.
  1022. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  1023. }
  1024. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1025. {
  1026. // Only certain target types have an rpath.
  1027. if (!(this->GetType() == cmState::SHARED_LIBRARY ||
  1028. this->GetType() == cmState::MODULE_LIBRARY ||
  1029. this->GetType() == cmState::EXECUTABLE)) {
  1030. return false;
  1031. }
  1032. // If the target will not be installed we do not need to change its
  1033. // rpath.
  1034. if (!this->Target->GetHaveInstallRule()) {
  1035. return false;
  1036. }
  1037. // Skip chrpath if skipping rpath altogether.
  1038. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1039. return false;
  1040. }
  1041. // Skip chrpath if it does not need to be changed at install time.
  1042. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1043. return false;
  1044. }
  1045. // Allow the user to disable builtin chrpath explicitly.
  1046. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1047. return false;
  1048. }
  1049. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1050. return true;
  1051. }
  1052. #if defined(CMAKE_USE_ELF_PARSER)
  1053. // Enable if the rpath flag uses a separator and the target uses ELF
  1054. // binaries.
  1055. std::string ll = this->GetLinkerLanguage(config);
  1056. if (!ll.empty()) {
  1057. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1058. sepVar += ll;
  1059. sepVar += "_FLAG_SEP";
  1060. const char* sep = this->Makefile->GetDefinition(sepVar);
  1061. if (sep && *sep) {
  1062. // TODO: Add ELF check to ABI detection and get rid of
  1063. // CMAKE_EXECUTABLE_FORMAT.
  1064. if (const char* fmt =
  1065. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1066. return strcmp(fmt, "ELF") == 0;
  1067. }
  1068. }
  1069. }
  1070. #endif
  1071. static_cast<void>(config);
  1072. return false;
  1073. }
  1074. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1075. const std::string& config) const
  1076. {
  1077. if (this->IsImported() && this->GetType() == cmState::SHARED_LIBRARY) {
  1078. if (cmGeneratorTarget::ImportInfo const* info =
  1079. this->GetImportInfo(config)) {
  1080. return info->NoSOName;
  1081. }
  1082. }
  1083. return false;
  1084. }
  1085. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1086. const std::string& config) const
  1087. {
  1088. bool install_name_is_rpath = false;
  1089. bool macosx_rpath = false;
  1090. if (!this->IsImported()) {
  1091. if (this->GetType() != cmState::SHARED_LIBRARY) {
  1092. return false;
  1093. }
  1094. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  1095. bool use_install_name =
  1096. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1097. if (install_name && use_install_name &&
  1098. std::string(install_name) == "@rpath") {
  1099. install_name_is_rpath = true;
  1100. } else if (install_name && use_install_name) {
  1101. return false;
  1102. }
  1103. if (!install_name_is_rpath) {
  1104. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1105. }
  1106. } else {
  1107. // Lookup the imported soname.
  1108. if (cmGeneratorTarget::ImportInfo const* info =
  1109. this->GetImportInfo(config)) {
  1110. if (!info->NoSOName && !info->SOName.empty()) {
  1111. if (info->SOName.find("@rpath/") == 0) {
  1112. install_name_is_rpath = true;
  1113. }
  1114. } else {
  1115. std::string install_name;
  1116. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1117. if (install_name.find("@rpath") != std::string::npos) {
  1118. install_name_is_rpath = true;
  1119. }
  1120. }
  1121. }
  1122. }
  1123. if (!install_name_is_rpath && !macosx_rpath) {
  1124. return false;
  1125. }
  1126. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1127. std::ostringstream w;
  1128. w << "Attempting to use";
  1129. if (macosx_rpath) {
  1130. w << " MACOSX_RPATH";
  1131. } else {
  1132. w << " @rpath";
  1133. }
  1134. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1135. w << " This could be because you are using a Mac OS X version";
  1136. w << " less than 10.5 or because CMake's platform configuration is";
  1137. w << " corrupt.";
  1138. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1139. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  1140. }
  1141. return true;
  1142. }
  1143. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1144. {
  1145. // we can't do rpaths when unsupported
  1146. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1147. return false;
  1148. }
  1149. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1150. if (macosx_rpath_str) {
  1151. return this->GetPropertyAsBool("MACOSX_RPATH");
  1152. }
  1153. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  1154. if (cmp0042 == cmPolicies::WARN) {
  1155. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  1156. this->GetName());
  1157. }
  1158. return cmp0042 == cmPolicies::NEW;
  1159. }
  1160. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1161. {
  1162. if (this->IsImported()) {
  1163. // Lookup the imported soname.
  1164. if (cmGeneratorTarget::ImportInfo const* info =
  1165. this->GetImportInfo(config)) {
  1166. if (info->NoSOName) {
  1167. // The imported library has no builtin soname so the name
  1168. // searched at runtime will be just the filename.
  1169. return cmSystemTools::GetFilenameName(info->Location);
  1170. } else {
  1171. // Use the soname given if any.
  1172. if (info->SOName.find("@rpath/") == 0) {
  1173. return info->SOName.substr(6);
  1174. }
  1175. return info->SOName;
  1176. }
  1177. } else {
  1178. return "";
  1179. }
  1180. } else {
  1181. // Compute the soname that will be built.
  1182. std::string name;
  1183. std::string soName;
  1184. std::string realName;
  1185. std::string impName;
  1186. std::string pdbName;
  1187. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  1188. return soName;
  1189. }
  1190. }
  1191. std::string cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  1192. bool contentOnly) const
  1193. {
  1194. std::string fpath = this->GetFullName(config, false);
  1195. fpath += ".app";
  1196. if (!this->Makefile->PlatformIsAppleIos()) {
  1197. fpath += "/Contents";
  1198. if (!contentOnly) {
  1199. fpath += "/MacOS";
  1200. }
  1201. }
  1202. return fpath;
  1203. }
  1204. bool cmGeneratorTarget::IsBundleOnApple() const
  1205. {
  1206. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  1207. this->IsCFBundleOnApple();
  1208. }
  1209. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  1210. bool contentOnly) const
  1211. {
  1212. std::string fpath;
  1213. fpath += this->GetOutputName(config, false);
  1214. fpath += ".";
  1215. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1216. if (!ext) {
  1217. if (this->IsXCTestOnApple()) {
  1218. ext = "xctest";
  1219. } else {
  1220. ext = "bundle";
  1221. }
  1222. }
  1223. fpath += ext;
  1224. if (!this->Makefile->PlatformIsAppleIos()) {
  1225. fpath += "/Contents";
  1226. if (!contentOnly) {
  1227. fpath += "/MacOS";
  1228. }
  1229. }
  1230. return fpath;
  1231. }
  1232. std::string cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  1233. bool rootDir) const
  1234. {
  1235. std::string fpath;
  1236. fpath += this->GetOutputName(config, false);
  1237. fpath += ".framework";
  1238. if (!rootDir && !this->Makefile->PlatformIsAppleIos()) {
  1239. fpath += "/Versions/";
  1240. fpath += this->GetFrameworkVersion();
  1241. }
  1242. return fpath;
  1243. }
  1244. std::string cmGeneratorTarget::GetFullName(const std::string& config,
  1245. bool implib) const
  1246. {
  1247. if (this->IsImported()) {
  1248. return this->GetFullNameImported(config, implib);
  1249. } else {
  1250. return this->GetFullNameInternal(config, implib);
  1251. }
  1252. }
  1253. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1254. const std::string& config) const
  1255. {
  1256. // If building directly for installation then the build tree install_name
  1257. // is the same as the install tree.
  1258. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1259. return this->GetInstallNameDirForInstallTree();
  1260. }
  1261. // Use the build tree directory for the target.
  1262. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1263. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1264. !this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  1265. std::string dir;
  1266. if (this->MacOSXRpathInstallNameDirDefault()) {
  1267. dir = "@rpath";
  1268. } else {
  1269. dir = this->GetDirectory(config);
  1270. }
  1271. dir += "/";
  1272. return dir;
  1273. } else {
  1274. return "";
  1275. }
  1276. }
  1277. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1278. {
  1279. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1280. std::string dir;
  1281. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1282. if (!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1283. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH")) {
  1284. if (install_name_dir && *install_name_dir) {
  1285. dir = install_name_dir;
  1286. dir += "/";
  1287. }
  1288. }
  1289. if (!install_name_dir) {
  1290. if (this->MacOSXRpathInstallNameDirDefault()) {
  1291. dir = "@rpath/";
  1292. }
  1293. }
  1294. return dir;
  1295. } else {
  1296. return "";
  1297. }
  1298. }
  1299. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  1300. {
  1301. return this->Target->GetBacktrace();
  1302. }
  1303. const std::vector<std::string>& cmGeneratorTarget::GetLinkDirectories() const
  1304. {
  1305. return this->Target->GetLinkDirectories();
  1306. }
  1307. const std::set<std::string>& cmGeneratorTarget::GetUtilities() const
  1308. {
  1309. return this->Target->GetUtilities();
  1310. }
  1311. const cmListFileBacktrace* cmGeneratorTarget::GetUtilityBacktrace(
  1312. const std::string& u) const
  1313. {
  1314. return this->Target->GetUtilityBacktrace(u);
  1315. }
  1316. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  1317. {
  1318. return this->GetType() == cmState::STATIC_LIBRARY ||
  1319. this->GetType() == cmState::SHARED_LIBRARY ||
  1320. this->GetType() == cmState::MODULE_LIBRARY ||
  1321. this->GetType() == cmState::EXECUTABLE;
  1322. }
  1323. const char* cmGeneratorTarget::GetExportMacro() const
  1324. {
  1325. // Define the symbol for targets that export symbols.
  1326. if (this->GetType() == cmState::SHARED_LIBRARY ||
  1327. this->GetType() == cmState::MODULE_LIBRARY ||
  1328. this->IsExecutableWithExports()) {
  1329. if (const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  1330. this->ExportMacro = custom_export_name;
  1331. } else {
  1332. std::string in = this->GetName();
  1333. in += "_EXPORTS";
  1334. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  1335. }
  1336. return this->ExportMacro.c_str();
  1337. } else {
  1338. return 0;
  1339. }
  1340. }
  1341. class cmTargetCollectLinkLanguages
  1342. {
  1343. public:
  1344. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1345. const std::string& config,
  1346. UNORDERED_SET<std::string>& languages,
  1347. cmGeneratorTarget const* head)
  1348. : Config(config)
  1349. , Languages(languages)
  1350. , HeadTarget(head)
  1351. , Target(target)
  1352. {
  1353. this->Visited.insert(target);
  1354. }
  1355. void Visit(cmLinkItem const& item)
  1356. {
  1357. if (!item.Target) {
  1358. if (item.find("::") != std::string::npos) {
  1359. bool noMessage = false;
  1360. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1361. std::ostringstream e;
  1362. switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
  1363. cmPolicies::CMP0028)) {
  1364. case cmPolicies::WARN: {
  1365. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1366. messageType = cmake::AUTHOR_WARNING;
  1367. } break;
  1368. case cmPolicies::OLD:
  1369. noMessage = true;
  1370. case cmPolicies::REQUIRED_IF_USED:
  1371. case cmPolicies::REQUIRED_ALWAYS:
  1372. case cmPolicies::NEW:
  1373. // Issue the fatal message.
  1374. break;
  1375. }
  1376. if (!noMessage) {
  1377. e << "Target \"" << this->Target->GetName()
  1378. << "\" links to target \"" << item
  1379. << "\" but the target was not found. Perhaps a find_package() "
  1380. "call is missing for an IMPORTED target, or an ALIAS target is "
  1381. "missing?";
  1382. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1383. messageType, e.str(), this->Target->GetBacktrace());
  1384. }
  1385. }
  1386. return;
  1387. }
  1388. if (!this->Visited.insert(item.Target).second) {
  1389. return;
  1390. }
  1391. cmLinkInterface const* iface =
  1392. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  1393. if (!iface) {
  1394. return;
  1395. }
  1396. for (std::vector<std::string>::const_iterator li =
  1397. iface->Languages.begin();
  1398. li != iface->Languages.end(); ++li) {
  1399. this->Languages.insert(*li);
  1400. }
  1401. for (std::vector<cmLinkItem>::const_iterator li = iface->Libraries.begin();
  1402. li != iface->Libraries.end(); ++li) {
  1403. this->Visit(*li);
  1404. }
  1405. }
  1406. private:
  1407. std::string Config;
  1408. UNORDERED_SET<std::string>& Languages;
  1409. cmGeneratorTarget const* HeadTarget;
  1410. const cmGeneratorTarget* Target;
  1411. std::set<cmGeneratorTarget const*> Visited;
  1412. };
  1413. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  1414. const std::string& config) const
  1415. {
  1416. std::string key(cmSystemTools::UpperCase(config));
  1417. LinkClosureMapType::iterator i = this->LinkClosureMap.find(key);
  1418. if (i == this->LinkClosureMap.end()) {
  1419. LinkClosure lc;
  1420. this->ComputeLinkClosure(config, lc);
  1421. LinkClosureMapType::value_type entry(key, lc);
  1422. i = this->LinkClosureMap.insert(entry).first;
  1423. }
  1424. return &i->second;
  1425. }
  1426. class cmTargetSelectLinker
  1427. {
  1428. int Preference;
  1429. cmGeneratorTarget const* Target;
  1430. cmGlobalGenerator* GG;
  1431. std::set<std::string> Preferred;
  1432. public:
  1433. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1434. : Preference(0)
  1435. , Target(target)
  1436. {
  1437. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1438. }
  1439. void Consider(const char* lang)
  1440. {
  1441. int preference = this->GG->GetLinkerPreference(lang);
  1442. if (preference > this->Preference) {
  1443. this->Preference = preference;
  1444. this->Preferred.clear();
  1445. }
  1446. if (preference == this->Preference) {
  1447. this->Preferred.insert(lang);
  1448. }
  1449. }
  1450. std::string Choose()
  1451. {
  1452. if (this->Preferred.empty()) {
  1453. return "";
  1454. } else if (this->Preferred.size() > 1) {
  1455. std::ostringstream e;
  1456. e << "Target " << this->Target->GetName()
  1457. << " contains multiple languages with the highest linker preference"
  1458. << " (" << this->Preference << "):\n";
  1459. for (std::set<std::string>::const_iterator li = this->Preferred.begin();
  1460. li != this->Preferred.end(); ++li) {
  1461. e << " " << *li << "\n";
  1462. }
  1463. e << "Set the LINKER_LANGUAGE property for this target.";
  1464. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  1465. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1466. this->Target->GetBacktrace());
  1467. }
  1468. return *this->Preferred.begin();
  1469. }
  1470. };
  1471. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1472. LinkClosure& lc) const
  1473. {
  1474. // Get languages built in this target.
  1475. UNORDERED_SET<std::string> languages;
  1476. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1477. assert(impl);
  1478. for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1479. li != impl->Languages.end(); ++li) {
  1480. languages.insert(*li);
  1481. }
  1482. // Add interface languages from linked targets.
  1483. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  1484. for (std::vector<cmLinkImplItem>::const_iterator li =
  1485. impl->Libraries.begin();
  1486. li != impl->Libraries.end(); ++li) {
  1487. cll.Visit(*li);
  1488. }
  1489. // Store the transitive closure of languages.
  1490. for (UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1491. li != languages.end(); ++li) {
  1492. lc.Languages.push_back(*li);
  1493. }
  1494. // Choose the language whose linker should be used.
  1495. if (this->GetProperty("HAS_CXX")) {
  1496. lc.LinkerLanguage = "CXX";
  1497. } else if (const char* linkerLang = this->GetProperty("LINKER_LANGUAGE")) {
  1498. lc.LinkerLanguage = linkerLang;
  1499. } else {
  1500. // Find the language with the highest preference value.
  1501. cmTargetSelectLinker tsl(this);
  1502. // First select from the languages compiled directly in this target.
  1503. for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1504. li != impl->Languages.end(); ++li) {
  1505. tsl.Consider(li->c_str());
  1506. }
  1507. // Now consider languages that propagate from linked targets.
  1508. for (UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1509. sit != languages.end(); ++sit) {
  1510. std::string propagates =
  1511. "CMAKE_" + *sit + "_LINKER_PREFERENCE_PROPAGATES";
  1512. if (this->Makefile->IsOn(propagates)) {
  1513. tsl.Consider(sit->c_str());
  1514. }
  1515. }
  1516. lc.LinkerLanguage = tsl.Choose();
  1517. }
  1518. }
  1519. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1520. std::string& base,
  1521. std::string& suffix,
  1522. const std::string& config,
  1523. bool implib) const
  1524. {
  1525. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1526. }
  1527. std::string cmGeneratorTarget::BuildMacContentDirectory(
  1528. const std::string& base, const std::string& config, bool contentOnly) const
  1529. {
  1530. std::string fpath = base;
  1531. if (this->IsAppBundleOnApple()) {
  1532. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1533. }
  1534. if (this->IsFrameworkOnApple()) {
  1535. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1536. }
  1537. if (this->IsCFBundleOnApple()) {
  1538. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1539. }
  1540. return fpath;
  1541. }
  1542. std::string cmGeneratorTarget::GetMacContentDirectory(
  1543. const std::string& config, bool implib) const
  1544. {
  1545. // Start with the output directory for the target.
  1546. std::string fpath = this->GetDirectory(config, implib);
  1547. fpath += "/";
  1548. bool contentOnly = true;
  1549. if (this->IsFrameworkOnApple()) {
  1550. // additional files with a framework go into the version specific
  1551. // directory
  1552. contentOnly = false;
  1553. }
  1554. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1555. return fpath;
  1556. }
  1557. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1558. const std::string& config) const
  1559. {
  1560. // There is no compile information for imported targets.
  1561. if (this->IsImported()) {
  1562. return 0;
  1563. }
  1564. if (this->GetType() > cmState::OBJECT_LIBRARY) {
  1565. std::string msg = "cmTarget::GetCompileInfo called for ";
  1566. msg += this->GetName();
  1567. msg += " which has type ";
  1568. msg += cmState::GetTargetTypeName(this->GetType());
  1569. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1570. return 0;
  1571. }
  1572. // Lookup/compute/cache the compile information for this configuration.
  1573. std::string config_upper;
  1574. if (!config.empty()) {
  1575. config_upper = cmSystemTools::UpperCase(config);
  1576. }
  1577. CompileInfoMapType::const_iterator i =
  1578. this->CompileInfoMap.find(config_upper);
  1579. if (i == this->CompileInfoMap.end()) {
  1580. CompileInfo info;
  1581. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1582. CompileInfoMapType::value_type entry(config_upper, info);
  1583. i = this->CompileInfoMap.insert(entry).first;
  1584. }
  1585. return &i->second;
  1586. }
  1587. cmSourceFile const* cmGeneratorTarget::GetModuleDefinitionFile(
  1588. const std::string& config) const
  1589. {
  1590. std::vector<cmSourceFile const*> data;
  1591. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile,
  1592. COMMA std::vector<cmSourceFile const*>)
  1593. if (!data.empty()) {
  1594. return data.front();
  1595. }
  1596. return 0;
  1597. }
  1598. bool cmGeneratorTarget::IsDLLPlatform() const
  1599. {
  1600. return this->DLLPlatform;
  1601. }
  1602. void cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1603. const std::string& config) const
  1604. {
  1605. std::vector<cmSourceFile const*> objectFiles;
  1606. this->GetExternalObjects(objectFiles, config);
  1607. std::vector<cmGeneratorTarget*> objectLibraries;
  1608. for (std::vector<cmSourceFile const*>::const_iterator it =
  1609. objectFiles.begin();
  1610. it != objectFiles.end(); ++it) {
  1611. std::string objLib = (*it)->GetObjectLibrary();
  1612. if (cmGeneratorTarget* tgt =
  1613. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  1614. objectLibraries.push_back(tgt);
  1615. }
  1616. }
  1617. std::vector<cmGeneratorTarget*>::const_iterator end =
  1618. cmRemoveDuplicates(objectLibraries);
  1619. for (std::vector<cmGeneratorTarget*>::const_iterator ti =
  1620. objectLibraries.begin();
  1621. ti != end; ++ti) {
  1622. cmGeneratorTarget* ogt = *ti;
  1623. std::vector<cmSourceFile const*> objectSources;
  1624. ogt->GetObjectSources(objectSources, config);
  1625. for (std::vector<cmSourceFile const*>::const_iterator si =
  1626. objectSources.begin();
  1627. si != objectSources.end(); ++si) {
  1628. std::string obj = ogt->ObjectDirectory;
  1629. obj += ogt->Objects[*si];
  1630. objs.push_back(obj);
  1631. }
  1632. }
  1633. }
  1634. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  1635. const std::string& config) const
  1636. {
  1637. const char* prop =
  1638. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  1639. if (!prop) {
  1640. return;
  1641. }
  1642. cmGeneratorExpression ge;
  1643. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1644. "AUTOUIC_OPTIONS", 0, 0);
  1645. cmSystemTools::ExpandListArgument(
  1646. ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this,
  1647. &dagChecker),
  1648. result);
  1649. }
  1650. void processILibs(const std::string& config,
  1651. cmGeneratorTarget const* headTarget, cmLinkItem const& item,
  1652. cmGlobalGenerator* gg,
  1653. std::vector<cmGeneratorTarget const*>& tgts,
  1654. std::set<cmGeneratorTarget const*>& emitted)
  1655. {
  1656. if (item.Target && emitted.insert(item.Target).second) {
  1657. tgts.push_back(item.Target);
  1658. if (cmLinkInterfaceLibraries const* iface =
  1659. item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) {
  1660. for (std::vector<cmLinkItem>::const_iterator it =
  1661. iface->Libraries.begin();
  1662. it != iface->Libraries.end(); ++it) {
  1663. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1664. }
  1665. }
  1666. }
  1667. }
  1668. const std::vector<const cmGeneratorTarget*>&
  1669. cmGeneratorTarget::GetLinkImplementationClosure(
  1670. const std::string& config) const
  1671. {
  1672. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  1673. if (!tgts.Done) {
  1674. tgts.Done = true;
  1675. std::set<cmGeneratorTarget const*> emitted;
  1676. cmLinkImplementationLibraries const* impl =
  1677. this->GetLinkImplementationLibraries(config);
  1678. for (std::vector<cmLinkImplItem>::const_iterator it =
  1679. impl->Libraries.begin();
  1680. it != impl->Libraries.end(); ++it) {
  1681. processILibs(config, this, *it,
  1682. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  1683. }
  1684. }
  1685. return tgts;
  1686. }
  1687. class cmTargetTraceDependencies
  1688. {
  1689. public:
  1690. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1691. void Trace();
  1692. private:
  1693. cmGeneratorTarget* GeneratorTarget;
  1694. cmMakefile* Makefile;
  1695. cmLocalGenerator* LocalGenerator;
  1696. cmGlobalGenerator const* GlobalGenerator;
  1697. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1698. SourceEntry* CurrentEntry;
  1699. std::queue<cmSourceFile*> SourceQueue;
  1700. std::set<cmSourceFile*> SourcesQueued;
  1701. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1702. NameMapType NameMap;
  1703. std::vector<std::string> NewSources;
  1704. void QueueSource(cmSourceFile* sf);
  1705. void FollowName(std::string const& name);
  1706. void FollowNames(std::vector<std::string> const& names);
  1707. bool IsUtility(std::string const& dep);
  1708. void CheckCustomCommand(cmCustomCommand const& cc);
  1709. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1710. void FollowCommandDepends(cmCustomCommand const& cc,
  1711. const std::string& config,
  1712. std::set<std::string>& emitted);
  1713. };
  1714. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  1715. : GeneratorTarget(target)
  1716. {
  1717. // Convenience.
  1718. this->Makefile = target->Target->GetMakefile();
  1719. this->LocalGenerator = target->GetLocalGenerator();
  1720. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  1721. this->CurrentEntry = 0;
  1722. // Queue all the source files already specified for the target.
  1723. if (target->GetType() != cmState::INTERFACE_LIBRARY) {
  1724. std::vector<std::string> configs;
  1725. this->Makefile->GetConfigurations(configs);
  1726. if (configs.empty()) {
  1727. configs.push_back("");
  1728. }
  1729. std::set<cmSourceFile*> emitted;
  1730. for (std::vector<std::string>::const_iterator ci = configs.begin();
  1731. ci != configs.end(); ++ci) {
  1732. std::vector<cmSourceFile*> sources;
  1733. this->GeneratorTarget->GetSourceFiles(sources, *ci);
  1734. for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1735. si != sources.end(); ++si) {
  1736. cmSourceFile* sf = *si;
  1737. const std::set<cmGeneratorTarget const*> tgts =
  1738. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1739. if (tgts.find(this->GeneratorTarget) != tgts.end()) {
  1740. std::ostringstream e;
  1741. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1742. << "\"\ndepends on the sources of a target it is used in. This "
  1743. "is a dependency loop and is not allowed.";
  1744. this->GeneratorTarget->LocalGenerator->IssueMessage(
  1745. cmake::FATAL_ERROR, e.str());
  1746. return;
  1747. }
  1748. if (emitted.insert(sf).second &&
  1749. this->SourcesQueued.insert(sf).second) {
  1750. this->SourceQueue.push(sf);
  1751. }
  1752. }
  1753. }
  1754. }
  1755. // Queue pre-build, pre-link, and post-build rule dependencies.
  1756. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  1757. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  1758. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  1759. }
  1760. void cmTargetTraceDependencies::Trace()
  1761. {
  1762. // Process one dependency at a time until the queue is empty.
  1763. while (!this->SourceQueue.empty()) {
  1764. // Get the next source from the queue.
  1765. cmSourceFile* sf = this->SourceQueue.front();
  1766. this->SourceQueue.pop();
  1767. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  1768. // Queue dependencies added explicitly by the user.
  1769. if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  1770. std::vector<std::string> objDeps;
  1771. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1772. for (std::vector<std::string>::iterator odi = objDeps.begin();
  1773. odi != objDeps.end(); ++odi) {
  1774. if (cmSystemTools::FileIsFullPath(*odi)) {
  1775. *odi = cmSystemTools::CollapseFullPath(*odi);
  1776. }
  1777. }
  1778. this->FollowNames(objDeps);
  1779. }
  1780. // Queue the source needed to generate this file, if any.
  1781. this->FollowName(sf->GetFullPath());
  1782. // Queue dependencies added programatically by commands.
  1783. this->FollowNames(sf->GetDepends());
  1784. // Queue custom command dependencies.
  1785. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  1786. this->CheckCustomCommand(*cc);
  1787. }
  1788. }
  1789. this->CurrentEntry = 0;
  1790. this->GeneratorTarget->AddTracedSources(this->NewSources);
  1791. }
  1792. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1793. {
  1794. if (this->SourcesQueued.insert(sf).second) {
  1795. this->SourceQueue.push(sf);
  1796. // Make sure this file is in the target at the end.
  1797. this->NewSources.push_back(sf->GetFullPath());
  1798. }
  1799. }
  1800. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1801. {
  1802. NameMapType::iterator i = this->NameMap.find(name);
  1803. if (i == this->NameMap.end()) {
  1804. // Check if we know how to generate this file.
  1805. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1806. NameMapType::value_type entry(name, sf);
  1807. i = this->NameMap.insert(entry).first;
  1808. }
  1809. if (cmSourceFile* sf = i->second) {
  1810. // Record the dependency we just followed.
  1811. if (this->CurrentEntry) {
  1812. this->CurrentEntry->Depends.push_back(sf);
  1813. }
  1814. this->QueueSource(sf);
  1815. }
  1816. }
  1817. void cmTargetTraceDependencies::FollowNames(
  1818. std::vector<std::string> const& names)
  1819. {
  1820. for (std::vector<std::string>::const_iterator i = names.begin();
  1821. i != names.end(); ++i) {
  1822. this->FollowName(*i);
  1823. }
  1824. }
  1825. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1826. {
  1827. // Dependencies on targets (utilities) are supposed to be named by
  1828. // just the target name. However for compatibility we support
  1829. // naming the output file generated by the target (assuming there is
  1830. // no output-name property which old code would not have set). In
  1831. // that case the target name will be the file basename of the
  1832. // dependency.
  1833. std::string util = cmSystemTools::GetFilenameName(dep);
  1834. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  1835. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1836. }
  1837. // Check for a target with this name.
  1838. if (cmGeneratorTarget* t =
  1839. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  1840. util)) {
  1841. // If we find the target and the dep was given as a full path,
  1842. // then make sure it was not a full path to something else, and
  1843. // the fact that the name matched a target was just a coincidence.
  1844. if (cmSystemTools::FileIsFullPath(dep.c_str())) {
  1845. if (t->GetType() >= cmState::EXECUTABLE &&
  1846. t->GetType() <= cmState::MODULE_LIBRARY) {
  1847. // This is really only for compatibility so we do not need to
  1848. // worry about configuration names and output names.
  1849. std::string tLocation = t->GetLocationForBuild();
  1850. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1851. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1852. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1853. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1854. if (depLocation == tLocation) {
  1855. this->GeneratorTarget->Target->AddUtility(util);
  1856. return true;
  1857. }
  1858. }
  1859. } else {
  1860. // The original name of the dependency was not a full path. It
  1861. // must name a target, so add the target-level dependency.
  1862. this->GeneratorTarget->Target->AddUtility(util);
  1863. return true;
  1864. }
  1865. }
  1866. // The dependency does not name a target built in this project.
  1867. return false;
  1868. }
  1869. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  1870. {
  1871. // Transform command names that reference targets built in this
  1872. // project to corresponding target-level dependencies.
  1873. cmGeneratorExpression ge(cc.GetBacktrace());
  1874. // Add target-level dependencies referenced by generator expressions.
  1875. std::set<cmGeneratorTarget*> targets;
  1876. for (cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1877. cit != cc.GetCommandLines().end(); ++cit) {
  1878. std::string const& command = *cit->begin();
  1879. // Check for a target with this name.
  1880. if (cmGeneratorTarget* t =
  1881. this->LocalGenerator->FindGeneratorTargetToUse(command)) {
  1882. if (t->GetType() == cmState::EXECUTABLE) {
  1883. // The command refers to an executable target built in
  1884. // this project. Add the target-level dependency to make
  1885. // sure the executable is up to date before this custom
  1886. // command possibly runs.
  1887. this->GeneratorTarget->Target->AddUtility(command);
  1888. }
  1889. }
  1890. // Check for target references in generator expressions.
  1891. for (cmCustomCommandLine::const_iterator cli = cit->begin();
  1892. cli != cit->end(); ++cli) {
  1893. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1894. ge.Parse(*cli);
  1895. cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
  1896. std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
  1897. targets.insert(geTargets.begin(), geTargets.end());
  1898. }
  1899. }
  1900. for (std::set<cmGeneratorTarget*>::iterator ti = targets.begin();
  1901. ti != targets.end(); ++ti) {
  1902. this->GeneratorTarget->Target->AddUtility((*ti)->GetName());
  1903. }
  1904. // Queue the custom command dependencies.
  1905. std::vector<std::string> configs;
  1906. std::set<std::string> emitted;
  1907. this->Makefile->GetConfigurations(configs);
  1908. if (configs.empty()) {
  1909. configs.push_back("");
  1910. }
  1911. for (std::vector<std::string>::const_iterator ci = configs.begin();
  1912. ci != configs.end(); ++ci) {
  1913. this->FollowCommandDepends(cc, *ci, emitted);
  1914. }
  1915. }
  1916. void cmTargetTraceDependencies::FollowCommandDepends(
  1917. cmCustomCommand const& cc, const std::string& config,
  1918. std::set<std::string>& emitted)
  1919. {
  1920. cmCustomCommandGenerator ccg(cc, config,
  1921. this->GeneratorTarget->LocalGenerator);
  1922. const std::vector<std::string>& depends = ccg.GetDepends();
  1923. for (std::vector<std::string>::const_iterator di = depends.begin();
  1924. di != depends.end(); ++di) {
  1925. std::string const& dep = *di;
  1926. if (emitted.insert(dep).second) {
  1927. if (!this->IsUtility(dep)) {
  1928. // The dependency does not name a target and may be a file we
  1929. // know how to generate. Queue it.
  1930. this->FollowName(dep);
  1931. }
  1932. }
  1933. }
  1934. }
  1935. void cmTargetTraceDependencies::CheckCustomCommands(
  1936. const std::vector<cmCustomCommand>& commands)
  1937. {
  1938. for (std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1939. cli != commands.end(); ++cli) {
  1940. this->CheckCustomCommand(*cli);
  1941. }
  1942. }
  1943. void cmGeneratorTarget::TraceDependencies()
  1944. {
  1945. // CMake-generated targets have no dependencies to trace. Normally tracing
  1946. // would find nothing anyway, but when building CMake itself the "install"
  1947. // target command ends up referencing the "cmake" target but we do not
  1948. // really want the dependency because "install" depend on "all" anyway.
  1949. if (this->GetType() == cmState::GLOBAL_TARGET) {
  1950. return;
  1951. }
  1952. // Use a helper object to trace the dependencies.
  1953. cmTargetTraceDependencies tracer(this);
  1954. tracer.Trace();
  1955. }
  1956. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  1957. const std::string& config) const
  1958. {
  1959. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  1960. return info->CompilePdbDir;
  1961. }
  1962. return "";
  1963. }
  1964. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1965. std::vector<std::string>& archVec) const
  1966. {
  1967. const char* archs = 0;
  1968. if (!config.empty()) {
  1969. std::string defVarName = "OSX_ARCHITECTURES_";
  1970. defVarName += cmSystemTools::UpperCase(config);
  1971. archs = this->GetProperty(defVarName);
  1972. }
  1973. if (!archs) {
  1974. archs = this->GetProperty("OSX_ARCHITECTURES");
  1975. }
  1976. if (archs) {
  1977. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1978. }
  1979. }
  1980. std::string cmGeneratorTarget::GetCreateRuleVariable(
  1981. std::string const& lang, std::string const& config) const
  1982. {
  1983. switch (this->GetType()) {
  1984. case cmState::STATIC_LIBRARY: {
  1985. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1986. if (this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) {
  1987. std::string varIPO = var + "_IPO";
  1988. if (this->Makefile->GetDefinition(varIPO)) {
  1989. return varIPO;
  1990. }
  1991. }
  1992. return var;
  1993. }
  1994. case cmState::SHARED_LIBRARY:
  1995. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1996. case cmState::MODULE_LIBRARY:
  1997. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1998. case cmState::EXECUTABLE:
  1999. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2000. default:
  2001. break;
  2002. }
  2003. return "";
  2004. }
  2005. static void processIncludeDirectories(
  2006. cmGeneratorTarget const* tgt,
  2007. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2008. std::vector<std::string>& includes,
  2009. UNORDERED_SET<std::string>& uniqueIncludes,
  2010. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2011. bool debugIncludes, const std::string& language)
  2012. {
  2013. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  2014. it = entries.begin(),
  2015. end = entries.end();
  2016. it != end; ++it) {
  2017. cmLinkImplItem const& item = (*it)->LinkImplItem;
  2018. std::string const& targetName = item;
  2019. bool const fromImported = item.Target && item.Target->IsImported();
  2020. bool const checkCMP0027 = item.FromGenex;
  2021. std::vector<std::string> entryIncludes;
  2022. cmSystemTools::ExpandListArgument(
  2023. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2024. dagChecker, language),
  2025. entryIncludes);
  2026. std::string usedIncludes;
  2027. for (std::vector<std::string>::iterator li = entryIncludes.begin();
  2028. li != entryIncludes.end(); ++li) {
  2029. if (fromImported && !cmSystemTools::FileExists(li->c_str())) {
  2030. std::ostringstream e;
  2031. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2032. if (checkCMP0027) {
  2033. switch (tgt->GetPolicyStatusCMP0027()) {
  2034. case cmPolicies::WARN:
  2035. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2036. case cmPolicies::OLD:
  2037. messageType = cmake::AUTHOR_WARNING;
  2038. break;
  2039. case cmPolicies::REQUIRED_ALWAYS:
  2040. case cmPolicies::REQUIRED_IF_USED:
  2041. case cmPolicies::NEW:
  2042. break;
  2043. }
  2044. }
  2045. /* clang-format off */
  2046. e << "Imported target \"" << targetName << "\" includes "
  2047. "non-existent path\n \"" << *li << "\"\nin its "
  2048. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2049. "* The path was deleted, renamed, or moved to another "
  2050. "location.\n"
  2051. "* An install or uninstall procedure did not complete "
  2052. "successfully.\n"
  2053. "* The installation package was faulty and references files it "
  2054. "does not provide.\n";
  2055. /* clang-format on */
  2056. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2057. return;
  2058. }
  2059. if (!cmSystemTools::FileIsFullPath(li->c_str())) {
  2060. std::ostringstream e;
  2061. bool noMessage = false;
  2062. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2063. if (!targetName.empty()) {
  2064. /* clang-format off */
  2065. e << "Target \"" << targetName << "\" contains relative "
  2066. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2067. " \"" << *li << "\"";
  2068. /* clang-format on */
  2069. } else {
  2070. switch (tgt->GetPolicyStatusCMP0021()) {
  2071. case cmPolicies::WARN: {
  2072. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2073. messageType = cmake::AUTHOR_WARNING;
  2074. } break;
  2075. case cmPolicies::OLD:
  2076. noMessage = true;
  2077. case cmPolicies::REQUIRED_IF_USED:
  2078. case cmPolicies::REQUIRED_ALWAYS:
  2079. case cmPolicies::NEW:
  2080. // Issue the fatal message.
  2081. break;
  2082. }
  2083. e << "Found relative path while evaluating include directories of "
  2084. "\""
  2085. << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  2086. }
  2087. if (!noMessage) {
  2088. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2089. if (messageType == cmake::FATAL_ERROR) {
  2090. return;
  2091. }
  2092. }
  2093. }
  2094. if (!cmSystemTools::IsOff(li->c_str())) {
  2095. cmSystemTools::ConvertToUnixSlashes(*li);
  2096. }
  2097. std::string inc = *li;
  2098. if (uniqueIncludes.insert(inc).second) {
  2099. includes.push_back(inc);
  2100. if (debugIncludes) {
  2101. usedIncludes += " * " + inc + "\n";
  2102. }
  2103. }
  2104. }
  2105. if (!usedIncludes.empty()) {
  2106. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2107. cmake::LOG, std::string("Used includes for target ") + tgt->GetName() +
  2108. ":\n" + usedIncludes,
  2109. (*it)->ge->GetBacktrace());
  2110. }
  2111. }
  2112. }
  2113. std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
  2114. const std::string& config, const std::string& lang) const
  2115. {
  2116. std::vector<std::string> includes;
  2117. UNORDERED_SET<std::string> uniqueIncludes;
  2118. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2119. "INCLUDE_DIRECTORIES", 0, 0);
  2120. std::vector<std::string> debugProperties;
  2121. const char* debugProp =
  2122. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2123. if (debugProp) {
  2124. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2125. }
  2126. bool debugIncludes = !this->DebugIncludesDone &&
  2127. std::find(debugProperties.begin(), debugProperties.end(),
  2128. "INCLUDE_DIRECTORIES") != debugProperties.end();
  2129. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2130. this->DebugIncludesDone = true;
  2131. }
  2132. processIncludeDirectories(this, this->IncludeDirectoriesEntries, includes,
  2133. uniqueIncludes, &dagChecker, config, debugIncludes,
  2134. lang);
  2135. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2136. linkInterfaceIncludeDirectoriesEntries;
  2137. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2138. linkInterfaceIncludeDirectoriesEntries);
  2139. if (this->Makefile->IsOn("APPLE")) {
  2140. cmLinkImplementationLibraries const* impl =
  2141. this->GetLinkImplementationLibraries(config);
  2142. for (std::vector<cmLinkImplItem>::const_iterator it =
  2143. impl->Libraries.begin();
  2144. it != impl->Libraries.end(); ++it) {
  2145. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2146. static cmsys::RegularExpression frameworkCheck(
  2147. "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2148. if (!frameworkCheck.find(libDir)) {
  2149. continue;
  2150. }
  2151. libDir = frameworkCheck.match(1);
  2152. cmGeneratorExpression ge;
  2153. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2154. ge.Parse(libDir.c_str());
  2155. linkInterfaceIncludeDirectoriesEntries.push_back(
  2156. new cmGeneratorTarget::TargetPropertyEntry(cge));
  2157. }
  2158. }
  2159. processIncludeDirectories(this, linkInterfaceIncludeDirectoriesEntries,
  2160. includes, uniqueIncludes, &dagChecker, config,
  2161. debugIncludes, lang);
  2162. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2163. // Add standard include directories for this language.
  2164. std::string const standardIncludesVar =
  2165. "CMAKE_" + lang + "_STANDARD_INCLUDE_DIRECTORIES";
  2166. std::string const standardIncludes =
  2167. this->Makefile->GetSafeDefinition(standardIncludesVar);
  2168. std::vector<std::string>::size_type const before = includes.size();
  2169. cmSystemTools::ExpandListArgument(standardIncludes, includes);
  2170. for (std::vector<std::string>::iterator i = includes.begin() + before;
  2171. i != includes.end(); ++i) {
  2172. cmSystemTools::ConvertToUnixSlashes(*i);
  2173. }
  2174. return includes;
  2175. }
  2176. static void processCompileOptionsInternal(
  2177. cmGeneratorTarget const* tgt,
  2178. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2179. std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
  2180. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2181. bool debugOptions, const char* logName, std::string const& language)
  2182. {
  2183. for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
  2184. it = entries.begin(),
  2185. end = entries.end();
  2186. it != end; ++it) {
  2187. std::vector<std::string> entryOptions;
  2188. cmSystemTools::ExpandListArgument(
  2189. (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2190. dagChecker, language),
  2191. entryOptions);
  2192. std::string usedOptions;
  2193. for (std::vector<std::string>::iterator li = entryOptions.begin();
  2194. li != entryOptions.end(); ++li) {
  2195. std::string const& opt = *li;
  2196. if (uniqueOptions.insert(opt).second) {
  2197. options.push_back(opt);
  2198. if (debugOptions) {
  2199. usedOptions += " * " + opt + "\n";
  2200. }
  2201. }
  2202. }
  2203. if (!usedOptions.empty()) {
  2204. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2205. cmake::LOG, std::string("Used compile ") + logName +
  2206. std::string(" for target ") + tgt->GetName() + ":\n" + usedOptions,
  2207. (*it)->ge->GetBacktrace());
  2208. }
  2209. }
  2210. }
  2211. static void processCompileOptions(
  2212. cmGeneratorTarget const* tgt,
  2213. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2214. std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
  2215. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2216. bool debugOptions, std::string const& language)
  2217. {
  2218. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2219. dagChecker, config, debugOptions, "options",
  2220. language);
  2221. }
  2222. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  2223. const std::string& config,
  2224. const std::string& language) const
  2225. {
  2226. UNORDERED_SET<std::string> uniqueOptions;
  2227. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2228. "COMPILE_OPTIONS", 0, 0);
  2229. std::vector<std::string> debugProperties;
  2230. const char* debugProp =
  2231. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2232. if (debugProp) {
  2233. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2234. }
  2235. bool debugOptions = !this->DebugCompileOptionsDone &&
  2236. std::find(debugProperties.begin(), debugProperties.end(),
  2237. "COMPILE_OPTIONS") != debugProperties.end();
  2238. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2239. this->DebugCompileOptionsDone = true;
  2240. }
  2241. processCompileOptions(this, this->CompileOptionsEntries, result,
  2242. uniqueOptions, &dagChecker, config, debugOptions,
  2243. language);
  2244. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2245. linkInterfaceCompileOptionsEntries;
  2246. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS",
  2247. linkInterfaceCompileOptionsEntries);
  2248. processCompileOptions(this, linkInterfaceCompileOptionsEntries, result,
  2249. uniqueOptions, &dagChecker, config, debugOptions,
  2250. language);
  2251. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2252. }
  2253. static void processCompileFeatures(
  2254. cmGeneratorTarget const* tgt,
  2255. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2256. std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
  2257. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2258. bool debugOptions)
  2259. {
  2260. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2261. dagChecker, config, debugOptions, "features",
  2262. std::string());
  2263. }
  2264. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  2265. const std::string& config) const
  2266. {
  2267. UNORDERED_SET<std::string> uniqueFeatures;
  2268. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2269. "COMPILE_FEATURES", 0, 0);
  2270. std::vector<std::string> debugProperties;
  2271. const char* debugProp =
  2272. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2273. if (debugProp) {
  2274. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2275. }
  2276. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  2277. std::find(debugProperties.begin(), debugProperties.end(),
  2278. "COMPILE_FEATURES") != debugProperties.end();
  2279. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2280. this->DebugCompileFeaturesDone = true;
  2281. }
  2282. processCompileFeatures(this, this->CompileFeaturesEntries, result,
  2283. uniqueFeatures, &dagChecker, config, debugFeatures);
  2284. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2285. linkInterfaceCompileFeaturesEntries;
  2286. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  2287. linkInterfaceCompileFeaturesEntries);
  2288. processCompileFeatures(this, linkInterfaceCompileFeaturesEntries, result,
  2289. uniqueFeatures, &dagChecker, config, debugFeatures);
  2290. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2291. }
  2292. static void processCompileDefinitions(
  2293. cmGeneratorTarget const* tgt,
  2294. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2295. std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
  2296. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2297. bool debugOptions, std::string const& language)
  2298. {
  2299. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2300. dagChecker, config, debugOptions,
  2301. "definitions", language);
  2302. }
  2303. void cmGeneratorTarget::GetCompileDefinitions(
  2304. std::vector<std::string>& list, const std::string& config,
  2305. const std::string& language) const
  2306. {
  2307. UNORDERED_SET<std::string> uniqueOptions;
  2308. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2309. "COMPILE_DEFINITIONS", 0, 0);
  2310. std::vector<std::string> debugProperties;
  2311. const char* debugProp =
  2312. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2313. if (debugProp) {
  2314. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2315. }
  2316. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  2317. std::find(debugProperties.begin(), debugProperties.end(),
  2318. "COMPILE_DEFINITIONS") != debugProperties.end();
  2319. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2320. this->DebugCompileDefinitionsDone = true;
  2321. }
  2322. processCompileDefinitions(this, this->CompileDefinitionsEntries, list,
  2323. uniqueOptions, &dagChecker, config, debugDefines,
  2324. language);
  2325. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2326. linkInterfaceCompileDefinitionsEntries;
  2327. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2328. linkInterfaceCompileDefinitionsEntries);
  2329. if (!config.empty()) {
  2330. std::string configPropName =
  2331. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  2332. const char* configProp = this->GetProperty(configPropName);
  2333. if (configProp) {
  2334. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  2335. case cmPolicies::WARN: {
  2336. std::ostringstream e;
  2337. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2338. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  2339. }
  2340. case cmPolicies::OLD: {
  2341. cmGeneratorExpression ge;
  2342. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2343. ge.Parse(configProp);
  2344. linkInterfaceCompileDefinitionsEntries.push_back(
  2345. new cmGeneratorTarget::TargetPropertyEntry(cge));
  2346. } break;
  2347. case cmPolicies::NEW:
  2348. case cmPolicies::REQUIRED_ALWAYS:
  2349. case cmPolicies::REQUIRED_IF_USED:
  2350. break;
  2351. }
  2352. }
  2353. }
  2354. processCompileDefinitions(this, linkInterfaceCompileDefinitionsEntries, list,
  2355. uniqueOptions, &dagChecker, config, debugDefines,
  2356. language);
  2357. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2358. }
  2359. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  2360. {
  2361. if (this->IsImported()) {
  2362. return;
  2363. }
  2364. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2365. // Get the names.
  2366. std::string name;
  2367. std::string soName;
  2368. std::string realName;
  2369. std::string impName;
  2370. std::string pdbName;
  2371. if (this->GetType() == cmState::EXECUTABLE) {
  2372. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2373. } else if (this->GetType() == cmState::STATIC_LIBRARY ||
  2374. this->GetType() == cmState::SHARED_LIBRARY ||
  2375. this->GetType() == cmState::MODULE_LIBRARY) {
  2376. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2377. } else {
  2378. return;
  2379. }
  2380. // Get the directory.
  2381. std::string dir = this->GetDirectory(config, false);
  2382. // Add each name.
  2383. std::string f;
  2384. if (!name.empty()) {
  2385. f = dir;
  2386. f += "/";
  2387. f += name;
  2388. gg->AddToManifest(f);
  2389. }
  2390. if (!soName.empty()) {
  2391. f = dir;
  2392. f += "/";
  2393. f += soName;
  2394. gg->AddToManifest(f);
  2395. }
  2396. if (!realName.empty()) {
  2397. f = dir;
  2398. f += "/";
  2399. f += realName;
  2400. gg->AddToManifest(f);
  2401. }
  2402. if (!pdbName.empty()) {
  2403. f = dir;
  2404. f += "/";
  2405. f += pdbName;
  2406. gg->AddToManifest(f);
  2407. }
  2408. if (!impName.empty()) {
  2409. f = this->GetDirectory(config, true);
  2410. f += "/";
  2411. f += impName;
  2412. gg->AddToManifest(f);
  2413. }
  2414. }
  2415. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2416. bool implib, bool realname) const
  2417. {
  2418. if (this->IsImported()) {
  2419. return this->Target->ImportedGetFullPath(config, implib);
  2420. } else {
  2421. return this->NormalGetFullPath(config, implib, realname);
  2422. }
  2423. }
  2424. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  2425. bool implib,
  2426. bool realname) const
  2427. {
  2428. std::string fpath = this->GetDirectory(config, implib);
  2429. fpath += "/";
  2430. if (this->IsAppBundleOnApple()) {
  2431. fpath = this->BuildMacContentDirectory(fpath, config, false);
  2432. fpath += "/";
  2433. }
  2434. // Add the full name of the target.
  2435. if (implib) {
  2436. fpath += this->GetFullName(config, true);
  2437. } else if (realname) {
  2438. fpath += this->NormalGetRealName(config);
  2439. } else {
  2440. fpath += this->GetFullName(config, false);
  2441. }
  2442. return fpath;
  2443. }
  2444. std::string cmGeneratorTarget::NormalGetRealName(
  2445. const std::string& config) const
  2446. {
  2447. // This should not be called for imported targets.
  2448. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2449. // enforcement of the limited imported target API.
  2450. if (this->IsImported()) {
  2451. std::string msg = "NormalGetRealName called on imported target: ";
  2452. msg += this->GetName();
  2453. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2454. }
  2455. if (this->GetType() == cmState::EXECUTABLE) {
  2456. // Compute the real name that will be built.
  2457. std::string name;
  2458. std::string realName;
  2459. std::string impName;
  2460. std::string pdbName;
  2461. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2462. return realName;
  2463. } else {
  2464. // Compute the real name that will be built.
  2465. std::string name;
  2466. std::string soName;
  2467. std::string realName;
  2468. std::string impName;
  2469. std::string pdbName;
  2470. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2471. return realName;
  2472. }
  2473. }
  2474. void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
  2475. std::string& realName,
  2476. std::string& impName,
  2477. std::string& pdbName,
  2478. const std::string& config) const
  2479. {
  2480. // This should not be called for imported targets.
  2481. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2482. // enforcement of the limited imported target API.
  2483. if (this->IsImported()) {
  2484. std::string msg = "GetLibraryNames called on imported target: ";
  2485. msg += this->GetName();
  2486. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2487. return;
  2488. }
  2489. // Check for library version properties.
  2490. const char* version = this->GetProperty("VERSION");
  2491. const char* soversion = this->GetProperty("SOVERSION");
  2492. if (!this->HasSOName(config) ||
  2493. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  2494. this->IsFrameworkOnApple()) {
  2495. // Versioning is supported only for shared libraries and modules,
  2496. // and then only when the platform supports an soname flag.
  2497. version = 0;
  2498. soversion = 0;
  2499. }
  2500. if (version && !soversion) {
  2501. // The soversion must be set if the library version is set. Use
  2502. // the library version as the soversion.
  2503. soversion = version;
  2504. }
  2505. if (!version && soversion) {
  2506. // Use the soversion as the library version.
  2507. version = soversion;
  2508. }
  2509. // Get the components of the library name.
  2510. std::string prefix;
  2511. std::string base;
  2512. std::string suffix;
  2513. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2514. // The library name.
  2515. name = prefix + base + suffix;
  2516. if (this->IsFrameworkOnApple()) {
  2517. realName = prefix;
  2518. if (!this->Makefile->PlatformIsAppleIos()) {
  2519. realName += "Versions/";
  2520. realName += this->GetFrameworkVersion();
  2521. realName += "/";
  2522. }
  2523. realName += base;
  2524. soName = realName;
  2525. } else {
  2526. // The library's soname.
  2527. this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
  2528. // The library's real name on disk.
  2529. this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
  2530. }
  2531. // The import library name.
  2532. if (this->GetType() == cmState::SHARED_LIBRARY ||
  2533. this->GetType() == cmState::MODULE_LIBRARY) {
  2534. impName = this->GetFullNameInternal(config, true);
  2535. } else {
  2536. impName = "";
  2537. }
  2538. // The program database file name.
  2539. pdbName = this->GetPDBName(config);
  2540. }
  2541. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2542. std::string& realName,
  2543. std::string& impName,
  2544. std::string& pdbName,
  2545. const std::string& config) const
  2546. {
  2547. // This should not be called for imported targets.
  2548. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2549. // enforcement of the limited imported target API.
  2550. if (this->IsImported()) {
  2551. std::string msg = "GetExecutableNames called on imported target: ";
  2552. msg += this->GetName();
  2553. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2554. }
  2555. // This versioning is supported only for executables and then only
  2556. // when the platform supports symbolic links.
  2557. #if defined(_WIN32) && !defined(__CYGWIN__)
  2558. const char* version = 0;
  2559. #else
  2560. // Check for executable version properties.
  2561. const char* version = this->GetProperty("VERSION");
  2562. if (this->GetType() != cmState::EXECUTABLE ||
  2563. this->Makefile->IsOn("XCODE")) {
  2564. version = 0;
  2565. }
  2566. #endif
  2567. // Get the components of the executable name.
  2568. std::string prefix;
  2569. std::string base;
  2570. std::string suffix;
  2571. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2572. // The executable name.
  2573. name = prefix + base + suffix;
  2574. // The executable's real name on disk.
  2575. #if defined(__CYGWIN__)
  2576. realName = prefix + base;
  2577. #else
  2578. realName = name;
  2579. #endif
  2580. if (version) {
  2581. realName += "-";
  2582. realName += version;
  2583. }
  2584. #if defined(__CYGWIN__)
  2585. realName += suffix;
  2586. #endif
  2587. // The import library name.
  2588. impName = this->GetFullNameInternal(config, true);
  2589. // The program database file name.
  2590. pdbName = this->GetPDBName(config);
  2591. }
  2592. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2593. bool implib) const
  2594. {
  2595. std::string prefix;
  2596. std::string base;
  2597. std::string suffix;
  2598. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2599. return prefix + base + suffix;
  2600. }
  2601. const char* cmGeneratorTarget::ImportedGetLocation(
  2602. const std::string& config) const
  2603. {
  2604. static std::string location;
  2605. assert(this->IsImported());
  2606. location = this->Target->ImportedGetFullPath(config, false);
  2607. return location.c_str();
  2608. }
  2609. std::string cmGeneratorTarget::GetFullNameImported(const std::string& config,
  2610. bool implib) const
  2611. {
  2612. return cmSystemTools::GetFilenameName(
  2613. this->Target->ImportedGetFullPath(config, implib));
  2614. }
  2615. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2616. bool implib,
  2617. std::string& outPrefix,
  2618. std::string& outBase,
  2619. std::string& outSuffix) const
  2620. {
  2621. // Use just the target name for non-main target types.
  2622. if (this->GetType() != cmState::STATIC_LIBRARY &&
  2623. this->GetType() != cmState::SHARED_LIBRARY &&
  2624. this->GetType() != cmState::MODULE_LIBRARY &&
  2625. this->GetType() != cmState::EXECUTABLE) {
  2626. outPrefix = "";
  2627. outBase = this->GetName();
  2628. outSuffix = "";
  2629. return;
  2630. }
  2631. // Return an empty name for the import library if this platform
  2632. // does not support import libraries.
  2633. if (implib &&
  2634. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
  2635. outPrefix = "";
  2636. outBase = "";
  2637. outSuffix = "";
  2638. return;
  2639. }
  2640. // The implib option is only allowed for shared libraries, module
  2641. // libraries, and executables.
  2642. if (this->GetType() != cmState::SHARED_LIBRARY &&
  2643. this->GetType() != cmState::MODULE_LIBRARY &&
  2644. this->GetType() != cmState::EXECUTABLE) {
  2645. implib = false;
  2646. }
  2647. // Compute the full name for main target types.
  2648. const char* targetPrefix = (implib ? this->GetProperty("IMPORT_PREFIX")
  2649. : this->GetProperty("PREFIX"));
  2650. const char* targetSuffix = (implib ? this->GetProperty("IMPORT_SUFFIX")
  2651. : this->GetProperty("SUFFIX"));
  2652. const char* configPostfix = 0;
  2653. if (!config.empty()) {
  2654. std::string configProp = cmSystemTools::UpperCase(config);
  2655. configProp += "_POSTFIX";
  2656. configPostfix = this->GetProperty(configProp);
  2657. // Mac application bundles and frameworks have no postfix.
  2658. if (configPostfix &&
  2659. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  2660. configPostfix = 0;
  2661. }
  2662. }
  2663. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2664. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2665. // Check for language-specific default prefix and suffix.
  2666. std::string ll = this->GetLinkerLanguage(config);
  2667. if (!ll.empty()) {
  2668. if (!targetSuffix && suffixVar && *suffixVar) {
  2669. std::string langSuff = suffixVar + std::string("_") + ll;
  2670. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2671. }
  2672. if (!targetPrefix && prefixVar && *prefixVar) {
  2673. std::string langPrefix = prefixVar + std::string("_") + ll;
  2674. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2675. }
  2676. }
  2677. // if there is no prefix on the target use the cmake definition
  2678. if (!targetPrefix && prefixVar) {
  2679. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2680. }
  2681. // if there is no suffix on the target use the cmake definition
  2682. if (!targetSuffix && suffixVar) {
  2683. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2684. }
  2685. // frameworks have directory prefix but no suffix
  2686. std::string fw_prefix;
  2687. if (this->IsFrameworkOnApple()) {
  2688. fw_prefix = this->GetOutputName(config, false);
  2689. fw_prefix += ".framework/";
  2690. targetPrefix = fw_prefix.c_str();
  2691. targetSuffix = 0;
  2692. }
  2693. if (this->IsCFBundleOnApple()) {
  2694. fw_prefix = this->GetCFBundleDirectory(config, false);
  2695. fw_prefix += "/";
  2696. targetPrefix = fw_prefix.c_str();
  2697. targetSuffix = 0;
  2698. }
  2699. // Begin the final name with the prefix.
  2700. outPrefix = targetPrefix ? targetPrefix : "";
  2701. // Append the target name or property-specified name.
  2702. outBase += this->GetOutputName(config, implib);
  2703. // Append the per-configuration postfix.
  2704. outBase += configPostfix ? configPostfix : "";
  2705. // Name shared libraries with their version number on some platforms.
  2706. if (const char* soversion = this->GetProperty("SOVERSION")) {
  2707. if (this->GetType() == cmState::SHARED_LIBRARY && !implib &&
  2708. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")) {
  2709. outBase += "-";
  2710. outBase += soversion;
  2711. }
  2712. }
  2713. // Append the suffix.
  2714. outSuffix = targetSuffix ? targetSuffix : "";
  2715. }
  2716. std::string cmGeneratorTarget::GetLinkerLanguage(
  2717. const std::string& config) const
  2718. {
  2719. return this->GetLinkClosure(config)->LinkerLanguage;
  2720. }
  2721. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2722. {
  2723. std::string prefix;
  2724. std::string base;
  2725. std::string suffix;
  2726. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2727. std::vector<std::string> props;
  2728. std::string configUpper = cmSystemTools::UpperCase(config);
  2729. if (!configUpper.empty()) {
  2730. // PDB_NAME_<CONFIG>
  2731. props.push_back("PDB_NAME_" + configUpper);
  2732. }
  2733. // PDB_NAME
  2734. props.push_back("PDB_NAME");
  2735. for (std::vector<std::string>::const_iterator i = props.begin();
  2736. i != props.end(); ++i) {
  2737. if (const char* outName = this->GetProperty(*i)) {
  2738. base = outName;
  2739. break;
  2740. }
  2741. }
  2742. return prefix + base + ".pdb";
  2743. }
  2744. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  2745. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  2746. {
  2747. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2748. if (nameResult == 0) {
  2749. return strcmp(t1->GetLocalGenerator()->GetCurrentBinaryDirectory(),
  2750. t2->GetLocalGenerator()->GetCurrentBinaryDirectory()) < 0;
  2751. }
  2752. return nameResult < 0;
  2753. }
  2754. struct cmGeneratorTarget::SourceFileFlags
  2755. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2756. {
  2757. struct SourceFileFlags flags;
  2758. this->ConstructSourceFileFlags();
  2759. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  2760. this->SourceFlagsMap.find(sf);
  2761. if (si != this->SourceFlagsMap.end()) {
  2762. flags = si->second;
  2763. } else {
  2764. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  2765. // were not listed in one of the other lists.
  2766. if (const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  2767. flags.MacFolder = location;
  2768. if (strcmp(location, "Resources") == 0) {
  2769. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2770. } else {
  2771. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  2772. }
  2773. }
  2774. }
  2775. return flags;
  2776. }
  2777. void cmGeneratorTarget::ConstructSourceFileFlags() const
  2778. {
  2779. if (this->SourceFileFlagsConstructed) {
  2780. return;
  2781. }
  2782. this->SourceFileFlagsConstructed = true;
  2783. // Process public headers to mark the source files.
  2784. if (const char* files = this->GetProperty("PUBLIC_HEADER")) {
  2785. std::vector<std::string> relFiles;
  2786. cmSystemTools::ExpandListArgument(files, relFiles);
  2787. for (std::vector<std::string>::iterator it = relFiles.begin();
  2788. it != relFiles.end(); ++it) {
  2789. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  2790. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2791. flags.MacFolder = "Headers";
  2792. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  2793. }
  2794. }
  2795. }
  2796. // Process private headers after public headers so that they take
  2797. // precedence if a file is listed in both.
  2798. if (const char* files = this->GetProperty("PRIVATE_HEADER")) {
  2799. std::vector<std::string> relFiles;
  2800. cmSystemTools::ExpandListArgument(files, relFiles);
  2801. for (std::vector<std::string>::iterator it = relFiles.begin();
  2802. it != relFiles.end(); ++it) {
  2803. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  2804. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2805. flags.MacFolder = "PrivateHeaders";
  2806. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  2807. }
  2808. }
  2809. }
  2810. // Mark sources listed as resources.
  2811. if (const char* files = this->GetProperty("RESOURCE")) {
  2812. std::vector<std::string> relFiles;
  2813. cmSystemTools::ExpandListArgument(files, relFiles);
  2814. for (std::vector<std::string>::iterator it = relFiles.begin();
  2815. it != relFiles.end(); ++it) {
  2816. if (cmSourceFile* sf = this->Makefile->GetSource(*it)) {
  2817. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2818. flags.MacFolder = "";
  2819. if (!this->Makefile->PlatformIsAppleIos()) {
  2820. flags.MacFolder = "Resources";
  2821. }
  2822. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2823. }
  2824. }
  2825. }
  2826. }
  2827. const cmGeneratorTarget::CompatibleInterfacesBase&
  2828. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  2829. {
  2830. cmGeneratorTarget::CompatibleInterfaces& compat =
  2831. this->CompatibleInterfacesMap[config];
  2832. if (!compat.Done) {
  2833. compat.Done = true;
  2834. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  2835. compat.PropsString.insert("AUTOUIC_OPTIONS");
  2836. std::vector<cmGeneratorTarget const*> const& deps =
  2837. this->GetLinkImplementationClosure(config);
  2838. for (std::vector<cmGeneratorTarget const*>::const_iterator li =
  2839. deps.begin();
  2840. li != deps.end(); ++li) {
  2841. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  2842. if (const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  2843. std::vector<std::string> props; \
  2844. cmSystemTools::ExpandListArgument(prop, props); \
  2845. compat.Props##x.insert(props.begin(), props.end()); \
  2846. }
  2847. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  2848. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  2849. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  2850. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  2851. #undef CM_READ_COMPATIBLE_INTERFACE
  2852. }
  2853. }
  2854. return compat;
  2855. }
  2856. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  2857. const std::string& p, const std::string& config) const
  2858. {
  2859. if (this->GetType() == cmState::OBJECT_LIBRARY ||
  2860. this->GetType() == cmState::INTERFACE_LIBRARY) {
  2861. return false;
  2862. }
  2863. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  2864. }
  2865. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  2866. const std::string& p, const std::string& config) const
  2867. {
  2868. if (this->GetType() == cmState::OBJECT_LIBRARY ||
  2869. this->GetType() == cmState::INTERFACE_LIBRARY) {
  2870. return false;
  2871. }
  2872. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  2873. }
  2874. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  2875. const std::string& p, const std::string& config) const
  2876. {
  2877. if (this->GetType() == cmState::OBJECT_LIBRARY ||
  2878. this->GetType() == cmState::INTERFACE_LIBRARY) {
  2879. return false;
  2880. }
  2881. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  2882. }
  2883. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  2884. const std::string& p, const std::string& config) const
  2885. {
  2886. if (this->GetType() == cmState::OBJECT_LIBRARY ||
  2887. this->GetType() == cmState::INTERFACE_LIBRARY) {
  2888. return false;
  2889. }
  2890. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  2891. }
  2892. enum CompatibleType
  2893. {
  2894. BoolType,
  2895. StringType,
  2896. NumberMinType,
  2897. NumberMaxType
  2898. };
  2899. template <typename PropertyType>
  2900. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2901. const std::string& prop,
  2902. const std::string& config,
  2903. CompatibleType, PropertyType*);
  2904. template <>
  2905. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2906. const std::string& prop,
  2907. const std::string& config,
  2908. CompatibleType, bool*)
  2909. {
  2910. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  2911. }
  2912. template <>
  2913. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2914. const std::string& prop,
  2915. const std::string& config,
  2916. CompatibleType t, const char**)
  2917. {
  2918. switch (t) {
  2919. case BoolType:
  2920. assert(0 && "String compatibility check function called for boolean");
  2921. return 0;
  2922. case StringType:
  2923. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  2924. case NumberMinType:
  2925. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  2926. case NumberMaxType:
  2927. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  2928. }
  2929. assert(0 && "Unreachable!");
  2930. return 0;
  2931. }
  2932. template <typename PropertyType>
  2933. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  2934. cmGeneratorTarget const* dependee,
  2935. const std::string& propName,
  2936. std::set<std::string>& emitted,
  2937. const std::string& config, CompatibleType t,
  2938. PropertyType*)
  2939. {
  2940. const char* prop = dependee->GetProperty(propName);
  2941. if (!prop) {
  2942. return;
  2943. }
  2944. std::vector<std::string> props;
  2945. cmSystemTools::ExpandListArgument(prop, props);
  2946. std::string pdir = cmSystemTools::GetCMakeRoot();
  2947. pdir += "/Help/prop_tgt/";
  2948. for (std::vector<std::string>::iterator pi = props.begin();
  2949. pi != props.end(); ++pi) {
  2950. std::string pname = cmSystemTools::HelpFileName(*pi);
  2951. std::string pfile = pdir + pname + ".rst";
  2952. if (cmSystemTools::FileExists(pfile.c_str(), true)) {
  2953. std::ostringstream e;
  2954. e << "Target \"" << dependee->GetName() << "\" has property \"" << *pi
  2955. << "\" listed in its " << propName
  2956. << " property. "
  2957. "This is not allowed. Only user-defined properties may appear "
  2958. "listed in the "
  2959. << propName << " property.";
  2960. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  2961. return;
  2962. }
  2963. if (emitted.insert(*pi).second) {
  2964. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config, t,
  2965. 0);
  2966. if (cmSystemTools::GetErrorOccuredFlag()) {
  2967. return;
  2968. }
  2969. }
  2970. }
  2971. }
  2972. static std::string intersect(const std::set<std::string>& s1,
  2973. const std::set<std::string>& s2)
  2974. {
  2975. std::set<std::string> intersect;
  2976. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  2977. std::inserter(intersect, intersect.begin()));
  2978. if (!intersect.empty()) {
  2979. return *intersect.begin();
  2980. }
  2981. return "";
  2982. }
  2983. static std::string intersect(const std::set<std::string>& s1,
  2984. const std::set<std::string>& s2,
  2985. const std::set<std::string>& s3)
  2986. {
  2987. std::string result;
  2988. result = intersect(s1, s2);
  2989. if (!result.empty()) {
  2990. return result;
  2991. }
  2992. result = intersect(s1, s3);
  2993. if (!result.empty()) {
  2994. return result;
  2995. }
  2996. return intersect(s2, s3);
  2997. }
  2998. static std::string intersect(const std::set<std::string>& s1,
  2999. const std::set<std::string>& s2,
  3000. const std::set<std::string>& s3,
  3001. const std::set<std::string>& s4)
  3002. {
  3003. std::string result;
  3004. result = intersect(s1, s2);
  3005. if (!result.empty()) {
  3006. return result;
  3007. }
  3008. result = intersect(s1, s3);
  3009. if (!result.empty()) {
  3010. return result;
  3011. }
  3012. result = intersect(s1, s4);
  3013. if (!result.empty()) {
  3014. return result;
  3015. }
  3016. return intersect(s2, s3, s4);
  3017. }
  3018. void cmGeneratorTarget::CheckPropertyCompatibility(
  3019. cmComputeLinkInformation* info, const std::string& config) const
  3020. {
  3021. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  3022. std::set<std::string> emittedBools;
  3023. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3024. std::set<std::string> emittedStrings;
  3025. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3026. std::set<std::string> emittedMinNumbers;
  3027. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3028. std::set<std::string> emittedMaxNumbers;
  3029. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3030. for (cmComputeLinkInformation::ItemVector::const_iterator li = deps.begin();
  3031. li != deps.end(); ++li) {
  3032. if (!li->Target) {
  3033. continue;
  3034. }
  3035. checkPropertyConsistency<bool>(this, li->Target, strBool, emittedBools,
  3036. config, BoolType, 0);
  3037. if (cmSystemTools::GetErrorOccuredFlag()) {
  3038. return;
  3039. }
  3040. checkPropertyConsistency<const char*>(
  3041. this, li->Target, strString, emittedStrings, config, StringType, 0);
  3042. if (cmSystemTools::GetErrorOccuredFlag()) {
  3043. return;
  3044. }
  3045. checkPropertyConsistency<const char*>(this, li->Target, strNumMin,
  3046. emittedMinNumbers, config,
  3047. NumberMinType, 0);
  3048. if (cmSystemTools::GetErrorOccuredFlag()) {
  3049. return;
  3050. }
  3051. checkPropertyConsistency<const char*>(this, li->Target, strNumMax,
  3052. emittedMaxNumbers, config,
  3053. NumberMaxType, 0);
  3054. if (cmSystemTools::GetErrorOccuredFlag()) {
  3055. return;
  3056. }
  3057. }
  3058. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  3059. emittedMaxNumbers);
  3060. if (!prop.empty()) {
  3061. // Use a sorted std::vector to keep the error message sorted.
  3062. std::vector<std::string> props;
  3063. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3064. if (i != emittedBools.end()) {
  3065. props.push_back(strBool);
  3066. }
  3067. i = emittedStrings.find(prop);
  3068. if (i != emittedStrings.end()) {
  3069. props.push_back(strString);
  3070. }
  3071. i = emittedMinNumbers.find(prop);
  3072. if (i != emittedMinNumbers.end()) {
  3073. props.push_back(strNumMin);
  3074. }
  3075. i = emittedMaxNumbers.find(prop);
  3076. if (i != emittedMaxNumbers.end()) {
  3077. props.push_back(strNumMax);
  3078. }
  3079. std::sort(props.begin(), props.end());
  3080. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3081. propsString += " and the " + props.back();
  3082. std::ostringstream e;
  3083. e << "Property \"" << prop << "\" appears in both the " << propsString
  3084. << " property in the dependencies of target \"" << this->GetName()
  3085. << "\". This is not allowed. A property may only require compatibility "
  3086. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  3087. "or a "
  3088. "string interpretation, but not a mixture.";
  3089. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3090. }
  3091. }
  3092. std::string compatibilityType(CompatibleType t)
  3093. {
  3094. switch (t) {
  3095. case BoolType:
  3096. return "Boolean compatibility";
  3097. case StringType:
  3098. return "String compatibility";
  3099. case NumberMaxType:
  3100. return "Numeric maximum compatibility";
  3101. case NumberMinType:
  3102. return "Numeric minimum compatibility";
  3103. }
  3104. assert(0 && "Unreachable!");
  3105. return "";
  3106. }
  3107. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3108. {
  3109. switch (t) {
  3110. case BoolType:
  3111. case StringType:
  3112. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3113. case NumberMaxType:
  3114. case NumberMinType:
  3115. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3116. }
  3117. assert(0 && "Unreachable!");
  3118. return "";
  3119. }
  3120. template <typename PropertyType>
  3121. PropertyType getTypedProperty(cmGeneratorTarget const* tgt,
  3122. const std::string& prop);
  3123. template <>
  3124. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  3125. const std::string& prop)
  3126. {
  3127. return tgt->GetPropertyAsBool(prop);
  3128. }
  3129. template <>
  3130. const char* getTypedProperty<const char*>(cmGeneratorTarget const* tgt,
  3131. const std::string& prop)
  3132. {
  3133. return tgt->GetProperty(prop);
  3134. }
  3135. template <typename PropertyType>
  3136. std::string valueAsString(PropertyType);
  3137. template <>
  3138. std::string valueAsString<bool>(bool value)
  3139. {
  3140. return value ? "TRUE" : "FALSE";
  3141. }
  3142. template <>
  3143. std::string valueAsString<const char*>(const char* value)
  3144. {
  3145. return value ? value : "(unset)";
  3146. }
  3147. template <typename PropertyType>
  3148. PropertyType impliedValue(PropertyType);
  3149. template <>
  3150. bool impliedValue<bool>(bool)
  3151. {
  3152. return false;
  3153. }
  3154. template <>
  3155. const char* impliedValue<const char*>(const char*)
  3156. {
  3157. return "";
  3158. }
  3159. template <typename PropertyType>
  3160. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3161. PropertyType rhs,
  3162. CompatibleType t);
  3163. template <>
  3164. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  3165. {
  3166. return std::make_pair(lhs == rhs, lhs);
  3167. }
  3168. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  3169. const char* rhs)
  3170. {
  3171. const bool b = strcmp(lhs, rhs) == 0;
  3172. return std::make_pair(b, b ? lhs : 0);
  3173. }
  3174. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  3175. const char* rhs,
  3176. CompatibleType t)
  3177. {
  3178. char* pEnd;
  3179. const char* const null_ptr = 0;
  3180. long lnum = strtol(lhs, &pEnd, 0);
  3181. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  3182. return std::pair<bool, const char*>(false, null_ptr);
  3183. }
  3184. long rnum = strtol(rhs, &pEnd, 0);
  3185. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  3186. return std::pair<bool, const char*>(false, null_ptr);
  3187. }
  3188. if (t == NumberMaxType) {
  3189. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3190. } else {
  3191. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3192. }
  3193. }
  3194. template <>
  3195. std::pair<bool, const char*> consistentProperty(const char* lhs,
  3196. const char* rhs,
  3197. CompatibleType t)
  3198. {
  3199. if (!lhs && !rhs) {
  3200. return std::make_pair(true, lhs);
  3201. }
  3202. if (!lhs) {
  3203. return std::make_pair(true, rhs);
  3204. }
  3205. if (!rhs) {
  3206. return std::make_pair(true, lhs);
  3207. }
  3208. const char* const null_ptr = 0;
  3209. switch (t) {
  3210. case BoolType:
  3211. assert(0 && "consistentProperty for strings called with BoolType");
  3212. return std::pair<bool, const char*>(false, null_ptr);
  3213. case StringType:
  3214. return consistentStringProperty(lhs, rhs);
  3215. case NumberMinType:
  3216. case NumberMaxType:
  3217. return consistentNumberProperty(lhs, rhs, t);
  3218. }
  3219. assert(0 && "Unreachable!");
  3220. return std::pair<bool, const char*>(false, null_ptr);
  3221. }
  3222. template <typename PropertyType>
  3223. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3224. const std::string& p,
  3225. const std::string& config,
  3226. const char* defaultValue,
  3227. CompatibleType t,
  3228. PropertyType*)
  3229. {
  3230. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  3231. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  3232. const bool explicitlySet =
  3233. std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
  3234. headPropKeys.end();
  3235. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  3236. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  3237. std::vector<cmGeneratorTarget const*> const& deps =
  3238. tgt->GetLinkImplementationClosure(config);
  3239. if (deps.empty()) {
  3240. return propContent;
  3241. }
  3242. bool propInitialized = explicitlySet;
  3243. std::string report = " * Target \"";
  3244. report += tgt->GetName();
  3245. if (explicitlySet) {
  3246. report += "\" has property content \"";
  3247. report += valueAsString<PropertyType>(propContent);
  3248. report += "\"\n";
  3249. } else if (impliedByUse) {
  3250. report += "\" property is implied by use.\n";
  3251. } else {
  3252. report += "\" property not set.\n";
  3253. }
  3254. std::string interfaceProperty = "INTERFACE_" + p;
  3255. for (std::vector<cmGeneratorTarget const*>::const_iterator li = deps.begin();
  3256. li != deps.end(); ++li) {
  3257. // An error should be reported if one dependency
  3258. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3259. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3260. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3261. // with a dependency.
  3262. cmGeneratorTarget const* theTarget = *li;
  3263. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  3264. const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
  3265. interfaceProperty) != propKeys.end();
  3266. PropertyType ifacePropContent =
  3267. getTypedProperty<PropertyType>(theTarget, interfaceProperty);
  3268. std::string reportEntry;
  3269. if (ifaceIsSet) {
  3270. reportEntry += " * Target \"";
  3271. reportEntry += theTarget->GetName();
  3272. reportEntry += "\" property value \"";
  3273. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3274. reportEntry += "\" ";
  3275. }
  3276. if (explicitlySet) {
  3277. if (ifaceIsSet) {
  3278. std::pair<bool, PropertyType> consistent =
  3279. consistentProperty(propContent, ifacePropContent, t);
  3280. report += reportEntry;
  3281. report += compatibilityAgree(t, propContent != consistent.second);
  3282. if (!consistent.first) {
  3283. std::ostringstream e;
  3284. e << "Property " << p << " on target \"" << tgt->GetName()
  3285. << "\" does\nnot match the "
  3286. "INTERFACE_"
  3287. << p << " property requirement\nof "
  3288. "dependency \""
  3289. << theTarget->GetName() << "\".\n";
  3290. cmSystemTools::Error(e.str().c_str());
  3291. break;
  3292. } else {
  3293. propContent = consistent.second;
  3294. continue;
  3295. }
  3296. } else {
  3297. // Explicitly set on target and not set in iface. Can't disagree.
  3298. continue;
  3299. }
  3300. } else if (impliedByUse) {
  3301. propContent = impliedValue<PropertyType>(propContent);
  3302. if (ifaceIsSet) {
  3303. std::pair<bool, PropertyType> consistent =
  3304. consistentProperty(propContent, ifacePropContent, t);
  3305. report += reportEntry;
  3306. report += compatibilityAgree(t, propContent != consistent.second);
  3307. if (!consistent.first) {
  3308. std::ostringstream e;
  3309. e << "Property " << p << " on target \"" << tgt->GetName()
  3310. << "\" is\nimplied to be " << defaultValue
  3311. << " because it was used to determine the link libraries\n"
  3312. "already. The INTERFACE_"
  3313. << p << " property on\ndependency \"" << theTarget->GetName()
  3314. << "\" is in conflict.\n";
  3315. cmSystemTools::Error(e.str().c_str());
  3316. break;
  3317. } else {
  3318. propContent = consistent.second;
  3319. continue;
  3320. }
  3321. } else {
  3322. // Implicitly set on target and not set in iface. Can't disagree.
  3323. continue;
  3324. }
  3325. } else {
  3326. if (ifaceIsSet) {
  3327. if (propInitialized) {
  3328. std::pair<bool, PropertyType> consistent =
  3329. consistentProperty(propContent, ifacePropContent, t);
  3330. report += reportEntry;
  3331. report += compatibilityAgree(t, propContent != consistent.second);
  3332. if (!consistent.first) {
  3333. std::ostringstream e;
  3334. e << "The INTERFACE_" << p << " property of \""
  3335. << theTarget->GetName() << "\" does\nnot agree with the value "
  3336. "of "
  3337. << p << " already determined\nfor \"" << tgt->GetName()
  3338. << "\".\n";
  3339. cmSystemTools::Error(e.str().c_str());
  3340. break;
  3341. } else {
  3342. propContent = consistent.second;
  3343. continue;
  3344. }
  3345. } else {
  3346. report += reportEntry + "(Interface set)\n";
  3347. propContent = ifacePropContent;
  3348. propInitialized = true;
  3349. }
  3350. } else {
  3351. // Not set. Nothing to agree on.
  3352. continue;
  3353. }
  3354. }
  3355. }
  3356. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  3357. report, compatibilityType(t));
  3358. return propContent;
  3359. }
  3360. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  3361. const std::string& p, const std::string& config) const
  3362. {
  3363. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  3364. BoolType, 0);
  3365. }
  3366. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  3367. const std::string& p, const std::string& config) const
  3368. {
  3369. return checkInterfacePropertyCompatibility<const char*>(
  3370. this, p, config, "empty", StringType, 0);
  3371. }
  3372. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  3373. const std::string& p, const std::string& config) const
  3374. {
  3375. return checkInterfacePropertyCompatibility<const char*>(
  3376. this, p, config, "empty", NumberMinType, 0);
  3377. }
  3378. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3379. const std::string& p, const std::string& config) const
  3380. {
  3381. return checkInterfacePropertyCompatibility<const char*>(
  3382. this, p, config, "empty", NumberMaxType, 0);
  3383. }
  3384. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  3385. const std::string& config) const
  3386. {
  3387. // Lookup any existing information for this configuration.
  3388. std::string key(cmSystemTools::UpperCase(config));
  3389. cmTargetLinkInformationMap::iterator i = this->LinkInformation.find(key);
  3390. if (i == this->LinkInformation.end()) {
  3391. // Compute information for this configuration.
  3392. cmComputeLinkInformation* info =
  3393. new cmComputeLinkInformation(this, config);
  3394. if (!info || !info->Compute()) {
  3395. delete info;
  3396. info = 0;
  3397. }
  3398. // Store the information for this configuration.
  3399. cmTargetLinkInformationMap::value_type entry(key, info);
  3400. i = this->LinkInformation.insert(entry).first;
  3401. if (info) {
  3402. this->CheckPropertyCompatibility(info, config);
  3403. }
  3404. }
  3405. return i->second;
  3406. }
  3407. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  3408. {
  3409. int patch;
  3410. this->GetTargetVersion(false, major, minor, patch);
  3411. }
  3412. void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
  3413. int& minor, int& patch) const
  3414. {
  3415. // Set the default values.
  3416. major = 0;
  3417. minor = 0;
  3418. patch = 0;
  3419. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  3420. // Look for a VERSION or SOVERSION property.
  3421. const char* prop = soversion ? "SOVERSION" : "VERSION";
  3422. if (const char* version = this->GetProperty(prop)) {
  3423. // Try to parse the version number and store the results that were
  3424. // successfully parsed.
  3425. int parsed_major;
  3426. int parsed_minor;
  3427. int parsed_patch;
  3428. switch (sscanf(version, "%d.%d.%d", &parsed_major, &parsed_minor,
  3429. &parsed_patch)) {
  3430. case 3:
  3431. patch = parsed_patch; // no break!
  3432. case 2:
  3433. minor = parsed_minor; // no break!
  3434. case 1:
  3435. major = parsed_major; // no break!
  3436. default:
  3437. break;
  3438. }
  3439. }
  3440. }
  3441. std::string cmGeneratorTarget::GetFortranModuleDirectory() const
  3442. {
  3443. if (!this->FortranModuleDirectoryCreated) {
  3444. this->FortranModuleDirectory = true;
  3445. this->FortranModuleDirectory = this->CreateFortranModuleDirectory();
  3446. }
  3447. return this->FortranModuleDirectory;
  3448. }
  3449. std::string cmGeneratorTarget::CreateFortranModuleDirectory() const
  3450. {
  3451. static std::string mod_dir;
  3452. const char* target_mod_dir = this->GetProperty("Fortran_MODULE_DIRECTORY");
  3453. const char* moddir_flag =
  3454. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  3455. if (target_mod_dir && moddir_flag) {
  3456. // Compute the full path to the module directory.
  3457. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  3458. // Already a full path.
  3459. mod_dir = target_mod_dir;
  3460. } else {
  3461. // Interpret relative to the current output directory.
  3462. mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  3463. mod_dir += "/";
  3464. mod_dir += target_mod_dir;
  3465. }
  3466. // Make sure the module output directory exists.
  3467. cmSystemTools::MakeDirectory(mod_dir);
  3468. }
  3469. return mod_dir;
  3470. }
  3471. std::string cmGeneratorTarget::GetFrameworkVersion() const
  3472. {
  3473. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  3474. if (const char* fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  3475. return fversion;
  3476. } else if (const char* tversion = this->GetProperty("VERSION")) {
  3477. return tversion;
  3478. } else {
  3479. return "A";
  3480. }
  3481. }
  3482. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  3483. std::string const& prefix,
  3484. std::string const& base,
  3485. std::string const& suffix,
  3486. std::string const& name,
  3487. const char* version) const
  3488. {
  3489. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  3490. if (version) {
  3491. vName += ".";
  3492. vName += version;
  3493. }
  3494. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  3495. }
  3496. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  3497. {
  3498. cmPropertyMap propsObject = this->Target->GetProperties();
  3499. std::vector<std::string> props;
  3500. props.reserve(propsObject.size());
  3501. for (cmPropertyMap::const_iterator it = propsObject.begin();
  3502. it != propsObject.end(); ++it) {
  3503. props.push_back(it->first);
  3504. }
  3505. return props;
  3506. }
  3507. void cmGeneratorTarget::ReportPropertyOrigin(
  3508. const std::string& p, const std::string& result, const std::string& report,
  3509. const std::string& compatibilityType) const
  3510. {
  3511. std::vector<std::string> debugProperties;
  3512. const char* debugProp = this->Target->GetMakefile()->GetDefinition(
  3513. "CMAKE_DEBUG_TARGET_PROPERTIES");
  3514. if (debugProp) {
  3515. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3516. }
  3517. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  3518. std::find(debugProperties.begin(), debugProperties.end(), p) !=
  3519. debugProperties.end();
  3520. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3521. this->DebugCompatiblePropertiesDone[p] = true;
  3522. }
  3523. if (!debugOrigin) {
  3524. return;
  3525. }
  3526. std::string areport = compatibilityType;
  3527. areport += std::string(" of property \"") + p + "\" for target \"";
  3528. areport += std::string(this->GetName());
  3529. areport += "\" (result: \"";
  3530. areport += result;
  3531. areport += "\"):\n" + report;
  3532. this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3533. }
  3534. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3535. std::vector<cmLinkItem>& items) const
  3536. {
  3537. for (std::vector<std::string>::const_iterator i = names.begin();
  3538. i != names.end(); ++i) {
  3539. std::string name = this->CheckCMP0004(*i);
  3540. if (name == this->GetName() || name.empty()) {
  3541. continue;
  3542. }
  3543. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  3544. }
  3545. }
  3546. void cmGeneratorTarget::ExpandLinkItems(
  3547. std::string const& prop, std::string const& value, std::string const& config,
  3548. cmGeneratorTarget const* headTarget, bool usage_requirements_only,
  3549. std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
  3550. {
  3551. cmGeneratorExpression ge;
  3552. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3553. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3554. // link dependencies that are otherwise excluded from usage requirements.
  3555. if (usage_requirements_only) {
  3556. dagChecker.SetTransitivePropertiesOnly();
  3557. }
  3558. std::vector<std::string> libs;
  3559. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3560. cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config,
  3561. false, headTarget, this,
  3562. &dagChecker),
  3563. libs);
  3564. this->LookupLinkItems(libs, items);
  3565. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3566. }
  3567. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  3568. const std::string& config, cmGeneratorTarget const* head) const
  3569. {
  3570. // Imported targets have their own link interface.
  3571. if (this->IsImported()) {
  3572. return this->GetImportLinkInterface(config, head, false);
  3573. }
  3574. // Link interfaces are not supported for executables that do not
  3575. // export symbols.
  3576. if (this->GetType() == cmState::EXECUTABLE &&
  3577. !this->IsExecutableWithExports()) {
  3578. return 0;
  3579. }
  3580. // Lookup any existing link interface for this configuration.
  3581. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  3582. // If the link interface does not depend on the head target
  3583. // then return the one we computed first.
  3584. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  3585. return &hm.begin()->second;
  3586. }
  3587. cmOptionalLinkInterface& iface = hm[head];
  3588. if (!iface.LibrariesDone) {
  3589. iface.LibrariesDone = true;
  3590. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  3591. }
  3592. if (!iface.AllDone) {
  3593. iface.AllDone = true;
  3594. if (iface.Exists) {
  3595. this->ComputeLinkInterface(config, iface, head);
  3596. }
  3597. }
  3598. return iface.Exists ? &iface : 0;
  3599. }
  3600. void cmGeneratorTarget::ComputeLinkInterface(
  3601. const std::string& config, cmOptionalLinkInterface& iface,
  3602. cmGeneratorTarget const* headTarget) const
  3603. {
  3604. if (iface.ExplicitLibraries) {
  3605. if (this->GetType() == cmState::SHARED_LIBRARY ||
  3606. this->GetType() == cmState::STATIC_LIBRARY ||
  3607. this->GetType() == cmState::INTERFACE_LIBRARY) {
  3608. // Shared libraries may have runtime implementation dependencies
  3609. // on other shared libraries that are not in the interface.
  3610. UNORDERED_SET<std::string> emitted;
  3611. for (std::vector<cmLinkItem>::const_iterator li =
  3612. iface.Libraries.begin();
  3613. li != iface.Libraries.end(); ++li) {
  3614. emitted.insert(*li);
  3615. }
  3616. if (this->GetType() != cmState::INTERFACE_LIBRARY) {
  3617. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  3618. for (std::vector<cmLinkImplItem>::const_iterator li =
  3619. impl->Libraries.begin();
  3620. li != impl->Libraries.end(); ++li) {
  3621. if (emitted.insert(*li).second) {
  3622. if (li->Target) {
  3623. // This is a runtime dependency on another shared library.
  3624. if (li->Target->GetType() == cmState::SHARED_LIBRARY) {
  3625. iface.SharedDeps.push_back(*li);
  3626. }
  3627. } else {
  3628. // TODO: Recognize shared library file names. Perhaps this
  3629. // should be moved to cmComputeLinkInformation, but that creates
  3630. // a chicken-and-egg problem since this list is needed for its
  3631. // construction.
  3632. }
  3633. }
  3634. }
  3635. }
  3636. }
  3637. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  3638. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  3639. // The link implementation is the default link interface.
  3640. cmLinkImplementationLibraries const* impl =
  3641. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  3642. iface.ImplementationIsInterface = true;
  3643. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3644. }
  3645. if (this->LinkLanguagePropagatesToDependents()) {
  3646. // Targets using this archive need its language runtime libraries.
  3647. if (cmLinkImplementation const* impl =
  3648. this->GetLinkImplementation(config)) {
  3649. iface.Languages = impl->Languages;
  3650. }
  3651. }
  3652. if (this->GetType() == cmState::STATIC_LIBRARY) {
  3653. // Construct the property name suffix for this configuration.
  3654. std::string suffix = "_";
  3655. if (!config.empty()) {
  3656. suffix += cmSystemTools::UpperCase(config);
  3657. } else {
  3658. suffix += "NOCONFIG";
  3659. }
  3660. // How many repetitions are needed if this library has cyclic
  3661. // dependencies?
  3662. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3663. propName += suffix;
  3664. if (const char* config_reps = this->GetProperty(propName)) {
  3665. sscanf(config_reps, "%u", &iface.Multiplicity);
  3666. } else if (const char* reps =
  3667. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  3668. sscanf(reps, "%u", &iface.Multiplicity);
  3669. }
  3670. }
  3671. }
  3672. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  3673. const std::string& config, cmGeneratorTarget const* head,
  3674. bool usage_requirements_only) const
  3675. {
  3676. // Imported targets have their own link interface.
  3677. if (this->IsImported()) {
  3678. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  3679. }
  3680. // Link interfaces are not supported for executables that do not
  3681. // export symbols.
  3682. if (this->GetType() == cmState::EXECUTABLE &&
  3683. !this->IsExecutableWithExports()) {
  3684. return 0;
  3685. }
  3686. // Lookup any existing link interface for this configuration.
  3687. std::string CONFIG = cmSystemTools::UpperCase(config);
  3688. cmHeadToLinkInterfaceMap& hm =
  3689. (usage_requirements_only
  3690. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  3691. : this->GetHeadToLinkInterfaceMap(config));
  3692. // If the link interface does not depend on the head target
  3693. // then return the one we computed first.
  3694. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  3695. return &hm.begin()->second;
  3696. }
  3697. cmOptionalLinkInterface& iface = hm[head];
  3698. if (!iface.LibrariesDone) {
  3699. iface.LibrariesDone = true;
  3700. this->ComputeLinkInterfaceLibraries(config, iface, head,
  3701. usage_requirements_only);
  3702. }
  3703. return iface.Exists ? &iface : 0;
  3704. }
  3705. std::string cmGeneratorTarget::GetDirectory(const std::string& config,
  3706. bool implib) const
  3707. {
  3708. if (this->IsImported()) {
  3709. // Return the directory from which the target is imported.
  3710. return cmSystemTools::GetFilenamePath(
  3711. this->Target->ImportedGetFullPath(config, implib));
  3712. } else if (OutputInfo const* info = this->GetOutputInfo(config)) {
  3713. // Return the directory in which the target will be built.
  3714. return implib ? info->ImpDir : info->OutDir;
  3715. }
  3716. return "";
  3717. }
  3718. bool cmGeneratorTarget::UsesDefaultOutputDir(const std::string& config,
  3719. bool implib) const
  3720. {
  3721. std::string dir;
  3722. return this->ComputeOutputDir(config, implib, dir);
  3723. }
  3724. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  3725. const std::string& config) const
  3726. {
  3727. // There is no output information for imported targets.
  3728. if (this->IsImported()) {
  3729. return 0;
  3730. }
  3731. // Only libraries and executables have well-defined output files.
  3732. if (!this->HaveWellDefinedOutputFiles()) {
  3733. std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
  3734. msg += this->GetName();
  3735. msg += " which has type ";
  3736. msg += cmState::GetTargetTypeName(this->GetType());
  3737. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  3738. return 0;
  3739. }
  3740. // Lookup/compute/cache the output information for this configuration.
  3741. std::string config_upper;
  3742. if (!config.empty()) {
  3743. config_upper = cmSystemTools::UpperCase(config);
  3744. }
  3745. OutputInfoMapType::iterator i = this->OutputInfoMap.find(config_upper);
  3746. if (i == this->OutputInfoMap.end()) {
  3747. // Add empty info in map to detect potential recursion.
  3748. OutputInfo info;
  3749. OutputInfoMapType::value_type entry(config_upper, info);
  3750. i = this->OutputInfoMap.insert(entry).first;
  3751. // Compute output directories.
  3752. this->ComputeOutputDir(config, false, info.OutDir);
  3753. this->ComputeOutputDir(config, true, info.ImpDir);
  3754. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  3755. info.PdbDir = info.OutDir;
  3756. }
  3757. // Now update the previously-prepared map entry.
  3758. i->second = info;
  3759. } else if (i->second.empty()) {
  3760. // An empty map entry indicates we have been called recursively
  3761. // from the above block.
  3762. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  3763. cmake::FATAL_ERROR,
  3764. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  3765. this->GetBacktrace());
  3766. return 0;
  3767. }
  3768. return &i->second;
  3769. }
  3770. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  3771. bool implib, std::string& out) const
  3772. {
  3773. bool usesDefaultOutputDir = false;
  3774. std::string conf = config;
  3775. // Look for a target property defining the target output directory
  3776. // based on the target type.
  3777. std::string targetTypeName = this->GetOutputTargetType(implib);
  3778. const char* propertyName = 0;
  3779. std::string propertyNameStr = targetTypeName;
  3780. if (!propertyNameStr.empty()) {
  3781. propertyNameStr += "_OUTPUT_DIRECTORY";
  3782. propertyName = propertyNameStr.c_str();
  3783. }
  3784. // Check for a per-configuration output directory target property.
  3785. std::string configUpper = cmSystemTools::UpperCase(conf);
  3786. const char* configProp = 0;
  3787. std::string configPropStr = targetTypeName;
  3788. if (!configPropStr.empty()) {
  3789. configPropStr += "_OUTPUT_DIRECTORY_";
  3790. configPropStr += configUpper;
  3791. configProp = configPropStr.c_str();
  3792. }
  3793. // Select an output directory.
  3794. if (const char* config_outdir = this->GetProperty(configProp)) {
  3795. // Use the user-specified per-configuration output directory.
  3796. cmGeneratorExpression ge;
  3797. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  3798. ge.Parse(config_outdir);
  3799. out = cge->Evaluate(this->LocalGenerator, config);
  3800. // Skip per-configuration subdirectory.
  3801. conf = "";
  3802. } else if (const char* outdir = this->GetProperty(propertyName)) {
  3803. // Use the user-specified output directory.
  3804. cmGeneratorExpression ge;
  3805. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  3806. out = cge->Evaluate(this->LocalGenerator, config);
  3807. // Skip per-configuration subdirectory if the value contained a
  3808. // generator expression.
  3809. if (out != outdir) {
  3810. conf = "";
  3811. }
  3812. } else if (this->GetType() == cmState::EXECUTABLE) {
  3813. // Lookup the output path for executables.
  3814. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3815. } else if (this->GetType() == cmState::STATIC_LIBRARY ||
  3816. this->GetType() == cmState::SHARED_LIBRARY ||
  3817. this->GetType() == cmState::MODULE_LIBRARY) {
  3818. // Lookup the output path for libraries.
  3819. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3820. }
  3821. if (out.empty()) {
  3822. // Default to the current output directory.
  3823. usesDefaultOutputDir = true;
  3824. out = ".";
  3825. }
  3826. // Convert the output path to a full path in case it is
  3827. // specified as a relative path. Treat a relative path as
  3828. // relative to the current output directory for this makefile.
  3829. out = (cmSystemTools::CollapseFullPath(
  3830. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  3831. // The generator may add the configuration's subdirectory.
  3832. if (!conf.empty()) {
  3833. bool iosPlatform = this->Makefile->PlatformIsAppleIos();
  3834. std::string suffix =
  3835. usesDefaultOutputDir && iosPlatform ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  3836. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  3837. "/", conf, suffix, out);
  3838. }
  3839. return usesDefaultOutputDir;
  3840. }
  3841. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  3842. const std::string& config,
  3843. std::string& out) const
  3844. {
  3845. // Look for a target property defining the target output directory
  3846. // based on the target type.
  3847. const char* propertyName = 0;
  3848. std::string propertyNameStr = kind;
  3849. if (!propertyNameStr.empty()) {
  3850. propertyNameStr += "_OUTPUT_DIRECTORY";
  3851. propertyName = propertyNameStr.c_str();
  3852. }
  3853. std::string conf = config;
  3854. // Check for a per-configuration output directory target property.
  3855. std::string configUpper = cmSystemTools::UpperCase(conf);
  3856. const char* configProp = 0;
  3857. std::string configPropStr = kind;
  3858. if (!configPropStr.empty()) {
  3859. configPropStr += "_OUTPUT_DIRECTORY_";
  3860. configPropStr += configUpper;
  3861. configProp = configPropStr.c_str();
  3862. }
  3863. // Select an output directory.
  3864. if (const char* config_outdir = this->GetProperty(configProp)) {
  3865. // Use the user-specified per-configuration output directory.
  3866. out = config_outdir;
  3867. // Skip per-configuration subdirectory.
  3868. conf = "";
  3869. } else if (const char* outdir = this->GetProperty(propertyName)) {
  3870. // Use the user-specified output directory.
  3871. out = outdir;
  3872. }
  3873. if (out.empty()) {
  3874. return false;
  3875. }
  3876. // Convert the output path to a full path in case it is
  3877. // specified as a relative path. Treat a relative path as
  3878. // relative to the current output directory for this makefile.
  3879. out = (cmSystemTools::CollapseFullPath(
  3880. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  3881. // The generator may add the configuration's subdirectory.
  3882. if (!conf.empty()) {
  3883. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  3884. "/", conf, "", out);
  3885. }
  3886. return true;
  3887. }
  3888. bool cmGeneratorTarget::HaveInstallTreeRPATH() const
  3889. {
  3890. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3891. return (install_rpath && *install_rpath) &&
  3892. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3893. }
  3894. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  3895. const std::string& config, cmOptionalLinkInterface& iface,
  3896. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  3897. {
  3898. // Construct the property name suffix for this configuration.
  3899. std::string suffix = "_";
  3900. if (!config.empty()) {
  3901. suffix += cmSystemTools::UpperCase(config);
  3902. } else {
  3903. suffix += "NOCONFIG";
  3904. }
  3905. // An explicit list of interface libraries may be set for shared
  3906. // libraries and executables that export symbols.
  3907. const char* explicitLibraries = 0;
  3908. std::string linkIfaceProp;
  3909. if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  3910. this->GetPolicyStatusCMP0022() != cmPolicies::WARN) {
  3911. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  3912. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  3913. explicitLibraries = this->GetProperty(linkIfaceProp);
  3914. } else if (this->GetType() == cmState::SHARED_LIBRARY ||
  3915. this->IsExecutableWithExports()) {
  3916. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  3917. // shared lib or executable.
  3918. // Lookup the per-configuration property.
  3919. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3920. linkIfaceProp += suffix;
  3921. explicitLibraries = this->GetProperty(linkIfaceProp);
  3922. // If not set, try the generic property.
  3923. if (!explicitLibraries) {
  3924. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3925. explicitLibraries = this->GetProperty(linkIfaceProp);
  3926. }
  3927. }
  3928. if (explicitLibraries &&
  3929. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3930. !this->PolicyWarnedCMP0022) {
  3931. // Compare the explicitly set old link interface properties to the
  3932. // preferred new link interface property one and warn if different.
  3933. const char* newExplicitLibraries =
  3934. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  3935. if (newExplicitLibraries &&
  3936. strcmp(newExplicitLibraries, explicitLibraries) != 0) {
  3937. std::ostringstream w;
  3938. /* clang-format off */
  3939. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3940. "Target \"" << this->GetName() << "\" has an "
  3941. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  3942. linkIfaceProp << " properties."
  3943. "\n"
  3944. "INTERFACE_LINK_LIBRARIES:\n"
  3945. " " << newExplicitLibraries << "\n" <<
  3946. linkIfaceProp << ":\n"
  3947. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  3948. /* clang-format on */
  3949. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3950. this->PolicyWarnedCMP0022 = true;
  3951. }
  3952. }
  3953. // There is no implicit link interface for executables or modules
  3954. // so if none was explicitly set then there is no link interface.
  3955. if (!explicitLibraries && (this->GetType() == cmState::EXECUTABLE ||
  3956. (this->GetType() == cmState::MODULE_LIBRARY))) {
  3957. return;
  3958. }
  3959. iface.Exists = true;
  3960. iface.ExplicitLibraries = explicitLibraries;
  3961. if (explicitLibraries) {
  3962. // The interface libraries have been explicitly set.
  3963. this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget,
  3964. usage_requirements_only, iface.Libraries,
  3965. iface.HadHeadSensitiveCondition);
  3966. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  3967. this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3968. // If CMP0022 is NEW then the plain tll signature sets the
  3969. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  3970. // cleared the property explicitly and we should not fall back
  3971. // to the link implementation.
  3972. {
  3973. // The link implementation is the default link interface.
  3974. cmLinkImplementationLibraries const* impl =
  3975. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  3976. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  3977. impl->Libraries.end());
  3978. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3979. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  3980. // Compare the link implementation fallback link interface to the
  3981. // preferred new link interface property and warn if different.
  3982. std::vector<cmLinkItem> ifaceLibs;
  3983. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  3984. if (const char* newExplicitLibraries = this->GetProperty(newProp)) {
  3985. bool hadHeadSensitiveConditionDummy = false;
  3986. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  3987. headTarget, usage_requirements_only, ifaceLibs,
  3988. hadHeadSensitiveConditionDummy);
  3989. }
  3990. if (ifaceLibs != iface.Libraries) {
  3991. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  3992. std::string newLibraries = cmJoin(ifaceLibs, ";");
  3993. if (oldLibraries.empty()) {
  3994. oldLibraries = "(empty)";
  3995. }
  3996. if (newLibraries.empty()) {
  3997. newLibraries = "(empty)";
  3998. }
  3999. std::ostringstream w;
  4000. /* clang-format off */
  4001. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4002. "Target \"" << this->GetName() << "\" has an "
  4003. "INTERFACE_LINK_LIBRARIES property. "
  4004. "This should be preferred as the source of the link interface "
  4005. "for this library but because CMP0022 is not set CMake is "
  4006. "ignoring the property and using the link implementation "
  4007. "as the link interface instead."
  4008. "\n"
  4009. "INTERFACE_LINK_LIBRARIES:\n"
  4010. " " << newLibraries << "\n"
  4011. "Link implementation:\n"
  4012. " " << oldLibraries << "\n";
  4013. /* clang-format on */
  4014. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4015. this->PolicyWarnedCMP0022 = true;
  4016. }
  4017. }
  4018. }
  4019. }
  4020. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  4021. const std::string& config, cmGeneratorTarget const* headTarget,
  4022. bool usage_requirements_only) const
  4023. {
  4024. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  4025. if (!info) {
  4026. return 0;
  4027. }
  4028. std::string CONFIG = cmSystemTools::UpperCase(config);
  4029. cmHeadToLinkInterfaceMap& hm =
  4030. (usage_requirements_only
  4031. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4032. : this->GetHeadToLinkInterfaceMap(config));
  4033. // If the link interface does not depend on the head target
  4034. // then return the one we computed first.
  4035. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4036. return &hm.begin()->second;
  4037. }
  4038. cmOptionalLinkInterface& iface = hm[headTarget];
  4039. if (!iface.AllDone) {
  4040. iface.AllDone = true;
  4041. iface.Multiplicity = info->Multiplicity;
  4042. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4043. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  4044. headTarget, usage_requirements_only, iface.Libraries,
  4045. iface.HadHeadSensitiveCondition);
  4046. std::vector<std::string> deps;
  4047. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4048. this->LookupLinkItems(deps, iface.SharedDeps);
  4049. }
  4050. return &iface;
  4051. }
  4052. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  4053. const std::string& config) const
  4054. {
  4055. // There is no imported information for non-imported targets.
  4056. if (!this->IsImported()) {
  4057. return 0;
  4058. }
  4059. // Lookup/compute/cache the import information for this
  4060. // configuration.
  4061. std::string config_upper;
  4062. if (!config.empty()) {
  4063. config_upper = cmSystemTools::UpperCase(config);
  4064. } else {
  4065. config_upper = "NOCONFIG";
  4066. }
  4067. ImportInfoMapType::const_iterator i = this->ImportInfoMap.find(config_upper);
  4068. if (i == this->ImportInfoMap.end()) {
  4069. ImportInfo info;
  4070. this->ComputeImportInfo(config_upper, info);
  4071. ImportInfoMapType::value_type entry(config_upper, info);
  4072. i = this->ImportInfoMap.insert(entry).first;
  4073. }
  4074. if (this->GetType() == cmState::INTERFACE_LIBRARY) {
  4075. return &i->second;
  4076. }
  4077. // If the location is empty then the target is not available for
  4078. // this configuration.
  4079. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  4080. return 0;
  4081. }
  4082. // Return the import information.
  4083. return &i->second;
  4084. }
  4085. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  4086. ImportInfo& info) const
  4087. {
  4088. // This method finds information about an imported target from its
  4089. // properties. The "IMPORTED_" namespace is reserved for properties
  4090. // defined by the project exporting the target.
  4091. // Initialize members.
  4092. info.NoSOName = false;
  4093. const char* loc = 0;
  4094. const char* imp = 0;
  4095. std::string suffix;
  4096. if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  4097. return;
  4098. }
  4099. // Get the link interface.
  4100. {
  4101. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4102. const char* propertyLibs = this->GetProperty(linkProp);
  4103. if (this->GetType() != cmState::INTERFACE_LIBRARY) {
  4104. if (!propertyLibs) {
  4105. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4106. linkProp += suffix;
  4107. propertyLibs = this->GetProperty(linkProp);
  4108. }
  4109. if (!propertyLibs) {
  4110. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4111. propertyLibs = this->GetProperty(linkProp);
  4112. }
  4113. }
  4114. if (propertyLibs) {
  4115. info.LibrariesProp = linkProp;
  4116. info.Libraries = propertyLibs;
  4117. }
  4118. }
  4119. if (this->GetType() == cmState::INTERFACE_LIBRARY) {
  4120. return;
  4121. }
  4122. // A provided configuration has been chosen. Load the
  4123. // configuration's properties.
  4124. // Get the location.
  4125. if (loc) {
  4126. info.Location = loc;
  4127. } else {
  4128. std::string impProp = "IMPORTED_LOCATION";
  4129. impProp += suffix;
  4130. if (const char* config_location = this->GetProperty(impProp)) {
  4131. info.Location = config_location;
  4132. } else if (const char* location = this->GetProperty("IMPORTED_LOCATION")) {
  4133. info.Location = location;
  4134. }
  4135. }
  4136. // Get the soname.
  4137. if (this->GetType() == cmState::SHARED_LIBRARY) {
  4138. std::string soProp = "IMPORTED_SONAME";
  4139. soProp += suffix;
  4140. if (const char* config_soname = this->GetProperty(soProp)) {
  4141. info.SOName = config_soname;
  4142. } else if (const char* soname = this->GetProperty("IMPORTED_SONAME")) {
  4143. info.SOName = soname;
  4144. }
  4145. }
  4146. // Get the "no-soname" mark.
  4147. if (this->GetType() == cmState::SHARED_LIBRARY) {
  4148. std::string soProp = "IMPORTED_NO_SONAME";
  4149. soProp += suffix;
  4150. if (const char* config_no_soname = this->GetProperty(soProp)) {
  4151. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4152. } else if (const char* no_soname =
  4153. this->GetProperty("IMPORTED_NO_SONAME")) {
  4154. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4155. }
  4156. }
  4157. // Get the import library.
  4158. if (imp) {
  4159. info.ImportLibrary = imp;
  4160. } else if (this->GetType() == cmState::SHARED_LIBRARY ||
  4161. this->IsExecutableWithExports()) {
  4162. std::string impProp = "IMPORTED_IMPLIB";
  4163. impProp += suffix;
  4164. if (const char* config_implib = this->GetProperty(impProp)) {
  4165. info.ImportLibrary = config_implib;
  4166. } else if (const char* implib = this->GetProperty("IMPORTED_IMPLIB")) {
  4167. info.ImportLibrary = implib;
  4168. }
  4169. }
  4170. // Get the link dependencies.
  4171. {
  4172. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4173. linkProp += suffix;
  4174. if (const char* config_libs = this->GetProperty(linkProp)) {
  4175. info.SharedDeps = config_libs;
  4176. } else if (const char* libs =
  4177. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  4178. info.SharedDeps = libs;
  4179. }
  4180. }
  4181. // Get the link languages.
  4182. if (this->LinkLanguagePropagatesToDependents()) {
  4183. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4184. linkProp += suffix;
  4185. if (const char* config_libs = this->GetProperty(linkProp)) {
  4186. info.Languages = config_libs;
  4187. } else if (const char* libs =
  4188. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  4189. info.Languages = libs;
  4190. }
  4191. }
  4192. // Get the cyclic repetition count.
  4193. if (this->GetType() == cmState::STATIC_LIBRARY) {
  4194. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4195. linkProp += suffix;
  4196. if (const char* config_reps = this->GetProperty(linkProp)) {
  4197. sscanf(config_reps, "%u", &info.Multiplicity);
  4198. } else if (const char* reps =
  4199. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  4200. sscanf(reps, "%u", &info.Multiplicity);
  4201. }
  4202. }
  4203. }
  4204. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  4205. const std::string& config) const
  4206. {
  4207. std::string CONFIG = cmSystemTools::UpperCase(config);
  4208. return this->LinkInterfaceMap[CONFIG];
  4209. }
  4210. cmHeadToLinkInterfaceMap&
  4211. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  4212. const std::string& config) const
  4213. {
  4214. std::string CONFIG = cmSystemTools::UpperCase(config);
  4215. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  4216. }
  4217. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  4218. const std::string& config) const
  4219. {
  4220. // There is no link implementation for imported targets.
  4221. if (this->IsImported()) {
  4222. return 0;
  4223. }
  4224. std::string CONFIG = cmSystemTools::UpperCase(config);
  4225. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this];
  4226. if (!impl.LibrariesDone) {
  4227. impl.LibrariesDone = true;
  4228. this->ComputeLinkImplementationLibraries(config, impl, this);
  4229. }
  4230. if (!impl.LanguagesDone) {
  4231. impl.LanguagesDone = true;
  4232. this->ComputeLinkImplementationLanguages(config, impl);
  4233. }
  4234. return &impl;
  4235. }
  4236. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  4237. std::vector<cmSourceFile*>& files) const
  4238. {
  4239. std::vector<std::string> configs;
  4240. this->Makefile->GetConfigurations(configs);
  4241. if (configs.empty()) {
  4242. configs.push_back("");
  4243. }
  4244. std::vector<std::string>::const_iterator it = configs.begin();
  4245. const std::string& firstConfig = *it;
  4246. this->GetSourceFiles(files, firstConfig);
  4247. for (; it != configs.end(); ++it) {
  4248. std::vector<cmSourceFile*> configFiles;
  4249. this->GetSourceFiles(configFiles, *it);
  4250. if (configFiles != files) {
  4251. std::string firstConfigFiles;
  4252. const char* sep = "";
  4253. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  4254. fi != files.end(); ++fi) {
  4255. firstConfigFiles += sep;
  4256. firstConfigFiles += (*fi)->GetFullPath();
  4257. sep = "\n ";
  4258. }
  4259. std::string thisConfigFiles;
  4260. sep = "";
  4261. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  4262. fi != configFiles.end(); ++fi) {
  4263. thisConfigFiles += sep;
  4264. thisConfigFiles += (*fi)->GetFullPath();
  4265. sep = "\n ";
  4266. }
  4267. std::ostringstream e;
  4268. /* clang-format off */
  4269. e << "Target \"" << this->GetName()
  4270. << "\" has source files which vary by "
  4271. "configuration. This is not supported by the \""
  4272. << this->GlobalGenerator->GetName()
  4273. << "\" generator.\n"
  4274. "Config \"" << firstConfig << "\":\n"
  4275. " " << firstConfigFiles << "\n"
  4276. "Config \"" << *it << "\":\n"
  4277. " " << thisConfigFiles << "\n";
  4278. /* clang-format on */
  4279. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  4280. return false;
  4281. }
  4282. }
  4283. return true;
  4284. }
  4285. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  4286. std::vector<cmGeneratorTarget*>& objlibs) const
  4287. {
  4288. // At configure-time, this method can be called as part of getting the
  4289. // LOCATION property or to export() a file to be include()d. However
  4290. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  4291. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  4292. // behavior of CMP0024 and CMP0026 only.
  4293. cmStringRange rng = this->Target->GetSourceEntries();
  4294. for (std::vector<std::string>::const_iterator i = rng.begin();
  4295. i != rng.end(); ++i) {
  4296. std::string const& entry = *i;
  4297. std::vector<std::string> files;
  4298. cmSystemTools::ExpandListArgument(entry, files);
  4299. for (std::vector<std::string>::const_iterator li = files.begin();
  4300. li != files.end(); ++li) {
  4301. if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  4302. (*li)[li->size() - 1] == '>') {
  4303. std::string objLibName = li->substr(17, li->size() - 18);
  4304. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  4305. continue;
  4306. }
  4307. cmGeneratorTarget* objLib =
  4308. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  4309. if (objLib) {
  4310. objlibs.push_back(objLib);
  4311. }
  4312. }
  4313. }
  4314. }
  4315. }
  4316. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  4317. {
  4318. // Strip whitespace off the library names because we used to do this
  4319. // in case variables were expanded at generate time. We no longer
  4320. // do the expansion but users link to libraries like " ${VAR} ".
  4321. std::string lib = item;
  4322. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4323. if (pos != lib.npos) {
  4324. lib = lib.substr(pos, lib.npos);
  4325. }
  4326. pos = lib.find_last_not_of(" \t\r\n");
  4327. if (pos != lib.npos) {
  4328. lib = lib.substr(0, pos + 1);
  4329. }
  4330. if (lib != item) {
  4331. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  4332. switch (this->GetPolicyStatusCMP0004()) {
  4333. case cmPolicies::WARN: {
  4334. std::ostringstream w;
  4335. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  4336. << "Target \"" << this->GetName() << "\" links to item \"" << item
  4337. << "\" which has leading or trailing whitespace.";
  4338. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  4339. }
  4340. case cmPolicies::OLD:
  4341. break;
  4342. case cmPolicies::NEW: {
  4343. std::ostringstream e;
  4344. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  4345. << "\" which has leading or trailing whitespace. "
  4346. << "This is now an error according to policy CMP0004.";
  4347. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4348. } break;
  4349. case cmPolicies::REQUIRED_IF_USED:
  4350. case cmPolicies::REQUIRED_ALWAYS: {
  4351. std::ostringstream e;
  4352. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  4353. << "Target \"" << this->GetName() << "\" links to item \"" << item
  4354. << "\" which has leading or trailing whitespace.";
  4355. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4356. } break;
  4357. }
  4358. }
  4359. return lib;
  4360. }
  4361. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  4362. const std::string& config) const
  4363. {
  4364. std::vector<cmSourceFile*> sourceFiles;
  4365. this->GetSourceFiles(sourceFiles, config);
  4366. for (std::vector<cmSourceFile*>::const_iterator i = sourceFiles.begin();
  4367. i != sourceFiles.end(); ++i) {
  4368. const std::string& lang = (*i)->GetLanguage();
  4369. if (!lang.empty()) {
  4370. languages.insert(lang);
  4371. }
  4372. }
  4373. std::vector<cmGeneratorTarget*> objectLibraries;
  4374. std::vector<cmSourceFile const*> externalObjects;
  4375. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4376. std::vector<cmGeneratorTarget*> objectTargets;
  4377. this->GetObjectLibrariesCMP0026(objectTargets);
  4378. objectLibraries.reserve(objectTargets.size());
  4379. for (std::vector<cmGeneratorTarget*>::const_iterator it =
  4380. objectTargets.begin();
  4381. it != objectTargets.end(); ++it) {
  4382. objectLibraries.push_back(*it);
  4383. }
  4384. } else {
  4385. this->GetExternalObjects(externalObjects, config);
  4386. for (std::vector<cmSourceFile const*>::const_iterator i =
  4387. externalObjects.begin();
  4388. i != externalObjects.end(); ++i) {
  4389. std::string objLib = (*i)->GetObjectLibrary();
  4390. if (cmGeneratorTarget* tgt =
  4391. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  4392. objectLibraries.push_back(tgt);
  4393. }
  4394. }
  4395. }
  4396. for (std::vector<cmGeneratorTarget*>::const_iterator i =
  4397. objectLibraries.begin();
  4398. i != objectLibraries.end(); ++i) {
  4399. (*i)->GetLanguages(languages, config);
  4400. }
  4401. }
  4402. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  4403. const std::string& config, cmOptionalLinkImplementation& impl) const
  4404. {
  4405. // This target needs runtime libraries for its source languages.
  4406. std::set<std::string> languages;
  4407. // Get languages used in our source files.
  4408. this->GetLanguages(languages, config);
  4409. // Copy the set of langauges to the link implementation.
  4410. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  4411. languages.end());
  4412. }
  4413. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  4414. {
  4415. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  4416. return false;
  4417. }
  4418. if (cmLinkImplementationLibraries const* impl =
  4419. this->GetLinkImplementationLibraries(config)) {
  4420. return !impl->Libraries.empty();
  4421. }
  4422. return false;
  4423. }
  4424. cmLinkImplementationLibraries const*
  4425. cmGeneratorTarget::GetLinkImplementationLibraries(
  4426. const std::string& config) const
  4427. {
  4428. return this->GetLinkImplementationLibrariesInternal(config, this);
  4429. }
  4430. cmLinkImplementationLibraries const*
  4431. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  4432. const std::string& config, cmGeneratorTarget const* head) const
  4433. {
  4434. // There is no link implementation for imported targets.
  4435. if (this->IsImported()) {
  4436. return 0;
  4437. }
  4438. // Populate the link implementation libraries for this configuration.
  4439. std::string CONFIG = cmSystemTools::UpperCase(config);
  4440. HeadToLinkImplementationMap& hm = this->LinkImplMap[CONFIG];
  4441. // If the link implementation does not depend on the head target
  4442. // then return the one we computed first.
  4443. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4444. return &hm.begin()->second;
  4445. }
  4446. cmOptionalLinkImplementation& impl = hm[head];
  4447. if (!impl.LibrariesDone) {
  4448. impl.LibrariesDone = true;
  4449. this->ComputeLinkImplementationLibraries(config, impl, head);
  4450. }
  4451. return &impl;
  4452. }
  4453. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  4454. const std::string& p) const
  4455. {
  4456. return this->LinkImplicitNullProperties.find(p) !=
  4457. this->LinkImplicitNullProperties.end();
  4458. }
  4459. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  4460. const std::string& config, cmOptionalLinkImplementation& impl,
  4461. cmGeneratorTarget const* head) const
  4462. {
  4463. cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
  4464. cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
  4465. cmBacktraceRange::const_iterator btIt = btRange.begin();
  4466. // Collect libraries directly linked in this configuration.
  4467. for (cmStringRange::const_iterator le = entryRange.begin(),
  4468. end = entryRange.end();
  4469. le != end; ++le, ++btIt) {
  4470. std::vector<std::string> llibs;
  4471. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  4472. "LINK_LIBRARIES", 0, 0);
  4473. cmGeneratorExpression ge(*btIt);
  4474. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
  4475. std::string const evaluated =
  4476. cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
  4477. cmSystemTools::ExpandListArgument(evaluated, llibs);
  4478. if (cge->GetHadHeadSensitiveCondition()) {
  4479. impl.HadHeadSensitiveCondition = true;
  4480. }
  4481. for (std::vector<std::string>::const_iterator li = llibs.begin();
  4482. li != llibs.end(); ++li) {
  4483. // Skip entries that resolve to the target itself or are empty.
  4484. std::string name = this->CheckCMP0004(*li);
  4485. if (name == this->GetName() || name.empty()) {
  4486. if (name == this->GetName()) {
  4487. bool noMessage = false;
  4488. cmake::MessageType messageType = cmake::FATAL_ERROR;
  4489. std::ostringstream e;
  4490. switch (this->GetPolicyStatusCMP0038()) {
  4491. case cmPolicies::WARN: {
  4492. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  4493. messageType = cmake::AUTHOR_WARNING;
  4494. } break;
  4495. case cmPolicies::OLD:
  4496. noMessage = true;
  4497. case cmPolicies::REQUIRED_IF_USED:
  4498. case cmPolicies::REQUIRED_ALWAYS:
  4499. case cmPolicies::NEW:
  4500. // Issue the fatal message.
  4501. break;
  4502. }
  4503. if (!noMessage) {
  4504. e << "Target \"" << this->GetName() << "\" links to itself.";
  4505. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4506. messageType, e.str(), this->GetBacktrace());
  4507. if (messageType == cmake::FATAL_ERROR) {
  4508. return;
  4509. }
  4510. }
  4511. }
  4512. continue;
  4513. }
  4514. // The entry is meant for this configuration.
  4515. impl.Libraries.push_back(cmLinkImplItem(
  4516. name, this->FindTargetToLink(name), *btIt, evaluated != *le));
  4517. }
  4518. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  4519. for (std::set<std::string>::const_iterator it = seenProps.begin();
  4520. it != seenProps.end(); ++it) {
  4521. if (!this->GetProperty(*it)) {
  4522. this->LinkImplicitNullProperties.insert(*it);
  4523. }
  4524. }
  4525. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  4526. }
  4527. // Get the list of configurations considered to be DEBUG.
  4528. std::vector<std::string> debugConfigs =
  4529. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  4530. cmTargetLinkLibraryType linkType =
  4531. CMP0003_ComputeLinkType(config, debugConfigs);
  4532. cmTarget::LinkLibraryVectorType const& oldllibs =
  4533. this->Target->GetOriginalLinkLibraries();
  4534. for (cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4535. li != oldllibs.end(); ++li) {
  4536. if (li->second != GENERAL_LibraryType && li->second != linkType) {
  4537. std::string name = this->CheckCMP0004(li->first);
  4538. if (name == this->GetName() || name.empty()) {
  4539. continue;
  4540. }
  4541. // Support OLD behavior for CMP0003.
  4542. impl.WrongConfigLibraries.push_back(
  4543. cmLinkItem(name, this->FindTargetToLink(name)));
  4544. }
  4545. }
  4546. }
  4547. cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink(
  4548. std::string const& name) const
  4549. {
  4550. cmGeneratorTarget* tgt =
  4551. this->LocalGenerator->FindGeneratorTargetToUse(name);
  4552. // Skip targets that will not really be linked. This is probably a
  4553. // name conflict between an external library and an executable
  4554. // within the project.
  4555. if (tgt && tgt->GetType() == cmState::EXECUTABLE &&
  4556. !tgt->IsExecutableWithExports()) {
  4557. tgt = 0;
  4558. }
  4559. if (tgt && tgt->GetType() == cmState::OBJECT_LIBRARY) {
  4560. std::ostringstream e;
  4561. e << "Target \"" << this->GetName() << "\" links to "
  4562. "OBJECT library \""
  4563. << tgt->GetName()
  4564. << "\" but this is not "
  4565. "allowed. "
  4566. "One may link only to STATIC or SHARED libraries, or to executables "
  4567. "with the ENABLE_EXPORTS property set.";
  4568. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  4569. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4570. tgt = 0;
  4571. }
  4572. return tgt;
  4573. }
  4574. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  4575. {
  4576. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  4577. // Return the directory in which the target will be built.
  4578. return info->PdbDir;
  4579. }
  4580. return "";
  4581. }
  4582. bool cmGeneratorTarget::HasImplibGNUtoMS() const
  4583. {
  4584. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  4585. }
  4586. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& gnuName,
  4587. std::string& out,
  4588. const char* newExt) const
  4589. {
  4590. if (this->HasImplibGNUtoMS() && gnuName.size() > 6 &&
  4591. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  4592. out = gnuName.substr(0, gnuName.size() - 6);
  4593. out += newExt ? newExt : ".lib";
  4594. return true;
  4595. }
  4596. return false;
  4597. }
  4598. bool cmGeneratorTarget::IsExecutableWithExports() const
  4599. {
  4600. return (this->GetType() == cmState::EXECUTABLE &&
  4601. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  4602. }
  4603. bool cmGeneratorTarget::HasImportLibrary() const
  4604. {
  4605. return (this->IsDLLPlatform() &&
  4606. (this->GetType() == cmState::SHARED_LIBRARY ||
  4607. this->IsExecutableWithExports()));
  4608. }
  4609. std::string cmGeneratorTarget::GetSupportDirectory() const
  4610. {
  4611. std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  4612. dir += cmake::GetCMakeFilesDirectory();
  4613. dir += "/";
  4614. dir += this->GetName();
  4615. #if defined(__VMS)
  4616. dir += "_dir";
  4617. #else
  4618. dir += ".dir";
  4619. #endif
  4620. return dir;
  4621. }
  4622. bool cmGeneratorTarget::IsLinkable() const
  4623. {
  4624. return (this->GetType() == cmState::STATIC_LIBRARY ||
  4625. this->GetType() == cmState::SHARED_LIBRARY ||
  4626. this->GetType() == cmState::MODULE_LIBRARY ||
  4627. this->GetType() == cmState::UNKNOWN_LIBRARY ||
  4628. this->GetType() == cmState::INTERFACE_LIBRARY ||
  4629. this->IsExecutableWithExports());
  4630. }
  4631. bool cmGeneratorTarget::IsFrameworkOnApple() const
  4632. {
  4633. return (this->GetType() == cmState::SHARED_LIBRARY &&
  4634. this->Makefile->IsOn("APPLE") &&
  4635. this->GetPropertyAsBool("FRAMEWORK"));
  4636. }
  4637. bool cmGeneratorTarget::IsAppBundleOnApple() const
  4638. {
  4639. return (this->GetType() == cmState::EXECUTABLE &&
  4640. this->Makefile->IsOn("APPLE") &&
  4641. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  4642. }
  4643. bool cmGeneratorTarget::IsXCTestOnApple() const
  4644. {
  4645. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  4646. }
  4647. bool cmGeneratorTarget::IsCFBundleOnApple() const
  4648. {
  4649. return (this->GetType() == cmState::MODULE_LIBRARY &&
  4650. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  4651. }