cmGeneratorTarget.cxx 189 KB

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