cmGeneratorTarget.cxx 170 KB

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