cmGeneratorTarget.cxx 183 KB

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