cmTarget.cxx 159 KB

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