cmGeneratorTarget.cxx 172 KB

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