cmTarget.cxx 163 KB

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