cmGeneratorTarget.cxx 178 KB

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