cmGeneratorTarget.cxx 175 KB

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