cmGeneratorTarget.cxx 176 KB

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