cmTarget.cxx 171 KB

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