cmTarget.cxx 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862
  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. this->ComputePDBOutputDir(config, info.PdbDir);
  2364. OutputInfoMapType::value_type entry(config_upper, info);
  2365. i = this->Internal->OutputInfoMap.insert(entry).first;
  2366. }
  2367. return &i->second;
  2368. }
  2369. //----------------------------------------------------------------------------
  2370. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2371. {
  2372. if (this->IsImported())
  2373. {
  2374. // Return the directory from which the target is imported.
  2375. return
  2376. cmSystemTools::GetFilenamePath(
  2377. this->ImportedGetFullPath(config, implib));
  2378. }
  2379. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2380. {
  2381. // Return the directory in which the target will be built.
  2382. return implib? info->ImpDir : info->OutDir;
  2383. }
  2384. return "";
  2385. }
  2386. //----------------------------------------------------------------------------
  2387. std::string cmTarget::GetPDBDirectory(const char* config)
  2388. {
  2389. if(OutputInfo const* info = this->GetOutputInfo(config))
  2390. {
  2391. // Return the directory in which the target will be built.
  2392. return info->PdbDir;
  2393. }
  2394. return "";
  2395. }
  2396. //----------------------------------------------------------------------------
  2397. const char* cmTarget::GetLocation(const char* config)
  2398. {
  2399. if (this->IsImported())
  2400. {
  2401. return this->ImportedGetLocation(config);
  2402. }
  2403. else
  2404. {
  2405. return this->NormalGetLocation(config);
  2406. }
  2407. }
  2408. //----------------------------------------------------------------------------
  2409. const char* cmTarget::ImportedGetLocation(const char* config)
  2410. {
  2411. this->Location = this->ImportedGetFullPath(config, false);
  2412. return this->Location.c_str();
  2413. }
  2414. //----------------------------------------------------------------------------
  2415. const char* cmTarget::NormalGetLocation(const char* config)
  2416. {
  2417. // Handle the configuration-specific case first.
  2418. if(config)
  2419. {
  2420. this->Location = this->GetFullPath(config, false);
  2421. return this->Location.c_str();
  2422. }
  2423. // Now handle the deprecated build-time configuration location.
  2424. this->Location = this->GetDirectory();
  2425. if(!this->Location.empty())
  2426. {
  2427. this->Location += "/";
  2428. }
  2429. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2430. if(cfgid && strcmp(cfgid, ".") != 0)
  2431. {
  2432. this->Location += cfgid;
  2433. this->Location += "/";
  2434. }
  2435. this->Location = this->BuildMacContentDirectory(this->Location, config);
  2436. this->Location += this->GetFullName(config, false);
  2437. return this->Location.c_str();
  2438. }
  2439. //----------------------------------------------------------------------------
  2440. void cmTarget::GetTargetVersion(int& major, int& minor)
  2441. {
  2442. int patch;
  2443. this->GetTargetVersion(false, major, minor, patch);
  2444. }
  2445. //----------------------------------------------------------------------------
  2446. void cmTarget::GetTargetVersion(bool soversion,
  2447. int& major, int& minor, int& patch)
  2448. {
  2449. // Set the default values.
  2450. major = 0;
  2451. minor = 0;
  2452. patch = 0;
  2453. // Look for a VERSION or SOVERSION property.
  2454. const char* prop = soversion? "SOVERSION" : "VERSION";
  2455. if(const char* version = this->GetProperty(prop))
  2456. {
  2457. // Try to parse the version number and store the results that were
  2458. // successfully parsed.
  2459. int parsed_major;
  2460. int parsed_minor;
  2461. int parsed_patch;
  2462. switch(sscanf(version, "%d.%d.%d",
  2463. &parsed_major, &parsed_minor, &parsed_patch))
  2464. {
  2465. case 3: patch = parsed_patch; // no break!
  2466. case 2: minor = parsed_minor; // no break!
  2467. case 1: major = parsed_major; // no break!
  2468. default: break;
  2469. }
  2470. }
  2471. }
  2472. //----------------------------------------------------------------------------
  2473. const char* cmTarget::GetFeature(const char* feature, const char* config)
  2474. {
  2475. if(config && *config)
  2476. {
  2477. std::string featureConfig = feature;
  2478. featureConfig += "_";
  2479. featureConfig += cmSystemTools::UpperCase(config);
  2480. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2481. {
  2482. return value;
  2483. }
  2484. }
  2485. if(const char* value = this->GetProperty(feature))
  2486. {
  2487. return value;
  2488. }
  2489. return this->Makefile->GetFeature(feature, config);
  2490. }
  2491. //----------------------------------------------------------------------------
  2492. const char *cmTarget::GetProperty(const char* prop)
  2493. {
  2494. return this->GetProperty(prop, cmProperty::TARGET);
  2495. }
  2496. //----------------------------------------------------------------------------
  2497. const char *cmTarget::GetProperty(const char* prop,
  2498. cmProperty::ScopeType scope)
  2499. {
  2500. if(!prop)
  2501. {
  2502. return 0;
  2503. }
  2504. // Watch for special "computed" properties that are dependent on
  2505. // other properties or variables. Always recompute them.
  2506. if(this->GetType() == cmTarget::EXECUTABLE ||
  2507. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2508. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2509. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2510. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2511. {
  2512. if(strcmp(prop,"LOCATION") == 0)
  2513. {
  2514. // Set the LOCATION property of the target.
  2515. //
  2516. // For an imported target this is the location of an arbitrary
  2517. // available configuration.
  2518. //
  2519. // For a non-imported target this is deprecated because it
  2520. // cannot take into account the per-configuration name of the
  2521. // target because the configuration type may not be known at
  2522. // CMake time.
  2523. this->SetProperty("LOCATION", this->GetLocation(0));
  2524. }
  2525. // Support "LOCATION_<CONFIG>".
  2526. if(strncmp(prop, "LOCATION_", 9) == 0)
  2527. {
  2528. std::string configName = prop+9;
  2529. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2530. }
  2531. else
  2532. {
  2533. // Support "<CONFIG>_LOCATION" for compatiblity.
  2534. int len = static_cast<int>(strlen(prop));
  2535. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  2536. {
  2537. std::string configName(prop, len-9);
  2538. if(configName != "IMPORTED")
  2539. {
  2540. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2541. }
  2542. }
  2543. }
  2544. }
  2545. if (strcmp(prop,"IMPORTED") == 0)
  2546. {
  2547. return this->IsImported()?"TRUE":"FALSE";
  2548. }
  2549. if(!strcmp(prop,"SOURCES"))
  2550. {
  2551. cmOStringStream ss;
  2552. const char* sep = "";
  2553. for(std::vector<cmSourceFile*>::const_iterator
  2554. i = this->SourceFiles.begin();
  2555. i != this->SourceFiles.end(); ++i)
  2556. {
  2557. // Separate from the previous list entries.
  2558. ss << sep;
  2559. sep = ";";
  2560. // Construct what is known about this source file location.
  2561. cmSourceFileLocation const& location = (*i)->GetLocation();
  2562. std::string sname = location.GetDirectory();
  2563. if(!sname.empty())
  2564. {
  2565. sname += "/";
  2566. }
  2567. sname += location.GetName();
  2568. // Append this list entry.
  2569. ss << sname;
  2570. }
  2571. this->SetProperty("SOURCES", ss.str().c_str());
  2572. }
  2573. // the type property returns what type the target is
  2574. if (!strcmp(prop,"TYPE"))
  2575. {
  2576. return cmTarget::GetTargetTypeName(this->GetType());
  2577. }
  2578. bool chain = false;
  2579. const char *retVal =
  2580. this->Properties.GetPropertyValue(prop, scope, chain);
  2581. if (chain)
  2582. {
  2583. return this->Makefile->GetProperty(prop,scope);
  2584. }
  2585. return retVal;
  2586. }
  2587. //----------------------------------------------------------------------------
  2588. bool cmTarget::GetPropertyAsBool(const char* prop)
  2589. {
  2590. return cmSystemTools::IsOn(this->GetProperty(prop));
  2591. }
  2592. //----------------------------------------------------------------------------
  2593. class cmTargetCollectLinkLanguages
  2594. {
  2595. public:
  2596. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  2597. std::set<cmStdString>& languages):
  2598. Config(config), Languages(languages) { this->Visited.insert(target); }
  2599. void Visit(cmTarget* target)
  2600. {
  2601. if(!target || !this->Visited.insert(target).second)
  2602. {
  2603. return;
  2604. }
  2605. cmTarget::LinkInterface const* iface =
  2606. target->GetLinkInterface(this->Config);
  2607. if(!iface) { return; }
  2608. for(std::vector<std::string>::const_iterator
  2609. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2610. {
  2611. this->Languages.insert(*li);
  2612. }
  2613. cmMakefile* mf = target->GetMakefile();
  2614. for(std::vector<std::string>::const_iterator
  2615. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2616. {
  2617. this->Visit(mf->FindTargetToUse(li->c_str()));
  2618. }
  2619. }
  2620. private:
  2621. const char* Config;
  2622. std::set<cmStdString>& Languages;
  2623. std::set<cmTarget*> Visited;
  2624. };
  2625. //----------------------------------------------------------------------------
  2626. const char* cmTarget::GetLinkerLanguage(const char* config)
  2627. {
  2628. const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
  2629. return *lang? lang : 0;
  2630. }
  2631. //----------------------------------------------------------------------------
  2632. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
  2633. {
  2634. std::string key = cmSystemTools::UpperCase(config? config : "");
  2635. cmTargetInternals::LinkClosureMapType::iterator
  2636. i = this->Internal->LinkClosureMap.find(key);
  2637. if(i == this->Internal->LinkClosureMap.end())
  2638. {
  2639. LinkClosure lc;
  2640. this->ComputeLinkClosure(config, lc);
  2641. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2642. i = this->Internal->LinkClosureMap.insert(entry).first;
  2643. }
  2644. return &i->second;
  2645. }
  2646. //----------------------------------------------------------------------------
  2647. class cmTargetSelectLinker
  2648. {
  2649. int Preference;
  2650. cmTarget* Target;
  2651. cmMakefile* Makefile;
  2652. cmGlobalGenerator* GG;
  2653. std::set<cmStdString> Preferred;
  2654. public:
  2655. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  2656. {
  2657. this->Makefile = this->Target->GetMakefile();
  2658. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  2659. }
  2660. void Consider(const char* lang)
  2661. {
  2662. int preference = this->GG->GetLinkerPreference(lang);
  2663. if(preference > this->Preference)
  2664. {
  2665. this->Preference = preference;
  2666. this->Preferred.clear();
  2667. }
  2668. if(preference == this->Preference)
  2669. {
  2670. this->Preferred.insert(lang);
  2671. }
  2672. }
  2673. std::string Choose()
  2674. {
  2675. if(this->Preferred.empty())
  2676. {
  2677. return "";
  2678. }
  2679. else if(this->Preferred.size() > 1)
  2680. {
  2681. cmOStringStream e;
  2682. e << "Target " << this->Target->GetName()
  2683. << " contains multiple languages with the highest linker preference"
  2684. << " (" << this->Preference << "):\n";
  2685. for(std::set<cmStdString>::const_iterator
  2686. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  2687. {
  2688. e << " " << *li << "\n";
  2689. }
  2690. e << "Set the LINKER_LANGUAGE property for this target.";
  2691. cmake* cm = this->Makefile->GetCMakeInstance();
  2692. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  2693. this->Target->GetBacktrace());
  2694. }
  2695. return *this->Preferred.begin();
  2696. }
  2697. };
  2698. //----------------------------------------------------------------------------
  2699. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
  2700. {
  2701. // Get languages built in this target.
  2702. std::set<cmStdString> languages;
  2703. LinkImplementation const* impl = this->GetLinkImplementation(config);
  2704. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2705. li != impl->Languages.end(); ++li)
  2706. {
  2707. languages.insert(*li);
  2708. }
  2709. // Add interface languages from linked targets.
  2710. cmTargetCollectLinkLanguages cll(this, config, languages);
  2711. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  2712. li != impl->Libraries.end(); ++li)
  2713. {
  2714. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  2715. }
  2716. // Store the transitive closure of languages.
  2717. for(std::set<cmStdString>::const_iterator li = languages.begin();
  2718. li != languages.end(); ++li)
  2719. {
  2720. lc.Languages.push_back(*li);
  2721. }
  2722. // Choose the language whose linker should be used.
  2723. if(this->GetProperty("HAS_CXX"))
  2724. {
  2725. lc.LinkerLanguage = "CXX";
  2726. }
  2727. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  2728. {
  2729. lc.LinkerLanguage = linkerLang;
  2730. }
  2731. else
  2732. {
  2733. // Find the language with the highest preference value.
  2734. cmTargetSelectLinker tsl(this);
  2735. // First select from the languages compiled directly in this target.
  2736. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2737. li != impl->Languages.end(); ++li)
  2738. {
  2739. tsl.Consider(li->c_str());
  2740. }
  2741. // Now consider languages that propagate from linked targets.
  2742. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  2743. sit != languages.end(); ++sit)
  2744. {
  2745. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  2746. if(this->Makefile->IsOn(propagates.c_str()))
  2747. {
  2748. tsl.Consider(sit->c_str());
  2749. }
  2750. }
  2751. lc.LinkerLanguage = tsl.Choose();
  2752. }
  2753. }
  2754. //----------------------------------------------------------------------------
  2755. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  2756. {
  2757. switch(this->GetType())
  2758. {
  2759. case cmTarget::STATIC_LIBRARY:
  2760. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2761. case cmTarget::SHARED_LIBRARY:
  2762. return (implib
  2763. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2764. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2765. case cmTarget::MODULE_LIBRARY:
  2766. return (implib
  2767. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2768. : "CMAKE_SHARED_MODULE_SUFFIX");
  2769. case cmTarget::EXECUTABLE:
  2770. return (implib
  2771. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2772. : "CMAKE_EXECUTABLE_SUFFIX");
  2773. default:
  2774. break;
  2775. }
  2776. return "";
  2777. }
  2778. //----------------------------------------------------------------------------
  2779. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  2780. {
  2781. switch(this->GetType())
  2782. {
  2783. case cmTarget::STATIC_LIBRARY:
  2784. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2785. case cmTarget::SHARED_LIBRARY:
  2786. return (implib
  2787. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2788. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2789. case cmTarget::MODULE_LIBRARY:
  2790. return (implib
  2791. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2792. : "CMAKE_SHARED_MODULE_PREFIX");
  2793. case cmTarget::EXECUTABLE:
  2794. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  2795. default:
  2796. break;
  2797. }
  2798. return "";
  2799. }
  2800. //----------------------------------------------------------------------------
  2801. std::string cmTarget::GetPDBName(const char* config)
  2802. {
  2803. std::string prefix;
  2804. std::string base;
  2805. std::string suffix;
  2806. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2807. std::vector<std::string> props;
  2808. std::string configUpper =
  2809. cmSystemTools::UpperCase(config? config : "");
  2810. if(!configUpper.empty())
  2811. {
  2812. // PDB_NAME_<CONFIG>
  2813. props.push_back("PDB_NAME_" + configUpper);
  2814. }
  2815. // PDB_NAME
  2816. props.push_back("PDB_NAME");
  2817. for(std::vector<std::string>::const_iterator i = props.begin();
  2818. i != props.end(); ++i)
  2819. {
  2820. if(const char* outName = this->GetProperty(i->c_str()))
  2821. {
  2822. base = outName;
  2823. break;
  2824. }
  2825. }
  2826. return prefix+base+".pdb";
  2827. }
  2828. //----------------------------------------------------------------------------
  2829. bool cmTarget::HasSOName(const char* config)
  2830. {
  2831. // soname is supported only for shared libraries and modules,
  2832. // and then only when the platform supports an soname flag.
  2833. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  2834. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  2835. !this->GetPropertyAsBool("NO_SONAME") &&
  2836. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  2837. }
  2838. //----------------------------------------------------------------------------
  2839. std::string cmTarget::GetSOName(const char* config)
  2840. {
  2841. if(this->IsImported())
  2842. {
  2843. // Lookup the imported soname.
  2844. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2845. {
  2846. if(info->NoSOName)
  2847. {
  2848. // The imported library has no builtin soname so the name
  2849. // searched at runtime will be just the filename.
  2850. return cmSystemTools::GetFilenameName(info->Location);
  2851. }
  2852. else
  2853. {
  2854. // Use the soname given if any.
  2855. return info->SOName;
  2856. }
  2857. }
  2858. else
  2859. {
  2860. return "";
  2861. }
  2862. }
  2863. else
  2864. {
  2865. // Compute the soname that will be built.
  2866. std::string name;
  2867. std::string soName;
  2868. std::string realName;
  2869. std::string impName;
  2870. std::string pdbName;
  2871. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2872. return soName;
  2873. }
  2874. }
  2875. //----------------------------------------------------------------------------
  2876. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  2877. {
  2878. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  2879. {
  2880. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2881. {
  2882. return info->NoSOName;
  2883. }
  2884. }
  2885. return false;
  2886. }
  2887. //----------------------------------------------------------------------------
  2888. std::string cmTarget::NormalGetRealName(const char* config)
  2889. {
  2890. // This should not be called for imported targets.
  2891. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2892. // enforcement of the limited imported target API.
  2893. if(this->IsImported())
  2894. {
  2895. std::string msg = "NormalGetRealName called on imported target: ";
  2896. msg += this->GetName();
  2897. this->GetMakefile()->
  2898. IssueMessage(cmake::INTERNAL_ERROR,
  2899. msg.c_str());
  2900. }
  2901. if(this->GetType() == cmTarget::EXECUTABLE)
  2902. {
  2903. // Compute the real name that will be built.
  2904. std::string name;
  2905. std::string realName;
  2906. std::string impName;
  2907. std::string pdbName;
  2908. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2909. return realName;
  2910. }
  2911. else
  2912. {
  2913. // Compute the real name that will be built.
  2914. std::string name;
  2915. std::string soName;
  2916. std::string realName;
  2917. std::string impName;
  2918. std::string pdbName;
  2919. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2920. return realName;
  2921. }
  2922. }
  2923. //----------------------------------------------------------------------------
  2924. std::string cmTarget::GetFullName(const char* config, bool implib)
  2925. {
  2926. if(this->IsImported())
  2927. {
  2928. return this->GetFullNameImported(config, implib);
  2929. }
  2930. else
  2931. {
  2932. return this->GetFullNameInternal(config, implib);
  2933. }
  2934. }
  2935. //----------------------------------------------------------------------------
  2936. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  2937. {
  2938. return cmSystemTools::GetFilenameName(
  2939. this->ImportedGetFullPath(config, implib));
  2940. }
  2941. //----------------------------------------------------------------------------
  2942. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  2943. std::string& suffix, const char* config,
  2944. bool implib)
  2945. {
  2946. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2947. }
  2948. //----------------------------------------------------------------------------
  2949. std::string cmTarget::GetFullPath(const char* config, bool implib,
  2950. bool realname)
  2951. {
  2952. if(this->IsImported())
  2953. {
  2954. return this->ImportedGetFullPath(config, implib);
  2955. }
  2956. else
  2957. {
  2958. return this->NormalGetFullPath(config, implib, realname);
  2959. }
  2960. }
  2961. //----------------------------------------------------------------------------
  2962. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  2963. bool realname)
  2964. {
  2965. std::string fpath = this->GetMacContentDirectory(config, implib);
  2966. // Add the full name of the target.
  2967. if(implib)
  2968. {
  2969. fpath += this->GetFullName(config, true);
  2970. }
  2971. else if(realname)
  2972. {
  2973. fpath += this->NormalGetRealName(config);
  2974. }
  2975. else
  2976. {
  2977. fpath += this->GetFullName(config, false);
  2978. }
  2979. return fpath;
  2980. }
  2981. //----------------------------------------------------------------------------
  2982. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  2983. {
  2984. std::string result;
  2985. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2986. {
  2987. result = implib? info->ImportLibrary : info->Location;
  2988. }
  2989. if(result.empty())
  2990. {
  2991. result = this->GetName();
  2992. result += "-NOTFOUND";
  2993. }
  2994. return result;
  2995. }
  2996. //----------------------------------------------------------------------------
  2997. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  2998. {
  2999. std::string prefix;
  3000. std::string base;
  3001. std::string suffix;
  3002. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3003. return prefix+base+suffix;
  3004. }
  3005. //----------------------------------------------------------------------------
  3006. void cmTarget::GetFullNameInternal(const char* config,
  3007. bool implib,
  3008. std::string& outPrefix,
  3009. std::string& outBase,
  3010. std::string& outSuffix)
  3011. {
  3012. // Use just the target name for non-main target types.
  3013. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3014. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3015. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3016. this->GetType() != cmTarget::EXECUTABLE)
  3017. {
  3018. outPrefix = "";
  3019. outBase = this->GetName();
  3020. outSuffix = "";
  3021. return;
  3022. }
  3023. // Return an empty name for the import library if this platform
  3024. // does not support import libraries.
  3025. if(implib &&
  3026. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3027. {
  3028. outPrefix = "";
  3029. outBase = "";
  3030. outSuffix = "";
  3031. return;
  3032. }
  3033. // The implib option is only allowed for shared libraries, module
  3034. // libraries, and executables.
  3035. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3036. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3037. this->GetType() != cmTarget::EXECUTABLE)
  3038. {
  3039. implib = false;
  3040. }
  3041. // Compute the full name for main target types.
  3042. const char* targetPrefix = (implib
  3043. ? this->GetProperty("IMPORT_PREFIX")
  3044. : this->GetProperty("PREFIX"));
  3045. const char* targetSuffix = (implib
  3046. ? this->GetProperty("IMPORT_SUFFIX")
  3047. : this->GetProperty("SUFFIX"));
  3048. const char* configPostfix = 0;
  3049. if(config && *config)
  3050. {
  3051. std::string configProp = cmSystemTools::UpperCase(config);
  3052. configProp += "_POSTFIX";
  3053. configPostfix = this->GetProperty(configProp.c_str());
  3054. // Mac application bundles and frameworks have no postfix.
  3055. if(configPostfix &&
  3056. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3057. {
  3058. configPostfix = 0;
  3059. }
  3060. }
  3061. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3062. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3063. // Check for language-specific default prefix and suffix.
  3064. if(const char* ll = this->GetLinkerLanguage(config))
  3065. {
  3066. if(!targetSuffix && suffixVar && *suffixVar)
  3067. {
  3068. std::string langSuff = suffixVar + std::string("_") + ll;
  3069. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  3070. }
  3071. if(!targetPrefix && prefixVar && *prefixVar)
  3072. {
  3073. std::string langPrefix = prefixVar + std::string("_") + ll;
  3074. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  3075. }
  3076. }
  3077. // if there is no prefix on the target use the cmake definition
  3078. if(!targetPrefix && prefixVar)
  3079. {
  3080. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3081. }
  3082. // if there is no suffix on the target use the cmake definition
  3083. if(!targetSuffix && suffixVar)
  3084. {
  3085. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3086. }
  3087. // frameworks do not have a prefix or a suffix
  3088. if(this->IsFrameworkOnApple())
  3089. {
  3090. targetPrefix = 0;
  3091. targetSuffix = 0;
  3092. }
  3093. // Begin the final name with the prefix.
  3094. outPrefix = targetPrefix?targetPrefix:"";
  3095. // Append the target name or property-specified name.
  3096. outBase += this->GetOutputName(config, implib);
  3097. // Append the per-configuration postfix.
  3098. outBase += configPostfix?configPostfix:"";
  3099. // Name shared libraries with their version number on some platforms.
  3100. if(const char* soversion = this->GetProperty("SOVERSION"))
  3101. {
  3102. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3103. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3104. {
  3105. outBase += "-";
  3106. outBase += soversion;
  3107. }
  3108. }
  3109. // Append the suffix.
  3110. outSuffix = targetSuffix?targetSuffix:"";
  3111. }
  3112. //----------------------------------------------------------------------------
  3113. void cmTarget::GetLibraryNames(std::string& name,
  3114. std::string& soName,
  3115. std::string& realName,
  3116. std::string& impName,
  3117. std::string& pdbName,
  3118. const char* config)
  3119. {
  3120. // This should not be called for imported targets.
  3121. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3122. // enforcement of the limited imported target API.
  3123. if(this->IsImported())
  3124. {
  3125. std::string msg = "GetLibraryNames called on imported target: ";
  3126. msg += this->GetName();
  3127. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3128. msg.c_str());
  3129. return;
  3130. }
  3131. // Check for library version properties.
  3132. const char* version = this->GetProperty("VERSION");
  3133. const char* soversion = this->GetProperty("SOVERSION");
  3134. if(!this->HasSOName(config) ||
  3135. this->IsFrameworkOnApple())
  3136. {
  3137. // Versioning is supported only for shared libraries and modules,
  3138. // and then only when the platform supports an soname flag.
  3139. version = 0;
  3140. soversion = 0;
  3141. }
  3142. if(version && !soversion)
  3143. {
  3144. // The soversion must be set if the library version is set. Use
  3145. // the library version as the soversion.
  3146. soversion = version;
  3147. }
  3148. if(!version && soversion)
  3149. {
  3150. // Use the soversion as the library version.
  3151. version = soversion;
  3152. }
  3153. // Get the components of the library name.
  3154. std::string prefix;
  3155. std::string base;
  3156. std::string suffix;
  3157. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3158. // The library name.
  3159. name = prefix+base+suffix;
  3160. // The library's soname.
  3161. this->ComputeVersionedName(soName, prefix, base, suffix,
  3162. name, soversion);
  3163. // The library's real name on disk.
  3164. this->ComputeVersionedName(realName, prefix, base, suffix,
  3165. name, version);
  3166. // The import library name.
  3167. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3168. this->GetType() == cmTarget::MODULE_LIBRARY)
  3169. {
  3170. impName = this->GetFullNameInternal(config, true);
  3171. }
  3172. else
  3173. {
  3174. impName = "";
  3175. }
  3176. // The program database file name.
  3177. pdbName = this->GetPDBName(config);
  3178. }
  3179. //----------------------------------------------------------------------------
  3180. void cmTarget::ComputeVersionedName(std::string& vName,
  3181. std::string const& prefix,
  3182. std::string const& base,
  3183. std::string const& suffix,
  3184. std::string const& name,
  3185. const char* version)
  3186. {
  3187. vName = this->IsApple? (prefix+base) : name;
  3188. if(version)
  3189. {
  3190. vName += ".";
  3191. vName += version;
  3192. }
  3193. vName += this->IsApple? suffix : std::string();
  3194. }
  3195. //----------------------------------------------------------------------------
  3196. void cmTarget::GetExecutableNames(std::string& name,
  3197. std::string& realName,
  3198. std::string& impName,
  3199. std::string& pdbName,
  3200. const char* config)
  3201. {
  3202. // This should not be called for imported targets.
  3203. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3204. // enforcement of the limited imported target API.
  3205. if(this->IsImported())
  3206. {
  3207. std::string msg =
  3208. "GetExecutableNames called on imported target: ";
  3209. msg += this->GetName();
  3210. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3211. }
  3212. // This versioning is supported only for executables and then only
  3213. // when the platform supports symbolic links.
  3214. #if defined(_WIN32) && !defined(__CYGWIN__)
  3215. const char* version = 0;
  3216. #else
  3217. // Check for executable version properties.
  3218. const char* version = this->GetProperty("VERSION");
  3219. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3220. {
  3221. version = 0;
  3222. }
  3223. #endif
  3224. // Get the components of the executable name.
  3225. std::string prefix;
  3226. std::string base;
  3227. std::string suffix;
  3228. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3229. // The executable name.
  3230. name = prefix+base+suffix;
  3231. // The executable's real name on disk.
  3232. #if defined(__CYGWIN__)
  3233. realName = prefix+base;
  3234. #else
  3235. realName = name;
  3236. #endif
  3237. if(version)
  3238. {
  3239. realName += "-";
  3240. realName += version;
  3241. }
  3242. #if defined(__CYGWIN__)
  3243. realName += suffix;
  3244. #endif
  3245. // The import library name.
  3246. impName = this->GetFullNameInternal(config, true);
  3247. // The program database file name.
  3248. pdbName = this->GetPDBName(config);
  3249. }
  3250. //----------------------------------------------------------------------------
  3251. bool cmTarget::HasImplibGNUtoMS()
  3252. {
  3253. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3254. }
  3255. //----------------------------------------------------------------------------
  3256. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3257. std::string& out, const char* newExt)
  3258. {
  3259. if(this->HasImplibGNUtoMS() &&
  3260. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3261. {
  3262. out = gnuName.substr(0, gnuName.size()-6);
  3263. out += newExt? newExt : ".lib";
  3264. return true;
  3265. }
  3266. return false;
  3267. }
  3268. //----------------------------------------------------------------------------
  3269. void cmTarget::GenerateTargetManifest(const char* config)
  3270. {
  3271. cmMakefile* mf = this->Makefile;
  3272. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3273. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3274. // Get the names.
  3275. std::string name;
  3276. std::string soName;
  3277. std::string realName;
  3278. std::string impName;
  3279. std::string pdbName;
  3280. if(this->GetType() == cmTarget::EXECUTABLE)
  3281. {
  3282. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3283. }
  3284. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3285. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3286. this->GetType() == cmTarget::MODULE_LIBRARY)
  3287. {
  3288. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3289. }
  3290. else
  3291. {
  3292. return;
  3293. }
  3294. // Get the directory.
  3295. std::string dir = this->GetDirectory(config, false);
  3296. // Add each name.
  3297. std::string f;
  3298. if(!name.empty())
  3299. {
  3300. f = dir;
  3301. f += "/";
  3302. f += name;
  3303. gg->AddToManifest(config? config:"", f);
  3304. }
  3305. if(!soName.empty())
  3306. {
  3307. f = dir;
  3308. f += "/";
  3309. f += soName;
  3310. gg->AddToManifest(config? config:"", f);
  3311. }
  3312. if(!realName.empty())
  3313. {
  3314. f = dir;
  3315. f += "/";
  3316. f += realName;
  3317. gg->AddToManifest(config? config:"", f);
  3318. }
  3319. if(!pdbName.empty())
  3320. {
  3321. f = this->GetPDBDirectory(config);
  3322. f += "/";
  3323. f += pdbName;
  3324. gg->AddToManifest(config? config:"", f);
  3325. }
  3326. if(!impName.empty())
  3327. {
  3328. f = this->GetDirectory(config, true);
  3329. f += "/";
  3330. f += impName;
  3331. gg->AddToManifest(config? config:"", f);
  3332. }
  3333. }
  3334. //----------------------------------------------------------------------------
  3335. void cmTarget::SetPropertyDefault(const char* property,
  3336. const char* default_value)
  3337. {
  3338. // Compute the name of the variable holding the default value.
  3339. std::string var = "CMAKE_";
  3340. var += property;
  3341. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3342. {
  3343. this->SetProperty(property, value);
  3344. }
  3345. else if(default_value)
  3346. {
  3347. this->SetProperty(property, default_value);
  3348. }
  3349. }
  3350. //----------------------------------------------------------------------------
  3351. bool cmTarget::HaveBuildTreeRPATH()
  3352. {
  3353. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  3354. !this->LinkLibraries.empty());
  3355. }
  3356. //----------------------------------------------------------------------------
  3357. bool cmTarget::HaveInstallTreeRPATH()
  3358. {
  3359. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3360. return (install_rpath && *install_rpath) &&
  3361. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3362. }
  3363. //----------------------------------------------------------------------------
  3364. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3365. {
  3366. // Only executables and shared libraries can have an rpath and may
  3367. // need relinking.
  3368. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3369. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3370. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3371. {
  3372. return false;
  3373. }
  3374. // If there is no install location this target will not be installed
  3375. // and therefore does not need relinking.
  3376. if(!this->GetHaveInstallRule())
  3377. {
  3378. return false;
  3379. }
  3380. // If skipping all rpaths completely then no relinking is needed.
  3381. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3382. {
  3383. return false;
  3384. }
  3385. // If building with the install-tree rpath no relinking is needed.
  3386. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3387. {
  3388. return false;
  3389. }
  3390. // If chrpath is going to be used no relinking is needed.
  3391. if(this->IsChrpathUsed(config))
  3392. {
  3393. return false;
  3394. }
  3395. // Check for rpath support on this platform.
  3396. if(const char* ll = this->GetLinkerLanguage(config))
  3397. {
  3398. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3399. flagVar += ll;
  3400. flagVar += "_FLAG";
  3401. if(!this->Makefile->IsSet(flagVar.c_str()))
  3402. {
  3403. // There is no rpath support on this platform so nothing needs
  3404. // relinking.
  3405. return false;
  3406. }
  3407. }
  3408. else
  3409. {
  3410. // No linker language is known. This error will be reported by
  3411. // other code.
  3412. return false;
  3413. }
  3414. // If either a build or install tree rpath is set then the rpath
  3415. // will likely change between the build tree and install tree and
  3416. // this target must be relinked.
  3417. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  3418. }
  3419. //----------------------------------------------------------------------------
  3420. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  3421. bool for_xcode)
  3422. {
  3423. // If building directly for installation then the build tree install_name
  3424. // is the same as the install tree.
  3425. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3426. {
  3427. return GetInstallNameDirForInstallTree(config, for_xcode);
  3428. }
  3429. // Use the build tree directory for the target.
  3430. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3431. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3432. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3433. {
  3434. std::string dir = this->GetDirectory(config);
  3435. dir += "/";
  3436. if(this->IsFrameworkOnApple() && !for_xcode)
  3437. {
  3438. dir += this->GetFrameworkDirectory(config);
  3439. }
  3440. return dir;
  3441. }
  3442. else
  3443. {
  3444. return "";
  3445. }
  3446. }
  3447. //----------------------------------------------------------------------------
  3448. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  3449. bool for_xcode)
  3450. {
  3451. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3452. {
  3453. std::string dir;
  3454. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3455. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  3456. {
  3457. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3458. if(install_name_dir && *install_name_dir)
  3459. {
  3460. dir = install_name_dir;
  3461. dir += "/";
  3462. }
  3463. }
  3464. if(this->IsFrameworkOnApple() && !for_xcode)
  3465. {
  3466. dir += this->GetFrameworkDirectory(config);
  3467. }
  3468. return dir;
  3469. }
  3470. else
  3471. {
  3472. return "";
  3473. }
  3474. }
  3475. //----------------------------------------------------------------------------
  3476. const char* cmTarget::GetOutputTargetType(bool implib)
  3477. {
  3478. switch(this->GetType())
  3479. {
  3480. case cmTarget::SHARED_LIBRARY:
  3481. if(this->DLLPlatform)
  3482. {
  3483. if(implib)
  3484. {
  3485. // A DLL import library is treated as an archive target.
  3486. return "ARCHIVE";
  3487. }
  3488. else
  3489. {
  3490. // A DLL shared library is treated as a runtime target.
  3491. return "RUNTIME";
  3492. }
  3493. }
  3494. else
  3495. {
  3496. // For non-DLL platforms shared libraries are treated as
  3497. // library targets.
  3498. return "LIBRARY";
  3499. }
  3500. case cmTarget::STATIC_LIBRARY:
  3501. // Static libraries are always treated as archive targets.
  3502. return "ARCHIVE";
  3503. case cmTarget::MODULE_LIBRARY:
  3504. if(implib)
  3505. {
  3506. // Module libraries are always treated as library targets.
  3507. return "ARCHIVE";
  3508. }
  3509. else
  3510. {
  3511. // Module import libraries are treated as archive targets.
  3512. return "LIBRARY";
  3513. }
  3514. case cmTarget::EXECUTABLE:
  3515. if(implib)
  3516. {
  3517. // Executable import libraries are treated as archive targets.
  3518. return "ARCHIVE";
  3519. }
  3520. else
  3521. {
  3522. // Executables are always treated as runtime targets.
  3523. return "RUNTIME";
  3524. }
  3525. default:
  3526. break;
  3527. }
  3528. return "";
  3529. }
  3530. //----------------------------------------------------------------------------
  3531. bool cmTarget::ComputeOutputDir(const char* config,
  3532. bool implib, std::string& out)
  3533. {
  3534. bool usesDefaultOutputDir = false;
  3535. // Look for a target property defining the target output directory
  3536. // based on the target type.
  3537. std::string targetTypeName = this->GetOutputTargetType(implib);
  3538. const char* propertyName = 0;
  3539. std::string propertyNameStr = targetTypeName;
  3540. if(!propertyNameStr.empty())
  3541. {
  3542. propertyNameStr += "_OUTPUT_DIRECTORY";
  3543. propertyName = propertyNameStr.c_str();
  3544. }
  3545. // Check for a per-configuration output directory target property.
  3546. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3547. const char* configProp = 0;
  3548. std::string configPropStr = targetTypeName;
  3549. if(!configPropStr.empty())
  3550. {
  3551. configPropStr += "_OUTPUT_DIRECTORY_";
  3552. configPropStr += configUpper;
  3553. configProp = configPropStr.c_str();
  3554. }
  3555. // Select an output directory.
  3556. if(const char* config_outdir = this->GetProperty(configProp))
  3557. {
  3558. // Use the user-specified per-configuration output directory.
  3559. out = config_outdir;
  3560. // Skip per-configuration subdirectory.
  3561. config = 0;
  3562. }
  3563. else if(const char* outdir = this->GetProperty(propertyName))
  3564. {
  3565. // Use the user-specified output directory.
  3566. out = outdir;
  3567. }
  3568. else if(this->GetType() == cmTarget::EXECUTABLE)
  3569. {
  3570. // Lookup the output path for executables.
  3571. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3572. }
  3573. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3574. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3575. this->GetType() == cmTarget::MODULE_LIBRARY)
  3576. {
  3577. // Lookup the output path for libraries.
  3578. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3579. }
  3580. if(out.empty())
  3581. {
  3582. // Default to the current output directory.
  3583. usesDefaultOutputDir = true;
  3584. out = ".";
  3585. }
  3586. // Convert the output path to a full path in case it is
  3587. // specified as a relative path. Treat a relative path as
  3588. // relative to the current output directory for this makefile.
  3589. out = (cmSystemTools::CollapseFullPath
  3590. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3591. // The generator may add the configuration's subdirectory.
  3592. if(config && *config)
  3593. {
  3594. const char *platforms = this->Makefile->GetDefinition(
  3595. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3596. std::string suffix =
  3597. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3598. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3599. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  3600. }
  3601. return usesDefaultOutputDir;
  3602. }
  3603. //----------------------------------------------------------------------------
  3604. void cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
  3605. {
  3606. // Look for a target property defining the target output directory
  3607. // based on the target type.
  3608. std::string targetTypeName = "PDB";
  3609. const char* propertyName = 0;
  3610. std::string propertyNameStr = targetTypeName;
  3611. if(!propertyNameStr.empty())
  3612. {
  3613. propertyNameStr += "_OUTPUT_DIRECTORY";
  3614. propertyName = propertyNameStr.c_str();
  3615. }
  3616. // Check for a per-configuration output directory target property.
  3617. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3618. const char* configProp = 0;
  3619. std::string configPropStr = targetTypeName;
  3620. if(!configPropStr.empty())
  3621. {
  3622. configPropStr += "_OUTPUT_DIRECTORY_";
  3623. configPropStr += configUpper;
  3624. configProp = configPropStr.c_str();
  3625. }
  3626. // Select an output directory.
  3627. if(const char* config_outdir = this->GetProperty(configProp))
  3628. {
  3629. // Use the user-specified per-configuration output directory.
  3630. out = config_outdir;
  3631. // Skip per-configuration subdirectory.
  3632. config = 0;
  3633. }
  3634. else if(const char* outdir = this->GetProperty(propertyName))
  3635. {
  3636. // Use the user-specified output directory.
  3637. out = outdir;
  3638. }
  3639. if(out.empty())
  3640. {
  3641. // Default to the current output directory.
  3642. out = ".";
  3643. }
  3644. // Convert the output path to a full path in case it is
  3645. // specified as a relative path. Treat a relative path as
  3646. // relative to the current output directory for this makefile.
  3647. out = (cmSystemTools::CollapseFullPath
  3648. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3649. // The generator may add the configuration's subdirectory.
  3650. if(config && *config)
  3651. {
  3652. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3653. AppendDirectoryForConfig("/", config, "", out);
  3654. }
  3655. }
  3656. //----------------------------------------------------------------------------
  3657. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
  3658. {
  3659. std::string dir;
  3660. return this->ComputeOutputDir(config, implib, dir);
  3661. }
  3662. //----------------------------------------------------------------------------
  3663. std::string cmTarget::GetOutputName(const char* config, bool implib)
  3664. {
  3665. std::vector<std::string> props;
  3666. std::string type = this->GetOutputTargetType(implib);
  3667. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3668. if(!type.empty() && !configUpper.empty())
  3669. {
  3670. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3671. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3672. }
  3673. if(!type.empty())
  3674. {
  3675. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3676. props.push_back(type + "_OUTPUT_NAME");
  3677. }
  3678. if(!configUpper.empty())
  3679. {
  3680. // OUTPUT_NAME_<CONFIG>
  3681. props.push_back("OUTPUT_NAME_" + configUpper);
  3682. // <CONFIG>_OUTPUT_NAME
  3683. props.push_back(configUpper + "_OUTPUT_NAME");
  3684. }
  3685. // OUTPUT_NAME
  3686. props.push_back("OUTPUT_NAME");
  3687. for(std::vector<std::string>::const_iterator i = props.begin();
  3688. i != props.end(); ++i)
  3689. {
  3690. if(const char* outName = this->GetProperty(i->c_str()))
  3691. {
  3692. return outName;
  3693. }
  3694. }
  3695. return this->GetName();
  3696. }
  3697. //----------------------------------------------------------------------------
  3698. std::string cmTarget::GetFrameworkVersion()
  3699. {
  3700. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3701. {
  3702. return fversion;
  3703. }
  3704. else if(const char* tversion = this->GetProperty("VERSION"))
  3705. {
  3706. return tversion;
  3707. }
  3708. else
  3709. {
  3710. return "A";
  3711. }
  3712. }
  3713. //----------------------------------------------------------------------------
  3714. const char* cmTarget::GetExportMacro()
  3715. {
  3716. // Define the symbol for targets that export symbols.
  3717. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3718. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3719. this->IsExecutableWithExports())
  3720. {
  3721. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3722. {
  3723. this->ExportMacro = custom_export_name;
  3724. }
  3725. else
  3726. {
  3727. std::string in = this->GetName();
  3728. in += "_EXPORTS";
  3729. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  3730. }
  3731. return this->ExportMacro.c_str();
  3732. }
  3733. else
  3734. {
  3735. return 0;
  3736. }
  3737. }
  3738. //----------------------------------------------------------------------------
  3739. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  3740. {
  3741. for(std::vector<cmSourceFile*>::const_iterator
  3742. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  3743. {
  3744. if(const char* lang = (*i)->GetLanguage())
  3745. {
  3746. languages.insert(lang);
  3747. }
  3748. }
  3749. }
  3750. //----------------------------------------------------------------------------
  3751. bool cmTarget::IsChrpathUsed(const char* config)
  3752. {
  3753. #if defined(CMAKE_USE_ELF_PARSER)
  3754. // Only certain target types have an rpath.
  3755. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3756. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3757. this->GetType() == cmTarget::EXECUTABLE))
  3758. {
  3759. return false;
  3760. }
  3761. // If the target will not be installed we do not need to change its
  3762. // rpath.
  3763. if(!this->GetHaveInstallRule())
  3764. {
  3765. return false;
  3766. }
  3767. // Skip chrpath if skipping rpath altogether.
  3768. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3769. {
  3770. return false;
  3771. }
  3772. // Skip chrpath if it does not need to be changed at install time.
  3773. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3774. {
  3775. return false;
  3776. }
  3777. // Allow the user to disable builtin chrpath explicitly.
  3778. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  3779. {
  3780. return false;
  3781. }
  3782. // Enable if the rpath flag uses a separator and the target uses ELF
  3783. // binaries.
  3784. if(const char* ll = this->GetLinkerLanguage(config))
  3785. {
  3786. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3787. sepVar += ll;
  3788. sepVar += "_FLAG_SEP";
  3789. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  3790. if(sep && *sep)
  3791. {
  3792. // TODO: Add ELF check to ABI detection and get rid of
  3793. // CMAKE_EXECUTABLE_FORMAT.
  3794. if(const char* fmt =
  3795. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  3796. {
  3797. return strcmp(fmt, "ELF") == 0;
  3798. }
  3799. }
  3800. }
  3801. #endif
  3802. static_cast<void>(config);
  3803. return false;
  3804. }
  3805. //----------------------------------------------------------------------------
  3806. cmTarget::ImportInfo const*
  3807. cmTarget::GetImportInfo(const char* config)
  3808. {
  3809. // There is no imported information for non-imported targets.
  3810. if(!this->IsImported())
  3811. {
  3812. return 0;
  3813. }
  3814. // Lookup/compute/cache the import information for this
  3815. // configuration.
  3816. std::string config_upper;
  3817. if(config && *config)
  3818. {
  3819. config_upper = cmSystemTools::UpperCase(config);
  3820. }
  3821. else
  3822. {
  3823. config_upper = "NOCONFIG";
  3824. }
  3825. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3826. ImportInfoMapType::const_iterator i =
  3827. this->Internal->ImportInfoMap.find(config_upper);
  3828. if(i == this->Internal->ImportInfoMap.end())
  3829. {
  3830. ImportInfo info;
  3831. this->ComputeImportInfo(config_upper, info);
  3832. ImportInfoMapType::value_type entry(config_upper, info);
  3833. i = this->Internal->ImportInfoMap.insert(entry).first;
  3834. }
  3835. // If the location is empty then the target is not available for
  3836. // this configuration.
  3837. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3838. {
  3839. return 0;
  3840. }
  3841. // Return the import information.
  3842. return &i->second;
  3843. }
  3844. //----------------------------------------------------------------------------
  3845. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3846. ImportInfo& info)
  3847. {
  3848. // This method finds information about an imported target from its
  3849. // properties. The "IMPORTED_" namespace is reserved for properties
  3850. // defined by the project exporting the target.
  3851. // Initialize members.
  3852. info.NoSOName = false;
  3853. // Track the configuration-specific property suffix.
  3854. std::string suffix = "_";
  3855. suffix += desired_config;
  3856. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3857. // library or an executable with exports.
  3858. bool allowImp = this->HasImportLibrary();
  3859. // Look for a mapping from the current project's configuration to
  3860. // the imported project's configuration.
  3861. std::vector<std::string> mappedConfigs;
  3862. {
  3863. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3864. mapProp += desired_config;
  3865. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  3866. {
  3867. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3868. }
  3869. }
  3870. // If a mapping was found, check its configurations.
  3871. const char* loc = 0;
  3872. const char* imp = 0;
  3873. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3874. !loc && !imp && mci != mappedConfigs.end(); ++mci)
  3875. {
  3876. // Look for this configuration.
  3877. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  3878. std::string locProp = "IMPORTED_LOCATION_";
  3879. locProp += mcUpper;
  3880. loc = this->GetProperty(locProp.c_str());
  3881. if(allowImp)
  3882. {
  3883. std::string impProp = "IMPORTED_IMPLIB_";
  3884. impProp += mcUpper;
  3885. imp = this->GetProperty(impProp.c_str());
  3886. }
  3887. // If it was found, use it for all properties below.
  3888. if(loc || imp)
  3889. {
  3890. suffix = "_";
  3891. suffix += mcUpper;
  3892. }
  3893. }
  3894. // If we needed to find one of the mapped configurations but did not
  3895. // then the target is not found. The project does not want any
  3896. // other configuration.
  3897. if(!mappedConfigs.empty() && !loc && !imp)
  3898. {
  3899. return;
  3900. }
  3901. // If we have not yet found it then there are no mapped
  3902. // configurations. Look for an exact-match.
  3903. if(!loc && !imp)
  3904. {
  3905. std::string locProp = "IMPORTED_LOCATION";
  3906. locProp += suffix;
  3907. loc = this->GetProperty(locProp.c_str());
  3908. if(allowImp)
  3909. {
  3910. std::string impProp = "IMPORTED_IMPLIB";
  3911. impProp += suffix;
  3912. imp = this->GetProperty(impProp.c_str());
  3913. }
  3914. }
  3915. // If we have not yet found it then there are no mapped
  3916. // configurations and no exact match.
  3917. if(!loc && !imp)
  3918. {
  3919. // The suffix computed above is not useful.
  3920. suffix = "";
  3921. // Look for a configuration-less location. This may be set by
  3922. // manually-written code.
  3923. loc = this->GetProperty("IMPORTED_LOCATION");
  3924. if(allowImp)
  3925. {
  3926. imp = this->GetProperty("IMPORTED_IMPLIB");
  3927. }
  3928. }
  3929. // If we have not yet found it then the project is willing to try
  3930. // any available configuration.
  3931. if(!loc && !imp)
  3932. {
  3933. std::vector<std::string> availableConfigs;
  3934. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3935. {
  3936. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3937. }
  3938. for(std::vector<std::string>::const_iterator
  3939. aci = availableConfigs.begin();
  3940. !loc && !imp && aci != availableConfigs.end(); ++aci)
  3941. {
  3942. suffix = "_";
  3943. suffix += cmSystemTools::UpperCase(*aci);
  3944. std::string locProp = "IMPORTED_LOCATION";
  3945. locProp += suffix;
  3946. loc = this->GetProperty(locProp.c_str());
  3947. if(allowImp)
  3948. {
  3949. std::string impProp = "IMPORTED_IMPLIB";
  3950. impProp += suffix;
  3951. imp = this->GetProperty(impProp.c_str());
  3952. }
  3953. }
  3954. }
  3955. // If we have not yet found it then the target is not available.
  3956. if(!loc && !imp)
  3957. {
  3958. return;
  3959. }
  3960. // A provided configuration has been chosen. Load the
  3961. // configuration's properties.
  3962. // Get the location.
  3963. if(loc)
  3964. {
  3965. info.Location = loc;
  3966. }
  3967. else
  3968. {
  3969. std::string impProp = "IMPORTED_LOCATION";
  3970. impProp += suffix;
  3971. if(const char* config_location = this->GetProperty(impProp.c_str()))
  3972. {
  3973. info.Location = config_location;
  3974. }
  3975. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3976. {
  3977. info.Location = location;
  3978. }
  3979. }
  3980. // Get the soname.
  3981. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3982. {
  3983. std::string soProp = "IMPORTED_SONAME";
  3984. soProp += suffix;
  3985. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  3986. {
  3987. info.SOName = config_soname;
  3988. }
  3989. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3990. {
  3991. info.SOName = soname;
  3992. }
  3993. }
  3994. // Get the "no-soname" mark.
  3995. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3996. {
  3997. std::string soProp = "IMPORTED_NO_SONAME";
  3998. soProp += suffix;
  3999. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  4000. {
  4001. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4002. }
  4003. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4004. {
  4005. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4006. }
  4007. }
  4008. // Get the import library.
  4009. if(imp)
  4010. {
  4011. info.ImportLibrary = imp;
  4012. }
  4013. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4014. this->IsExecutableWithExports())
  4015. {
  4016. std::string impProp = "IMPORTED_IMPLIB";
  4017. impProp += suffix;
  4018. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  4019. {
  4020. info.ImportLibrary = config_implib;
  4021. }
  4022. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4023. {
  4024. info.ImportLibrary = implib;
  4025. }
  4026. }
  4027. // Get the link interface.
  4028. {
  4029. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4030. linkProp += suffix;
  4031. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4032. {
  4033. cmSystemTools::ExpandListArgument(config_libs,
  4034. info.LinkInterface.Libraries);
  4035. }
  4036. else if(const char* libs =
  4037. this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
  4038. {
  4039. cmSystemTools::ExpandListArgument(libs,
  4040. info.LinkInterface.Libraries);
  4041. }
  4042. }
  4043. // Get the link dependencies.
  4044. {
  4045. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4046. linkProp += suffix;
  4047. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4048. {
  4049. cmSystemTools::ExpandListArgument(config_libs,
  4050. info.LinkInterface.SharedDeps);
  4051. }
  4052. else if(const char* libs =
  4053. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4054. {
  4055. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  4056. }
  4057. }
  4058. // Get the link languages.
  4059. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4060. {
  4061. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4062. linkProp += suffix;
  4063. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4064. {
  4065. cmSystemTools::ExpandListArgument(config_libs,
  4066. info.LinkInterface.Languages);
  4067. }
  4068. else if(const char* libs =
  4069. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4070. {
  4071. cmSystemTools::ExpandListArgument(libs,
  4072. info.LinkInterface.Languages);
  4073. }
  4074. }
  4075. // Get the cyclic repetition count.
  4076. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4077. {
  4078. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4079. linkProp += suffix;
  4080. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  4081. {
  4082. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  4083. }
  4084. else if(const char* reps =
  4085. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4086. {
  4087. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  4088. }
  4089. }
  4090. }
  4091. //----------------------------------------------------------------------------
  4092. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
  4093. {
  4094. // Imported targets have their own link interface.
  4095. if(this->IsImported())
  4096. {
  4097. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  4098. {
  4099. return &info->LinkInterface;
  4100. }
  4101. return 0;
  4102. }
  4103. // Link interfaces are not supported for executables that do not
  4104. // export symbols.
  4105. if(this->GetType() == cmTarget::EXECUTABLE &&
  4106. !this->IsExecutableWithExports())
  4107. {
  4108. return 0;
  4109. }
  4110. // Lookup any existing link interface for this configuration.
  4111. std::string key = cmSystemTools::UpperCase(config? config : "");
  4112. cmTargetInternals::LinkInterfaceMapType::iterator
  4113. i = this->Internal->LinkInterfaceMap.find(key);
  4114. if(i == this->Internal->LinkInterfaceMap.end())
  4115. {
  4116. // Compute the link interface for this configuration.
  4117. cmTargetInternals::OptionalLinkInterface iface;
  4118. iface.Exists = this->ComputeLinkInterface(config, iface);
  4119. // Store the information for this configuration.
  4120. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  4121. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  4122. }
  4123. return i->second.Exists? &i->second : 0;
  4124. }
  4125. //----------------------------------------------------------------------------
  4126. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
  4127. {
  4128. // Construct the property name suffix for this configuration.
  4129. std::string suffix = "_";
  4130. if(config && *config)
  4131. {
  4132. suffix += cmSystemTools::UpperCase(config);
  4133. }
  4134. else
  4135. {
  4136. suffix += "NOCONFIG";
  4137. }
  4138. // An explicit list of interface libraries may be set for shared
  4139. // libraries and executables that export symbols.
  4140. const char* explicitLibraries = 0;
  4141. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4142. this->IsExecutableWithExports())
  4143. {
  4144. // Lookup the per-configuration property.
  4145. std::string propName = "LINK_INTERFACE_LIBRARIES";
  4146. propName += suffix;
  4147. explicitLibraries = this->GetProperty(propName.c_str());
  4148. // If not set, try the generic property.
  4149. if(!explicitLibraries)
  4150. {
  4151. explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
  4152. }
  4153. }
  4154. // There is no implicit link interface for executables or modules
  4155. // so if none was explicitly set then there is no link interface.
  4156. // Note that CMake versions 2.2 and below allowed linking to modules.
  4157. bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
  4158. if(!explicitLibraries &&
  4159. (this->GetType() == cmTarget::EXECUTABLE ||
  4160. (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
  4161. {
  4162. return false;
  4163. }
  4164. if(explicitLibraries)
  4165. {
  4166. // The interface libraries have been explicitly set.
  4167. cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
  4168. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4169. {
  4170. // Shared libraries may have runtime implementation dependencies
  4171. // on other shared libraries that are not in the interface.
  4172. std::set<cmStdString> emitted;
  4173. for(std::vector<std::string>::const_iterator
  4174. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4175. {
  4176. emitted.insert(*li);
  4177. }
  4178. LinkImplementation const* impl = this->GetLinkImplementation(config);
  4179. for(std::vector<std::string>::const_iterator
  4180. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4181. {
  4182. if(emitted.insert(*li).second)
  4183. {
  4184. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  4185. {
  4186. // This is a runtime dependency on another shared library.
  4187. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  4188. {
  4189. iface.SharedDeps.push_back(*li);
  4190. }
  4191. }
  4192. else
  4193. {
  4194. // TODO: Recognize shared library file names. Perhaps this
  4195. // should be moved to cmComputeLinkInformation, but that creates
  4196. // a chicken-and-egg problem since this list is needed for its
  4197. // construction.
  4198. }
  4199. }
  4200. }
  4201. }
  4202. }
  4203. else
  4204. {
  4205. // The link implementation is the default link interface.
  4206. LinkImplementation const* impl = this->GetLinkImplementation(config);
  4207. iface.Libraries = impl->Libraries;
  4208. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4209. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4210. {
  4211. // Targets using this archive need its language runtime libraries.
  4212. iface.Languages = impl->Languages;
  4213. }
  4214. }
  4215. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4216. {
  4217. // How many repetitions are needed if this library has cyclic
  4218. // dependencies?
  4219. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4220. propName += suffix;
  4221. if(const char* config_reps = this->GetProperty(propName.c_str()))
  4222. {
  4223. sscanf(config_reps, "%u", &iface.Multiplicity);
  4224. }
  4225. else if(const char* reps =
  4226. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4227. {
  4228. sscanf(reps, "%u", &iface.Multiplicity);
  4229. }
  4230. }
  4231. return true;
  4232. }
  4233. //----------------------------------------------------------------------------
  4234. cmTarget::LinkImplementation const*
  4235. cmTarget::GetLinkImplementation(const char* config)
  4236. {
  4237. // There is no link implementation for imported targets.
  4238. if(this->IsImported())
  4239. {
  4240. return 0;
  4241. }
  4242. // Lookup any existing link implementation for this configuration.
  4243. std::string key = cmSystemTools::UpperCase(config? config : "");
  4244. cmTargetInternals::LinkImplMapType::iterator
  4245. i = this->Internal->LinkImplMap.find(key);
  4246. if(i == this->Internal->LinkImplMap.end())
  4247. {
  4248. // Compute the link implementation for this configuration.
  4249. LinkImplementation impl;
  4250. this->ComputeLinkImplementation(config, impl);
  4251. // Store the information for this configuration.
  4252. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  4253. i = this->Internal->LinkImplMap.insert(entry).first;
  4254. }
  4255. return &i->second;
  4256. }
  4257. //----------------------------------------------------------------------------
  4258. void cmTarget::ComputeLinkImplementation(const char* config,
  4259. LinkImplementation& impl)
  4260. {
  4261. // Compute which library configuration to link.
  4262. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  4263. // Collect libraries directly linked in this configuration.
  4264. LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
  4265. for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
  4266. li != llibs.end(); ++li)
  4267. {
  4268. // Skip entries that resolve to the target itself or are empty.
  4269. std::string item = this->CheckCMP0004(li->first);
  4270. if(item == this->GetName() || item.empty())
  4271. {
  4272. continue;
  4273. }
  4274. if(li->second == cmTarget::GENERAL || li->second == linkType)
  4275. {
  4276. // The entry is meant for this configuration.
  4277. impl.Libraries.push_back(item);
  4278. }
  4279. else
  4280. {
  4281. // Support OLD behavior for CMP0003.
  4282. impl.WrongConfigLibraries.push_back(item);
  4283. }
  4284. }
  4285. // This target needs runtime libraries for its source languages.
  4286. std::set<cmStdString> languages;
  4287. // Get languages used in our source files.
  4288. this->GetLanguages(languages);
  4289. // Get languages used in object library sources.
  4290. for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
  4291. i != this->ObjectLibraries.end(); ++i)
  4292. {
  4293. if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
  4294. {
  4295. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  4296. {
  4297. objLib->GetLanguages(languages);
  4298. }
  4299. }
  4300. }
  4301. // Copy the set of langauges to the link implementation.
  4302. for(std::set<cmStdString>::iterator li = languages.begin();
  4303. li != languages.end(); ++li)
  4304. {
  4305. impl.Languages.push_back(*li);
  4306. }
  4307. }
  4308. //----------------------------------------------------------------------------
  4309. std::string cmTarget::CheckCMP0004(std::string const& item)
  4310. {
  4311. // Strip whitespace off the library names because we used to do this
  4312. // in case variables were expanded at generate time. We no longer
  4313. // do the expansion but users link to libraries like " ${VAR} ".
  4314. std::string lib = item;
  4315. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4316. if(pos != lib.npos)
  4317. {
  4318. lib = lib.substr(pos, lib.npos);
  4319. }
  4320. pos = lib.find_last_not_of(" \t\r\n");
  4321. if(pos != lib.npos)
  4322. {
  4323. lib = lib.substr(0, pos+1);
  4324. }
  4325. if(lib != item)
  4326. {
  4327. cmake* cm = this->Makefile->GetCMakeInstance();
  4328. switch(this->PolicyStatusCMP0004)
  4329. {
  4330. case cmPolicies::WARN:
  4331. {
  4332. cmOStringStream w;
  4333. w << (this->Makefile->GetPolicies()
  4334. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  4335. << "Target \"" << this->GetName() << "\" links to item \""
  4336. << item << "\" which has leading or trailing whitespace.";
  4337. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4338. this->GetBacktrace());
  4339. }
  4340. case cmPolicies::OLD:
  4341. break;
  4342. case cmPolicies::NEW:
  4343. {
  4344. cmOStringStream e;
  4345. e << "Target \"" << this->GetName() << "\" links to item \""
  4346. << item << "\" which has leading or trailing whitespace. "
  4347. << "This is now an error according to policy CMP0004.";
  4348. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4349. }
  4350. break;
  4351. case cmPolicies::REQUIRED_IF_USED:
  4352. case cmPolicies::REQUIRED_ALWAYS:
  4353. {
  4354. cmOStringStream e;
  4355. e << (this->Makefile->GetPolicies()
  4356. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  4357. << "Target \"" << this->GetName() << "\" links to item \""
  4358. << item << "\" which has leading or trailing whitespace.";
  4359. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4360. }
  4361. break;
  4362. }
  4363. }
  4364. return lib;
  4365. }
  4366. //----------------------------------------------------------------------------
  4367. std::string cmTarget::GetFrameworkDirectory(const char* config)
  4368. {
  4369. std::string fpath;
  4370. fpath += this->GetFullName(config, false);
  4371. fpath += ".framework/Versions/";
  4372. fpath += this->GetFrameworkVersion();
  4373. fpath += "/";
  4374. return fpath;
  4375. }
  4376. //----------------------------------------------------------------------------
  4377. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  4378. const char* config,
  4379. bool includeMacOS)
  4380. {
  4381. std::string fpath = base;
  4382. if(this->IsAppBundleOnApple())
  4383. {
  4384. fpath += this->GetFullName(config, false);
  4385. fpath += ".app/Contents/";
  4386. if(includeMacOS)
  4387. fpath += "MacOS/";
  4388. }
  4389. if(this->IsFrameworkOnApple())
  4390. {
  4391. fpath += this->GetFrameworkDirectory(config);
  4392. }
  4393. if(this->IsCFBundleOnApple())
  4394. {
  4395. fpath += this->GetFullName(config, false);
  4396. fpath += ".";
  4397. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  4398. if (!ext)
  4399. {
  4400. ext = "bundle";
  4401. }
  4402. fpath += ext;
  4403. fpath += "/Contents/";
  4404. if(includeMacOS)
  4405. fpath += "MacOS/";
  4406. }
  4407. return fpath;
  4408. }
  4409. //----------------------------------------------------------------------------
  4410. std::string cmTarget::GetMacContentDirectory(const char* config,
  4411. bool implib,
  4412. bool includeMacOS)
  4413. {
  4414. // Start with the output directory for the target.
  4415. std::string fpath = this->GetDirectory(config, implib);
  4416. fpath += "/";
  4417. fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
  4418. return fpath;
  4419. }
  4420. //----------------------------------------------------------------------------
  4421. cmTargetInternalPointer::cmTargetInternalPointer()
  4422. {
  4423. this->Pointer = new cmTargetInternals;
  4424. }
  4425. //----------------------------------------------------------------------------
  4426. cmTargetInternalPointer
  4427. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4428. {
  4429. // Ideally cmTarget instances should never be copied. However until
  4430. // we can make a sweep to remove that, this copy constructor avoids
  4431. // allowing the resources (Internals) to be copied.
  4432. this->Pointer = new cmTargetInternals(*r.Pointer);
  4433. }
  4434. //----------------------------------------------------------------------------
  4435. cmTargetInternalPointer::~cmTargetInternalPointer()
  4436. {
  4437. delete this->Pointer;
  4438. }
  4439. //----------------------------------------------------------------------------
  4440. cmTargetInternalPointer&
  4441. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4442. {
  4443. if(this == &r) { return *this; } // avoid warning on HP about self check
  4444. // Ideally cmTarget instances should never be copied. However until
  4445. // we can make a sweep to remove that, this copy constructor avoids
  4446. // allowing the resources (Internals) to be copied.
  4447. cmTargetInternals* oldPointer = this->Pointer;
  4448. this->Pointer = new cmTargetInternals(*r.Pointer);
  4449. delete oldPointer;
  4450. return *this;
  4451. }