cmTarget.cxx 192 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 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 "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmDocumentCompileDefinitions.h"
  18. #include "cmDocumentGeneratorExpressions.h"
  19. #include "cmDocumentLocationUndefined.h"
  20. #include "cmListFileCache.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorExpressionDAGChecker.h"
  23. #include <cmsys/RegularExpression.hxx>
  24. #include <map>
  25. #include <set>
  26. #include <queue>
  27. #include <stdlib.h> // required for atof
  28. #include <assert.h>
  29. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  30. {
  31. switch( targetType )
  32. {
  33. case cmTarget::STATIC_LIBRARY:
  34. return "STATIC_LIBRARY";
  35. case cmTarget::MODULE_LIBRARY:
  36. return "MODULE_LIBRARY";
  37. case cmTarget::SHARED_LIBRARY:
  38. return "SHARED_LIBRARY";
  39. case cmTarget::OBJECT_LIBRARY:
  40. return "OBJECT_LIBRARY";
  41. case cmTarget::EXECUTABLE:
  42. return "EXECUTABLE";
  43. case cmTarget::UTILITY:
  44. return "UTILITY";
  45. case cmTarget::GLOBAL_TARGET:
  46. return "GLOBAL_TARGET";
  47. case cmTarget::UNKNOWN_LIBRARY:
  48. return "UNKNOWN_LIBRARY";
  49. }
  50. assert(0 && "Unexpected target type");
  51. return 0;
  52. }
  53. //----------------------------------------------------------------------------
  54. struct cmTarget::OutputInfo
  55. {
  56. std::string OutDir;
  57. std::string ImpDir;
  58. std::string PdbDir;
  59. };
  60. //----------------------------------------------------------------------------
  61. struct cmTarget::ImportInfo
  62. {
  63. bool NoSOName;
  64. std::string Location;
  65. std::string SOName;
  66. std::string ImportLibrary;
  67. cmTarget::LinkInterface LinkInterface;
  68. };
  69. struct TargetConfigPair : public std::pair<cmTarget*, std::string> {
  70. TargetConfigPair(cmTarget* tgt, const std::string &config)
  71. : std::pair<cmTarget*, std::string>(tgt, config) {}
  72. };
  73. //----------------------------------------------------------------------------
  74. class cmTargetInternals
  75. {
  76. public:
  77. cmTargetInternals()
  78. {
  79. this->SourceFileFlagsConstructed = false;
  80. }
  81. cmTargetInternals(cmTargetInternals const& r)
  82. {
  83. this->SourceFileFlagsConstructed = false;
  84. // Only some of these entries are part of the object state.
  85. // Others not copied here are result caches.
  86. this->SourceEntries = r.SourceEntries;
  87. }
  88. typedef cmTarget::SourceFileFlags SourceFileFlags;
  89. std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  90. bool SourceFileFlagsConstructed;
  91. // The backtrace when the target was created.
  92. cmListFileBacktrace Backtrace;
  93. // Cache link interface computation from each configuration.
  94. struct OptionalLinkInterface: public cmTarget::LinkInterface
  95. {
  96. OptionalLinkInterface(): Exists(false) {}
  97. bool Exists;
  98. };
  99. typedef std::map<TargetConfigPair, OptionalLinkInterface>
  100. LinkInterfaceMapType;
  101. LinkInterfaceMapType LinkInterfaceMap;
  102. typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
  103. OutputInfoMapType OutputInfoMap;
  104. typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
  105. ImportInfoMapType;
  106. ImportInfoMapType ImportInfoMap;
  107. // Cache link implementation computation from each configuration.
  108. typedef std::map<TargetConfigPair,
  109. cmTarget::LinkImplementation> LinkImplMapType;
  110. LinkImplMapType LinkImplMap;
  111. typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
  112. LinkClosureMapType;
  113. LinkClosureMapType LinkClosureMap;
  114. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  115. typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
  116. SourceEntriesType SourceEntries;
  117. struct IncludeDirectoriesEntry {
  118. IncludeDirectoriesEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge)
  119. : ge(cge)
  120. {}
  121. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  122. };
  123. std::vector<IncludeDirectoriesEntry*> IncludeDirectoriesEntries;
  124. };
  125. //----------------------------------------------------------------------------
  126. cmTarget::cmTarget()
  127. {
  128. this->Makefile = 0;
  129. this->PolicyStatusCMP0003 = cmPolicies::WARN;
  130. this->PolicyStatusCMP0004 = cmPolicies::WARN;
  131. this->PolicyStatusCMP0008 = cmPolicies::WARN;
  132. this->LinkLibrariesAnalyzed = false;
  133. this->HaveInstallRule = false;
  134. this->DLLPlatform = false;
  135. this->IsApple = false;
  136. this->IsImportedTarget = false;
  137. }
  138. //----------------------------------------------------------------------------
  139. void cmTarget::DefineProperties(cmake *cm)
  140. {
  141. cm->DefineProperty
  142. ("AUTOMOC", cmProperty::TARGET,
  143. "Should the target be processed with automoc (for Qt projects).",
  144. "AUTOMOC is a boolean specifying whether CMake will handle "
  145. "the Qt moc preprocessor automatically, i.e. without having to use "
  146. "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. "
  147. "When this property is set to TRUE, CMake will scan the source files "
  148. "at build time and invoke moc accordingly. "
  149. "If an #include statement like #include \"moc_foo.cpp\" is found, "
  150. "the Q_OBJECT class declaration is expected in the header, and moc is "
  151. "run on the header file. "
  152. "If an #include statement like #include \"foo.moc\" is found, "
  153. "then a Q_OBJECT is expected in the current source file and moc "
  154. "is run on the file itself. "
  155. "Additionally, all header files are parsed for Q_OBJECT macros, "
  156. "and if found, moc is also executed on those files. The resulting "
  157. "moc files, which are not included as shown above in any of the source "
  158. "files are included in a generated <targetname>_automoc.cpp file, "
  159. "which is compiled as part of the target."
  160. "This property is initialized by the value of the variable "
  161. "CMAKE_AUTOMOC if it is set when a target is created.\n"
  162. "Additional command line options for moc can be set via the "
  163. "AUTOMOC_MOC_OPTIONS property.\n"
  164. "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
  165. "for searching the files which will be processed by moc can be relaxed. "
  166. "See the documentation for this variable for more details.");
  167. cm->DefineProperty
  168. ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
  169. "Additional options for moc when using automoc (see the AUTOMOC property)",
  170. "This property is only used if the AUTOMOC property is set to TRUE for "
  171. "this target. In this case, it holds additional command line options "
  172. "which will be used when moc is executed during the build, i.e. it is "
  173. "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
  174. "macro.\n"
  175. "By default it is empty.");
  176. cm->DefineProperty
  177. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  178. "Should build tree targets have install tree rpaths.",
  179. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  180. "the target in the build tree with the INSTALL_RPATH. This takes "
  181. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  182. "before installation. "
  183. "This property is initialized by the value of the variable "
  184. "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
  185. cm->DefineProperty
  186. ("COMPILE_FLAGS", cmProperty::TARGET,
  187. "Additional flags to use when compiling this target's sources.",
  188. "The COMPILE_FLAGS property sets additional compiler flags used "
  189. "to build sources within the target. Use COMPILE_DEFINITIONS "
  190. "to pass additional preprocessor definitions.");
  191. cm->DefineProperty
  192. ("COMPILE_DEFINITIONS", cmProperty::TARGET,
  193. "Preprocessor definitions for compiling a target's sources.",
  194. "The COMPILE_DEFINITIONS property may be set to a "
  195. "semicolon-separated list of preprocessor "
  196. "definitions using the syntax VAR or VAR=value. Function-style "
  197. "definitions are not supported. CMake will automatically escape "
  198. "the value correctly for the native build system (note that CMake "
  199. "language syntax may require escapes to specify some values). "
  200. "This property may be set on a per-configuration basis using the name "
  201. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  202. "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
  203. "CMake will automatically drop some definitions that "
  204. "are not supported by the native build tool. "
  205. "The VS6 IDE does not support definition values with spaces "
  206. "(but NMake does).\n"
  207. "Contents of COMPILE_DEFINITIONS may use \"generator expressions\" with "
  208. "the syntax \"$<...>\". "
  209. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
  210. CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
  211. cm->DefineProperty
  212. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
  213. "Per-configuration preprocessor definitions on a target.",
  214. "This is the configuration-specific version of COMPILE_DEFINITIONS.");
  215. cm->DefineProperty
  216. ("DEFINE_SYMBOL", cmProperty::TARGET,
  217. "Define a symbol when compiling this target's sources.",
  218. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  219. "compiling sources in a shared library. "
  220. "If not set here then it is set to target_EXPORTS by default "
  221. "(with some substitutions if the target is not a valid C "
  222. "identifier). This is useful for headers to know whether they are "
  223. "being included from inside their library our outside to properly "
  224. "setup dllexport/dllimport decorations. ");
  225. cm->DefineProperty
  226. ("DEBUG_POSTFIX", cmProperty::TARGET,
  227. "See target property <CONFIG>_POSTFIX.",
  228. "This property is a special case of the more-general <CONFIG>_POSTFIX "
  229. "property for the DEBUG configuration.");
  230. cm->DefineProperty
  231. ("<CONFIG>_POSTFIX", cmProperty::TARGET,
  232. "Postfix to append to the target file name for configuration <CONFIG>.",
  233. "When building with configuration <CONFIG> the value of this property "
  234. "is appended to the target file name built on disk. "
  235. "For non-executable targets, this property is initialized by the value "
  236. "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
  237. "created. "
  238. "This property is ignored on the Mac for Frameworks and App Bundles.");
  239. cm->DefineProperty
  240. ("EchoString", cmProperty::TARGET,
  241. "A message to be displayed when the target is built.",
  242. "A message to display on some generators (such as makefiles) when "
  243. "the target is built.");
  244. cm->DefineProperty
  245. ("BUNDLE", cmProperty::TARGET,
  246. "This target is a CFBundle on the Mac.",
  247. "If a module library target has this property set to true it will "
  248. "be built as a CFBundle when built on the mac. It will have the "
  249. "directory structure required for a CFBundle and will be suitable "
  250. "to be used for creating Browser Plugins or other application "
  251. "resources.");
  252. cm->DefineProperty
  253. ("BUNDLE_EXTENSION", cmProperty::TARGET,
  254. "The file extension used to name a BUNDLE target on the Mac.",
  255. "The default value is \"bundle\" - you can also use \"plugin\" or "
  256. "whatever file extension is required by the host app for your "
  257. "bundle.");
  258. cm->DefineProperty
  259. ("EXCLUDE_FROM_DEFAULT_BUILD", cmProperty::TARGET,
  260. "Exclude target from \"Build Solution\".",
  261. "This property is only used by Visual Studio generators 7 and above. "
  262. "When set to TRUE, the target will not be built when you press "
  263. "\"Build Solution\".");
  264. cm->DefineProperty
  265. ("EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>", cmProperty::TARGET,
  266. "Per-configuration version of target exclusion from \"Build Solution\". ",
  267. "This is the configuration-specific version of "
  268. "EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD "
  269. "is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes "
  270. "precedence in configurations for which it has a value.");
  271. cm->DefineProperty
  272. ("FRAMEWORK", cmProperty::TARGET,
  273. "This target is a framework on the Mac.",
  274. "If a shared library target has this property set to true it will "
  275. "be built as a framework when built on the mac. It will have the "
  276. "directory structure required for a framework and will be suitable "
  277. "to be used with the -framework option");
  278. cm->DefineProperty
  279. ("HAS_CXX", cmProperty::TARGET,
  280. "Link the target using the C++ linker tool (obsolete).",
  281. "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
  282. "See that property's documentation for details.");
  283. cm->DefineProperty
  284. ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
  285. "Specify #include line transforms for dependencies in a target.",
  286. "This property specifies rules to transform macro-like #include lines "
  287. "during implicit dependency scanning of C and C++ source files. "
  288. "The list of rules must be semicolon-separated with each entry of "
  289. "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
  290. "During dependency scanning occurrences of A_MACRO(...) on #include "
  291. "lines will be replaced by the value given with the macro argument "
  292. "substituted for '%'. For example, the entry\n"
  293. " MYDIR(%)=<mydir/%>\n"
  294. "will convert lines of the form\n"
  295. " #include MYDIR(myheader.h)\n"
  296. "to\n"
  297. " #include <mydir/myheader.h>\n"
  298. "allowing the dependency to be followed.\n"
  299. "This property applies to sources in the target on which it is set.");
  300. cm->DefineProperty
  301. ("IMPORT_PREFIX", cmProperty::TARGET,
  302. "What comes before the import library name.",
  303. "Similar to the target property PREFIX, but used for import libraries "
  304. "(typically corresponding to a DLL) instead of regular libraries. "
  305. "A target property that can be set to override the prefix "
  306. "(such as \"lib\") on an import library name.");
  307. cm->DefineProperty
  308. ("IMPORT_SUFFIX", cmProperty::TARGET,
  309. "What comes after the import library name.",
  310. "Similar to the target property SUFFIX, but used for import libraries "
  311. "(typically corresponding to a DLL) instead of regular libraries. "
  312. "A target property that can be set to override the suffix "
  313. "(such as \".lib\") on an import library name.");
  314. cm->DefineProperty
  315. ("IMPORTED", cmProperty::TARGET,
  316. "Read-only indication of whether a target is IMPORTED.",
  317. "The boolean value of this property is true for targets created with "
  318. "the IMPORTED option to add_executable or add_library. "
  319. "It is false for targets built within the project.");
  320. cm->DefineProperty
  321. ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
  322. "Configurations provided for an IMPORTED target.",
  323. "Set this to the list of configuration names available for an "
  324. "IMPORTED target. "
  325. "The names correspond to configurations defined in the project from "
  326. "which the target is imported. "
  327. "If the importing project uses a different set of configurations "
  328. "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
  329. "property. "
  330. "Ignored for non-imported targets.");
  331. cm->DefineProperty
  332. ("IMPORTED_IMPLIB", cmProperty::TARGET,
  333. "Full path to the import library for an IMPORTED target.",
  334. "Set this to the location of the \".lib\" part of a windows DLL. "
  335. "Ignored for non-imported targets.");
  336. cm->DefineProperty
  337. ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
  338. "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
  339. "Configuration names correspond to those provided by the project "
  340. "from which the target is imported.");
  341. cm->DefineProperty
  342. ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
  343. "Dependent shared libraries of an imported shared library.",
  344. "Shared libraries may be linked to other shared libraries as part "
  345. "of their implementation. On some platforms the linker searches "
  346. "for the dependent libraries of shared libraries they are including "
  347. "in the link. "
  348. "Set this property to the list of dependent shared libraries of an "
  349. "imported library. "
  350. "The list "
  351. "should be disjoint from the list of interface libraries in the "
  352. "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
  353. "dependent shared libraries to be found at link time CMake uses this "
  354. "list to add appropriate files or paths to the link command line. "
  355. "Ignored for non-imported targets.");
  356. cm->DefineProperty
  357. ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  358. "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
  359. "Configuration names correspond to those provided by the project "
  360. "from which the target is imported. "
  361. "If set, this property completely overrides the generic property "
  362. "for the named configuration.");
  363. cm->DefineProperty
  364. ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  365. "Transitive link interface of an IMPORTED target.",
  366. "Set this to the list of libraries whose interface is included when "
  367. "an IMPORTED library target is linked to another target. "
  368. "The libraries will be included on the link line for the target. "
  369. "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
  370. "to all imported target types, including STATIC libraries. "
  371. "This property is ignored for non-imported targets.");
  372. cm->DefineProperty
  373. ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  374. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
  375. "Configuration names correspond to those provided by the project "
  376. "from which the target is imported. "
  377. "If set, this property completely overrides the generic property "
  378. "for the named configuration.");
  379. cm->DefineProperty
  380. ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
  381. "Languages compiled into an IMPORTED static library.",
  382. "Set this to the list of languages of source files compiled to "
  383. "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). "
  384. "CMake accounts for these languages when computing how to link a "
  385. "target to the imported library. "
  386. "For example, when a C executable links to an imported C++ static "
  387. "library CMake chooses the C++ linker to satisfy language runtime "
  388. "dependencies of the static library. "
  389. "\n"
  390. "This property is ignored for targets that are not STATIC libraries. "
  391. "This property is ignored for non-imported targets.");
  392. cm->DefineProperty
  393. ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
  394. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
  395. "Configuration names correspond to those provided by the project "
  396. "from which the target is imported. "
  397. "If set, this property completely overrides the generic property "
  398. "for the named configuration.");
  399. cm->DefineProperty
  400. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  401. "Repetition count for cycles of IMPORTED static libraries.",
  402. "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
  403. cm->DefineProperty
  404. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  405. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
  406. "If set, this property completely overrides the generic property "
  407. "for the named configuration.");
  408. cm->DefineProperty
  409. ("IMPORTED_LOCATION", cmProperty::TARGET,
  410. "Full path to the main file on disk for an IMPORTED target.",
  411. "Set this to the location of an IMPORTED target file on disk. "
  412. "For executables this is the location of the executable file. "
  413. "For bundles on OS X this is the location of the executable file "
  414. "inside Contents/MacOS under the application bundle folder. "
  415. "For static libraries and modules this is the location of the "
  416. "library or module. "
  417. "For shared libraries on non-DLL platforms this is the location of "
  418. "the shared library. "
  419. "For frameworks on OS X this is the location of the library file "
  420. "symlink just inside the framework folder. "
  421. "For DLLs this is the location of the \".dll\" part of the library. "
  422. "For UNKNOWN libraries this is the location of the file to be linked. "
  423. "Ignored for non-imported targets."
  424. "\n"
  425. "Projects may skip IMPORTED_LOCATION if the configuration-specific "
  426. "property IMPORTED_LOCATION_<CONFIG> is set. "
  427. "To get the location of an imported target read one of the "
  428. "LOCATION or LOCATION_<CONFIG> properties.");
  429. cm->DefineProperty
  430. ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
  431. "<CONFIG>-specific version of IMPORTED_LOCATION property.",
  432. "Configuration names correspond to those provided by the project "
  433. "from which the target is imported.");
  434. cm->DefineProperty
  435. ("IMPORTED_SONAME", cmProperty::TARGET,
  436. "The \"soname\" of an IMPORTED target of shared library type.",
  437. "Set this to the \"soname\" embedded in an imported shared library. "
  438. "This is meaningful only on platforms supporting the feature. "
  439. "Ignored for non-imported targets.");
  440. cm->DefineProperty
  441. ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
  442. "<CONFIG>-specific version of IMPORTED_SONAME property.",
  443. "Configuration names correspond to those provided by the project "
  444. "from which the target is imported.");
  445. cm->DefineProperty
  446. ("IMPORTED_NO_SONAME", cmProperty::TARGET,
  447. "Specifies that an IMPORTED shared library target has no \"soname\". ",
  448. "Set this property to true for an imported shared library file that "
  449. "has no \"soname\" field. "
  450. "CMake may adjust generated link commands for some platforms to prevent "
  451. "the linker from using the path to the library in place of its missing "
  452. "soname. "
  453. "Ignored for non-imported targets.");
  454. cm->DefineProperty
  455. ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
  456. "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
  457. "Configuration names correspond to those provided by the project "
  458. "from which the target is imported.");
  459. cm->DefineProperty
  460. ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
  461. "Exclude the target from the all target.",
  462. "A property on a target that indicates if the target is excluded "
  463. "from the default build target. If it is not, then with a Makefile "
  464. "for example typing make will cause this target to be built. "
  465. "The same concept applies to the default build of other generators. "
  466. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  467. "undefined behavior.");
  468. cm->DefineProperty
  469. ("LINK_LIBRARIES", cmProperty::TARGET,
  470. "List of direct link dependencies.",
  471. "This property specifies the list of libraries or targets which will be "
  472. "used for linking. "
  473. "In addition to accepting values from the target_link_libraries "
  474. "command, values may be set directly on any target using the "
  475. "set_property command. "
  476. "\n"
  477. "The target property values are used by the generators to set "
  478. "the link libraries for the compiler. "
  479. "See also the target_link_libraries command.\n"
  480. "Contents of LINK_LIBRARIES may use \"generator expressions\" with "
  481. "the syntax \"$<...>\". "
  482. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  483. cm->DefineProperty
  484. ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
  485. "List of preprocessor include file search directories.",
  486. "This property specifies the list of directories given "
  487. "so far to the include_directories command. "
  488. "This property exists on directories and targets. "
  489. "In addition to accepting values from the include_directories "
  490. "command, values may be set directly on any directory or any "
  491. "target using the set_property command. "
  492. "A target gets its initial value for this property from the value "
  493. "of the directory property. "
  494. "A directory gets its initial value from its parent directory if "
  495. "it has one. "
  496. "Both directory and target property values are adjusted by calls "
  497. "to the include_directories command."
  498. "\n"
  499. "The target property values are used by the generators to set "
  500. "the include paths for the compiler. "
  501. "See also the include_directories command.\n"
  502. "Contents of INCLUDE_DIRECTORIES may use \"generator expressions\" with "
  503. "the syntax \"$<...>\". "
  504. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  505. cm->DefineProperty
  506. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  507. "Mac OSX directory name for installed targets.",
  508. "INSTALL_NAME_DIR is a string specifying the "
  509. "directory portion of the \"install_name\" field of shared libraries "
  510. "on Mac OSX to use in the installed targets. ");
  511. cm->DefineProperty
  512. ("INSTALL_RPATH", cmProperty::TARGET,
  513. "The rpath to use for installed targets.",
  514. "A semicolon-separated list specifying the rpath "
  515. "to use in installed targets (for platforms that support it). "
  516. "This property is initialized by the value of the variable "
  517. "CMAKE_INSTALL_RPATH if it is set when a target is created.");
  518. cm->DefineProperty
  519. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  520. "Add paths to linker search and installed rpath.",
  521. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  522. "append directories in the linker search path and outside the "
  523. "project to the INSTALL_RPATH. "
  524. "This property is initialized by the value of the variable "
  525. "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
  526. "created.");
  527. cm->DefineProperty
  528. ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
  529. "Enable interprocedural optimization for a target.",
  530. "If set to true, enables interprocedural optimizations "
  531. "if they are known to be supported by the compiler.");
  532. cm->DefineProperty
  533. ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
  534. "Per-configuration interprocedural optimization for a target.",
  535. "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
  536. "If set, this property overrides the generic property "
  537. "for the named configuration.");
  538. cm->DefineProperty
  539. ("LABELS", cmProperty::TARGET,
  540. "Specify a list of text labels associated with a target.",
  541. "Target label semantics are currently unspecified.");
  542. cm->DefineProperty
  543. ("LINK_FLAGS", cmProperty::TARGET,
  544. "Additional flags to use when linking this target.",
  545. "The LINK_FLAGS property can be used to add extra flags to the "
  546. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  547. "configuration <CONFIG>, "
  548. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  549. cm->DefineProperty
  550. ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
  551. "Per-configuration linker flags for a target.",
  552. "This is the configuration-specific version of LINK_FLAGS.");
  553. #define CM_LINK_SEARCH_SUMMARY \
  554. "Some linkers support switches such as -Bstatic and -Bdynamic " \
  555. "to determine whether to use static or shared libraries for -lXXX " \
  556. "options. CMake uses these options to set the link type for " \
  557. "libraries whose full paths are not known or (in some cases) are in " \
  558. "implicit link directories for the platform. "
  559. cm->DefineProperty
  560. ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
  561. "Assume the linker looks for static libraries by default.",
  562. CM_LINK_SEARCH_SUMMARY
  563. "By default the linker search type is assumed to be -Bdynamic at "
  564. "the beginning of the library list. This property switches the "
  565. "assumption to -Bstatic. It is intended for use when linking an "
  566. "executable statically (e.g. with the GNU -static option). "
  567. "See also LINK_SEARCH_END_STATIC.");
  568. cm->DefineProperty
  569. ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
  570. "End a link line such that static system libraries are used.",
  571. CM_LINK_SEARCH_SUMMARY
  572. "By default CMake adds an option at the end of the library list (if "
  573. "necessary) to set the linker search type back to its starting type. "
  574. "This property switches the final linker search type to -Bstatic "
  575. "regardless of how it started. "
  576. "See also LINK_SEARCH_START_STATIC.");
  577. cm->DefineProperty
  578. ("LINKER_LANGUAGE", cmProperty::TARGET,
  579. "Specifies language whose compiler will invoke the linker.",
  580. "For executables, shared libraries, and modules, this sets the "
  581. "language whose compiler is used to link the target "
  582. "(such as \"C\" or \"CXX\"). "
  583. "A typical value for an executable is the language of the source "
  584. "file providing the program entry point (main). "
  585. "If not set, the language with the highest linker preference "
  586. "value is the default. "
  587. "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
  588. cm->DefineProperty
  589. ("LOCATION", cmProperty::TARGET,
  590. "Read-only location of a target on disk.",
  591. "For an imported target, this read-only property returns the value of "
  592. "the LOCATION_<CONFIG> property for an unspecified configuration "
  593. "<CONFIG> provided by the target.\n"
  594. "For a non-imported target, this property is provided for compatibility "
  595. "with CMake 2.4 and below. "
  596. "It was meant to get the location of an executable target's output file "
  597. "for use in add_custom_command. "
  598. "The path may contain a build-system-specific portion that "
  599. "is replaced at build time with the configuration getting built "
  600. "(such as \"$(ConfigurationName)\" in VS). "
  601. "In CMake 2.6 and above add_custom_command automatically recognizes a "
  602. "target name in its COMMAND and DEPENDS options and computes the "
  603. "target location. "
  604. "In CMake 2.8.4 and above add_custom_command recognizes generator "
  605. "expressions to refer to target locations anywhere in the command. "
  606. "Therefore this property is not needed for creating custom commands."
  607. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  608. cm->DefineProperty
  609. ("LOCATION_<CONFIG>", cmProperty::TARGET,
  610. "Read-only property providing a target location on disk.",
  611. "A read-only property that indicates where a target's main file is "
  612. "located on disk for the configuration <CONFIG>. "
  613. "The property is defined only for library and executable targets. "
  614. "An imported target may provide a set of configurations different "
  615. "from that of the importing project. "
  616. "By default CMake looks for an exact-match but otherwise uses an "
  617. "arbitrary available configuration. "
  618. "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
  619. "configurations explicitly."
  620. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  621. cm->DefineProperty
  622. ("LINK_DEPENDS", cmProperty::TARGET,
  623. "Additional files on which a target binary depends for linking.",
  624. "Specifies a semicolon-separated list of full-paths to files on which "
  625. "the link rule for this target depends. "
  626. "The target binary will be linked if any of the named files is newer "
  627. "than it."
  628. "\n"
  629. "This property is ignored by non-Makefile generators. "
  630. "It is intended to specify dependencies on \"linker scripts\" for "
  631. "custom Makefile link rules.");
  632. cm->DefineProperty
  633. ("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
  634. "Do not depend on linked shared library files.",
  635. "Set this property to true to tell CMake generators not to add "
  636. "file-level dependencies on the shared library files linked by "
  637. "this target. "
  638. "Modification to the shared libraries will not be sufficient to "
  639. "re-link this target. "
  640. "Logical target-level dependencies will not be affected so the "
  641. "linked shared libraries will still be brought up to date before "
  642. "this target is built."
  643. "\n"
  644. "This property is initialized by the value of the variable "
  645. "CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
  646. "created.");
  647. cm->DefineProperty
  648. ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  649. "List public interface libraries for a shared library or executable.",
  650. "By default linking to a shared library target transitively "
  651. "links to targets with which the library itself was linked. "
  652. "For an executable with exports (see the ENABLE_EXPORTS property) "
  653. "no default transitive link dependencies are used. "
  654. "This property replaces the default transitive link dependencies with "
  655. "an explicit list. "
  656. "When the target is linked into another target the libraries "
  657. "listed (and recursively their link interface libraries) will be "
  658. "provided to the other target also. "
  659. "If the list is empty then no transitive link dependencies will be "
  660. "incorporated when this target is linked into another target even if "
  661. "the default set is non-empty. "
  662. "This property is initialized by the value of the variable "
  663. "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
  664. "created. "
  665. "This property is ignored for STATIC libraries.");
  666. cm->DefineProperty
  667. ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  668. "Per-configuration list of public interface libraries for a target.",
  669. "This is the configuration-specific version of "
  670. "LINK_INTERFACE_LIBRARIES. "
  671. "If set, this property completely overrides the generic property "
  672. "for the named configuration.");
  673. cm->DefineProperty
  674. ("INTERFACE_INCLUDE_DIRECTORIES", cmProperty::TARGET,
  675. "List of public include directories for a library.",
  676. "Targets may populate this property to publish the include directories "
  677. "required to compile against the headers for the target. Consuming "
  678. "targets can add entries to their own INCLUDE_DIRECTORIES property such "
  679. "as $<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES> to use the "
  680. "include directories specified in the interface of 'foo'."
  681. "\n"
  682. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  683. cm->DefineProperty
  684. ("INTERFACE_COMPILE_DEFINITIONS", cmProperty::TARGET,
  685. "List of public compile definitions for a library.",
  686. "Targets may populate this property to publish the compile definitions "
  687. "required to compile against the headers for the target. Consuming "
  688. "targets can add entries to their own COMPILE_DEFINITIONS property such "
  689. "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS> to use the "
  690. "compile definitions specified in the interface of 'foo'."
  691. "\n"
  692. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  693. cm->DefineProperty
  694. ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  695. "Repetition count for STATIC libraries with cyclic dependencies.",
  696. "When linking to a STATIC library target with cyclic dependencies the "
  697. "linker may need to scan more than once through the archives in the "
  698. "strongly connected component of the dependency graph. "
  699. "CMake by default constructs the link line so that the linker will "
  700. "scan through the component at least twice. "
  701. "This property specifies the minimum number of scans if it is larger "
  702. "than the default. "
  703. "CMake uses the largest value specified by any target in a component.");
  704. cm->DefineProperty
  705. ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  706. "Per-configuration repetition count for cycles of STATIC libraries.",
  707. "This is the configuration-specific version of "
  708. "LINK_INTERFACE_MULTIPLICITY. "
  709. "If set, this property completely overrides the generic property "
  710. "for the named configuration.");
  711. cm->DefineProperty
  712. ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
  713. "Map from project configuration to IMPORTED target's configuration.",
  714. "Set this to the list of configurations of an imported target that "
  715. "may be used for the current project's <CONFIG> configuration. "
  716. "Targets imported from another project may not provide the same set "
  717. "of configuration names available in the current project. "
  718. "Setting this property tells CMake what imported configurations are "
  719. "suitable for use when building the <CONFIG> configuration. "
  720. "The first configuration in the list found to be provided by the "
  721. "imported target is selected. If this property is set and no matching "
  722. "configurations are available, then the imported target is considered "
  723. "to be not found. This property is ignored for non-imported targets.",
  724. false /* TODO: make this chained */ );
  725. cm->DefineProperty
  726. ("OSX_ARCHITECTURES", cmProperty::TARGET,
  727. "Target specific architectures for OS X.",
  728. "The OSX_ARCHITECTURES property sets the target binary architecture "
  729. "for targets on OS X. "
  730. "This property is initialized by the value of the variable "
  731. "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
  732. "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
  733. "per-configuration basis. "
  734. "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
  735. cm->DefineProperty
  736. ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
  737. "Per-configuration OS X binary architectures for a target.",
  738. "This property is the configuration-specific version of "
  739. "OSX_ARCHITECTURES.");
  740. cm->DefineProperty
  741. ("OUTPUT_NAME", cmProperty::TARGET,
  742. "Output name for target files.",
  743. "This sets the base name for output files created for an executable or "
  744. "library target. "
  745. "If not set, the logical target name is used by default.");
  746. cm->DefineProperty
  747. ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  748. "Per-configuration target file base name.",
  749. "This is the configuration-specific version of OUTPUT_NAME.");
  750. cm->DefineProperty
  751. ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
  752. "Old per-configuration target file base name.",
  753. "This is a configuration-specific version of OUTPUT_NAME. "
  754. "Use OUTPUT_NAME_<CONFIG> instead.");
  755. cm->DefineProperty
  756. ("PDB_NAME", cmProperty::TARGET,
  757. "Output name for MS debug symbols .pdb file.",
  758. "Set the base name for debug symbols file created for an "
  759. "executable or library target. "
  760. "If not set, the logical target name is used by default. "
  761. "\n"
  762. "This property is not implemented by the Visual Studio 6 generator.");
  763. cm->DefineProperty
  764. ("PDB_NAME_<CONFIG>", cmProperty::TARGET,
  765. "Per-configuration name for MS debug symbols .pdb file. ",
  766. "This is the configuration-specific version of PDB_NAME. "
  767. "\n"
  768. "This property is not implemented by the Visual Studio 6 generator.");
  769. cm->DefineProperty
  770. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  771. "Deprecated install support.",
  772. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  773. "old way to specify CMake scripts to run before and after "
  774. "installing a target. They are used only when the old "
  775. "INSTALL_TARGETS command is used to install the target. Use the "
  776. "INSTALL command instead.");
  777. cm->DefineProperty
  778. ("PREFIX", cmProperty::TARGET,
  779. "What comes before the library name.",
  780. "A target property that can be set to override the prefix "
  781. "(such as \"lib\") on a library name.");
  782. cm->DefineProperty
  783. ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  784. "Whether to create a position-independent target",
  785. "The POSITION_INDEPENDENT_CODE property determines whether position "
  786. "independent executables or shared libraries will be created. "
  787. "This property is true by default for SHARED and MODULE library "
  788. "targets and false otherwise. "
  789. "This property is initialized by the value of the variable "
  790. "CMAKE_POSITION_INDEPENDENT_CODE if it is set when a target is "
  791. "created.");
  792. cm->DefineProperty
  793. ("INTERFACE_POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  794. "Whether consumers need to create a position-independent target",
  795. "The INTERFACE_POSITION_INDEPENDENT_CODE property informs consumers of "
  796. "this target whether they must set their POSITION_INDEPENDENT_CODE "
  797. "property to ON. If this property is set to ON, then the "
  798. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  799. "ON. Similarly, if this property is set to OFF, then the "
  800. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  801. "OFF. If this property is undefined, then consumers will determine "
  802. "their POSITION_INDEPENDENT_CODE property by other means. Consumers "
  803. "must ensure that the targets that they link to have a consistent "
  804. "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property.");
  805. cm->DefineProperty
  806. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  807. "Deprecated install support.",
  808. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  809. "old way to specify CMake scripts to run before and after "
  810. "installing a target. They are used only when the old "
  811. "INSTALL_TARGETS command is used to install the target. Use the "
  812. "INSTALL command instead.");
  813. cm->DefineProperty
  814. ("PRIVATE_HEADER", cmProperty::TARGET,
  815. "Specify private header files in a FRAMEWORK shared library target.",
  816. "Shared library targets marked with the FRAMEWORK property generate "
  817. "frameworks on OS X and normal shared libraries on other platforms. "
  818. "This property may be set to a list of header files to be placed "
  819. "in the PrivateHeaders directory inside the framework folder. "
  820. "On non-Apple platforms these headers may be installed using the "
  821. "PRIVATE_HEADER option to the install(TARGETS) command.");
  822. cm->DefineProperty
  823. ("PUBLIC_HEADER", cmProperty::TARGET,
  824. "Specify public header files in a FRAMEWORK shared library target.",
  825. "Shared library targets marked with the FRAMEWORK property generate "
  826. "frameworks on OS X and normal shared libraries on other platforms. "
  827. "This property may be set to a list of header files to be placed "
  828. "in the Headers directory inside the framework folder. "
  829. "On non-Apple platforms these headers may be installed using the "
  830. "PUBLIC_HEADER option to the install(TARGETS) command.");
  831. cm->DefineProperty
  832. ("RESOURCE", cmProperty::TARGET,
  833. "Specify resource files in a FRAMEWORK shared library target.",
  834. "Shared library targets marked with the FRAMEWORK property generate "
  835. "frameworks on OS X and normal shared libraries on other platforms. "
  836. "This property may be set to a list of files to be placed "
  837. "in the Resources directory inside the framework folder. "
  838. "On non-Apple platforms these files may be installed using the "
  839. "RESOURCE option to the install(TARGETS) command.");
  840. cm->DefineProperty
  841. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  842. "Specify a launcher for compile rules.",
  843. "See the global property of the same name for details. "
  844. "This overrides the global and directory property for a target.",
  845. true);
  846. cm->DefineProperty
  847. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  848. "Specify a launcher for link rules.",
  849. "See the global property of the same name for details. "
  850. "This overrides the global and directory property for a target.",
  851. true);
  852. cm->DefineProperty
  853. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  854. "Specify a launcher for custom rules.",
  855. "See the global property of the same name for details. "
  856. "This overrides the global and directory property for a target.",
  857. true);
  858. cm->DefineProperty
  859. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  860. "Should rpaths be used for the build tree.",
  861. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  862. "generation of an rpath allowing the target to run from the "
  863. "build tree. "
  864. "This property is initialized by the value of the variable "
  865. "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
  866. cm->DefineProperty
  867. ("NO_SONAME", cmProperty::TARGET,
  868. "Whether to set \"soname\" when linking a shared library or module.",
  869. "Enable this boolean property if a generated shared library or module "
  870. "should not have \"soname\" set. Default is to set \"soname\" on all "
  871. "shared libraries and modules as long as the platform supports it. "
  872. "Generally, use this property only for leaf private libraries or "
  873. "plugins. If you use it on normal shared libraries which other targets "
  874. "link against, on some platforms a linker will insert a full path to "
  875. "the library (as specified at link time) into the dynamic section of "
  876. "the dependent binary. Therefore, once installed, dynamic loader may "
  877. "eventually fail to locate the library for the binary.");
  878. cm->DefineProperty
  879. ("SOVERSION", cmProperty::TARGET,
  880. "What version number is this target.",
  881. "For shared libraries VERSION and SOVERSION can be used to specify "
  882. "the build version and api version respectively. When building or "
  883. "installing appropriate symlinks are created if the platform "
  884. "supports symlinks and the linker supports so-names. "
  885. "If only one of both is specified the missing is assumed to have "
  886. "the same version number. "
  887. "SOVERSION is ignored if NO_SONAME property is set. "
  888. "For shared libraries and executables on Windows the VERSION "
  889. "attribute is parsed to extract a \"major.minor\" version number. "
  890. "These numbers are used as the image version of the binary. ");
  891. cm->DefineProperty
  892. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  893. "Extra flags to use when linking static libraries.",
  894. "Extra flags to use when linking a static library.");
  895. cm->DefineProperty
  896. ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
  897. "Per-configuration flags for creating a static library.",
  898. "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
  899. cm->DefineProperty
  900. ("SUFFIX", cmProperty::TARGET,
  901. "What comes after the target name.",
  902. "A target property that can be set to override the suffix "
  903. "(such as \".so\" or \".exe\") on the name of a library, module or "
  904. "executable.");
  905. cm->DefineProperty
  906. ("TYPE", cmProperty::TARGET,
  907. "The type of the target.",
  908. "This read-only property can be used to test the type of the given "
  909. "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
  910. "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
  911. cm->DefineProperty
  912. ("VERSION", cmProperty::TARGET,
  913. "What version number is this target.",
  914. "For shared libraries VERSION and SOVERSION can be used to specify "
  915. "the build version and api version respectively. When building or "
  916. "installing appropriate symlinks are created if the platform "
  917. "supports symlinks and the linker supports so-names. "
  918. "If only one of both is specified the missing is assumed to have "
  919. "the same version number. "
  920. "For executables VERSION can be used to specify the build version. "
  921. "When building or installing appropriate symlinks are created if "
  922. "the platform supports symlinks. "
  923. "For shared libraries and executables on Windows the VERSION "
  924. "attribute is parsed to extract a \"major.minor\" version number. "
  925. "These numbers are used as the image version of the binary. ");
  926. cm->DefineProperty
  927. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  928. "Build an executable with a WinMain entry point on windows.",
  929. "When this property is set to true the executable when linked "
  930. "on Windows will be created with a WinMain() entry point instead "
  931. "of just main(). "
  932. "This makes it a GUI executable instead of a console application. "
  933. "See the CMAKE_MFC_FLAG variable documentation to configure use "
  934. "of MFC for WinMain executables. "
  935. "This property is initialized by the value of the variable "
  936. "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
  937. cm->DefineProperty
  938. ("MACOSX_BUNDLE", cmProperty::TARGET,
  939. "Build an executable as an application bundle on Mac OS X.",
  940. "When this property is set to true the executable when built "
  941. "on Mac OS X will be created as an application bundle. "
  942. "This makes it a GUI executable that can be launched from "
  943. "the Finder. "
  944. "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
  945. "about creation of the Info.plist file for the application bundle. "
  946. "This property is initialized by the value of the variable "
  947. "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
  948. cm->DefineProperty
  949. ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
  950. "Specify a custom Info.plist template for a Mac OS X App Bundle.",
  951. "An executable target with MACOSX_BUNDLE enabled will be built as an "
  952. "application bundle on Mac OS X. "
  953. "By default its Info.plist file is created by configuring a template "
  954. "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
  955. "This property specifies an alternative template file name which "
  956. "may be a full path.\n"
  957. "The following target properties may be set to specify content to "
  958. "be configured into the file:\n"
  959. " MACOSX_BUNDLE_INFO_STRING\n"
  960. " MACOSX_BUNDLE_ICON_FILE\n"
  961. " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
  962. " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
  963. " MACOSX_BUNDLE_BUNDLE_NAME\n"
  964. " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
  965. " MACOSX_BUNDLE_BUNDLE_VERSION\n"
  966. " MACOSX_BUNDLE_COPYRIGHT\n"
  967. "CMake variables of the same name may be set to affect all targets "
  968. "in a directory that do not have each specific property set. "
  969. "If a custom Info.plist is specified by this property it may of course "
  970. "hard-code all the settings instead of using the target properties.");
  971. cm->DefineProperty
  972. ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
  973. "Specify a custom Info.plist template for a Mac OS X Framework.",
  974. "An library target with FRAMEWORK enabled will be built as a "
  975. "framework on Mac OS X. "
  976. "By default its Info.plist file is created by configuring a template "
  977. "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
  978. "This property specifies an alternative template file name which "
  979. "may be a full path.\n"
  980. "The following target properties may be set to specify content to "
  981. "be configured into the file:\n"
  982. " MACOSX_FRAMEWORK_ICON_FILE\n"
  983. " MACOSX_FRAMEWORK_IDENTIFIER\n"
  984. " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
  985. " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
  986. "CMake variables of the same name may be set to affect all targets "
  987. "in a directory that do not have each specific property set. "
  988. "If a custom Info.plist is specified by this property it may of course "
  989. "hard-code all the settings instead of using the target properties.");
  990. cm->DefineProperty
  991. ("ENABLE_EXPORTS", cmProperty::TARGET,
  992. "Specify whether an executable exports symbols for loadable modules.",
  993. "Normally an executable does not export any symbols because it is "
  994. "the final program. It is possible for an executable to export "
  995. "symbols to be used by loadable modules. When this property is "
  996. "set to true CMake will allow other targets to \"link\" to the "
  997. "executable with the TARGET_LINK_LIBRARIES command. "
  998. "On all platforms a target-level dependency on the executable is "
  999. "created for targets that link to it. "
  1000. "For DLL platforms an import library will be created for the "
  1001. "exported symbols and then used for linking. "
  1002. "All Windows-based systems including Cygwin are DLL platforms. "
  1003. "For non-DLL platforms that require all symbols to be resolved at "
  1004. "link time, such as Mac OS X, the module will \"link\" to the "
  1005. "executable using a flag like \"-bundle_loader\". "
  1006. "For other non-DLL platforms the link rule is simply ignored since "
  1007. "the dynamic loader will automatically bind symbols when the "
  1008. "module is loaded. "
  1009. );
  1010. cm->DefineProperty
  1011. ("Fortran_FORMAT", cmProperty::TARGET,
  1012. "Set to FIXED or FREE to indicate the Fortran source layout.",
  1013. "This property tells CMake whether the Fortran source files "
  1014. "in a target use fixed-format or free-format. "
  1015. "CMake will pass the corresponding format flag to the compiler. "
  1016. "Use the source-specific Fortran_FORMAT property to change the "
  1017. "format of a specific source file. "
  1018. "If the variable CMAKE_Fortran_FORMAT is set when a target "
  1019. "is created its value is used to initialize this property.");
  1020. cm->DefineProperty
  1021. ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
  1022. "Specify output directory for Fortran modules provided by the target.",
  1023. "If the target contains Fortran source files that provide modules "
  1024. "and the compiler supports a module output directory this specifies "
  1025. "the directory in which the modules will be placed. "
  1026. "When this property is not set the modules will be placed in the "
  1027. "build directory corresponding to the target's source directory. "
  1028. "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
  1029. "is created its value is used to initialize this property."
  1030. "\n"
  1031. "Note that some compilers will automatically search the module output "
  1032. "directory for modules USEd during compilation but others will not. "
  1033. "If your sources USE modules their location must be specified by "
  1034. "INCLUDE_DIRECTORIES regardless of this property.");
  1035. cm->DefineProperty
  1036. ("GNUtoMS", cmProperty::TARGET,
  1037. "Convert GNU import library (.dll.a) to MS format (.lib).",
  1038. "When linking a shared library or executable that exports symbols "
  1039. "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
  1040. "convert the import library (.dll.a) from GNU to MS format (.lib). "
  1041. "Both import libraries will be installed by install(TARGETS) and "
  1042. "exported by install(EXPORT) and export() to be linked by applications "
  1043. "with either GNU- or MS-compatible tools."
  1044. "\n"
  1045. "If the variable CMAKE_GNUtoMS is set when a target "
  1046. "is created its value is used to initialize this property. "
  1047. "The variable must be set prior to the first command that enables "
  1048. "a language such as project() or enable_language(). "
  1049. "CMake provides the variable as an option to the user automatically "
  1050. "when configuring on Windows with GNU tools.");
  1051. cm->DefineProperty
  1052. ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
  1053. "Set Xcode target attributes directly.",
  1054. "Tell the Xcode generator to set '<an-attribute>' to a given value "
  1055. "in the generated Xcode project. Ignored on other generators.");
  1056. cm->DefineProperty
  1057. ("GENERATOR_FILE_NAME", cmProperty::TARGET,
  1058. "Generator's file for this target.",
  1059. "An internal property used by some generators to record the name of "
  1060. "project or dsp file associated with this target.");
  1061. cm->DefineProperty
  1062. ("SOURCES", cmProperty::TARGET,
  1063. "Source names specified for a target.",
  1064. "Read-only list of sources specified for a target. "
  1065. "The names returned are suitable for passing to the "
  1066. "set_source_files_properties command.");
  1067. cm->DefineProperty
  1068. ("FOLDER", cmProperty::TARGET,
  1069. "Set the folder name. Use to organize targets in an IDE.",
  1070. "Targets with no FOLDER property will appear as top level "
  1071. "entities in IDEs like Visual Studio. Targets with the same "
  1072. "FOLDER property value will appear next to each other in a "
  1073. "folder of that name. To nest folders, use FOLDER values such "
  1074. "as 'GUI/Dialogs' with '/' characters separating folder levels.");
  1075. cm->DefineProperty
  1076. ("PROJECT_LABEL", cmProperty::TARGET,
  1077. "Change the name of a target in an IDE.",
  1078. "Can be used to change the name of the target in an IDE "
  1079. "like Visual Studio. ");
  1080. cm->DefineProperty
  1081. ("VS_KEYWORD", cmProperty::TARGET,
  1082. "Visual Studio project keyword.",
  1083. "Can be set to change the visual studio keyword, for example "
  1084. "Qt integration works better if this is set to Qt4VSv1.0. ");
  1085. cm->DefineProperty
  1086. ("VS_SCC_PROVIDER", cmProperty::TARGET,
  1087. "Visual Studio Source Code Control Provider.",
  1088. "Can be set to change the visual studio source code control "
  1089. "provider property.");
  1090. cm->DefineProperty
  1091. ("VS_SCC_LOCALPATH", cmProperty::TARGET,
  1092. "Visual Studio Source Code Control Local Path.",
  1093. "Can be set to change the visual studio source code control "
  1094. "local path property.");
  1095. cm->DefineProperty
  1096. ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
  1097. "Visual Studio Source Code Control Project.",
  1098. "Can be set to change the visual studio source code control "
  1099. "project name property.");
  1100. cm->DefineProperty
  1101. ("VS_SCC_AUXPATH", cmProperty::TARGET,
  1102. "Visual Studio Source Code Control Aux Path.",
  1103. "Can be set to change the visual studio source code control "
  1104. "auxpath property.");
  1105. cm->DefineProperty
  1106. ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
  1107. "Visual Studio project type(s).",
  1108. "Can be set to one or more UUIDs recognized by Visual Studio "
  1109. "to indicate the type of project. This value is copied "
  1110. "verbatim into the generated project file. Example for a "
  1111. "managed C++ unit testing project:\n"
  1112. " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
  1113. "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
  1114. "UUIDs are semicolon-delimited.");
  1115. cm->DefineProperty
  1116. ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
  1117. "Visual Studio project keyword.",
  1118. "Sets the \"keyword\" attribute for a generated Visual Studio "
  1119. "project. Defaults to \"Win32Proj\". You may wish to override "
  1120. "this value with \"ManagedCProj\", for example, in a Visual "
  1121. "Studio managed C++ unit test project.");
  1122. cm->DefineProperty
  1123. ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
  1124. "Visual Studio managed project .NET references",
  1125. "Adds one or more semicolon-delimited .NET references to a "
  1126. "generated Visual Studio project. For example, \"System;"
  1127. "System.Windows.Forms\".");
  1128. cm->DefineProperty
  1129. ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
  1130. "Visual Studio project C++/CX language extensions for Windows Runtime",
  1131. "Can be set to enable C++/CX language extensions.");
  1132. cm->DefineProperty
  1133. ("VS_WINRT_REFERENCES", cmProperty::TARGET,
  1134. "Visual Studio project Windows Runtime Metadata references",
  1135. "Adds one or more semicolon-delimited WinRT references to a "
  1136. "generated Visual Studio project. For example, \"Windows;"
  1137. "Windows.UI.Core\".");
  1138. cm->DefineProperty
  1139. ("VS_GLOBAL_<variable>", cmProperty::TARGET,
  1140. "Visual Studio project-specific global variable.",
  1141. "Tell the Visual Studio generator to set the global variable "
  1142. "'<variable>' to a given value in the generated Visual Studio "
  1143. "project. Ignored on other generators. Qt integration works "
  1144. "better if VS_GLOBAL_QtVersion is set to the version "
  1145. "FindQt4.cmake found. For example, \"4.7.3\"");
  1146. #define CM_TARGET_FILE_TYPES_DOC \
  1147. "There are three kinds of target files that may be built: " \
  1148. "archive, library, and runtime. " \
  1149. "Executables are always treated as runtime targets. " \
  1150. "Static libraries are always treated as archive targets. " \
  1151. "Module libraries are always treated as library targets. " \
  1152. "For non-DLL platforms shared libraries are treated as library " \
  1153. "targets. " \
  1154. "For DLL platforms the DLL part of a shared library is treated as " \
  1155. "a runtime target and the corresponding import library is treated as " \
  1156. "an archive target. " \
  1157. "All Windows-based systems including Cygwin are DLL platforms."
  1158. #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
  1159. "This property specifies the directory into which " #type " target " \
  1160. "files should be built. " \
  1161. "Multi-configuration generators (VS, Xcode) append " \
  1162. "a per-configuration subdirectory to the specified directory. " \
  1163. CM_TARGET_FILE_TYPES_DOC " " \
  1164. "This property is initialized by the value of the variable " \
  1165. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
  1166. #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
  1167. "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
  1168. "but multi-configuration generators (VS, Xcode) do NOT append " \
  1169. "a per-configuration subdirectory to the specified directory. " \
  1170. "This property is initialized by the value of the variable " \
  1171. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
  1172. "if it is set when a target is created."
  1173. cm->DefineProperty
  1174. ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1175. "Output directory in which to build ARCHIVE target files.",
  1176. CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
  1177. cm->DefineProperty
  1178. ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1179. "Per-configuration output directory for ARCHIVE target files.",
  1180. CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
  1181. cm->DefineProperty
  1182. ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1183. "Output directory in which to build LIBRARY target files.",
  1184. CM_TARGET_OUTDIR_DOC(LIBRARY, library));
  1185. cm->DefineProperty
  1186. ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1187. "Per-configuration output directory for LIBRARY target files.",
  1188. CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
  1189. cm->DefineProperty
  1190. ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1191. "Output directory in which to build RUNTIME target files.",
  1192. CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
  1193. cm->DefineProperty
  1194. ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1195. "Per-configuration output directory for RUNTIME target files.",
  1196. CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
  1197. cm->DefineProperty
  1198. ("PDB_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1199. "Output directory for MS debug symbols .pdb files.",
  1200. "This property specifies the directory into which the MS debug symbols "
  1201. "will be placed. "
  1202. "This property is initialized by the value of the variable "
  1203. "CMAKE_PDB_OUTPUT_DIRECTORY if it is set when a target is created."
  1204. "\n"
  1205. "This property is not implemented by the Visual Studio 6 generator.");
  1206. cm->DefineProperty
  1207. ("PDB_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1208. "Per-configuration output directory for MS debug symbols .pdb files.",
  1209. "This is a per-configuration version of PDB_OUTPUT_DIRECTORY, "
  1210. "but multi-configuration generators (VS, Xcode) do NOT append "
  1211. "a per-configuration subdirectory to the specified directory. "
  1212. "This property is initialized by the value of the variable "
  1213. "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG> "
  1214. "if it is set when a target is created."
  1215. "\n"
  1216. "This property is not implemented by the Visual Studio 6 generator.");
  1217. cm->DefineProperty
  1218. ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
  1219. "Output name for ARCHIVE target files.",
  1220. "This property specifies the base name for archive target files. "
  1221. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1222. CM_TARGET_FILE_TYPES_DOC);
  1223. cm->DefineProperty
  1224. ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1225. "Per-configuration output name for ARCHIVE target files.",
  1226. "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
  1227. cm->DefineProperty
  1228. ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
  1229. "Output name for LIBRARY target files.",
  1230. "This property specifies the base name for library target files. "
  1231. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1232. CM_TARGET_FILE_TYPES_DOC);
  1233. cm->DefineProperty
  1234. ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1235. "Per-configuration output name for LIBRARY target files.",
  1236. "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
  1237. cm->DefineProperty
  1238. ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
  1239. "Output name for RUNTIME target files.",
  1240. "This property specifies the base name for runtime target files. "
  1241. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1242. CM_TARGET_FILE_TYPES_DOC);
  1243. cm->DefineProperty
  1244. ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1245. "Per-configuration output name for RUNTIME target files.",
  1246. "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
  1247. }
  1248. void cmTarget::SetType(TargetType type, const char* name)
  1249. {
  1250. this->Name = name;
  1251. // only add dependency information for library targets
  1252. this->TargetTypeValue = type;
  1253. if(this->TargetTypeValue >= STATIC_LIBRARY
  1254. && this->TargetTypeValue <= MODULE_LIBRARY)
  1255. {
  1256. this->RecordDependencies = true;
  1257. }
  1258. else
  1259. {
  1260. this->RecordDependencies = false;
  1261. }
  1262. }
  1263. //----------------------------------------------------------------------------
  1264. void cmTarget::SetMakefile(cmMakefile* mf)
  1265. {
  1266. // Set our makefile.
  1267. this->Makefile = mf;
  1268. // set the cmake instance of the properties
  1269. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  1270. // Check whether this is a DLL platform.
  1271. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  1272. this->Makefile->IsOn("CYGWIN") ||
  1273. this->Makefile->IsOn("MINGW"));
  1274. // Check whether we are targeting an Apple platform.
  1275. this->IsApple = this->Makefile->IsOn("APPLE");
  1276. // Setup default property values.
  1277. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  1278. this->SetPropertyDefault("INSTALL_RPATH", "");
  1279. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  1280. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  1281. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  1282. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  1283. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  1284. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  1285. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  1286. this->SetPropertyDefault("Fortran_FORMAT", 0);
  1287. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  1288. this->SetPropertyDefault("GNUtoMS", 0);
  1289. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  1290. this->SetPropertyDefault("AUTOMOC", 0);
  1291. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  1292. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  1293. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  1294. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  1295. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  1296. // Collect the set of configuration types.
  1297. std::vector<std::string> configNames;
  1298. mf->GetConfigurations(configNames);
  1299. // Setup per-configuration property default values.
  1300. const char* configProps[] = {
  1301. "ARCHIVE_OUTPUT_DIRECTORY_",
  1302. "LIBRARY_OUTPUT_DIRECTORY_",
  1303. "RUNTIME_OUTPUT_DIRECTORY_",
  1304. "PDB_OUTPUT_DIRECTORY_",
  1305. 0};
  1306. for(std::vector<std::string>::iterator ci = configNames.begin();
  1307. ci != configNames.end(); ++ci)
  1308. {
  1309. std::string configUpper = cmSystemTools::UpperCase(*ci);
  1310. for(const char** p = configProps; *p; ++p)
  1311. {
  1312. std::string property = *p;
  1313. property += configUpper;
  1314. this->SetPropertyDefault(property.c_str(), 0);
  1315. }
  1316. // Initialize per-configuration name postfix property from the
  1317. // variable only for non-executable targets. This preserves
  1318. // compatibility with previous CMake versions in which executables
  1319. // did not support this variable. Projects may still specify the
  1320. // property directly. TODO: Make this depend on backwards
  1321. // compatibility setting.
  1322. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  1323. {
  1324. std::string property = cmSystemTools::UpperCase(*ci);
  1325. property += "_POSTFIX";
  1326. this->SetPropertyDefault(property.c_str(), 0);
  1327. }
  1328. }
  1329. // Save the backtrace of target construction.
  1330. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  1331. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  1332. // of the same directory property:
  1333. const std::vector<cmMakefileIncludeDirectoriesEntry> parentIncludes =
  1334. this->Makefile->GetIncludeDirectoriesEntries();
  1335. for (std::vector<cmMakefileIncludeDirectoriesEntry>::const_iterator it
  1336. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  1337. {
  1338. this->InsertInclude(*it);
  1339. }
  1340. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  1341. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  1342. {
  1343. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  1344. }
  1345. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  1346. // Record current policies for later use.
  1347. this->PolicyStatusCMP0003 =
  1348. this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
  1349. this->PolicyStatusCMP0004 =
  1350. this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
  1351. this->PolicyStatusCMP0008 =
  1352. this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
  1353. }
  1354. //----------------------------------------------------------------------------
  1355. void cmTarget::FinishConfigure()
  1356. {
  1357. // Erase any cached link information that might have been comptued
  1358. // on-demand during the configuration. This ensures that build
  1359. // system generation uses up-to-date information even if other cache
  1360. // invalidation code in this source file is buggy.
  1361. this->ClearLinkMaps();
  1362. // Do old-style link dependency analysis.
  1363. this->AnalyzeLibDependencies(*this->Makefile);
  1364. }
  1365. //----------------------------------------------------------------------------
  1366. void cmTarget::ClearLinkMaps()
  1367. {
  1368. this->Internal->LinkImplMap.clear();
  1369. this->Internal->LinkInterfaceMap.clear();
  1370. this->Internal->LinkClosureMap.clear();
  1371. }
  1372. //----------------------------------------------------------------------------
  1373. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  1374. {
  1375. return this->Internal->Backtrace;
  1376. }
  1377. //----------------------------------------------------------------------------
  1378. std::string cmTarget::GetSupportDirectory() const
  1379. {
  1380. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1381. dir += cmake::GetCMakeFilesDirectory();
  1382. dir += "/";
  1383. dir += this->Name;
  1384. #if defined(__VMS)
  1385. dir += "_dir";
  1386. #else
  1387. dir += ".dir";
  1388. #endif
  1389. return dir;
  1390. }
  1391. //----------------------------------------------------------------------------
  1392. bool cmTarget::IsExecutableWithExports()
  1393. {
  1394. return (this->GetType() == cmTarget::EXECUTABLE &&
  1395. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1396. }
  1397. //----------------------------------------------------------------------------
  1398. bool cmTarget::IsLinkable()
  1399. {
  1400. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  1401. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1402. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1403. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  1404. this->IsExecutableWithExports());
  1405. }
  1406. //----------------------------------------------------------------------------
  1407. bool cmTarget::HasImportLibrary()
  1408. {
  1409. return (this->DLLPlatform &&
  1410. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  1411. this->IsExecutableWithExports()));
  1412. }
  1413. //----------------------------------------------------------------------------
  1414. bool cmTarget::IsFrameworkOnApple()
  1415. {
  1416. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  1417. this->Makefile->IsOn("APPLE") &&
  1418. this->GetPropertyAsBool("FRAMEWORK"));
  1419. }
  1420. //----------------------------------------------------------------------------
  1421. bool cmTarget::IsAppBundleOnApple()
  1422. {
  1423. return (this->GetType() == cmTarget::EXECUTABLE &&
  1424. this->Makefile->IsOn("APPLE") &&
  1425. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  1426. }
  1427. //----------------------------------------------------------------------------
  1428. bool cmTarget::IsCFBundleOnApple()
  1429. {
  1430. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  1431. this->Makefile->IsOn("APPLE") &&
  1432. this->GetPropertyAsBool("BUNDLE"));
  1433. }
  1434. //----------------------------------------------------------------------------
  1435. class cmTargetTraceDependencies
  1436. {
  1437. public:
  1438. cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1439. const char* vsProjectFile);
  1440. void Trace();
  1441. private:
  1442. cmTarget* Target;
  1443. cmTargetInternals* Internal;
  1444. cmMakefile* Makefile;
  1445. cmGlobalGenerator* GlobalGenerator;
  1446. typedef cmTargetInternals::SourceEntry SourceEntry;
  1447. SourceEntry* CurrentEntry;
  1448. std::queue<cmSourceFile*> SourceQueue;
  1449. std::set<cmSourceFile*> SourcesQueued;
  1450. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  1451. NameMapType NameMap;
  1452. void QueueSource(cmSourceFile* sf);
  1453. void FollowName(std::string const& name);
  1454. void FollowNames(std::vector<std::string> const& names);
  1455. bool IsUtility(std::string const& dep);
  1456. void CheckCustomCommand(cmCustomCommand const& cc);
  1457. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1458. };
  1459. //----------------------------------------------------------------------------
  1460. cmTargetTraceDependencies
  1461. ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1462. const char* vsProjectFile):
  1463. Target(target), Internal(internal)
  1464. {
  1465. // Convenience.
  1466. this->Makefile = this->Target->GetMakefile();
  1467. this->GlobalGenerator =
  1468. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  1469. this->CurrentEntry = 0;
  1470. // Queue all the source files already specified for the target.
  1471. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  1472. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1473. si != sources.end(); ++si)
  1474. {
  1475. this->QueueSource(*si);
  1476. }
  1477. // Queue the VS project file to check dependencies on the rule to
  1478. // generate it.
  1479. if(vsProjectFile)
  1480. {
  1481. this->FollowName(vsProjectFile);
  1482. }
  1483. // Queue pre-build, pre-link, and post-build rule dependencies.
  1484. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1485. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1486. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1487. }
  1488. //----------------------------------------------------------------------------
  1489. void cmTargetTraceDependencies::Trace()
  1490. {
  1491. // Process one dependency at a time until the queue is empty.
  1492. while(!this->SourceQueue.empty())
  1493. {
  1494. // Get the next source from the queue.
  1495. cmSourceFile* sf = this->SourceQueue.front();
  1496. this->SourceQueue.pop();
  1497. this->CurrentEntry = &this->Internal->SourceEntries[sf];
  1498. // Queue dependencies added explicitly by the user.
  1499. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1500. {
  1501. std::vector<std::string> objDeps;
  1502. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1503. this->FollowNames(objDeps);
  1504. }
  1505. // Queue the source needed to generate this file, if any.
  1506. this->FollowName(sf->GetFullPath());
  1507. // Queue dependencies added programatically by commands.
  1508. this->FollowNames(sf->GetDepends());
  1509. // Queue custom command dependencies.
  1510. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1511. {
  1512. this->CheckCustomCommand(*cc);
  1513. }
  1514. }
  1515. this->CurrentEntry = 0;
  1516. }
  1517. //----------------------------------------------------------------------------
  1518. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1519. {
  1520. if(this->SourcesQueued.insert(sf).second)
  1521. {
  1522. this->SourceQueue.push(sf);
  1523. // Make sure this file is in the target.
  1524. this->Target->AddSourceFile(sf);
  1525. }
  1526. }
  1527. //----------------------------------------------------------------------------
  1528. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1529. {
  1530. NameMapType::iterator i = this->NameMap.find(name);
  1531. if(i == this->NameMap.end())
  1532. {
  1533. // Check if we know how to generate this file.
  1534. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  1535. NameMapType::value_type entry(name, sf);
  1536. i = this->NameMap.insert(entry).first;
  1537. }
  1538. if(cmSourceFile* sf = i->second)
  1539. {
  1540. // Record the dependency we just followed.
  1541. if(this->CurrentEntry)
  1542. {
  1543. this->CurrentEntry->Depends.push_back(sf);
  1544. }
  1545. this->QueueSource(sf);
  1546. }
  1547. }
  1548. //----------------------------------------------------------------------------
  1549. void
  1550. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1551. {
  1552. for(std::vector<std::string>::const_iterator i = names.begin();
  1553. i != names.end(); ++i)
  1554. {
  1555. this->FollowName(*i);
  1556. }
  1557. }
  1558. //----------------------------------------------------------------------------
  1559. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1560. {
  1561. // Dependencies on targets (utilities) are supposed to be named by
  1562. // just the target name. However for compatibility we support
  1563. // naming the output file generated by the target (assuming there is
  1564. // no output-name property which old code would not have set). In
  1565. // that case the target name will be the file basename of the
  1566. // dependency.
  1567. std::string util = cmSystemTools::GetFilenameName(dep);
  1568. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1569. {
  1570. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1571. }
  1572. // Check for a target with this name.
  1573. if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
  1574. {
  1575. // If we find the target and the dep was given as a full path,
  1576. // then make sure it was not a full path to something else, and
  1577. // the fact that the name matched a target was just a coincidence.
  1578. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1579. {
  1580. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1581. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1582. {
  1583. // This is really only for compatibility so we do not need to
  1584. // worry about configuration names and output names.
  1585. std::string tLocation = t->GetLocation(0);
  1586. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1587. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1588. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1589. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1590. if(depLocation == tLocation)
  1591. {
  1592. this->Target->AddUtility(util.c_str());
  1593. return true;
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. // The original name of the dependency was not a full path. It
  1600. // must name a target, so add the target-level dependency.
  1601. this->Target->AddUtility(util.c_str());
  1602. return true;
  1603. }
  1604. }
  1605. // The dependency does not name a target built in this project.
  1606. return false;
  1607. }
  1608. //----------------------------------------------------------------------------
  1609. void
  1610. cmTargetTraceDependencies
  1611. ::CheckCustomCommand(cmCustomCommand const& cc)
  1612. {
  1613. // Transform command names that reference targets built in this
  1614. // project to corresponding target-level dependencies.
  1615. cmGeneratorExpression ge(cc.GetBacktrace());
  1616. // Add target-level dependencies referenced by generator expressions.
  1617. std::set<cmTarget*> targets;
  1618. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1619. cit != cc.GetCommandLines().end(); ++cit)
  1620. {
  1621. std::string const& command = *cit->begin();
  1622. // Check for a target with this name.
  1623. if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
  1624. {
  1625. if(t->GetType() == cmTarget::EXECUTABLE)
  1626. {
  1627. // The command refers to an executable target built in
  1628. // this project. Add the target-level dependency to make
  1629. // sure the executable is up to date before this custom
  1630. // command possibly runs.
  1631. this->Target->AddUtility(command.c_str());
  1632. }
  1633. }
  1634. // Check for target references in generator expressions.
  1635. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1636. cli != cit->end(); ++cli)
  1637. {
  1638. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1639. = ge.Parse(*cli);
  1640. cge->Evaluate(this->Makefile, 0, true);
  1641. std::set<cmTarget*> geTargets = cge->GetTargets();
  1642. for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
  1643. it != geTargets.end(); ++it)
  1644. {
  1645. targets.insert(*it);
  1646. }
  1647. }
  1648. }
  1649. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1650. ti != targets.end(); ++ti)
  1651. {
  1652. this->Target->AddUtility((*ti)->GetName());
  1653. }
  1654. // Queue the custom command dependencies.
  1655. std::vector<std::string> const& depends = cc.GetDepends();
  1656. for(std::vector<std::string>::const_iterator di = depends.begin();
  1657. di != depends.end(); ++di)
  1658. {
  1659. std::string const& dep = *di;
  1660. if(!this->IsUtility(dep))
  1661. {
  1662. // The dependency does not name a target and may be a file we
  1663. // know how to generate. Queue it.
  1664. this->FollowName(dep);
  1665. }
  1666. }
  1667. }
  1668. //----------------------------------------------------------------------------
  1669. void
  1670. cmTargetTraceDependencies
  1671. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1672. {
  1673. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1674. cli != commands.end(); ++cli)
  1675. {
  1676. this->CheckCustomCommand(*cli);
  1677. }
  1678. }
  1679. //----------------------------------------------------------------------------
  1680. void cmTarget::TraceDependencies(const char* vsProjectFile)
  1681. {
  1682. // CMake-generated targets have no dependencies to trace. Normally tracing
  1683. // would find nothing anyway, but when building CMake itself the "install"
  1684. // target command ends up referencing the "cmake" target but we do not
  1685. // really want the dependency because "install" depend on "all" anyway.
  1686. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1687. {
  1688. return;
  1689. }
  1690. // Use a helper object to trace the dependencies.
  1691. cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
  1692. tracer.Trace();
  1693. }
  1694. //----------------------------------------------------------------------------
  1695. bool cmTarget::FindSourceFiles()
  1696. {
  1697. for(std::vector<cmSourceFile*>::const_iterator
  1698. si = this->SourceFiles.begin();
  1699. si != this->SourceFiles.end(); ++si)
  1700. {
  1701. std::string e;
  1702. if((*si)->GetFullPath(&e).empty())
  1703. {
  1704. if(!e.empty())
  1705. {
  1706. cmake* cm = this->Makefile->GetCMakeInstance();
  1707. cm->IssueMessage(cmake::FATAL_ERROR, e,
  1708. this->GetBacktrace());
  1709. }
  1710. return false;
  1711. }
  1712. }
  1713. return true;
  1714. }
  1715. //----------------------------------------------------------------------------
  1716. std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
  1717. {
  1718. return this->SourceFiles;
  1719. }
  1720. //----------------------------------------------------------------------------
  1721. void cmTarget::AddSourceFile(cmSourceFile* sf)
  1722. {
  1723. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1724. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1725. if(i == this->Internal->SourceEntries.end())
  1726. {
  1727. typedef cmTargetInternals::SourceEntry SourceEntry;
  1728. SourceEntriesType::value_type entry(sf, SourceEntry());
  1729. i = this->Internal->SourceEntries.insert(entry).first;
  1730. this->SourceFiles.push_back(sf);
  1731. }
  1732. }
  1733. //----------------------------------------------------------------------------
  1734. std::vector<cmSourceFile*> const*
  1735. cmTarget::GetSourceDepends(cmSourceFile* sf)
  1736. {
  1737. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1738. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1739. if(i != this->Internal->SourceEntries.end())
  1740. {
  1741. return &i->second.Depends;
  1742. }
  1743. return 0;
  1744. }
  1745. //----------------------------------------------------------------------------
  1746. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1747. {
  1748. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1749. i != srcs.end(); ++i)
  1750. {
  1751. const char* src = i->c_str();
  1752. if(src[0] == '$' && src[1] == '<')
  1753. {
  1754. this->ProcessSourceExpression(*i);
  1755. }
  1756. else
  1757. {
  1758. this->AddSource(src);
  1759. }
  1760. }
  1761. }
  1762. //----------------------------------------------------------------------------
  1763. cmSourceFile* cmTarget::AddSource(const char* s)
  1764. {
  1765. std::string src = s;
  1766. // For backwards compatibility replace varibles in source names.
  1767. // This should eventually be removed.
  1768. this->Makefile->ExpandVariablesInString(src);
  1769. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  1770. this->AddSourceFile(sf);
  1771. return sf;
  1772. }
  1773. //----------------------------------------------------------------------------
  1774. void cmTarget::ProcessSourceExpression(std::string const& expr)
  1775. {
  1776. if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
  1777. expr[expr.size()-1] == '>')
  1778. {
  1779. std::string objLibName = expr.substr(17, expr.size()-18);
  1780. this->ObjectLibraries.push_back(objLibName);
  1781. }
  1782. else
  1783. {
  1784. cmOStringStream e;
  1785. e << "Unrecognized generator expression:\n"
  1786. << " " << expr;
  1787. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1788. }
  1789. }
  1790. //----------------------------------------------------------------------------
  1791. struct cmTarget::SourceFileFlags
  1792. cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
  1793. {
  1794. struct SourceFileFlags flags;
  1795. this->ConstructSourceFileFlags();
  1796. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1797. this->Internal->SourceFlagsMap.find(sf);
  1798. if(si != this->Internal->SourceFlagsMap.end())
  1799. {
  1800. flags = si->second;
  1801. }
  1802. return flags;
  1803. }
  1804. //----------------------------------------------------------------------------
  1805. void cmTarget::ConstructSourceFileFlags()
  1806. {
  1807. if(this->Internal->SourceFileFlagsConstructed)
  1808. {
  1809. return;
  1810. }
  1811. this->Internal->SourceFileFlagsConstructed = true;
  1812. // Process public headers to mark the source files.
  1813. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  1814. {
  1815. std::vector<std::string> relFiles;
  1816. cmSystemTools::ExpandListArgument(files, relFiles);
  1817. for(std::vector<std::string>::iterator it = relFiles.begin();
  1818. it != relFiles.end(); ++it)
  1819. {
  1820. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1821. {
  1822. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1823. flags.MacFolder = "Headers";
  1824. flags.Type = cmTarget::SourceFileTypePublicHeader;
  1825. }
  1826. }
  1827. }
  1828. // Process private headers after public headers so that they take
  1829. // precedence if a file is listed in both.
  1830. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  1831. {
  1832. std::vector<std::string> relFiles;
  1833. cmSystemTools::ExpandListArgument(files, relFiles);
  1834. for(std::vector<std::string>::iterator it = relFiles.begin();
  1835. it != relFiles.end(); ++it)
  1836. {
  1837. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1838. {
  1839. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1840. flags.MacFolder = "PrivateHeaders";
  1841. flags.Type = cmTarget::SourceFileTypePrivateHeader;
  1842. }
  1843. }
  1844. }
  1845. // Mark sources listed as resources.
  1846. if(const char* files = this->GetProperty("RESOURCE"))
  1847. {
  1848. std::vector<std::string> relFiles;
  1849. cmSystemTools::ExpandListArgument(files, relFiles);
  1850. for(std::vector<std::string>::iterator it = relFiles.begin();
  1851. it != relFiles.end(); ++it)
  1852. {
  1853. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1854. {
  1855. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1856. flags.MacFolder = "Resources";
  1857. flags.Type = cmTarget::SourceFileTypeResource;
  1858. }
  1859. }
  1860. }
  1861. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1862. // were not listed in one of the other lists.
  1863. std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
  1864. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1865. si != sources.end(); ++si)
  1866. {
  1867. cmSourceFile* sf = *si;
  1868. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1869. {
  1870. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1871. if(flags.Type == cmTarget::SourceFileTypeNormal)
  1872. {
  1873. flags.MacFolder = location;
  1874. if(strcmp(location, "Resources") == 0)
  1875. {
  1876. flags.Type = cmTarget::SourceFileTypeResource;
  1877. }
  1878. else
  1879. {
  1880. flags.Type = cmTarget::SourceFileTypeMacContent;
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //----------------------------------------------------------------------------
  1887. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  1888. const char *selfname,
  1889. const LinkLibraryVectorType& libs )
  1890. {
  1891. // Only add on libraries we haven't added on before.
  1892. // Assumption: the global link libraries could only grow, never shrink
  1893. LinkLibraryVectorType::const_iterator i = libs.begin();
  1894. i += this->PrevLinkedLibraries.size();
  1895. for( ; i != libs.end(); ++i )
  1896. {
  1897. // We call this so that the dependencies get written to the cache
  1898. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  1899. }
  1900. this->PrevLinkedLibraries = libs;
  1901. }
  1902. //----------------------------------------------------------------------------
  1903. void cmTarget::AddLinkDirectory(const char* d)
  1904. {
  1905. // Make sure we don't add unnecessary search directories.
  1906. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1907. {
  1908. this->LinkDirectories.push_back(d);
  1909. }
  1910. }
  1911. //----------------------------------------------------------------------------
  1912. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  1913. {
  1914. return this->LinkDirectories;
  1915. }
  1916. //----------------------------------------------------------------------------
  1917. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
  1918. {
  1919. // No configuration is always optimized.
  1920. if(!(config && *config))
  1921. {
  1922. return cmTarget::OPTIMIZED;
  1923. }
  1924. // Get the list of configurations considered to be DEBUG.
  1925. std::vector<std::string> const& debugConfigs =
  1926. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1927. // Check if any entry in the list matches this configuration.
  1928. std::string configUpper = cmSystemTools::UpperCase(config);
  1929. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  1930. i != debugConfigs.end(); ++i)
  1931. {
  1932. if(*i == configUpper)
  1933. {
  1934. return cmTarget::DEBUG;
  1935. }
  1936. }
  1937. // The current configuration is not a debug configuration.
  1938. return cmTarget::OPTIMIZED;
  1939. }
  1940. //----------------------------------------------------------------------------
  1941. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1942. const char* target )
  1943. {
  1944. // Clear the dependencies. The cache variable must exist iff we are
  1945. // recording dependency information for this target.
  1946. std::string depname = target;
  1947. depname += "_LIB_DEPENDS";
  1948. if (this->RecordDependencies)
  1949. {
  1950. mf.AddCacheDefinition(depname.c_str(), "",
  1951. "Dependencies for target", cmCacheManager::STATIC);
  1952. }
  1953. else
  1954. {
  1955. if (mf.GetDefinition( depname.c_str() ))
  1956. {
  1957. std::string message = "Target ";
  1958. message += target;
  1959. message += " has dependency information when it shouldn't.\n";
  1960. message += "Your cache is probably stale. Please remove the entry\n ";
  1961. message += depname;
  1962. message += "\nfrom the cache.";
  1963. cmSystemTools::Error( message.c_str() );
  1964. }
  1965. }
  1966. }
  1967. //----------------------------------------------------------------------------
  1968. bool cmTarget::NameResolvesToFramework(const std::string& libname)
  1969. {
  1970. return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
  1971. NameResolvesToFramework(libname);
  1972. }
  1973. //----------------------------------------------------------------------------
  1974. void cmTarget::GetDirectLinkLibraries(const char *config,
  1975. std::vector<std::string> &libs, cmTarget *head)
  1976. {
  1977. const char *prop = this->GetProperty("LINK_LIBRARIES");
  1978. if (prop)
  1979. {
  1980. cmListFileBacktrace lfbt;
  1981. cmGeneratorExpression ge(lfbt);
  1982. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  1983. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1984. this->GetName(),
  1985. "LINK_LIBRARIES", 0, 0);
  1986. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  1987. config,
  1988. false,
  1989. head,
  1990. &dagChecker),
  1991. libs);
  1992. this->AddLinkDependentTargetsForProperties(cge->GetSeenTargetProperties());
  1993. }
  1994. }
  1995. //----------------------------------------------------------------------------
  1996. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1997. cmTarget::LinkLibraryType llt)
  1998. {
  1999. if (llt == GENERAL)
  2000. {
  2001. return value;
  2002. }
  2003. // Get the list of configurations considered to be DEBUG.
  2004. std::vector<std::string> const& debugConfigs =
  2005. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  2006. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  2007. if (debugConfigs.size() > 1)
  2008. {
  2009. for(std::vector<std::string>::const_iterator
  2010. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  2011. {
  2012. configString += ",$<CONFIG:" + *li + ">";
  2013. }
  2014. configString = "$<OR:" + configString + ">";
  2015. }
  2016. if (llt == OPTIMIZED)
  2017. {
  2018. configString = "$<NOT:" + configString + ">";
  2019. }
  2020. return "$<" + configString + ":" + value + ">";
  2021. }
  2022. //----------------------------------------------------------------------------
  2023. static std::string targetNameGenex(const char *lib)
  2024. {
  2025. return std::string("$<TARGET_NAME:") + lib + ">";
  2026. }
  2027. //----------------------------------------------------------------------------
  2028. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  2029. const char *target, const char* lib,
  2030. LinkLibraryType llt)
  2031. {
  2032. // Never add a self dependency, even if the user asks for it.
  2033. if(strcmp( target, lib ) == 0)
  2034. {
  2035. return;
  2036. }
  2037. {
  2038. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  2039. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  2040. std::string libName = isNonImportedTarget ? targetNameGenex(lib)
  2041. : std::string(lib);
  2042. this->AppendProperty("LINK_LIBRARIES",
  2043. this->GetDebugGeneratorExpressions(libName,
  2044. llt).c_str());
  2045. }
  2046. cmTarget::LibraryID tmp;
  2047. tmp.first = lib;
  2048. tmp.second = llt;
  2049. this->LinkLibraries.push_back( tmp );
  2050. this->OriginalLinkLibraries.push_back(tmp);
  2051. this->ClearLinkMaps();
  2052. // Add the explicit dependency information for this target. This is
  2053. // simply a set of libraries separated by ";". There should always
  2054. // be a trailing ";". These library names are not canonical, in that
  2055. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  2056. // We shouldn't remove duplicates here because external libraries
  2057. // may be purposefully duplicated to handle recursive dependencies,
  2058. // and we removing one instance will break the link line. Duplicates
  2059. // will be appropriately eliminated at emit time.
  2060. if(this->RecordDependencies)
  2061. {
  2062. std::string targetEntry = target;
  2063. targetEntry += "_LIB_DEPENDS";
  2064. std::string dependencies;
  2065. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  2066. if( old_val )
  2067. {
  2068. dependencies += old_val;
  2069. }
  2070. switch (llt)
  2071. {
  2072. case cmTarget::GENERAL:
  2073. dependencies += "general";
  2074. break;
  2075. case cmTarget::DEBUG:
  2076. dependencies += "debug";
  2077. break;
  2078. case cmTarget::OPTIMIZED:
  2079. dependencies += "optimized";
  2080. break;
  2081. }
  2082. dependencies += ";";
  2083. dependencies += lib;
  2084. dependencies += ";";
  2085. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  2086. "Dependencies for the target",
  2087. cmCacheManager::STATIC );
  2088. }
  2089. }
  2090. //----------------------------------------------------------------------------
  2091. void
  2092. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  2093. {
  2094. // There are two key parts of the dependency analysis: (1)
  2095. // determining the libraries in the link line, and (2) constructing
  2096. // the dependency graph for those libraries.
  2097. //
  2098. // The latter is done using the cache entries that record the
  2099. // dependencies of each library.
  2100. //
  2101. // The former is a more thorny issue, since it is not clear how to
  2102. // determine if two libraries listed on the link line refer to the a
  2103. // single library or not. For example, consider the link "libraries"
  2104. // /usr/lib/libtiff.so -ltiff
  2105. // Is this one library or two? The solution implemented here is the
  2106. // simplest (and probably the only practical) one: two libraries are
  2107. // the same if their "link strings" are identical. Thus, the two
  2108. // libraries above are considered distinct. This also means that for
  2109. // dependency analysis to be effective, the CMake user must specify
  2110. // libraries build by his project without using any linker flags or
  2111. // file extensions. That is,
  2112. // LINK_LIBRARIES( One Two )
  2113. // instead of
  2114. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  2115. // The former is probably what most users would do, but it never
  2116. // hurts to document the assumptions. :-) Therefore, in the analysis
  2117. // code, the "canonical name" of a library is simply its name as
  2118. // given to a LINK_LIBRARIES command.
  2119. //
  2120. // Also, we will leave the original link line intact; we will just add any
  2121. // dependencies that were missing.
  2122. //
  2123. // There is a problem with recursive external libraries
  2124. // (i.e. libraries with no dependency information that are
  2125. // recursively dependent). We must make sure that the we emit one of
  2126. // the libraries twice to satisfy the recursion, but we shouldn't
  2127. // emit it more times than necessary. In particular, we must make
  2128. // sure that handling this improbable case doesn't cost us when
  2129. // dealing with the common case of non-recursive libraries. The
  2130. // solution is to assume that the recursion is satisfied at one node
  2131. // of the dependency tree. To illustrate, assume libA and libB are
  2132. // extrenal and mutually dependent. Suppose libX depends on
  2133. // libA, and libY on libA and libX. Then
  2134. // TARGET_LINK_LIBRARIES( Y X A B A )
  2135. // TARGET_LINK_LIBRARIES( X A B A )
  2136. // TARGET_LINK_LIBRARIES( Exec Y )
  2137. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  2138. // specify the dependencies, since the mutual dependency of A and B
  2139. // is resolved *every time libA is specified*.
  2140. //
  2141. // Something like
  2142. // TARGET_LINK_LIBRARIES( Y X A B A )
  2143. // TARGET_LINK_LIBRARIES( X A B )
  2144. // TARGET_LINK_LIBRARIES( Exec Y )
  2145. // would result in "-lY -lX -lA -lB", and the mutual dependency
  2146. // information is lost. This is because in some case (Y), the mutual
  2147. // dependency of A and B is listed, while in another other case (X),
  2148. // it is not. Depending on which line actually emits A, the mutual
  2149. // dependency may or may not be on the final link line. We can't
  2150. // handle this pathalogical case cleanly without emitting extra
  2151. // libraries for the normal cases. Besides, the dependency
  2152. // information for X is wrong anyway: if we build an executable
  2153. // depending on X alone, we would not have the mutual dependency on
  2154. // A and B resolved.
  2155. //
  2156. // IMPROVEMENTS:
  2157. // -- The current algorithm will not always pick the "optimal" link line
  2158. // when recursive dependencies are present. It will instead break the
  2159. // cycles at an aribtrary point. The majority of projects won't have
  2160. // cyclic dependencies, so this is probably not a big deal. Note that
  2161. // the link line is always correct, just not necessary optimal.
  2162. {
  2163. // Expand variables in link library names. This is for backwards
  2164. // compatibility with very early CMake versions and should
  2165. // eventually be removed. This code was moved here from the end of
  2166. // old source list processing code which was called just before this
  2167. // method.
  2168. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  2169. p != this->LinkLibraries.end(); ++p)
  2170. {
  2171. this->Makefile->ExpandVariablesInString(p->first, true, true);
  2172. }
  2173. }
  2174. typedef std::vector< std::string > LinkLine;
  2175. // The dependency map.
  2176. DependencyMap dep_map;
  2177. // 1. Build the dependency graph
  2178. //
  2179. for(LinkLibraryVectorType::reverse_iterator lib
  2180. = this->LinkLibraries.rbegin();
  2181. lib != this->LinkLibraries.rend(); ++lib)
  2182. {
  2183. this->GatherDependencies( mf, *lib, dep_map);
  2184. }
  2185. // 2. Remove any dependencies that are already satisfied in the original
  2186. // link line.
  2187. //
  2188. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  2189. lib != this->LinkLibraries.end(); ++lib)
  2190. {
  2191. for( LinkLibraryVectorType::iterator lib2 = lib;
  2192. lib2 != this->LinkLibraries.end(); ++lib2)
  2193. {
  2194. this->DeleteDependency( dep_map, *lib, *lib2);
  2195. }
  2196. }
  2197. // 3. Create the new link line by simply emitting any dependencies that are
  2198. // missing. Start from the back and keep adding.
  2199. //
  2200. std::set<DependencyMap::key_type> done, visited;
  2201. std::vector<DependencyMap::key_type> newLinkLibraries;
  2202. for(LinkLibraryVectorType::reverse_iterator lib =
  2203. this->LinkLibraries.rbegin();
  2204. lib != this->LinkLibraries.rend(); ++lib)
  2205. {
  2206. // skip zero size library entries, this may happen
  2207. // if a variable expands to nothing.
  2208. if (lib->first.size() != 0)
  2209. {
  2210. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  2211. }
  2212. }
  2213. // 4. Add the new libraries to the link line.
  2214. //
  2215. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  2216. newLinkLibraries.rbegin();
  2217. k != newLinkLibraries.rend(); ++k )
  2218. {
  2219. // get the llt from the dep_map
  2220. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  2221. }
  2222. this->LinkLibrariesAnalyzed = true;
  2223. }
  2224. //----------------------------------------------------------------------------
  2225. void cmTarget::InsertDependency( DependencyMap& depMap,
  2226. const LibraryID& lib,
  2227. const LibraryID& dep)
  2228. {
  2229. depMap[lib].push_back(dep);
  2230. }
  2231. //----------------------------------------------------------------------------
  2232. void cmTarget::DeleteDependency( DependencyMap& depMap,
  2233. const LibraryID& lib,
  2234. const LibraryID& dep)
  2235. {
  2236. // Make sure there is an entry in the map for lib. If so, delete all
  2237. // dependencies to dep. There may be repeated entries because of
  2238. // external libraries that are specified multiple times.
  2239. DependencyMap::iterator map_itr = depMap.find( lib );
  2240. if( map_itr != depMap.end() )
  2241. {
  2242. DependencyList& depList = map_itr->second;
  2243. DependencyList::iterator itr;
  2244. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  2245. depList.end() )
  2246. {
  2247. depList.erase( itr );
  2248. }
  2249. }
  2250. }
  2251. //----------------------------------------------------------------------------
  2252. void cmTarget::Emit(const LibraryID lib,
  2253. const DependencyMap& dep_map,
  2254. std::set<LibraryID>& emitted,
  2255. std::set<LibraryID>& visited,
  2256. DependencyList& link_line )
  2257. {
  2258. // It's already been emitted
  2259. if( emitted.find(lib) != emitted.end() )
  2260. {
  2261. return;
  2262. }
  2263. // Emit the dependencies only if this library node hasn't been
  2264. // visited before. If it has, then we have a cycle. The recursion
  2265. // that got us here should take care of everything.
  2266. if( visited.insert(lib).second )
  2267. {
  2268. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  2269. {
  2270. const DependencyList& dep_on = dep_map.find( lib )->second;
  2271. DependencyList::const_reverse_iterator i;
  2272. // To cater for recursive external libraries, we must emit
  2273. // duplicates on this link line *unless* they were emitted by
  2274. // some other node, in which case we assume that the recursion
  2275. // was resolved then. We making the simplifying assumption that
  2276. // any duplicates on a single link line are on purpose, and must
  2277. // be preserved.
  2278. // This variable will keep track of the libraries that were
  2279. // emitted directly from the current node, and not from a
  2280. // recursive call. This way, if we come across a library that
  2281. // has already been emitted, we repeat it iff it has been
  2282. // emitted here.
  2283. std::set<DependencyMap::key_type> emitted_here;
  2284. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  2285. {
  2286. if( emitted_here.find(*i) != emitted_here.end() )
  2287. {
  2288. // a repeat. Must emit.
  2289. emitted.insert(*i);
  2290. link_line.push_back( *i );
  2291. }
  2292. else
  2293. {
  2294. // Emit only if no-one else has
  2295. if( emitted.find(*i) == emitted.end() )
  2296. {
  2297. // emit dependencies
  2298. Emit( *i, dep_map, emitted, visited, link_line );
  2299. // emit self
  2300. emitted.insert(*i);
  2301. emitted_here.insert(*i);
  2302. link_line.push_back( *i );
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. //----------------------------------------------------------------------------
  2310. void cmTarget::GatherDependencies( const cmMakefile& mf,
  2311. const LibraryID& lib,
  2312. DependencyMap& dep_map)
  2313. {
  2314. // If the library is already in the dependency map, then it has
  2315. // already been fully processed.
  2316. if( dep_map.find(lib) != dep_map.end() )
  2317. {
  2318. return;
  2319. }
  2320. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  2321. if( deps && strcmp(deps,"") != 0 )
  2322. {
  2323. // Make sure this library is in the map, even if it has an empty
  2324. // set of dependencies. This distinguishes the case of explicitly
  2325. // no dependencies with that of unspecified dependencies.
  2326. dep_map[lib];
  2327. // Parse the dependency information, which is a set of
  2328. // type, library pairs separated by ";". There is always a trailing ";".
  2329. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  2330. std::string depline = deps;
  2331. std::string::size_type start = 0;
  2332. std::string::size_type end;
  2333. end = depline.find( ";", start );
  2334. while( end != std::string::npos )
  2335. {
  2336. std::string l = depline.substr( start, end-start );
  2337. if( l.size() != 0 )
  2338. {
  2339. if (l == "debug")
  2340. {
  2341. llt = cmTarget::DEBUG;
  2342. }
  2343. else if (l == "optimized")
  2344. {
  2345. llt = cmTarget::OPTIMIZED;
  2346. }
  2347. else if (l == "general")
  2348. {
  2349. llt = cmTarget::GENERAL;
  2350. }
  2351. else
  2352. {
  2353. LibraryID lib2(l,llt);
  2354. this->InsertDependency( dep_map, lib, lib2);
  2355. this->GatherDependencies( mf, lib2, dep_map);
  2356. llt = cmTarget::GENERAL;
  2357. }
  2358. }
  2359. start = end+1; // skip the ;
  2360. end = depline.find( ";", start );
  2361. }
  2362. // cannot depend on itself
  2363. this->DeleteDependency( dep_map, lib, lib);
  2364. }
  2365. }
  2366. //----------------------------------------------------------------------------
  2367. void deleteAndClear(
  2368. std::vector<cmTargetInternals::IncludeDirectoriesEntry*> &entries)
  2369. {
  2370. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  2371. it = entries.begin(),
  2372. end = entries.end();
  2373. it != end; ++it)
  2374. {
  2375. delete *it;
  2376. }
  2377. entries.clear();
  2378. }
  2379. //----------------------------------------------------------------------------
  2380. void cmTarget::SetProperty(const char* prop, const char* value)
  2381. {
  2382. if (!prop)
  2383. {
  2384. return;
  2385. }
  2386. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2387. {
  2388. cmListFileBacktrace lfbt;
  2389. this->Makefile->GetBacktrace(lfbt);
  2390. cmGeneratorExpression ge(lfbt);
  2391. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  2392. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  2393. this->Internal->IncludeDirectoriesEntries.push_back(
  2394. new cmTargetInternals::IncludeDirectoriesEntry(cge));
  2395. return;
  2396. }
  2397. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  2398. this->MaybeInvalidatePropertyCache(prop);
  2399. }
  2400. //----------------------------------------------------------------------------
  2401. void cmTarget::AppendProperty(const char* prop, const char* value,
  2402. bool asString)
  2403. {
  2404. if (!prop)
  2405. {
  2406. return;
  2407. }
  2408. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2409. {
  2410. cmListFileBacktrace lfbt;
  2411. this->Makefile->GetBacktrace(lfbt);
  2412. cmGeneratorExpression ge(lfbt);
  2413. this->Internal->IncludeDirectoriesEntries.push_back(
  2414. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
  2415. return;
  2416. }
  2417. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  2418. this->MaybeInvalidatePropertyCache(prop);
  2419. }
  2420. //----------------------------------------------------------------------------
  2421. void cmTarget::InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry,
  2422. bool before)
  2423. {
  2424. cmGeneratorExpression ge(entry.Backtrace);
  2425. std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::iterator position
  2426. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  2427. : this->Internal->IncludeDirectoriesEntries.end();
  2428. this->Internal->IncludeDirectoriesEntries.insert(position,
  2429. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(entry.Value)));
  2430. }
  2431. //----------------------------------------------------------------------------
  2432. std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
  2433. {
  2434. std::vector<std::string> includes;
  2435. std::set<std::string> uniqueIncludes;
  2436. cmListFileBacktrace lfbt;
  2437. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2438. this->GetName(),
  2439. "INCLUDE_DIRECTORIES", 0, 0);
  2440. std::vector<std::string> debugProperties;
  2441. const char *debugProp =
  2442. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2443. if (debugProp)
  2444. {
  2445. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2446. }
  2447. bool debugIncludes = std::find(debugProperties.begin(),
  2448. debugProperties.end(),
  2449. "INCLUDE_DIRECTORIES")
  2450. != debugProperties.end();
  2451. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  2452. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2453. end = this->Internal->IncludeDirectoriesEntries.end();
  2454. it != end; ++it)
  2455. {
  2456. std::vector<std::string> entryIncludes;
  2457. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(this->Makefile,
  2458. config,
  2459. false,
  2460. this,
  2461. &dagChecker),
  2462. entryIncludes);
  2463. std::string usedIncludes;
  2464. for(std::vector<std::string>::const_iterator
  2465. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  2466. {
  2467. std::string inc = *li;
  2468. if (!cmSystemTools::IsOff(inc.c_str()))
  2469. {
  2470. cmSystemTools::ConvertToUnixSlashes(inc);
  2471. }
  2472. if(uniqueIncludes.insert(inc).second)
  2473. {
  2474. includes.push_back(*li);
  2475. if (debugIncludes)
  2476. {
  2477. usedIncludes += " * " + *li + "\n";
  2478. }
  2479. }
  2480. }
  2481. if (!usedIncludes.empty())
  2482. {
  2483. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2484. "Used includes:\n" + usedIncludes,
  2485. (*it)->ge->GetBacktrace());
  2486. }
  2487. }
  2488. return includes;
  2489. }
  2490. //----------------------------------------------------------------------------
  2491. void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
  2492. {
  2493. // Wipe out maps caching information affected by this property.
  2494. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  2495. {
  2496. this->Internal->ImportInfoMap.clear();
  2497. }
  2498. if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
  2499. {
  2500. this->ClearLinkMaps();
  2501. }
  2502. }
  2503. //----------------------------------------------------------------------------
  2504. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2505. const char* prop, const char* value, cmMakefile* context, bool imported
  2506. )
  2507. {
  2508. // Look for link-type keywords in the value.
  2509. static cmsys::RegularExpression
  2510. keys("(^|;)(debug|optimized|general)(;|$)");
  2511. if(!keys.find(value))
  2512. {
  2513. return;
  2514. }
  2515. // Support imported and non-imported versions of the property.
  2516. const char* base = (imported?
  2517. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2518. "LINK_INTERFACE_LIBRARIES");
  2519. // Report an error.
  2520. cmOStringStream e;
  2521. e << "Property " << prop << " may not contain link-type keyword \""
  2522. << keys.match(2) << "\". "
  2523. << "The " << base << " property has a per-configuration "
  2524. << "version called " << base << "_<CONFIG> which may be "
  2525. << "used to specify per-configuration rules.";
  2526. if(!imported)
  2527. {
  2528. e << " "
  2529. << "Alternatively, an IMPORTED library may be created, configured "
  2530. << "with a per-configuration location, and then named in the "
  2531. << "property value. "
  2532. << "See the add_library command's IMPORTED mode for details."
  2533. << "\n"
  2534. << "If you have a list of libraries that already contains the "
  2535. << "keyword, use the target_link_libraries command with its "
  2536. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2537. << "The command automatically recognizes link-type keywords and sets "
  2538. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2539. << "properties accordingly.";
  2540. }
  2541. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2542. }
  2543. //----------------------------------------------------------------------------
  2544. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  2545. {
  2546. // Certain properties need checking.
  2547. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  2548. {
  2549. if(const char* value = this->GetProperty(prop))
  2550. {
  2551. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2552. }
  2553. }
  2554. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  2555. {
  2556. if(const char* value = this->GetProperty(prop))
  2557. {
  2558. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2559. }
  2560. }
  2561. }
  2562. //----------------------------------------------------------------------------
  2563. void cmTarget::MarkAsImported()
  2564. {
  2565. this->IsImportedTarget = true;
  2566. }
  2567. //----------------------------------------------------------------------------
  2568. bool cmTarget::HaveWellDefinedOutputFiles()
  2569. {
  2570. return
  2571. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2572. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2573. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2574. this->GetType() == cmTarget::EXECUTABLE;
  2575. }
  2576. //----------------------------------------------------------------------------
  2577. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
  2578. {
  2579. // There is no output information for imported targets.
  2580. if(this->IsImported())
  2581. {
  2582. return 0;
  2583. }
  2584. // Only libraries and executables have well-defined output files.
  2585. if(!this->HaveWellDefinedOutputFiles())
  2586. {
  2587. std::string msg = "cmTarget::GetOutputInfo called for ";
  2588. msg += this->GetName();
  2589. msg += " which has type ";
  2590. msg += cmTarget::GetTargetTypeName(this->GetType());
  2591. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2592. abort();
  2593. return 0;
  2594. }
  2595. // Lookup/compute/cache the output information for this configuration.
  2596. std::string config_upper;
  2597. if(config && *config)
  2598. {
  2599. config_upper = cmSystemTools::UpperCase(config);
  2600. }
  2601. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2602. OutputInfoMapType::const_iterator i =
  2603. this->Internal->OutputInfoMap.find(config_upper);
  2604. if(i == this->Internal->OutputInfoMap.end())
  2605. {
  2606. OutputInfo info;
  2607. this->ComputeOutputDir(config, false, info.OutDir);
  2608. this->ComputeOutputDir(config, true, info.ImpDir);
  2609. if(!this->ComputePDBOutputDir(config, info.PdbDir))
  2610. {
  2611. info.PdbDir = info.OutDir;
  2612. }
  2613. OutputInfoMapType::value_type entry(config_upper, info);
  2614. i = this->Internal->OutputInfoMap.insert(entry).first;
  2615. }
  2616. return &i->second;
  2617. }
  2618. //----------------------------------------------------------------------------
  2619. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2620. {
  2621. if (this->IsImported())
  2622. {
  2623. // Return the directory from which the target is imported.
  2624. return
  2625. cmSystemTools::GetFilenamePath(
  2626. this->ImportedGetFullPath(config, implib));
  2627. }
  2628. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2629. {
  2630. // Return the directory in which the target will be built.
  2631. return implib? info->ImpDir : info->OutDir;
  2632. }
  2633. return "";
  2634. }
  2635. //----------------------------------------------------------------------------
  2636. std::string cmTarget::GetPDBDirectory(const char* config)
  2637. {
  2638. if(OutputInfo const* info = this->GetOutputInfo(config))
  2639. {
  2640. // Return the directory in which the target will be built.
  2641. return info->PdbDir;
  2642. }
  2643. return "";
  2644. }
  2645. //----------------------------------------------------------------------------
  2646. const char* cmTarget::GetLocation(const char* config)
  2647. {
  2648. if (this->IsImported())
  2649. {
  2650. return this->ImportedGetLocation(config);
  2651. }
  2652. else
  2653. {
  2654. return this->NormalGetLocation(config);
  2655. }
  2656. }
  2657. //----------------------------------------------------------------------------
  2658. const char* cmTarget::ImportedGetLocation(const char* config)
  2659. {
  2660. this->Location = this->ImportedGetFullPath(config, false);
  2661. return this->Location.c_str();
  2662. }
  2663. //----------------------------------------------------------------------------
  2664. const char* cmTarget::NormalGetLocation(const char* config)
  2665. {
  2666. // Handle the configuration-specific case first.
  2667. if(config)
  2668. {
  2669. this->Location = this->GetFullPath(config, false);
  2670. return this->Location.c_str();
  2671. }
  2672. // Now handle the deprecated build-time configuration location.
  2673. this->Location = this->GetDirectory();
  2674. if(!this->Location.empty())
  2675. {
  2676. this->Location += "/";
  2677. }
  2678. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2679. if(cfgid && strcmp(cfgid, ".") != 0)
  2680. {
  2681. this->Location += cfgid;
  2682. this->Location += "/";
  2683. }
  2684. this->Location = this->BuildMacContentDirectory(this->Location, config);
  2685. this->Location += this->GetFullName(config, false);
  2686. return this->Location.c_str();
  2687. }
  2688. //----------------------------------------------------------------------------
  2689. void cmTarget::GetTargetVersion(int& major, int& minor)
  2690. {
  2691. int patch;
  2692. this->GetTargetVersion(false, major, minor, patch);
  2693. }
  2694. //----------------------------------------------------------------------------
  2695. void cmTarget::GetTargetVersion(bool soversion,
  2696. int& major, int& minor, int& patch)
  2697. {
  2698. // Set the default values.
  2699. major = 0;
  2700. minor = 0;
  2701. patch = 0;
  2702. // Look for a VERSION or SOVERSION property.
  2703. const char* prop = soversion? "SOVERSION" : "VERSION";
  2704. if(const char* version = this->GetProperty(prop))
  2705. {
  2706. // Try to parse the version number and store the results that were
  2707. // successfully parsed.
  2708. int parsed_major;
  2709. int parsed_minor;
  2710. int parsed_patch;
  2711. switch(sscanf(version, "%d.%d.%d",
  2712. &parsed_major, &parsed_minor, &parsed_patch))
  2713. {
  2714. case 3: patch = parsed_patch; // no break!
  2715. case 2: minor = parsed_minor; // no break!
  2716. case 1: major = parsed_major; // no break!
  2717. default: break;
  2718. }
  2719. }
  2720. }
  2721. //----------------------------------------------------------------------------
  2722. const char* cmTarget::GetFeature(const char* feature, const char* config)
  2723. {
  2724. if(config && *config)
  2725. {
  2726. std::string featureConfig = feature;
  2727. featureConfig += "_";
  2728. featureConfig += cmSystemTools::UpperCase(config);
  2729. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2730. {
  2731. return value;
  2732. }
  2733. }
  2734. if(const char* value = this->GetProperty(feature))
  2735. {
  2736. return value;
  2737. }
  2738. return this->Makefile->GetFeature(feature, config);
  2739. }
  2740. //----------------------------------------------------------------------------
  2741. const char *cmTarget::GetProperty(const char* prop)
  2742. {
  2743. return this->GetProperty(prop, cmProperty::TARGET);
  2744. }
  2745. //----------------------------------------------------------------------------
  2746. const char *cmTarget::GetProperty(const char* prop,
  2747. cmProperty::ScopeType scope)
  2748. {
  2749. if(!prop)
  2750. {
  2751. return 0;
  2752. }
  2753. // Watch for special "computed" properties that are dependent on
  2754. // other properties or variables. Always recompute them.
  2755. if(this->GetType() == cmTarget::EXECUTABLE ||
  2756. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2757. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2758. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2759. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2760. {
  2761. if(strcmp(prop,"LOCATION") == 0)
  2762. {
  2763. // Set the LOCATION property of the target.
  2764. //
  2765. // For an imported target this is the location of an arbitrary
  2766. // available configuration.
  2767. //
  2768. // For a non-imported target this is deprecated because it
  2769. // cannot take into account the per-configuration name of the
  2770. // target because the configuration type may not be known at
  2771. // CMake time.
  2772. this->SetProperty("LOCATION", this->GetLocation(0));
  2773. }
  2774. // Support "LOCATION_<CONFIG>".
  2775. if(strncmp(prop, "LOCATION_", 9) == 0)
  2776. {
  2777. std::string configName = prop+9;
  2778. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2779. }
  2780. else
  2781. {
  2782. // Support "<CONFIG>_LOCATION" for compatiblity.
  2783. int len = static_cast<int>(strlen(prop));
  2784. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  2785. {
  2786. std::string configName(prop, len-9);
  2787. if(configName != "IMPORTED")
  2788. {
  2789. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2790. }
  2791. }
  2792. }
  2793. }
  2794. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2795. {
  2796. static std::string output;
  2797. output = "";
  2798. std::string sep;
  2799. typedef cmTargetInternals::IncludeDirectoriesEntry
  2800. IncludeDirectoriesEntry;
  2801. for (std::vector<IncludeDirectoriesEntry*>::const_iterator
  2802. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2803. end = this->Internal->IncludeDirectoriesEntries.end();
  2804. it != end; ++it)
  2805. {
  2806. output += sep;
  2807. output += (*it)->ge->GetInput();
  2808. sep = ";";
  2809. }
  2810. return output.c_str();
  2811. }
  2812. if (strcmp(prop,"IMPORTED") == 0)
  2813. {
  2814. return this->IsImported()?"TRUE":"FALSE";
  2815. }
  2816. if(!strcmp(prop,"SOURCES"))
  2817. {
  2818. cmOStringStream ss;
  2819. const char* sep = "";
  2820. for(std::vector<cmSourceFile*>::const_iterator
  2821. i = this->SourceFiles.begin();
  2822. i != this->SourceFiles.end(); ++i)
  2823. {
  2824. // Separate from the previous list entries.
  2825. ss << sep;
  2826. sep = ";";
  2827. // Construct what is known about this source file location.
  2828. cmSourceFileLocation const& location = (*i)->GetLocation();
  2829. std::string sname = location.GetDirectory();
  2830. if(!sname.empty())
  2831. {
  2832. sname += "/";
  2833. }
  2834. sname += location.GetName();
  2835. // Append this list entry.
  2836. ss << sname;
  2837. }
  2838. this->SetProperty("SOURCES", ss.str().c_str());
  2839. }
  2840. // the type property returns what type the target is
  2841. if (!strcmp(prop,"TYPE"))
  2842. {
  2843. return cmTarget::GetTargetTypeName(this->GetType());
  2844. }
  2845. bool chain = false;
  2846. const char *retVal =
  2847. this->Properties.GetPropertyValue(prop, scope, chain);
  2848. if (chain)
  2849. {
  2850. return this->Makefile->GetProperty(prop,scope);
  2851. }
  2852. return retVal;
  2853. }
  2854. //----------------------------------------------------------------------------
  2855. bool cmTarget::GetPropertyAsBool(const char* prop)
  2856. {
  2857. return cmSystemTools::IsOn(this->GetProperty(prop));
  2858. }
  2859. //----------------------------------------------------------------------------
  2860. class cmTargetCollectLinkLanguages
  2861. {
  2862. public:
  2863. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  2864. std::set<cmStdString>& languages,
  2865. cmTarget* head):
  2866. Config(config), Languages(languages), HeadTarget(head)
  2867. { this->Visited.insert(target); }
  2868. void Visit(cmTarget* target)
  2869. {
  2870. if(!target || !this->Visited.insert(target).second)
  2871. {
  2872. return;
  2873. }
  2874. cmTarget::LinkInterface const* iface =
  2875. target->GetLinkInterface(this->Config, this->HeadTarget);
  2876. if(!iface) { return; }
  2877. for(std::vector<std::string>::const_iterator
  2878. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2879. {
  2880. this->Languages.insert(*li);
  2881. }
  2882. cmMakefile* mf = target->GetMakefile();
  2883. for(std::vector<std::string>::const_iterator
  2884. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2885. {
  2886. this->Visit(mf->FindTargetToUse(li->c_str()));
  2887. }
  2888. }
  2889. private:
  2890. const char* Config;
  2891. std::set<cmStdString>& Languages;
  2892. cmTarget* HeadTarget;
  2893. std::set<cmTarget*> Visited;
  2894. };
  2895. //----------------------------------------------------------------------------
  2896. const char* cmTarget::GetLinkerLanguage(const char* config, cmTarget *head)
  2897. {
  2898. cmTarget *headTarget = head ? head : this;
  2899. const char* lang = this->GetLinkClosure(config, headTarget)
  2900. ->LinkerLanguage.c_str();
  2901. return *lang? lang : 0;
  2902. }
  2903. //----------------------------------------------------------------------------
  2904. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
  2905. cmTarget *head)
  2906. {
  2907. TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
  2908. cmTargetInternals::LinkClosureMapType::iterator
  2909. i = this->Internal->LinkClosureMap.find(key);
  2910. if(i == this->Internal->LinkClosureMap.end())
  2911. {
  2912. LinkClosure lc;
  2913. this->ComputeLinkClosure(config, lc, head);
  2914. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2915. i = this->Internal->LinkClosureMap.insert(entry).first;
  2916. }
  2917. return &i->second;
  2918. }
  2919. //----------------------------------------------------------------------------
  2920. class cmTargetSelectLinker
  2921. {
  2922. int Preference;
  2923. cmTarget* Target;
  2924. cmMakefile* Makefile;
  2925. cmGlobalGenerator* GG;
  2926. std::set<cmStdString> Preferred;
  2927. public:
  2928. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  2929. {
  2930. this->Makefile = this->Target->GetMakefile();
  2931. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  2932. }
  2933. void Consider(const char* lang)
  2934. {
  2935. int preference = this->GG->GetLinkerPreference(lang);
  2936. if(preference > this->Preference)
  2937. {
  2938. this->Preference = preference;
  2939. this->Preferred.clear();
  2940. }
  2941. if(preference == this->Preference)
  2942. {
  2943. this->Preferred.insert(lang);
  2944. }
  2945. }
  2946. std::string Choose()
  2947. {
  2948. if(this->Preferred.empty())
  2949. {
  2950. return "";
  2951. }
  2952. else if(this->Preferred.size() > 1)
  2953. {
  2954. cmOStringStream e;
  2955. e << "Target " << this->Target->GetName()
  2956. << " contains multiple languages with the highest linker preference"
  2957. << " (" << this->Preference << "):\n";
  2958. for(std::set<cmStdString>::const_iterator
  2959. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  2960. {
  2961. e << " " << *li << "\n";
  2962. }
  2963. e << "Set the LINKER_LANGUAGE property for this target.";
  2964. cmake* cm = this->Makefile->GetCMakeInstance();
  2965. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  2966. this->Target->GetBacktrace());
  2967. }
  2968. return *this->Preferred.begin();
  2969. }
  2970. };
  2971. //----------------------------------------------------------------------------
  2972. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
  2973. cmTarget *head)
  2974. {
  2975. // Get languages built in this target.
  2976. std::set<cmStdString> languages;
  2977. LinkImplementation const* impl = this->GetLinkImplementation(config, head);
  2978. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2979. li != impl->Languages.end(); ++li)
  2980. {
  2981. languages.insert(*li);
  2982. }
  2983. // Add interface languages from linked targets.
  2984. cmTargetCollectLinkLanguages cll(this, config, languages, head);
  2985. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  2986. li != impl->Libraries.end(); ++li)
  2987. {
  2988. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  2989. }
  2990. // Store the transitive closure of languages.
  2991. for(std::set<cmStdString>::const_iterator li = languages.begin();
  2992. li != languages.end(); ++li)
  2993. {
  2994. lc.Languages.push_back(*li);
  2995. }
  2996. // Choose the language whose linker should be used.
  2997. if(this->GetProperty("HAS_CXX"))
  2998. {
  2999. lc.LinkerLanguage = "CXX";
  3000. }
  3001. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3002. {
  3003. lc.LinkerLanguage = linkerLang;
  3004. }
  3005. else
  3006. {
  3007. // Find the language with the highest preference value.
  3008. cmTargetSelectLinker tsl(this);
  3009. // First select from the languages compiled directly in this target.
  3010. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3011. li != impl->Languages.end(); ++li)
  3012. {
  3013. tsl.Consider(li->c_str());
  3014. }
  3015. // Now consider languages that propagate from linked targets.
  3016. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  3017. sit != languages.end(); ++sit)
  3018. {
  3019. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3020. if(this->Makefile->IsOn(propagates.c_str()))
  3021. {
  3022. tsl.Consider(sit->c_str());
  3023. }
  3024. }
  3025. lc.LinkerLanguage = tsl.Choose();
  3026. }
  3027. }
  3028. //----------------------------------------------------------------------------
  3029. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  3030. {
  3031. switch(this->GetType())
  3032. {
  3033. case cmTarget::STATIC_LIBRARY:
  3034. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3035. case cmTarget::SHARED_LIBRARY:
  3036. return (implib
  3037. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3038. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3039. case cmTarget::MODULE_LIBRARY:
  3040. return (implib
  3041. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3042. : "CMAKE_SHARED_MODULE_SUFFIX");
  3043. case cmTarget::EXECUTABLE:
  3044. return (implib
  3045. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3046. : "CMAKE_EXECUTABLE_SUFFIX");
  3047. default:
  3048. break;
  3049. }
  3050. return "";
  3051. }
  3052. //----------------------------------------------------------------------------
  3053. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  3054. {
  3055. switch(this->GetType())
  3056. {
  3057. case cmTarget::STATIC_LIBRARY:
  3058. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3059. case cmTarget::SHARED_LIBRARY:
  3060. return (implib
  3061. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3062. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3063. case cmTarget::MODULE_LIBRARY:
  3064. return (implib
  3065. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3066. : "CMAKE_SHARED_MODULE_PREFIX");
  3067. case cmTarget::EXECUTABLE:
  3068. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  3069. default:
  3070. break;
  3071. }
  3072. return "";
  3073. }
  3074. //----------------------------------------------------------------------------
  3075. std::string cmTarget::GetPDBName(const char* config)
  3076. {
  3077. std::string prefix;
  3078. std::string base;
  3079. std::string suffix;
  3080. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3081. std::vector<std::string> props;
  3082. std::string configUpper =
  3083. cmSystemTools::UpperCase(config? config : "");
  3084. if(!configUpper.empty())
  3085. {
  3086. // PDB_NAME_<CONFIG>
  3087. props.push_back("PDB_NAME_" + configUpper);
  3088. }
  3089. // PDB_NAME
  3090. props.push_back("PDB_NAME");
  3091. for(std::vector<std::string>::const_iterator i = props.begin();
  3092. i != props.end(); ++i)
  3093. {
  3094. if(const char* outName = this->GetProperty(i->c_str()))
  3095. {
  3096. base = outName;
  3097. break;
  3098. }
  3099. }
  3100. return prefix+base+".pdb";
  3101. }
  3102. //----------------------------------------------------------------------------
  3103. bool cmTarget::HasSOName(const char* config)
  3104. {
  3105. // soname is supported only for shared libraries and modules,
  3106. // and then only when the platform supports an soname flag.
  3107. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3108. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3109. !this->GetPropertyAsBool("NO_SONAME") &&
  3110. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
  3111. this)));
  3112. }
  3113. //----------------------------------------------------------------------------
  3114. std::string cmTarget::GetSOName(const char* config)
  3115. {
  3116. if(this->IsImported())
  3117. {
  3118. // Lookup the imported soname.
  3119. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3120. {
  3121. if(info->NoSOName)
  3122. {
  3123. // The imported library has no builtin soname so the name
  3124. // searched at runtime will be just the filename.
  3125. return cmSystemTools::GetFilenameName(info->Location);
  3126. }
  3127. else
  3128. {
  3129. // Use the soname given if any.
  3130. return info->SOName;
  3131. }
  3132. }
  3133. else
  3134. {
  3135. return "";
  3136. }
  3137. }
  3138. else
  3139. {
  3140. // Compute the soname that will be built.
  3141. std::string name;
  3142. std::string soName;
  3143. std::string realName;
  3144. std::string impName;
  3145. std::string pdbName;
  3146. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3147. return soName;
  3148. }
  3149. }
  3150. //----------------------------------------------------------------------------
  3151. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  3152. {
  3153. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3154. {
  3155. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3156. {
  3157. return info->NoSOName;
  3158. }
  3159. }
  3160. return false;
  3161. }
  3162. //----------------------------------------------------------------------------
  3163. std::string cmTarget::NormalGetRealName(const char* config)
  3164. {
  3165. // This should not be called for imported targets.
  3166. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3167. // enforcement of the limited imported target API.
  3168. if(this->IsImported())
  3169. {
  3170. std::string msg = "NormalGetRealName called on imported target: ";
  3171. msg += this->GetName();
  3172. this->GetMakefile()->
  3173. IssueMessage(cmake::INTERNAL_ERROR,
  3174. msg.c_str());
  3175. }
  3176. if(this->GetType() == cmTarget::EXECUTABLE)
  3177. {
  3178. // Compute the real name that will be built.
  3179. std::string name;
  3180. std::string realName;
  3181. std::string impName;
  3182. std::string pdbName;
  3183. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3184. return realName;
  3185. }
  3186. else
  3187. {
  3188. // Compute the real name that will be built.
  3189. std::string name;
  3190. std::string soName;
  3191. std::string realName;
  3192. std::string impName;
  3193. std::string pdbName;
  3194. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3195. return realName;
  3196. }
  3197. }
  3198. //----------------------------------------------------------------------------
  3199. std::string cmTarget::GetFullName(const char* config, bool implib)
  3200. {
  3201. if(this->IsImported())
  3202. {
  3203. return this->GetFullNameImported(config, implib);
  3204. }
  3205. else
  3206. {
  3207. return this->GetFullNameInternal(config, implib);
  3208. }
  3209. }
  3210. //----------------------------------------------------------------------------
  3211. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  3212. {
  3213. return cmSystemTools::GetFilenameName(
  3214. this->ImportedGetFullPath(config, implib));
  3215. }
  3216. //----------------------------------------------------------------------------
  3217. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3218. std::string& suffix, const char* config,
  3219. bool implib)
  3220. {
  3221. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3222. }
  3223. //----------------------------------------------------------------------------
  3224. std::string cmTarget::GetFullPath(const char* config, bool implib,
  3225. bool realname)
  3226. {
  3227. if(this->IsImported())
  3228. {
  3229. return this->ImportedGetFullPath(config, implib);
  3230. }
  3231. else
  3232. {
  3233. return this->NormalGetFullPath(config, implib, realname);
  3234. }
  3235. }
  3236. //----------------------------------------------------------------------------
  3237. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  3238. bool realname)
  3239. {
  3240. std::string fpath = this->GetMacContentDirectory(config, implib);
  3241. // Add the full name of the target.
  3242. if(implib)
  3243. {
  3244. fpath += this->GetFullName(config, true);
  3245. }
  3246. else if(realname)
  3247. {
  3248. fpath += this->NormalGetRealName(config);
  3249. }
  3250. else
  3251. {
  3252. fpath += this->GetFullName(config, false);
  3253. }
  3254. return fpath;
  3255. }
  3256. //----------------------------------------------------------------------------
  3257. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  3258. {
  3259. std::string result;
  3260. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3261. {
  3262. result = implib? info->ImportLibrary : info->Location;
  3263. }
  3264. if(result.empty())
  3265. {
  3266. result = this->GetName();
  3267. result += "-NOTFOUND";
  3268. }
  3269. return result;
  3270. }
  3271. //----------------------------------------------------------------------------
  3272. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  3273. {
  3274. std::string prefix;
  3275. std::string base;
  3276. std::string suffix;
  3277. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3278. return prefix+base+suffix;
  3279. }
  3280. //----------------------------------------------------------------------------
  3281. void cmTarget::GetFullNameInternal(const char* config,
  3282. bool implib,
  3283. std::string& outPrefix,
  3284. std::string& outBase,
  3285. std::string& outSuffix)
  3286. {
  3287. // Use just the target name for non-main target types.
  3288. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3289. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3290. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3291. this->GetType() != cmTarget::EXECUTABLE)
  3292. {
  3293. outPrefix = "";
  3294. outBase = this->GetName();
  3295. outSuffix = "";
  3296. return;
  3297. }
  3298. // Return an empty name for the import library if this platform
  3299. // does not support import libraries.
  3300. if(implib &&
  3301. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3302. {
  3303. outPrefix = "";
  3304. outBase = "";
  3305. outSuffix = "";
  3306. return;
  3307. }
  3308. // The implib option is only allowed for shared libraries, module
  3309. // libraries, and executables.
  3310. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3311. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3312. this->GetType() != cmTarget::EXECUTABLE)
  3313. {
  3314. implib = false;
  3315. }
  3316. // Compute the full name for main target types.
  3317. const char* targetPrefix = (implib
  3318. ? this->GetProperty("IMPORT_PREFIX")
  3319. : this->GetProperty("PREFIX"));
  3320. const char* targetSuffix = (implib
  3321. ? this->GetProperty("IMPORT_SUFFIX")
  3322. : this->GetProperty("SUFFIX"));
  3323. const char* configPostfix = 0;
  3324. if(config && *config)
  3325. {
  3326. std::string configProp = cmSystemTools::UpperCase(config);
  3327. configProp += "_POSTFIX";
  3328. configPostfix = this->GetProperty(configProp.c_str());
  3329. // Mac application bundles and frameworks have no postfix.
  3330. if(configPostfix &&
  3331. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3332. {
  3333. configPostfix = 0;
  3334. }
  3335. }
  3336. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3337. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3338. // Check for language-specific default prefix and suffix.
  3339. if(const char* ll = this->GetLinkerLanguage(config, this))
  3340. {
  3341. if(!targetSuffix && suffixVar && *suffixVar)
  3342. {
  3343. std::string langSuff = suffixVar + std::string("_") + ll;
  3344. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  3345. }
  3346. if(!targetPrefix && prefixVar && *prefixVar)
  3347. {
  3348. std::string langPrefix = prefixVar + std::string("_") + ll;
  3349. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  3350. }
  3351. }
  3352. // if there is no prefix on the target use the cmake definition
  3353. if(!targetPrefix && prefixVar)
  3354. {
  3355. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3356. }
  3357. // if there is no suffix on the target use the cmake definition
  3358. if(!targetSuffix && suffixVar)
  3359. {
  3360. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3361. }
  3362. // frameworks do not have a prefix or a suffix
  3363. if(this->IsFrameworkOnApple())
  3364. {
  3365. targetPrefix = 0;
  3366. targetSuffix = 0;
  3367. }
  3368. // Begin the final name with the prefix.
  3369. outPrefix = targetPrefix?targetPrefix:"";
  3370. // Append the target name or property-specified name.
  3371. outBase += this->GetOutputName(config, implib);
  3372. // Append the per-configuration postfix.
  3373. outBase += configPostfix?configPostfix:"";
  3374. // Name shared libraries with their version number on some platforms.
  3375. if(const char* soversion = this->GetProperty("SOVERSION"))
  3376. {
  3377. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3378. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3379. {
  3380. outBase += "-";
  3381. outBase += soversion;
  3382. }
  3383. }
  3384. // Append the suffix.
  3385. outSuffix = targetSuffix?targetSuffix:"";
  3386. }
  3387. //----------------------------------------------------------------------------
  3388. void cmTarget::GetLibraryNames(std::string& name,
  3389. std::string& soName,
  3390. std::string& realName,
  3391. std::string& impName,
  3392. std::string& pdbName,
  3393. const char* config)
  3394. {
  3395. // This should not be called for imported targets.
  3396. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3397. // enforcement of the limited imported target API.
  3398. if(this->IsImported())
  3399. {
  3400. std::string msg = "GetLibraryNames called on imported target: ";
  3401. msg += this->GetName();
  3402. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3403. msg.c_str());
  3404. return;
  3405. }
  3406. // Check for library version properties.
  3407. const char* version = this->GetProperty("VERSION");
  3408. const char* soversion = this->GetProperty("SOVERSION");
  3409. if(!this->HasSOName(config) ||
  3410. this->IsFrameworkOnApple())
  3411. {
  3412. // Versioning is supported only for shared libraries and modules,
  3413. // and then only when the platform supports an soname flag.
  3414. version = 0;
  3415. soversion = 0;
  3416. }
  3417. if(version && !soversion)
  3418. {
  3419. // The soversion must be set if the library version is set. Use
  3420. // the library version as the soversion.
  3421. soversion = version;
  3422. }
  3423. if(!version && soversion)
  3424. {
  3425. // Use the soversion as the library version.
  3426. version = soversion;
  3427. }
  3428. // Get the components of the library name.
  3429. std::string prefix;
  3430. std::string base;
  3431. std::string suffix;
  3432. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3433. // The library name.
  3434. name = prefix+base+suffix;
  3435. // The library's soname.
  3436. this->ComputeVersionedName(soName, prefix, base, suffix,
  3437. name, soversion);
  3438. // The library's real name on disk.
  3439. this->ComputeVersionedName(realName, prefix, base, suffix,
  3440. name, version);
  3441. // The import library name.
  3442. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3443. this->GetType() == cmTarget::MODULE_LIBRARY)
  3444. {
  3445. impName = this->GetFullNameInternal(config, true);
  3446. }
  3447. else
  3448. {
  3449. impName = "";
  3450. }
  3451. // The program database file name.
  3452. pdbName = this->GetPDBName(config);
  3453. }
  3454. //----------------------------------------------------------------------------
  3455. void cmTarget::ComputeVersionedName(std::string& vName,
  3456. std::string const& prefix,
  3457. std::string const& base,
  3458. std::string const& suffix,
  3459. std::string const& name,
  3460. const char* version)
  3461. {
  3462. vName = this->IsApple? (prefix+base) : name;
  3463. if(version)
  3464. {
  3465. vName += ".";
  3466. vName += version;
  3467. }
  3468. vName += this->IsApple? suffix : std::string();
  3469. }
  3470. //----------------------------------------------------------------------------
  3471. void cmTarget::GetExecutableNames(std::string& name,
  3472. std::string& realName,
  3473. std::string& impName,
  3474. std::string& pdbName,
  3475. const char* config)
  3476. {
  3477. // This should not be called for imported targets.
  3478. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3479. // enforcement of the limited imported target API.
  3480. if(this->IsImported())
  3481. {
  3482. std::string msg =
  3483. "GetExecutableNames called on imported target: ";
  3484. msg += this->GetName();
  3485. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3486. }
  3487. // This versioning is supported only for executables and then only
  3488. // when the platform supports symbolic links.
  3489. #if defined(_WIN32) && !defined(__CYGWIN__)
  3490. const char* version = 0;
  3491. #else
  3492. // Check for executable version properties.
  3493. const char* version = this->GetProperty("VERSION");
  3494. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3495. {
  3496. version = 0;
  3497. }
  3498. #endif
  3499. // Get the components of the executable name.
  3500. std::string prefix;
  3501. std::string base;
  3502. std::string suffix;
  3503. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3504. // The executable name.
  3505. name = prefix+base+suffix;
  3506. // The executable's real name on disk.
  3507. #if defined(__CYGWIN__)
  3508. realName = prefix+base;
  3509. #else
  3510. realName = name;
  3511. #endif
  3512. if(version)
  3513. {
  3514. realName += "-";
  3515. realName += version;
  3516. }
  3517. #if defined(__CYGWIN__)
  3518. realName += suffix;
  3519. #endif
  3520. // The import library name.
  3521. impName = this->GetFullNameInternal(config, true);
  3522. // The program database file name.
  3523. pdbName = this->GetPDBName(config);
  3524. }
  3525. //----------------------------------------------------------------------------
  3526. bool cmTarget::HasImplibGNUtoMS()
  3527. {
  3528. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3529. }
  3530. //----------------------------------------------------------------------------
  3531. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3532. std::string& out, const char* newExt)
  3533. {
  3534. if(this->HasImplibGNUtoMS() &&
  3535. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3536. {
  3537. out = gnuName.substr(0, gnuName.size()-6);
  3538. out += newExt? newExt : ".lib";
  3539. return true;
  3540. }
  3541. return false;
  3542. }
  3543. //----------------------------------------------------------------------------
  3544. void cmTarget::GenerateTargetManifest(const char* config)
  3545. {
  3546. cmMakefile* mf = this->Makefile;
  3547. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3548. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3549. // Get the names.
  3550. std::string name;
  3551. std::string soName;
  3552. std::string realName;
  3553. std::string impName;
  3554. std::string pdbName;
  3555. if(this->GetType() == cmTarget::EXECUTABLE)
  3556. {
  3557. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3558. }
  3559. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3560. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3561. this->GetType() == cmTarget::MODULE_LIBRARY)
  3562. {
  3563. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3564. }
  3565. else
  3566. {
  3567. return;
  3568. }
  3569. // Get the directory.
  3570. std::string dir = this->GetDirectory(config, false);
  3571. // Add each name.
  3572. std::string f;
  3573. if(!name.empty())
  3574. {
  3575. f = dir;
  3576. f += "/";
  3577. f += name;
  3578. gg->AddToManifest(config? config:"", f);
  3579. }
  3580. if(!soName.empty())
  3581. {
  3582. f = dir;
  3583. f += "/";
  3584. f += soName;
  3585. gg->AddToManifest(config? config:"", f);
  3586. }
  3587. if(!realName.empty())
  3588. {
  3589. f = dir;
  3590. f += "/";
  3591. f += realName;
  3592. gg->AddToManifest(config? config:"", f);
  3593. }
  3594. if(!pdbName.empty())
  3595. {
  3596. f = this->GetPDBDirectory(config);
  3597. f += "/";
  3598. f += pdbName;
  3599. gg->AddToManifest(config? config:"", f);
  3600. }
  3601. if(!impName.empty())
  3602. {
  3603. f = this->GetDirectory(config, true);
  3604. f += "/";
  3605. f += impName;
  3606. gg->AddToManifest(config? config:"", f);
  3607. }
  3608. }
  3609. //----------------------------------------------------------------------------
  3610. void cmTarget::SetPropertyDefault(const char* property,
  3611. const char* default_value)
  3612. {
  3613. // Compute the name of the variable holding the default value.
  3614. std::string var = "CMAKE_";
  3615. var += property;
  3616. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3617. {
  3618. this->SetProperty(property, value);
  3619. }
  3620. else if(default_value)
  3621. {
  3622. this->SetProperty(property, default_value);
  3623. }
  3624. }
  3625. //----------------------------------------------------------------------------
  3626. bool cmTarget::HaveBuildTreeRPATH()
  3627. {
  3628. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  3629. !this->LinkLibraries.empty());
  3630. }
  3631. //----------------------------------------------------------------------------
  3632. bool cmTarget::HaveInstallTreeRPATH()
  3633. {
  3634. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3635. return (install_rpath && *install_rpath) &&
  3636. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3637. }
  3638. //----------------------------------------------------------------------------
  3639. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3640. {
  3641. // Only executables and shared libraries can have an rpath and may
  3642. // need relinking.
  3643. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3644. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3645. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3646. {
  3647. return false;
  3648. }
  3649. // If there is no install location this target will not be installed
  3650. // and therefore does not need relinking.
  3651. if(!this->GetHaveInstallRule())
  3652. {
  3653. return false;
  3654. }
  3655. // If skipping all rpaths completely then no relinking is needed.
  3656. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3657. {
  3658. return false;
  3659. }
  3660. // If building with the install-tree rpath no relinking is needed.
  3661. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3662. {
  3663. return false;
  3664. }
  3665. // If chrpath is going to be used no relinking is needed.
  3666. if(this->IsChrpathUsed(config))
  3667. {
  3668. return false;
  3669. }
  3670. // Check for rpath support on this platform.
  3671. if(const char* ll = this->GetLinkerLanguage(config, this))
  3672. {
  3673. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3674. flagVar += ll;
  3675. flagVar += "_FLAG";
  3676. if(!this->Makefile->IsSet(flagVar.c_str()))
  3677. {
  3678. // There is no rpath support on this platform so nothing needs
  3679. // relinking.
  3680. return false;
  3681. }
  3682. }
  3683. else
  3684. {
  3685. // No linker language is known. This error will be reported by
  3686. // other code.
  3687. return false;
  3688. }
  3689. // If either a build or install tree rpath is set then the rpath
  3690. // will likely change between the build tree and install tree and
  3691. // this target must be relinked.
  3692. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  3693. }
  3694. //----------------------------------------------------------------------------
  3695. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  3696. bool for_xcode)
  3697. {
  3698. // If building directly for installation then the build tree install_name
  3699. // is the same as the install tree.
  3700. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3701. {
  3702. return GetInstallNameDirForInstallTree(config, for_xcode);
  3703. }
  3704. // Use the build tree directory for the target.
  3705. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3706. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3707. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3708. {
  3709. std::string dir = this->GetDirectory(config);
  3710. dir += "/";
  3711. if(this->IsFrameworkOnApple() && !for_xcode)
  3712. {
  3713. dir += this->GetFrameworkDirectory(config);
  3714. }
  3715. return dir;
  3716. }
  3717. else
  3718. {
  3719. return "";
  3720. }
  3721. }
  3722. //----------------------------------------------------------------------------
  3723. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  3724. bool for_xcode)
  3725. {
  3726. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3727. {
  3728. std::string dir;
  3729. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3730. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  3731. {
  3732. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3733. if(install_name_dir && *install_name_dir)
  3734. {
  3735. dir = install_name_dir;
  3736. dir += "/";
  3737. }
  3738. }
  3739. if(this->IsFrameworkOnApple() && !for_xcode)
  3740. {
  3741. dir += this->GetFrameworkDirectory(config);
  3742. }
  3743. return dir;
  3744. }
  3745. else
  3746. {
  3747. return "";
  3748. }
  3749. }
  3750. //----------------------------------------------------------------------------
  3751. const char* cmTarget::GetOutputTargetType(bool implib)
  3752. {
  3753. switch(this->GetType())
  3754. {
  3755. case cmTarget::SHARED_LIBRARY:
  3756. if(this->DLLPlatform)
  3757. {
  3758. if(implib)
  3759. {
  3760. // A DLL import library is treated as an archive target.
  3761. return "ARCHIVE";
  3762. }
  3763. else
  3764. {
  3765. // A DLL shared library is treated as a runtime target.
  3766. return "RUNTIME";
  3767. }
  3768. }
  3769. else
  3770. {
  3771. // For non-DLL platforms shared libraries are treated as
  3772. // library targets.
  3773. return "LIBRARY";
  3774. }
  3775. case cmTarget::STATIC_LIBRARY:
  3776. // Static libraries are always treated as archive targets.
  3777. return "ARCHIVE";
  3778. case cmTarget::MODULE_LIBRARY:
  3779. if(implib)
  3780. {
  3781. // Module libraries are always treated as library targets.
  3782. return "ARCHIVE";
  3783. }
  3784. else
  3785. {
  3786. // Module import libraries are treated as archive targets.
  3787. return "LIBRARY";
  3788. }
  3789. case cmTarget::EXECUTABLE:
  3790. if(implib)
  3791. {
  3792. // Executable import libraries are treated as archive targets.
  3793. return "ARCHIVE";
  3794. }
  3795. else
  3796. {
  3797. // Executables are always treated as runtime targets.
  3798. return "RUNTIME";
  3799. }
  3800. default:
  3801. break;
  3802. }
  3803. return "";
  3804. }
  3805. //----------------------------------------------------------------------------
  3806. bool cmTarget::ComputeOutputDir(const char* config,
  3807. bool implib, std::string& out)
  3808. {
  3809. bool usesDefaultOutputDir = false;
  3810. // Look for a target property defining the target output directory
  3811. // based on the target type.
  3812. std::string targetTypeName = this->GetOutputTargetType(implib);
  3813. const char* propertyName = 0;
  3814. std::string propertyNameStr = targetTypeName;
  3815. if(!propertyNameStr.empty())
  3816. {
  3817. propertyNameStr += "_OUTPUT_DIRECTORY";
  3818. propertyName = propertyNameStr.c_str();
  3819. }
  3820. // Check for a per-configuration output directory target property.
  3821. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3822. const char* configProp = 0;
  3823. std::string configPropStr = targetTypeName;
  3824. if(!configPropStr.empty())
  3825. {
  3826. configPropStr += "_OUTPUT_DIRECTORY_";
  3827. configPropStr += configUpper;
  3828. configProp = configPropStr.c_str();
  3829. }
  3830. // Select an output directory.
  3831. if(const char* config_outdir = this->GetProperty(configProp))
  3832. {
  3833. // Use the user-specified per-configuration output directory.
  3834. out = config_outdir;
  3835. // Skip per-configuration subdirectory.
  3836. config = 0;
  3837. }
  3838. else if(const char* outdir = this->GetProperty(propertyName))
  3839. {
  3840. // Use the user-specified output directory.
  3841. out = outdir;
  3842. }
  3843. else if(this->GetType() == cmTarget::EXECUTABLE)
  3844. {
  3845. // Lookup the output path for executables.
  3846. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3847. }
  3848. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3849. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3850. this->GetType() == cmTarget::MODULE_LIBRARY)
  3851. {
  3852. // Lookup the output path for libraries.
  3853. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3854. }
  3855. if(out.empty())
  3856. {
  3857. // Default to the current output directory.
  3858. usesDefaultOutputDir = true;
  3859. out = ".";
  3860. }
  3861. // Convert the output path to a full path in case it is
  3862. // specified as a relative path. Treat a relative path as
  3863. // relative to the current output directory for this makefile.
  3864. out = (cmSystemTools::CollapseFullPath
  3865. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3866. // The generator may add the configuration's subdirectory.
  3867. if(config && *config)
  3868. {
  3869. const char *platforms = this->Makefile->GetDefinition(
  3870. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3871. std::string suffix =
  3872. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3873. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3874. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  3875. }
  3876. return usesDefaultOutputDir;
  3877. }
  3878. //----------------------------------------------------------------------------
  3879. bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
  3880. {
  3881. // Look for a target property defining the target output directory
  3882. // based on the target type.
  3883. std::string targetTypeName = "PDB";
  3884. const char* propertyName = 0;
  3885. std::string propertyNameStr = targetTypeName;
  3886. if(!propertyNameStr.empty())
  3887. {
  3888. propertyNameStr += "_OUTPUT_DIRECTORY";
  3889. propertyName = propertyNameStr.c_str();
  3890. }
  3891. // Check for a per-configuration output directory target property.
  3892. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3893. const char* configProp = 0;
  3894. std::string configPropStr = targetTypeName;
  3895. if(!configPropStr.empty())
  3896. {
  3897. configPropStr += "_OUTPUT_DIRECTORY_";
  3898. configPropStr += configUpper;
  3899. configProp = configPropStr.c_str();
  3900. }
  3901. // Select an output directory.
  3902. if(const char* config_outdir = this->GetProperty(configProp))
  3903. {
  3904. // Use the user-specified per-configuration output directory.
  3905. out = config_outdir;
  3906. // Skip per-configuration subdirectory.
  3907. config = 0;
  3908. }
  3909. else if(const char* outdir = this->GetProperty(propertyName))
  3910. {
  3911. // Use the user-specified output directory.
  3912. out = outdir;
  3913. }
  3914. if(out.empty())
  3915. {
  3916. return false;
  3917. }
  3918. // Convert the output path to a full path in case it is
  3919. // specified as a relative path. Treat a relative path as
  3920. // relative to the current output directory for this makefile.
  3921. out = (cmSystemTools::CollapseFullPath
  3922. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3923. // The generator may add the configuration's subdirectory.
  3924. if(config && *config)
  3925. {
  3926. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3927. AppendDirectoryForConfig("/", config, "", out);
  3928. }
  3929. return true;
  3930. }
  3931. //----------------------------------------------------------------------------
  3932. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
  3933. {
  3934. std::string dir;
  3935. return this->ComputeOutputDir(config, implib, dir);
  3936. }
  3937. //----------------------------------------------------------------------------
  3938. std::string cmTarget::GetOutputName(const char* config, bool implib)
  3939. {
  3940. std::vector<std::string> props;
  3941. std::string type = this->GetOutputTargetType(implib);
  3942. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3943. if(!type.empty() && !configUpper.empty())
  3944. {
  3945. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3946. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3947. }
  3948. if(!type.empty())
  3949. {
  3950. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3951. props.push_back(type + "_OUTPUT_NAME");
  3952. }
  3953. if(!configUpper.empty())
  3954. {
  3955. // OUTPUT_NAME_<CONFIG>
  3956. props.push_back("OUTPUT_NAME_" + configUpper);
  3957. // <CONFIG>_OUTPUT_NAME
  3958. props.push_back(configUpper + "_OUTPUT_NAME");
  3959. }
  3960. // OUTPUT_NAME
  3961. props.push_back("OUTPUT_NAME");
  3962. for(std::vector<std::string>::const_iterator i = props.begin();
  3963. i != props.end(); ++i)
  3964. {
  3965. if(const char* outName = this->GetProperty(i->c_str()))
  3966. {
  3967. return outName;
  3968. }
  3969. }
  3970. return this->GetName();
  3971. }
  3972. //----------------------------------------------------------------------------
  3973. std::string cmTarget::GetFrameworkVersion()
  3974. {
  3975. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3976. {
  3977. return fversion;
  3978. }
  3979. else if(const char* tversion = this->GetProperty("VERSION"))
  3980. {
  3981. return tversion;
  3982. }
  3983. else
  3984. {
  3985. return "A";
  3986. }
  3987. }
  3988. //----------------------------------------------------------------------------
  3989. const char* cmTarget::GetExportMacro()
  3990. {
  3991. // Define the symbol for targets that export symbols.
  3992. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3993. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3994. this->IsExecutableWithExports())
  3995. {
  3996. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3997. {
  3998. this->ExportMacro = custom_export_name;
  3999. }
  4000. else
  4001. {
  4002. std::string in = this->GetName();
  4003. in += "_EXPORTS";
  4004. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4005. }
  4006. return this->ExportMacro.c_str();
  4007. }
  4008. else
  4009. {
  4010. return 0;
  4011. }
  4012. }
  4013. //----------------------------------------------------------------------------
  4014. void cmTarget::GetLinkDependentTargetsForProperty(const std::string &p,
  4015. std::set<std::string> &targets)
  4016. {
  4017. const std::map<cmStdString, std::set<std::string> >::const_iterator findIt
  4018. = this->LinkDependentProperties.find(p);
  4019. if (findIt != this->LinkDependentProperties.end())
  4020. {
  4021. targets = findIt->second;
  4022. }
  4023. }
  4024. //----------------------------------------------------------------------------
  4025. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p)
  4026. {
  4027. return this->LinkImplicitNullProperties.find(p)
  4028. != this->LinkImplicitNullProperties.end();
  4029. }
  4030. //----------------------------------------------------------------------------
  4031. void cmTarget::AddLinkDependentTargetsForProperties(
  4032. const std::map<cmStdString, cmStdString> &map)
  4033. {
  4034. for (std::map<cmStdString, cmStdString>::const_iterator it = map.begin();
  4035. it != map.end(); ++it)
  4036. {
  4037. std::vector<std::string> targets;
  4038. cmSystemTools::ExpandListArgument(it->second.c_str(), targets);
  4039. this->LinkDependentProperties[it->first].insert(targets.begin(),
  4040. targets.end());
  4041. if (!this->GetProperty(it->first.c_str()))
  4042. {
  4043. this->LinkImplicitNullProperties.insert(it->first);
  4044. }
  4045. }
  4046. }
  4047. //----------------------------------------------------------------------------
  4048. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4049. const char *config)
  4050. {
  4051. bool propContent = this->GetPropertyAsBool(p.c_str());
  4052. const bool explicitlySet = this->GetProperties()
  4053. .find(p.c_str())
  4054. != this->GetProperties().end();
  4055. std::set<std::string> dependentTargets;
  4056. this->GetLinkDependentTargetsForProperty(p,
  4057. dependentTargets);
  4058. const bool impliedByUse =
  4059. this->IsNullImpliedByLinkLibraries(p);
  4060. assert((impliedByUse ^ explicitlySet)
  4061. || (!impliedByUse && !explicitlySet));
  4062. cmComputeLinkInformation *info = this->GetLinkInformation(config);
  4063. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  4064. bool propInitialized = explicitlySet;
  4065. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  4066. deps.begin();
  4067. li != deps.end(); ++li)
  4068. {
  4069. // An error should be reported if one dependency
  4070. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4071. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4072. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4073. // with a dependency.
  4074. if (!li->Target)
  4075. {
  4076. continue;
  4077. }
  4078. const bool ifaceIsSet = li->Target->GetProperties()
  4079. .find("INTERFACE_" + p)
  4080. != li->Target->GetProperties().end();
  4081. const bool ifacePropContent = li->Target->GetPropertyAsBool(
  4082. ("INTERFACE_" + p).c_str());
  4083. if (explicitlySet)
  4084. {
  4085. if (ifaceIsSet)
  4086. {
  4087. if (propContent != ifacePropContent)
  4088. {
  4089. cmOStringStream e;
  4090. e << "Property " << p << " on target \""
  4091. << this->GetName() << "\" does\nnot match the "
  4092. "INTERFACE_" << p << " property requirement\nof "
  4093. "dependency \"" << li->Target->GetName() << "\".\n";
  4094. cmSystemTools::Error(e.str().c_str());
  4095. }
  4096. else
  4097. {
  4098. // Agree
  4099. continue;
  4100. }
  4101. }
  4102. else
  4103. {
  4104. // Explicitly set on target and not set in iface. Can't disagree.
  4105. continue;
  4106. }
  4107. }
  4108. else if (impliedByUse)
  4109. {
  4110. if (ifaceIsSet)
  4111. {
  4112. if (propContent != ifacePropContent)
  4113. {
  4114. cmOStringStream e;
  4115. e << "Property " << p << " on target \""
  4116. << this->GetName() << "\" is\nimplied to be FALSE because it "
  4117. "was used to determine the link libraries\nalready. The "
  4118. "INTERFACE_" << p << " property on\ndependency \""
  4119. << li->Target->GetName() << "\" is in conflict.\n";
  4120. cmSystemTools::Error(e.str().c_str());
  4121. }
  4122. else
  4123. {
  4124. // Agree
  4125. continue;
  4126. }
  4127. }
  4128. else
  4129. {
  4130. // Implicitly set on target and not set in iface. Can't disagree.
  4131. continue;
  4132. }
  4133. }
  4134. else
  4135. {
  4136. if (ifaceIsSet)
  4137. {
  4138. if (propInitialized)
  4139. {
  4140. if (propContent != ifacePropContent)
  4141. {
  4142. cmOStringStream e;
  4143. e << "The INTERFACE_" << p << " property of \""
  4144. << li->Target->GetName() << "\" does\nnot agree with the value "
  4145. "of " << p << " already determined\nfor \""
  4146. << this->GetName() << "\".\n";
  4147. cmSystemTools::Error(e.str().c_str());
  4148. }
  4149. else
  4150. {
  4151. // Agree.
  4152. continue;
  4153. }
  4154. }
  4155. else
  4156. {
  4157. propContent = ifacePropContent;
  4158. propInitialized = true;
  4159. }
  4160. }
  4161. else
  4162. {
  4163. // Not set. Nothing to agree on.
  4164. continue;
  4165. }
  4166. }
  4167. }
  4168. return propContent;
  4169. }
  4170. //----------------------------------------------------------------------------
  4171. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  4172. {
  4173. for(std::vector<cmSourceFile*>::const_iterator
  4174. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  4175. {
  4176. if(const char* lang = (*i)->GetLanguage())
  4177. {
  4178. languages.insert(lang);
  4179. }
  4180. }
  4181. }
  4182. //----------------------------------------------------------------------------
  4183. bool cmTarget::IsChrpathUsed(const char* config)
  4184. {
  4185. #if defined(CMAKE_USE_ELF_PARSER)
  4186. // Only certain target types have an rpath.
  4187. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4188. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4189. this->GetType() == cmTarget::EXECUTABLE))
  4190. {
  4191. return false;
  4192. }
  4193. // If the target will not be installed we do not need to change its
  4194. // rpath.
  4195. if(!this->GetHaveInstallRule())
  4196. {
  4197. return false;
  4198. }
  4199. // Skip chrpath if skipping rpath altogether.
  4200. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4201. {
  4202. return false;
  4203. }
  4204. // Skip chrpath if it does not need to be changed at install time.
  4205. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4206. {
  4207. return false;
  4208. }
  4209. // Allow the user to disable builtin chrpath explicitly.
  4210. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4211. {
  4212. return false;
  4213. }
  4214. // Enable if the rpath flag uses a separator and the target uses ELF
  4215. // binaries.
  4216. if(const char* ll = this->GetLinkerLanguage(config, this))
  4217. {
  4218. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4219. sepVar += ll;
  4220. sepVar += "_FLAG_SEP";
  4221. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  4222. if(sep && *sep)
  4223. {
  4224. // TODO: Add ELF check to ABI detection and get rid of
  4225. // CMAKE_EXECUTABLE_FORMAT.
  4226. if(const char* fmt =
  4227. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4228. {
  4229. return strcmp(fmt, "ELF") == 0;
  4230. }
  4231. }
  4232. }
  4233. #endif
  4234. static_cast<void>(config);
  4235. return false;
  4236. }
  4237. //----------------------------------------------------------------------------
  4238. cmTarget::ImportInfo const*
  4239. cmTarget::GetImportInfo(const char* config, cmTarget *headTarget)
  4240. {
  4241. // There is no imported information for non-imported targets.
  4242. if(!this->IsImported())
  4243. {
  4244. return 0;
  4245. }
  4246. // Lookup/compute/cache the import information for this
  4247. // configuration.
  4248. std::string config_upper;
  4249. if(config && *config)
  4250. {
  4251. config_upper = cmSystemTools::UpperCase(config);
  4252. }
  4253. else
  4254. {
  4255. config_upper = "NOCONFIG";
  4256. }
  4257. TargetConfigPair key(headTarget, config_upper);
  4258. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4259. ImportInfoMapType::const_iterator i =
  4260. this->Internal->ImportInfoMap.find(key);
  4261. if(i == this->Internal->ImportInfoMap.end())
  4262. {
  4263. ImportInfo info;
  4264. this->ComputeImportInfo(config_upper, info, headTarget);
  4265. ImportInfoMapType::value_type entry(key, info);
  4266. i = this->Internal->ImportInfoMap.insert(entry).first;
  4267. }
  4268. // If the location is empty then the target is not available for
  4269. // this configuration.
  4270. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4271. {
  4272. return 0;
  4273. }
  4274. // Return the import information.
  4275. return &i->second;
  4276. }
  4277. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4278. const char** loc,
  4279. const char** imp,
  4280. std::string& suffix)
  4281. {
  4282. // Track the configuration-specific property suffix.
  4283. suffix = "_";
  4284. suffix += desired_config;
  4285. std::vector<std::string> mappedConfigs;
  4286. {
  4287. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  4288. mapProp += desired_config;
  4289. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  4290. {
  4291. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  4292. }
  4293. }
  4294. // If we needed to find one of the mapped configurations but did not
  4295. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  4296. // library or an executable with exports.
  4297. bool allowImp = this->HasImportLibrary();
  4298. // If a mapping was found, check its configurations.
  4299. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  4300. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  4301. {
  4302. // Look for this configuration.
  4303. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  4304. std::string locProp = "IMPORTED_LOCATION_";
  4305. locProp += mcUpper;
  4306. *loc = this->GetProperty(locProp.c_str());
  4307. if(allowImp)
  4308. {
  4309. std::string impProp = "IMPORTED_IMPLIB_";
  4310. impProp += mcUpper;
  4311. *imp = this->GetProperty(impProp.c_str());
  4312. }
  4313. // If it was found, use it for all properties below.
  4314. if(*loc || *imp)
  4315. {
  4316. suffix = "_";
  4317. suffix += mcUpper;
  4318. }
  4319. }
  4320. // If we needed to find one of the mapped configurations but did not
  4321. // then the target is not found. The project does not want any
  4322. // other configuration.
  4323. if(!mappedConfigs.empty() && !*loc && !*imp)
  4324. {
  4325. return false;
  4326. }
  4327. // If we have not yet found it then there are no mapped
  4328. // configurations. Look for an exact-match.
  4329. if(!*loc && !*imp)
  4330. {
  4331. std::string locProp = "IMPORTED_LOCATION";
  4332. locProp += suffix;
  4333. *loc = this->GetProperty(locProp.c_str());
  4334. if(allowImp)
  4335. {
  4336. std::string impProp = "IMPORTED_IMPLIB";
  4337. impProp += suffix;
  4338. *imp = this->GetProperty(impProp.c_str());
  4339. }
  4340. }
  4341. // If we have not yet found it then there are no mapped
  4342. // configurations and no exact match.
  4343. if(!*loc && !*imp)
  4344. {
  4345. // The suffix computed above is not useful.
  4346. suffix = "";
  4347. // Look for a configuration-less location. This may be set by
  4348. // manually-written code.
  4349. *loc = this->GetProperty("IMPORTED_LOCATION");
  4350. if(allowImp)
  4351. {
  4352. *imp = this->GetProperty("IMPORTED_IMPLIB");
  4353. }
  4354. }
  4355. // If we have not yet found it then the project is willing to try
  4356. // any available configuration.
  4357. if(!*loc && !*imp)
  4358. {
  4359. std::vector<std::string> availableConfigs;
  4360. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  4361. {
  4362. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  4363. }
  4364. for(std::vector<std::string>::const_iterator
  4365. aci = availableConfigs.begin();
  4366. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  4367. {
  4368. suffix = "_";
  4369. suffix += cmSystemTools::UpperCase(*aci);
  4370. std::string locProp = "IMPORTED_LOCATION";
  4371. locProp += suffix;
  4372. *loc = this->GetProperty(locProp.c_str());
  4373. if(allowImp)
  4374. {
  4375. std::string impProp = "IMPORTED_IMPLIB";
  4376. impProp += suffix;
  4377. *imp = this->GetProperty(impProp.c_str());
  4378. }
  4379. }
  4380. }
  4381. // If we have not yet found it then the target is not available.
  4382. if(!*loc && !*imp)
  4383. {
  4384. return false;
  4385. }
  4386. return true;
  4387. }
  4388. //----------------------------------------------------------------------------
  4389. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  4390. ImportInfo& info,
  4391. cmTarget *headTarget)
  4392. {
  4393. (void)headTarget;
  4394. // This method finds information about an imported target from its
  4395. // properties. The "IMPORTED_" namespace is reserved for properties
  4396. // defined by the project exporting the target.
  4397. // Initialize members.
  4398. info.NoSOName = false;
  4399. const char* loc = 0;
  4400. const char* imp = 0;
  4401. std::string suffix;
  4402. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  4403. {
  4404. return;
  4405. }
  4406. // A provided configuration has been chosen. Load the
  4407. // configuration's properties.
  4408. // Get the location.
  4409. if(loc)
  4410. {
  4411. info.Location = loc;
  4412. }
  4413. else
  4414. {
  4415. std::string impProp = "IMPORTED_LOCATION";
  4416. impProp += suffix;
  4417. if(const char* config_location = this->GetProperty(impProp.c_str()))
  4418. {
  4419. info.Location = config_location;
  4420. }
  4421. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  4422. {
  4423. info.Location = location;
  4424. }
  4425. }
  4426. // Get the soname.
  4427. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4428. {
  4429. std::string soProp = "IMPORTED_SONAME";
  4430. soProp += suffix;
  4431. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  4432. {
  4433. info.SOName = config_soname;
  4434. }
  4435. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  4436. {
  4437. info.SOName = soname;
  4438. }
  4439. }
  4440. // Get the "no-soname" mark.
  4441. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4442. {
  4443. std::string soProp = "IMPORTED_NO_SONAME";
  4444. soProp += suffix;
  4445. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  4446. {
  4447. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4448. }
  4449. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4450. {
  4451. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4452. }
  4453. }
  4454. // Get the import library.
  4455. if(imp)
  4456. {
  4457. info.ImportLibrary = imp;
  4458. }
  4459. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4460. this->IsExecutableWithExports())
  4461. {
  4462. std::string impProp = "IMPORTED_IMPLIB";
  4463. impProp += suffix;
  4464. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  4465. {
  4466. info.ImportLibrary = config_implib;
  4467. }
  4468. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4469. {
  4470. info.ImportLibrary = implib;
  4471. }
  4472. }
  4473. // Get the link interface.
  4474. {
  4475. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4476. linkProp += suffix;
  4477. const char *propertyLibs = this->GetProperty(linkProp.c_str());
  4478. if(!propertyLibs)
  4479. {
  4480. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4481. propertyLibs = this->GetProperty(linkProp.c_str());
  4482. }
  4483. if(propertyLibs)
  4484. {
  4485. cmListFileBacktrace lfbt;
  4486. cmGeneratorExpression ge(lfbt);
  4487. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  4488. this->GetName(),
  4489. linkProp, 0, 0);
  4490. cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
  4491. ->Evaluate(this->Makefile,
  4492. desired_config.c_str(),
  4493. false,
  4494. headTarget,
  4495. this,
  4496. &dagChecker),
  4497. info.LinkInterface.Libraries);
  4498. }
  4499. }
  4500. // Get the link dependencies.
  4501. {
  4502. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4503. linkProp += suffix;
  4504. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4505. {
  4506. cmSystemTools::ExpandListArgument(config_libs,
  4507. info.LinkInterface.SharedDeps);
  4508. }
  4509. else if(const char* libs =
  4510. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4511. {
  4512. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  4513. }
  4514. }
  4515. // Get the link languages.
  4516. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4517. {
  4518. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4519. linkProp += suffix;
  4520. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4521. {
  4522. cmSystemTools::ExpandListArgument(config_libs,
  4523. info.LinkInterface.Languages);
  4524. }
  4525. else if(const char* libs =
  4526. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4527. {
  4528. cmSystemTools::ExpandListArgument(libs,
  4529. info.LinkInterface.Languages);
  4530. }
  4531. }
  4532. // Get the cyclic repetition count.
  4533. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4534. {
  4535. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4536. linkProp += suffix;
  4537. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  4538. {
  4539. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  4540. }
  4541. else if(const char* reps =
  4542. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4543. {
  4544. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  4545. }
  4546. }
  4547. }
  4548. //----------------------------------------------------------------------------
  4549. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
  4550. cmTarget *head)
  4551. {
  4552. // Imported targets have their own link interface.
  4553. if(this->IsImported())
  4554. {
  4555. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  4556. {
  4557. return &info->LinkInterface;
  4558. }
  4559. return 0;
  4560. }
  4561. // Link interfaces are not supported for executables that do not
  4562. // export symbols.
  4563. if(this->GetType() == cmTarget::EXECUTABLE &&
  4564. !this->IsExecutableWithExports())
  4565. {
  4566. return 0;
  4567. }
  4568. // Lookup any existing link interface for this configuration.
  4569. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4570. cmTargetInternals::LinkInterfaceMapType::iterator
  4571. i = this->Internal->LinkInterfaceMap.find(key);
  4572. if(i == this->Internal->LinkInterfaceMap.end())
  4573. {
  4574. // Compute the link interface for this configuration.
  4575. cmTargetInternals::OptionalLinkInterface iface;
  4576. iface.Exists = this->ComputeLinkInterface(config, iface, head);
  4577. // Store the information for this configuration.
  4578. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  4579. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  4580. }
  4581. return i->second.Exists? &i->second : 0;
  4582. }
  4583. //----------------------------------------------------------------------------
  4584. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
  4585. cmTarget *headTarget)
  4586. {
  4587. // Construct the property name suffix for this configuration.
  4588. std::string suffix = "_";
  4589. if(config && *config)
  4590. {
  4591. suffix += cmSystemTools::UpperCase(config);
  4592. }
  4593. else
  4594. {
  4595. suffix += "NOCONFIG";
  4596. }
  4597. // An explicit list of interface libraries may be set for shared
  4598. // libraries and executables that export symbols.
  4599. const char* explicitLibraries = 0;
  4600. std::string linkIfaceProp;
  4601. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4602. this->IsExecutableWithExports())
  4603. {
  4604. // Lookup the per-configuration property.
  4605. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4606. linkIfaceProp += suffix;
  4607. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  4608. // If not set, try the generic property.
  4609. if(!explicitLibraries)
  4610. {
  4611. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4612. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  4613. }
  4614. }
  4615. // There is no implicit link interface for executables or modules
  4616. // so if none was explicitly set then there is no link interface.
  4617. // Note that CMake versions 2.2 and below allowed linking to modules.
  4618. bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
  4619. if(!explicitLibraries &&
  4620. (this->GetType() == cmTarget::EXECUTABLE ||
  4621. (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
  4622. {
  4623. return false;
  4624. }
  4625. if(explicitLibraries)
  4626. {
  4627. // The interface libraries have been explicitly set.
  4628. cmListFileBacktrace lfbt;
  4629. cmGeneratorExpression ge(lfbt);
  4630. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  4631. linkIfaceProp, 0, 0);
  4632. cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
  4633. this->Makefile,
  4634. config,
  4635. false,
  4636. headTarget,
  4637. this, &dagChecker), iface.Libraries);
  4638. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4639. {
  4640. // Shared libraries may have runtime implementation dependencies
  4641. // on other shared libraries that are not in the interface.
  4642. std::set<cmStdString> emitted;
  4643. for(std::vector<std::string>::const_iterator
  4644. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4645. {
  4646. emitted.insert(*li);
  4647. }
  4648. LinkImplementation const* impl = this->GetLinkImplementation(config,
  4649. headTarget);
  4650. for(std::vector<std::string>::const_iterator
  4651. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4652. {
  4653. if(emitted.insert(*li).second)
  4654. {
  4655. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  4656. {
  4657. // This is a runtime dependency on another shared library.
  4658. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  4659. {
  4660. iface.SharedDeps.push_back(*li);
  4661. }
  4662. }
  4663. else
  4664. {
  4665. // TODO: Recognize shared library file names. Perhaps this
  4666. // should be moved to cmComputeLinkInformation, but that creates
  4667. // a chicken-and-egg problem since this list is needed for its
  4668. // construction.
  4669. }
  4670. }
  4671. }
  4672. }
  4673. }
  4674. else
  4675. {
  4676. // The link implementation is the default link interface.
  4677. LinkImplementation const* impl = this->GetLinkImplementation(config,
  4678. headTarget);
  4679. iface.ImplementationIsInterface = true;
  4680. iface.Libraries = impl->Libraries;
  4681. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4682. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4683. {
  4684. // Targets using this archive need its language runtime libraries.
  4685. iface.Languages = impl->Languages;
  4686. }
  4687. }
  4688. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4689. {
  4690. // How many repetitions are needed if this library has cyclic
  4691. // dependencies?
  4692. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4693. propName += suffix;
  4694. if(const char* config_reps = this->GetProperty(propName.c_str()))
  4695. {
  4696. sscanf(config_reps, "%u", &iface.Multiplicity);
  4697. }
  4698. else if(const char* reps =
  4699. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4700. {
  4701. sscanf(reps, "%u", &iface.Multiplicity);
  4702. }
  4703. }
  4704. return true;
  4705. }
  4706. //----------------------------------------------------------------------------
  4707. cmTarget::LinkImplementation const*
  4708. cmTarget::GetLinkImplementation(const char* config, cmTarget *head)
  4709. {
  4710. // There is no link implementation for imported targets.
  4711. if(this->IsImported())
  4712. {
  4713. return 0;
  4714. }
  4715. // Lookup any existing link implementation for this configuration.
  4716. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4717. cmTargetInternals::LinkImplMapType::iterator
  4718. i = this->Internal->LinkImplMap.find(key);
  4719. if(i == this->Internal->LinkImplMap.end())
  4720. {
  4721. // Compute the link implementation for this configuration.
  4722. LinkImplementation impl;
  4723. this->ComputeLinkImplementation(config, impl, head);
  4724. // Store the information for this configuration.
  4725. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  4726. i = this->Internal->LinkImplMap.insert(entry).first;
  4727. }
  4728. return &i->second;
  4729. }
  4730. //----------------------------------------------------------------------------
  4731. void cmTarget::ComputeLinkImplementation(const char* config,
  4732. LinkImplementation& impl,
  4733. cmTarget *head)
  4734. {
  4735. // Compute which library configuration to link.
  4736. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  4737. // Collect libraries directly linked in this configuration.
  4738. std::vector<std::string> llibs;
  4739. this->GetDirectLinkLibraries(config, llibs, head);
  4740. for(std::vector<std::string>::const_iterator li = llibs.begin();
  4741. li != llibs.end(); ++li)
  4742. {
  4743. // Skip entries that resolve to the target itself or are empty.
  4744. std::string item = this->CheckCMP0004(*li);
  4745. if(item == this->GetName() || item.empty())
  4746. {
  4747. continue;
  4748. }
  4749. // The entry is meant for this configuration.
  4750. impl.Libraries.push_back(item);
  4751. }
  4752. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  4753. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4754. li != oldllibs.end(); ++li)
  4755. {
  4756. if(li->second != cmTarget::GENERAL && li->second != linkType)
  4757. {
  4758. std::string item = this->CheckCMP0004(li->first);
  4759. if(item == this->GetName() || item.empty())
  4760. {
  4761. continue;
  4762. }
  4763. // Support OLD behavior for CMP0003.
  4764. impl.WrongConfigLibraries.push_back(item);
  4765. }
  4766. }
  4767. // This target needs runtime libraries for its source languages.
  4768. std::set<cmStdString> languages;
  4769. // Get languages used in our source files.
  4770. this->GetLanguages(languages);
  4771. // Get languages used in object library sources.
  4772. for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
  4773. i != this->ObjectLibraries.end(); ++i)
  4774. {
  4775. if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
  4776. {
  4777. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  4778. {
  4779. objLib->GetLanguages(languages);
  4780. }
  4781. }
  4782. }
  4783. // Copy the set of langauges to the link implementation.
  4784. for(std::set<cmStdString>::iterator li = languages.begin();
  4785. li != languages.end(); ++li)
  4786. {
  4787. impl.Languages.push_back(*li);
  4788. }
  4789. }
  4790. //----------------------------------------------------------------------------
  4791. std::string cmTarget::CheckCMP0004(std::string const& item)
  4792. {
  4793. // Strip whitespace off the library names because we used to do this
  4794. // in case variables were expanded at generate time. We no longer
  4795. // do the expansion but users link to libraries like " ${VAR} ".
  4796. std::string lib = item;
  4797. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4798. if(pos != lib.npos)
  4799. {
  4800. lib = lib.substr(pos, lib.npos);
  4801. }
  4802. pos = lib.find_last_not_of(" \t\r\n");
  4803. if(pos != lib.npos)
  4804. {
  4805. lib = lib.substr(0, pos+1);
  4806. }
  4807. if(lib != item)
  4808. {
  4809. cmake* cm = this->Makefile->GetCMakeInstance();
  4810. switch(this->PolicyStatusCMP0004)
  4811. {
  4812. case cmPolicies::WARN:
  4813. {
  4814. cmOStringStream w;
  4815. w << (this->Makefile->GetPolicies()
  4816. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  4817. << "Target \"" << this->GetName() << "\" links to item \""
  4818. << item << "\" which has leading or trailing whitespace.";
  4819. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4820. this->GetBacktrace());
  4821. }
  4822. case cmPolicies::OLD:
  4823. break;
  4824. case cmPolicies::NEW:
  4825. {
  4826. cmOStringStream e;
  4827. e << "Target \"" << this->GetName() << "\" links to item \""
  4828. << item << "\" which has leading or trailing whitespace. "
  4829. << "This is now an error according to policy CMP0004.";
  4830. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4831. }
  4832. break;
  4833. case cmPolicies::REQUIRED_IF_USED:
  4834. case cmPolicies::REQUIRED_ALWAYS:
  4835. {
  4836. cmOStringStream e;
  4837. e << (this->Makefile->GetPolicies()
  4838. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  4839. << "Target \"" << this->GetName() << "\" links to item \""
  4840. << item << "\" which has leading or trailing whitespace.";
  4841. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4842. }
  4843. break;
  4844. }
  4845. }
  4846. return lib;
  4847. }
  4848. //----------------------------------------------------------------------------
  4849. cmComputeLinkInformation*
  4850. cmTarget::GetLinkInformation(const char* config, cmTarget *head)
  4851. {
  4852. cmTarget *headTarget = head ? head : this;
  4853. // Lookup any existing information for this configuration.
  4854. TargetConfigPair key(headTarget,
  4855. cmSystemTools::UpperCase(config?config:""));
  4856. cmTargetLinkInformationMap::iterator
  4857. i = this->LinkInformation.find(key);
  4858. if(i == this->LinkInformation.end())
  4859. {
  4860. // Compute information for this configuration.
  4861. cmComputeLinkInformation* info =
  4862. new cmComputeLinkInformation(this, config, headTarget);
  4863. if(!info || !info->Compute())
  4864. {
  4865. delete info;
  4866. info = 0;
  4867. }
  4868. // Store the information for this configuration.
  4869. cmTargetLinkInformationMap::value_type entry(key, info);
  4870. i = this->LinkInformation.insert(entry).first;
  4871. }
  4872. return i->second;
  4873. }
  4874. //----------------------------------------------------------------------------
  4875. std::string cmTarget::GetFrameworkDirectory(const char* config)
  4876. {
  4877. std::string fpath;
  4878. fpath += this->GetFullName(config, false);
  4879. fpath += ".framework/Versions/";
  4880. fpath += this->GetFrameworkVersion();
  4881. fpath += "/";
  4882. return fpath;
  4883. }
  4884. //----------------------------------------------------------------------------
  4885. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  4886. const char* config,
  4887. bool includeMacOS)
  4888. {
  4889. std::string fpath = base;
  4890. if(this->IsAppBundleOnApple())
  4891. {
  4892. fpath += this->GetFullName(config, false);
  4893. fpath += ".app/Contents/";
  4894. if(includeMacOS)
  4895. fpath += "MacOS/";
  4896. }
  4897. if(this->IsFrameworkOnApple())
  4898. {
  4899. fpath += this->GetFrameworkDirectory(config);
  4900. }
  4901. if(this->IsCFBundleOnApple())
  4902. {
  4903. fpath += this->GetFullName(config, false);
  4904. fpath += ".";
  4905. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  4906. if (!ext)
  4907. {
  4908. ext = "bundle";
  4909. }
  4910. fpath += ext;
  4911. fpath += "/Contents/";
  4912. if(includeMacOS)
  4913. fpath += "MacOS/";
  4914. }
  4915. return fpath;
  4916. }
  4917. //----------------------------------------------------------------------------
  4918. std::string cmTarget::GetMacContentDirectory(const char* config,
  4919. bool implib,
  4920. bool includeMacOS)
  4921. {
  4922. // Start with the output directory for the target.
  4923. std::string fpath = this->GetDirectory(config, implib);
  4924. fpath += "/";
  4925. fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
  4926. return fpath;
  4927. }
  4928. //----------------------------------------------------------------------------
  4929. cmTargetLinkInformationMap
  4930. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  4931. {
  4932. // Ideally cmTarget instances should never be copied. However until
  4933. // we can make a sweep to remove that, this copy constructor avoids
  4934. // allowing the resources (LinkInformation) from getting copied. In
  4935. // the worst case this will lead to extra cmComputeLinkInformation
  4936. // instances. We also enforce in debug mode that the map be emptied
  4937. // when copied.
  4938. static_cast<void>(r);
  4939. assert(r.empty());
  4940. }
  4941. //----------------------------------------------------------------------------
  4942. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  4943. {
  4944. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  4945. {
  4946. delete i->second;
  4947. }
  4948. }
  4949. //----------------------------------------------------------------------------
  4950. cmTargetInternalPointer::cmTargetInternalPointer()
  4951. {
  4952. this->Pointer = new cmTargetInternals;
  4953. }
  4954. //----------------------------------------------------------------------------
  4955. cmTargetInternalPointer
  4956. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4957. {
  4958. // Ideally cmTarget instances should never be copied. However until
  4959. // we can make a sweep to remove that, this copy constructor avoids
  4960. // allowing the resources (Internals) to be copied.
  4961. this->Pointer = new cmTargetInternals(*r.Pointer);
  4962. }
  4963. //----------------------------------------------------------------------------
  4964. cmTargetInternalPointer::~cmTargetInternalPointer()
  4965. {
  4966. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  4967. delete this->Pointer;
  4968. }
  4969. //----------------------------------------------------------------------------
  4970. cmTargetInternalPointer&
  4971. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4972. {
  4973. if(this == &r) { return *this; } // avoid warning on HP about self check
  4974. // Ideally cmTarget instances should never be copied. However until
  4975. // we can make a sweep to remove that, this copy constructor avoids
  4976. // allowing the resources (Internals) to be copied.
  4977. cmTargetInternals* oldPointer = this->Pointer;
  4978. this->Pointer = new cmTargetInternals(*r.Pointer);
  4979. delete oldPointer;
  4980. return *this;
  4981. }