cmTarget.cxx 214 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 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 "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmDocumentCompileDefinitions.h"
  18. #include "cmDocumentGeneratorExpressions.h"
  19. #include "cmDocumentLocationUndefined.h"
  20. #include "cmListFileCache.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorExpressionDAGChecker.h"
  23. #include <cmsys/RegularExpression.hxx>
  24. #include <map>
  25. #include <set>
  26. #include <queue>
  27. #include <stdlib.h> // required for atof
  28. #include <assert.h>
  29. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  30. {
  31. switch( targetType )
  32. {
  33. case cmTarget::STATIC_LIBRARY:
  34. return "STATIC_LIBRARY";
  35. case cmTarget::MODULE_LIBRARY:
  36. return "MODULE_LIBRARY";
  37. case cmTarget::SHARED_LIBRARY:
  38. return "SHARED_LIBRARY";
  39. case cmTarget::OBJECT_LIBRARY:
  40. return "OBJECT_LIBRARY";
  41. case cmTarget::EXECUTABLE:
  42. return "EXECUTABLE";
  43. case cmTarget::UTILITY:
  44. return "UTILITY";
  45. case cmTarget::GLOBAL_TARGET:
  46. return "GLOBAL_TARGET";
  47. case cmTarget::UNKNOWN_LIBRARY:
  48. return "UNKNOWN_LIBRARY";
  49. }
  50. assert(0 && "Unexpected target type");
  51. return 0;
  52. }
  53. //----------------------------------------------------------------------------
  54. struct cmTarget::OutputInfo
  55. {
  56. std::string OutDir;
  57. std::string ImpDir;
  58. std::string PdbDir;
  59. };
  60. //----------------------------------------------------------------------------
  61. struct cmTarget::ImportInfo
  62. {
  63. bool NoSOName;
  64. std::string Location;
  65. std::string SOName;
  66. std::string ImportLibrary;
  67. cmTarget::LinkInterface LinkInterface;
  68. };
  69. struct TargetConfigPair : public std::pair<cmTarget*, std::string> {
  70. TargetConfigPair(cmTarget* tgt, const std::string &config)
  71. : std::pair<cmTarget*, std::string>(tgt, config) {}
  72. };
  73. //----------------------------------------------------------------------------
  74. class cmTargetInternals
  75. {
  76. public:
  77. cmTargetInternals()
  78. {
  79. this->SourceFileFlagsConstructed = false;
  80. }
  81. cmTargetInternals(cmTargetInternals const& r)
  82. {
  83. this->SourceFileFlagsConstructed = false;
  84. // Only some of these entries are part of the object state.
  85. // Others not copied here are result caches.
  86. this->SourceEntries = r.SourceEntries;
  87. }
  88. ~cmTargetInternals();
  89. typedef cmTarget::SourceFileFlags SourceFileFlags;
  90. std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  91. bool SourceFileFlagsConstructed;
  92. // The backtrace when the target was created.
  93. cmListFileBacktrace Backtrace;
  94. // Cache link interface computation from each configuration.
  95. struct OptionalLinkInterface: public cmTarget::LinkInterface
  96. {
  97. OptionalLinkInterface(): Exists(false) {}
  98. bool Exists;
  99. };
  100. typedef std::map<TargetConfigPair, OptionalLinkInterface>
  101. LinkInterfaceMapType;
  102. LinkInterfaceMapType LinkInterfaceMap;
  103. typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
  104. OutputInfoMapType OutputInfoMap;
  105. typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
  106. ImportInfoMapType;
  107. ImportInfoMapType ImportInfoMap;
  108. // Cache link implementation computation from each configuration.
  109. typedef std::map<TargetConfigPair,
  110. cmTarget::LinkImplementation> LinkImplMapType;
  111. LinkImplMapType LinkImplMap;
  112. typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
  113. LinkClosureMapType;
  114. LinkClosureMapType LinkClosureMap;
  115. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  116. typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
  117. SourceEntriesType SourceEntries;
  118. struct IncludeDirectoriesEntry {
  119. IncludeDirectoriesEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  120. const std::string &targetName = std::string())
  121. : ge(cge), TargetName(targetName)
  122. {}
  123. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  124. std::vector<std::string> CachedIncludes;
  125. const std::string TargetName;
  126. };
  127. std::vector<IncludeDirectoriesEntry*> IncludeDirectoriesEntries;
  128. std::vector<cmValueWithOrigin> LinkInterfaceIncludeDirectoriesEntries;
  129. std::map<std::string, std::vector<IncludeDirectoriesEntry*> >
  130. CachedLinkInterfaceIncludeDirectoriesEntries;
  131. std::map<std::string, std::string> CachedLinkInterfaceCompileDefinitions;
  132. std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
  133. std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
  134. };
  135. //----------------------------------------------------------------------------
  136. void deleteAndClear(
  137. std::vector<cmTargetInternals::IncludeDirectoriesEntry*> &entries)
  138. {
  139. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  140. it = entries.begin(),
  141. end = entries.end();
  142. it != end; ++it)
  143. {
  144. delete *it;
  145. }
  146. entries.clear();
  147. }
  148. //----------------------------------------------------------------------------
  149. void deleteAndClear(
  150. std::map<std::string,
  151. std::vector<cmTargetInternals::IncludeDirectoriesEntry*> > &entries)
  152. {
  153. for (std::map<std::string,
  154. std::vector<cmTargetInternals::IncludeDirectoriesEntry*> >::iterator
  155. it = entries.begin(), end = entries.end(); it != end; ++it)
  156. {
  157. deleteAndClear(it->second);
  158. }
  159. }
  160. //----------------------------------------------------------------------------
  161. cmTargetInternals::~cmTargetInternals()
  162. {
  163. deleteAndClear(CachedLinkInterfaceIncludeDirectoriesEntries);
  164. }
  165. //----------------------------------------------------------------------------
  166. cmTarget::cmTarget()
  167. {
  168. this->Makefile = 0;
  169. this->PolicyStatusCMP0003 = cmPolicies::WARN;
  170. this->PolicyStatusCMP0004 = cmPolicies::WARN;
  171. this->PolicyStatusCMP0008 = cmPolicies::WARN;
  172. this->PolicyStatusCMP0020 = cmPolicies::WARN;
  173. this->LinkLibrariesAnalyzed = false;
  174. this->HaveInstallRule = false;
  175. this->DLLPlatform = false;
  176. this->IsApple = false;
  177. this->IsImportedTarget = false;
  178. this->BuildInterfaceIncludesAppended = false;
  179. this->DebugIncludesDone = false;
  180. }
  181. //----------------------------------------------------------------------------
  182. void cmTarget::DefineProperties(cmake *cm)
  183. {
  184. cm->DefineProperty
  185. ("AUTOMOC", cmProperty::TARGET,
  186. "Should the target be processed with automoc (for Qt projects).",
  187. "AUTOMOC is a boolean specifying whether CMake will handle "
  188. "the Qt moc preprocessor automatically, i.e. without having to use "
  189. "the QT4_WRAP_CPP() or QT5_WRAP_CPP() macro. Currently Qt4 and Qt5 are "
  190. "supported. "
  191. "When this property is set to TRUE, CMake will scan the source files "
  192. "at build time and invoke moc accordingly. "
  193. "If an #include statement like #include \"moc_foo.cpp\" is found, "
  194. "the Q_OBJECT class declaration is expected in the header, and moc is "
  195. "run on the header file. "
  196. "If an #include statement like #include \"foo.moc\" is found, "
  197. "then a Q_OBJECT is expected in the current source file and moc "
  198. "is run on the file itself. "
  199. "Additionally, all header files are parsed for Q_OBJECT macros, "
  200. "and if found, moc is also executed on those files. The resulting "
  201. "moc files, which are not included as shown above in any of the source "
  202. "files are included in a generated <targetname>_automoc.cpp file, "
  203. "which is compiled as part of the target."
  204. "This property is initialized by the value of the variable "
  205. "CMAKE_AUTOMOC if it is set when a target is created.\n"
  206. "Additional command line options for moc can be set via the "
  207. "AUTOMOC_MOC_OPTIONS property.\n"
  208. "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
  209. "for searching the files which will be processed by moc can be relaxed. "
  210. "See the documentation for this variable for more details.");
  211. cm->DefineProperty
  212. ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
  213. "Additional options for moc when using automoc (see the AUTOMOC property)",
  214. "This property is only used if the AUTOMOC property is set to TRUE for "
  215. "this target. In this case, it holds additional command line options "
  216. "which will be used when moc is executed during the build, i.e. it is "
  217. "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
  218. "macro.\n"
  219. "By default it is empty.");
  220. cm->DefineProperty
  221. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  222. "Should build tree targets have install tree rpaths.",
  223. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  224. "the target in the build tree with the INSTALL_RPATH. This takes "
  225. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  226. "before installation. "
  227. "This property is initialized by the value of the variable "
  228. "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
  229. cm->DefineProperty
  230. ("COMPILE_FLAGS", cmProperty::TARGET,
  231. "Additional flags to use when compiling this target's sources.",
  232. "The COMPILE_FLAGS property sets additional compiler flags used "
  233. "to build sources within the target. Use COMPILE_DEFINITIONS "
  234. "to pass additional preprocessor definitions.");
  235. cm->DefineProperty
  236. ("COMPILE_DEFINITIONS", cmProperty::TARGET,
  237. "Preprocessor definitions for compiling a target's sources.",
  238. "The COMPILE_DEFINITIONS property may be set to a "
  239. "semicolon-separated list of preprocessor "
  240. "definitions using the syntax VAR or VAR=value. Function-style "
  241. "definitions are not supported. CMake will automatically escape "
  242. "the value correctly for the native build system (note that CMake "
  243. "language syntax may require escapes to specify some values). "
  244. "This property may be set on a per-configuration basis using the name "
  245. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  246. "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
  247. "CMake will automatically drop some definitions that "
  248. "are not supported by the native build tool. "
  249. "The VS6 IDE does not support definition values with spaces "
  250. "(but NMake does).\n"
  251. "Contents of COMPILE_DEFINITIONS may use \"generator expressions\" with "
  252. "the syntax \"$<...>\". "
  253. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
  254. CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
  255. cm->DefineProperty
  256. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
  257. "Per-configuration preprocessor definitions on a target.",
  258. "This is the configuration-specific version of COMPILE_DEFINITIONS.");
  259. cm->DefineProperty
  260. ("DEFINE_SYMBOL", cmProperty::TARGET,
  261. "Define a symbol when compiling this target's sources.",
  262. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  263. "compiling sources in a shared library. "
  264. "If not set here then it is set to target_EXPORTS by default "
  265. "(with some substitutions if the target is not a valid C "
  266. "identifier). This is useful for headers to know whether they are "
  267. "being included from inside their library our outside to properly "
  268. "setup dllexport/dllimport decorations. ");
  269. cm->DefineProperty
  270. ("DEBUG_POSTFIX", cmProperty::TARGET,
  271. "See target property <CONFIG>_POSTFIX.",
  272. "This property is a special case of the more-general <CONFIG>_POSTFIX "
  273. "property for the DEBUG configuration.");
  274. cm->DefineProperty
  275. ("<CONFIG>_POSTFIX", cmProperty::TARGET,
  276. "Postfix to append to the target file name for configuration <CONFIG>.",
  277. "When building with configuration <CONFIG> the value of this property "
  278. "is appended to the target file name built on disk. "
  279. "For non-executable targets, this property is initialized by the value "
  280. "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
  281. "created. "
  282. "This property is ignored on the Mac for Frameworks and App Bundles.");
  283. cm->DefineProperty
  284. ("EchoString", cmProperty::TARGET,
  285. "A message to be displayed when the target is built.",
  286. "A message to display on some generators (such as makefiles) when "
  287. "the target is built.");
  288. cm->DefineProperty
  289. ("BUNDLE", cmProperty::TARGET,
  290. "This target is a CFBundle on the Mac.",
  291. "If a module library target has this property set to true it will "
  292. "be built as a CFBundle when built on the mac. It will have the "
  293. "directory structure required for a CFBundle and will be suitable "
  294. "to be used for creating Browser Plugins or other application "
  295. "resources.");
  296. cm->DefineProperty
  297. ("BUNDLE_EXTENSION", cmProperty::TARGET,
  298. "The file extension used to name a BUNDLE target on the Mac.",
  299. "The default value is \"bundle\" - you can also use \"plugin\" or "
  300. "whatever file extension is required by the host app for your "
  301. "bundle.");
  302. cm->DefineProperty
  303. ("EXCLUDE_FROM_DEFAULT_BUILD", cmProperty::TARGET,
  304. "Exclude target from \"Build Solution\".",
  305. "This property is only used by Visual Studio generators 7 and above. "
  306. "When set to TRUE, the target will not be built when you press "
  307. "\"Build Solution\".");
  308. cm->DefineProperty
  309. ("EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>", cmProperty::TARGET,
  310. "Per-configuration version of target exclusion from \"Build Solution\". ",
  311. "This is the configuration-specific version of "
  312. "EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD "
  313. "is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes "
  314. "precedence in configurations for which it has a value.");
  315. cm->DefineProperty
  316. ("FRAMEWORK", cmProperty::TARGET,
  317. "This target is a framework on the Mac.",
  318. "If a shared library target has this property set to true it will "
  319. "be built as a framework when built on the mac. It will have the "
  320. "directory structure required for a framework and will be suitable "
  321. "to be used with the -framework option");
  322. cm->DefineProperty
  323. ("HAS_CXX", cmProperty::TARGET,
  324. "Link the target using the C++ linker tool (obsolete).",
  325. "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
  326. "See that property's documentation for details.");
  327. cm->DefineProperty
  328. ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
  329. "Specify #include line transforms for dependencies in a target.",
  330. "This property specifies rules to transform macro-like #include lines "
  331. "during implicit dependency scanning of C and C++ source files. "
  332. "The list of rules must be semicolon-separated with each entry of "
  333. "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
  334. "During dependency scanning occurrences of A_MACRO(...) on #include "
  335. "lines will be replaced by the value given with the macro argument "
  336. "substituted for '%'. For example, the entry\n"
  337. " MYDIR(%)=<mydir/%>\n"
  338. "will convert lines of the form\n"
  339. " #include MYDIR(myheader.h)\n"
  340. "to\n"
  341. " #include <mydir/myheader.h>\n"
  342. "allowing the dependency to be followed.\n"
  343. "This property applies to sources in the target on which it is set.");
  344. cm->DefineProperty
  345. ("IMPORT_PREFIX", cmProperty::TARGET,
  346. "What comes before the import library name.",
  347. "Similar to the target property PREFIX, but used for import libraries "
  348. "(typically corresponding to a DLL) instead of regular libraries. "
  349. "A target property that can be set to override the prefix "
  350. "(such as \"lib\") on an import library name.");
  351. cm->DefineProperty
  352. ("IMPORT_SUFFIX", cmProperty::TARGET,
  353. "What comes after the import library name.",
  354. "Similar to the target property SUFFIX, but used for import libraries "
  355. "(typically corresponding to a DLL) instead of regular libraries. "
  356. "A target property that can be set to override the suffix "
  357. "(such as \".lib\") on an import library name.");
  358. cm->DefineProperty
  359. ("IMPORTED", cmProperty::TARGET,
  360. "Read-only indication of whether a target is IMPORTED.",
  361. "The boolean value of this property is true for targets created with "
  362. "the IMPORTED option to add_executable or add_library. "
  363. "It is false for targets built within the project.");
  364. cm->DefineProperty
  365. ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
  366. "Configurations provided for an IMPORTED target.",
  367. "Set this to the list of configuration names available for an "
  368. "IMPORTED target. "
  369. "The names correspond to configurations defined in the project from "
  370. "which the target is imported. "
  371. "If the importing project uses a different set of configurations "
  372. "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
  373. "property. "
  374. "Ignored for non-imported targets.");
  375. cm->DefineProperty
  376. ("IMPORTED_IMPLIB", cmProperty::TARGET,
  377. "Full path to the import library for an IMPORTED target.",
  378. "Set this to the location of the \".lib\" part of a windows DLL. "
  379. "Ignored for non-imported targets.");
  380. cm->DefineProperty
  381. ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
  382. "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
  383. "Configuration names correspond to those provided by the project "
  384. "from which the target is imported.");
  385. cm->DefineProperty
  386. ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
  387. "Dependent shared libraries of an imported shared library.",
  388. "Shared libraries may be linked to other shared libraries as part "
  389. "of their implementation. On some platforms the linker searches "
  390. "for the dependent libraries of shared libraries they are including "
  391. "in the link. "
  392. "Set this property to the list of dependent shared libraries of an "
  393. "imported library. "
  394. "The list "
  395. "should be disjoint from the list of interface libraries in the "
  396. "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
  397. "dependent shared libraries to be found at link time CMake uses this "
  398. "list to add appropriate files or paths to the link command line. "
  399. "Ignored for non-imported targets.");
  400. cm->DefineProperty
  401. ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  402. "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
  403. "Configuration names correspond to those provided by the project "
  404. "from which the target is imported. "
  405. "If set, this property completely overrides the generic property "
  406. "for the named configuration.");
  407. cm->DefineProperty
  408. ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  409. "Transitive link interface of an IMPORTED target.",
  410. "Set this to the list of libraries whose interface is included when "
  411. "an IMPORTED library target is linked to another target. "
  412. "The libraries will be included on the link line for the target. "
  413. "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
  414. "to all imported target types, including STATIC libraries. "
  415. "This property is ignored for non-imported targets.");
  416. cm->DefineProperty
  417. ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  418. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
  419. "Configuration names correspond to those provided by the project "
  420. "from which the target is imported. "
  421. "If set, this property completely overrides the generic property "
  422. "for the named configuration.");
  423. cm->DefineProperty
  424. ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
  425. "Languages compiled into an IMPORTED static library.",
  426. "Set this to the list of languages of source files compiled to "
  427. "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). "
  428. "CMake accounts for these languages when computing how to link a "
  429. "target to the imported library. "
  430. "For example, when a C executable links to an imported C++ static "
  431. "library CMake chooses the C++ linker to satisfy language runtime "
  432. "dependencies of the static library. "
  433. "\n"
  434. "This property is ignored for targets that are not STATIC libraries. "
  435. "This property is ignored for non-imported targets.");
  436. cm->DefineProperty
  437. ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
  438. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
  439. "Configuration names correspond to those provided by the project "
  440. "from which the target is imported. "
  441. "If set, this property completely overrides the generic property "
  442. "for the named configuration.");
  443. cm->DefineProperty
  444. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  445. "Repetition count for cycles of IMPORTED static libraries.",
  446. "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
  447. cm->DefineProperty
  448. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  449. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
  450. "If set, this property completely overrides the generic property "
  451. "for the named configuration.");
  452. cm->DefineProperty
  453. ("IMPORTED_LOCATION", cmProperty::TARGET,
  454. "Full path to the main file on disk for an IMPORTED target.",
  455. "Set this to the location of an IMPORTED target file on disk. "
  456. "For executables this is the location of the executable file. "
  457. "For bundles on OS X this is the location of the executable file "
  458. "inside Contents/MacOS under the application bundle folder. "
  459. "For static libraries and modules this is the location of the "
  460. "library or module. "
  461. "For shared libraries on non-DLL platforms this is the location of "
  462. "the shared library. "
  463. "For frameworks on OS X this is the location of the library file "
  464. "symlink just inside the framework folder. "
  465. "For DLLs this is the location of the \".dll\" part of the library. "
  466. "For UNKNOWN libraries this is the location of the file to be linked. "
  467. "Ignored for non-imported targets."
  468. "\n"
  469. "Projects may skip IMPORTED_LOCATION if the configuration-specific "
  470. "property IMPORTED_LOCATION_<CONFIG> is set. "
  471. "To get the location of an imported target read one of the "
  472. "LOCATION or LOCATION_<CONFIG> properties.");
  473. cm->DefineProperty
  474. ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
  475. "<CONFIG>-specific version of IMPORTED_LOCATION property.",
  476. "Configuration names correspond to those provided by the project "
  477. "from which the target is imported.");
  478. cm->DefineProperty
  479. ("IMPORTED_SONAME", cmProperty::TARGET,
  480. "The \"soname\" of an IMPORTED target of shared library type.",
  481. "Set this to the \"soname\" embedded in an imported shared library. "
  482. "This is meaningful only on platforms supporting the feature. "
  483. "Ignored for non-imported targets.");
  484. cm->DefineProperty
  485. ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
  486. "<CONFIG>-specific version of IMPORTED_SONAME property.",
  487. "Configuration names correspond to those provided by the project "
  488. "from which the target is imported.");
  489. cm->DefineProperty
  490. ("IMPORTED_NO_SONAME", cmProperty::TARGET,
  491. "Specifies that an IMPORTED shared library target has no \"soname\". ",
  492. "Set this property to true for an imported shared library file that "
  493. "has no \"soname\" field. "
  494. "CMake may adjust generated link commands for some platforms to prevent "
  495. "the linker from using the path to the library in place of its missing "
  496. "soname. "
  497. "Ignored for non-imported targets.");
  498. cm->DefineProperty
  499. ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
  500. "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
  501. "Configuration names correspond to those provided by the project "
  502. "from which the target is imported.");
  503. cm->DefineProperty
  504. ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
  505. "Exclude the target from the all target.",
  506. "A property on a target that indicates if the target is excluded "
  507. "from the default build target. If it is not, then with a Makefile "
  508. "for example typing make will cause this target to be built. "
  509. "The same concept applies to the default build of other generators. "
  510. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  511. "undefined behavior.");
  512. cm->DefineProperty
  513. ("LINK_LIBRARIES", cmProperty::TARGET,
  514. "List of direct link dependencies.",
  515. "This property specifies the list of libraries or targets which will be "
  516. "used for linking. "
  517. "In addition to accepting values from the target_link_libraries "
  518. "command, values may be set directly on any target using the "
  519. "set_property command. "
  520. "\n"
  521. "The target property values are used by the generators to set "
  522. "the link libraries for the compiler. "
  523. "See also the target_link_libraries command.\n"
  524. "Contents of LINK_LIBRARIES may use \"generator expressions\" with "
  525. "the syntax \"$<...>\". "
  526. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  527. cm->DefineProperty
  528. ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
  529. "List of preprocessor include file search directories.",
  530. "This property specifies the list of directories given "
  531. "so far to the include_directories command. "
  532. "This property exists on directories and targets. "
  533. "In addition to accepting values from the include_directories "
  534. "command, values may be set directly on any directory or any "
  535. "target using the set_property command. "
  536. "A target gets its initial value for this property from the value "
  537. "of the directory property. "
  538. "A directory gets its initial value from its parent directory if "
  539. "it has one. "
  540. "Both directory and target property values are adjusted by calls "
  541. "to the include_directories command."
  542. "\n"
  543. "The target property values are used by the generators to set "
  544. "the include paths for the compiler. "
  545. "See also the include_directories command.\n"
  546. "Contents of INCLUDE_DIRECTORIES may use \"generator expressions\" with "
  547. "the syntax \"$<...>\". "
  548. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  549. cm->DefineProperty
  550. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  551. "Mac OSX directory name for installed targets.",
  552. "INSTALL_NAME_DIR is a string specifying the "
  553. "directory portion of the \"install_name\" field of shared libraries "
  554. "on Mac OSX to use in the installed targets. ");
  555. cm->DefineProperty
  556. ("INSTALL_RPATH", cmProperty::TARGET,
  557. "The rpath to use for installed targets.",
  558. "A semicolon-separated list specifying the rpath "
  559. "to use in installed targets (for platforms that support it). "
  560. "This property is initialized by the value of the variable "
  561. "CMAKE_INSTALL_RPATH if it is set when a target is created.");
  562. cm->DefineProperty
  563. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  564. "Add paths to linker search and installed rpath.",
  565. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  566. "append directories in the linker search path and outside the "
  567. "project to the INSTALL_RPATH. "
  568. "This property is initialized by the value of the variable "
  569. "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
  570. "created.");
  571. cm->DefineProperty
  572. ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
  573. "Enable interprocedural optimization for a target.",
  574. "If set to true, enables interprocedural optimizations "
  575. "if they are known to be supported by the compiler.");
  576. cm->DefineProperty
  577. ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
  578. "Per-configuration interprocedural optimization for a target.",
  579. "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
  580. "If set, this property overrides the generic property "
  581. "for the named configuration.");
  582. cm->DefineProperty
  583. ("LABELS", cmProperty::TARGET,
  584. "Specify a list of text labels associated with a target.",
  585. "Target label semantics are currently unspecified.");
  586. cm->DefineProperty
  587. ("LINK_FLAGS", cmProperty::TARGET,
  588. "Additional flags to use when linking this target.",
  589. "The LINK_FLAGS property can be used to add extra flags to the "
  590. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  591. "configuration <CONFIG>, "
  592. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  593. cm->DefineProperty
  594. ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
  595. "Per-configuration linker flags for a target.",
  596. "This is the configuration-specific version of LINK_FLAGS.");
  597. #define CM_LINK_SEARCH_SUMMARY \
  598. "Some linkers support switches such as -Bstatic and -Bdynamic " \
  599. "to determine whether to use static or shared libraries for -lXXX " \
  600. "options. CMake uses these options to set the link type for " \
  601. "libraries whose full paths are not known or (in some cases) are in " \
  602. "implicit link directories for the platform. "
  603. cm->DefineProperty
  604. ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
  605. "Assume the linker looks for static libraries by default.",
  606. CM_LINK_SEARCH_SUMMARY
  607. "By default the linker search type is assumed to be -Bdynamic at "
  608. "the beginning of the library list. This property switches the "
  609. "assumption to -Bstatic. It is intended for use when linking an "
  610. "executable statically (e.g. with the GNU -static option). "
  611. "See also LINK_SEARCH_END_STATIC.");
  612. cm->DefineProperty
  613. ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
  614. "End a link line such that static system libraries are used.",
  615. CM_LINK_SEARCH_SUMMARY
  616. "By default CMake adds an option at the end of the library list (if "
  617. "necessary) to set the linker search type back to its starting type. "
  618. "This property switches the final linker search type to -Bstatic "
  619. "regardless of how it started. "
  620. "See also LINK_SEARCH_START_STATIC.");
  621. cm->DefineProperty
  622. ("LINKER_LANGUAGE", cmProperty::TARGET,
  623. "Specifies language whose compiler will invoke the linker.",
  624. "For executables, shared libraries, and modules, this sets the "
  625. "language whose compiler is used to link the target "
  626. "(such as \"C\" or \"CXX\"). "
  627. "A typical value for an executable is the language of the source "
  628. "file providing the program entry point (main). "
  629. "If not set, the language with the highest linker preference "
  630. "value is the default. "
  631. "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
  632. cm->DefineProperty
  633. ("LOCATION", cmProperty::TARGET,
  634. "Read-only location of a target on disk.",
  635. "For an imported target, this read-only property returns the value of "
  636. "the LOCATION_<CONFIG> property for an unspecified configuration "
  637. "<CONFIG> provided by the target.\n"
  638. "For a non-imported target, this property is provided for compatibility "
  639. "with CMake 2.4 and below. "
  640. "It was meant to get the location of an executable target's output file "
  641. "for use in add_custom_command. "
  642. "The path may contain a build-system-specific portion that "
  643. "is replaced at build time with the configuration getting built "
  644. "(such as \"$(ConfigurationName)\" in VS). "
  645. "In CMake 2.6 and above add_custom_command automatically recognizes a "
  646. "target name in its COMMAND and DEPENDS options and computes the "
  647. "target location. "
  648. "In CMake 2.8.4 and above add_custom_command recognizes generator "
  649. "expressions to refer to target locations anywhere in the command. "
  650. "Therefore this property is not needed for creating custom commands."
  651. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  652. cm->DefineProperty
  653. ("LOCATION_<CONFIG>", cmProperty::TARGET,
  654. "Read-only property providing a target location on disk.",
  655. "A read-only property that indicates where a target's main file is "
  656. "located on disk for the configuration <CONFIG>. "
  657. "The property is defined only for library and executable targets. "
  658. "An imported target may provide a set of configurations different "
  659. "from that of the importing project. "
  660. "By default CMake looks for an exact-match but otherwise uses an "
  661. "arbitrary available configuration. "
  662. "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
  663. "configurations explicitly."
  664. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  665. cm->DefineProperty
  666. ("LINK_DEPENDS", cmProperty::TARGET,
  667. "Additional files on which a target binary depends for linking.",
  668. "Specifies a semicolon-separated list of full-paths to files on which "
  669. "the link rule for this target depends. "
  670. "The target binary will be linked if any of the named files is newer "
  671. "than it."
  672. "\n"
  673. "This property is ignored by non-Makefile generators. "
  674. "It is intended to specify dependencies on \"linker scripts\" for "
  675. "custom Makefile link rules.");
  676. cm->DefineProperty
  677. ("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
  678. "Do not depend on linked shared library files.",
  679. "Set this property to true to tell CMake generators not to add "
  680. "file-level dependencies on the shared library files linked by "
  681. "this target. "
  682. "Modification to the shared libraries will not be sufficient to "
  683. "re-link this target. "
  684. "Logical target-level dependencies will not be affected so the "
  685. "linked shared libraries will still be brought up to date before "
  686. "this target is built."
  687. "\n"
  688. "This property is initialized by the value of the variable "
  689. "CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
  690. "created.");
  691. cm->DefineProperty
  692. ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  693. "List public interface libraries for a shared library or executable.",
  694. "By default linking to a shared library target transitively "
  695. "links to targets with which the library itself was linked. "
  696. "For an executable with exports (see the ENABLE_EXPORTS property) "
  697. "no default transitive link dependencies are used. "
  698. "This property replaces the default transitive link dependencies with "
  699. "an explicit list. "
  700. "When the target is linked into another target the libraries "
  701. "listed (and recursively their link interface libraries) will be "
  702. "provided to the other target also. "
  703. "If the list is empty then no transitive link dependencies will be "
  704. "incorporated when this target is linked into another target even if "
  705. "the default set is non-empty. "
  706. "This property is initialized by the value of the variable "
  707. "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
  708. "created. "
  709. "This property is ignored for STATIC libraries.");
  710. cm->DefineProperty
  711. ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  712. "Per-configuration list of public interface libraries for a target.",
  713. "This is the configuration-specific version of "
  714. "LINK_INTERFACE_LIBRARIES. "
  715. "If set, this property completely overrides the generic property "
  716. "for the named configuration.");
  717. cm->DefineProperty
  718. ("INTERFACE_INCLUDE_DIRECTORIES", cmProperty::TARGET,
  719. "List of public include directories for a library.",
  720. "Targets may populate this property to publish the include directories "
  721. "required to compile against the headers for the target. Consuming "
  722. "targets can add entries to their own INCLUDE_DIRECTORIES property such "
  723. "as $<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES> to use the "
  724. "include directories specified in the interface of 'foo'."
  725. "\n"
  726. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  727. cm->DefineProperty
  728. ("INTERFACE_COMPILE_DEFINITIONS", cmProperty::TARGET,
  729. "List of public compile definitions for a library.",
  730. "Targets may populate this property to publish the compile definitions "
  731. "required to compile against the headers for the target. Consuming "
  732. "targets can add entries to their own COMPILE_DEFINITIONS property such "
  733. "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS> to use the "
  734. "compile definitions specified in the interface of 'foo'."
  735. "\n"
  736. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  737. cm->DefineProperty
  738. ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  739. "Repetition count for STATIC libraries with cyclic dependencies.",
  740. "When linking to a STATIC library target with cyclic dependencies the "
  741. "linker may need to scan more than once through the archives in the "
  742. "strongly connected component of the dependency graph. "
  743. "CMake by default constructs the link line so that the linker will "
  744. "scan through the component at least twice. "
  745. "This property specifies the minimum number of scans if it is larger "
  746. "than the default. "
  747. "CMake uses the largest value specified by any target in a component.");
  748. cm->DefineProperty
  749. ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  750. "Per-configuration repetition count for cycles of STATIC libraries.",
  751. "This is the configuration-specific version of "
  752. "LINK_INTERFACE_MULTIPLICITY. "
  753. "If set, this property completely overrides the generic property "
  754. "for the named configuration.");
  755. cm->DefineProperty
  756. ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
  757. "Map from project configuration to IMPORTED target's configuration.",
  758. "Set this to the list of configurations of an imported target that "
  759. "may be used for the current project's <CONFIG> configuration. "
  760. "Targets imported from another project may not provide the same set "
  761. "of configuration names available in the current project. "
  762. "Setting this property tells CMake what imported configurations are "
  763. "suitable for use when building the <CONFIG> configuration. "
  764. "The first configuration in the list found to be provided by the "
  765. "imported target is selected. If this property is set and no matching "
  766. "configurations are available, then the imported target is considered "
  767. "to be not found. This property is ignored for non-imported targets.",
  768. false /* TODO: make this chained */ );
  769. cm->DefineProperty
  770. ("OSX_ARCHITECTURES", cmProperty::TARGET,
  771. "Target specific architectures for OS X.",
  772. "The OSX_ARCHITECTURES property sets the target binary architecture "
  773. "for targets on OS X. "
  774. "This property is initialized by the value of the variable "
  775. "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
  776. "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
  777. "per-configuration basis. "
  778. "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
  779. cm->DefineProperty
  780. ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
  781. "Per-configuration OS X binary architectures for a target.",
  782. "This property is the configuration-specific version of "
  783. "OSX_ARCHITECTURES.");
  784. cm->DefineProperty
  785. ("OUTPUT_NAME", cmProperty::TARGET,
  786. "Output name for target files.",
  787. "This sets the base name for output files created for an executable or "
  788. "library target. "
  789. "If not set, the logical target name is used by default.");
  790. cm->DefineProperty
  791. ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  792. "Per-configuration target file base name.",
  793. "This is the configuration-specific version of OUTPUT_NAME.");
  794. cm->DefineProperty
  795. ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
  796. "Old per-configuration target file base name.",
  797. "This is a configuration-specific version of OUTPUT_NAME. "
  798. "Use OUTPUT_NAME_<CONFIG> instead.");
  799. cm->DefineProperty
  800. ("PDB_NAME", cmProperty::TARGET,
  801. "Output name for MS debug symbols .pdb file.",
  802. "Set the base name for debug symbols file created for an "
  803. "executable or library target. "
  804. "If not set, the logical target name is used by default. "
  805. "\n"
  806. "This property is not implemented by the Visual Studio 6 generator.");
  807. cm->DefineProperty
  808. ("PDB_NAME_<CONFIG>", cmProperty::TARGET,
  809. "Per-configuration name for MS debug symbols .pdb file. ",
  810. "This is the configuration-specific version of PDB_NAME. "
  811. "\n"
  812. "This property is not implemented by the Visual Studio 6 generator.");
  813. cm->DefineProperty
  814. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  815. "Deprecated install support.",
  816. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  817. "old way to specify CMake scripts to run before and after "
  818. "installing a target. They are used only when the old "
  819. "INSTALL_TARGETS command is used to install the target. Use the "
  820. "INSTALL command instead.");
  821. cm->DefineProperty
  822. ("PREFIX", cmProperty::TARGET,
  823. "What comes before the library name.",
  824. "A target property that can be set to override the prefix "
  825. "(such as \"lib\") on a library name.");
  826. cm->DefineProperty
  827. ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  828. "Whether to create a position-independent target",
  829. "The POSITION_INDEPENDENT_CODE property determines whether position "
  830. "independent executables or shared libraries will be created. "
  831. "This property is true by default for SHARED and MODULE library "
  832. "targets and false otherwise. "
  833. "This property is initialized by the value of the variable "
  834. "CMAKE_POSITION_INDEPENDENT_CODE if it is set when a target is "
  835. "created.");
  836. cm->DefineProperty
  837. ("INTERFACE_POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  838. "Whether consumers need to create a position-independent target",
  839. "The INTERFACE_POSITION_INDEPENDENT_CODE property informs consumers of "
  840. "this target whether they must set their POSITION_INDEPENDENT_CODE "
  841. "property to ON. If this property is set to ON, then the "
  842. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  843. "ON. Similarly, if this property is set to OFF, then the "
  844. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  845. "OFF. If this property is undefined, then consumers will determine "
  846. "their POSITION_INDEPENDENT_CODE property by other means. Consumers "
  847. "must ensure that the targets that they link to have a consistent "
  848. "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property.");
  849. cm->DefineProperty
  850. ("COMPATIBLE_INTERFACE_BOOL", cmProperty::TARGET,
  851. "Properties which must be compatible with their link interface",
  852. "The COMPATIBLE_INTERFACE_BOOL property may contain a list of properties"
  853. "for this target which must be consistent when evaluated as a boolean "
  854. "in the INTERFACE of all linked dependees. For example, if a "
  855. "property \"FOO\" appears in the list, then for each dependee, the "
  856. "\"INTERFACE_FOO\" property content in all of its dependencies must be "
  857. "consistent with each other, and with the \"FOO\" property in the "
  858. "dependee. Consistency in this sense has the meaning that if the "
  859. "property is set, then it must have the same boolean value as all "
  860. "others, and if the property is not set, then it is ignored. Note that "
  861. "for each dependee, the set of properties from this property must not "
  862. "intersect with the set of properties from the "
  863. "COMPATIBLE_INTERFACE_STRING property.");
  864. cm->DefineProperty
  865. ("COMPATIBLE_INTERFACE_STRING", cmProperty::TARGET,
  866. "Properties which must be string-compatible with their link interface",
  867. "The COMPATIBLE_INTERFACE_STRING property may contain a list of "
  868. "properties for this target which must be the same when evaluated as "
  869. "a string in the INTERFACE of all linked dependees. For example, "
  870. "if a property \"FOO\" appears in the list, then for each dependee, the "
  871. "\"INTERFACE_FOO\" property content in all of its dependencies must be "
  872. "equal with each other, and with the \"FOO\" property in the dependee. "
  873. "If the property is not set, then it is ignored. Note that for each "
  874. "dependee, the set of properties from this property must not intersect "
  875. "with the set of properties from the COMPATIBLE_INTERFACE_BOOL "
  876. "property.");
  877. cm->DefineProperty
  878. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  879. "Deprecated install support.",
  880. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  881. "old way to specify CMake scripts to run before and after "
  882. "installing a target. They are used only when the old "
  883. "INSTALL_TARGETS command is used to install the target. Use the "
  884. "INSTALL command instead.");
  885. cm->DefineProperty
  886. ("PRIVATE_HEADER", cmProperty::TARGET,
  887. "Specify private header files in a FRAMEWORK shared library target.",
  888. "Shared library targets marked with the FRAMEWORK property generate "
  889. "frameworks on OS X and normal shared libraries on other platforms. "
  890. "This property may be set to a list of header files to be placed "
  891. "in the PrivateHeaders directory inside the framework folder. "
  892. "On non-Apple platforms these headers may be installed using the "
  893. "PRIVATE_HEADER option to the install(TARGETS) command.");
  894. cm->DefineProperty
  895. ("PUBLIC_HEADER", cmProperty::TARGET,
  896. "Specify public header files in a FRAMEWORK shared library target.",
  897. "Shared library targets marked with the FRAMEWORK property generate "
  898. "frameworks on OS X and normal shared libraries on other platforms. "
  899. "This property may be set to a list of header files to be placed "
  900. "in the Headers directory inside the framework folder. "
  901. "On non-Apple platforms these headers may be installed using the "
  902. "PUBLIC_HEADER option to the install(TARGETS) command.");
  903. cm->DefineProperty
  904. ("RESOURCE", cmProperty::TARGET,
  905. "Specify resource files in a FRAMEWORK shared library target.",
  906. "Shared library targets marked with the FRAMEWORK property generate "
  907. "frameworks on OS X and normal shared libraries on other platforms. "
  908. "This property may be set to a list of files to be placed "
  909. "in the Resources directory inside the framework folder. "
  910. "On non-Apple platforms these files may be installed using the "
  911. "RESOURCE option to the install(TARGETS) command.");
  912. cm->DefineProperty
  913. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  914. "Specify a launcher for compile rules.",
  915. "See the global property of the same name for details. "
  916. "This overrides the global and directory property for a target.",
  917. true);
  918. cm->DefineProperty
  919. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  920. "Specify a launcher for link rules.",
  921. "See the global property of the same name for details. "
  922. "This overrides the global and directory property for a target.",
  923. true);
  924. cm->DefineProperty
  925. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  926. "Specify a launcher for custom rules.",
  927. "See the global property of the same name for details. "
  928. "This overrides the global and directory property for a target.",
  929. true);
  930. cm->DefineProperty
  931. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  932. "Should rpaths be used for the build tree.",
  933. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  934. "generation of an rpath allowing the target to run from the "
  935. "build tree. "
  936. "This property is initialized by the value of the variable "
  937. "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
  938. cm->DefineProperty
  939. ("NO_SONAME", cmProperty::TARGET,
  940. "Whether to set \"soname\" when linking a shared library or module.",
  941. "Enable this boolean property if a generated shared library or module "
  942. "should not have \"soname\" set. Default is to set \"soname\" on all "
  943. "shared libraries and modules as long as the platform supports it. "
  944. "Generally, use this property only for leaf private libraries or "
  945. "plugins. If you use it on normal shared libraries which other targets "
  946. "link against, on some platforms a linker will insert a full path to "
  947. "the library (as specified at link time) into the dynamic section of "
  948. "the dependent binary. Therefore, once installed, dynamic loader may "
  949. "eventually fail to locate the library for the binary.");
  950. cm->DefineProperty
  951. ("SOVERSION", cmProperty::TARGET,
  952. "What version number is this target.",
  953. "For shared libraries VERSION and SOVERSION can be used to specify "
  954. "the build version and api version respectively. When building or "
  955. "installing appropriate symlinks are created if the platform "
  956. "supports symlinks and the linker supports so-names. "
  957. "If only one of both is specified the missing is assumed to have "
  958. "the same version number. "
  959. "SOVERSION is ignored if NO_SONAME property is set. "
  960. "For shared libraries and executables on Windows the VERSION "
  961. "attribute is parsed to extract a \"major.minor\" version number. "
  962. "These numbers are used as the image version of the binary. ");
  963. cm->DefineProperty
  964. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  965. "Extra flags to use when linking static libraries.",
  966. "Extra flags to use when linking a static library.");
  967. cm->DefineProperty
  968. ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
  969. "Per-configuration flags for creating a static library.",
  970. "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
  971. cm->DefineProperty
  972. ("SUFFIX", cmProperty::TARGET,
  973. "What comes after the target name.",
  974. "A target property that can be set to override the suffix "
  975. "(such as \".so\" or \".exe\") on the name of a library, module or "
  976. "executable.");
  977. cm->DefineProperty
  978. ("TYPE", cmProperty::TARGET,
  979. "The type of the target.",
  980. "This read-only property can be used to test the type of the given "
  981. "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
  982. "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
  983. cm->DefineProperty
  984. ("VERSION", cmProperty::TARGET,
  985. "What version number is this target.",
  986. "For shared libraries VERSION and SOVERSION can be used to specify "
  987. "the build version and api version respectively. When building or "
  988. "installing appropriate symlinks are created if the platform "
  989. "supports symlinks and the linker supports so-names. "
  990. "If only one of both is specified the missing is assumed to have "
  991. "the same version number. "
  992. "For executables VERSION can be used to specify the build version. "
  993. "When building or installing appropriate symlinks are created if "
  994. "the platform supports symlinks. "
  995. "For shared libraries and executables on Windows the VERSION "
  996. "attribute is parsed to extract a \"major.minor\" version number. "
  997. "These numbers are used as the image version of the binary. ");
  998. cm->DefineProperty
  999. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  1000. "Build an executable with a WinMain entry point on windows.",
  1001. "When this property is set to true the executable when linked "
  1002. "on Windows will be created with a WinMain() entry point instead "
  1003. "of just main(). "
  1004. "This makes it a GUI executable instead of a console application. "
  1005. "See the CMAKE_MFC_FLAG variable documentation to configure use "
  1006. "of MFC for WinMain executables. "
  1007. "This property is initialized by the value of the variable "
  1008. "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
  1009. cm->DefineProperty
  1010. ("MACOSX_BUNDLE", cmProperty::TARGET,
  1011. "Build an executable as an application bundle on Mac OS X.",
  1012. "When this property is set to true the executable when built "
  1013. "on Mac OS X will be created as an application bundle. "
  1014. "This makes it a GUI executable that can be launched from "
  1015. "the Finder. "
  1016. "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
  1017. "about creation of the Info.plist file for the application bundle. "
  1018. "This property is initialized by the value of the variable "
  1019. "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
  1020. cm->DefineProperty
  1021. ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
  1022. "Specify a custom Info.plist template for a Mac OS X App Bundle.",
  1023. "An executable target with MACOSX_BUNDLE enabled will be built as an "
  1024. "application bundle on Mac OS X. "
  1025. "By default its Info.plist file is created by configuring a template "
  1026. "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
  1027. "This property specifies an alternative template file name which "
  1028. "may be a full path.\n"
  1029. "The following target properties may be set to specify content to "
  1030. "be configured into the file:\n"
  1031. " MACOSX_BUNDLE_INFO_STRING\n"
  1032. " MACOSX_BUNDLE_ICON_FILE\n"
  1033. " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
  1034. " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
  1035. " MACOSX_BUNDLE_BUNDLE_NAME\n"
  1036. " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
  1037. " MACOSX_BUNDLE_BUNDLE_VERSION\n"
  1038. " MACOSX_BUNDLE_COPYRIGHT\n"
  1039. "CMake variables of the same name may be set to affect all targets "
  1040. "in a directory that do not have each specific property set. "
  1041. "If a custom Info.plist is specified by this property it may of course "
  1042. "hard-code all the settings instead of using the target properties.");
  1043. cm->DefineProperty
  1044. ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
  1045. "Specify a custom Info.plist template for a Mac OS X Framework.",
  1046. "An library target with FRAMEWORK enabled will be built as a "
  1047. "framework on Mac OS X. "
  1048. "By default its Info.plist file is created by configuring a template "
  1049. "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
  1050. "This property specifies an alternative template file name which "
  1051. "may be a full path.\n"
  1052. "The following target properties may be set to specify content to "
  1053. "be configured into the file:\n"
  1054. " MACOSX_FRAMEWORK_ICON_FILE\n"
  1055. " MACOSX_FRAMEWORK_IDENTIFIER\n"
  1056. " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
  1057. " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
  1058. "CMake variables of the same name may be set to affect all targets "
  1059. "in a directory that do not have each specific property set. "
  1060. "If a custom Info.plist is specified by this property it may of course "
  1061. "hard-code all the settings instead of using the target properties.");
  1062. cm->DefineProperty
  1063. ("ENABLE_EXPORTS", cmProperty::TARGET,
  1064. "Specify whether an executable exports symbols for loadable modules.",
  1065. "Normally an executable does not export any symbols because it is "
  1066. "the final program. It is possible for an executable to export "
  1067. "symbols to be used by loadable modules. When this property is "
  1068. "set to true CMake will allow other targets to \"link\" to the "
  1069. "executable with the TARGET_LINK_LIBRARIES command. "
  1070. "On all platforms a target-level dependency on the executable is "
  1071. "created for targets that link to it. "
  1072. "For DLL platforms an import library will be created for the "
  1073. "exported symbols and then used for linking. "
  1074. "All Windows-based systems including Cygwin are DLL platforms. "
  1075. "For non-DLL platforms that require all symbols to be resolved at "
  1076. "link time, such as Mac OS X, the module will \"link\" to the "
  1077. "executable using a flag like \"-bundle_loader\". "
  1078. "For other non-DLL platforms the link rule is simply ignored since "
  1079. "the dynamic loader will automatically bind symbols when the "
  1080. "module is loaded. "
  1081. );
  1082. cm->DefineProperty
  1083. ("Fortran_FORMAT", cmProperty::TARGET,
  1084. "Set to FIXED or FREE to indicate the Fortran source layout.",
  1085. "This property tells CMake whether the Fortran source files "
  1086. "in a target use fixed-format or free-format. "
  1087. "CMake will pass the corresponding format flag to the compiler. "
  1088. "Use the source-specific Fortran_FORMAT property to change the "
  1089. "format of a specific source file. "
  1090. "If the variable CMAKE_Fortran_FORMAT is set when a target "
  1091. "is created its value is used to initialize this property.");
  1092. cm->DefineProperty
  1093. ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
  1094. "Specify output directory for Fortran modules provided by the target.",
  1095. "If the target contains Fortran source files that provide modules "
  1096. "and the compiler supports a module output directory this specifies "
  1097. "the directory in which the modules will be placed. "
  1098. "When this property is not set the modules will be placed in the "
  1099. "build directory corresponding to the target's source directory. "
  1100. "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
  1101. "is created its value is used to initialize this property."
  1102. "\n"
  1103. "Note that some compilers will automatically search the module output "
  1104. "directory for modules USEd during compilation but others will not. "
  1105. "If your sources USE modules their location must be specified by "
  1106. "INCLUDE_DIRECTORIES regardless of this property.");
  1107. cm->DefineProperty
  1108. ("GNUtoMS", cmProperty::TARGET,
  1109. "Convert GNU import library (.dll.a) to MS format (.lib).",
  1110. "When linking a shared library or executable that exports symbols "
  1111. "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
  1112. "convert the import library (.dll.a) from GNU to MS format (.lib). "
  1113. "Both import libraries will be installed by install(TARGETS) and "
  1114. "exported by install(EXPORT) and export() to be linked by applications "
  1115. "with either GNU- or MS-compatible tools."
  1116. "\n"
  1117. "If the variable CMAKE_GNUtoMS is set when a target "
  1118. "is created its value is used to initialize this property. "
  1119. "The variable must be set prior to the first command that enables "
  1120. "a language such as project() or enable_language(). "
  1121. "CMake provides the variable as an option to the user automatically "
  1122. "when configuring on Windows with GNU tools.");
  1123. cm->DefineProperty
  1124. ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
  1125. "Set Xcode target attributes directly.",
  1126. "Tell the Xcode generator to set '<an-attribute>' to a given value "
  1127. "in the generated Xcode project. Ignored on other generators.");
  1128. cm->DefineProperty
  1129. ("GENERATOR_FILE_NAME", cmProperty::TARGET,
  1130. "Generator's file for this target.",
  1131. "An internal property used by some generators to record the name of "
  1132. "project or dsp file associated with this target. Note that at configure "
  1133. "time, this property is only set for targets created by "
  1134. "include_external_msproject().");
  1135. cm->DefineProperty
  1136. ("SOURCES", cmProperty::TARGET,
  1137. "Source names specified for a target.",
  1138. "Read-only list of sources specified for a target. "
  1139. "The names returned are suitable for passing to the "
  1140. "set_source_files_properties command.");
  1141. cm->DefineProperty
  1142. ("FOLDER", cmProperty::TARGET,
  1143. "Set the folder name. Use to organize targets in an IDE.",
  1144. "Targets with no FOLDER property will appear as top level "
  1145. "entities in IDEs like Visual Studio. Targets with the same "
  1146. "FOLDER property value will appear next to each other in a "
  1147. "folder of that name. To nest folders, use FOLDER values such "
  1148. "as 'GUI/Dialogs' with '/' characters separating folder levels.");
  1149. cm->DefineProperty
  1150. ("PROJECT_LABEL", cmProperty::TARGET,
  1151. "Change the name of a target in an IDE.",
  1152. "Can be used to change the name of the target in an IDE "
  1153. "like Visual Studio. ");
  1154. cm->DefineProperty
  1155. ("VS_KEYWORD", cmProperty::TARGET,
  1156. "Visual Studio project keyword.",
  1157. "Can be set to change the visual studio keyword, for example "
  1158. "Qt integration works better if this is set to Qt4VSv1.0. ");
  1159. cm->DefineProperty
  1160. ("VS_SCC_PROVIDER", cmProperty::TARGET,
  1161. "Visual Studio Source Code Control Provider.",
  1162. "Can be set to change the visual studio source code control "
  1163. "provider property.");
  1164. cm->DefineProperty
  1165. ("VS_SCC_LOCALPATH", cmProperty::TARGET,
  1166. "Visual Studio Source Code Control Local Path.",
  1167. "Can be set to change the visual studio source code control "
  1168. "local path property.");
  1169. cm->DefineProperty
  1170. ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
  1171. "Visual Studio Source Code Control Project.",
  1172. "Can be set to change the visual studio source code control "
  1173. "project name property.");
  1174. cm->DefineProperty
  1175. ("VS_SCC_AUXPATH", cmProperty::TARGET,
  1176. "Visual Studio Source Code Control Aux Path.",
  1177. "Can be set to change the visual studio source code control "
  1178. "auxpath property.");
  1179. cm->DefineProperty
  1180. ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
  1181. "Visual Studio project type(s).",
  1182. "Can be set to one or more UUIDs recognized by Visual Studio "
  1183. "to indicate the type of project. This value is copied "
  1184. "verbatim into the generated project file. Example for a "
  1185. "managed C++ unit testing project:\n"
  1186. " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
  1187. "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
  1188. "UUIDs are semicolon-delimited.");
  1189. cm->DefineProperty
  1190. ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
  1191. "Visual Studio project keyword.",
  1192. "Sets the \"keyword\" attribute for a generated Visual Studio "
  1193. "project. Defaults to \"Win32Proj\". You may wish to override "
  1194. "this value with \"ManagedCProj\", for example, in a Visual "
  1195. "Studio managed C++ unit test project.");
  1196. cm->DefineProperty
  1197. ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
  1198. "Visual Studio managed project .NET references",
  1199. "Adds one or more semicolon-delimited .NET references to a "
  1200. "generated Visual Studio project. For example, \"System;"
  1201. "System.Windows.Forms\".");
  1202. cm->DefineProperty
  1203. ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
  1204. "Visual Studio project C++/CX language extensions for Windows Runtime",
  1205. "Can be set to enable C++/CX language extensions.");
  1206. cm->DefineProperty
  1207. ("VS_WINRT_REFERENCES", cmProperty::TARGET,
  1208. "Visual Studio project Windows Runtime Metadata references",
  1209. "Adds one or more semicolon-delimited WinRT references to a "
  1210. "generated Visual Studio project. For example, \"Windows;"
  1211. "Windows.UI.Core\".");
  1212. cm->DefineProperty
  1213. ("VS_GLOBAL_<variable>", cmProperty::TARGET,
  1214. "Visual Studio project-specific global variable.",
  1215. "Tell the Visual Studio generator to set the global variable "
  1216. "'<variable>' to a given value in the generated Visual Studio "
  1217. "project. Ignored on other generators. Qt integration works "
  1218. "better if VS_GLOBAL_QtVersion is set to the version "
  1219. "FindQt4.cmake found. For example, \"4.7.3\"");
  1220. #define CM_TARGET_FILE_TYPES_DOC \
  1221. "There are three kinds of target files that may be built: " \
  1222. "archive, library, and runtime. " \
  1223. "Executables are always treated as runtime targets. " \
  1224. "Static libraries are always treated as archive targets. " \
  1225. "Module libraries are always treated as library targets. " \
  1226. "For non-DLL platforms shared libraries are treated as library " \
  1227. "targets. " \
  1228. "For DLL platforms the DLL part of a shared library is treated as " \
  1229. "a runtime target and the corresponding import library is treated as " \
  1230. "an archive target. " \
  1231. "All Windows-based systems including Cygwin are DLL platforms."
  1232. #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
  1233. "This property specifies the directory into which " #type " target " \
  1234. "files should be built. " \
  1235. "Multi-configuration generators (VS, Xcode) append " \
  1236. "a per-configuration subdirectory to the specified directory. " \
  1237. CM_TARGET_FILE_TYPES_DOC " " \
  1238. "This property is initialized by the value of the variable " \
  1239. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
  1240. #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
  1241. "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
  1242. "but multi-configuration generators (VS, Xcode) do NOT append " \
  1243. "a per-configuration subdirectory to the specified directory. " \
  1244. "This property is initialized by the value of the variable " \
  1245. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
  1246. "if it is set when a target is created."
  1247. cm->DefineProperty
  1248. ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1249. "Output directory in which to build ARCHIVE target files.",
  1250. CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
  1251. cm->DefineProperty
  1252. ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1253. "Per-configuration output directory for ARCHIVE target files.",
  1254. CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
  1255. cm->DefineProperty
  1256. ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1257. "Output directory in which to build LIBRARY target files.",
  1258. CM_TARGET_OUTDIR_DOC(LIBRARY, library));
  1259. cm->DefineProperty
  1260. ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1261. "Per-configuration output directory for LIBRARY target files.",
  1262. CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
  1263. cm->DefineProperty
  1264. ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1265. "Output directory in which to build RUNTIME target files.",
  1266. CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
  1267. cm->DefineProperty
  1268. ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1269. "Per-configuration output directory for RUNTIME target files.",
  1270. CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
  1271. cm->DefineProperty
  1272. ("PDB_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1273. "Output directory for MS debug symbols .pdb files.",
  1274. "This property specifies the directory into which the MS debug symbols "
  1275. "will be placed. "
  1276. "This property is initialized by the value of the variable "
  1277. "CMAKE_PDB_OUTPUT_DIRECTORY if it is set when a target is created."
  1278. "\n"
  1279. "This property is not implemented by the Visual Studio 6 generator.");
  1280. cm->DefineProperty
  1281. ("PDB_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1282. "Per-configuration output directory for MS debug symbols .pdb files.",
  1283. "This is a per-configuration version of PDB_OUTPUT_DIRECTORY, "
  1284. "but multi-configuration generators (VS, Xcode) do NOT append "
  1285. "a per-configuration subdirectory to the specified directory. "
  1286. "This property is initialized by the value of the variable "
  1287. "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG> "
  1288. "if it is set when a target is created."
  1289. "\n"
  1290. "This property is not implemented by the Visual Studio 6 generator.");
  1291. cm->DefineProperty
  1292. ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
  1293. "Output name for ARCHIVE target files.",
  1294. "This property specifies the base name for archive target files. "
  1295. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1296. CM_TARGET_FILE_TYPES_DOC);
  1297. cm->DefineProperty
  1298. ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1299. "Per-configuration output name for ARCHIVE target files.",
  1300. "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
  1301. cm->DefineProperty
  1302. ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
  1303. "Output name for LIBRARY target files.",
  1304. "This property specifies the base name for library target files. "
  1305. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1306. CM_TARGET_FILE_TYPES_DOC);
  1307. cm->DefineProperty
  1308. ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1309. "Per-configuration output name for LIBRARY target files.",
  1310. "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
  1311. cm->DefineProperty
  1312. ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
  1313. "Output name for RUNTIME target files.",
  1314. "This property specifies the base name for runtime target files. "
  1315. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1316. CM_TARGET_FILE_TYPES_DOC);
  1317. cm->DefineProperty
  1318. ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1319. "Per-configuration output name for RUNTIME target files.",
  1320. "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
  1321. }
  1322. void cmTarget::SetType(TargetType type, const char* name)
  1323. {
  1324. this->Name = name;
  1325. // only add dependency information for library targets
  1326. this->TargetTypeValue = type;
  1327. if(this->TargetTypeValue >= STATIC_LIBRARY
  1328. && this->TargetTypeValue <= MODULE_LIBRARY)
  1329. {
  1330. this->RecordDependencies = true;
  1331. }
  1332. else
  1333. {
  1334. this->RecordDependencies = false;
  1335. }
  1336. }
  1337. //----------------------------------------------------------------------------
  1338. void cmTarget::SetMakefile(cmMakefile* mf)
  1339. {
  1340. // Set our makefile.
  1341. this->Makefile = mf;
  1342. // set the cmake instance of the properties
  1343. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  1344. // Check whether this is a DLL platform.
  1345. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  1346. this->Makefile->IsOn("CYGWIN") ||
  1347. this->Makefile->IsOn("MINGW"));
  1348. // Check whether we are targeting an Apple platform.
  1349. this->IsApple = this->Makefile->IsOn("APPLE");
  1350. // Setup default property values.
  1351. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  1352. this->SetPropertyDefault("INSTALL_RPATH", "");
  1353. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  1354. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  1355. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  1356. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  1357. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  1358. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  1359. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  1360. this->SetPropertyDefault("Fortran_FORMAT", 0);
  1361. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  1362. this->SetPropertyDefault("GNUtoMS", 0);
  1363. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  1364. this->SetPropertyDefault("AUTOMOC", 0);
  1365. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  1366. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  1367. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  1368. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  1369. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  1370. // Collect the set of configuration types.
  1371. std::vector<std::string> configNames;
  1372. mf->GetConfigurations(configNames);
  1373. // Setup per-configuration property default values.
  1374. const char* configProps[] = {
  1375. "ARCHIVE_OUTPUT_DIRECTORY_",
  1376. "LIBRARY_OUTPUT_DIRECTORY_",
  1377. "RUNTIME_OUTPUT_DIRECTORY_",
  1378. "PDB_OUTPUT_DIRECTORY_",
  1379. 0};
  1380. for(std::vector<std::string>::iterator ci = configNames.begin();
  1381. ci != configNames.end(); ++ci)
  1382. {
  1383. std::string configUpper = cmSystemTools::UpperCase(*ci);
  1384. for(const char** p = configProps; *p; ++p)
  1385. {
  1386. std::string property = *p;
  1387. property += configUpper;
  1388. this->SetPropertyDefault(property.c_str(), 0);
  1389. }
  1390. // Initialize per-configuration name postfix property from the
  1391. // variable only for non-executable targets. This preserves
  1392. // compatibility with previous CMake versions in which executables
  1393. // did not support this variable. Projects may still specify the
  1394. // property directly. TODO: Make this depend on backwards
  1395. // compatibility setting.
  1396. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  1397. {
  1398. std::string property = cmSystemTools::UpperCase(*ci);
  1399. property += "_POSTFIX";
  1400. this->SetPropertyDefault(property.c_str(), 0);
  1401. }
  1402. }
  1403. // Save the backtrace of target construction.
  1404. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  1405. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  1406. // of the same directory property:
  1407. const std::vector<cmValueWithOrigin> parentIncludes =
  1408. this->Makefile->GetIncludeDirectoriesEntries();
  1409. for (std::vector<cmValueWithOrigin>::const_iterator it
  1410. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  1411. {
  1412. this->InsertInclude(*it);
  1413. }
  1414. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  1415. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  1416. {
  1417. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  1418. }
  1419. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  1420. // Record current policies for later use.
  1421. this->PolicyStatusCMP0003 =
  1422. this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
  1423. this->PolicyStatusCMP0004 =
  1424. this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
  1425. this->PolicyStatusCMP0008 =
  1426. this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
  1427. this->PolicyStatusCMP0020 =
  1428. this->Makefile->GetPolicyStatus(cmPolicies::CMP0020);
  1429. }
  1430. //----------------------------------------------------------------------------
  1431. void cmTarget::FinishConfigure()
  1432. {
  1433. // Erase any cached link information that might have been comptued
  1434. // on-demand during the configuration. This ensures that build
  1435. // system generation uses up-to-date information even if other cache
  1436. // invalidation code in this source file is buggy.
  1437. this->ClearLinkMaps();
  1438. // Do old-style link dependency analysis.
  1439. this->AnalyzeLibDependencies(*this->Makefile);
  1440. }
  1441. //----------------------------------------------------------------------------
  1442. void cmTarget::ClearLinkMaps()
  1443. {
  1444. this->Internal->LinkImplMap.clear();
  1445. this->Internal->LinkInterfaceMap.clear();
  1446. this->Internal->LinkClosureMap.clear();
  1447. for (cmTargetLinkInformationMap::const_iterator it
  1448. = this->LinkInformation.begin();
  1449. it != this->LinkInformation.end(); ++it)
  1450. {
  1451. delete it->second;
  1452. }
  1453. this->LinkInformation.clear();
  1454. }
  1455. //----------------------------------------------------------------------------
  1456. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  1457. {
  1458. return this->Internal->Backtrace;
  1459. }
  1460. //----------------------------------------------------------------------------
  1461. std::string cmTarget::GetSupportDirectory() const
  1462. {
  1463. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1464. dir += cmake::GetCMakeFilesDirectory();
  1465. dir += "/";
  1466. dir += this->Name;
  1467. #if defined(__VMS)
  1468. dir += "_dir";
  1469. #else
  1470. dir += ".dir";
  1471. #endif
  1472. return dir;
  1473. }
  1474. //----------------------------------------------------------------------------
  1475. bool cmTarget::IsExecutableWithExports()
  1476. {
  1477. return (this->GetType() == cmTarget::EXECUTABLE &&
  1478. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1479. }
  1480. //----------------------------------------------------------------------------
  1481. bool cmTarget::IsLinkable()
  1482. {
  1483. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  1484. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1485. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1486. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  1487. this->IsExecutableWithExports());
  1488. }
  1489. //----------------------------------------------------------------------------
  1490. bool cmTarget::HasImportLibrary()
  1491. {
  1492. return (this->DLLPlatform &&
  1493. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  1494. this->IsExecutableWithExports()));
  1495. }
  1496. //----------------------------------------------------------------------------
  1497. bool cmTarget::IsFrameworkOnApple()
  1498. {
  1499. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  1500. this->Makefile->IsOn("APPLE") &&
  1501. this->GetPropertyAsBool("FRAMEWORK"));
  1502. }
  1503. //----------------------------------------------------------------------------
  1504. bool cmTarget::IsAppBundleOnApple()
  1505. {
  1506. return (this->GetType() == cmTarget::EXECUTABLE &&
  1507. this->Makefile->IsOn("APPLE") &&
  1508. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  1509. }
  1510. //----------------------------------------------------------------------------
  1511. bool cmTarget::IsCFBundleOnApple()
  1512. {
  1513. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  1514. this->Makefile->IsOn("APPLE") &&
  1515. this->GetPropertyAsBool("BUNDLE"));
  1516. }
  1517. //----------------------------------------------------------------------------
  1518. class cmTargetTraceDependencies
  1519. {
  1520. public:
  1521. cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1522. const char* vsProjectFile);
  1523. void Trace();
  1524. private:
  1525. cmTarget* Target;
  1526. cmTargetInternals* Internal;
  1527. cmMakefile* Makefile;
  1528. cmGlobalGenerator* GlobalGenerator;
  1529. typedef cmTargetInternals::SourceEntry SourceEntry;
  1530. SourceEntry* CurrentEntry;
  1531. std::queue<cmSourceFile*> SourceQueue;
  1532. std::set<cmSourceFile*> SourcesQueued;
  1533. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  1534. NameMapType NameMap;
  1535. void QueueSource(cmSourceFile* sf);
  1536. void FollowName(std::string const& name);
  1537. void FollowNames(std::vector<std::string> const& names);
  1538. bool IsUtility(std::string const& dep);
  1539. void CheckCustomCommand(cmCustomCommand const& cc);
  1540. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1541. };
  1542. //----------------------------------------------------------------------------
  1543. cmTargetTraceDependencies
  1544. ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1545. const char* vsProjectFile):
  1546. Target(target), Internal(internal)
  1547. {
  1548. // Convenience.
  1549. this->Makefile = this->Target->GetMakefile();
  1550. this->GlobalGenerator =
  1551. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  1552. this->CurrentEntry = 0;
  1553. // Queue all the source files already specified for the target.
  1554. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  1555. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1556. si != sources.end(); ++si)
  1557. {
  1558. this->QueueSource(*si);
  1559. }
  1560. // Queue the VS project file to check dependencies on the rule to
  1561. // generate it.
  1562. if(vsProjectFile)
  1563. {
  1564. this->FollowName(vsProjectFile);
  1565. }
  1566. // Queue pre-build, pre-link, and post-build rule dependencies.
  1567. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1568. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1569. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1570. }
  1571. //----------------------------------------------------------------------------
  1572. void cmTargetTraceDependencies::Trace()
  1573. {
  1574. // Process one dependency at a time until the queue is empty.
  1575. while(!this->SourceQueue.empty())
  1576. {
  1577. // Get the next source from the queue.
  1578. cmSourceFile* sf = this->SourceQueue.front();
  1579. this->SourceQueue.pop();
  1580. this->CurrentEntry = &this->Internal->SourceEntries[sf];
  1581. // Queue dependencies added explicitly by the user.
  1582. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1583. {
  1584. std::vector<std::string> objDeps;
  1585. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1586. this->FollowNames(objDeps);
  1587. }
  1588. // Queue the source needed to generate this file, if any.
  1589. this->FollowName(sf->GetFullPath());
  1590. // Queue dependencies added programatically by commands.
  1591. this->FollowNames(sf->GetDepends());
  1592. // Queue custom command dependencies.
  1593. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1594. {
  1595. this->CheckCustomCommand(*cc);
  1596. }
  1597. }
  1598. this->CurrentEntry = 0;
  1599. }
  1600. //----------------------------------------------------------------------------
  1601. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1602. {
  1603. if(this->SourcesQueued.insert(sf).second)
  1604. {
  1605. this->SourceQueue.push(sf);
  1606. // Make sure this file is in the target.
  1607. this->Target->AddSourceFile(sf);
  1608. }
  1609. }
  1610. //----------------------------------------------------------------------------
  1611. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1612. {
  1613. NameMapType::iterator i = this->NameMap.find(name);
  1614. if(i == this->NameMap.end())
  1615. {
  1616. // Check if we know how to generate this file.
  1617. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  1618. NameMapType::value_type entry(name, sf);
  1619. i = this->NameMap.insert(entry).first;
  1620. }
  1621. if(cmSourceFile* sf = i->second)
  1622. {
  1623. // Record the dependency we just followed.
  1624. if(this->CurrentEntry)
  1625. {
  1626. this->CurrentEntry->Depends.push_back(sf);
  1627. }
  1628. this->QueueSource(sf);
  1629. }
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. void
  1633. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1634. {
  1635. for(std::vector<std::string>::const_iterator i = names.begin();
  1636. i != names.end(); ++i)
  1637. {
  1638. this->FollowName(*i);
  1639. }
  1640. }
  1641. //----------------------------------------------------------------------------
  1642. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1643. {
  1644. // Dependencies on targets (utilities) are supposed to be named by
  1645. // just the target name. However for compatibility we support
  1646. // naming the output file generated by the target (assuming there is
  1647. // no output-name property which old code would not have set). In
  1648. // that case the target name will be the file basename of the
  1649. // dependency.
  1650. std::string util = cmSystemTools::GetFilenameName(dep);
  1651. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1652. {
  1653. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1654. }
  1655. // Check for a target with this name.
  1656. if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
  1657. {
  1658. // If we find the target and the dep was given as a full path,
  1659. // then make sure it was not a full path to something else, and
  1660. // the fact that the name matched a target was just a coincidence.
  1661. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1662. {
  1663. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1664. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1665. {
  1666. // This is really only for compatibility so we do not need to
  1667. // worry about configuration names and output names.
  1668. std::string tLocation = t->GetLocation(0);
  1669. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1670. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1671. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1672. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1673. if(depLocation == tLocation)
  1674. {
  1675. this->Target->AddUtility(util.c_str());
  1676. return true;
  1677. }
  1678. }
  1679. }
  1680. else
  1681. {
  1682. // The original name of the dependency was not a full path. It
  1683. // must name a target, so add the target-level dependency.
  1684. this->Target->AddUtility(util.c_str());
  1685. return true;
  1686. }
  1687. }
  1688. // The dependency does not name a target built in this project.
  1689. return false;
  1690. }
  1691. //----------------------------------------------------------------------------
  1692. void
  1693. cmTargetTraceDependencies
  1694. ::CheckCustomCommand(cmCustomCommand const& cc)
  1695. {
  1696. // Transform command names that reference targets built in this
  1697. // project to corresponding target-level dependencies.
  1698. cmGeneratorExpression ge(cc.GetBacktrace());
  1699. // Add target-level dependencies referenced by generator expressions.
  1700. std::set<cmTarget*> targets;
  1701. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1702. cit != cc.GetCommandLines().end(); ++cit)
  1703. {
  1704. std::string const& command = *cit->begin();
  1705. // Check for a target with this name.
  1706. if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
  1707. {
  1708. if(t->GetType() == cmTarget::EXECUTABLE)
  1709. {
  1710. // The command refers to an executable target built in
  1711. // this project. Add the target-level dependency to make
  1712. // sure the executable is up to date before this custom
  1713. // command possibly runs.
  1714. this->Target->AddUtility(command.c_str());
  1715. }
  1716. }
  1717. // Check for target references in generator expressions.
  1718. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1719. cli != cit->end(); ++cli)
  1720. {
  1721. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1722. = ge.Parse(*cli);
  1723. cge->Evaluate(this->Makefile, 0, true);
  1724. std::set<cmTarget*> geTargets = cge->GetTargets();
  1725. for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
  1726. it != geTargets.end(); ++it)
  1727. {
  1728. targets.insert(*it);
  1729. }
  1730. }
  1731. }
  1732. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1733. ti != targets.end(); ++ti)
  1734. {
  1735. this->Target->AddUtility((*ti)->GetName());
  1736. }
  1737. // Queue the custom command dependencies.
  1738. std::vector<std::string> const& depends = cc.GetDepends();
  1739. for(std::vector<std::string>::const_iterator di = depends.begin();
  1740. di != depends.end(); ++di)
  1741. {
  1742. std::string const& dep = *di;
  1743. if(!this->IsUtility(dep))
  1744. {
  1745. // The dependency does not name a target and may be a file we
  1746. // know how to generate. Queue it.
  1747. this->FollowName(dep);
  1748. }
  1749. }
  1750. }
  1751. //----------------------------------------------------------------------------
  1752. void
  1753. cmTargetTraceDependencies
  1754. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1755. {
  1756. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1757. cli != commands.end(); ++cli)
  1758. {
  1759. this->CheckCustomCommand(*cli);
  1760. }
  1761. }
  1762. //----------------------------------------------------------------------------
  1763. void cmTarget::TraceDependencies(const char* vsProjectFile)
  1764. {
  1765. // CMake-generated targets have no dependencies to trace. Normally tracing
  1766. // would find nothing anyway, but when building CMake itself the "install"
  1767. // target command ends up referencing the "cmake" target but we do not
  1768. // really want the dependency because "install" depend on "all" anyway.
  1769. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1770. {
  1771. return;
  1772. }
  1773. // Use a helper object to trace the dependencies.
  1774. cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
  1775. tracer.Trace();
  1776. }
  1777. //----------------------------------------------------------------------------
  1778. bool cmTarget::FindSourceFiles()
  1779. {
  1780. for(std::vector<cmSourceFile*>::const_iterator
  1781. si = this->SourceFiles.begin();
  1782. si != this->SourceFiles.end(); ++si)
  1783. {
  1784. std::string e;
  1785. if((*si)->GetFullPath(&e).empty())
  1786. {
  1787. if(!e.empty())
  1788. {
  1789. cmake* cm = this->Makefile->GetCMakeInstance();
  1790. cm->IssueMessage(cmake::FATAL_ERROR, e,
  1791. this->GetBacktrace());
  1792. }
  1793. return false;
  1794. }
  1795. }
  1796. return true;
  1797. }
  1798. //----------------------------------------------------------------------------
  1799. std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
  1800. {
  1801. return this->SourceFiles;
  1802. }
  1803. //----------------------------------------------------------------------------
  1804. void cmTarget::AddSourceFile(cmSourceFile* sf)
  1805. {
  1806. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1807. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1808. if(i == this->Internal->SourceEntries.end())
  1809. {
  1810. typedef cmTargetInternals::SourceEntry SourceEntry;
  1811. SourceEntriesType::value_type entry(sf, SourceEntry());
  1812. i = this->Internal->SourceEntries.insert(entry).first;
  1813. this->SourceFiles.push_back(sf);
  1814. }
  1815. }
  1816. //----------------------------------------------------------------------------
  1817. std::vector<cmSourceFile*> const*
  1818. cmTarget::GetSourceDepends(cmSourceFile* sf)
  1819. {
  1820. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1821. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1822. if(i != this->Internal->SourceEntries.end())
  1823. {
  1824. return &i->second.Depends;
  1825. }
  1826. return 0;
  1827. }
  1828. //----------------------------------------------------------------------------
  1829. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1830. {
  1831. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1832. i != srcs.end(); ++i)
  1833. {
  1834. const char* src = i->c_str();
  1835. if(src[0] == '$' && src[1] == '<')
  1836. {
  1837. this->ProcessSourceExpression(*i);
  1838. }
  1839. else
  1840. {
  1841. this->AddSource(src);
  1842. }
  1843. }
  1844. }
  1845. //----------------------------------------------------------------------------
  1846. cmSourceFile* cmTarget::AddSource(const char* s)
  1847. {
  1848. std::string src = s;
  1849. // For backwards compatibility replace varibles in source names.
  1850. // This should eventually be removed.
  1851. this->Makefile->ExpandVariablesInString(src);
  1852. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  1853. this->AddSourceFile(sf);
  1854. return sf;
  1855. }
  1856. //----------------------------------------------------------------------------
  1857. void cmTarget::ProcessSourceExpression(std::string const& expr)
  1858. {
  1859. if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
  1860. expr[expr.size()-1] == '>')
  1861. {
  1862. std::string objLibName = expr.substr(17, expr.size()-18);
  1863. this->ObjectLibraries.push_back(objLibName);
  1864. }
  1865. else
  1866. {
  1867. cmOStringStream e;
  1868. e << "Unrecognized generator expression:\n"
  1869. << " " << expr;
  1870. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1871. }
  1872. }
  1873. //----------------------------------------------------------------------------
  1874. struct cmTarget::SourceFileFlags
  1875. cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
  1876. {
  1877. struct SourceFileFlags flags;
  1878. this->ConstructSourceFileFlags();
  1879. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1880. this->Internal->SourceFlagsMap.find(sf);
  1881. if(si != this->Internal->SourceFlagsMap.end())
  1882. {
  1883. flags = si->second;
  1884. }
  1885. return flags;
  1886. }
  1887. //----------------------------------------------------------------------------
  1888. void cmTarget::ConstructSourceFileFlags()
  1889. {
  1890. if(this->Internal->SourceFileFlagsConstructed)
  1891. {
  1892. return;
  1893. }
  1894. this->Internal->SourceFileFlagsConstructed = true;
  1895. // Process public headers to mark the source files.
  1896. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  1897. {
  1898. std::vector<std::string> relFiles;
  1899. cmSystemTools::ExpandListArgument(files, relFiles);
  1900. for(std::vector<std::string>::iterator it = relFiles.begin();
  1901. it != relFiles.end(); ++it)
  1902. {
  1903. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1904. {
  1905. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1906. flags.MacFolder = "Headers";
  1907. flags.Type = cmTarget::SourceFileTypePublicHeader;
  1908. }
  1909. }
  1910. }
  1911. // Process private headers after public headers so that they take
  1912. // precedence if a file is listed in both.
  1913. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  1914. {
  1915. std::vector<std::string> relFiles;
  1916. cmSystemTools::ExpandListArgument(files, relFiles);
  1917. for(std::vector<std::string>::iterator it = relFiles.begin();
  1918. it != relFiles.end(); ++it)
  1919. {
  1920. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1921. {
  1922. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1923. flags.MacFolder = "PrivateHeaders";
  1924. flags.Type = cmTarget::SourceFileTypePrivateHeader;
  1925. }
  1926. }
  1927. }
  1928. // Mark sources listed as resources.
  1929. if(const char* files = this->GetProperty("RESOURCE"))
  1930. {
  1931. std::vector<std::string> relFiles;
  1932. cmSystemTools::ExpandListArgument(files, relFiles);
  1933. for(std::vector<std::string>::iterator it = relFiles.begin();
  1934. it != relFiles.end(); ++it)
  1935. {
  1936. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1937. {
  1938. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1939. flags.MacFolder = "Resources";
  1940. flags.Type = cmTarget::SourceFileTypeResource;
  1941. }
  1942. }
  1943. }
  1944. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1945. // were not listed in one of the other lists.
  1946. std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
  1947. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1948. si != sources.end(); ++si)
  1949. {
  1950. cmSourceFile* sf = *si;
  1951. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1952. {
  1953. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1954. if(flags.Type == cmTarget::SourceFileTypeNormal)
  1955. {
  1956. flags.MacFolder = location;
  1957. if(strcmp(location, "Resources") == 0)
  1958. {
  1959. flags.Type = cmTarget::SourceFileTypeResource;
  1960. }
  1961. else
  1962. {
  1963. flags.Type = cmTarget::SourceFileTypeMacContent;
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969. //----------------------------------------------------------------------------
  1970. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  1971. const char *selfname,
  1972. const LinkLibraryVectorType& libs )
  1973. {
  1974. // Only add on libraries we haven't added on before.
  1975. // Assumption: the global link libraries could only grow, never shrink
  1976. LinkLibraryVectorType::const_iterator i = libs.begin();
  1977. i += this->PrevLinkedLibraries.size();
  1978. for( ; i != libs.end(); ++i )
  1979. {
  1980. // We call this so that the dependencies get written to the cache
  1981. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  1982. }
  1983. this->PrevLinkedLibraries = libs;
  1984. }
  1985. //----------------------------------------------------------------------------
  1986. void cmTarget::AddLinkDirectory(const char* d)
  1987. {
  1988. // Make sure we don't add unnecessary search directories.
  1989. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1990. {
  1991. this->LinkDirectories.push_back(d);
  1992. }
  1993. }
  1994. //----------------------------------------------------------------------------
  1995. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  1996. {
  1997. return this->LinkDirectories;
  1998. }
  1999. //----------------------------------------------------------------------------
  2000. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
  2001. {
  2002. // No configuration is always optimized.
  2003. if(!(config && *config))
  2004. {
  2005. return cmTarget::OPTIMIZED;
  2006. }
  2007. // Get the list of configurations considered to be DEBUG.
  2008. std::vector<std::string> const& debugConfigs =
  2009. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  2010. // Check if any entry in the list matches this configuration.
  2011. std::string configUpper = cmSystemTools::UpperCase(config);
  2012. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  2013. i != debugConfigs.end(); ++i)
  2014. {
  2015. if(*i == configUpper)
  2016. {
  2017. return cmTarget::DEBUG;
  2018. }
  2019. }
  2020. // The current configuration is not a debug configuration.
  2021. return cmTarget::OPTIMIZED;
  2022. }
  2023. //----------------------------------------------------------------------------
  2024. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  2025. const char* target )
  2026. {
  2027. // Clear the dependencies. The cache variable must exist iff we are
  2028. // recording dependency information for this target.
  2029. std::string depname = target;
  2030. depname += "_LIB_DEPENDS";
  2031. if (this->RecordDependencies)
  2032. {
  2033. mf.AddCacheDefinition(depname.c_str(), "",
  2034. "Dependencies for target", cmCacheManager::STATIC);
  2035. }
  2036. else
  2037. {
  2038. if (mf.GetDefinition( depname.c_str() ))
  2039. {
  2040. std::string message = "Target ";
  2041. message += target;
  2042. message += " has dependency information when it shouldn't.\n";
  2043. message += "Your cache is probably stale. Please remove the entry\n ";
  2044. message += depname;
  2045. message += "\nfrom the cache.";
  2046. cmSystemTools::Error( message.c_str() );
  2047. }
  2048. }
  2049. }
  2050. //----------------------------------------------------------------------------
  2051. bool cmTarget::NameResolvesToFramework(const std::string& libname)
  2052. {
  2053. return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
  2054. NameResolvesToFramework(libname);
  2055. }
  2056. //----------------------------------------------------------------------------
  2057. void cmTarget::GetDirectLinkLibraries(const char *config,
  2058. std::vector<std::string> &libs, cmTarget *head)
  2059. {
  2060. const char *prop = this->GetProperty("LINK_LIBRARIES");
  2061. if (prop)
  2062. {
  2063. cmListFileBacktrace lfbt;
  2064. cmGeneratorExpression ge(lfbt);
  2065. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  2066. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2067. this->GetName(),
  2068. "LINK_LIBRARIES", 0, 0);
  2069. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  2070. config,
  2071. false,
  2072. head,
  2073. &dagChecker),
  2074. libs);
  2075. std::set<cmStdString> seenProps = cge->GetSeenTargetProperties();
  2076. for (std::set<cmStdString>::const_iterator it = seenProps.begin();
  2077. it != seenProps.end(); ++it)
  2078. {
  2079. if (!this->GetProperty(it->c_str()))
  2080. {
  2081. this->LinkImplicitNullProperties.insert(*it);
  2082. }
  2083. }
  2084. }
  2085. }
  2086. //----------------------------------------------------------------------------
  2087. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  2088. cmTarget::LinkLibraryType llt)
  2089. {
  2090. if (llt == GENERAL)
  2091. {
  2092. return value;
  2093. }
  2094. // Get the list of configurations considered to be DEBUG.
  2095. std::vector<std::string> const& debugConfigs =
  2096. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  2097. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  2098. if (debugConfigs.size() > 1)
  2099. {
  2100. for(std::vector<std::string>::const_iterator
  2101. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  2102. {
  2103. configString += ",$<CONFIG:" + *li + ">";
  2104. }
  2105. configString = "$<OR:" + configString + ">";
  2106. }
  2107. if (llt == OPTIMIZED)
  2108. {
  2109. configString = "$<NOT:" + configString + ">";
  2110. }
  2111. return "$<" + configString + ":" + value + ">";
  2112. }
  2113. //----------------------------------------------------------------------------
  2114. static std::string targetNameGenex(const char *lib)
  2115. {
  2116. return std::string("$<TARGET_NAME:") + lib + ">";
  2117. }
  2118. //----------------------------------------------------------------------------
  2119. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  2120. const char *target, const char* lib,
  2121. LinkLibraryType llt)
  2122. {
  2123. // Never add a self dependency, even if the user asks for it.
  2124. if(strcmp( target, lib ) == 0)
  2125. {
  2126. return;
  2127. }
  2128. {
  2129. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  2130. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  2131. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  2132. ? targetNameGenex(lib)
  2133. : std::string(lib);
  2134. this->AppendProperty("LINK_LIBRARIES",
  2135. this->GetDebugGeneratorExpressions(libName,
  2136. llt).c_str());
  2137. }
  2138. if (cmGeneratorExpression::Find(lib) != std::string::npos)
  2139. {
  2140. return;
  2141. }
  2142. cmTarget::LibraryID tmp;
  2143. tmp.first = lib;
  2144. tmp.second = llt;
  2145. this->LinkLibraries.push_back( tmp );
  2146. this->OriginalLinkLibraries.push_back(tmp);
  2147. this->ClearLinkMaps();
  2148. // Add the explicit dependency information for this target. This is
  2149. // simply a set of libraries separated by ";". There should always
  2150. // be a trailing ";". These library names are not canonical, in that
  2151. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  2152. // We shouldn't remove duplicates here because external libraries
  2153. // may be purposefully duplicated to handle recursive dependencies,
  2154. // and we removing one instance will break the link line. Duplicates
  2155. // will be appropriately eliminated at emit time.
  2156. if(this->RecordDependencies)
  2157. {
  2158. std::string targetEntry = target;
  2159. targetEntry += "_LIB_DEPENDS";
  2160. std::string dependencies;
  2161. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  2162. if( old_val )
  2163. {
  2164. dependencies += old_val;
  2165. }
  2166. switch (llt)
  2167. {
  2168. case cmTarget::GENERAL:
  2169. dependencies += "general";
  2170. break;
  2171. case cmTarget::DEBUG:
  2172. dependencies += "debug";
  2173. break;
  2174. case cmTarget::OPTIMIZED:
  2175. dependencies += "optimized";
  2176. break;
  2177. }
  2178. dependencies += ";";
  2179. dependencies += lib;
  2180. dependencies += ";";
  2181. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  2182. "Dependencies for the target",
  2183. cmCacheManager::STATIC );
  2184. }
  2185. }
  2186. //----------------------------------------------------------------------------
  2187. void
  2188. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  2189. {
  2190. // There are two key parts of the dependency analysis: (1)
  2191. // determining the libraries in the link line, and (2) constructing
  2192. // the dependency graph for those libraries.
  2193. //
  2194. // The latter is done using the cache entries that record the
  2195. // dependencies of each library.
  2196. //
  2197. // The former is a more thorny issue, since it is not clear how to
  2198. // determine if two libraries listed on the link line refer to the a
  2199. // single library or not. For example, consider the link "libraries"
  2200. // /usr/lib/libtiff.so -ltiff
  2201. // Is this one library or two? The solution implemented here is the
  2202. // simplest (and probably the only practical) one: two libraries are
  2203. // the same if their "link strings" are identical. Thus, the two
  2204. // libraries above are considered distinct. This also means that for
  2205. // dependency analysis to be effective, the CMake user must specify
  2206. // libraries build by his project without using any linker flags or
  2207. // file extensions. That is,
  2208. // LINK_LIBRARIES( One Two )
  2209. // instead of
  2210. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  2211. // The former is probably what most users would do, but it never
  2212. // hurts to document the assumptions. :-) Therefore, in the analysis
  2213. // code, the "canonical name" of a library is simply its name as
  2214. // given to a LINK_LIBRARIES command.
  2215. //
  2216. // Also, we will leave the original link line intact; we will just add any
  2217. // dependencies that were missing.
  2218. //
  2219. // There is a problem with recursive external libraries
  2220. // (i.e. libraries with no dependency information that are
  2221. // recursively dependent). We must make sure that the we emit one of
  2222. // the libraries twice to satisfy the recursion, but we shouldn't
  2223. // emit it more times than necessary. In particular, we must make
  2224. // sure that handling this improbable case doesn't cost us when
  2225. // dealing with the common case of non-recursive libraries. The
  2226. // solution is to assume that the recursion is satisfied at one node
  2227. // of the dependency tree. To illustrate, assume libA and libB are
  2228. // extrenal and mutually dependent. Suppose libX depends on
  2229. // libA, and libY on libA and libX. Then
  2230. // TARGET_LINK_LIBRARIES( Y X A B A )
  2231. // TARGET_LINK_LIBRARIES( X A B A )
  2232. // TARGET_LINK_LIBRARIES( Exec Y )
  2233. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  2234. // specify the dependencies, since the mutual dependency of A and B
  2235. // is resolved *every time libA is specified*.
  2236. //
  2237. // Something like
  2238. // TARGET_LINK_LIBRARIES( Y X A B A )
  2239. // TARGET_LINK_LIBRARIES( X A B )
  2240. // TARGET_LINK_LIBRARIES( Exec Y )
  2241. // would result in "-lY -lX -lA -lB", and the mutual dependency
  2242. // information is lost. This is because in some case (Y), the mutual
  2243. // dependency of A and B is listed, while in another other case (X),
  2244. // it is not. Depending on which line actually emits A, the mutual
  2245. // dependency may or may not be on the final link line. We can't
  2246. // handle this pathalogical case cleanly without emitting extra
  2247. // libraries for the normal cases. Besides, the dependency
  2248. // information for X is wrong anyway: if we build an executable
  2249. // depending on X alone, we would not have the mutual dependency on
  2250. // A and B resolved.
  2251. //
  2252. // IMPROVEMENTS:
  2253. // -- The current algorithm will not always pick the "optimal" link line
  2254. // when recursive dependencies are present. It will instead break the
  2255. // cycles at an aribtrary point. The majority of projects won't have
  2256. // cyclic dependencies, so this is probably not a big deal. Note that
  2257. // the link line is always correct, just not necessary optimal.
  2258. {
  2259. // Expand variables in link library names. This is for backwards
  2260. // compatibility with very early CMake versions and should
  2261. // eventually be removed. This code was moved here from the end of
  2262. // old source list processing code which was called just before this
  2263. // method.
  2264. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  2265. p != this->LinkLibraries.end(); ++p)
  2266. {
  2267. this->Makefile->ExpandVariablesInString(p->first, true, true);
  2268. }
  2269. }
  2270. typedef std::vector< std::string > LinkLine;
  2271. // The dependency map.
  2272. DependencyMap dep_map;
  2273. // 1. Build the dependency graph
  2274. //
  2275. for(LinkLibraryVectorType::reverse_iterator lib
  2276. = this->LinkLibraries.rbegin();
  2277. lib != this->LinkLibraries.rend(); ++lib)
  2278. {
  2279. this->GatherDependencies( mf, *lib, dep_map);
  2280. }
  2281. // 2. Remove any dependencies that are already satisfied in the original
  2282. // link line.
  2283. //
  2284. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  2285. lib != this->LinkLibraries.end(); ++lib)
  2286. {
  2287. for( LinkLibraryVectorType::iterator lib2 = lib;
  2288. lib2 != this->LinkLibraries.end(); ++lib2)
  2289. {
  2290. this->DeleteDependency( dep_map, *lib, *lib2);
  2291. }
  2292. }
  2293. // 3. Create the new link line by simply emitting any dependencies that are
  2294. // missing. Start from the back and keep adding.
  2295. //
  2296. std::set<DependencyMap::key_type> done, visited;
  2297. std::vector<DependencyMap::key_type> newLinkLibraries;
  2298. for(LinkLibraryVectorType::reverse_iterator lib =
  2299. this->LinkLibraries.rbegin();
  2300. lib != this->LinkLibraries.rend(); ++lib)
  2301. {
  2302. // skip zero size library entries, this may happen
  2303. // if a variable expands to nothing.
  2304. if (lib->first.size() != 0)
  2305. {
  2306. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  2307. }
  2308. }
  2309. // 4. Add the new libraries to the link line.
  2310. //
  2311. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  2312. newLinkLibraries.rbegin();
  2313. k != newLinkLibraries.rend(); ++k )
  2314. {
  2315. // get the llt from the dep_map
  2316. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  2317. }
  2318. this->LinkLibrariesAnalyzed = true;
  2319. }
  2320. //----------------------------------------------------------------------------
  2321. void cmTarget::InsertDependency( DependencyMap& depMap,
  2322. const LibraryID& lib,
  2323. const LibraryID& dep)
  2324. {
  2325. depMap[lib].push_back(dep);
  2326. }
  2327. //----------------------------------------------------------------------------
  2328. void cmTarget::DeleteDependency( DependencyMap& depMap,
  2329. const LibraryID& lib,
  2330. const LibraryID& dep)
  2331. {
  2332. // Make sure there is an entry in the map for lib. If so, delete all
  2333. // dependencies to dep. There may be repeated entries because of
  2334. // external libraries that are specified multiple times.
  2335. DependencyMap::iterator map_itr = depMap.find( lib );
  2336. if( map_itr != depMap.end() )
  2337. {
  2338. DependencyList& depList = map_itr->second;
  2339. DependencyList::iterator itr;
  2340. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  2341. depList.end() )
  2342. {
  2343. depList.erase( itr );
  2344. }
  2345. }
  2346. }
  2347. //----------------------------------------------------------------------------
  2348. void cmTarget::Emit(const LibraryID lib,
  2349. const DependencyMap& dep_map,
  2350. std::set<LibraryID>& emitted,
  2351. std::set<LibraryID>& visited,
  2352. DependencyList& link_line )
  2353. {
  2354. // It's already been emitted
  2355. if( emitted.find(lib) != emitted.end() )
  2356. {
  2357. return;
  2358. }
  2359. // Emit the dependencies only if this library node hasn't been
  2360. // visited before. If it has, then we have a cycle. The recursion
  2361. // that got us here should take care of everything.
  2362. if( visited.insert(lib).second )
  2363. {
  2364. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  2365. {
  2366. const DependencyList& dep_on = dep_map.find( lib )->second;
  2367. DependencyList::const_reverse_iterator i;
  2368. // To cater for recursive external libraries, we must emit
  2369. // duplicates on this link line *unless* they were emitted by
  2370. // some other node, in which case we assume that the recursion
  2371. // was resolved then. We making the simplifying assumption that
  2372. // any duplicates on a single link line are on purpose, and must
  2373. // be preserved.
  2374. // This variable will keep track of the libraries that were
  2375. // emitted directly from the current node, and not from a
  2376. // recursive call. This way, if we come across a library that
  2377. // has already been emitted, we repeat it iff it has been
  2378. // emitted here.
  2379. std::set<DependencyMap::key_type> emitted_here;
  2380. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  2381. {
  2382. if( emitted_here.find(*i) != emitted_here.end() )
  2383. {
  2384. // a repeat. Must emit.
  2385. emitted.insert(*i);
  2386. link_line.push_back( *i );
  2387. }
  2388. else
  2389. {
  2390. // Emit only if no-one else has
  2391. if( emitted.find(*i) == emitted.end() )
  2392. {
  2393. // emit dependencies
  2394. Emit( *i, dep_map, emitted, visited, link_line );
  2395. // emit self
  2396. emitted.insert(*i);
  2397. emitted_here.insert(*i);
  2398. link_line.push_back( *i );
  2399. }
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. //----------------------------------------------------------------------------
  2406. void cmTarget::GatherDependencies( const cmMakefile& mf,
  2407. const LibraryID& lib,
  2408. DependencyMap& dep_map)
  2409. {
  2410. // If the library is already in the dependency map, then it has
  2411. // already been fully processed.
  2412. if( dep_map.find(lib) != dep_map.end() )
  2413. {
  2414. return;
  2415. }
  2416. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  2417. if( deps && strcmp(deps,"") != 0 )
  2418. {
  2419. // Make sure this library is in the map, even if it has an empty
  2420. // set of dependencies. This distinguishes the case of explicitly
  2421. // no dependencies with that of unspecified dependencies.
  2422. dep_map[lib];
  2423. // Parse the dependency information, which is a set of
  2424. // type, library pairs separated by ";". There is always a trailing ";".
  2425. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  2426. std::string depline = deps;
  2427. std::string::size_type start = 0;
  2428. std::string::size_type end;
  2429. end = depline.find( ";", start );
  2430. while( end != std::string::npos )
  2431. {
  2432. std::string l = depline.substr( start, end-start );
  2433. if( l.size() != 0 )
  2434. {
  2435. if (l == "debug")
  2436. {
  2437. llt = cmTarget::DEBUG;
  2438. }
  2439. else if (l == "optimized")
  2440. {
  2441. llt = cmTarget::OPTIMIZED;
  2442. }
  2443. else if (l == "general")
  2444. {
  2445. llt = cmTarget::GENERAL;
  2446. }
  2447. else
  2448. {
  2449. LibraryID lib2(l,llt);
  2450. this->InsertDependency( dep_map, lib, lib2);
  2451. this->GatherDependencies( mf, lib2, dep_map);
  2452. llt = cmTarget::GENERAL;
  2453. }
  2454. }
  2455. start = end+1; // skip the ;
  2456. end = depline.find( ";", start );
  2457. }
  2458. // cannot depend on itself
  2459. this->DeleteDependency( dep_map, lib, lib);
  2460. }
  2461. }
  2462. //----------------------------------------------------------------------------
  2463. void cmTarget::SetProperty(const char* prop, const char* value)
  2464. {
  2465. if (!prop)
  2466. {
  2467. return;
  2468. }
  2469. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2470. {
  2471. cmListFileBacktrace lfbt;
  2472. this->Makefile->GetBacktrace(lfbt);
  2473. cmGeneratorExpression ge(lfbt);
  2474. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  2475. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  2476. this->Internal->IncludeDirectoriesEntries.push_back(
  2477. new cmTargetInternals::IncludeDirectoriesEntry(cge));
  2478. return;
  2479. }
  2480. if (strcmp(prop, "LINK_LIBRARIES") == 0)
  2481. {
  2482. this->Internal->LinkInterfaceIncludeDirectoriesEntries.clear();
  2483. if (cmGeneratorExpression::IsValidTargetName(value)
  2484. || cmGeneratorExpression::Find(value) != std::string::npos)
  2485. {
  2486. cmListFileBacktrace lfbt;
  2487. this->Makefile->GetBacktrace(lfbt);
  2488. cmValueWithOrigin entry(value, lfbt);
  2489. this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
  2490. }
  2491. // Fall through
  2492. }
  2493. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  2494. this->MaybeInvalidatePropertyCache(prop);
  2495. }
  2496. //----------------------------------------------------------------------------
  2497. void cmTarget::AppendProperty(const char* prop, const char* value,
  2498. bool asString)
  2499. {
  2500. if (!prop)
  2501. {
  2502. return;
  2503. }
  2504. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2505. {
  2506. cmListFileBacktrace lfbt;
  2507. this->Makefile->GetBacktrace(lfbt);
  2508. cmGeneratorExpression ge(lfbt);
  2509. this->Internal->IncludeDirectoriesEntries.push_back(
  2510. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
  2511. return;
  2512. }
  2513. if (strcmp(prop, "LINK_LIBRARIES") == 0)
  2514. {
  2515. if (cmGeneratorExpression::IsValidTargetName(value)
  2516. || cmGeneratorExpression::Find(value) != std::string::npos)
  2517. {
  2518. cmListFileBacktrace lfbt;
  2519. this->Makefile->GetBacktrace(lfbt);
  2520. cmValueWithOrigin entry(value, lfbt);
  2521. this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
  2522. }
  2523. // Fall through
  2524. }
  2525. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  2526. this->MaybeInvalidatePropertyCache(prop);
  2527. }
  2528. //----------------------------------------------------------------------------
  2529. void cmTarget::AppendBuildInterfaceIncludes()
  2530. {
  2531. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2532. this->GetType() != cmTarget::STATIC_LIBRARY &&
  2533. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2534. !this->IsExecutableWithExports())
  2535. {
  2536. return;
  2537. }
  2538. if (this->BuildInterfaceIncludesAppended)
  2539. {
  2540. return;
  2541. }
  2542. this->BuildInterfaceIncludesAppended = true;
  2543. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  2544. {
  2545. const char *binDir = this->Makefile->GetStartOutputDirectory();
  2546. const char *srcDir = this->Makefile->GetStartDirectory();
  2547. const std::string dirs = std::string(binDir ? binDir : "")
  2548. + std::string(binDir ? ";" : "")
  2549. + std::string(srcDir ? srcDir : "");
  2550. if (!dirs.empty())
  2551. {
  2552. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  2553. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  2554. }
  2555. }
  2556. }
  2557. //----------------------------------------------------------------------------
  2558. void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
  2559. bool before)
  2560. {
  2561. cmGeneratorExpression ge(entry.Backtrace);
  2562. std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::iterator position
  2563. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  2564. : this->Internal->IncludeDirectoriesEntries.end();
  2565. this->Internal->IncludeDirectoriesEntries.insert(position,
  2566. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(entry.Value)));
  2567. }
  2568. //----------------------------------------------------------------------------
  2569. static void processIncludeDirectories(cmTarget *tgt,
  2570. const std::vector<cmTargetInternals::IncludeDirectoriesEntry*> &entries,
  2571. std::vector<std::string> &includes,
  2572. std::set<std::string> &uniqueIncludes,
  2573. cmGeneratorExpressionDAGChecker *dagChecker,
  2574. const char *config, bool debugIncludes)
  2575. {
  2576. cmMakefile *mf = tgt->GetMakefile();
  2577. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  2578. it = entries.begin(), end = entries.end(); it != end; ++it)
  2579. {
  2580. bool testIsOff = true;
  2581. bool cacheIncludes = false;
  2582. std::vector<std::string> entryIncludes = (*it)->CachedIncludes;
  2583. if(!entryIncludes.empty())
  2584. {
  2585. testIsOff = false;
  2586. }
  2587. else
  2588. {
  2589. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2590. config,
  2591. false,
  2592. tgt,
  2593. dagChecker),
  2594. entryIncludes);
  2595. if (mf->IsGeneratingBuildSystem()
  2596. && !(*it)->ge->GetHadContextSensitiveCondition())
  2597. {
  2598. cacheIncludes = true;
  2599. }
  2600. }
  2601. std::string usedIncludes;
  2602. for(std::vector<std::string>::iterator
  2603. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  2604. {
  2605. cmTarget *dependentTarget =
  2606. mf->FindTargetToUse((*it)->TargetName.c_str());
  2607. const bool fromImported = dependentTarget
  2608. && dependentTarget->IsImported();
  2609. if (fromImported && !cmSystemTools::FileExists(li->c_str()))
  2610. {
  2611. cmOStringStream e;
  2612. e << "Imported target \"" << (*it)->TargetName << "\" includes "
  2613. "non-existent path\n \"" << *li << "\"\nin its "
  2614. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2615. "* The path was deleted, renamed, or moved to another "
  2616. "location.\n"
  2617. "* An install or uninstall procedure did not complete "
  2618. "successfully.\n"
  2619. "* The installation package was faulty and references files it "
  2620. "does not provide.\n";
  2621. tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  2622. return;
  2623. }
  2624. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  2625. {
  2626. if (!(*it)->TargetName.empty())
  2627. {
  2628. cmOStringStream e;
  2629. e << "Target \"" << (*it)->TargetName << "\" contains relative "
  2630. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2631. " \"" << *li << "\" ";
  2632. tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR,
  2633. e.str().c_str());
  2634. return;
  2635. }
  2636. }
  2637. if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
  2638. {
  2639. cmSystemTools::ConvertToUnixSlashes(*li);
  2640. }
  2641. std::string inc = *li;
  2642. if(uniqueIncludes.insert(inc).second)
  2643. {
  2644. includes.push_back(inc);
  2645. if (debugIncludes)
  2646. {
  2647. usedIncludes += " * " + inc + "\n";
  2648. }
  2649. }
  2650. }
  2651. if (cacheIncludes)
  2652. {
  2653. (*it)->CachedIncludes = entryIncludes;
  2654. }
  2655. if (!usedIncludes.empty())
  2656. {
  2657. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2658. std::string("Used includes for target ")
  2659. + tgt->GetName() + ":\n"
  2660. + usedIncludes, (*it)->ge->GetBacktrace());
  2661. }
  2662. }
  2663. }
  2664. //----------------------------------------------------------------------------
  2665. std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
  2666. {
  2667. std::vector<std::string> includes;
  2668. std::set<std::string> uniqueIncludes;
  2669. cmListFileBacktrace lfbt;
  2670. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2671. this->GetName(),
  2672. "INCLUDE_DIRECTORIES", 0, 0);
  2673. this->AppendBuildInterfaceIncludes();
  2674. std::vector<std::string> debugProperties;
  2675. const char *debugProp =
  2676. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2677. if (debugProp)
  2678. {
  2679. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2680. }
  2681. bool debugIncludes = !this->DebugIncludesDone
  2682. && std::find(debugProperties.begin(),
  2683. debugProperties.end(),
  2684. "INCLUDE_DIRECTORIES")
  2685. != debugProperties.end();
  2686. if (this->Makefile->IsGeneratingBuildSystem())
  2687. {
  2688. this->DebugIncludesDone = true;
  2689. }
  2690. processIncludeDirectories(this,
  2691. this->Internal->IncludeDirectoriesEntries,
  2692. includes,
  2693. uniqueIncludes,
  2694. &dagChecker,
  2695. config,
  2696. debugIncludes);
  2697. std::string configString = config ? config : "";
  2698. if (!this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString])
  2699. {
  2700. for (std::vector<cmValueWithOrigin>::const_iterator
  2701. it = this->Internal->LinkInterfaceIncludeDirectoriesEntries.begin(),
  2702. end = this->Internal->LinkInterfaceIncludeDirectoriesEntries.end();
  2703. it != end; ++it)
  2704. {
  2705. {
  2706. cmGeneratorExpression ge(lfbt);
  2707. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2708. ge.Parse(it->Value);
  2709. std::string result = cge->Evaluate(this->Makefile, config,
  2710. false, this, 0, 0);
  2711. if (!this->Makefile->FindTargetToUse(result.c_str()))
  2712. {
  2713. continue;
  2714. }
  2715. }
  2716. std::string includeGenex = "$<TARGET_PROPERTY:" +
  2717. it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
  2718. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  2719. {
  2720. // Because it->Value is a generator expression, ensure that it
  2721. // evaluates to the non-empty string before being used in the
  2722. // TARGET_PROPERTY expression.
  2723. includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
  2724. }
  2725. cmGeneratorExpression ge(it->Backtrace);
  2726. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  2727. includeGenex);
  2728. this->Internal
  2729. ->CachedLinkInterfaceIncludeDirectoriesEntries[configString].push_back(
  2730. new cmTargetInternals::IncludeDirectoriesEntry(cge,
  2731. it->Value));
  2732. }
  2733. }
  2734. processIncludeDirectories(this,
  2735. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries[configString],
  2736. includes,
  2737. uniqueIncludes,
  2738. &dagChecker,
  2739. config,
  2740. debugIncludes);
  2741. if (!this->Makefile->IsGeneratingBuildSystem())
  2742. {
  2743. deleteAndClear(
  2744. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries);
  2745. }
  2746. else
  2747. {
  2748. this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString]
  2749. = true;
  2750. }
  2751. return includes;
  2752. }
  2753. //----------------------------------------------------------------------------
  2754. std::string cmTarget::GetCompileDefinitions(const char *config)
  2755. {
  2756. const char *configProp = 0;
  2757. if (config)
  2758. {
  2759. std::string configPropName;
  2760. configPropName = "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  2761. configProp = this->GetProperty(configPropName.c_str());
  2762. }
  2763. const char *noconfigProp = this->GetProperty("COMPILE_DEFINITIONS");
  2764. cmListFileBacktrace lfbt;
  2765. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2766. this->GetName(),
  2767. "COMPILE_DEFINITIONS", 0, 0);
  2768. std::string defsString = (noconfigProp ? noconfigProp : "");
  2769. if (configProp && noconfigProp)
  2770. {
  2771. defsString += ";";
  2772. }
  2773. defsString += (configProp ? configProp : "");
  2774. cmGeneratorExpression ge(lfbt);
  2775. std::string result = ge.Parse(defsString.c_str())->Evaluate(this->Makefile,
  2776. config,
  2777. false,
  2778. this,
  2779. &dagChecker);
  2780. std::vector<std::string> libs;
  2781. this->GetDirectLinkLibraries(config, libs, this);
  2782. if (libs.empty())
  2783. {
  2784. return result;
  2785. }
  2786. std::string sep;
  2787. std::string depString;
  2788. for (std::vector<std::string>::const_iterator it = libs.begin();
  2789. it != libs.end(); ++it)
  2790. {
  2791. if ((cmGeneratorExpression::IsValidTargetName(it->c_str())
  2792. || cmGeneratorExpression::Find(it->c_str()) != std::string::npos)
  2793. && this->Makefile->FindTargetToUse(it->c_str()))
  2794. {
  2795. depString += sep + "$<TARGET_PROPERTY:"
  2796. + *it + ",INTERFACE_COMPILE_DEFINITIONS>";
  2797. sep = ";";
  2798. }
  2799. }
  2800. std::string configString = config ? config : "";
  2801. if (!this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString])
  2802. {
  2803. cmGeneratorExpression ge2(lfbt);
  2804. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge2 =
  2805. ge2.Parse(depString);
  2806. this->Internal->CachedLinkInterfaceCompileDefinitions[configString] =
  2807. cge2->Evaluate(this->Makefile,
  2808. config,
  2809. false,
  2810. this,
  2811. &dagChecker);
  2812. }
  2813. if (!this->Internal->CachedLinkInterfaceCompileDefinitions[configString]
  2814. .empty())
  2815. {
  2816. result += (result.empty() ? "" : ";")
  2817. + this->Internal->CachedLinkInterfaceCompileDefinitions[configString];
  2818. }
  2819. if (!this->Makefile->IsGeneratingBuildSystem())
  2820. {
  2821. this->Internal->CachedLinkInterfaceCompileDefinitions[configString] = "";
  2822. }
  2823. else
  2824. {
  2825. this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString]
  2826. = true;
  2827. }
  2828. return result;
  2829. }
  2830. //----------------------------------------------------------------------------
  2831. void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
  2832. {
  2833. // Wipe out maps caching information affected by this property.
  2834. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  2835. {
  2836. this->Internal->ImportInfoMap.clear();
  2837. }
  2838. if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
  2839. {
  2840. this->ClearLinkMaps();
  2841. }
  2842. }
  2843. //----------------------------------------------------------------------------
  2844. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2845. const char* prop, const char* value, cmMakefile* context, bool imported
  2846. )
  2847. {
  2848. // Look for link-type keywords in the value.
  2849. static cmsys::RegularExpression
  2850. keys("(^|;)(debug|optimized|general)(;|$)");
  2851. if(!keys.find(value))
  2852. {
  2853. return;
  2854. }
  2855. // Support imported and non-imported versions of the property.
  2856. const char* base = (imported?
  2857. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2858. "LINK_INTERFACE_LIBRARIES");
  2859. // Report an error.
  2860. cmOStringStream e;
  2861. e << "Property " << prop << " may not contain link-type keyword \""
  2862. << keys.match(2) << "\". "
  2863. << "The " << base << " property has a per-configuration "
  2864. << "version called " << base << "_<CONFIG> which may be "
  2865. << "used to specify per-configuration rules.";
  2866. if(!imported)
  2867. {
  2868. e << " "
  2869. << "Alternatively, an IMPORTED library may be created, configured "
  2870. << "with a per-configuration location, and then named in the "
  2871. << "property value. "
  2872. << "See the add_library command's IMPORTED mode for details."
  2873. << "\n"
  2874. << "If you have a list of libraries that already contains the "
  2875. << "keyword, use the target_link_libraries command with its "
  2876. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2877. << "The command automatically recognizes link-type keywords and sets "
  2878. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2879. << "properties accordingly.";
  2880. }
  2881. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2882. }
  2883. //----------------------------------------------------------------------------
  2884. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  2885. {
  2886. // Certain properties need checking.
  2887. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  2888. {
  2889. if(const char* value = this->GetProperty(prop))
  2890. {
  2891. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2892. }
  2893. }
  2894. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  2895. {
  2896. if(const char* value = this->GetProperty(prop))
  2897. {
  2898. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2899. }
  2900. }
  2901. }
  2902. //----------------------------------------------------------------------------
  2903. void cmTarget::MarkAsImported()
  2904. {
  2905. this->IsImportedTarget = true;
  2906. }
  2907. //----------------------------------------------------------------------------
  2908. bool cmTarget::HaveWellDefinedOutputFiles()
  2909. {
  2910. return
  2911. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2912. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2913. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2914. this->GetType() == cmTarget::EXECUTABLE;
  2915. }
  2916. //----------------------------------------------------------------------------
  2917. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
  2918. {
  2919. // There is no output information for imported targets.
  2920. if(this->IsImported())
  2921. {
  2922. return 0;
  2923. }
  2924. // Only libraries and executables have well-defined output files.
  2925. if(!this->HaveWellDefinedOutputFiles())
  2926. {
  2927. std::string msg = "cmTarget::GetOutputInfo called for ";
  2928. msg += this->GetName();
  2929. msg += " which has type ";
  2930. msg += cmTarget::GetTargetTypeName(this->GetType());
  2931. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2932. abort();
  2933. return 0;
  2934. }
  2935. // Lookup/compute/cache the output information for this configuration.
  2936. std::string config_upper;
  2937. if(config && *config)
  2938. {
  2939. config_upper = cmSystemTools::UpperCase(config);
  2940. }
  2941. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2942. OutputInfoMapType::const_iterator i =
  2943. this->Internal->OutputInfoMap.find(config_upper);
  2944. if(i == this->Internal->OutputInfoMap.end())
  2945. {
  2946. OutputInfo info;
  2947. this->ComputeOutputDir(config, false, info.OutDir);
  2948. this->ComputeOutputDir(config, true, info.ImpDir);
  2949. if(!this->ComputePDBOutputDir(config, info.PdbDir))
  2950. {
  2951. info.PdbDir = info.OutDir;
  2952. }
  2953. OutputInfoMapType::value_type entry(config_upper, info);
  2954. i = this->Internal->OutputInfoMap.insert(entry).first;
  2955. }
  2956. return &i->second;
  2957. }
  2958. //----------------------------------------------------------------------------
  2959. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2960. {
  2961. if (this->IsImported())
  2962. {
  2963. // Return the directory from which the target is imported.
  2964. return
  2965. cmSystemTools::GetFilenamePath(
  2966. this->ImportedGetFullPath(config, implib));
  2967. }
  2968. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2969. {
  2970. // Return the directory in which the target will be built.
  2971. return implib? info->ImpDir : info->OutDir;
  2972. }
  2973. return "";
  2974. }
  2975. //----------------------------------------------------------------------------
  2976. std::string cmTarget::GetPDBDirectory(const char* config)
  2977. {
  2978. if(OutputInfo const* info = this->GetOutputInfo(config))
  2979. {
  2980. // Return the directory in which the target will be built.
  2981. return info->PdbDir;
  2982. }
  2983. return "";
  2984. }
  2985. //----------------------------------------------------------------------------
  2986. const char* cmTarget::GetLocation(const char* config)
  2987. {
  2988. if (this->IsImported())
  2989. {
  2990. return this->ImportedGetLocation(config);
  2991. }
  2992. else
  2993. {
  2994. return this->NormalGetLocation(config);
  2995. }
  2996. }
  2997. //----------------------------------------------------------------------------
  2998. const char* cmTarget::ImportedGetLocation(const char* config)
  2999. {
  3000. this->Location = this->ImportedGetFullPath(config, false);
  3001. return this->Location.c_str();
  3002. }
  3003. //----------------------------------------------------------------------------
  3004. const char* cmTarget::NormalGetLocation(const char* config)
  3005. {
  3006. // Handle the configuration-specific case first.
  3007. if(config)
  3008. {
  3009. this->Location = this->GetFullPath(config, false);
  3010. return this->Location.c_str();
  3011. }
  3012. // Now handle the deprecated build-time configuration location.
  3013. this->Location = this->GetDirectory();
  3014. if(!this->Location.empty())
  3015. {
  3016. this->Location += "/";
  3017. }
  3018. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  3019. if(cfgid && strcmp(cfgid, ".") != 0)
  3020. {
  3021. this->Location += cfgid;
  3022. this->Location += "/";
  3023. }
  3024. this->Location = this->BuildMacContentDirectory(this->Location, config);
  3025. this->Location += this->GetFullName(config, false);
  3026. return this->Location.c_str();
  3027. }
  3028. //----------------------------------------------------------------------------
  3029. void cmTarget::GetTargetVersion(int& major, int& minor)
  3030. {
  3031. int patch;
  3032. this->GetTargetVersion(false, major, minor, patch);
  3033. }
  3034. //----------------------------------------------------------------------------
  3035. void cmTarget::GetTargetVersion(bool soversion,
  3036. int& major, int& minor, int& patch)
  3037. {
  3038. // Set the default values.
  3039. major = 0;
  3040. minor = 0;
  3041. patch = 0;
  3042. // Look for a VERSION or SOVERSION property.
  3043. const char* prop = soversion? "SOVERSION" : "VERSION";
  3044. if(const char* version = this->GetProperty(prop))
  3045. {
  3046. // Try to parse the version number and store the results that were
  3047. // successfully parsed.
  3048. int parsed_major;
  3049. int parsed_minor;
  3050. int parsed_patch;
  3051. switch(sscanf(version, "%d.%d.%d",
  3052. &parsed_major, &parsed_minor, &parsed_patch))
  3053. {
  3054. case 3: patch = parsed_patch; // no break!
  3055. case 2: minor = parsed_minor; // no break!
  3056. case 1: major = parsed_major; // no break!
  3057. default: break;
  3058. }
  3059. }
  3060. }
  3061. //----------------------------------------------------------------------------
  3062. const char* cmTarget::GetFeature(const char* feature, const char* config)
  3063. {
  3064. if(config && *config)
  3065. {
  3066. std::string featureConfig = feature;
  3067. featureConfig += "_";
  3068. featureConfig += cmSystemTools::UpperCase(config);
  3069. if(const char* value = this->GetProperty(featureConfig.c_str()))
  3070. {
  3071. return value;
  3072. }
  3073. }
  3074. if(const char* value = this->GetProperty(feature))
  3075. {
  3076. return value;
  3077. }
  3078. return this->Makefile->GetFeature(feature, config);
  3079. }
  3080. //----------------------------------------------------------------------------
  3081. const char *cmTarget::GetProperty(const char* prop)
  3082. {
  3083. return this->GetProperty(prop, cmProperty::TARGET);
  3084. }
  3085. //----------------------------------------------------------------------------
  3086. const char *cmTarget::GetProperty(const char* prop,
  3087. cmProperty::ScopeType scope)
  3088. {
  3089. if(!prop)
  3090. {
  3091. return 0;
  3092. }
  3093. // Watch for special "computed" properties that are dependent on
  3094. // other properties or variables. Always recompute them.
  3095. if(this->GetType() == cmTarget::EXECUTABLE ||
  3096. this->GetType() == cmTarget::STATIC_LIBRARY ||
  3097. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3098. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3099. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  3100. {
  3101. if(strcmp(prop,"LOCATION") == 0)
  3102. {
  3103. // Set the LOCATION property of the target.
  3104. //
  3105. // For an imported target this is the location of an arbitrary
  3106. // available configuration.
  3107. //
  3108. // For a non-imported target this is deprecated because it
  3109. // cannot take into account the per-configuration name of the
  3110. // target because the configuration type may not be known at
  3111. // CMake time.
  3112. this->SetProperty("LOCATION", this->GetLocation(0));
  3113. }
  3114. // Support "LOCATION_<CONFIG>".
  3115. if(strncmp(prop, "LOCATION_", 9) == 0)
  3116. {
  3117. std::string configName = prop+9;
  3118. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  3119. }
  3120. else
  3121. {
  3122. // Support "<CONFIG>_LOCATION" for compatiblity.
  3123. int len = static_cast<int>(strlen(prop));
  3124. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  3125. {
  3126. std::string configName(prop, len-9);
  3127. if(configName != "IMPORTED")
  3128. {
  3129. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  3130. }
  3131. }
  3132. }
  3133. }
  3134. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  3135. {
  3136. static std::string output;
  3137. output = "";
  3138. std::string sep;
  3139. typedef cmTargetInternals::IncludeDirectoriesEntry
  3140. IncludeDirectoriesEntry;
  3141. for (std::vector<IncludeDirectoriesEntry*>::const_iterator
  3142. it = this->Internal->IncludeDirectoriesEntries.begin(),
  3143. end = this->Internal->IncludeDirectoriesEntries.end();
  3144. it != end; ++it)
  3145. {
  3146. output += sep;
  3147. output += (*it)->ge->GetInput();
  3148. sep = ";";
  3149. }
  3150. return output.c_str();
  3151. }
  3152. if (strcmp(prop,"IMPORTED") == 0)
  3153. {
  3154. return this->IsImported()?"TRUE":"FALSE";
  3155. }
  3156. if(!strcmp(prop,"SOURCES"))
  3157. {
  3158. cmOStringStream ss;
  3159. const char* sep = "";
  3160. for(std::vector<cmSourceFile*>::const_iterator
  3161. i = this->SourceFiles.begin();
  3162. i != this->SourceFiles.end(); ++i)
  3163. {
  3164. // Separate from the previous list entries.
  3165. ss << sep;
  3166. sep = ";";
  3167. // Construct what is known about this source file location.
  3168. cmSourceFileLocation const& location = (*i)->GetLocation();
  3169. std::string sname = location.GetDirectory();
  3170. if(!sname.empty())
  3171. {
  3172. sname += "/";
  3173. }
  3174. sname += location.GetName();
  3175. // Append this list entry.
  3176. ss << sname;
  3177. }
  3178. this->SetProperty("SOURCES", ss.str().c_str());
  3179. }
  3180. // the type property returns what type the target is
  3181. if (!strcmp(prop,"TYPE"))
  3182. {
  3183. return cmTarget::GetTargetTypeName(this->GetType());
  3184. }
  3185. bool chain = false;
  3186. const char *retVal =
  3187. this->Properties.GetPropertyValue(prop, scope, chain);
  3188. if (chain)
  3189. {
  3190. return this->Makefile->GetProperty(prop,scope);
  3191. }
  3192. return retVal;
  3193. }
  3194. //----------------------------------------------------------------------------
  3195. bool cmTarget::GetPropertyAsBool(const char* prop)
  3196. {
  3197. return cmSystemTools::IsOn(this->GetProperty(prop));
  3198. }
  3199. //----------------------------------------------------------------------------
  3200. class cmTargetCollectLinkLanguages
  3201. {
  3202. public:
  3203. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  3204. std::set<cmStdString>& languages,
  3205. cmTarget* head):
  3206. Config(config), Languages(languages), HeadTarget(head)
  3207. { this->Visited.insert(target); }
  3208. void Visit(cmTarget* target)
  3209. {
  3210. if(!target || !this->Visited.insert(target).second)
  3211. {
  3212. return;
  3213. }
  3214. cmTarget::LinkInterface const* iface =
  3215. target->GetLinkInterface(this->Config, this->HeadTarget);
  3216. if(!iface) { return; }
  3217. for(std::vector<std::string>::const_iterator
  3218. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  3219. {
  3220. this->Languages.insert(*li);
  3221. }
  3222. cmMakefile* mf = target->GetMakefile();
  3223. for(std::vector<std::string>::const_iterator
  3224. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  3225. {
  3226. this->Visit(mf->FindTargetToUse(li->c_str()));
  3227. }
  3228. }
  3229. private:
  3230. const char* Config;
  3231. std::set<cmStdString>& Languages;
  3232. cmTarget* HeadTarget;
  3233. std::set<cmTarget*> Visited;
  3234. };
  3235. //----------------------------------------------------------------------------
  3236. const char* cmTarget::GetLinkerLanguage(const char* config, cmTarget *head)
  3237. {
  3238. cmTarget *headTarget = head ? head : this;
  3239. const char* lang = this->GetLinkClosure(config, headTarget)
  3240. ->LinkerLanguage.c_str();
  3241. return *lang? lang : 0;
  3242. }
  3243. //----------------------------------------------------------------------------
  3244. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
  3245. cmTarget *head)
  3246. {
  3247. TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
  3248. cmTargetInternals::LinkClosureMapType::iterator
  3249. i = this->Internal->LinkClosureMap.find(key);
  3250. if(i == this->Internal->LinkClosureMap.end())
  3251. {
  3252. LinkClosure lc;
  3253. this->ComputeLinkClosure(config, lc, head);
  3254. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  3255. i = this->Internal->LinkClosureMap.insert(entry).first;
  3256. }
  3257. return &i->second;
  3258. }
  3259. //----------------------------------------------------------------------------
  3260. class cmTargetSelectLinker
  3261. {
  3262. int Preference;
  3263. cmTarget* Target;
  3264. cmMakefile* Makefile;
  3265. cmGlobalGenerator* GG;
  3266. std::set<cmStdString> Preferred;
  3267. public:
  3268. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  3269. {
  3270. this->Makefile = this->Target->GetMakefile();
  3271. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  3272. }
  3273. void Consider(const char* lang)
  3274. {
  3275. int preference = this->GG->GetLinkerPreference(lang);
  3276. if(preference > this->Preference)
  3277. {
  3278. this->Preference = preference;
  3279. this->Preferred.clear();
  3280. }
  3281. if(preference == this->Preference)
  3282. {
  3283. this->Preferred.insert(lang);
  3284. }
  3285. }
  3286. std::string Choose()
  3287. {
  3288. if(this->Preferred.empty())
  3289. {
  3290. return "";
  3291. }
  3292. else if(this->Preferred.size() > 1)
  3293. {
  3294. cmOStringStream e;
  3295. e << "Target " << this->Target->GetName()
  3296. << " contains multiple languages with the highest linker preference"
  3297. << " (" << this->Preference << "):\n";
  3298. for(std::set<cmStdString>::const_iterator
  3299. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3300. {
  3301. e << " " << *li << "\n";
  3302. }
  3303. e << "Set the LINKER_LANGUAGE property for this target.";
  3304. cmake* cm = this->Makefile->GetCMakeInstance();
  3305. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3306. this->Target->GetBacktrace());
  3307. }
  3308. return *this->Preferred.begin();
  3309. }
  3310. };
  3311. //----------------------------------------------------------------------------
  3312. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
  3313. cmTarget *head)
  3314. {
  3315. // Get languages built in this target.
  3316. std::set<cmStdString> languages;
  3317. LinkImplementation const* impl = this->GetLinkImplementation(config, head);
  3318. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3319. li != impl->Languages.end(); ++li)
  3320. {
  3321. languages.insert(*li);
  3322. }
  3323. // Add interface languages from linked targets.
  3324. cmTargetCollectLinkLanguages cll(this, config, languages, head);
  3325. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  3326. li != impl->Libraries.end(); ++li)
  3327. {
  3328. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  3329. }
  3330. // Store the transitive closure of languages.
  3331. for(std::set<cmStdString>::const_iterator li = languages.begin();
  3332. li != languages.end(); ++li)
  3333. {
  3334. lc.Languages.push_back(*li);
  3335. }
  3336. // Choose the language whose linker should be used.
  3337. if(this->GetProperty("HAS_CXX"))
  3338. {
  3339. lc.LinkerLanguage = "CXX";
  3340. }
  3341. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3342. {
  3343. lc.LinkerLanguage = linkerLang;
  3344. }
  3345. else
  3346. {
  3347. // Find the language with the highest preference value.
  3348. cmTargetSelectLinker tsl(this);
  3349. // First select from the languages compiled directly in this target.
  3350. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3351. li != impl->Languages.end(); ++li)
  3352. {
  3353. tsl.Consider(li->c_str());
  3354. }
  3355. // Now consider languages that propagate from linked targets.
  3356. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  3357. sit != languages.end(); ++sit)
  3358. {
  3359. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3360. if(this->Makefile->IsOn(propagates.c_str()))
  3361. {
  3362. tsl.Consider(sit->c_str());
  3363. }
  3364. }
  3365. lc.LinkerLanguage = tsl.Choose();
  3366. }
  3367. }
  3368. //----------------------------------------------------------------------------
  3369. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  3370. {
  3371. switch(this->GetType())
  3372. {
  3373. case cmTarget::STATIC_LIBRARY:
  3374. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3375. case cmTarget::SHARED_LIBRARY:
  3376. return (implib
  3377. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3378. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3379. case cmTarget::MODULE_LIBRARY:
  3380. return (implib
  3381. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3382. : "CMAKE_SHARED_MODULE_SUFFIX");
  3383. case cmTarget::EXECUTABLE:
  3384. return (implib
  3385. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3386. : "CMAKE_EXECUTABLE_SUFFIX");
  3387. default:
  3388. break;
  3389. }
  3390. return "";
  3391. }
  3392. //----------------------------------------------------------------------------
  3393. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  3394. {
  3395. switch(this->GetType())
  3396. {
  3397. case cmTarget::STATIC_LIBRARY:
  3398. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3399. case cmTarget::SHARED_LIBRARY:
  3400. return (implib
  3401. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3402. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3403. case cmTarget::MODULE_LIBRARY:
  3404. return (implib
  3405. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3406. : "CMAKE_SHARED_MODULE_PREFIX");
  3407. case cmTarget::EXECUTABLE:
  3408. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  3409. default:
  3410. break;
  3411. }
  3412. return "";
  3413. }
  3414. //----------------------------------------------------------------------------
  3415. std::string cmTarget::GetPDBName(const char* config)
  3416. {
  3417. std::string prefix;
  3418. std::string base;
  3419. std::string suffix;
  3420. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3421. std::vector<std::string> props;
  3422. std::string configUpper =
  3423. cmSystemTools::UpperCase(config? config : "");
  3424. if(!configUpper.empty())
  3425. {
  3426. // PDB_NAME_<CONFIG>
  3427. props.push_back("PDB_NAME_" + configUpper);
  3428. }
  3429. // PDB_NAME
  3430. props.push_back("PDB_NAME");
  3431. for(std::vector<std::string>::const_iterator i = props.begin();
  3432. i != props.end(); ++i)
  3433. {
  3434. if(const char* outName = this->GetProperty(i->c_str()))
  3435. {
  3436. base = outName;
  3437. break;
  3438. }
  3439. }
  3440. return prefix+base+".pdb";
  3441. }
  3442. //----------------------------------------------------------------------------
  3443. bool cmTarget::HasSOName(const char* config)
  3444. {
  3445. // soname is supported only for shared libraries and modules,
  3446. // and then only when the platform supports an soname flag.
  3447. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3448. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3449. !this->GetPropertyAsBool("NO_SONAME") &&
  3450. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
  3451. this)));
  3452. }
  3453. //----------------------------------------------------------------------------
  3454. std::string cmTarget::GetSOName(const char* config)
  3455. {
  3456. if(this->IsImported())
  3457. {
  3458. // Lookup the imported soname.
  3459. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3460. {
  3461. if(info->NoSOName)
  3462. {
  3463. // The imported library has no builtin soname so the name
  3464. // searched at runtime will be just the filename.
  3465. return cmSystemTools::GetFilenameName(info->Location);
  3466. }
  3467. else
  3468. {
  3469. // Use the soname given if any.
  3470. return info->SOName;
  3471. }
  3472. }
  3473. else
  3474. {
  3475. return "";
  3476. }
  3477. }
  3478. else
  3479. {
  3480. // Compute the soname that will be built.
  3481. std::string name;
  3482. std::string soName;
  3483. std::string realName;
  3484. std::string impName;
  3485. std::string pdbName;
  3486. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3487. return soName;
  3488. }
  3489. }
  3490. //----------------------------------------------------------------------------
  3491. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  3492. {
  3493. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3494. {
  3495. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3496. {
  3497. return info->NoSOName;
  3498. }
  3499. }
  3500. return false;
  3501. }
  3502. //----------------------------------------------------------------------------
  3503. std::string cmTarget::NormalGetRealName(const char* config)
  3504. {
  3505. // This should not be called for imported targets.
  3506. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3507. // enforcement of the limited imported target API.
  3508. if(this->IsImported())
  3509. {
  3510. std::string msg = "NormalGetRealName called on imported target: ";
  3511. msg += this->GetName();
  3512. this->GetMakefile()->
  3513. IssueMessage(cmake::INTERNAL_ERROR,
  3514. msg.c_str());
  3515. }
  3516. if(this->GetType() == cmTarget::EXECUTABLE)
  3517. {
  3518. // Compute the real name that will be built.
  3519. std::string name;
  3520. std::string realName;
  3521. std::string impName;
  3522. std::string pdbName;
  3523. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3524. return realName;
  3525. }
  3526. else
  3527. {
  3528. // Compute the real name that will be built.
  3529. std::string name;
  3530. std::string soName;
  3531. std::string realName;
  3532. std::string impName;
  3533. std::string pdbName;
  3534. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3535. return realName;
  3536. }
  3537. }
  3538. //----------------------------------------------------------------------------
  3539. std::string cmTarget::GetFullName(const char* config, bool implib)
  3540. {
  3541. if(this->IsImported())
  3542. {
  3543. return this->GetFullNameImported(config, implib);
  3544. }
  3545. else
  3546. {
  3547. return this->GetFullNameInternal(config, implib);
  3548. }
  3549. }
  3550. //----------------------------------------------------------------------------
  3551. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  3552. {
  3553. return cmSystemTools::GetFilenameName(
  3554. this->ImportedGetFullPath(config, implib));
  3555. }
  3556. //----------------------------------------------------------------------------
  3557. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3558. std::string& suffix, const char* config,
  3559. bool implib)
  3560. {
  3561. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3562. }
  3563. //----------------------------------------------------------------------------
  3564. std::string cmTarget::GetFullPath(const char* config, bool implib,
  3565. bool realname)
  3566. {
  3567. if(this->IsImported())
  3568. {
  3569. return this->ImportedGetFullPath(config, implib);
  3570. }
  3571. else
  3572. {
  3573. return this->NormalGetFullPath(config, implib, realname);
  3574. }
  3575. }
  3576. //----------------------------------------------------------------------------
  3577. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  3578. bool realname)
  3579. {
  3580. std::string fpath = this->GetMacContentDirectory(config, implib);
  3581. // Add the full name of the target.
  3582. if(implib)
  3583. {
  3584. fpath += this->GetFullName(config, true);
  3585. }
  3586. else if(realname)
  3587. {
  3588. fpath += this->NormalGetRealName(config);
  3589. }
  3590. else
  3591. {
  3592. fpath += this->GetFullName(config, false);
  3593. }
  3594. return fpath;
  3595. }
  3596. //----------------------------------------------------------------------------
  3597. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  3598. {
  3599. std::string result;
  3600. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3601. {
  3602. result = implib? info->ImportLibrary : info->Location;
  3603. }
  3604. if(result.empty())
  3605. {
  3606. result = this->GetName();
  3607. result += "-NOTFOUND";
  3608. }
  3609. return result;
  3610. }
  3611. //----------------------------------------------------------------------------
  3612. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  3613. {
  3614. std::string prefix;
  3615. std::string base;
  3616. std::string suffix;
  3617. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3618. return prefix+base+suffix;
  3619. }
  3620. //----------------------------------------------------------------------------
  3621. void cmTarget::GetFullNameInternal(const char* config,
  3622. bool implib,
  3623. std::string& outPrefix,
  3624. std::string& outBase,
  3625. std::string& outSuffix)
  3626. {
  3627. // Use just the target name for non-main target types.
  3628. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3629. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3630. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3631. this->GetType() != cmTarget::EXECUTABLE)
  3632. {
  3633. outPrefix = "";
  3634. outBase = this->GetName();
  3635. outSuffix = "";
  3636. return;
  3637. }
  3638. // Return an empty name for the import library if this platform
  3639. // does not support import libraries.
  3640. if(implib &&
  3641. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3642. {
  3643. outPrefix = "";
  3644. outBase = "";
  3645. outSuffix = "";
  3646. return;
  3647. }
  3648. // The implib option is only allowed for shared libraries, module
  3649. // libraries, and executables.
  3650. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3651. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3652. this->GetType() != cmTarget::EXECUTABLE)
  3653. {
  3654. implib = false;
  3655. }
  3656. // Compute the full name for main target types.
  3657. const char* targetPrefix = (implib
  3658. ? this->GetProperty("IMPORT_PREFIX")
  3659. : this->GetProperty("PREFIX"));
  3660. const char* targetSuffix = (implib
  3661. ? this->GetProperty("IMPORT_SUFFIX")
  3662. : this->GetProperty("SUFFIX"));
  3663. const char* configPostfix = 0;
  3664. if(config && *config)
  3665. {
  3666. std::string configProp = cmSystemTools::UpperCase(config);
  3667. configProp += "_POSTFIX";
  3668. configPostfix = this->GetProperty(configProp.c_str());
  3669. // Mac application bundles and frameworks have no postfix.
  3670. if(configPostfix &&
  3671. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3672. {
  3673. configPostfix = 0;
  3674. }
  3675. }
  3676. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3677. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3678. // Check for language-specific default prefix and suffix.
  3679. if(const char* ll = this->GetLinkerLanguage(config, this))
  3680. {
  3681. if(!targetSuffix && suffixVar && *suffixVar)
  3682. {
  3683. std::string langSuff = suffixVar + std::string("_") + ll;
  3684. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  3685. }
  3686. if(!targetPrefix && prefixVar && *prefixVar)
  3687. {
  3688. std::string langPrefix = prefixVar + std::string("_") + ll;
  3689. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  3690. }
  3691. }
  3692. // if there is no prefix on the target use the cmake definition
  3693. if(!targetPrefix && prefixVar)
  3694. {
  3695. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3696. }
  3697. // if there is no suffix on the target use the cmake definition
  3698. if(!targetSuffix && suffixVar)
  3699. {
  3700. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3701. }
  3702. // frameworks do not have a prefix or a suffix
  3703. if(this->IsFrameworkOnApple())
  3704. {
  3705. targetPrefix = 0;
  3706. targetSuffix = 0;
  3707. }
  3708. // Begin the final name with the prefix.
  3709. outPrefix = targetPrefix?targetPrefix:"";
  3710. // Append the target name or property-specified name.
  3711. outBase += this->GetOutputName(config, implib);
  3712. // Append the per-configuration postfix.
  3713. outBase += configPostfix?configPostfix:"";
  3714. // Name shared libraries with their version number on some platforms.
  3715. if(const char* soversion = this->GetProperty("SOVERSION"))
  3716. {
  3717. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3718. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3719. {
  3720. outBase += "-";
  3721. outBase += soversion;
  3722. }
  3723. }
  3724. // Append the suffix.
  3725. outSuffix = targetSuffix?targetSuffix:"";
  3726. }
  3727. //----------------------------------------------------------------------------
  3728. void cmTarget::GetLibraryNames(std::string& name,
  3729. std::string& soName,
  3730. std::string& realName,
  3731. std::string& impName,
  3732. std::string& pdbName,
  3733. const char* config)
  3734. {
  3735. // This should not be called for imported targets.
  3736. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3737. // enforcement of the limited imported target API.
  3738. if(this->IsImported())
  3739. {
  3740. std::string msg = "GetLibraryNames called on imported target: ";
  3741. msg += this->GetName();
  3742. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3743. msg.c_str());
  3744. return;
  3745. }
  3746. // Check for library version properties.
  3747. const char* version = this->GetProperty("VERSION");
  3748. const char* soversion = this->GetProperty("SOVERSION");
  3749. if(!this->HasSOName(config) ||
  3750. this->IsFrameworkOnApple())
  3751. {
  3752. // Versioning is supported only for shared libraries and modules,
  3753. // and then only when the platform supports an soname flag.
  3754. version = 0;
  3755. soversion = 0;
  3756. }
  3757. if(version && !soversion)
  3758. {
  3759. // The soversion must be set if the library version is set. Use
  3760. // the library version as the soversion.
  3761. soversion = version;
  3762. }
  3763. if(!version && soversion)
  3764. {
  3765. // Use the soversion as the library version.
  3766. version = soversion;
  3767. }
  3768. // Get the components of the library name.
  3769. std::string prefix;
  3770. std::string base;
  3771. std::string suffix;
  3772. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3773. // The library name.
  3774. name = prefix+base+suffix;
  3775. // The library's soname.
  3776. this->ComputeVersionedName(soName, prefix, base, suffix,
  3777. name, soversion);
  3778. // The library's real name on disk.
  3779. this->ComputeVersionedName(realName, prefix, base, suffix,
  3780. name, version);
  3781. // The import library name.
  3782. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3783. this->GetType() == cmTarget::MODULE_LIBRARY)
  3784. {
  3785. impName = this->GetFullNameInternal(config, true);
  3786. }
  3787. else
  3788. {
  3789. impName = "";
  3790. }
  3791. // The program database file name.
  3792. pdbName = this->GetPDBName(config);
  3793. }
  3794. //----------------------------------------------------------------------------
  3795. void cmTarget::ComputeVersionedName(std::string& vName,
  3796. std::string const& prefix,
  3797. std::string const& base,
  3798. std::string const& suffix,
  3799. std::string const& name,
  3800. const char* version)
  3801. {
  3802. vName = this->IsApple? (prefix+base) : name;
  3803. if(version)
  3804. {
  3805. vName += ".";
  3806. vName += version;
  3807. }
  3808. vName += this->IsApple? suffix : std::string();
  3809. }
  3810. //----------------------------------------------------------------------------
  3811. void cmTarget::GetExecutableNames(std::string& name,
  3812. std::string& realName,
  3813. std::string& impName,
  3814. std::string& pdbName,
  3815. const char* config)
  3816. {
  3817. // This should not be called for imported targets.
  3818. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3819. // enforcement of the limited imported target API.
  3820. if(this->IsImported())
  3821. {
  3822. std::string msg =
  3823. "GetExecutableNames called on imported target: ";
  3824. msg += this->GetName();
  3825. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3826. }
  3827. // This versioning is supported only for executables and then only
  3828. // when the platform supports symbolic links.
  3829. #if defined(_WIN32) && !defined(__CYGWIN__)
  3830. const char* version = 0;
  3831. #else
  3832. // Check for executable version properties.
  3833. const char* version = this->GetProperty("VERSION");
  3834. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3835. {
  3836. version = 0;
  3837. }
  3838. #endif
  3839. // Get the components of the executable name.
  3840. std::string prefix;
  3841. std::string base;
  3842. std::string suffix;
  3843. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3844. // The executable name.
  3845. name = prefix+base+suffix;
  3846. // The executable's real name on disk.
  3847. #if defined(__CYGWIN__)
  3848. realName = prefix+base;
  3849. #else
  3850. realName = name;
  3851. #endif
  3852. if(version)
  3853. {
  3854. realName += "-";
  3855. realName += version;
  3856. }
  3857. #if defined(__CYGWIN__)
  3858. realName += suffix;
  3859. #endif
  3860. // The import library name.
  3861. impName = this->GetFullNameInternal(config, true);
  3862. // The program database file name.
  3863. pdbName = this->GetPDBName(config);
  3864. }
  3865. //----------------------------------------------------------------------------
  3866. bool cmTarget::HasImplibGNUtoMS()
  3867. {
  3868. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3869. }
  3870. //----------------------------------------------------------------------------
  3871. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3872. std::string& out, const char* newExt)
  3873. {
  3874. if(this->HasImplibGNUtoMS() &&
  3875. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3876. {
  3877. out = gnuName.substr(0, gnuName.size()-6);
  3878. out += newExt? newExt : ".lib";
  3879. return true;
  3880. }
  3881. return false;
  3882. }
  3883. //----------------------------------------------------------------------------
  3884. void cmTarget::GenerateTargetManifest(const char* config)
  3885. {
  3886. cmMakefile* mf = this->Makefile;
  3887. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3888. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3889. // Get the names.
  3890. std::string name;
  3891. std::string soName;
  3892. std::string realName;
  3893. std::string impName;
  3894. std::string pdbName;
  3895. if(this->GetType() == cmTarget::EXECUTABLE)
  3896. {
  3897. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3898. }
  3899. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3900. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3901. this->GetType() == cmTarget::MODULE_LIBRARY)
  3902. {
  3903. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3904. }
  3905. else
  3906. {
  3907. return;
  3908. }
  3909. // Get the directory.
  3910. std::string dir = this->GetDirectory(config, false);
  3911. // Add each name.
  3912. std::string f;
  3913. if(!name.empty())
  3914. {
  3915. f = dir;
  3916. f += "/";
  3917. f += name;
  3918. gg->AddToManifest(config? config:"", f);
  3919. }
  3920. if(!soName.empty())
  3921. {
  3922. f = dir;
  3923. f += "/";
  3924. f += soName;
  3925. gg->AddToManifest(config? config:"", f);
  3926. }
  3927. if(!realName.empty())
  3928. {
  3929. f = dir;
  3930. f += "/";
  3931. f += realName;
  3932. gg->AddToManifest(config? config:"", f);
  3933. }
  3934. if(!pdbName.empty())
  3935. {
  3936. f = this->GetPDBDirectory(config);
  3937. f += "/";
  3938. f += pdbName;
  3939. gg->AddToManifest(config? config:"", f);
  3940. }
  3941. if(!impName.empty())
  3942. {
  3943. f = this->GetDirectory(config, true);
  3944. f += "/";
  3945. f += impName;
  3946. gg->AddToManifest(config? config:"", f);
  3947. }
  3948. }
  3949. //----------------------------------------------------------------------------
  3950. void cmTarget::SetPropertyDefault(const char* property,
  3951. const char* default_value)
  3952. {
  3953. // Compute the name of the variable holding the default value.
  3954. std::string var = "CMAKE_";
  3955. var += property;
  3956. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3957. {
  3958. this->SetProperty(property, value);
  3959. }
  3960. else if(default_value)
  3961. {
  3962. this->SetProperty(property, default_value);
  3963. }
  3964. }
  3965. //----------------------------------------------------------------------------
  3966. bool cmTarget::HaveBuildTreeRPATH(const char *config)
  3967. {
  3968. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3969. {
  3970. return false;
  3971. }
  3972. std::vector<std::string> libs;
  3973. this->GetDirectLinkLibraries(config, libs, this);
  3974. return !libs.empty();
  3975. }
  3976. //----------------------------------------------------------------------------
  3977. bool cmTarget::HaveInstallTreeRPATH()
  3978. {
  3979. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3980. return (install_rpath && *install_rpath) &&
  3981. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3982. }
  3983. //----------------------------------------------------------------------------
  3984. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3985. {
  3986. // Only executables and shared libraries can have an rpath and may
  3987. // need relinking.
  3988. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3989. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3990. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3991. {
  3992. return false;
  3993. }
  3994. // If there is no install location this target will not be installed
  3995. // and therefore does not need relinking.
  3996. if(!this->GetHaveInstallRule())
  3997. {
  3998. return false;
  3999. }
  4000. // If skipping all rpaths completely then no relinking is needed.
  4001. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4002. {
  4003. return false;
  4004. }
  4005. // If building with the install-tree rpath no relinking is needed.
  4006. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4007. {
  4008. return false;
  4009. }
  4010. // If chrpath is going to be used no relinking is needed.
  4011. if(this->IsChrpathUsed(config))
  4012. {
  4013. return false;
  4014. }
  4015. // Check for rpath support on this platform.
  4016. if(const char* ll = this->GetLinkerLanguage(config, this))
  4017. {
  4018. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4019. flagVar += ll;
  4020. flagVar += "_FLAG";
  4021. if(!this->Makefile->IsSet(flagVar.c_str()))
  4022. {
  4023. // There is no rpath support on this platform so nothing needs
  4024. // relinking.
  4025. return false;
  4026. }
  4027. }
  4028. else
  4029. {
  4030. // No linker language is known. This error will be reported by
  4031. // other code.
  4032. return false;
  4033. }
  4034. // If either a build or install tree rpath is set then the rpath
  4035. // will likely change between the build tree and install tree and
  4036. // this target must be relinked.
  4037. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  4038. }
  4039. //----------------------------------------------------------------------------
  4040. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  4041. bool for_xcode)
  4042. {
  4043. // If building directly for installation then the build tree install_name
  4044. // is the same as the install tree.
  4045. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4046. {
  4047. return GetInstallNameDirForInstallTree(config, for_xcode);
  4048. }
  4049. // Use the build tree directory for the target.
  4050. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  4051. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4052. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  4053. {
  4054. std::string dir = this->GetDirectory(config);
  4055. dir += "/";
  4056. if(this->IsFrameworkOnApple() && !for_xcode)
  4057. {
  4058. dir += this->GetFrameworkDirectory(config);
  4059. }
  4060. return dir;
  4061. }
  4062. else
  4063. {
  4064. return "";
  4065. }
  4066. }
  4067. //----------------------------------------------------------------------------
  4068. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  4069. bool for_xcode)
  4070. {
  4071. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4072. {
  4073. std::string dir;
  4074. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4075. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  4076. {
  4077. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  4078. if(install_name_dir && *install_name_dir)
  4079. {
  4080. dir = install_name_dir;
  4081. dir += "/";
  4082. }
  4083. }
  4084. if(this->IsFrameworkOnApple() && !for_xcode)
  4085. {
  4086. dir += this->GetFrameworkDirectory(config);
  4087. }
  4088. return dir;
  4089. }
  4090. else
  4091. {
  4092. return "";
  4093. }
  4094. }
  4095. //----------------------------------------------------------------------------
  4096. const char* cmTarget::GetOutputTargetType(bool implib)
  4097. {
  4098. switch(this->GetType())
  4099. {
  4100. case cmTarget::SHARED_LIBRARY:
  4101. if(this->DLLPlatform)
  4102. {
  4103. if(implib)
  4104. {
  4105. // A DLL import library is treated as an archive target.
  4106. return "ARCHIVE";
  4107. }
  4108. else
  4109. {
  4110. // A DLL shared library is treated as a runtime target.
  4111. return "RUNTIME";
  4112. }
  4113. }
  4114. else
  4115. {
  4116. // For non-DLL platforms shared libraries are treated as
  4117. // library targets.
  4118. return "LIBRARY";
  4119. }
  4120. case cmTarget::STATIC_LIBRARY:
  4121. // Static libraries are always treated as archive targets.
  4122. return "ARCHIVE";
  4123. case cmTarget::MODULE_LIBRARY:
  4124. if(implib)
  4125. {
  4126. // Module libraries are always treated as library targets.
  4127. return "ARCHIVE";
  4128. }
  4129. else
  4130. {
  4131. // Module import libraries are treated as archive targets.
  4132. return "LIBRARY";
  4133. }
  4134. case cmTarget::EXECUTABLE:
  4135. if(implib)
  4136. {
  4137. // Executable import libraries are treated as archive targets.
  4138. return "ARCHIVE";
  4139. }
  4140. else
  4141. {
  4142. // Executables are always treated as runtime targets.
  4143. return "RUNTIME";
  4144. }
  4145. default:
  4146. break;
  4147. }
  4148. return "";
  4149. }
  4150. //----------------------------------------------------------------------------
  4151. bool cmTarget::ComputeOutputDir(const char* config,
  4152. bool implib, std::string& out)
  4153. {
  4154. bool usesDefaultOutputDir = false;
  4155. // Look for a target property defining the target output directory
  4156. // based on the target type.
  4157. std::string targetTypeName = this->GetOutputTargetType(implib);
  4158. const char* propertyName = 0;
  4159. std::string propertyNameStr = targetTypeName;
  4160. if(!propertyNameStr.empty())
  4161. {
  4162. propertyNameStr += "_OUTPUT_DIRECTORY";
  4163. propertyName = propertyNameStr.c_str();
  4164. }
  4165. // Check for a per-configuration output directory target property.
  4166. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  4167. const char* configProp = 0;
  4168. std::string configPropStr = targetTypeName;
  4169. if(!configPropStr.empty())
  4170. {
  4171. configPropStr += "_OUTPUT_DIRECTORY_";
  4172. configPropStr += configUpper;
  4173. configProp = configPropStr.c_str();
  4174. }
  4175. // Select an output directory.
  4176. if(const char* config_outdir = this->GetProperty(configProp))
  4177. {
  4178. // Use the user-specified per-configuration output directory.
  4179. out = config_outdir;
  4180. // Skip per-configuration subdirectory.
  4181. config = 0;
  4182. }
  4183. else if(const char* outdir = this->GetProperty(propertyName))
  4184. {
  4185. // Use the user-specified output directory.
  4186. out = outdir;
  4187. }
  4188. else if(this->GetType() == cmTarget::EXECUTABLE)
  4189. {
  4190. // Lookup the output path for executables.
  4191. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4192. }
  4193. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  4194. this->GetType() == cmTarget::SHARED_LIBRARY ||
  4195. this->GetType() == cmTarget::MODULE_LIBRARY)
  4196. {
  4197. // Lookup the output path for libraries.
  4198. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4199. }
  4200. if(out.empty())
  4201. {
  4202. // Default to the current output directory.
  4203. usesDefaultOutputDir = true;
  4204. out = ".";
  4205. }
  4206. // Convert the output path to a full path in case it is
  4207. // specified as a relative path. Treat a relative path as
  4208. // relative to the current output directory for this makefile.
  4209. out = (cmSystemTools::CollapseFullPath
  4210. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4211. // The generator may add the configuration's subdirectory.
  4212. if(config && *config)
  4213. {
  4214. const char *platforms = this->Makefile->GetDefinition(
  4215. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  4216. std::string suffix =
  4217. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  4218. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4219. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  4220. }
  4221. return usesDefaultOutputDir;
  4222. }
  4223. //----------------------------------------------------------------------------
  4224. bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
  4225. {
  4226. // Look for a target property defining the target output directory
  4227. // based on the target type.
  4228. std::string targetTypeName = "PDB";
  4229. const char* propertyName = 0;
  4230. std::string propertyNameStr = targetTypeName;
  4231. if(!propertyNameStr.empty())
  4232. {
  4233. propertyNameStr += "_OUTPUT_DIRECTORY";
  4234. propertyName = propertyNameStr.c_str();
  4235. }
  4236. // Check for a per-configuration output directory target property.
  4237. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  4238. const char* configProp = 0;
  4239. std::string configPropStr = targetTypeName;
  4240. if(!configPropStr.empty())
  4241. {
  4242. configPropStr += "_OUTPUT_DIRECTORY_";
  4243. configPropStr += configUpper;
  4244. configProp = configPropStr.c_str();
  4245. }
  4246. // Select an output directory.
  4247. if(const char* config_outdir = this->GetProperty(configProp))
  4248. {
  4249. // Use the user-specified per-configuration output directory.
  4250. out = config_outdir;
  4251. // Skip per-configuration subdirectory.
  4252. config = 0;
  4253. }
  4254. else if(const char* outdir = this->GetProperty(propertyName))
  4255. {
  4256. // Use the user-specified output directory.
  4257. out = outdir;
  4258. }
  4259. if(out.empty())
  4260. {
  4261. return false;
  4262. }
  4263. // Convert the output path to a full path in case it is
  4264. // specified as a relative path. Treat a relative path as
  4265. // relative to the current output directory for this makefile.
  4266. out = (cmSystemTools::CollapseFullPath
  4267. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4268. // The generator may add the configuration's subdirectory.
  4269. if(config && *config)
  4270. {
  4271. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4272. AppendDirectoryForConfig("/", config, "", out);
  4273. }
  4274. return true;
  4275. }
  4276. //----------------------------------------------------------------------------
  4277. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
  4278. {
  4279. std::string dir;
  4280. return this->ComputeOutputDir(config, implib, dir);
  4281. }
  4282. //----------------------------------------------------------------------------
  4283. std::string cmTarget::GetOutputName(const char* config, bool implib)
  4284. {
  4285. std::vector<std::string> props;
  4286. std::string type = this->GetOutputTargetType(implib);
  4287. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  4288. if(!type.empty() && !configUpper.empty())
  4289. {
  4290. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4291. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4292. }
  4293. if(!type.empty())
  4294. {
  4295. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4296. props.push_back(type + "_OUTPUT_NAME");
  4297. }
  4298. if(!configUpper.empty())
  4299. {
  4300. // OUTPUT_NAME_<CONFIG>
  4301. props.push_back("OUTPUT_NAME_" + configUpper);
  4302. // <CONFIG>_OUTPUT_NAME
  4303. props.push_back(configUpper + "_OUTPUT_NAME");
  4304. }
  4305. // OUTPUT_NAME
  4306. props.push_back("OUTPUT_NAME");
  4307. for(std::vector<std::string>::const_iterator i = props.begin();
  4308. i != props.end(); ++i)
  4309. {
  4310. if(const char* outName = this->GetProperty(i->c_str()))
  4311. {
  4312. return outName;
  4313. }
  4314. }
  4315. return this->GetName();
  4316. }
  4317. //----------------------------------------------------------------------------
  4318. std::string cmTarget::GetFrameworkVersion()
  4319. {
  4320. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4321. {
  4322. return fversion;
  4323. }
  4324. else if(const char* tversion = this->GetProperty("VERSION"))
  4325. {
  4326. return tversion;
  4327. }
  4328. else
  4329. {
  4330. return "A";
  4331. }
  4332. }
  4333. //----------------------------------------------------------------------------
  4334. const char* cmTarget::GetExportMacro()
  4335. {
  4336. // Define the symbol for targets that export symbols.
  4337. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4338. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4339. this->IsExecutableWithExports())
  4340. {
  4341. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4342. {
  4343. this->ExportMacro = custom_export_name;
  4344. }
  4345. else
  4346. {
  4347. std::string in = this->GetName();
  4348. in += "_EXPORTS";
  4349. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4350. }
  4351. return this->ExportMacro.c_str();
  4352. }
  4353. else
  4354. {
  4355. return 0;
  4356. }
  4357. }
  4358. //----------------------------------------------------------------------------
  4359. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p)
  4360. {
  4361. return this->LinkImplicitNullProperties.find(p)
  4362. != this->LinkImplicitNullProperties.end();
  4363. }
  4364. //----------------------------------------------------------------------------
  4365. template<typename PropertyType>
  4366. PropertyType getTypedProperty(cmTarget *tgt, const char *prop,
  4367. PropertyType *);
  4368. //----------------------------------------------------------------------------
  4369. template<>
  4370. bool getTypedProperty<bool>(cmTarget *tgt, const char *prop, bool *)
  4371. {
  4372. return tgt->GetPropertyAsBool(prop);
  4373. }
  4374. //----------------------------------------------------------------------------
  4375. template<>
  4376. const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop,
  4377. const char **)
  4378. {
  4379. return tgt->GetProperty(prop);
  4380. }
  4381. //----------------------------------------------------------------------------
  4382. template<typename PropertyType>
  4383. bool consistentProperty(PropertyType lhs, PropertyType rhs);
  4384. //----------------------------------------------------------------------------
  4385. template<>
  4386. bool consistentProperty(bool lhs, bool rhs)
  4387. {
  4388. return lhs == rhs;
  4389. }
  4390. //----------------------------------------------------------------------------
  4391. template<>
  4392. bool consistentProperty(const char *lhs, const char *rhs)
  4393. {
  4394. if (!lhs && !rhs)
  4395. return true;
  4396. if (!lhs || !rhs)
  4397. return false;
  4398. return strcmp(lhs, rhs) == 0;
  4399. }
  4400. //----------------------------------------------------------------------------
  4401. template<typename PropertyType>
  4402. PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
  4403. const std::string &p,
  4404. const char *config,
  4405. const char *defaultValue,
  4406. PropertyType *)
  4407. {
  4408. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
  4409. 0);
  4410. const bool explicitlySet = tgt->GetProperties()
  4411. .find(p.c_str())
  4412. != tgt->GetProperties().end();
  4413. const bool impliedByUse =
  4414. tgt->IsNullImpliedByLinkLibraries(p);
  4415. assert((impliedByUse ^ explicitlySet)
  4416. || (!impliedByUse && !explicitlySet));
  4417. cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
  4418. if(!info)
  4419. {
  4420. return propContent;
  4421. }
  4422. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  4423. bool propInitialized = explicitlySet;
  4424. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  4425. deps.begin();
  4426. li != deps.end(); ++li)
  4427. {
  4428. // An error should be reported if one dependency
  4429. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4430. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4431. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4432. // with a dependency.
  4433. if (!li->Target)
  4434. {
  4435. continue;
  4436. }
  4437. const bool ifaceIsSet = li->Target->GetProperties()
  4438. .find("INTERFACE_" + p)
  4439. != li->Target->GetProperties().end();
  4440. PropertyType ifacePropContent =
  4441. getTypedProperty<PropertyType>(li->Target,
  4442. ("INTERFACE_" + p).c_str(), 0);
  4443. if (explicitlySet)
  4444. {
  4445. if (ifaceIsSet)
  4446. {
  4447. if (!consistentProperty(propContent, ifacePropContent))
  4448. {
  4449. cmOStringStream e;
  4450. e << "Property " << p << " on target \""
  4451. << tgt->GetName() << "\" does\nnot match the "
  4452. "INTERFACE_" << p << " property requirement\nof "
  4453. "dependency \"" << li->Target->GetName() << "\".\n";
  4454. cmSystemTools::Error(e.str().c_str());
  4455. break;
  4456. }
  4457. else
  4458. {
  4459. // Agree
  4460. continue;
  4461. }
  4462. }
  4463. else
  4464. {
  4465. // Explicitly set on target and not set in iface. Can't disagree.
  4466. continue;
  4467. }
  4468. }
  4469. else if (impliedByUse)
  4470. {
  4471. if (ifaceIsSet)
  4472. {
  4473. if (!consistentProperty(propContent, ifacePropContent))
  4474. {
  4475. cmOStringStream e;
  4476. e << "Property " << p << " on target \""
  4477. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4478. << " because it was used to determine the link libraries\n"
  4479. "already. The INTERFACE_" << p << " property on\ndependency \""
  4480. << li->Target->GetName() << "\" is in conflict.\n";
  4481. cmSystemTools::Error(e.str().c_str());
  4482. break;
  4483. }
  4484. else
  4485. {
  4486. // Agree
  4487. continue;
  4488. }
  4489. }
  4490. else
  4491. {
  4492. // Implicitly set on target and not set in iface. Can't disagree.
  4493. continue;
  4494. }
  4495. }
  4496. else
  4497. {
  4498. if (ifaceIsSet)
  4499. {
  4500. if (propInitialized)
  4501. {
  4502. if (!consistentProperty(propContent, ifacePropContent))
  4503. {
  4504. cmOStringStream e;
  4505. e << "The INTERFACE_" << p << " property of \""
  4506. << li->Target->GetName() << "\" does\nnot agree with the value "
  4507. "of " << p << " already determined\nfor \""
  4508. << tgt->GetName() << "\".\n";
  4509. cmSystemTools::Error(e.str().c_str());
  4510. break;
  4511. }
  4512. else
  4513. {
  4514. // Agree.
  4515. continue;
  4516. }
  4517. }
  4518. else
  4519. {
  4520. propContent = ifacePropContent;
  4521. propInitialized = true;
  4522. }
  4523. }
  4524. else
  4525. {
  4526. // Not set. Nothing to agree on.
  4527. continue;
  4528. }
  4529. }
  4530. }
  4531. return propContent;
  4532. }
  4533. //----------------------------------------------------------------------------
  4534. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4535. const char *config)
  4536. {
  4537. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4538. 0);
  4539. }
  4540. //----------------------------------------------------------------------------
  4541. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4542. const std::string &p,
  4543. const char *config)
  4544. {
  4545. return checkInterfacePropertyCompatibility<const char *>(this,
  4546. p,
  4547. config,
  4548. "empty", 0);
  4549. }
  4550. //----------------------------------------------------------------------------
  4551. bool isLinkDependentProperty(cmTarget *tgt, const std::string &p,
  4552. const char *interfaceProperty,
  4553. const char *config)
  4554. {
  4555. cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
  4556. if(!info)
  4557. {
  4558. return false;
  4559. }
  4560. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  4561. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  4562. deps.begin();
  4563. li != deps.end(); ++li)
  4564. {
  4565. if (!li->Target)
  4566. {
  4567. continue;
  4568. }
  4569. const char *prop = li->Target->GetProperty(interfaceProperty);
  4570. if (!prop)
  4571. {
  4572. continue;
  4573. }
  4574. std::vector<std::string> props;
  4575. cmSystemTools::ExpandListArgument(prop, props);
  4576. for(std::vector<std::string>::iterator pi = props.begin();
  4577. pi != props.end(); ++pi)
  4578. {
  4579. if (*pi == p)
  4580. {
  4581. return true;
  4582. }
  4583. }
  4584. }
  4585. return false;
  4586. }
  4587. //----------------------------------------------------------------------------
  4588. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4589. const char *config)
  4590. {
  4591. if (this->TargetTypeValue == OBJECT_LIBRARY)
  4592. {
  4593. return false;
  4594. }
  4595. return (p == "POSITION_INDEPENDENT_CODE") ||
  4596. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
  4597. config);
  4598. }
  4599. //----------------------------------------------------------------------------
  4600. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4601. const char *config)
  4602. {
  4603. if (this->TargetTypeValue == OBJECT_LIBRARY)
  4604. {
  4605. return false;
  4606. }
  4607. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
  4608. config);
  4609. }
  4610. //----------------------------------------------------------------------------
  4611. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  4612. {
  4613. for(std::vector<cmSourceFile*>::const_iterator
  4614. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  4615. {
  4616. if(const char* lang = (*i)->GetLanguage())
  4617. {
  4618. languages.insert(lang);
  4619. }
  4620. }
  4621. }
  4622. //----------------------------------------------------------------------------
  4623. bool cmTarget::IsChrpathUsed(const char* config)
  4624. {
  4625. #if defined(CMAKE_USE_ELF_PARSER)
  4626. // Only certain target types have an rpath.
  4627. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4628. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4629. this->GetType() == cmTarget::EXECUTABLE))
  4630. {
  4631. return false;
  4632. }
  4633. // If the target will not be installed we do not need to change its
  4634. // rpath.
  4635. if(!this->GetHaveInstallRule())
  4636. {
  4637. return false;
  4638. }
  4639. // Skip chrpath if skipping rpath altogether.
  4640. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4641. {
  4642. return false;
  4643. }
  4644. // Skip chrpath if it does not need to be changed at install time.
  4645. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4646. {
  4647. return false;
  4648. }
  4649. // Allow the user to disable builtin chrpath explicitly.
  4650. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4651. {
  4652. return false;
  4653. }
  4654. // Enable if the rpath flag uses a separator and the target uses ELF
  4655. // binaries.
  4656. if(const char* ll = this->GetLinkerLanguage(config, this))
  4657. {
  4658. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4659. sepVar += ll;
  4660. sepVar += "_FLAG_SEP";
  4661. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  4662. if(sep && *sep)
  4663. {
  4664. // TODO: Add ELF check to ABI detection and get rid of
  4665. // CMAKE_EXECUTABLE_FORMAT.
  4666. if(const char* fmt =
  4667. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4668. {
  4669. return strcmp(fmt, "ELF") == 0;
  4670. }
  4671. }
  4672. }
  4673. #endif
  4674. static_cast<void>(config);
  4675. return false;
  4676. }
  4677. //----------------------------------------------------------------------------
  4678. cmTarget::ImportInfo const*
  4679. cmTarget::GetImportInfo(const char* config, cmTarget *headTarget)
  4680. {
  4681. // There is no imported information for non-imported targets.
  4682. if(!this->IsImported())
  4683. {
  4684. return 0;
  4685. }
  4686. // Lookup/compute/cache the import information for this
  4687. // configuration.
  4688. std::string config_upper;
  4689. if(config && *config)
  4690. {
  4691. config_upper = cmSystemTools::UpperCase(config);
  4692. }
  4693. else
  4694. {
  4695. config_upper = "NOCONFIG";
  4696. }
  4697. TargetConfigPair key(headTarget, config_upper);
  4698. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4699. ImportInfoMapType::const_iterator i =
  4700. this->Internal->ImportInfoMap.find(key);
  4701. if(i == this->Internal->ImportInfoMap.end())
  4702. {
  4703. ImportInfo info;
  4704. this->ComputeImportInfo(config_upper, info, headTarget);
  4705. ImportInfoMapType::value_type entry(key, info);
  4706. i = this->Internal->ImportInfoMap.insert(entry).first;
  4707. }
  4708. // If the location is empty then the target is not available for
  4709. // this configuration.
  4710. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4711. {
  4712. return 0;
  4713. }
  4714. // Return the import information.
  4715. return &i->second;
  4716. }
  4717. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4718. const char** loc,
  4719. const char** imp,
  4720. std::string& suffix)
  4721. {
  4722. // Track the configuration-specific property suffix.
  4723. suffix = "_";
  4724. suffix += desired_config;
  4725. std::vector<std::string> mappedConfigs;
  4726. {
  4727. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  4728. mapProp += desired_config;
  4729. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  4730. {
  4731. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  4732. }
  4733. }
  4734. // If we needed to find one of the mapped configurations but did not
  4735. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  4736. // library or an executable with exports.
  4737. bool allowImp = this->HasImportLibrary();
  4738. // If a mapping was found, check its configurations.
  4739. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  4740. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  4741. {
  4742. // Look for this configuration.
  4743. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  4744. std::string locProp = "IMPORTED_LOCATION_";
  4745. locProp += mcUpper;
  4746. *loc = this->GetProperty(locProp.c_str());
  4747. if(allowImp)
  4748. {
  4749. std::string impProp = "IMPORTED_IMPLIB_";
  4750. impProp += mcUpper;
  4751. *imp = this->GetProperty(impProp.c_str());
  4752. }
  4753. // If it was found, use it for all properties below.
  4754. if(*loc || *imp)
  4755. {
  4756. suffix = "_";
  4757. suffix += mcUpper;
  4758. }
  4759. }
  4760. // If we needed to find one of the mapped configurations but did not
  4761. // then the target is not found. The project does not want any
  4762. // other configuration.
  4763. if(!mappedConfigs.empty() && !*loc && !*imp)
  4764. {
  4765. return false;
  4766. }
  4767. // If we have not yet found it then there are no mapped
  4768. // configurations. Look for an exact-match.
  4769. if(!*loc && !*imp)
  4770. {
  4771. std::string locProp = "IMPORTED_LOCATION";
  4772. locProp += suffix;
  4773. *loc = this->GetProperty(locProp.c_str());
  4774. if(allowImp)
  4775. {
  4776. std::string impProp = "IMPORTED_IMPLIB";
  4777. impProp += suffix;
  4778. *imp = this->GetProperty(impProp.c_str());
  4779. }
  4780. }
  4781. // If we have not yet found it then there are no mapped
  4782. // configurations and no exact match.
  4783. if(!*loc && !*imp)
  4784. {
  4785. // The suffix computed above is not useful.
  4786. suffix = "";
  4787. // Look for a configuration-less location. This may be set by
  4788. // manually-written code.
  4789. *loc = this->GetProperty("IMPORTED_LOCATION");
  4790. if(allowImp)
  4791. {
  4792. *imp = this->GetProperty("IMPORTED_IMPLIB");
  4793. }
  4794. }
  4795. // If we have not yet found it then the project is willing to try
  4796. // any available configuration.
  4797. if(!*loc && !*imp)
  4798. {
  4799. std::vector<std::string> availableConfigs;
  4800. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  4801. {
  4802. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  4803. }
  4804. for(std::vector<std::string>::const_iterator
  4805. aci = availableConfigs.begin();
  4806. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  4807. {
  4808. suffix = "_";
  4809. suffix += cmSystemTools::UpperCase(*aci);
  4810. std::string locProp = "IMPORTED_LOCATION";
  4811. locProp += suffix;
  4812. *loc = this->GetProperty(locProp.c_str());
  4813. if(allowImp)
  4814. {
  4815. std::string impProp = "IMPORTED_IMPLIB";
  4816. impProp += suffix;
  4817. *imp = this->GetProperty(impProp.c_str());
  4818. }
  4819. }
  4820. }
  4821. // If we have not yet found it then the target is not available.
  4822. if(!*loc && !*imp)
  4823. {
  4824. return false;
  4825. }
  4826. return true;
  4827. }
  4828. //----------------------------------------------------------------------------
  4829. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  4830. ImportInfo& info,
  4831. cmTarget *headTarget)
  4832. {
  4833. // This method finds information about an imported target from its
  4834. // properties. The "IMPORTED_" namespace is reserved for properties
  4835. // defined by the project exporting the target.
  4836. // Initialize members.
  4837. info.NoSOName = false;
  4838. const char* loc = 0;
  4839. const char* imp = 0;
  4840. std::string suffix;
  4841. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  4842. {
  4843. return;
  4844. }
  4845. // A provided configuration has been chosen. Load the
  4846. // configuration's properties.
  4847. // Get the location.
  4848. if(loc)
  4849. {
  4850. info.Location = loc;
  4851. }
  4852. else
  4853. {
  4854. std::string impProp = "IMPORTED_LOCATION";
  4855. impProp += suffix;
  4856. if(const char* config_location = this->GetProperty(impProp.c_str()))
  4857. {
  4858. info.Location = config_location;
  4859. }
  4860. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  4861. {
  4862. info.Location = location;
  4863. }
  4864. }
  4865. // Get the soname.
  4866. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4867. {
  4868. std::string soProp = "IMPORTED_SONAME";
  4869. soProp += suffix;
  4870. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  4871. {
  4872. info.SOName = config_soname;
  4873. }
  4874. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  4875. {
  4876. info.SOName = soname;
  4877. }
  4878. }
  4879. // Get the "no-soname" mark.
  4880. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4881. {
  4882. std::string soProp = "IMPORTED_NO_SONAME";
  4883. soProp += suffix;
  4884. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  4885. {
  4886. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4887. }
  4888. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4889. {
  4890. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4891. }
  4892. }
  4893. // Get the import library.
  4894. if(imp)
  4895. {
  4896. info.ImportLibrary = imp;
  4897. }
  4898. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4899. this->IsExecutableWithExports())
  4900. {
  4901. std::string impProp = "IMPORTED_IMPLIB";
  4902. impProp += suffix;
  4903. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  4904. {
  4905. info.ImportLibrary = config_implib;
  4906. }
  4907. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4908. {
  4909. info.ImportLibrary = implib;
  4910. }
  4911. }
  4912. // Get the link interface.
  4913. {
  4914. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4915. linkProp += suffix;
  4916. const char *propertyLibs = this->GetProperty(linkProp.c_str());
  4917. if(!propertyLibs)
  4918. {
  4919. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4920. propertyLibs = this->GetProperty(linkProp.c_str());
  4921. }
  4922. if(propertyLibs)
  4923. {
  4924. cmListFileBacktrace lfbt;
  4925. cmGeneratorExpression ge(lfbt);
  4926. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  4927. this->GetName(),
  4928. linkProp, 0, 0);
  4929. cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
  4930. ->Evaluate(this->Makefile,
  4931. desired_config.c_str(),
  4932. false,
  4933. headTarget,
  4934. this,
  4935. &dagChecker),
  4936. info.LinkInterface.Libraries);
  4937. }
  4938. }
  4939. // Get the link dependencies.
  4940. {
  4941. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4942. linkProp += suffix;
  4943. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4944. {
  4945. cmSystemTools::ExpandListArgument(config_libs,
  4946. info.LinkInterface.SharedDeps);
  4947. }
  4948. else if(const char* libs =
  4949. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4950. {
  4951. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  4952. }
  4953. }
  4954. // Get the link languages.
  4955. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4956. {
  4957. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4958. linkProp += suffix;
  4959. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4960. {
  4961. cmSystemTools::ExpandListArgument(config_libs,
  4962. info.LinkInterface.Languages);
  4963. }
  4964. else if(const char* libs =
  4965. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4966. {
  4967. cmSystemTools::ExpandListArgument(libs,
  4968. info.LinkInterface.Languages);
  4969. }
  4970. }
  4971. // Get the cyclic repetition count.
  4972. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4973. {
  4974. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4975. linkProp += suffix;
  4976. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  4977. {
  4978. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  4979. }
  4980. else if(const char* reps =
  4981. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4982. {
  4983. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  4984. }
  4985. }
  4986. }
  4987. //----------------------------------------------------------------------------
  4988. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
  4989. cmTarget *head)
  4990. {
  4991. // Imported targets have their own link interface.
  4992. if(this->IsImported())
  4993. {
  4994. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  4995. {
  4996. return &info->LinkInterface;
  4997. }
  4998. return 0;
  4999. }
  5000. // Link interfaces are not supported for executables that do not
  5001. // export symbols.
  5002. if(this->GetType() == cmTarget::EXECUTABLE &&
  5003. !this->IsExecutableWithExports())
  5004. {
  5005. return 0;
  5006. }
  5007. // Lookup any existing link interface for this configuration.
  5008. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  5009. cmTargetInternals::LinkInterfaceMapType::iterator
  5010. i = this->Internal->LinkInterfaceMap.find(key);
  5011. if(i == this->Internal->LinkInterfaceMap.end())
  5012. {
  5013. // Compute the link interface for this configuration.
  5014. cmTargetInternals::OptionalLinkInterface iface;
  5015. iface.Exists = this->ComputeLinkInterface(config, iface, head);
  5016. // Store the information for this configuration.
  5017. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  5018. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  5019. }
  5020. return i->second.Exists? &i->second : 0;
  5021. }
  5022. //----------------------------------------------------------------------------
  5023. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
  5024. cmTarget *headTarget)
  5025. {
  5026. // Construct the property name suffix for this configuration.
  5027. std::string suffix = "_";
  5028. if(config && *config)
  5029. {
  5030. suffix += cmSystemTools::UpperCase(config);
  5031. }
  5032. else
  5033. {
  5034. suffix += "NOCONFIG";
  5035. }
  5036. // An explicit list of interface libraries may be set for shared
  5037. // libraries and executables that export symbols.
  5038. const char* explicitLibraries = 0;
  5039. std::string linkIfaceProp;
  5040. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5041. this->IsExecutableWithExports())
  5042. {
  5043. // Lookup the per-configuration property.
  5044. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5045. linkIfaceProp += suffix;
  5046. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  5047. // If not set, try the generic property.
  5048. if(!explicitLibraries)
  5049. {
  5050. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5051. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  5052. }
  5053. }
  5054. // There is no implicit link interface for executables or modules
  5055. // so if none was explicitly set then there is no link interface.
  5056. // Note that CMake versions 2.2 and below allowed linking to modules.
  5057. bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
  5058. if(!explicitLibraries &&
  5059. (this->GetType() == cmTarget::EXECUTABLE ||
  5060. (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
  5061. {
  5062. return false;
  5063. }
  5064. if(explicitLibraries)
  5065. {
  5066. // The interface libraries have been explicitly set.
  5067. cmListFileBacktrace lfbt;
  5068. cmGeneratorExpression ge(lfbt);
  5069. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5070. linkIfaceProp, 0, 0);
  5071. cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
  5072. this->Makefile,
  5073. config,
  5074. false,
  5075. headTarget,
  5076. this, &dagChecker), iface.Libraries);
  5077. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5078. {
  5079. // Shared libraries may have runtime implementation dependencies
  5080. // on other shared libraries that are not in the interface.
  5081. std::set<cmStdString> emitted;
  5082. for(std::vector<std::string>::const_iterator
  5083. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5084. {
  5085. emitted.insert(*li);
  5086. }
  5087. LinkImplementation const* impl = this->GetLinkImplementation(config,
  5088. headTarget);
  5089. for(std::vector<std::string>::const_iterator
  5090. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5091. {
  5092. if(emitted.insert(*li).second)
  5093. {
  5094. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  5095. {
  5096. // This is a runtime dependency on another shared library.
  5097. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  5098. {
  5099. iface.SharedDeps.push_back(*li);
  5100. }
  5101. }
  5102. else
  5103. {
  5104. // TODO: Recognize shared library file names. Perhaps this
  5105. // should be moved to cmComputeLinkInformation, but that creates
  5106. // a chicken-and-egg problem since this list is needed for its
  5107. // construction.
  5108. }
  5109. }
  5110. }
  5111. }
  5112. }
  5113. else
  5114. {
  5115. // The link implementation is the default link interface.
  5116. LinkImplementation const* impl = this->GetLinkImplementation(config,
  5117. headTarget);
  5118. iface.ImplementationIsInterface = true;
  5119. iface.Libraries = impl->Libraries;
  5120. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5121. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5122. {
  5123. // Targets using this archive need its language runtime libraries.
  5124. iface.Languages = impl->Languages;
  5125. }
  5126. }
  5127. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5128. {
  5129. // How many repetitions are needed if this library has cyclic
  5130. // dependencies?
  5131. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5132. propName += suffix;
  5133. if(const char* config_reps = this->GetProperty(propName.c_str()))
  5134. {
  5135. sscanf(config_reps, "%u", &iface.Multiplicity);
  5136. }
  5137. else if(const char* reps =
  5138. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5139. {
  5140. sscanf(reps, "%u", &iface.Multiplicity);
  5141. }
  5142. }
  5143. return true;
  5144. }
  5145. //----------------------------------------------------------------------------
  5146. cmTarget::LinkImplementation const*
  5147. cmTarget::GetLinkImplementation(const char* config, cmTarget *head)
  5148. {
  5149. // There is no link implementation for imported targets.
  5150. if(this->IsImported())
  5151. {
  5152. return 0;
  5153. }
  5154. // Lookup any existing link implementation for this configuration.
  5155. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  5156. cmTargetInternals::LinkImplMapType::iterator
  5157. i = this->Internal->LinkImplMap.find(key);
  5158. if(i == this->Internal->LinkImplMap.end())
  5159. {
  5160. // Compute the link implementation for this configuration.
  5161. LinkImplementation impl;
  5162. this->ComputeLinkImplementation(config, impl, head);
  5163. // Store the information for this configuration.
  5164. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  5165. i = this->Internal->LinkImplMap.insert(entry).first;
  5166. }
  5167. return &i->second;
  5168. }
  5169. //----------------------------------------------------------------------------
  5170. void cmTarget::ComputeLinkImplementation(const char* config,
  5171. LinkImplementation& impl,
  5172. cmTarget *head)
  5173. {
  5174. // Compute which library configuration to link.
  5175. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  5176. // Collect libraries directly linked in this configuration.
  5177. std::vector<std::string> llibs;
  5178. this->GetDirectLinkLibraries(config, llibs, head);
  5179. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5180. li != llibs.end(); ++li)
  5181. {
  5182. // Skip entries that resolve to the target itself or are empty.
  5183. std::string item = this->CheckCMP0004(*li);
  5184. if(item == this->GetName() || item.empty())
  5185. {
  5186. continue;
  5187. }
  5188. // The entry is meant for this configuration.
  5189. impl.Libraries.push_back(item);
  5190. }
  5191. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  5192. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5193. li != oldllibs.end(); ++li)
  5194. {
  5195. if(li->second != cmTarget::GENERAL && li->second != linkType)
  5196. {
  5197. std::string item = this->CheckCMP0004(li->first);
  5198. if(item == this->GetName() || item.empty())
  5199. {
  5200. continue;
  5201. }
  5202. // Support OLD behavior for CMP0003.
  5203. impl.WrongConfigLibraries.push_back(item);
  5204. }
  5205. }
  5206. // This target needs runtime libraries for its source languages.
  5207. std::set<cmStdString> languages;
  5208. // Get languages used in our source files.
  5209. this->GetLanguages(languages);
  5210. // Get languages used in object library sources.
  5211. for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
  5212. i != this->ObjectLibraries.end(); ++i)
  5213. {
  5214. if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
  5215. {
  5216. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  5217. {
  5218. objLib->GetLanguages(languages);
  5219. }
  5220. }
  5221. }
  5222. // Copy the set of langauges to the link implementation.
  5223. for(std::set<cmStdString>::iterator li = languages.begin();
  5224. li != languages.end(); ++li)
  5225. {
  5226. impl.Languages.push_back(*li);
  5227. }
  5228. }
  5229. //----------------------------------------------------------------------------
  5230. std::string cmTarget::CheckCMP0004(std::string const& item)
  5231. {
  5232. // Strip whitespace off the library names because we used to do this
  5233. // in case variables were expanded at generate time. We no longer
  5234. // do the expansion but users link to libraries like " ${VAR} ".
  5235. std::string lib = item;
  5236. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5237. if(pos != lib.npos)
  5238. {
  5239. lib = lib.substr(pos, lib.npos);
  5240. }
  5241. pos = lib.find_last_not_of(" \t\r\n");
  5242. if(pos != lib.npos)
  5243. {
  5244. lib = lib.substr(0, pos+1);
  5245. }
  5246. if(lib != item)
  5247. {
  5248. cmake* cm = this->Makefile->GetCMakeInstance();
  5249. switch(this->PolicyStatusCMP0004)
  5250. {
  5251. case cmPolicies::WARN:
  5252. {
  5253. cmOStringStream w;
  5254. w << (this->Makefile->GetPolicies()
  5255. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  5256. << "Target \"" << this->GetName() << "\" links to item \""
  5257. << item << "\" which has leading or trailing whitespace.";
  5258. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5259. this->GetBacktrace());
  5260. }
  5261. case cmPolicies::OLD:
  5262. break;
  5263. case cmPolicies::NEW:
  5264. {
  5265. cmOStringStream e;
  5266. e << "Target \"" << this->GetName() << "\" links to item \""
  5267. << item << "\" which has leading or trailing whitespace. "
  5268. << "This is now an error according to policy CMP0004.";
  5269. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5270. }
  5271. break;
  5272. case cmPolicies::REQUIRED_IF_USED:
  5273. case cmPolicies::REQUIRED_ALWAYS:
  5274. {
  5275. cmOStringStream e;
  5276. e << (this->Makefile->GetPolicies()
  5277. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  5278. << "Target \"" << this->GetName() << "\" links to item \""
  5279. << item << "\" which has leading or trailing whitespace.";
  5280. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5281. }
  5282. break;
  5283. }
  5284. }
  5285. return lib;
  5286. }
  5287. template<typename PropertyType>
  5288. PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt,
  5289. const std::string prop,
  5290. const char *config,
  5291. PropertyType *);
  5292. template<>
  5293. bool getLinkInterfaceDependentProperty(cmTarget *tgt,
  5294. const std::string prop,
  5295. const char *config, bool *)
  5296. {
  5297. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5298. }
  5299. template<>
  5300. const char * getLinkInterfaceDependentProperty(cmTarget *tgt,
  5301. const std::string prop,
  5302. const char *config,
  5303. const char **)
  5304. {
  5305. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5306. }
  5307. //----------------------------------------------------------------------------
  5308. template<typename PropertyType>
  5309. void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
  5310. const char *propName,
  5311. std::set<cmStdString> &emitted,
  5312. const char *config,
  5313. PropertyType *)
  5314. {
  5315. const char *prop = dependee->GetProperty(propName);
  5316. if (!prop)
  5317. {
  5318. return;
  5319. }
  5320. std::vector<std::string> props;
  5321. cmSystemTools::ExpandListArgument(prop, props);
  5322. for(std::vector<std::string>::iterator pi = props.begin();
  5323. pi != props.end(); ++pi)
  5324. {
  5325. if (depender->GetMakefile()->GetCMakeInstance()
  5326. ->GetIsPropertyDefined(pi->c_str(),
  5327. cmProperty::TARGET))
  5328. {
  5329. cmOStringStream e;
  5330. e << "Target \"" << dependee->GetName() << "\" has property \""
  5331. << *pi << "\" listed in its " << propName << " property. "
  5332. "This is not allowed. Only user-defined properties may appear "
  5333. "listed in the " << propName << " property.";
  5334. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  5335. return;
  5336. }
  5337. if(emitted.insert(*pi).second)
  5338. {
  5339. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  5340. 0);
  5341. if (cmSystemTools::GetErrorOccuredFlag())
  5342. {
  5343. return;
  5344. }
  5345. }
  5346. }
  5347. }
  5348. //----------------------------------------------------------------------------
  5349. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  5350. const char* config)
  5351. {
  5352. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  5353. std::set<cmStdString> emittedBools;
  5354. std::set<cmStdString> emittedStrings;
  5355. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  5356. deps.begin();
  5357. li != deps.end(); ++li)
  5358. {
  5359. if (!li->Target)
  5360. {
  5361. continue;
  5362. }
  5363. checkPropertyConsistency<bool>(this, li->Target,
  5364. "COMPATIBLE_INTERFACE_BOOL",
  5365. emittedBools, config, 0);
  5366. if (cmSystemTools::GetErrorOccuredFlag())
  5367. {
  5368. return;
  5369. }
  5370. checkPropertyConsistency<const char *>(this, li->Target,
  5371. "COMPATIBLE_INTERFACE_STRING",
  5372. emittedStrings, config, 0);
  5373. if (cmSystemTools::GetErrorOccuredFlag())
  5374. {
  5375. return;
  5376. }
  5377. }
  5378. for(std::set<cmStdString>::const_iterator li = emittedBools.begin();
  5379. li != emittedBools.end(); ++li)
  5380. {
  5381. const std::set<cmStdString>::const_iterator si = emittedStrings.find(*li);
  5382. if (si != emittedStrings.end())
  5383. {
  5384. cmOStringStream e;
  5385. e << "Property \"" << *li << "\" appears in both the "
  5386. "COMPATIBLE_INTERFACE_BOOL and the COMPATIBLE_INTERFACE_STRING "
  5387. "property in the dependencies of target \"" << this->GetName() <<
  5388. "\". This is not allowed. A property may only require compatibility "
  5389. "in a boolean interpretation or a string interpretation, but not both.";
  5390. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  5391. break;
  5392. }
  5393. }
  5394. }
  5395. //----------------------------------------------------------------------------
  5396. cmComputeLinkInformation*
  5397. cmTarget::GetLinkInformation(const char* config, cmTarget *head)
  5398. {
  5399. cmTarget *headTarget = head ? head : this;
  5400. // Lookup any existing information for this configuration.
  5401. TargetConfigPair key(headTarget,
  5402. cmSystemTools::UpperCase(config?config:""));
  5403. cmTargetLinkInformationMap::iterator
  5404. i = this->LinkInformation.find(key);
  5405. if(i == this->LinkInformation.end())
  5406. {
  5407. // Compute information for this configuration.
  5408. cmComputeLinkInformation* info =
  5409. new cmComputeLinkInformation(this, config, headTarget);
  5410. if(!info || !info->Compute())
  5411. {
  5412. delete info;
  5413. info = 0;
  5414. }
  5415. // Store the information for this configuration.
  5416. cmTargetLinkInformationMap::value_type entry(key, info);
  5417. i = this->LinkInformation.insert(entry).first;
  5418. if (info)
  5419. {
  5420. this->CheckPropertyCompatibility(info, config);
  5421. }
  5422. }
  5423. return i->second;
  5424. }
  5425. //----------------------------------------------------------------------------
  5426. std::string cmTarget::GetFrameworkDirectory(const char* config)
  5427. {
  5428. std::string fpath;
  5429. fpath += this->GetFullName(config, false);
  5430. fpath += ".framework/Versions/";
  5431. fpath += this->GetFrameworkVersion();
  5432. fpath += "/";
  5433. return fpath;
  5434. }
  5435. //----------------------------------------------------------------------------
  5436. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  5437. const char* config,
  5438. bool includeMacOS)
  5439. {
  5440. std::string fpath = base;
  5441. if(this->IsAppBundleOnApple())
  5442. {
  5443. fpath += this->GetFullName(config, false);
  5444. fpath += ".app/Contents/";
  5445. if(includeMacOS)
  5446. fpath += "MacOS/";
  5447. }
  5448. if(this->IsFrameworkOnApple())
  5449. {
  5450. fpath += this->GetFrameworkDirectory(config);
  5451. }
  5452. if(this->IsCFBundleOnApple())
  5453. {
  5454. fpath += this->GetFullName(config, false);
  5455. fpath += ".";
  5456. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  5457. if (!ext)
  5458. {
  5459. ext = "bundle";
  5460. }
  5461. fpath += ext;
  5462. fpath += "/Contents/";
  5463. if(includeMacOS)
  5464. fpath += "MacOS/";
  5465. }
  5466. return fpath;
  5467. }
  5468. //----------------------------------------------------------------------------
  5469. std::string cmTarget::GetMacContentDirectory(const char* config,
  5470. bool implib,
  5471. bool includeMacOS)
  5472. {
  5473. // Start with the output directory for the target.
  5474. std::string fpath = this->GetDirectory(config, implib);
  5475. fpath += "/";
  5476. fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
  5477. return fpath;
  5478. }
  5479. //----------------------------------------------------------------------------
  5480. cmTargetLinkInformationMap
  5481. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  5482. {
  5483. // Ideally cmTarget instances should never be copied. However until
  5484. // we can make a sweep to remove that, this copy constructor avoids
  5485. // allowing the resources (LinkInformation) from getting copied. In
  5486. // the worst case this will lead to extra cmComputeLinkInformation
  5487. // instances. We also enforce in debug mode that the map be emptied
  5488. // when copied.
  5489. static_cast<void>(r);
  5490. assert(r.empty());
  5491. }
  5492. //----------------------------------------------------------------------------
  5493. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  5494. {
  5495. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  5496. {
  5497. delete i->second;
  5498. }
  5499. }
  5500. //----------------------------------------------------------------------------
  5501. cmTargetInternalPointer::cmTargetInternalPointer()
  5502. {
  5503. this->Pointer = new cmTargetInternals;
  5504. }
  5505. //----------------------------------------------------------------------------
  5506. cmTargetInternalPointer
  5507. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  5508. {
  5509. // Ideally cmTarget instances should never be copied. However until
  5510. // we can make a sweep to remove that, this copy constructor avoids
  5511. // allowing the resources (Internals) to be copied.
  5512. this->Pointer = new cmTargetInternals(*r.Pointer);
  5513. }
  5514. //----------------------------------------------------------------------------
  5515. cmTargetInternalPointer::~cmTargetInternalPointer()
  5516. {
  5517. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  5518. delete this->Pointer;
  5519. }
  5520. //----------------------------------------------------------------------------
  5521. cmTargetInternalPointer&
  5522. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  5523. {
  5524. if(this == &r) { return *this; } // avoid warning on HP about self check
  5525. // Ideally cmTarget instances should never be copied. However until
  5526. // we can make a sweep to remove that, this copy constructor avoids
  5527. // allowing the resources (Internals) to be copied.
  5528. cmTargetInternals* oldPointer = this->Pointer;
  5529. this->Pointer = new cmTargetInternals(*r.Pointer);
  5530. delete oldPointer;
  5531. return *this;
  5532. }