cmTarget.cxx 197 KB

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