cmGeneratorTarget.cxx 177 KB

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