cmTarget.cxx 171 KB

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