cmGeneratorTarget.cxx 174 KB

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