cmTarget.cxx 161 KB

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