cmGeneratorTarget.cxx 172 KB

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