cmTarget.cxx 167 KB

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