cmGeneratorTarget.cxx 190 KB

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