cmTarget.cxx 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmOutputConverter.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include "cmAlgorithms.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <map>
  23. #include <set>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. #include <errno.h>
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. #include <cmsys/hash_set.hxx>
  29. #define UNORDERED_SET cmsys::hash_set
  30. #else
  31. #define UNORDERED_SET std::set
  32. #endif
  33. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  34. {
  35. switch( targetType )
  36. {
  37. case cmTarget::STATIC_LIBRARY:
  38. return "STATIC_LIBRARY";
  39. case cmTarget::MODULE_LIBRARY:
  40. return "MODULE_LIBRARY";
  41. case cmTarget::SHARED_LIBRARY:
  42. return "SHARED_LIBRARY";
  43. case cmTarget::OBJECT_LIBRARY:
  44. return "OBJECT_LIBRARY";
  45. case cmTarget::EXECUTABLE:
  46. return "EXECUTABLE";
  47. case cmTarget::UTILITY:
  48. return "UTILITY";
  49. case cmTarget::GLOBAL_TARGET:
  50. return "GLOBAL_TARGET";
  51. case cmTarget::INTERFACE_LIBRARY:
  52. return "INTERFACE_LIBRARY";
  53. case cmTarget::UNKNOWN_LIBRARY:
  54. return "UNKNOWN_LIBRARY";
  55. }
  56. assert(0 && "Unexpected target type");
  57. return 0;
  58. }
  59. //----------------------------------------------------------------------------
  60. struct cmTarget::OutputInfo
  61. {
  62. std::string OutDir;
  63. std::string ImpDir;
  64. std::string PdbDir;
  65. };
  66. //----------------------------------------------------------------------------
  67. struct cmTarget::CompileInfo
  68. {
  69. std::string CompilePdbDir;
  70. };
  71. //----------------------------------------------------------------------------
  72. class cmTargetInternals
  73. {
  74. public:
  75. cmTargetInternals()
  76. : Backtrace()
  77. {
  78. this->PolicyWarnedCMP0022 = false;
  79. this->UtilityItemsDone = false;
  80. }
  81. cmTargetInternals(cmTargetInternals const&)
  82. : Backtrace()
  83. {
  84. this->PolicyWarnedCMP0022 = false;
  85. this->UtilityItemsDone = false;
  86. }
  87. ~cmTargetInternals();
  88. // The backtrace when the target was created.
  89. cmListFileBacktrace Backtrace;
  90. // Cache link interface computation from each configuration.
  91. struct OptionalLinkInterface: public cmTarget::LinkInterface
  92. {
  93. OptionalLinkInterface():
  94. LibrariesDone(false), AllDone(false),
  95. Exists(false), HadHeadSensitiveCondition(false),
  96. ExplicitLibraries(0) {}
  97. bool LibrariesDone;
  98. bool AllDone;
  99. bool Exists;
  100. bool HadHeadSensitiveCondition;
  101. const char* ExplicitLibraries;
  102. };
  103. void ComputeLinkInterface(cmTarget const* thisTarget,
  104. const std::string& config,
  105. OptionalLinkInterface& iface,
  106. cmTarget const* head) const;
  107. void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget,
  108. const std::string& config,
  109. OptionalLinkInterface& iface,
  110. cmTarget const* head,
  111. bool usage_requirements_only);
  112. struct HeadToLinkInterfaceMap:
  113. public std::map<cmTarget const*, OptionalLinkInterface> {};
  114. typedef std::map<std::string, HeadToLinkInterfaceMap>
  115. LinkInterfaceMapType;
  116. LinkInterfaceMapType LinkInterfaceMap;
  117. LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
  118. bool PolicyWarnedCMP0022;
  119. typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
  120. OutputInfoMapType OutputInfoMap;
  121. typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
  122. ImportInfoMapType ImportInfoMap;
  123. typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType;
  124. CompileInfoMapType CompileInfoMap;
  125. // Cache link implementation computation from each configuration.
  126. struct OptionalLinkImplementation: public cmTarget::LinkImplementation
  127. {
  128. OptionalLinkImplementation():
  129. LibrariesDone(false), LanguagesDone(false),
  130. HadHeadSensitiveCondition(false) {}
  131. bool LibrariesDone;
  132. bool LanguagesDone;
  133. bool HadHeadSensitiveCondition;
  134. };
  135. void ComputeLinkImplementationLibraries(cmTarget const* thisTarget,
  136. const std::string& config,
  137. OptionalLinkImplementation& impl,
  138. cmTarget const* head) const;
  139. void ComputeLinkImplementationLanguages(cmTarget const* thisTarget,
  140. const std::string& config,
  141. OptionalLinkImplementation& impl
  142. ) const;
  143. struct HeadToLinkImplementationMap:
  144. public std::map<cmTarget const*, OptionalLinkImplementation> {};
  145. typedef std::map<std::string,
  146. HeadToLinkImplementationMap> LinkImplMapType;
  147. LinkImplMapType LinkImplMap;
  148. typedef std::map<std::string, cmTarget::LinkClosure> LinkClosureMapType;
  149. LinkClosureMapType LinkClosureMap;
  150. typedef std::map<std::string, std::vector<cmSourceFile*> >
  151. SourceFilesMapType;
  152. SourceFilesMapType SourceFilesMap;
  153. std::set<cmLinkItem> UtilityItems;
  154. bool UtilityItemsDone;
  155. class TargetPropertyEntry {
  156. static cmLinkImplItem NoLinkImplItem;
  157. public:
  158. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  159. cmLinkImplItem const& item = NoLinkImplItem)
  160. : ge(cge), LinkImplItem(item)
  161. {}
  162. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  163. cmLinkImplItem const& LinkImplItem;
  164. };
  165. std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
  166. std::vector<TargetPropertyEntry*> CompileOptionsEntries;
  167. std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
  168. std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
  169. std::vector<TargetPropertyEntry*> SourceEntries;
  170. std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
  171. void AddInterfaceEntries(
  172. cmTarget const* thisTarget, std::string const& config,
  173. std::string const& prop, std::vector<TargetPropertyEntry*>& entries);
  174. };
  175. cmLinkImplItem cmTargetInternals::TargetPropertyEntry::NoLinkImplItem;
  176. //----------------------------------------------------------------------------
  177. static void deleteAndClear(
  178. std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
  179. {
  180. cmDeleteAll(entries);
  181. entries.clear();
  182. }
  183. //----------------------------------------------------------------------------
  184. cmTargetInternals::~cmTargetInternals()
  185. {
  186. }
  187. //----------------------------------------------------------------------------
  188. cmTarget::cmTarget()
  189. {
  190. this->Makefile = 0;
  191. #if defined(_WIN32) && !defined(__CYGWIN__)
  192. this->LinkLibrariesForVS6Analyzed = false;
  193. #endif
  194. this->HaveInstallRule = false;
  195. this->DLLPlatform = false;
  196. this->IsAndroid = false;
  197. this->IsApple = false;
  198. this->IsImportedTarget = false;
  199. this->BuildInterfaceIncludesAppended = false;
  200. this->DebugIncludesDone = false;
  201. this->DebugCompileOptionsDone = false;
  202. this->DebugCompileFeaturesDone = false;
  203. this->DebugCompileDefinitionsDone = false;
  204. this->DebugSourcesDone = false;
  205. this->LinkImplementationLanguageIsContextDependent = true;
  206. }
  207. void cmTarget::SetType(TargetType type, const std::string& name)
  208. {
  209. this->Name = name;
  210. // only add dependency information for library targets
  211. this->TargetTypeValue = type;
  212. if(this->TargetTypeValue >= STATIC_LIBRARY
  213. && this->TargetTypeValue <= MODULE_LIBRARY)
  214. {
  215. this->RecordDependencies = true;
  216. }
  217. else
  218. {
  219. this->RecordDependencies = false;
  220. }
  221. }
  222. //----------------------------------------------------------------------------
  223. void cmTarget::SetMakefile(cmMakefile* mf)
  224. {
  225. // Set our makefile.
  226. this->Makefile = mf;
  227. // Check whether this is a DLL platform.
  228. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  229. this->Makefile->IsOn("CYGWIN") ||
  230. this->Makefile->IsOn("MINGW"));
  231. // Check whether we are targeting an Android platform.
  232. this->IsAndroid =
  233. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  234. "Android") == 0;
  235. // Check whether we are targeting an Apple platform.
  236. this->IsApple = this->Makefile->IsOn("APPLE");
  237. // Setup default property values.
  238. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  239. {
  240. this->SetPropertyDefault("ANDROID_API", 0);
  241. this->SetPropertyDefault("ANDROID_API_MIN", 0);
  242. this->SetPropertyDefault("ANDROID_ARCH", 0);
  243. this->SetPropertyDefault("ANDROID_STL_TYPE", 0);
  244. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", 0);
  245. this->SetPropertyDefault("ANDROID_PROCESS_MAX", 0);
  246. this->SetPropertyDefault("ANDROID_PROGUARD", 0);
  247. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", 0);
  248. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", 0);
  249. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", 0);
  250. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", 0);
  251. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", 0);
  252. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", 0);
  253. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", 0);
  254. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", 0);
  255. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", 0);
  256. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  257. this->SetPropertyDefault("INSTALL_RPATH", "");
  258. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  259. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  260. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  261. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  262. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  263. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  264. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  265. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  266. this->SetPropertyDefault("Fortran_FORMAT", 0);
  267. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  268. this->SetPropertyDefault("GNUtoMS", 0);
  269. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  270. this->SetPropertyDefault("AUTOMOC", 0);
  271. this->SetPropertyDefault("AUTOUIC", 0);
  272. this->SetPropertyDefault("AUTORCC", 0);
  273. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  274. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  275. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  276. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  277. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  278. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  279. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  280. this->SetPropertyDefault("MACOSX_RPATH", 0);
  281. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  282. this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
  283. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
  284. this->SetPropertyDefault("C_STANDARD", 0);
  285. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  286. this->SetPropertyDefault("C_EXTENSIONS", 0);
  287. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
  288. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
  289. this->SetPropertyDefault("CXX_STANDARD", 0);
  290. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  291. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  292. }
  293. // Collect the set of configuration types.
  294. std::vector<std::string> configNames;
  295. mf->GetConfigurations(configNames);
  296. // Setup per-configuration property default values.
  297. if (this->GetType() != UTILITY)
  298. {
  299. const char* configProps[] = {
  300. "ARCHIVE_OUTPUT_DIRECTORY_",
  301. "LIBRARY_OUTPUT_DIRECTORY_",
  302. "RUNTIME_OUTPUT_DIRECTORY_",
  303. "PDB_OUTPUT_DIRECTORY_",
  304. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  305. "MAP_IMPORTED_CONFIG_",
  306. 0};
  307. for(std::vector<std::string>::iterator ci = configNames.begin();
  308. ci != configNames.end(); ++ci)
  309. {
  310. std::string configUpper = cmSystemTools::UpperCase(*ci);
  311. for(const char** p = configProps; *p; ++p)
  312. {
  313. if (this->TargetTypeValue == INTERFACE_LIBRARY
  314. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  315. {
  316. continue;
  317. }
  318. std::string property = *p;
  319. property += configUpper;
  320. this->SetPropertyDefault(property, 0);
  321. }
  322. // Initialize per-configuration name postfix property from the
  323. // variable only for non-executable targets. This preserves
  324. // compatibility with previous CMake versions in which executables
  325. // did not support this variable. Projects may still specify the
  326. // property directly.
  327. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  328. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  329. {
  330. std::string property = cmSystemTools::UpperCase(*ci);
  331. property += "_POSTFIX";
  332. this->SetPropertyDefault(property, 0);
  333. }
  334. }
  335. }
  336. // Save the backtrace of target construction.
  337. this->Internal->Backtrace = this->Makefile->GetBacktrace();
  338. if (!this->IsImported())
  339. {
  340. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  341. // of the same directory property:
  342. const cmStringRange parentIncludes =
  343. this->Makefile->GetIncludeDirectoriesEntries();
  344. const cmBacktraceRange parentIncludesBts =
  345. this->Makefile->GetIncludeDirectoriesBacktraces();
  346. cmBacktraceRange::const_iterator btIt = parentIncludesBts.begin();
  347. for (cmStringRange::const_iterator it
  348. = parentIncludes.begin();
  349. it != parentIncludes.end(); ++it, ++btIt)
  350. {
  351. this->InsertInclude(*it, *btIt);
  352. }
  353. const std::set<std::string> parentSystemIncludes =
  354. this->Makefile->GetSystemIncludeDirectories();
  355. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  356. parentSystemIncludes.end());
  357. const cmStringRange parentOptions =
  358. this->Makefile->GetCompileOptionsEntries();
  359. const cmBacktraceRange parentOptionsBts =
  360. this->Makefile->GetCompileOptionsBacktraces();
  361. btIt = parentOptionsBts.begin();
  362. for (cmStringRange::const_iterator it
  363. = parentOptions.begin();
  364. it != parentOptions.end(); ++it, ++btIt)
  365. {
  366. this->InsertCompileOption(*it, *btIt);
  367. }
  368. }
  369. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  370. {
  371. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  372. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  373. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  374. }
  375. if(this->TargetTypeValue == cmTarget::EXECUTABLE)
  376. {
  377. this->SetPropertyDefault("ANDROID_GUI", 0);
  378. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
  379. }
  380. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  381. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  382. {
  383. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  384. }
  385. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY)
  386. {
  387. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
  388. }
  389. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  390. {
  391. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  392. }
  393. // Record current policies for later use.
  394. this->Makefile->RecordPolicies(this->PolicyMap);
  395. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  396. {
  397. // This policy is checked in a few conditions. The properties relevant
  398. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  399. // so ensure that the conditions don't lead to nonsense.
  400. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  401. }
  402. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  403. {
  404. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  405. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  406. }
  407. }
  408. //----------------------------------------------------------------------------
  409. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  410. {
  411. if(this->Utilities.insert(u).second && makefile)
  412. {
  413. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  414. }
  415. }
  416. //----------------------------------------------------------------------------
  417. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  418. const std::string& u) const
  419. {
  420. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  421. this->UtilityBacktraces.find(u);
  422. if(i == this->UtilityBacktraces.end()) return 0;
  423. return &i->second;
  424. }
  425. //----------------------------------------------------------------------------
  426. std::set<cmLinkItem> const& cmTarget::GetUtilityItems() const
  427. {
  428. if(!this->Internal->UtilityItemsDone)
  429. {
  430. this->Internal->UtilityItemsDone = true;
  431. for(std::set<std::string>::const_iterator i = this->Utilities.begin();
  432. i != this->Utilities.end(); ++i)
  433. {
  434. this->Internal->UtilityItems.insert(
  435. cmLinkItem(*i, this->Makefile->FindTargetToUse(*i)));
  436. }
  437. }
  438. return this->Internal->UtilityItems;
  439. }
  440. //----------------------------------------------------------------------------
  441. void cmTarget::FinishConfigure()
  442. {
  443. // Erase any cached link information that might have been comptued
  444. // on-demand during the configuration. This ensures that build
  445. // system generation uses up-to-date information even if other cache
  446. // invalidation code in this source file is buggy.
  447. this->ClearLinkMaps();
  448. #if defined(_WIN32) && !defined(__CYGWIN__)
  449. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  450. if(this->Makefile->GetGlobalGenerator()->IsForVS6())
  451. {
  452. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  453. }
  454. #endif
  455. }
  456. //----------------------------------------------------------------------------
  457. void cmTarget::ClearLinkMaps()
  458. {
  459. this->LinkImplementationLanguageIsContextDependent = true;
  460. this->Internal->LinkImplMap.clear();
  461. this->Internal->LinkInterfaceMap.clear();
  462. this->Internal->LinkInterfaceUsageRequirementsOnlyMap.clear();
  463. this->Internal->LinkClosureMap.clear();
  464. this->Internal->SourceFilesMap.clear();
  465. }
  466. //----------------------------------------------------------------------------
  467. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  468. {
  469. return this->Internal->Backtrace;
  470. }
  471. //----------------------------------------------------------------------------
  472. std::string cmTarget::GetSupportDirectory() const
  473. {
  474. std::string dir = this->Makefile->GetCurrentBinaryDirectory();
  475. dir += cmake::GetCMakeFilesDirectory();
  476. dir += "/";
  477. dir += this->Name;
  478. #if defined(__VMS)
  479. dir += "_dir";
  480. #else
  481. dir += ".dir";
  482. #endif
  483. return dir;
  484. }
  485. //----------------------------------------------------------------------------
  486. bool cmTarget::IsExecutableWithExports() const
  487. {
  488. return (this->GetType() == cmTarget::EXECUTABLE &&
  489. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  490. }
  491. //----------------------------------------------------------------------------
  492. bool cmTarget::IsLinkable() const
  493. {
  494. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  495. this->GetType() == cmTarget::SHARED_LIBRARY ||
  496. this->GetType() == cmTarget::MODULE_LIBRARY ||
  497. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  498. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  499. this->IsExecutableWithExports());
  500. }
  501. //----------------------------------------------------------------------------
  502. bool cmTarget::HasImportLibrary() const
  503. {
  504. return (this->DLLPlatform &&
  505. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  506. this->IsExecutableWithExports()));
  507. }
  508. //----------------------------------------------------------------------------
  509. bool cmTarget::IsFrameworkOnApple() const
  510. {
  511. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  512. this->Makefile->IsOn("APPLE") &&
  513. this->GetPropertyAsBool("FRAMEWORK"));
  514. }
  515. //----------------------------------------------------------------------------
  516. bool cmTarget::IsAppBundleOnApple() const
  517. {
  518. return (this->GetType() == cmTarget::EXECUTABLE &&
  519. this->Makefile->IsOn("APPLE") &&
  520. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  521. }
  522. //----------------------------------------------------------------------------
  523. bool cmTarget::IsCFBundleOnApple() const
  524. {
  525. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  526. this->Makefile->IsOn("APPLE") &&
  527. this->GetPropertyAsBool("BUNDLE"));
  528. }
  529. //----------------------------------------------------------------------------
  530. bool cmTarget::IsXCTestOnApple() const
  531. {
  532. return (this->IsCFBundleOnApple() &&
  533. this->GetPropertyAsBool("XCTEST"));
  534. }
  535. //----------------------------------------------------------------------------
  536. bool cmTarget::IsBundleOnApple() const
  537. {
  538. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  539. this->IsCFBundleOnApple();
  540. }
  541. //----------------------------------------------------------------------------
  542. static bool processSources(cmTarget const* tgt,
  543. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  544. std::vector<std::string> &srcs,
  545. UNORDERED_SET<std::string> &uniqueSrcs,
  546. cmGeneratorExpressionDAGChecker *dagChecker,
  547. std::string const& config, bool debugSources)
  548. {
  549. cmMakefile *mf = tgt->GetMakefile();
  550. bool contextDependent = false;
  551. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  552. it = entries.begin(), end = entries.end(); it != end; ++it)
  553. {
  554. cmLinkImplItem const& item = (*it)->LinkImplItem;
  555. std::string const& targetName = item;
  556. std::vector<std::string> entrySources;
  557. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  558. config,
  559. false,
  560. tgt,
  561. tgt,
  562. dagChecker),
  563. entrySources);
  564. if ((*it)->ge->GetHadContextSensitiveCondition())
  565. {
  566. contextDependent = true;
  567. }
  568. for(std::vector<std::string>::iterator i = entrySources.begin();
  569. i != entrySources.end(); ++i)
  570. {
  571. std::string& src = *i;
  572. cmSourceFile* sf = mf->GetOrCreateSource(src);
  573. std::string e;
  574. std::string fullPath = sf->GetFullPath(&e);
  575. if(fullPath.empty())
  576. {
  577. if(!e.empty())
  578. {
  579. cmake* cm = mf->GetCMakeInstance();
  580. cm->IssueMessage(cmake::FATAL_ERROR, e,
  581. tgt->GetBacktrace());
  582. }
  583. return contextDependent;
  584. }
  585. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
  586. {
  587. std::ostringstream err;
  588. if (!targetName.empty())
  589. {
  590. err << "Target \"" << targetName << "\" contains relative "
  591. "path in its INTERFACE_SOURCES:\n"
  592. " \"" << src << "\"";
  593. }
  594. else
  595. {
  596. err << "Found relative path while evaluating sources of "
  597. "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
  598. }
  599. tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, err.str());
  600. return contextDependent;
  601. }
  602. src = fullPath;
  603. }
  604. std::string usedSources;
  605. for(std::vector<std::string>::iterator
  606. li = entrySources.begin(); li != entrySources.end(); ++li)
  607. {
  608. std::string src = *li;
  609. if(uniqueSrcs.insert(src).second)
  610. {
  611. srcs.push_back(src);
  612. if (debugSources)
  613. {
  614. usedSources += " * " + src + "\n";
  615. }
  616. }
  617. }
  618. if (!usedSources.empty())
  619. {
  620. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  621. std::string("Used sources for target ")
  622. + tgt->GetName() + ":\n"
  623. + usedSources, (*it)->ge->GetBacktrace());
  624. }
  625. }
  626. return contextDependent;
  627. }
  628. //----------------------------------------------------------------------------
  629. void cmTarget::GetSourceFiles(std::vector<std::string> &files,
  630. const std::string& config) const
  631. {
  632. assert(this->GetType() != INTERFACE_LIBRARY);
  633. if (!this->Makefile->IsConfigured())
  634. {
  635. // At configure-time, this method can be called as part of getting the
  636. // LOCATION property or to export() a file to be include()d. However
  637. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  638. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  639. // behavior of CMP0024 and CMP0026 only.
  640. typedef cmTargetInternals::TargetPropertyEntry
  641. TargetPropertyEntry;
  642. for(std::vector<TargetPropertyEntry*>::const_iterator
  643. i = this->Internal->SourceEntries.begin();
  644. i != this->Internal->SourceEntries.end(); ++i)
  645. {
  646. std::string entry = (*i)->ge->GetInput();
  647. std::vector<std::string> items;
  648. cmSystemTools::ExpandListArgument(entry, items);
  649. for (std::vector<std::string>::const_iterator
  650. li = items.begin(); li != items.end(); ++li)
  651. {
  652. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  653. (*li)[li->size() - 1] == '>')
  654. {
  655. continue;
  656. }
  657. files.push_back(*li);
  658. }
  659. }
  660. return;
  661. }
  662. std::vector<std::string> debugProperties;
  663. const char *debugProp =
  664. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  665. if (debugProp)
  666. {
  667. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  668. }
  669. bool debugSources = !this->DebugSourcesDone
  670. && std::find(debugProperties.begin(),
  671. debugProperties.end(),
  672. "SOURCES")
  673. != debugProperties.end();
  674. if (this->Makefile->IsConfigured())
  675. {
  676. this->DebugSourcesDone = true;
  677. }
  678. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  679. "SOURCES", 0, 0);
  680. UNORDERED_SET<std::string> uniqueSrcs;
  681. bool contextDependentDirectSources = processSources(this,
  682. this->Internal->SourceEntries,
  683. files,
  684. uniqueSrcs,
  685. &dagChecker,
  686. config,
  687. debugSources);
  688. std::vector<cmTargetInternals::TargetPropertyEntry*>
  689. linkInterfaceSourcesEntries;
  690. this->Internal->AddInterfaceEntries(
  691. this, config, "INTERFACE_SOURCES",
  692. linkInterfaceSourcesEntries);
  693. std::vector<std::string>::size_type numFilesBefore = files.size();
  694. bool contextDependentInterfaceSources = processSources(this,
  695. linkInterfaceSourcesEntries,
  696. files,
  697. uniqueSrcs,
  698. &dagChecker,
  699. config,
  700. debugSources);
  701. if (!contextDependentDirectSources
  702. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  703. {
  704. this->LinkImplementationLanguageIsContextDependent = false;
  705. }
  706. deleteAndClear(linkInterfaceSourcesEntries);
  707. }
  708. //----------------------------------------------------------------------------
  709. bool
  710. cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
  711. {
  712. std::vector<std::string> configs;
  713. this->Makefile->GetConfigurations(configs);
  714. if (configs.empty())
  715. {
  716. configs.push_back("");
  717. }
  718. std::vector<std::string>::const_iterator it = configs.begin();
  719. const std::string& firstConfig = *it;
  720. this->GetSourceFiles(files, firstConfig);
  721. for ( ; it != configs.end(); ++it)
  722. {
  723. std::vector<cmSourceFile*> configFiles;
  724. this->GetSourceFiles(configFiles, *it);
  725. if (configFiles != files)
  726. {
  727. std::string firstConfigFiles;
  728. const char* sep = "";
  729. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  730. fi != files.end(); ++fi)
  731. {
  732. firstConfigFiles += sep;
  733. firstConfigFiles += (*fi)->GetFullPath();
  734. sep = "\n ";
  735. }
  736. std::string thisConfigFiles;
  737. sep = "";
  738. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  739. fi != configFiles.end(); ++fi)
  740. {
  741. thisConfigFiles += sep;
  742. thisConfigFiles += (*fi)->GetFullPath();
  743. sep = "\n ";
  744. }
  745. std::ostringstream e;
  746. e << "Target \"" << this->Name << "\" has source files which vary by "
  747. "configuration. This is not supported by the \""
  748. << this->Makefile->GetGlobalGenerator()->GetName()
  749. << "\" generator.\n"
  750. "Config \"" << firstConfig << "\":\n"
  751. " " << firstConfigFiles << "\n"
  752. "Config \"" << *it << "\":\n"
  753. " " << thisConfigFiles << "\n";
  754. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  755. return false;
  756. }
  757. }
  758. return true;
  759. }
  760. //----------------------------------------------------------------------------
  761. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  762. const std::string& config) const
  763. {
  764. // Lookup any existing link implementation for this configuration.
  765. std::string key = cmSystemTools::UpperCase(config);
  766. if(!this->LinkImplementationLanguageIsContextDependent)
  767. {
  768. files = this->Internal->SourceFilesMap.begin()->second;
  769. return;
  770. }
  771. cmTargetInternals::SourceFilesMapType::iterator
  772. it = this->Internal->SourceFilesMap.find(key);
  773. if(it != this->Internal->SourceFilesMap.end())
  774. {
  775. files = it->second;
  776. }
  777. else
  778. {
  779. std::vector<std::string> srcs;
  780. this->GetSourceFiles(srcs, config);
  781. std::set<cmSourceFile*> emitted;
  782. for(std::vector<std::string>::const_iterator i = srcs.begin();
  783. i != srcs.end(); ++i)
  784. {
  785. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  786. if (emitted.insert(sf).second)
  787. {
  788. files.push_back(sf);
  789. }
  790. }
  791. this->Internal->SourceFilesMap[key] = files;
  792. }
  793. }
  794. //----------------------------------------------------------------------------
  795. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  796. {
  797. std::string srcFiles = cmJoin(srcs, ";");
  798. if (!srcFiles.empty())
  799. {
  800. this->Internal->SourceFilesMap.clear();
  801. this->LinkImplementationLanguageIsContextDependent = true;
  802. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  803. cmGeneratorExpression ge(lfbt);
  804. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  805. cge->SetEvaluateForBuildsystem(true);
  806. this->Internal->SourceEntries.push_back(
  807. new cmTargetInternals::TargetPropertyEntry(cge));
  808. }
  809. }
  810. //----------------------------------------------------------------------------
  811. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  812. {
  813. std::string srcFiles;
  814. const char* sep = "";
  815. for(std::vector<std::string>::const_iterator i = srcs.begin();
  816. i != srcs.end(); ++i)
  817. {
  818. std::string filename = *i;
  819. const char* src = filename.c_str();
  820. if(!(src[0] == '$' && src[1] == '<'))
  821. {
  822. if(!filename.empty())
  823. {
  824. filename = this->ProcessSourceItemCMP0049(filename);
  825. if(filename.empty())
  826. {
  827. return;
  828. }
  829. }
  830. this->Makefile->GetOrCreateSource(filename);
  831. }
  832. srcFiles += sep;
  833. srcFiles += filename;
  834. sep = ";";
  835. }
  836. if (!srcFiles.empty())
  837. {
  838. this->Internal->SourceFilesMap.clear();
  839. this->LinkImplementationLanguageIsContextDependent = true;
  840. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  841. cmGeneratorExpression ge(lfbt);
  842. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  843. cge->SetEvaluateForBuildsystem(true);
  844. this->Internal->SourceEntries.push_back(
  845. new cmTargetInternals::TargetPropertyEntry(cge));
  846. }
  847. }
  848. //----------------------------------------------------------------------------
  849. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  850. {
  851. std::string src = s;
  852. // For backwards compatibility replace varibles in source names.
  853. // This should eventually be removed.
  854. this->Makefile->ExpandVariablesInString(src);
  855. if (src != s)
  856. {
  857. std::ostringstream e;
  858. bool noMessage = false;
  859. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  860. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  861. {
  862. case cmPolicies::WARN:
  863. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  864. break;
  865. case cmPolicies::OLD:
  866. noMessage = true;
  867. break;
  868. case cmPolicies::REQUIRED_ALWAYS:
  869. case cmPolicies::REQUIRED_IF_USED:
  870. case cmPolicies::NEW:
  871. messageType = cmake::FATAL_ERROR;
  872. }
  873. if (!noMessage)
  874. {
  875. e << "Legacy variable expansion in source file \""
  876. << s << "\" expanded to \"" << src << "\" in target \""
  877. << this->GetName() << "\". This behavior will be removed in a "
  878. "future version of CMake.";
  879. this->Makefile->IssueMessage(messageType, e.str());
  880. if (messageType == cmake::FATAL_ERROR)
  881. {
  882. return "";
  883. }
  884. }
  885. }
  886. return src;
  887. }
  888. //----------------------------------------------------------------------------
  889. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  890. {
  891. std::string src = this->ProcessSourceItemCMP0049(s);
  892. if(!s.empty() && src.empty())
  893. {
  894. return 0;
  895. }
  896. return this->AddSource(src);
  897. }
  898. //----------------------------------------------------------------------------
  899. struct CreateLocation
  900. {
  901. cmMakefile const* Makefile;
  902. CreateLocation(cmMakefile const* mf)
  903. : Makefile(mf)
  904. {
  905. }
  906. cmSourceFileLocation operator()(const std::string& filename)
  907. {
  908. return cmSourceFileLocation(this->Makefile, filename);
  909. }
  910. };
  911. //----------------------------------------------------------------------------
  912. struct LocationMatcher
  913. {
  914. const cmSourceFileLocation& Needle;
  915. LocationMatcher(const cmSourceFileLocation& needle)
  916. : Needle(needle)
  917. {
  918. }
  919. bool operator()(cmSourceFileLocation &loc)
  920. {
  921. return loc.Matches(this->Needle);
  922. }
  923. };
  924. //----------------------------------------------------------------------------
  925. struct TargetPropertyEntryFinder
  926. {
  927. private:
  928. const cmSourceFileLocation& Needle;
  929. public:
  930. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  931. : Needle(needle)
  932. {
  933. }
  934. bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
  935. {
  936. std::vector<std::string> files;
  937. cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
  938. std::vector<cmSourceFileLocation> locations(files.size());
  939. std::transform(files.begin(), files.end(), locations.begin(),
  940. CreateLocation(this->Needle.GetMakefile()));
  941. return std::find_if(locations.begin(), locations.end(),
  942. LocationMatcher(this->Needle)) != locations.end();
  943. }
  944. };
  945. //----------------------------------------------------------------------------
  946. cmSourceFile* cmTarget::AddSource(const std::string& src)
  947. {
  948. cmSourceFileLocation sfl(this->Makefile, src);
  949. if (std::find_if(this->Internal->SourceEntries.begin(),
  950. this->Internal->SourceEntries.end(),
  951. TargetPropertyEntryFinder(sfl))
  952. == this->Internal->SourceEntries.end())
  953. {
  954. this->Internal->SourceFilesMap.clear();
  955. this->LinkImplementationLanguageIsContextDependent = true;
  956. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  957. cmGeneratorExpression ge(lfbt);
  958. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  959. cge->SetEvaluateForBuildsystem(true);
  960. this->Internal->SourceEntries.push_back(
  961. new cmTargetInternals::TargetPropertyEntry(cge));
  962. }
  963. if (cmGeneratorExpression::Find(src) != std::string::npos)
  964. {
  965. return 0;
  966. }
  967. return this->Makefile->GetOrCreateSource(src);
  968. }
  969. //----------------------------------------------------------------------------
  970. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  971. const std::string& selfname,
  972. const LinkLibraryVectorType& libs )
  973. {
  974. // Only add on libraries we haven't added on before.
  975. // Assumption: the global link libraries could only grow, never shrink
  976. LinkLibraryVectorType::const_iterator i = libs.begin();
  977. i += this->PrevLinkedLibraries.size();
  978. for( ; i != libs.end(); ++i )
  979. {
  980. // This is equivalent to the target_link_libraries plain signature.
  981. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  982. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  983. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  984. }
  985. this->PrevLinkedLibraries = libs;
  986. }
  987. //----------------------------------------------------------------------------
  988. void cmTarget::AddLinkDirectory(const std::string& d)
  989. {
  990. // Make sure we don't add unnecessary search directories.
  991. if(this->LinkDirectoriesEmmitted.insert(d).second)
  992. {
  993. this->LinkDirectories.push_back(d);
  994. }
  995. }
  996. //----------------------------------------------------------------------------
  997. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  998. {
  999. return this->LinkDirectories;
  1000. }
  1001. //----------------------------------------------------------------------------
  1002. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
  1003. const std::string& config) const
  1004. {
  1005. // No configuration is always optimized.
  1006. if(config.empty())
  1007. {
  1008. return cmTarget::OPTIMIZED;
  1009. }
  1010. // Get the list of configurations considered to be DEBUG.
  1011. std::vector<std::string> debugConfigs =
  1012. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1013. // Check if any entry in the list matches this configuration.
  1014. std::string configUpper = cmSystemTools::UpperCase(config);
  1015. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  1016. debugConfigs.end())
  1017. {
  1018. return cmTarget::DEBUG;
  1019. }
  1020. // The current configuration is not a debug configuration.
  1021. return cmTarget::OPTIMIZED;
  1022. }
  1023. //----------------------------------------------------------------------------
  1024. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1025. const std::string& target )
  1026. {
  1027. // Clear the dependencies. The cache variable must exist iff we are
  1028. // recording dependency information for this target.
  1029. std::string depname = target;
  1030. depname += "_LIB_DEPENDS";
  1031. if (this->RecordDependencies)
  1032. {
  1033. mf.AddCacheDefinition(depname, "",
  1034. "Dependencies for target", cmState::STATIC);
  1035. }
  1036. else
  1037. {
  1038. if (mf.GetDefinition( depname ))
  1039. {
  1040. std::string message = "Target ";
  1041. message += target;
  1042. message += " has dependency information when it shouldn't.\n";
  1043. message += "Your cache is probably stale. Please remove the entry\n ";
  1044. message += depname;
  1045. message += "\nfrom the cache.";
  1046. cmSystemTools::Error( message.c_str() );
  1047. }
  1048. }
  1049. }
  1050. //----------------------------------------------------------------------------
  1051. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  1052. {
  1053. return this->Makefile->GetGlobalGenerator()->
  1054. NameResolvesToFramework(libname);
  1055. }
  1056. //----------------------------------------------------------------------------
  1057. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1058. cmTarget::LinkLibraryType llt) const
  1059. {
  1060. if (llt == GENERAL)
  1061. {
  1062. return value;
  1063. }
  1064. // Get the list of configurations considered to be DEBUG.
  1065. std::vector<std::string> debugConfigs =
  1066. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1067. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1068. if (debugConfigs.size() > 1)
  1069. {
  1070. for(std::vector<std::string>::const_iterator
  1071. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  1072. {
  1073. configString += ",$<CONFIG:" + *li + ">";
  1074. }
  1075. configString = "$<OR:" + configString + ">";
  1076. }
  1077. if (llt == OPTIMIZED)
  1078. {
  1079. configString = "$<NOT:" + configString + ">";
  1080. }
  1081. return "$<" + configString + ":" + value + ">";
  1082. }
  1083. //----------------------------------------------------------------------------
  1084. static std::string targetNameGenex(const std::string& lib)
  1085. {
  1086. return "$<TARGET_NAME:" + lib + ">";
  1087. }
  1088. //----------------------------------------------------------------------------
  1089. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1090. cmListFileContext const& lfc)
  1091. {
  1092. bool ret = true;
  1093. if (!this->TLLCommands.empty())
  1094. {
  1095. if (this->TLLCommands.back().first != signature)
  1096. {
  1097. ret = false;
  1098. }
  1099. }
  1100. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
  1101. {
  1102. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  1103. }
  1104. return ret;
  1105. }
  1106. //----------------------------------------------------------------------------
  1107. void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
  1108. TLLSignature sig) const
  1109. {
  1110. const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  1111. : "plain");
  1112. s << "The uses of the " << sigString << " signature are here:\n";
  1113. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  1114. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  1115. for(Container::const_iterator it = this->TLLCommands.begin();
  1116. it != this->TLLCommands.end(); ++it)
  1117. {
  1118. if (it->first == sig)
  1119. {
  1120. cmListFileContext lfc = it->second;
  1121. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  1122. s << " * " << lfc << std::endl;
  1123. }
  1124. }
  1125. }
  1126. //----------------------------------------------------------------------------
  1127. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1128. const std::string& target,
  1129. const std::string& lib,
  1130. LinkLibraryType llt)
  1131. {
  1132. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  1133. {
  1134. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1135. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  1136. ? targetNameGenex(lib)
  1137. : lib;
  1138. this->AppendProperty("LINK_LIBRARIES",
  1139. this->GetDebugGeneratorExpressions(libName,
  1140. llt).c_str());
  1141. }
  1142. if (cmGeneratorExpression::Find(lib) != std::string::npos
  1143. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  1144. || (target == lib ))
  1145. {
  1146. return;
  1147. }
  1148. cmTarget::LibraryID tmp;
  1149. tmp.first = lib;
  1150. tmp.second = llt;
  1151. #if defined(_WIN32) && !defined(__CYGWIN__)
  1152. this->LinkLibrariesForVS6.push_back( tmp );
  1153. #endif
  1154. this->OriginalLinkLibraries.push_back(tmp);
  1155. this->ClearLinkMaps();
  1156. // Add the explicit dependency information for this target. This is
  1157. // simply a set of libraries separated by ";". There should always
  1158. // be a trailing ";". These library names are not canonical, in that
  1159. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1160. // We shouldn't remove duplicates here because external libraries
  1161. // may be purposefully duplicated to handle recursive dependencies,
  1162. // and we removing one instance will break the link line. Duplicates
  1163. // will be appropriately eliminated at emit time.
  1164. if(this->RecordDependencies)
  1165. {
  1166. std::string targetEntry = target;
  1167. targetEntry += "_LIB_DEPENDS";
  1168. std::string dependencies;
  1169. const char* old_val = mf.GetDefinition( targetEntry );
  1170. if( old_val )
  1171. {
  1172. dependencies += old_val;
  1173. }
  1174. switch (llt)
  1175. {
  1176. case cmTarget::GENERAL:
  1177. dependencies += "general";
  1178. break;
  1179. case cmTarget::DEBUG:
  1180. dependencies += "debug";
  1181. break;
  1182. case cmTarget::OPTIMIZED:
  1183. dependencies += "optimized";
  1184. break;
  1185. }
  1186. dependencies += ";";
  1187. dependencies += lib;
  1188. dependencies += ";";
  1189. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  1190. "Dependencies for the target",
  1191. cmState::STATIC );
  1192. }
  1193. }
  1194. //----------------------------------------------------------------------------
  1195. void
  1196. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1197. {
  1198. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1199. }
  1200. //----------------------------------------------------------------------------
  1201. void
  1202. cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
  1203. {
  1204. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1205. }
  1206. #if defined(_WIN32) && !defined(__CYGWIN__)
  1207. //----------------------------------------------------------------------------
  1208. void
  1209. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  1210. {
  1211. // There are two key parts of the dependency analysis: (1)
  1212. // determining the libraries in the link line, and (2) constructing
  1213. // the dependency graph for those libraries.
  1214. //
  1215. // The latter is done using the cache entries that record the
  1216. // dependencies of each library.
  1217. //
  1218. // The former is a more thorny issue, since it is not clear how to
  1219. // determine if two libraries listed on the link line refer to the a
  1220. // single library or not. For example, consider the link "libraries"
  1221. // /usr/lib/libtiff.so -ltiff
  1222. // Is this one library or two? The solution implemented here is the
  1223. // simplest (and probably the only practical) one: two libraries are
  1224. // the same if their "link strings" are identical. Thus, the two
  1225. // libraries above are considered distinct. This also means that for
  1226. // dependency analysis to be effective, the CMake user must specify
  1227. // libraries build by his project without using any linker flags or
  1228. // file extensions. That is,
  1229. // LINK_LIBRARIES( One Two )
  1230. // instead of
  1231. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1232. // The former is probably what most users would do, but it never
  1233. // hurts to document the assumptions. :-) Therefore, in the analysis
  1234. // code, the "canonical name" of a library is simply its name as
  1235. // given to a LINK_LIBRARIES command.
  1236. //
  1237. // Also, we will leave the original link line intact; we will just add any
  1238. // dependencies that were missing.
  1239. //
  1240. // There is a problem with recursive external libraries
  1241. // (i.e. libraries with no dependency information that are
  1242. // recursively dependent). We must make sure that the we emit one of
  1243. // the libraries twice to satisfy the recursion, but we shouldn't
  1244. // emit it more times than necessary. In particular, we must make
  1245. // sure that handling this improbable case doesn't cost us when
  1246. // dealing with the common case of non-recursive libraries. The
  1247. // solution is to assume that the recursion is satisfied at one node
  1248. // of the dependency tree. To illustrate, assume libA and libB are
  1249. // extrenal and mutually dependent. Suppose libX depends on
  1250. // libA, and libY on libA and libX. Then
  1251. // TARGET_LINK_LIBRARIES( Y X A B A )
  1252. // TARGET_LINK_LIBRARIES( X A B A )
  1253. // TARGET_LINK_LIBRARIES( Exec Y )
  1254. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1255. // specify the dependencies, since the mutual dependency of A and B
  1256. // is resolved *every time libA is specified*.
  1257. //
  1258. // Something like
  1259. // TARGET_LINK_LIBRARIES( Y X A B A )
  1260. // TARGET_LINK_LIBRARIES( X A B )
  1261. // TARGET_LINK_LIBRARIES( Exec Y )
  1262. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1263. // information is lost. This is because in some case (Y), the mutual
  1264. // dependency of A and B is listed, while in another other case (X),
  1265. // it is not. Depending on which line actually emits A, the mutual
  1266. // dependency may or may not be on the final link line. We can't
  1267. // handle this pathalogical case cleanly without emitting extra
  1268. // libraries for the normal cases. Besides, the dependency
  1269. // information for X is wrong anyway: if we build an executable
  1270. // depending on X alone, we would not have the mutual dependency on
  1271. // A and B resolved.
  1272. //
  1273. // IMPROVEMENTS:
  1274. // -- The current algorithm will not always pick the "optimal" link line
  1275. // when recursive dependencies are present. It will instead break the
  1276. // cycles at an aribtrary point. The majority of projects won't have
  1277. // cyclic dependencies, so this is probably not a big deal. Note that
  1278. // the link line is always correct, just not necessary optimal.
  1279. {
  1280. // Expand variables in link library names. This is for backwards
  1281. // compatibility with very early CMake versions and should
  1282. // eventually be removed. This code was moved here from the end of
  1283. // old source list processing code which was called just before this
  1284. // method.
  1285. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  1286. p != this->LinkLibrariesForVS6.end(); ++p)
  1287. {
  1288. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1289. }
  1290. }
  1291. // The dependency map.
  1292. DependencyMap dep_map;
  1293. // 1. Build the dependency graph
  1294. //
  1295. for(LinkLibraryVectorType::reverse_iterator lib
  1296. = this->LinkLibrariesForVS6.rbegin();
  1297. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1298. {
  1299. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  1300. }
  1301. // 2. Remove any dependencies that are already satisfied in the original
  1302. // link line.
  1303. //
  1304. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  1305. lib != this->LinkLibrariesForVS6.end(); ++lib)
  1306. {
  1307. for( LinkLibraryVectorType::iterator lib2 = lib;
  1308. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  1309. {
  1310. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  1311. }
  1312. }
  1313. // 3. Create the new link line by simply emitting any dependencies that are
  1314. // missing. Start from the back and keep adding.
  1315. //
  1316. std::set<DependencyMap::key_type> done, visited;
  1317. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  1318. for(LinkLibraryVectorType::reverse_iterator lib =
  1319. this->LinkLibrariesForVS6.rbegin();
  1320. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1321. {
  1322. // skip zero size library entries, this may happen
  1323. // if a variable expands to nothing.
  1324. if (!lib->first.empty())
  1325. {
  1326. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  1327. }
  1328. }
  1329. // 4. Add the new libraries to the link line.
  1330. //
  1331. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1332. newLinkLibrariesForVS6.rbegin();
  1333. k != newLinkLibrariesForVS6.rend(); ++k )
  1334. {
  1335. // get the llt from the dep_map
  1336. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  1337. }
  1338. this->LinkLibrariesForVS6Analyzed = true;
  1339. }
  1340. //----------------------------------------------------------------------------
  1341. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  1342. const LibraryID& lib,
  1343. const LibraryID& dep)
  1344. {
  1345. depMap[lib].push_back(dep);
  1346. }
  1347. //----------------------------------------------------------------------------
  1348. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  1349. const LibraryID& lib,
  1350. const LibraryID& dep)
  1351. {
  1352. // Make sure there is an entry in the map for lib. If so, delete all
  1353. // dependencies to dep. There may be repeated entries because of
  1354. // external libraries that are specified multiple times.
  1355. DependencyMap::iterator map_itr = depMap.find( lib );
  1356. if( map_itr != depMap.end() )
  1357. {
  1358. DependencyList& depList = map_itr->second;
  1359. DependencyList::iterator begin =
  1360. std::remove(depList.begin(), depList.end(), dep);
  1361. depList.erase(begin, depList.end());
  1362. }
  1363. }
  1364. //----------------------------------------------------------------------------
  1365. void cmTarget::EmitForVS6(const LibraryID lib,
  1366. const DependencyMap& dep_map,
  1367. std::set<LibraryID>& emitted,
  1368. std::set<LibraryID>& visited,
  1369. DependencyList& link_line )
  1370. {
  1371. // It's already been emitted
  1372. if( emitted.find(lib) != emitted.end() )
  1373. {
  1374. return;
  1375. }
  1376. // Emit the dependencies only if this library node hasn't been
  1377. // visited before. If it has, then we have a cycle. The recursion
  1378. // that got us here should take care of everything.
  1379. if( visited.insert(lib).second )
  1380. {
  1381. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1382. {
  1383. const DependencyList& dep_on = dep_map.find( lib )->second;
  1384. DependencyList::const_reverse_iterator i;
  1385. // To cater for recursive external libraries, we must emit
  1386. // duplicates on this link line *unless* they were emitted by
  1387. // some other node, in which case we assume that the recursion
  1388. // was resolved then. We making the simplifying assumption that
  1389. // any duplicates on a single link line are on purpose, and must
  1390. // be preserved.
  1391. // This variable will keep track of the libraries that were
  1392. // emitted directly from the current node, and not from a
  1393. // recursive call. This way, if we come across a library that
  1394. // has already been emitted, we repeat it iff it has been
  1395. // emitted here.
  1396. std::set<DependencyMap::key_type> emitted_here;
  1397. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1398. {
  1399. if( emitted_here.find(*i) != emitted_here.end() )
  1400. {
  1401. // a repeat. Must emit.
  1402. emitted.insert(*i);
  1403. link_line.push_back( *i );
  1404. }
  1405. else
  1406. {
  1407. // Emit only if no-one else has
  1408. if( emitted.find(*i) == emitted.end() )
  1409. {
  1410. // emit dependencies
  1411. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1412. // emit self
  1413. emitted.insert(*i);
  1414. emitted_here.insert(*i);
  1415. link_line.push_back( *i );
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. //----------------------------------------------------------------------------
  1423. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1424. const LibraryID& lib,
  1425. DependencyMap& dep_map)
  1426. {
  1427. // If the library is already in the dependency map, then it has
  1428. // already been fully processed.
  1429. if( dep_map.find(lib) != dep_map.end() )
  1430. {
  1431. return;
  1432. }
  1433. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1434. if( deps && strcmp(deps,"") != 0 )
  1435. {
  1436. // Make sure this library is in the map, even if it has an empty
  1437. // set of dependencies. This distinguishes the case of explicitly
  1438. // no dependencies with that of unspecified dependencies.
  1439. dep_map[lib];
  1440. // Parse the dependency information, which is a set of
  1441. // type, library pairs separated by ";". There is always a trailing ";".
  1442. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1443. std::string depline = deps;
  1444. std::string::size_type start = 0;
  1445. std::string::size_type end;
  1446. end = depline.find( ";", start );
  1447. while( end != std::string::npos )
  1448. {
  1449. std::string l = depline.substr( start, end-start );
  1450. if(!l.empty())
  1451. {
  1452. if (l == "debug")
  1453. {
  1454. llt = cmTarget::DEBUG;
  1455. }
  1456. else if (l == "optimized")
  1457. {
  1458. llt = cmTarget::OPTIMIZED;
  1459. }
  1460. else if (l == "general")
  1461. {
  1462. llt = cmTarget::GENERAL;
  1463. }
  1464. else
  1465. {
  1466. LibraryID lib2(l,llt);
  1467. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1468. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1469. llt = cmTarget::GENERAL;
  1470. }
  1471. }
  1472. start = end+1; // skip the ;
  1473. end = depline.find( ";", start );
  1474. }
  1475. // cannot depend on itself
  1476. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1477. }
  1478. }
  1479. #endif
  1480. //----------------------------------------------------------------------------
  1481. static bool whiteListedInterfaceProperty(const std::string& prop)
  1482. {
  1483. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1484. {
  1485. return true;
  1486. }
  1487. static UNORDERED_SET<std::string> builtIns;
  1488. if (builtIns.empty())
  1489. {
  1490. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1491. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1492. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1493. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1494. builtIns.insert("EXPORT_NAME");
  1495. builtIns.insert("IMPORTED");
  1496. builtIns.insert("NAME");
  1497. builtIns.insert("TYPE");
  1498. }
  1499. if (builtIns.count(prop))
  1500. {
  1501. return true;
  1502. }
  1503. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1504. {
  1505. return true;
  1506. }
  1507. return false;
  1508. }
  1509. //----------------------------------------------------------------------------
  1510. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1511. {
  1512. if (this->GetType() == INTERFACE_LIBRARY
  1513. && !whiteListedInterfaceProperty(prop))
  1514. {
  1515. std::ostringstream e;
  1516. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1517. "The property \"" << prop << "\" is not allowed.";
  1518. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1519. return;
  1520. }
  1521. else if (prop == "NAME")
  1522. {
  1523. std::ostringstream e;
  1524. e << "NAME property is read-only\n";
  1525. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1526. return;
  1527. }
  1528. else if(prop == "INCLUDE_DIRECTORIES")
  1529. {
  1530. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1531. cmGeneratorExpression ge(lfbt);
  1532. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  1533. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1534. this->Internal->IncludeDirectoriesEntries.push_back(
  1535. new cmTargetInternals::TargetPropertyEntry(cge));
  1536. }
  1537. else if(prop == "COMPILE_OPTIONS")
  1538. {
  1539. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1540. cmGeneratorExpression ge(lfbt);
  1541. deleteAndClear(this->Internal->CompileOptionsEntries);
  1542. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1543. this->Internal->CompileOptionsEntries.push_back(
  1544. new cmTargetInternals::TargetPropertyEntry(cge));
  1545. }
  1546. else if(prop == "COMPILE_FEATURES")
  1547. {
  1548. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1549. cmGeneratorExpression ge(lfbt);
  1550. deleteAndClear(this->Internal->CompileFeaturesEntries);
  1551. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1552. this->Internal->CompileFeaturesEntries.push_back(
  1553. new cmTargetInternals::TargetPropertyEntry(cge));
  1554. }
  1555. else if(prop == "COMPILE_DEFINITIONS")
  1556. {
  1557. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1558. cmGeneratorExpression ge(lfbt);
  1559. deleteAndClear(this->Internal->CompileDefinitionsEntries);
  1560. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1561. this->Internal->CompileDefinitionsEntries.push_back(
  1562. new cmTargetInternals::TargetPropertyEntry(cge));
  1563. }
  1564. else if(prop == "EXPORT_NAME" && this->IsImported())
  1565. {
  1566. std::ostringstream e;
  1567. e << "EXPORT_NAME property can't be set on imported targets (\""
  1568. << this->Name << "\")\n";
  1569. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1570. }
  1571. else if (prop == "LINK_LIBRARIES")
  1572. {
  1573. this->Internal->LinkImplementationPropertyEntries.clear();
  1574. if (value)
  1575. {
  1576. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1577. cmValueWithOrigin entry(value, lfbt);
  1578. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1579. }
  1580. }
  1581. else if (prop == "SOURCES")
  1582. {
  1583. if(this->IsImported())
  1584. {
  1585. std::ostringstream e;
  1586. e << "SOURCES property can't be set on imported targets (\""
  1587. << this->Name << "\")\n";
  1588. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1589. return;
  1590. }
  1591. this->Internal->SourceFilesMap.clear();
  1592. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1593. cmGeneratorExpression ge(lfbt);
  1594. this->Internal->SourceEntries.clear();
  1595. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1596. this->Internal->SourceEntries.push_back(
  1597. new cmTargetInternals::TargetPropertyEntry(cge));
  1598. }
  1599. else
  1600. {
  1601. this->Properties.SetProperty(prop, value);
  1602. this->MaybeInvalidatePropertyCache(prop);
  1603. }
  1604. }
  1605. //----------------------------------------------------------------------------
  1606. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1607. bool asString)
  1608. {
  1609. if (this->GetType() == INTERFACE_LIBRARY
  1610. && !whiteListedInterfaceProperty(prop))
  1611. {
  1612. std::ostringstream e;
  1613. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1614. "The property \"" << prop << "\" is not allowed.";
  1615. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1616. return;
  1617. }
  1618. else if (prop == "NAME")
  1619. {
  1620. std::ostringstream e;
  1621. e << "NAME property is read-only\n";
  1622. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1623. return;
  1624. }
  1625. else if(prop == "INCLUDE_DIRECTORIES")
  1626. {
  1627. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1628. cmGeneratorExpression ge(lfbt);
  1629. this->Internal->IncludeDirectoriesEntries.push_back(
  1630. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1631. }
  1632. else if(prop == "COMPILE_OPTIONS")
  1633. {
  1634. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1635. cmGeneratorExpression ge(lfbt);
  1636. this->Internal->CompileOptionsEntries.push_back(
  1637. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1638. }
  1639. else if(prop == "COMPILE_FEATURES")
  1640. {
  1641. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1642. cmGeneratorExpression ge(lfbt);
  1643. this->Internal->CompileFeaturesEntries.push_back(
  1644. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1645. }
  1646. else if(prop == "COMPILE_DEFINITIONS")
  1647. {
  1648. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1649. cmGeneratorExpression ge(lfbt);
  1650. this->Internal->CompileDefinitionsEntries.push_back(
  1651. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1652. }
  1653. else if(prop == "EXPORT_NAME" && this->IsImported())
  1654. {
  1655. std::ostringstream e;
  1656. e << "EXPORT_NAME property can't be set on imported targets (\""
  1657. << this->Name << "\")\n";
  1658. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1659. }
  1660. else if (prop == "LINK_LIBRARIES")
  1661. {
  1662. if (value)
  1663. {
  1664. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1665. cmValueWithOrigin entry(value, lfbt);
  1666. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1667. }
  1668. }
  1669. else if (prop == "SOURCES")
  1670. {
  1671. if(this->IsImported())
  1672. {
  1673. std::ostringstream e;
  1674. e << "SOURCES property can't be set on imported targets (\""
  1675. << this->Name << "\")\n";
  1676. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1677. return;
  1678. }
  1679. this->Internal->SourceFilesMap.clear();
  1680. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1681. cmGeneratorExpression ge(lfbt);
  1682. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1683. this->Internal->SourceEntries.push_back(
  1684. new cmTargetInternals::TargetPropertyEntry(cge));
  1685. }
  1686. else
  1687. {
  1688. this->Properties.AppendProperty(prop, value, asString);
  1689. this->MaybeInvalidatePropertyCache(prop);
  1690. }
  1691. }
  1692. //----------------------------------------------------------------------------
  1693. std::string cmTarget::GetExportName() const
  1694. {
  1695. const char *exportName = this->GetProperty("EXPORT_NAME");
  1696. if (exportName && *exportName)
  1697. {
  1698. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1699. {
  1700. std::ostringstream e;
  1701. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1702. << this->GetName() << "\": is not valid.";
  1703. cmSystemTools::Error(e.str().c_str());
  1704. return "";
  1705. }
  1706. return exportName;
  1707. }
  1708. return this->GetName();
  1709. }
  1710. //----------------------------------------------------------------------------
  1711. void cmTarget::AppendBuildInterfaceIncludes()
  1712. {
  1713. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1714. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1715. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1716. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1717. !this->IsExecutableWithExports())
  1718. {
  1719. return;
  1720. }
  1721. if (this->BuildInterfaceIncludesAppended)
  1722. {
  1723. return;
  1724. }
  1725. this->BuildInterfaceIncludesAppended = true;
  1726. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1727. {
  1728. const char *binDir = this->Makefile->GetCurrentBinaryDirectory();
  1729. const char *srcDir = this->Makefile->GetCurrentSourceDirectory();
  1730. const std::string dirs = std::string(binDir ? binDir : "")
  1731. + std::string(binDir ? ";" : "")
  1732. + std::string(srcDir ? srcDir : "");
  1733. if (!dirs.empty())
  1734. {
  1735. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1736. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1737. }
  1738. }
  1739. }
  1740. //----------------------------------------------------------------------------
  1741. void cmTarget::InsertInclude(std::string const& entry,
  1742. cmListFileBacktrace const& bt,
  1743. bool before)
  1744. {
  1745. cmGeneratorExpression ge(bt);
  1746. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1747. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  1748. : this->Internal->IncludeDirectoriesEntries.end();
  1749. this->Internal->IncludeDirectoriesEntries.insert(position,
  1750. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry)));
  1751. }
  1752. //----------------------------------------------------------------------------
  1753. void cmTarget::InsertCompileOption(std::string const& entry,
  1754. cmListFileBacktrace const& bt,
  1755. bool before)
  1756. {
  1757. cmGeneratorExpression ge(bt);
  1758. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1759. = before ? this->Internal->CompileOptionsEntries.begin()
  1760. : this->Internal->CompileOptionsEntries.end();
  1761. this->Internal->CompileOptionsEntries.insert(position,
  1762. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry)));
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1766. cmListFileBacktrace const& bt)
  1767. {
  1768. cmGeneratorExpression ge(bt);
  1769. this->Internal->CompileDefinitionsEntries.push_back(
  1770. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry)));
  1771. }
  1772. //----------------------------------------------------------------------------
  1773. static void processIncludeDirectories(cmTarget const* tgt,
  1774. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1775. std::vector<std::string> &includes,
  1776. UNORDERED_SET<std::string> &uniqueIncludes,
  1777. cmGeneratorExpressionDAGChecker *dagChecker,
  1778. const std::string& config, bool debugIncludes,
  1779. const std::string& language)
  1780. {
  1781. cmMakefile *mf = tgt->GetMakefile();
  1782. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1783. it = entries.begin(), end = entries.end(); it != end; ++it)
  1784. {
  1785. cmLinkImplItem const& item = (*it)->LinkImplItem;
  1786. std::string const& targetName = item;
  1787. bool const fromImported = item.Target && item.Target->IsImported();
  1788. bool const checkCMP0027 = item.FromGenex;
  1789. std::vector<std::string> entryIncludes;
  1790. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1791. config,
  1792. false,
  1793. tgt,
  1794. dagChecker, language),
  1795. entryIncludes);
  1796. std::string usedIncludes;
  1797. for(std::vector<std::string>::iterator
  1798. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1799. {
  1800. if (fromImported
  1801. && !cmSystemTools::FileExists(li->c_str()))
  1802. {
  1803. std::ostringstream e;
  1804. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1805. if (checkCMP0027)
  1806. {
  1807. switch(tgt->GetPolicyStatusCMP0027())
  1808. {
  1809. case cmPolicies::WARN:
  1810. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  1811. case cmPolicies::OLD:
  1812. messageType = cmake::AUTHOR_WARNING;
  1813. break;
  1814. case cmPolicies::REQUIRED_ALWAYS:
  1815. case cmPolicies::REQUIRED_IF_USED:
  1816. case cmPolicies::NEW:
  1817. break;
  1818. }
  1819. }
  1820. e << "Imported target \"" << targetName << "\" includes "
  1821. "non-existent path\n \"" << *li << "\"\nin its "
  1822. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1823. "* The path was deleted, renamed, or moved to another "
  1824. "location.\n"
  1825. "* An install or uninstall procedure did not complete "
  1826. "successfully.\n"
  1827. "* The installation package was faulty and references files it "
  1828. "does not provide.\n";
  1829. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1830. return;
  1831. }
  1832. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1833. {
  1834. std::ostringstream e;
  1835. bool noMessage = false;
  1836. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1837. if (!targetName.empty())
  1838. {
  1839. e << "Target \"" << targetName << "\" contains relative "
  1840. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1841. " \"" << *li << "\"";
  1842. }
  1843. else
  1844. {
  1845. switch(tgt->GetPolicyStatusCMP0021())
  1846. {
  1847. case cmPolicies::WARN:
  1848. {
  1849. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  1850. messageType = cmake::AUTHOR_WARNING;
  1851. }
  1852. break;
  1853. case cmPolicies::OLD:
  1854. noMessage = true;
  1855. case cmPolicies::REQUIRED_IF_USED:
  1856. case cmPolicies::REQUIRED_ALWAYS:
  1857. case cmPolicies::NEW:
  1858. // Issue the fatal message.
  1859. break;
  1860. }
  1861. e << "Found relative path while evaluating include directories of "
  1862. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1863. }
  1864. if (!noMessage)
  1865. {
  1866. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1867. if (messageType == cmake::FATAL_ERROR)
  1868. {
  1869. return;
  1870. }
  1871. }
  1872. }
  1873. if (!cmSystemTools::IsOff(li->c_str()))
  1874. {
  1875. cmSystemTools::ConvertToUnixSlashes(*li);
  1876. }
  1877. std::string inc = *li;
  1878. if(uniqueIncludes.insert(inc).second)
  1879. {
  1880. includes.push_back(inc);
  1881. if (debugIncludes)
  1882. {
  1883. usedIncludes += " * " + inc + "\n";
  1884. }
  1885. }
  1886. }
  1887. if (!usedIncludes.empty())
  1888. {
  1889. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1890. std::string("Used includes for target ")
  1891. + tgt->GetName() + ":\n"
  1892. + usedIncludes, (*it)->ge->GetBacktrace());
  1893. }
  1894. }
  1895. }
  1896. //----------------------------------------------------------------------------
  1897. std::vector<std::string>
  1898. cmTarget::GetIncludeDirectories(const std::string& config,
  1899. const std::string& language) const
  1900. {
  1901. std::vector<std::string> includes;
  1902. UNORDERED_SET<std::string> uniqueIncludes;
  1903. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1904. "INCLUDE_DIRECTORIES", 0, 0);
  1905. std::vector<std::string> debugProperties;
  1906. const char *debugProp =
  1907. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1908. if (debugProp)
  1909. {
  1910. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1911. }
  1912. bool debugIncludes = !this->DebugIncludesDone
  1913. && std::find(debugProperties.begin(),
  1914. debugProperties.end(),
  1915. "INCLUDE_DIRECTORIES")
  1916. != debugProperties.end();
  1917. if (this->Makefile->IsConfigured())
  1918. {
  1919. this->DebugIncludesDone = true;
  1920. }
  1921. processIncludeDirectories(this,
  1922. this->Internal->IncludeDirectoriesEntries,
  1923. includes,
  1924. uniqueIncludes,
  1925. &dagChecker,
  1926. config,
  1927. debugIncludes,
  1928. language);
  1929. std::vector<cmTargetInternals::TargetPropertyEntry*>
  1930. linkInterfaceIncludeDirectoriesEntries;
  1931. this->Internal->AddInterfaceEntries(
  1932. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  1933. linkInterfaceIncludeDirectoriesEntries);
  1934. if(this->Makefile->IsOn("APPLE"))
  1935. {
  1936. LinkImplementation const* impl = this->GetLinkImplementation(config);
  1937. for(std::vector<cmLinkImplItem>::const_iterator
  1938. it = impl->Libraries.begin();
  1939. it != impl->Libraries.end(); ++it)
  1940. {
  1941. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  1942. static cmsys::RegularExpression
  1943. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  1944. if(!frameworkCheck.find(libDir))
  1945. {
  1946. continue;
  1947. }
  1948. libDir = frameworkCheck.match(1);
  1949. cmGeneratorExpression ge;
  1950. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1951. ge.Parse(libDir.c_str());
  1952. linkInterfaceIncludeDirectoriesEntries
  1953. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1954. }
  1955. }
  1956. processIncludeDirectories(this,
  1957. linkInterfaceIncludeDirectoriesEntries,
  1958. includes,
  1959. uniqueIncludes,
  1960. &dagChecker,
  1961. config,
  1962. debugIncludes,
  1963. language);
  1964. deleteAndClear(linkInterfaceIncludeDirectoriesEntries);
  1965. return includes;
  1966. }
  1967. //----------------------------------------------------------------------------
  1968. static void processCompileOptionsInternal(cmTarget const* tgt,
  1969. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1970. std::vector<std::string> &options,
  1971. UNORDERED_SET<std::string> &uniqueOptions,
  1972. cmGeneratorExpressionDAGChecker *dagChecker,
  1973. const std::string& config, bool debugOptions, const char *logName,
  1974. std::string const& language)
  1975. {
  1976. cmMakefile *mf = tgt->GetMakefile();
  1977. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1978. it = entries.begin(), end = entries.end(); it != end; ++it)
  1979. {
  1980. std::vector<std::string> entryOptions;
  1981. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1982. config,
  1983. false,
  1984. tgt,
  1985. dagChecker,
  1986. language),
  1987. entryOptions);
  1988. std::string usedOptions;
  1989. for(std::vector<std::string>::iterator
  1990. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  1991. {
  1992. std::string const& opt = *li;
  1993. if(uniqueOptions.insert(opt).second)
  1994. {
  1995. options.push_back(opt);
  1996. if (debugOptions)
  1997. {
  1998. usedOptions += " * " + opt + "\n";
  1999. }
  2000. }
  2001. }
  2002. if (!usedOptions.empty())
  2003. {
  2004. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2005. std::string("Used compile ") + logName
  2006. + std::string(" for target ")
  2007. + tgt->GetName() + ":\n"
  2008. + usedOptions, (*it)->ge->GetBacktrace());
  2009. }
  2010. }
  2011. }
  2012. //----------------------------------------------------------------------------
  2013. static void processCompileOptions(cmTarget const* tgt,
  2014. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2015. std::vector<std::string> &options,
  2016. UNORDERED_SET<std::string> &uniqueOptions,
  2017. cmGeneratorExpressionDAGChecker *dagChecker,
  2018. const std::string& config, bool debugOptions,
  2019. std::string const& language)
  2020. {
  2021. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2022. dagChecker, config, debugOptions, "options",
  2023. language);
  2024. }
  2025. //----------------------------------------------------------------------------
  2026. void cmTarget::GetCompileOptions(std::vector<std::string> &result,
  2027. const std::string& config,
  2028. const std::string& language) const
  2029. {
  2030. UNORDERED_SET<std::string> uniqueOptions;
  2031. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2032. "COMPILE_OPTIONS", 0, 0);
  2033. std::vector<std::string> debugProperties;
  2034. const char *debugProp =
  2035. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2036. if (debugProp)
  2037. {
  2038. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2039. }
  2040. bool debugOptions = !this->DebugCompileOptionsDone
  2041. && std::find(debugProperties.begin(),
  2042. debugProperties.end(),
  2043. "COMPILE_OPTIONS")
  2044. != debugProperties.end();
  2045. if (this->Makefile->IsConfigured())
  2046. {
  2047. this->DebugCompileOptionsDone = true;
  2048. }
  2049. processCompileOptions(this,
  2050. this->Internal->CompileOptionsEntries,
  2051. result,
  2052. uniqueOptions,
  2053. &dagChecker,
  2054. config,
  2055. debugOptions,
  2056. language);
  2057. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2058. linkInterfaceCompileOptionsEntries;
  2059. this->Internal->AddInterfaceEntries(
  2060. this, config, "INTERFACE_COMPILE_OPTIONS",
  2061. linkInterfaceCompileOptionsEntries);
  2062. processCompileOptions(this,
  2063. linkInterfaceCompileOptionsEntries,
  2064. result,
  2065. uniqueOptions,
  2066. &dagChecker,
  2067. config,
  2068. debugOptions,
  2069. language);
  2070. deleteAndClear(linkInterfaceCompileOptionsEntries);
  2071. }
  2072. //----------------------------------------------------------------------------
  2073. static void processCompileDefinitions(cmTarget const* tgt,
  2074. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2075. std::vector<std::string> &options,
  2076. UNORDERED_SET<std::string> &uniqueOptions,
  2077. cmGeneratorExpressionDAGChecker *dagChecker,
  2078. const std::string& config, bool debugOptions,
  2079. std::string const& language)
  2080. {
  2081. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2082. dagChecker, config, debugOptions,
  2083. "definitions", language);
  2084. }
  2085. //----------------------------------------------------------------------------
  2086. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2087. const std::string& config,
  2088. const std::string& language) const
  2089. {
  2090. UNORDERED_SET<std::string> uniqueOptions;
  2091. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2092. "COMPILE_DEFINITIONS", 0, 0);
  2093. std::vector<std::string> debugProperties;
  2094. const char *debugProp =
  2095. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2096. if (debugProp)
  2097. {
  2098. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2099. }
  2100. bool debugDefines = !this->DebugCompileDefinitionsDone
  2101. && std::find(debugProperties.begin(),
  2102. debugProperties.end(),
  2103. "COMPILE_DEFINITIONS")
  2104. != debugProperties.end();
  2105. if (this->Makefile->IsConfigured())
  2106. {
  2107. this->DebugCompileDefinitionsDone = true;
  2108. }
  2109. processCompileDefinitions(this,
  2110. this->Internal->CompileDefinitionsEntries,
  2111. list,
  2112. uniqueOptions,
  2113. &dagChecker,
  2114. config,
  2115. debugDefines,
  2116. language);
  2117. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2118. linkInterfaceCompileDefinitionsEntries;
  2119. this->Internal->AddInterfaceEntries(
  2120. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2121. linkInterfaceCompileDefinitionsEntries);
  2122. if (!config.empty())
  2123. {
  2124. std::string configPropName = "COMPILE_DEFINITIONS_"
  2125. + cmSystemTools::UpperCase(config);
  2126. const char *configProp = this->GetProperty(configPropName);
  2127. if (configProp)
  2128. {
  2129. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2130. {
  2131. case cmPolicies::WARN:
  2132. {
  2133. std::ostringstream e;
  2134. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2135. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  2136. e.str());
  2137. }
  2138. case cmPolicies::OLD:
  2139. {
  2140. cmGeneratorExpression ge;
  2141. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2142. ge.Parse(configProp);
  2143. linkInterfaceCompileDefinitionsEntries
  2144. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  2145. }
  2146. break;
  2147. case cmPolicies::NEW:
  2148. case cmPolicies::REQUIRED_ALWAYS:
  2149. case cmPolicies::REQUIRED_IF_USED:
  2150. break;
  2151. }
  2152. }
  2153. }
  2154. processCompileDefinitions(this,
  2155. linkInterfaceCompileDefinitionsEntries,
  2156. list,
  2157. uniqueOptions,
  2158. &dagChecker,
  2159. config,
  2160. debugDefines,
  2161. language);
  2162. deleteAndClear(linkInterfaceCompileDefinitionsEntries);
  2163. }
  2164. //----------------------------------------------------------------------------
  2165. static void processCompileFeatures(cmTarget const* tgt,
  2166. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2167. std::vector<std::string> &options,
  2168. UNORDERED_SET<std::string> &uniqueOptions,
  2169. cmGeneratorExpressionDAGChecker *dagChecker,
  2170. const std::string& config, bool debugOptions)
  2171. {
  2172. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2173. dagChecker, config, debugOptions, "features",
  2174. std::string());
  2175. }
  2176. //----------------------------------------------------------------------------
  2177. void cmTarget::GetCompileFeatures(std::vector<std::string> &result,
  2178. const std::string& config) const
  2179. {
  2180. UNORDERED_SET<std::string> uniqueFeatures;
  2181. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2182. "COMPILE_FEATURES",
  2183. 0, 0);
  2184. std::vector<std::string> debugProperties;
  2185. const char *debugProp =
  2186. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2187. if (debugProp)
  2188. {
  2189. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2190. }
  2191. bool debugFeatures = !this->DebugCompileFeaturesDone
  2192. && std::find(debugProperties.begin(),
  2193. debugProperties.end(),
  2194. "COMPILE_FEATURES")
  2195. != debugProperties.end();
  2196. if (this->Makefile->IsConfigured())
  2197. {
  2198. this->DebugCompileFeaturesDone = true;
  2199. }
  2200. processCompileFeatures(this,
  2201. this->Internal->CompileFeaturesEntries,
  2202. result,
  2203. uniqueFeatures,
  2204. &dagChecker,
  2205. config,
  2206. debugFeatures);
  2207. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2208. linkInterfaceCompileFeaturesEntries;
  2209. this->Internal->AddInterfaceEntries(
  2210. this, config, "INTERFACE_COMPILE_FEATURES",
  2211. linkInterfaceCompileFeaturesEntries);
  2212. processCompileFeatures(this,
  2213. linkInterfaceCompileFeaturesEntries,
  2214. result,
  2215. uniqueFeatures,
  2216. &dagChecker,
  2217. config,
  2218. debugFeatures);
  2219. deleteAndClear(linkInterfaceCompileFeaturesEntries);
  2220. }
  2221. //----------------------------------------------------------------------------
  2222. void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
  2223. {
  2224. // Wipe out maps caching information affected by this property.
  2225. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
  2226. {
  2227. this->Internal->ImportInfoMap.clear();
  2228. }
  2229. if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
  2230. {
  2231. this->ClearLinkMaps();
  2232. }
  2233. }
  2234. //----------------------------------------------------------------------------
  2235. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2236. const std::string& prop, const char* value, cmMakefile* context,
  2237. bool imported)
  2238. {
  2239. // Look for link-type keywords in the value.
  2240. static cmsys::RegularExpression
  2241. keys("(^|;)(debug|optimized|general)(;|$)");
  2242. if(!keys.find(value))
  2243. {
  2244. return;
  2245. }
  2246. // Support imported and non-imported versions of the property.
  2247. const char* base = (imported?
  2248. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2249. "LINK_INTERFACE_LIBRARIES");
  2250. // Report an error.
  2251. std::ostringstream e;
  2252. e << "Property " << prop << " may not contain link-type keyword \""
  2253. << keys.match(2) << "\". "
  2254. << "The " << base << " property has a per-configuration "
  2255. << "version called " << base << "_<CONFIG> which may be "
  2256. << "used to specify per-configuration rules.";
  2257. if(!imported)
  2258. {
  2259. e << " "
  2260. << "Alternatively, an IMPORTED library may be created, configured "
  2261. << "with a per-configuration location, and then named in the "
  2262. << "property value. "
  2263. << "See the add_library command's IMPORTED mode for details."
  2264. << "\n"
  2265. << "If you have a list of libraries that already contains the "
  2266. << "keyword, use the target_link_libraries command with its "
  2267. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2268. << "The command automatically recognizes link-type keywords and sets "
  2269. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2270. << "properties accordingly.";
  2271. }
  2272. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2273. }
  2274. //----------------------------------------------------------------------------
  2275. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  2276. cmMakefile* context)
  2277. {
  2278. // Look for link-type keywords in the value.
  2279. static cmsys::RegularExpression
  2280. keys("(^|;)(debug|optimized|general)(;|$)");
  2281. if(!keys.find(value))
  2282. {
  2283. return;
  2284. }
  2285. // Report an error.
  2286. std::ostringstream e;
  2287. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2288. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  2289. "property may contain configuration-sensitive generator-expressions "
  2290. "which may be used to specify per-configuration rules.";
  2291. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2292. }
  2293. //----------------------------------------------------------------------------
  2294. void cmTarget::CheckProperty(const std::string& prop,
  2295. cmMakefile* context) const
  2296. {
  2297. // Certain properties need checking.
  2298. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  2299. {
  2300. if(const char* value = this->GetProperty(prop))
  2301. {
  2302. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2303. }
  2304. }
  2305. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2306. {
  2307. if(const char* value = this->GetProperty(prop))
  2308. {
  2309. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2310. }
  2311. }
  2312. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  2313. {
  2314. if(const char* value = this->GetProperty(prop))
  2315. {
  2316. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  2317. }
  2318. }
  2319. }
  2320. //----------------------------------------------------------------------------
  2321. void cmTarget::MarkAsImported()
  2322. {
  2323. this->IsImportedTarget = true;
  2324. }
  2325. //----------------------------------------------------------------------------
  2326. bool cmTarget::HaveWellDefinedOutputFiles() const
  2327. {
  2328. return
  2329. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2330. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2331. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2332. this->GetType() == cmTarget::EXECUTABLE;
  2333. }
  2334. //----------------------------------------------------------------------------
  2335. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(
  2336. const std::string& config) const
  2337. {
  2338. // There is no output information for imported targets.
  2339. if(this->IsImported())
  2340. {
  2341. return 0;
  2342. }
  2343. // Only libraries and executables have well-defined output files.
  2344. if(!this->HaveWellDefinedOutputFiles())
  2345. {
  2346. std::string msg = "cmTarget::GetOutputInfo called for ";
  2347. msg += this->GetName();
  2348. msg += " which has type ";
  2349. msg += cmTarget::GetTargetTypeName(this->GetType());
  2350. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2351. return 0;
  2352. }
  2353. // Lookup/compute/cache the output information for this configuration.
  2354. std::string config_upper;
  2355. if(!config.empty())
  2356. {
  2357. config_upper = cmSystemTools::UpperCase(config);
  2358. }
  2359. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2360. OutputInfoMapType::const_iterator i =
  2361. this->Internal->OutputInfoMap.find(config_upper);
  2362. if(i == this->Internal->OutputInfoMap.end())
  2363. {
  2364. OutputInfo info;
  2365. this->ComputeOutputDir(config, false, info.OutDir);
  2366. this->ComputeOutputDir(config, true, info.ImpDir);
  2367. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  2368. {
  2369. info.PdbDir = info.OutDir;
  2370. }
  2371. OutputInfoMapType::value_type entry(config_upper, info);
  2372. i = this->Internal->OutputInfoMap.insert(entry).first;
  2373. }
  2374. return &i->second;
  2375. }
  2376. //----------------------------------------------------------------------------
  2377. cmTarget::CompileInfo const* cmTarget::GetCompileInfo(
  2378. const std::string& config) const
  2379. {
  2380. // There is no compile information for imported targets.
  2381. if(this->IsImported())
  2382. {
  2383. return 0;
  2384. }
  2385. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  2386. {
  2387. std::string msg = "cmTarget::GetCompileInfo called for ";
  2388. msg += this->GetName();
  2389. msg += " which has type ";
  2390. msg += cmTarget::GetTargetTypeName(this->GetType());
  2391. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2392. return 0;
  2393. }
  2394. // Lookup/compute/cache the compile information for this configuration.
  2395. std::string config_upper;
  2396. if(!config.empty())
  2397. {
  2398. config_upper = cmSystemTools::UpperCase(config);
  2399. }
  2400. typedef cmTargetInternals::CompileInfoMapType CompileInfoMapType;
  2401. CompileInfoMapType::const_iterator i =
  2402. this->Internal->CompileInfoMap.find(config_upper);
  2403. if(i == this->Internal->CompileInfoMap.end())
  2404. {
  2405. CompileInfo info;
  2406. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  2407. CompileInfoMapType::value_type entry(config_upper, info);
  2408. i = this->Internal->CompileInfoMap.insert(entry).first;
  2409. }
  2410. return &i->second;
  2411. }
  2412. //----------------------------------------------------------------------------
  2413. std::string cmTarget::GetDirectory(const std::string& config,
  2414. bool implib) const
  2415. {
  2416. if (this->IsImported())
  2417. {
  2418. // Return the directory from which the target is imported.
  2419. return
  2420. cmSystemTools::GetFilenamePath(
  2421. this->ImportedGetFullPath(config, implib));
  2422. }
  2423. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2424. {
  2425. // Return the directory in which the target will be built.
  2426. return implib? info->ImpDir : info->OutDir;
  2427. }
  2428. return "";
  2429. }
  2430. //----------------------------------------------------------------------------
  2431. std::string cmTarget::GetPDBDirectory(const std::string& config) const
  2432. {
  2433. if(OutputInfo const* info = this->GetOutputInfo(config))
  2434. {
  2435. // Return the directory in which the target will be built.
  2436. return info->PdbDir;
  2437. }
  2438. return "";
  2439. }
  2440. //----------------------------------------------------------------------------
  2441. std::string cmTarget::GetCompilePDBDirectory(const std::string& config) const
  2442. {
  2443. if(CompileInfo const* info = this->GetCompileInfo(config))
  2444. {
  2445. return info->CompilePdbDir;
  2446. }
  2447. return "";
  2448. }
  2449. //----------------------------------------------------------------------------
  2450. const char* cmTarget::ImportedGetLocation(const std::string& config) const
  2451. {
  2452. static std::string location;
  2453. assert(this->IsImported());
  2454. location = this->ImportedGetFullPath(config, false);
  2455. return location.c_str();
  2456. }
  2457. //----------------------------------------------------------------------------
  2458. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2459. {
  2460. int patch;
  2461. this->GetTargetVersion(false, major, minor, patch);
  2462. }
  2463. //----------------------------------------------------------------------------
  2464. void cmTarget::GetTargetVersion(bool soversion,
  2465. int& major, int& minor, int& patch) const
  2466. {
  2467. // Set the default values.
  2468. major = 0;
  2469. minor = 0;
  2470. patch = 0;
  2471. assert(this->GetType() != INTERFACE_LIBRARY);
  2472. // Look for a VERSION or SOVERSION property.
  2473. const char* prop = soversion? "SOVERSION" : "VERSION";
  2474. if(const char* version = this->GetProperty(prop))
  2475. {
  2476. // Try to parse the version number and store the results that were
  2477. // successfully parsed.
  2478. int parsed_major;
  2479. int parsed_minor;
  2480. int parsed_patch;
  2481. switch(sscanf(version, "%d.%d.%d",
  2482. &parsed_major, &parsed_minor, &parsed_patch))
  2483. {
  2484. case 3: patch = parsed_patch; // no break!
  2485. case 2: minor = parsed_minor; // no break!
  2486. case 1: major = parsed_major; // no break!
  2487. default: break;
  2488. }
  2489. }
  2490. }
  2491. //----------------------------------------------------------------------------
  2492. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  2493. {
  2494. if (this->IsImported())
  2495. {
  2496. return true;
  2497. }
  2498. std::ostringstream e;
  2499. const char *modal = 0;
  2500. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2501. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  2502. {
  2503. case cmPolicies::WARN:
  2504. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  2505. modal = "should";
  2506. case cmPolicies::OLD:
  2507. break;
  2508. case cmPolicies::REQUIRED_ALWAYS:
  2509. case cmPolicies::REQUIRED_IF_USED:
  2510. case cmPolicies::NEW:
  2511. modal = "may";
  2512. messageType = cmake::FATAL_ERROR;
  2513. }
  2514. if (modal)
  2515. {
  2516. e << "The LOCATION property " << modal << " not be read from target \""
  2517. << this->GetName() << "\". Use the target name directly with "
  2518. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2519. "as appropriate.\n";
  2520. context->IssueMessage(messageType, e.str());
  2521. }
  2522. return messageType != cmake::FATAL_ERROR;
  2523. }
  2524. //----------------------------------------------------------------------------
  2525. static void MakePropertyList(std::string& output,
  2526. std::vector<cmTargetInternals::TargetPropertyEntry*> const& values)
  2527. {
  2528. output = "";
  2529. std::string sep;
  2530. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  2531. it = values.begin(), end = values.end();
  2532. it != end; ++it)
  2533. {
  2534. output += sep;
  2535. output += (*it)->ge->GetInput();
  2536. sep = ";";
  2537. }
  2538. }
  2539. //----------------------------------------------------------------------------
  2540. const char *cmTarget::GetProperty(const std::string& prop) const
  2541. {
  2542. return this->GetProperty(prop, this->Makefile);
  2543. }
  2544. //----------------------------------------------------------------------------
  2545. const char *cmTarget::GetProperty(const std::string& prop,
  2546. cmMakefile* context) const
  2547. {
  2548. if (this->GetType() == INTERFACE_LIBRARY
  2549. && !whiteListedInterfaceProperty(prop))
  2550. {
  2551. std::ostringstream e;
  2552. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2553. "The property \"" << prop << "\" is not allowed.";
  2554. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2555. return 0;
  2556. }
  2557. // Watch for special "computed" properties that are dependent on
  2558. // other properties or variables. Always recompute them.
  2559. if(this->GetType() == cmTarget::EXECUTABLE ||
  2560. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2561. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2562. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2563. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2564. {
  2565. static const std::string propLOCATION = "LOCATION";
  2566. if(prop == propLOCATION)
  2567. {
  2568. if (!this->HandleLocationPropertyPolicy(context))
  2569. {
  2570. return 0;
  2571. }
  2572. // Set the LOCATION property of the target.
  2573. //
  2574. // For an imported target this is the location of an arbitrary
  2575. // available configuration.
  2576. //
  2577. if(this->IsImported())
  2578. {
  2579. this->Properties.SetProperty(
  2580. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  2581. }
  2582. else
  2583. {
  2584. // For a non-imported target this is deprecated because it
  2585. // cannot take into account the per-configuration name of the
  2586. // target because the configuration type may not be known at
  2587. // CMake time.
  2588. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2589. gg->CreateGenerationObjects();
  2590. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2591. this->Properties.SetProperty(propLOCATION,
  2592. gt->GetLocationForBuild());
  2593. }
  2594. }
  2595. // Support "LOCATION_<CONFIG>".
  2596. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2597. {
  2598. if (!this->HandleLocationPropertyPolicy(context))
  2599. {
  2600. return 0;
  2601. }
  2602. const char* configName = prop.c_str() + 9;
  2603. if (this->IsImported())
  2604. {
  2605. this->Properties.SetProperty(
  2606. prop, this->ImportedGetFullPath(configName, false).c_str());
  2607. }
  2608. else
  2609. {
  2610. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2611. gg->CreateGenerationObjects();
  2612. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2613. this->Properties.SetProperty(
  2614. prop, gt->GetFullPath(configName, false).c_str());
  2615. }
  2616. }
  2617. // Support "<CONFIG>_LOCATION".
  2618. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  2619. {
  2620. std::string configName(prop.c_str(), prop.size() - 9);
  2621. if(configName != "IMPORTED")
  2622. {
  2623. if (!this->HandleLocationPropertyPolicy(context))
  2624. {
  2625. return 0;
  2626. }
  2627. if (this->IsImported())
  2628. {
  2629. this->Properties.SetProperty(
  2630. prop, this->ImportedGetFullPath(configName, false).c_str());
  2631. }
  2632. else
  2633. {
  2634. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2635. gg->CreateGenerationObjects();
  2636. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2637. this->Properties.SetProperty(
  2638. prop, gt->GetFullPath(configName, false).c_str());
  2639. }
  2640. }
  2641. }
  2642. }
  2643. static UNORDERED_SET<std::string> specialProps;
  2644. #define MAKE_STATIC_PROP(PROP) \
  2645. static const std::string prop##PROP = #PROP
  2646. MAKE_STATIC_PROP(LINK_LIBRARIES);
  2647. MAKE_STATIC_PROP(TYPE);
  2648. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  2649. MAKE_STATIC_PROP(COMPILE_FEATURES);
  2650. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  2651. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  2652. MAKE_STATIC_PROP(IMPORTED);
  2653. MAKE_STATIC_PROP(NAME);
  2654. MAKE_STATIC_PROP(BINARY_DIR);
  2655. MAKE_STATIC_PROP(SOURCE_DIR);
  2656. MAKE_STATIC_PROP(SOURCES);
  2657. #undef MAKE_STATIC_PROP
  2658. if(specialProps.empty())
  2659. {
  2660. specialProps.insert(propLINK_LIBRARIES);
  2661. specialProps.insert(propTYPE);
  2662. specialProps.insert(propINCLUDE_DIRECTORIES);
  2663. specialProps.insert(propCOMPILE_FEATURES);
  2664. specialProps.insert(propCOMPILE_OPTIONS);
  2665. specialProps.insert(propCOMPILE_DEFINITIONS);
  2666. specialProps.insert(propIMPORTED);
  2667. specialProps.insert(propNAME);
  2668. specialProps.insert(propBINARY_DIR);
  2669. specialProps.insert(propSOURCE_DIR);
  2670. specialProps.insert(propSOURCES);
  2671. }
  2672. if(specialProps.count(prop))
  2673. {
  2674. if(prop == propLINK_LIBRARIES)
  2675. {
  2676. if (this->Internal->LinkImplementationPropertyEntries.empty())
  2677. {
  2678. return 0;
  2679. }
  2680. static std::string output;
  2681. output = "";
  2682. std::string sep;
  2683. for (std::vector<cmValueWithOrigin>::const_iterator
  2684. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2685. end = this->Internal->LinkImplementationPropertyEntries.end();
  2686. it != end; ++it)
  2687. {
  2688. output += sep;
  2689. output += it->Value;
  2690. sep = ";";
  2691. }
  2692. return output.c_str();
  2693. }
  2694. // the type property returns what type the target is
  2695. else if (prop == propTYPE)
  2696. {
  2697. return cmTarget::GetTargetTypeName(this->GetType());
  2698. }
  2699. else if(prop == propINCLUDE_DIRECTORIES)
  2700. {
  2701. if (this->Internal->IncludeDirectoriesEntries.empty())
  2702. {
  2703. return 0;
  2704. }
  2705. static std::string output;
  2706. MakePropertyList(output, this->Internal->IncludeDirectoriesEntries);
  2707. return output.c_str();
  2708. }
  2709. else if(prop == propCOMPILE_FEATURES)
  2710. {
  2711. if (this->Internal->CompileFeaturesEntries.empty())
  2712. {
  2713. return 0;
  2714. }
  2715. static std::string output;
  2716. MakePropertyList(output, this->Internal->CompileFeaturesEntries);
  2717. return output.c_str();
  2718. }
  2719. else if(prop == propCOMPILE_OPTIONS)
  2720. {
  2721. if (this->Internal->CompileOptionsEntries.empty())
  2722. {
  2723. return 0;
  2724. }
  2725. static std::string output;
  2726. MakePropertyList(output, this->Internal->CompileOptionsEntries);
  2727. return output.c_str();
  2728. }
  2729. else if(prop == propCOMPILE_DEFINITIONS)
  2730. {
  2731. if (this->Internal->CompileDefinitionsEntries.empty())
  2732. {
  2733. return 0;
  2734. }
  2735. static std::string output;
  2736. MakePropertyList(output, this->Internal->CompileDefinitionsEntries);
  2737. return output.c_str();
  2738. }
  2739. else if (prop == propIMPORTED)
  2740. {
  2741. return this->IsImported()?"TRUE":"FALSE";
  2742. }
  2743. else if (prop == propNAME)
  2744. {
  2745. return this->GetName().c_str();
  2746. }
  2747. else if (prop == propBINARY_DIR)
  2748. {
  2749. return this->GetMakefile()->GetCurrentBinaryDirectory();
  2750. }
  2751. else if (prop == propSOURCE_DIR)
  2752. {
  2753. return this->GetMakefile()->GetCurrentSourceDirectory();
  2754. }
  2755. else if(prop == propSOURCES)
  2756. {
  2757. if (this->Internal->SourceEntries.empty())
  2758. {
  2759. return 0;
  2760. }
  2761. std::ostringstream ss;
  2762. const char* sep = "";
  2763. typedef cmTargetInternals::TargetPropertyEntry
  2764. TargetPropertyEntry;
  2765. for(std::vector<TargetPropertyEntry*>::const_iterator
  2766. i = this->Internal->SourceEntries.begin();
  2767. i != this->Internal->SourceEntries.end(); ++i)
  2768. {
  2769. std::string entry = (*i)->ge->GetInput();
  2770. std::vector<std::string> files;
  2771. cmSystemTools::ExpandListArgument(entry, files);
  2772. for (std::vector<std::string>::const_iterator
  2773. li = files.begin(); li != files.end(); ++li)
  2774. {
  2775. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  2776. (*li)[li->size() - 1] == '>')
  2777. {
  2778. std::string objLibName = li->substr(17, li->size()-18);
  2779. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  2780. {
  2781. ss << sep;
  2782. sep = ";";
  2783. ss << *li;
  2784. continue;
  2785. }
  2786. bool addContent = false;
  2787. bool noMessage = true;
  2788. std::ostringstream e;
  2789. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2790. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  2791. {
  2792. case cmPolicies::WARN:
  2793. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  2794. noMessage = false;
  2795. case cmPolicies::OLD:
  2796. break;
  2797. case cmPolicies::REQUIRED_ALWAYS:
  2798. case cmPolicies::REQUIRED_IF_USED:
  2799. case cmPolicies::NEW:
  2800. addContent = true;
  2801. }
  2802. if (!noMessage)
  2803. {
  2804. e << "Target \"" << this->Name << "\" contains "
  2805. "$<TARGET_OBJECTS> generator expression in its sources list. "
  2806. "This content was not previously part of the SOURCES property "
  2807. "when that property was read at configure time. Code reading "
  2808. "that property needs to be adapted to ignore the generator "
  2809. "expression using the string(GENEX_STRIP) command.";
  2810. context->IssueMessage(messageType, e.str());
  2811. }
  2812. if (addContent)
  2813. {
  2814. ss << sep;
  2815. sep = ";";
  2816. ss << *li;
  2817. }
  2818. }
  2819. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  2820. {
  2821. ss << sep;
  2822. sep = ";";
  2823. ss << *li;
  2824. }
  2825. else
  2826. {
  2827. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  2828. // Construct what is known about this source file location.
  2829. cmSourceFileLocation const& location = sf->GetLocation();
  2830. std::string sname = location.GetDirectory();
  2831. if(!sname.empty())
  2832. {
  2833. sname += "/";
  2834. }
  2835. sname += location.GetName();
  2836. ss << sep;
  2837. sep = ";";
  2838. // Append this list entry.
  2839. ss << sname;
  2840. }
  2841. }
  2842. }
  2843. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  2844. }
  2845. }
  2846. const char *retVal = this->Properties.GetPropertyValue(prop);
  2847. if (!retVal)
  2848. {
  2849. const bool chain = this->GetMakefile()->GetState()->
  2850. IsPropertyChained(prop, cmProperty::TARGET);
  2851. if (chain)
  2852. {
  2853. return this->Makefile->GetProperty(prop, chain);
  2854. }
  2855. }
  2856. return retVal;
  2857. }
  2858. //----------------------------------------------------------------------------
  2859. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2860. {
  2861. return cmSystemTools::IsOn(this->GetProperty(prop));
  2862. }
  2863. //----------------------------------------------------------------------------
  2864. class cmTargetCollectLinkLanguages
  2865. {
  2866. public:
  2867. cmTargetCollectLinkLanguages(cmTarget const* target,
  2868. const std::string& config,
  2869. UNORDERED_SET<std::string>& languages,
  2870. cmTarget const* head):
  2871. Config(config), Languages(languages), HeadTarget(head),
  2872. Makefile(target->GetMakefile()), Target(target)
  2873. { this->Visited.insert(target); }
  2874. void Visit(cmLinkItem const& item)
  2875. {
  2876. if(!item.Target)
  2877. {
  2878. if(item.find("::") != std::string::npos)
  2879. {
  2880. bool noMessage = false;
  2881. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2882. std::ostringstream e;
  2883. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  2884. {
  2885. case cmPolicies::WARN:
  2886. {
  2887. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  2888. messageType = cmake::AUTHOR_WARNING;
  2889. }
  2890. break;
  2891. case cmPolicies::OLD:
  2892. noMessage = true;
  2893. case cmPolicies::REQUIRED_IF_USED:
  2894. case cmPolicies::REQUIRED_ALWAYS:
  2895. case cmPolicies::NEW:
  2896. // Issue the fatal message.
  2897. break;
  2898. }
  2899. if(!noMessage)
  2900. {
  2901. e << "Target \"" << this->Target->GetName()
  2902. << "\" links to target \"" << item
  2903. << "\" but the target was not found. Perhaps a find_package() "
  2904. "call is missing for an IMPORTED target, or an ALIAS target is "
  2905. "missing?";
  2906. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  2907. e.str(),
  2908. this->Target->GetBacktrace());
  2909. }
  2910. }
  2911. return;
  2912. }
  2913. if(!this->Visited.insert(item.Target).second)
  2914. {
  2915. return;
  2916. }
  2917. cmTarget::LinkInterface const* iface =
  2918. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  2919. if(!iface) { return; }
  2920. for(std::vector<std::string>::const_iterator
  2921. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2922. {
  2923. this->Languages.insert(*li);
  2924. }
  2925. for(std::vector<cmLinkItem>::const_iterator
  2926. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2927. {
  2928. this->Visit(*li);
  2929. }
  2930. }
  2931. private:
  2932. std::string Config;
  2933. UNORDERED_SET<std::string>& Languages;
  2934. cmTarget const* HeadTarget;
  2935. cmMakefile* Makefile;
  2936. const cmTarget* Target;
  2937. std::set<cmTarget const*> Visited;
  2938. };
  2939. //----------------------------------------------------------------------------
  2940. std::string cmTarget::GetLinkerLanguage(const std::string& config) const
  2941. {
  2942. return this->GetLinkClosure(config)->LinkerLanguage;
  2943. }
  2944. //----------------------------------------------------------------------------
  2945. cmTarget::LinkClosure const*
  2946. cmTarget::GetLinkClosure(const std::string& config) const
  2947. {
  2948. std::string key(cmSystemTools::UpperCase(config));
  2949. cmTargetInternals::LinkClosureMapType::iterator
  2950. i = this->Internal->LinkClosureMap.find(key);
  2951. if(i == this->Internal->LinkClosureMap.end())
  2952. {
  2953. LinkClosure lc;
  2954. this->ComputeLinkClosure(config, lc);
  2955. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2956. i = this->Internal->LinkClosureMap.insert(entry).first;
  2957. }
  2958. return &i->second;
  2959. }
  2960. //----------------------------------------------------------------------------
  2961. class cmTargetSelectLinker
  2962. {
  2963. int Preference;
  2964. cmTarget const* Target;
  2965. cmMakefile* Makefile;
  2966. cmGlobalGenerator* GG;
  2967. UNORDERED_SET<std::string> Preferred;
  2968. public:
  2969. cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
  2970. {
  2971. this->Makefile = this->Target->GetMakefile();
  2972. this->GG = this->Makefile->GetGlobalGenerator();
  2973. }
  2974. void Consider(const std::string& lang)
  2975. {
  2976. int preference = this->GG->GetLinkerPreference(lang);
  2977. if(preference > this->Preference)
  2978. {
  2979. this->Preference = preference;
  2980. this->Preferred.clear();
  2981. }
  2982. if(preference == this->Preference)
  2983. {
  2984. this->Preferred.insert(lang);
  2985. }
  2986. }
  2987. std::string Choose()
  2988. {
  2989. if(this->Preferred.empty())
  2990. {
  2991. return "";
  2992. }
  2993. else if(this->Preferred.size() > 1)
  2994. {
  2995. std::ostringstream e;
  2996. e << "Target " << this->Target->GetName()
  2997. << " contains multiple languages with the highest linker preference"
  2998. << " (" << this->Preference << "):\n";
  2999. for(UNORDERED_SET<std::string>::const_iterator
  3000. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3001. {
  3002. e << " " << *li << "\n";
  3003. }
  3004. e << "Set the LINKER_LANGUAGE property for this target.";
  3005. cmake* cm = this->Makefile->GetCMakeInstance();
  3006. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3007. this->Target->GetBacktrace());
  3008. }
  3009. return *this->Preferred.begin();
  3010. }
  3011. };
  3012. //----------------------------------------------------------------------------
  3013. void cmTarget::ComputeLinkClosure(const std::string& config,
  3014. LinkClosure& lc) const
  3015. {
  3016. // Get languages built in this target.
  3017. UNORDERED_SET<std::string> languages;
  3018. LinkImplementation const* impl = this->GetLinkImplementation(config);
  3019. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3020. li != impl->Languages.end(); ++li)
  3021. {
  3022. languages.insert(*li);
  3023. }
  3024. // Add interface languages from linked targets.
  3025. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  3026. for(std::vector<cmLinkImplItem>::const_iterator
  3027. li = impl->Libraries.begin();
  3028. li != impl->Libraries.end(); ++li)
  3029. {
  3030. cll.Visit(*li);
  3031. }
  3032. // Store the transitive closure of languages.
  3033. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  3034. li != languages.end(); ++li)
  3035. {
  3036. lc.Languages.push_back(*li);
  3037. }
  3038. // Choose the language whose linker should be used.
  3039. if(this->GetProperty("HAS_CXX"))
  3040. {
  3041. lc.LinkerLanguage = "CXX";
  3042. }
  3043. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3044. {
  3045. lc.LinkerLanguage = linkerLang;
  3046. }
  3047. else
  3048. {
  3049. // Find the language with the highest preference value.
  3050. cmTargetSelectLinker tsl(this);
  3051. // First select from the languages compiled directly in this target.
  3052. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3053. li != impl->Languages.end(); ++li)
  3054. {
  3055. tsl.Consider(*li);
  3056. }
  3057. // Now consider languages that propagate from linked targets.
  3058. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  3059. sit != languages.end(); ++sit)
  3060. {
  3061. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3062. if(this->Makefile->IsOn(propagates))
  3063. {
  3064. tsl.Consider(*sit);
  3065. }
  3066. }
  3067. lc.LinkerLanguage = tsl.Choose();
  3068. }
  3069. }
  3070. //----------------------------------------------------------------------------
  3071. void cmTarget::ExpandLinkItems(std::string const& prop,
  3072. std::string const& value,
  3073. std::string const& config,
  3074. cmTarget const* headTarget,
  3075. bool usage_requirements_only,
  3076. std::vector<cmLinkItem>& items,
  3077. bool& hadHeadSensitiveCondition) const
  3078. {
  3079. cmGeneratorExpression ge;
  3080. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3081. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3082. // link dependencies that are otherwise excluded from usage requirements.
  3083. if(usage_requirements_only)
  3084. {
  3085. dagChecker.SetTransitivePropertiesOnly();
  3086. }
  3087. std::vector<std::string> libs;
  3088. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3089. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3090. this->Makefile,
  3091. config,
  3092. false,
  3093. headTarget,
  3094. this, &dagChecker), libs);
  3095. this->LookupLinkItems(libs, items);
  3096. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3097. }
  3098. //----------------------------------------------------------------------------
  3099. void cmTarget::LookupLinkItems(std::vector<std::string> const& names,
  3100. std::vector<cmLinkItem>& items) const
  3101. {
  3102. for(std::vector<std::string>::const_iterator i = names.begin();
  3103. i != names.end(); ++i)
  3104. {
  3105. std::string name = this->CheckCMP0004(*i);
  3106. if(name == this->GetName() || name.empty())
  3107. {
  3108. continue;
  3109. }
  3110. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  3111. }
  3112. }
  3113. //----------------------------------------------------------------------------
  3114. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  3115. {
  3116. switch(this->GetType())
  3117. {
  3118. case cmTarget::STATIC_LIBRARY:
  3119. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3120. case cmTarget::SHARED_LIBRARY:
  3121. return (implib
  3122. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3123. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3124. case cmTarget::MODULE_LIBRARY:
  3125. return (implib
  3126. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3127. : "CMAKE_SHARED_MODULE_SUFFIX");
  3128. case cmTarget::EXECUTABLE:
  3129. return (implib
  3130. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3131. // Android GUI application packages store the native
  3132. // binary as a shared library.
  3133. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  3134. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  3135. default:
  3136. break;
  3137. }
  3138. return "";
  3139. }
  3140. //----------------------------------------------------------------------------
  3141. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  3142. {
  3143. switch(this->GetType())
  3144. {
  3145. case cmTarget::STATIC_LIBRARY:
  3146. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3147. case cmTarget::SHARED_LIBRARY:
  3148. return (implib
  3149. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3150. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3151. case cmTarget::MODULE_LIBRARY:
  3152. return (implib
  3153. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3154. : "CMAKE_SHARED_MODULE_PREFIX");
  3155. case cmTarget::EXECUTABLE:
  3156. return (implib
  3157. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3158. // Android GUI application packages store the native
  3159. // binary as a shared library.
  3160. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  3161. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  3162. default:
  3163. break;
  3164. }
  3165. return "";
  3166. }
  3167. //----------------------------------------------------------------------------
  3168. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  3169. {
  3170. bool install_name_is_rpath = false;
  3171. bool macosx_rpath = false;
  3172. if(!this->IsImportedTarget)
  3173. {
  3174. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  3175. {
  3176. return false;
  3177. }
  3178. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  3179. bool use_install_name =
  3180. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  3181. if(install_name && use_install_name &&
  3182. std::string(install_name) == "@rpath")
  3183. {
  3184. install_name_is_rpath = true;
  3185. }
  3186. else if(install_name && use_install_name)
  3187. {
  3188. return false;
  3189. }
  3190. if(!install_name_is_rpath)
  3191. {
  3192. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3193. }
  3194. }
  3195. else
  3196. {
  3197. // Lookup the imported soname.
  3198. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3199. {
  3200. if(!info->NoSOName && !info->SOName.empty())
  3201. {
  3202. if(info->SOName.find("@rpath/") == 0)
  3203. {
  3204. install_name_is_rpath = true;
  3205. }
  3206. }
  3207. else
  3208. {
  3209. std::string install_name;
  3210. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  3211. if(install_name.find("@rpath") != std::string::npos)
  3212. {
  3213. install_name_is_rpath = true;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. if(!install_name_is_rpath && !macosx_rpath)
  3219. {
  3220. return false;
  3221. }
  3222. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3223. {
  3224. std::ostringstream w;
  3225. w << "Attempting to use";
  3226. if(macosx_rpath)
  3227. {
  3228. w << " MACOSX_RPATH";
  3229. }
  3230. else
  3231. {
  3232. w << " @rpath";
  3233. }
  3234. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  3235. w << " This could be because you are using a Mac OS X version";
  3236. w << " less than 10.5 or because CMake's platform configuration is";
  3237. w << " corrupt.";
  3238. cmake* cm = this->Makefile->GetCMakeInstance();
  3239. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  3240. }
  3241. return true;
  3242. }
  3243. //----------------------------------------------------------------------------
  3244. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3245. {
  3246. // we can't do rpaths when unsupported
  3247. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3248. {
  3249. return false;
  3250. }
  3251. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3252. if(macosx_rpath_str)
  3253. {
  3254. return this->GetPropertyAsBool("MACOSX_RPATH");
  3255. }
  3256. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3257. if(cmp0042 == cmPolicies::WARN)
  3258. {
  3259. this->Makefile->GetGlobalGenerator()->
  3260. AddCMP0042WarnTarget(this->GetName());
  3261. }
  3262. if(cmp0042 == cmPolicies::NEW)
  3263. {
  3264. return true;
  3265. }
  3266. return false;
  3267. }
  3268. //----------------------------------------------------------------------------
  3269. bool cmTarget::IsImportedSharedLibWithoutSOName(
  3270. const std::string& config) const
  3271. {
  3272. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3273. {
  3274. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3275. {
  3276. return info->NoSOName;
  3277. }
  3278. }
  3279. return false;
  3280. }
  3281. //----------------------------------------------------------------------------
  3282. std::string
  3283. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  3284. {
  3285. return cmSystemTools::GetFilenameName(
  3286. this->ImportedGetFullPath(config, implib));
  3287. }
  3288. //----------------------------------------------------------------------------
  3289. std::string
  3290. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  3291. {
  3292. std::string result;
  3293. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3294. {
  3295. result = implib? info->ImportLibrary : info->Location;
  3296. }
  3297. if(result.empty())
  3298. {
  3299. result = this->GetName();
  3300. result += "-NOTFOUND";
  3301. }
  3302. return result;
  3303. }
  3304. //----------------------------------------------------------------------------
  3305. void cmTarget::ComputeVersionedName(std::string& vName,
  3306. std::string const& prefix,
  3307. std::string const& base,
  3308. std::string const& suffix,
  3309. std::string const& name,
  3310. const char* version) const
  3311. {
  3312. vName = this->IsApple? (prefix+base) : name;
  3313. if(version)
  3314. {
  3315. vName += ".";
  3316. vName += version;
  3317. }
  3318. vName += this->IsApple? suffix : std::string();
  3319. }
  3320. //----------------------------------------------------------------------------
  3321. bool cmTarget::HasImplibGNUtoMS() const
  3322. {
  3323. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3324. }
  3325. //----------------------------------------------------------------------------
  3326. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3327. std::string& out, const char* newExt) const
  3328. {
  3329. if(this->HasImplibGNUtoMS() &&
  3330. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3331. {
  3332. out = gnuName.substr(0, gnuName.size()-6);
  3333. out += newExt? newExt : ".lib";
  3334. return true;
  3335. }
  3336. return false;
  3337. }
  3338. //----------------------------------------------------------------------------
  3339. void cmTarget::SetPropertyDefault(const std::string& property,
  3340. const char* default_value)
  3341. {
  3342. // Compute the name of the variable holding the default value.
  3343. std::string var = "CMAKE_";
  3344. var += property;
  3345. if(const char* value = this->Makefile->GetDefinition(var))
  3346. {
  3347. this->SetProperty(property, value);
  3348. }
  3349. else if(default_value)
  3350. {
  3351. this->SetProperty(property, default_value);
  3352. }
  3353. }
  3354. //----------------------------------------------------------------------------
  3355. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  3356. {
  3357. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3358. {
  3359. return false;
  3360. }
  3361. if(LinkImplementationLibraries const* impl =
  3362. this->GetLinkImplementationLibraries(config))
  3363. {
  3364. return !impl->Libraries.empty();
  3365. }
  3366. return false;
  3367. }
  3368. //----------------------------------------------------------------------------
  3369. bool cmTarget::HaveInstallTreeRPATH() const
  3370. {
  3371. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3372. return (install_rpath && *install_rpath) &&
  3373. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3374. }
  3375. //----------------------------------------------------------------------------
  3376. const char* cmTarget::GetOutputTargetType(bool implib) const
  3377. {
  3378. switch(this->GetType())
  3379. {
  3380. case cmTarget::SHARED_LIBRARY:
  3381. if(this->DLLPlatform)
  3382. {
  3383. if(implib)
  3384. {
  3385. // A DLL import library is treated as an archive target.
  3386. return "ARCHIVE";
  3387. }
  3388. else
  3389. {
  3390. // A DLL shared library is treated as a runtime target.
  3391. return "RUNTIME";
  3392. }
  3393. }
  3394. else
  3395. {
  3396. // For non-DLL platforms shared libraries are treated as
  3397. // library targets.
  3398. return "LIBRARY";
  3399. }
  3400. case cmTarget::STATIC_LIBRARY:
  3401. // Static libraries are always treated as archive targets.
  3402. return "ARCHIVE";
  3403. case cmTarget::MODULE_LIBRARY:
  3404. if(implib)
  3405. {
  3406. // Module libraries are always treated as library targets.
  3407. return "ARCHIVE";
  3408. }
  3409. else
  3410. {
  3411. // Module import libraries are treated as archive targets.
  3412. return "LIBRARY";
  3413. }
  3414. case cmTarget::EXECUTABLE:
  3415. if(implib)
  3416. {
  3417. // Executable import libraries are treated as archive targets.
  3418. return "ARCHIVE";
  3419. }
  3420. else
  3421. {
  3422. // Executables are always treated as runtime targets.
  3423. return "RUNTIME";
  3424. }
  3425. default:
  3426. break;
  3427. }
  3428. return "";
  3429. }
  3430. //----------------------------------------------------------------------------
  3431. bool cmTarget::ComputeOutputDir(const std::string& config,
  3432. bool implib, std::string& out) const
  3433. {
  3434. bool usesDefaultOutputDir = false;
  3435. std::string conf = config;
  3436. // Look for a target property defining the target output directory
  3437. // based on the target type.
  3438. std::string targetTypeName = this->GetOutputTargetType(implib);
  3439. const char* propertyName = 0;
  3440. std::string propertyNameStr = targetTypeName;
  3441. if(!propertyNameStr.empty())
  3442. {
  3443. propertyNameStr += "_OUTPUT_DIRECTORY";
  3444. propertyName = propertyNameStr.c_str();
  3445. }
  3446. // Check for a per-configuration output directory target property.
  3447. std::string configUpper = cmSystemTools::UpperCase(conf);
  3448. const char* configProp = 0;
  3449. std::string configPropStr = targetTypeName;
  3450. if(!configPropStr.empty())
  3451. {
  3452. configPropStr += "_OUTPUT_DIRECTORY_";
  3453. configPropStr += configUpper;
  3454. configProp = configPropStr.c_str();
  3455. }
  3456. // Select an output directory.
  3457. if(const char* config_outdir = this->GetProperty(configProp))
  3458. {
  3459. // Use the user-specified per-configuration output directory.
  3460. out = config_outdir;
  3461. // Skip per-configuration subdirectory.
  3462. conf = "";
  3463. }
  3464. else if(const char* outdir = this->GetProperty(propertyName))
  3465. {
  3466. // Use the user-specified output directory.
  3467. out = outdir;
  3468. }
  3469. else if(this->GetType() == cmTarget::EXECUTABLE)
  3470. {
  3471. // Lookup the output path for executables.
  3472. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3473. }
  3474. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3475. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3476. this->GetType() == cmTarget::MODULE_LIBRARY)
  3477. {
  3478. // Lookup the output path for libraries.
  3479. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3480. }
  3481. if(out.empty())
  3482. {
  3483. // Default to the current output directory.
  3484. usesDefaultOutputDir = true;
  3485. out = ".";
  3486. }
  3487. // Convert the output path to a full path in case it is
  3488. // specified as a relative path. Treat a relative path as
  3489. // relative to the current output directory for this makefile.
  3490. out = (cmSystemTools::CollapseFullPath
  3491. (out, this->Makefile->GetCurrentBinaryDirectory()));
  3492. // The generator may add the configuration's subdirectory.
  3493. if(!conf.empty())
  3494. {
  3495. const char *platforms = this->Makefile->GetDefinition(
  3496. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3497. std::string suffix =
  3498. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3499. this->Makefile->GetGlobalGenerator()->
  3500. AppendDirectoryForConfig("/", conf, suffix, out);
  3501. }
  3502. return usesDefaultOutputDir;
  3503. }
  3504. //----------------------------------------------------------------------------
  3505. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  3506. const std::string& config,
  3507. std::string& out) const
  3508. {
  3509. // Look for a target property defining the target output directory
  3510. // based on the target type.
  3511. const char* propertyName = 0;
  3512. std::string propertyNameStr = kind;
  3513. if(!propertyNameStr.empty())
  3514. {
  3515. propertyNameStr += "_OUTPUT_DIRECTORY";
  3516. propertyName = propertyNameStr.c_str();
  3517. }
  3518. std::string conf = config;
  3519. // Check for a per-configuration output directory target property.
  3520. std::string configUpper = cmSystemTools::UpperCase(conf);
  3521. const char* configProp = 0;
  3522. std::string configPropStr = kind;
  3523. if(!configPropStr.empty())
  3524. {
  3525. configPropStr += "_OUTPUT_DIRECTORY_";
  3526. configPropStr += configUpper;
  3527. configProp = configPropStr.c_str();
  3528. }
  3529. // Select an output directory.
  3530. if(const char* config_outdir = this->GetProperty(configProp))
  3531. {
  3532. // Use the user-specified per-configuration output directory.
  3533. out = config_outdir;
  3534. // Skip per-configuration subdirectory.
  3535. conf = "";
  3536. }
  3537. else if(const char* outdir = this->GetProperty(propertyName))
  3538. {
  3539. // Use the user-specified output directory.
  3540. out = outdir;
  3541. }
  3542. if(out.empty())
  3543. {
  3544. return false;
  3545. }
  3546. // Convert the output path to a full path in case it is
  3547. // specified as a relative path. Treat a relative path as
  3548. // relative to the current output directory for this makefile.
  3549. out = (cmSystemTools::CollapseFullPath
  3550. (out, this->Makefile->GetCurrentBinaryDirectory()));
  3551. // The generator may add the configuration's subdirectory.
  3552. if(!conf.empty())
  3553. {
  3554. this->Makefile->GetGlobalGenerator()->
  3555. AppendDirectoryForConfig("/", conf, "", out);
  3556. }
  3557. return true;
  3558. }
  3559. //----------------------------------------------------------------------------
  3560. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  3561. bool implib) const
  3562. {
  3563. std::string dir;
  3564. return this->ComputeOutputDir(config, implib, dir);
  3565. }
  3566. //----------------------------------------------------------------------------
  3567. std::string cmTarget::GetOutputName(const std::string& config,
  3568. bool implib) const
  3569. {
  3570. std::vector<std::string> props;
  3571. std::string type = this->GetOutputTargetType(implib);
  3572. std::string configUpper = cmSystemTools::UpperCase(config);
  3573. if(!type.empty() && !configUpper.empty())
  3574. {
  3575. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3576. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3577. }
  3578. if(!type.empty())
  3579. {
  3580. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3581. props.push_back(type + "_OUTPUT_NAME");
  3582. }
  3583. if(!configUpper.empty())
  3584. {
  3585. // OUTPUT_NAME_<CONFIG>
  3586. props.push_back("OUTPUT_NAME_" + configUpper);
  3587. // <CONFIG>_OUTPUT_NAME
  3588. props.push_back(configUpper + "_OUTPUT_NAME");
  3589. }
  3590. // OUTPUT_NAME
  3591. props.push_back("OUTPUT_NAME");
  3592. std::string outName;
  3593. for(std::vector<std::string>::const_iterator i = props.begin();
  3594. i != props.end(); ++i)
  3595. {
  3596. if (const char* outNameProp = this->GetProperty(*i))
  3597. {
  3598. outName = outNameProp;
  3599. break;
  3600. }
  3601. }
  3602. if (outName.empty())
  3603. {
  3604. outName = this->GetName();
  3605. }
  3606. cmGeneratorExpression ge;
  3607. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  3608. return cge->Evaluate(this->Makefile, config);
  3609. }
  3610. //----------------------------------------------------------------------------
  3611. std::string cmTarget::GetFrameworkVersion() const
  3612. {
  3613. assert(this->GetType() != INTERFACE_LIBRARY);
  3614. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3615. {
  3616. return fversion;
  3617. }
  3618. else if(const char* tversion = this->GetProperty("VERSION"))
  3619. {
  3620. return tversion;
  3621. }
  3622. else
  3623. {
  3624. return "A";
  3625. }
  3626. }
  3627. //----------------------------------------------------------------------------
  3628. const char* cmTarget::GetExportMacro() const
  3629. {
  3630. // Define the symbol for targets that export symbols.
  3631. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3632. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3633. this->IsExecutableWithExports())
  3634. {
  3635. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3636. {
  3637. this->ExportMacro = custom_export_name;
  3638. }
  3639. else
  3640. {
  3641. std::string in = this->GetName();
  3642. in += "_EXPORTS";
  3643. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  3644. }
  3645. return this->ExportMacro.c_str();
  3646. }
  3647. else
  3648. {
  3649. return 0;
  3650. }
  3651. }
  3652. //----------------------------------------------------------------------------
  3653. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  3654. {
  3655. return this->LinkImplicitNullProperties.find(p)
  3656. != this->LinkImplicitNullProperties.end();
  3657. }
  3658. //----------------------------------------------------------------------------
  3659. void
  3660. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  3661. {
  3662. // At configure-time, this method can be called as part of getting the
  3663. // LOCATION property or to export() a file to be include()d. However
  3664. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  3665. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  3666. // behavior of CMP0024 and CMP0026 only.
  3667. typedef cmTargetInternals::TargetPropertyEntry
  3668. TargetPropertyEntry;
  3669. for(std::vector<TargetPropertyEntry*>::const_iterator
  3670. i = this->Internal->SourceEntries.begin();
  3671. i != this->Internal->SourceEntries.end(); ++i)
  3672. {
  3673. std::string entry = (*i)->ge->GetInput();
  3674. std::vector<std::string> files;
  3675. cmSystemTools::ExpandListArgument(entry, files);
  3676. for (std::vector<std::string>::const_iterator
  3677. li = files.begin(); li != files.end(); ++li)
  3678. {
  3679. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  3680. (*li)[li->size() - 1] == '>')
  3681. {
  3682. std::string objLibName = li->substr(17, li->size()-18);
  3683. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  3684. {
  3685. continue;
  3686. }
  3687. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
  3688. if(objLib)
  3689. {
  3690. objlibs.push_back(objLib);
  3691. }
  3692. }
  3693. }
  3694. }
  3695. }
  3696. //----------------------------------------------------------------------------
  3697. void cmTarget::GetLanguages(std::set<std::string>& languages,
  3698. const std::string& config) const
  3699. {
  3700. std::vector<cmSourceFile*> sourceFiles;
  3701. this->GetSourceFiles(sourceFiles, config);
  3702. for(std::vector<cmSourceFile*>::const_iterator
  3703. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  3704. {
  3705. const std::string& lang = (*i)->GetLanguage();
  3706. if(!lang.empty())
  3707. {
  3708. languages.insert(lang);
  3709. }
  3710. }
  3711. std::vector<cmTarget*> objectLibraries;
  3712. std::vector<cmSourceFile const*> externalObjects;
  3713. if (!this->Makefile->IsConfigured())
  3714. {
  3715. this->GetObjectLibrariesCMP0026(objectLibraries);
  3716. }
  3717. else
  3718. {
  3719. cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator()
  3720. ->GetGeneratorTarget(this);
  3721. gt->GetExternalObjects(externalObjects, config);
  3722. for(std::vector<cmSourceFile const*>::const_iterator
  3723. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  3724. {
  3725. std::string objLib = (*i)->GetObjectLibrary();
  3726. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  3727. {
  3728. objectLibraries.push_back(tgt);
  3729. }
  3730. }
  3731. }
  3732. for(std::vector<cmTarget*>::const_iterator
  3733. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  3734. {
  3735. (*i)->GetLanguages(languages, config);
  3736. }
  3737. }
  3738. //----------------------------------------------------------------------------
  3739. cmTarget::ImportInfo const*
  3740. cmTarget::GetImportInfo(const std::string& config) const
  3741. {
  3742. // There is no imported information for non-imported targets.
  3743. if(!this->IsImported())
  3744. {
  3745. return 0;
  3746. }
  3747. // Lookup/compute/cache the import information for this
  3748. // configuration.
  3749. std::string config_upper;
  3750. if(!config.empty())
  3751. {
  3752. config_upper = cmSystemTools::UpperCase(config);
  3753. }
  3754. else
  3755. {
  3756. config_upper = "NOCONFIG";
  3757. }
  3758. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3759. ImportInfoMapType::const_iterator i =
  3760. this->Internal->ImportInfoMap.find(config_upper);
  3761. if(i == this->Internal->ImportInfoMap.end())
  3762. {
  3763. ImportInfo info;
  3764. this->ComputeImportInfo(config_upper, info);
  3765. ImportInfoMapType::value_type entry(config_upper, info);
  3766. i = this->Internal->ImportInfoMap.insert(entry).first;
  3767. }
  3768. if(this->GetType() == INTERFACE_LIBRARY)
  3769. {
  3770. return &i->second;
  3771. }
  3772. // If the location is empty then the target is not available for
  3773. // this configuration.
  3774. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3775. {
  3776. return 0;
  3777. }
  3778. // Return the import information.
  3779. return &i->second;
  3780. }
  3781. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  3782. const char** loc,
  3783. const char** imp,
  3784. std::string& suffix) const
  3785. {
  3786. if (this->GetType() == INTERFACE_LIBRARY)
  3787. {
  3788. // This method attempts to find a config-specific LOCATION for the
  3789. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  3790. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  3791. // and valid response.
  3792. return true;
  3793. }
  3794. // Track the configuration-specific property suffix.
  3795. suffix = "_";
  3796. suffix += desired_config;
  3797. std::vector<std::string> mappedConfigs;
  3798. {
  3799. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3800. mapProp += desired_config;
  3801. if(const char* mapValue = this->GetProperty(mapProp))
  3802. {
  3803. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3804. }
  3805. }
  3806. // If we needed to find one of the mapped configurations but did not
  3807. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3808. // library or an executable with exports.
  3809. bool allowImp = this->HasImportLibrary();
  3810. // If a mapping was found, check its configurations.
  3811. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3812. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  3813. {
  3814. // Look for this configuration.
  3815. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  3816. std::string locProp = "IMPORTED_LOCATION_";
  3817. locProp += mcUpper;
  3818. *loc = this->GetProperty(locProp);
  3819. if(allowImp)
  3820. {
  3821. std::string impProp = "IMPORTED_IMPLIB_";
  3822. impProp += mcUpper;
  3823. *imp = this->GetProperty(impProp);
  3824. }
  3825. // If it was found, use it for all properties below.
  3826. if(*loc || *imp)
  3827. {
  3828. suffix = "_";
  3829. suffix += mcUpper;
  3830. }
  3831. }
  3832. // If we needed to find one of the mapped configurations but did not
  3833. // then the target is not found. The project does not want any
  3834. // other configuration.
  3835. if(!mappedConfigs.empty() && !*loc && !*imp)
  3836. {
  3837. return false;
  3838. }
  3839. // If we have not yet found it then there are no mapped
  3840. // configurations. Look for an exact-match.
  3841. if(!*loc && !*imp)
  3842. {
  3843. std::string locProp = "IMPORTED_LOCATION";
  3844. locProp += suffix;
  3845. *loc = this->GetProperty(locProp);
  3846. if(allowImp)
  3847. {
  3848. std::string impProp = "IMPORTED_IMPLIB";
  3849. impProp += suffix;
  3850. *imp = this->GetProperty(impProp);
  3851. }
  3852. }
  3853. // If we have not yet found it then there are no mapped
  3854. // configurations and no exact match.
  3855. if(!*loc && !*imp)
  3856. {
  3857. // The suffix computed above is not useful.
  3858. suffix = "";
  3859. // Look for a configuration-less location. This may be set by
  3860. // manually-written code.
  3861. *loc = this->GetProperty("IMPORTED_LOCATION");
  3862. if(allowImp)
  3863. {
  3864. *imp = this->GetProperty("IMPORTED_IMPLIB");
  3865. }
  3866. }
  3867. // If we have not yet found it then the project is willing to try
  3868. // any available configuration.
  3869. if(!*loc && !*imp)
  3870. {
  3871. std::vector<std::string> availableConfigs;
  3872. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3873. {
  3874. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3875. }
  3876. for(std::vector<std::string>::const_iterator
  3877. aci = availableConfigs.begin();
  3878. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  3879. {
  3880. suffix = "_";
  3881. suffix += cmSystemTools::UpperCase(*aci);
  3882. std::string locProp = "IMPORTED_LOCATION";
  3883. locProp += suffix;
  3884. *loc = this->GetProperty(locProp);
  3885. if(allowImp)
  3886. {
  3887. std::string impProp = "IMPORTED_IMPLIB";
  3888. impProp += suffix;
  3889. *imp = this->GetProperty(impProp);
  3890. }
  3891. }
  3892. }
  3893. // If we have not yet found it then the target is not available.
  3894. if(!*loc && !*imp)
  3895. {
  3896. return false;
  3897. }
  3898. return true;
  3899. }
  3900. //----------------------------------------------------------------------------
  3901. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3902. ImportInfo& info) const
  3903. {
  3904. // This method finds information about an imported target from its
  3905. // properties. The "IMPORTED_" namespace is reserved for properties
  3906. // defined by the project exporting the target.
  3907. // Initialize members.
  3908. info.NoSOName = false;
  3909. const char* loc = 0;
  3910. const char* imp = 0;
  3911. std::string suffix;
  3912. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  3913. {
  3914. return;
  3915. }
  3916. // Get the link interface.
  3917. {
  3918. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  3919. const char *propertyLibs = this->GetProperty(linkProp);
  3920. if (this->GetType() != INTERFACE_LIBRARY)
  3921. {
  3922. if(!propertyLibs)
  3923. {
  3924. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3925. linkProp += suffix;
  3926. propertyLibs = this->GetProperty(linkProp);
  3927. }
  3928. if(!propertyLibs)
  3929. {
  3930. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3931. propertyLibs = this->GetProperty(linkProp);
  3932. }
  3933. }
  3934. if(propertyLibs)
  3935. {
  3936. info.LibrariesProp = linkProp;
  3937. info.Libraries = propertyLibs;
  3938. }
  3939. }
  3940. if(this->GetType() == INTERFACE_LIBRARY)
  3941. {
  3942. return;
  3943. }
  3944. // A provided configuration has been chosen. Load the
  3945. // configuration's properties.
  3946. // Get the location.
  3947. if(loc)
  3948. {
  3949. info.Location = loc;
  3950. }
  3951. else
  3952. {
  3953. std::string impProp = "IMPORTED_LOCATION";
  3954. impProp += suffix;
  3955. if(const char* config_location = this->GetProperty(impProp))
  3956. {
  3957. info.Location = config_location;
  3958. }
  3959. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3960. {
  3961. info.Location = location;
  3962. }
  3963. }
  3964. // Get the soname.
  3965. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3966. {
  3967. std::string soProp = "IMPORTED_SONAME";
  3968. soProp += suffix;
  3969. if(const char* config_soname = this->GetProperty(soProp))
  3970. {
  3971. info.SOName = config_soname;
  3972. }
  3973. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3974. {
  3975. info.SOName = soname;
  3976. }
  3977. }
  3978. // Get the "no-soname" mark.
  3979. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3980. {
  3981. std::string soProp = "IMPORTED_NO_SONAME";
  3982. soProp += suffix;
  3983. if(const char* config_no_soname = this->GetProperty(soProp))
  3984. {
  3985. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3986. }
  3987. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3988. {
  3989. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3990. }
  3991. }
  3992. // Get the import library.
  3993. if(imp)
  3994. {
  3995. info.ImportLibrary = imp;
  3996. }
  3997. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3998. this->IsExecutableWithExports())
  3999. {
  4000. std::string impProp = "IMPORTED_IMPLIB";
  4001. impProp += suffix;
  4002. if(const char* config_implib = this->GetProperty(impProp))
  4003. {
  4004. info.ImportLibrary = config_implib;
  4005. }
  4006. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4007. {
  4008. info.ImportLibrary = implib;
  4009. }
  4010. }
  4011. // Get the link dependencies.
  4012. {
  4013. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4014. linkProp += suffix;
  4015. if(const char* config_libs = this->GetProperty(linkProp))
  4016. {
  4017. info.SharedDeps = config_libs;
  4018. }
  4019. else if(const char* libs =
  4020. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4021. {
  4022. info.SharedDeps = libs;
  4023. }
  4024. }
  4025. // Get the link languages.
  4026. if(this->LinkLanguagePropagatesToDependents())
  4027. {
  4028. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4029. linkProp += suffix;
  4030. if(const char* config_libs = this->GetProperty(linkProp))
  4031. {
  4032. info.Languages = config_libs;
  4033. }
  4034. else if(const char* libs =
  4035. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4036. {
  4037. info.Languages = libs;
  4038. }
  4039. }
  4040. // Get the cyclic repetition count.
  4041. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4042. {
  4043. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4044. linkProp += suffix;
  4045. if(const char* config_reps = this->GetProperty(linkProp))
  4046. {
  4047. sscanf(config_reps, "%u", &info.Multiplicity);
  4048. }
  4049. else if(const char* reps =
  4050. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4051. {
  4052. sscanf(reps, "%u", &info.Multiplicity);
  4053. }
  4054. }
  4055. }
  4056. //----------------------------------------------------------------------------
  4057. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  4058. const std::string& config,
  4059. cmTarget 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->IsExecutableWithExports())
  4070. {
  4071. return 0;
  4072. }
  4073. // Lookup any existing link interface for this configuration.
  4074. std::string CONFIG = cmSystemTools::UpperCase(config);
  4075. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  4076. this->Internal->LinkInterfaceMap[CONFIG];
  4077. // If the link interface does not depend on the head target
  4078. // then return the one we computed first.
  4079. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4080. {
  4081. return &hm.begin()->second;
  4082. }
  4083. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  4084. if(!iface.LibrariesDone)
  4085. {
  4086. iface.LibrariesDone = true;
  4087. this->Internal->ComputeLinkInterfaceLibraries(
  4088. this, config, iface, head, false);
  4089. }
  4090. if(!iface.AllDone)
  4091. {
  4092. iface.AllDone = true;
  4093. if(iface.Exists)
  4094. {
  4095. this->Internal->ComputeLinkInterface(this, config, iface, head);
  4096. }
  4097. }
  4098. return iface.Exists? &iface : 0;
  4099. }
  4100. //----------------------------------------------------------------------------
  4101. cmTarget::LinkInterfaceLibraries const*
  4102. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  4103. cmTarget const* head,
  4104. bool usage_requirements_only) const
  4105. {
  4106. // Imported targets have their own link interface.
  4107. if(this->IsImported())
  4108. {
  4109. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  4110. }
  4111. // Link interfaces are not supported for executables that do not
  4112. // export symbols.
  4113. if(this->GetType() == cmTarget::EXECUTABLE &&
  4114. !this->IsExecutableWithExports())
  4115. {
  4116. return 0;
  4117. }
  4118. // Lookup any existing link interface for this configuration.
  4119. std::string CONFIG = cmSystemTools::UpperCase(config);
  4120. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  4121. (usage_requirements_only ?
  4122. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  4123. this->Internal->LinkInterfaceMap[CONFIG]);
  4124. // If the link interface does not depend on the head target
  4125. // then return the one we computed first.
  4126. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4127. {
  4128. return &hm.begin()->second;
  4129. }
  4130. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  4131. if(!iface.LibrariesDone)
  4132. {
  4133. iface.LibrariesDone = true;
  4134. this->Internal->ComputeLinkInterfaceLibraries(
  4135. this, config, iface, head, usage_requirements_only);
  4136. }
  4137. return iface.Exists? &iface : 0;
  4138. }
  4139. //----------------------------------------------------------------------------
  4140. cmTarget::LinkInterface const*
  4141. cmTarget::GetImportLinkInterface(const std::string& config,
  4142. cmTarget const* headTarget,
  4143. bool usage_requirements_only) const
  4144. {
  4145. cmTarget::ImportInfo const* info = this->GetImportInfo(config);
  4146. if(!info)
  4147. {
  4148. return 0;
  4149. }
  4150. std::string CONFIG = cmSystemTools::UpperCase(config);
  4151. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  4152. (usage_requirements_only ?
  4153. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  4154. this->Internal->LinkInterfaceMap[CONFIG]);
  4155. // If the link interface does not depend on the head target
  4156. // then return the one we computed first.
  4157. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4158. {
  4159. return &hm.begin()->second;
  4160. }
  4161. cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget];
  4162. if(!iface.AllDone)
  4163. {
  4164. iface.AllDone = true;
  4165. iface.Multiplicity = info->Multiplicity;
  4166. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4167. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  4168. headTarget, usage_requirements_only,
  4169. iface.Libraries,
  4170. iface.HadHeadSensitiveCondition);
  4171. std::vector<std::string> deps;
  4172. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4173. this->LookupLinkItems(deps, iface.SharedDeps);
  4174. }
  4175. return &iface;
  4176. }
  4177. //----------------------------------------------------------------------------
  4178. void
  4179. cmTargetInternals::ComputeLinkInterfaceLibraries(
  4180. cmTarget const* thisTarget,
  4181. const std::string& config,
  4182. OptionalLinkInterface& iface,
  4183. cmTarget const* headTarget,
  4184. bool usage_requirements_only)
  4185. {
  4186. // Construct the property name suffix for this configuration.
  4187. std::string suffix = "_";
  4188. if(!config.empty())
  4189. {
  4190. suffix += cmSystemTools::UpperCase(config);
  4191. }
  4192. else
  4193. {
  4194. suffix += "NOCONFIG";
  4195. }
  4196. // An explicit list of interface libraries may be set for shared
  4197. // libraries and executables that export symbols.
  4198. const char* explicitLibraries = 0;
  4199. std::string linkIfaceProp;
  4200. if(thisTarget->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4201. thisTarget->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  4202. {
  4203. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4204. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4205. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  4206. }
  4207. else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  4208. thisTarget->IsExecutableWithExports())
  4209. {
  4210. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4211. // shared lib or executable.
  4212. // Lookup the per-configuration property.
  4213. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4214. linkIfaceProp += suffix;
  4215. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  4216. // If not set, try the generic property.
  4217. if(!explicitLibraries)
  4218. {
  4219. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4220. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  4221. }
  4222. }
  4223. if(explicitLibraries &&
  4224. thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4225. !this->PolicyWarnedCMP0022)
  4226. {
  4227. // Compare the explicitly set old link interface properties to the
  4228. // preferred new link interface property one and warn if different.
  4229. const char* newExplicitLibraries =
  4230. thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES");
  4231. if (newExplicitLibraries
  4232. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  4233. {
  4234. std::ostringstream w;
  4235. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4236. "Target \"" << thisTarget->GetName() << "\" has an "
  4237. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4238. linkIfaceProp << " properties."
  4239. "\n"
  4240. "INTERFACE_LINK_LIBRARIES:\n"
  4241. " " << newExplicitLibraries << "\n" <<
  4242. linkIfaceProp << ":\n"
  4243. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  4244. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4245. this->PolicyWarnedCMP0022 = true;
  4246. }
  4247. }
  4248. // There is no implicit link interface for executables or modules
  4249. // so if none was explicitly set then there is no link interface.
  4250. if(!explicitLibraries &&
  4251. (thisTarget->GetType() == cmTarget::EXECUTABLE ||
  4252. (thisTarget->GetType() == cmTarget::MODULE_LIBRARY)))
  4253. {
  4254. return;
  4255. }
  4256. iface.Exists = true;
  4257. iface.ExplicitLibraries = explicitLibraries;
  4258. if(explicitLibraries)
  4259. {
  4260. // The interface libraries have been explicitly set.
  4261. thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
  4262. headTarget, usage_requirements_only,
  4263. iface.Libraries,
  4264. iface.HadHeadSensitiveCondition);
  4265. }
  4266. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4267. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4268. // If CMP0022 is NEW then the plain tll signature sets the
  4269. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4270. // cleared the property explicitly and we should not fall back
  4271. // to the link implementation.
  4272. {
  4273. // The link implementation is the default link interface.
  4274. cmTarget::LinkImplementationLibraries const* impl =
  4275. thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
  4276. iface.Libraries.insert(iface.Libraries.end(),
  4277. impl->Libraries.begin(), impl->Libraries.end());
  4278. if(thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4279. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  4280. {
  4281. // Compare the link implementation fallback link interface to the
  4282. // preferred new link interface property and warn if different.
  4283. std::vector<cmLinkItem> ifaceLibs;
  4284. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4285. if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp))
  4286. {
  4287. bool hadHeadSensitiveConditionDummy = false;
  4288. thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4289. headTarget, usage_requirements_only,
  4290. ifaceLibs, hadHeadSensitiveConditionDummy);
  4291. }
  4292. if (ifaceLibs != iface.Libraries)
  4293. {
  4294. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4295. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4296. if(oldLibraries.empty())
  4297. { oldLibraries = "(empty)"; }
  4298. if(newLibraries.empty())
  4299. { newLibraries = "(empty)"; }
  4300. std::ostringstream w;
  4301. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4302. "Target \"" << thisTarget->GetName() << "\" has an "
  4303. "INTERFACE_LINK_LIBRARIES property. "
  4304. "This should be preferred as the source of the link interface "
  4305. "for this library but because CMP0022 is not set CMake is "
  4306. "ignoring the property and using the link implementation "
  4307. "as the link interface instead."
  4308. "\n"
  4309. "INTERFACE_LINK_LIBRARIES:\n"
  4310. " " << newLibraries << "\n"
  4311. "Link implementation:\n"
  4312. " " << oldLibraries << "\n";
  4313. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4314. this->PolicyWarnedCMP0022 = true;
  4315. }
  4316. }
  4317. }
  4318. }
  4319. //----------------------------------------------------------------------------
  4320. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  4321. const std::string& config,
  4322. OptionalLinkInterface& iface,
  4323. cmTarget const* headTarget) const
  4324. {
  4325. if(iface.ExplicitLibraries)
  4326. {
  4327. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  4328. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  4329. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  4330. {
  4331. // Shared libraries may have runtime implementation dependencies
  4332. // on other shared libraries that are not in the interface.
  4333. UNORDERED_SET<std::string> emitted;
  4334. for(std::vector<cmLinkItem>::const_iterator
  4335. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4336. {
  4337. emitted.insert(*li);
  4338. }
  4339. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  4340. {
  4341. cmTarget::LinkImplementation const* impl =
  4342. thisTarget->GetLinkImplementation(config);
  4343. for(std::vector<cmLinkImplItem>::const_iterator
  4344. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4345. {
  4346. if(emitted.insert(*li).second)
  4347. {
  4348. if(li->Target)
  4349. {
  4350. // This is a runtime dependency on another shared library.
  4351. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  4352. {
  4353. iface.SharedDeps.push_back(*li);
  4354. }
  4355. }
  4356. else
  4357. {
  4358. // TODO: Recognize shared library file names. Perhaps this
  4359. // should be moved to cmComputeLinkInformation, but that creates
  4360. // a chicken-and-egg problem since this list is needed for its
  4361. // construction.
  4362. }
  4363. }
  4364. }
  4365. }
  4366. }
  4367. }
  4368. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4369. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4370. {
  4371. // The link implementation is the default link interface.
  4372. cmTarget::LinkImplementationLibraries const*
  4373. impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
  4374. headTarget);
  4375. iface.ImplementationIsInterface = true;
  4376. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4377. }
  4378. if(thisTarget->LinkLanguagePropagatesToDependents())
  4379. {
  4380. // Targets using this archive need its language runtime libraries.
  4381. if(cmTarget::LinkImplementation const* impl =
  4382. thisTarget->GetLinkImplementation(config))
  4383. {
  4384. iface.Languages = impl->Languages;
  4385. }
  4386. }
  4387. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  4388. {
  4389. // Construct the property name suffix for this configuration.
  4390. std::string suffix = "_";
  4391. if(!config.empty())
  4392. {
  4393. suffix += cmSystemTools::UpperCase(config);
  4394. }
  4395. else
  4396. {
  4397. suffix += "NOCONFIG";
  4398. }
  4399. // How many repetitions are needed if this library has cyclic
  4400. // dependencies?
  4401. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4402. propName += suffix;
  4403. if(const char* config_reps = thisTarget->GetProperty(propName))
  4404. {
  4405. sscanf(config_reps, "%u", &iface.Multiplicity);
  4406. }
  4407. else if(const char* reps =
  4408. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4409. {
  4410. sscanf(reps, "%u", &iface.Multiplicity);
  4411. }
  4412. }
  4413. }
  4414. //----------------------------------------------------------------------------
  4415. void cmTargetInternals::AddInterfaceEntries(
  4416. cmTarget const* thisTarget, std::string const& config,
  4417. std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
  4418. {
  4419. if(cmTarget::LinkImplementationLibraries const* impl =
  4420. thisTarget->GetLinkImplementationLibraries(config))
  4421. {
  4422. for (std::vector<cmLinkImplItem>::const_iterator
  4423. it = impl->Libraries.begin(), end = impl->Libraries.end();
  4424. it != end; ++it)
  4425. {
  4426. if(it->Target)
  4427. {
  4428. std::string genex =
  4429. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  4430. cmGeneratorExpression ge(it->Backtrace);
  4431. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  4432. cge->SetEvaluateForBuildsystem(true);
  4433. entries.push_back(
  4434. new cmTargetInternals::TargetPropertyEntry(cge, *it));
  4435. }
  4436. }
  4437. }
  4438. }
  4439. //----------------------------------------------------------------------------
  4440. cmTarget::LinkImplementation const*
  4441. cmTarget::GetLinkImplementation(const std::string& config) const
  4442. {
  4443. // There is no link implementation for imported targets.
  4444. if(this->IsImported())
  4445. {
  4446. return 0;
  4447. }
  4448. // Populate the link implementation for this configuration.
  4449. std::string CONFIG = cmSystemTools::UpperCase(config);
  4450. cmTargetInternals::OptionalLinkImplementation&
  4451. impl = this->Internal->LinkImplMap[CONFIG][this];
  4452. if(!impl.LibrariesDone)
  4453. {
  4454. impl.LibrariesDone = true;
  4455. this->Internal
  4456. ->ComputeLinkImplementationLibraries(this, config, impl, this);
  4457. }
  4458. if(!impl.LanguagesDone)
  4459. {
  4460. impl.LanguagesDone = true;
  4461. this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
  4462. }
  4463. return &impl;
  4464. }
  4465. //----------------------------------------------------------------------------
  4466. cmTarget::LinkImplementationLibraries const*
  4467. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  4468. {
  4469. return this->GetLinkImplementationLibrariesInternal(config, this);
  4470. }
  4471. //----------------------------------------------------------------------------
  4472. cmTarget::LinkImplementationLibraries const*
  4473. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  4474. cmTarget const* head) const
  4475. {
  4476. // There is no link implementation for imported targets.
  4477. if(this->IsImported())
  4478. {
  4479. return 0;
  4480. }
  4481. // Populate the link implementation libraries for this configuration.
  4482. std::string CONFIG = cmSystemTools::UpperCase(config);
  4483. cmTargetInternals::HeadToLinkImplementationMap& hm =
  4484. this->Internal->LinkImplMap[CONFIG];
  4485. // If the link implementation does not depend on the head target
  4486. // then return the one we computed first.
  4487. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4488. {
  4489. return &hm.begin()->second;
  4490. }
  4491. cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
  4492. if(!impl.LibrariesDone)
  4493. {
  4494. impl.LibrariesDone = true;
  4495. this->Internal
  4496. ->ComputeLinkImplementationLibraries(this, config, impl, head);
  4497. }
  4498. return &impl;
  4499. }
  4500. //----------------------------------------------------------------------------
  4501. void
  4502. cmTargetInternals::ComputeLinkImplementationLibraries(
  4503. cmTarget const* thisTarget,
  4504. const std::string& config,
  4505. OptionalLinkImplementation& impl,
  4506. cmTarget const* head) const
  4507. {
  4508. // Collect libraries directly linked in this configuration.
  4509. for (std::vector<cmValueWithOrigin>::const_iterator
  4510. le = this->LinkImplementationPropertyEntries.begin(),
  4511. end = this->LinkImplementationPropertyEntries.end();
  4512. le != end; ++le)
  4513. {
  4514. std::vector<std::string> llibs;
  4515. cmGeneratorExpressionDAGChecker dagChecker(
  4516. thisTarget->GetName(),
  4517. "LINK_LIBRARIES", 0, 0);
  4518. cmGeneratorExpression ge(le->Backtrace);
  4519. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  4520. ge.Parse(le->Value);
  4521. std::string const evaluated =
  4522. cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker);
  4523. cmSystemTools::ExpandListArgument(evaluated, llibs);
  4524. if(cge->GetHadHeadSensitiveCondition())
  4525. {
  4526. impl.HadHeadSensitiveCondition = true;
  4527. }
  4528. for(std::vector<std::string>::const_iterator li = llibs.begin();
  4529. li != llibs.end(); ++li)
  4530. {
  4531. // Skip entries that resolve to the target itself or are empty.
  4532. std::string name = thisTarget->CheckCMP0004(*li);
  4533. if(name == thisTarget->GetName() || name.empty())
  4534. {
  4535. if(name == thisTarget->GetName())
  4536. {
  4537. bool noMessage = false;
  4538. cmake::MessageType messageType = cmake::FATAL_ERROR;
  4539. std::ostringstream e;
  4540. switch(thisTarget->GetPolicyStatusCMP0038())
  4541. {
  4542. case cmPolicies::WARN:
  4543. {
  4544. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  4545. messageType = cmake::AUTHOR_WARNING;
  4546. }
  4547. break;
  4548. case cmPolicies::OLD:
  4549. noMessage = true;
  4550. case cmPolicies::REQUIRED_IF_USED:
  4551. case cmPolicies::REQUIRED_ALWAYS:
  4552. case cmPolicies::NEW:
  4553. // Issue the fatal message.
  4554. break;
  4555. }
  4556. if(!noMessage)
  4557. {
  4558. e << "Target \"" << thisTarget->GetName() << "\" links to itself.";
  4559. thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
  4560. messageType, e.str(), thisTarget->GetBacktrace());
  4561. if (messageType == cmake::FATAL_ERROR)
  4562. {
  4563. return;
  4564. }
  4565. }
  4566. }
  4567. continue;
  4568. }
  4569. // The entry is meant for this configuration.
  4570. impl.Libraries.push_back(
  4571. cmLinkImplItem(name, thisTarget->FindTargetToLink(name),
  4572. le->Backtrace, evaluated != le->Value));
  4573. }
  4574. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  4575. for (std::set<std::string>::const_iterator it = seenProps.begin();
  4576. it != seenProps.end(); ++it)
  4577. {
  4578. if (!thisTarget->GetProperty(*it))
  4579. {
  4580. thisTarget->LinkImplicitNullProperties.insert(*it);
  4581. }
  4582. }
  4583. cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
  4584. }
  4585. cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
  4586. cmTarget::LinkLibraryVectorType const& oldllibs =
  4587. thisTarget->GetOriginalLinkLibraries();
  4588. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4589. li != oldllibs.end(); ++li)
  4590. {
  4591. if(li->second != cmTarget::GENERAL && li->second != linkType)
  4592. {
  4593. std::string name = thisTarget->CheckCMP0004(li->first);
  4594. if(name == thisTarget->GetName() || name.empty())
  4595. {
  4596. continue;
  4597. }
  4598. // Support OLD behavior for CMP0003.
  4599. impl.WrongConfigLibraries.push_back(
  4600. cmLinkItem(name, thisTarget->FindTargetToLink(name)));
  4601. }
  4602. }
  4603. }
  4604. //----------------------------------------------------------------------------
  4605. void
  4606. cmTargetInternals::ComputeLinkImplementationLanguages(
  4607. cmTarget const* thisTarget,
  4608. const std::string& config,
  4609. OptionalLinkImplementation& impl) const
  4610. {
  4611. // This target needs runtime libraries for its source languages.
  4612. std::set<std::string> languages;
  4613. // Get languages used in our source files.
  4614. thisTarget->GetLanguages(languages, config);
  4615. // Copy the set of langauges to the link implementation.
  4616. impl.Languages.insert(impl.Languages.begin(),
  4617. languages.begin(), languages.end());
  4618. }
  4619. //----------------------------------------------------------------------------
  4620. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  4621. {
  4622. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  4623. // Skip targets that will not really be linked. This is probably a
  4624. // name conflict between an external library and an executable
  4625. // within the project.
  4626. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  4627. !tgt->IsExecutableWithExports())
  4628. {
  4629. tgt = 0;
  4630. }
  4631. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  4632. {
  4633. std::ostringstream e;
  4634. e << "Target \"" << this->GetName() << "\" links to "
  4635. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  4636. "allowed. "
  4637. "One may link only to STATIC or SHARED libraries, or to executables "
  4638. "with the ENABLE_EXPORTS property set.";
  4639. cmake* cm = this->Makefile->GetCMakeInstance();
  4640. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4641. tgt = 0;
  4642. }
  4643. // Return the target found, if any.
  4644. return tgt;
  4645. }
  4646. //----------------------------------------------------------------------------
  4647. std::string cmTarget::CheckCMP0004(std::string const& item) const
  4648. {
  4649. // Strip whitespace off the library names because we used to do this
  4650. // in case variables were expanded at generate time. We no longer
  4651. // do the expansion but users link to libraries like " ${VAR} ".
  4652. std::string lib = item;
  4653. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4654. if(pos != lib.npos)
  4655. {
  4656. lib = lib.substr(pos, lib.npos);
  4657. }
  4658. pos = lib.find_last_not_of(" \t\r\n");
  4659. if(pos != lib.npos)
  4660. {
  4661. lib = lib.substr(0, pos+1);
  4662. }
  4663. if(lib != item)
  4664. {
  4665. cmake* cm = this->Makefile->GetCMakeInstance();
  4666. switch(this->GetPolicyStatusCMP0004())
  4667. {
  4668. case cmPolicies::WARN:
  4669. {
  4670. std::ostringstream w;
  4671. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  4672. << "Target \"" << this->GetName() << "\" links to item \""
  4673. << item << "\" which has leading or trailing whitespace.";
  4674. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4675. this->GetBacktrace());
  4676. }
  4677. case cmPolicies::OLD:
  4678. break;
  4679. case cmPolicies::NEW:
  4680. {
  4681. std::ostringstream e;
  4682. e << "Target \"" << this->GetName() << "\" links to item \""
  4683. << item << "\" which has leading or trailing whitespace. "
  4684. << "This is now an error according to policy CMP0004.";
  4685. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4686. }
  4687. break;
  4688. case cmPolicies::REQUIRED_IF_USED:
  4689. case cmPolicies::REQUIRED_ALWAYS:
  4690. {
  4691. std::ostringstream e;
  4692. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  4693. << "Target \"" << this->GetName() << "\" links to item \""
  4694. << item << "\" which has leading or trailing whitespace.";
  4695. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4696. }
  4697. break;
  4698. }
  4699. }
  4700. return lib;
  4701. }
  4702. //----------------------------------------------------------------------------
  4703. cmTargetInternalPointer::cmTargetInternalPointer()
  4704. {
  4705. this->Pointer = new cmTargetInternals;
  4706. }
  4707. //----------------------------------------------------------------------------
  4708. cmTargetInternalPointer
  4709. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4710. {
  4711. // Ideally cmTarget instances should never be copied. However until
  4712. // we can make a sweep to remove that, this copy constructor avoids
  4713. // allowing the resources (Internals) to be copied.
  4714. this->Pointer = new cmTargetInternals(*r.Pointer);
  4715. }
  4716. //----------------------------------------------------------------------------
  4717. cmTargetInternalPointer::~cmTargetInternalPointer()
  4718. {
  4719. cmDeleteAll(this->Pointer->IncludeDirectoriesEntries);
  4720. cmDeleteAll(this->Pointer->CompileOptionsEntries);
  4721. cmDeleteAll(this->Pointer->CompileFeaturesEntries);
  4722. cmDeleteAll(this->Pointer->CompileDefinitionsEntries);
  4723. cmDeleteAll(this->Pointer->SourceEntries);
  4724. delete this->Pointer;
  4725. }
  4726. //----------------------------------------------------------------------------
  4727. cmTargetInternalPointer&
  4728. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4729. {
  4730. if(this == &r) { return *this; } // avoid warning on HP about self check
  4731. // Ideally cmTarget instances should never be copied. However until
  4732. // we can make a sweep to remove that, this copy constructor avoids
  4733. // allowing the resources (Internals) to be copied.
  4734. cmTargetInternals* oldPointer = this->Pointer;
  4735. this->Pointer = new cmTargetInternals(*r.Pointer);
  4736. delete oldPointer;
  4737. return *this;
  4738. }