cmGeneratorTarget.cxx 174 KB

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