cmGeneratorTarget.cxx 173 KB

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