cmGeneratorTarget.cxx 181 KB

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