cmGeneratorTarget.cxx 174 KB

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