cmGeneratorTarget.cxx 173 KB

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