cmGeneratorTarget.cxx 174 KB

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