cmGeneratorTarget.cxx 180 KB

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