cmTarget.cxx 186 KB

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