cmTarget.cxx 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmTarget.h"
  14. #include "cmake.h"
  15. #include "cmMakefile.h"
  16. #include "cmSourceFile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmComputeLinkInformation.h"
  20. #include "cmListFileCache.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::TargetTypeNames[] = {
  28. "EXECUTABLE", "STATIC_LIBRARY",
  29. "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
  30. "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
  31. "UNKNOWN_LIBRARY"
  32. };
  33. //----------------------------------------------------------------------------
  34. class cmTargetInternals
  35. {
  36. public:
  37. cmTargetInternals()
  38. {
  39. this->SourceFileFlagsConstructed = false;
  40. }
  41. typedef cmTarget::SourceFileFlags SourceFileFlags;
  42. std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  43. bool SourceFileFlagsConstructed;
  44. // The backtrace when the target was created.
  45. cmListFileBacktrace Backtrace;
  46. };
  47. //----------------------------------------------------------------------------
  48. cmTarget::cmTarget()
  49. {
  50. this->Makefile = 0;
  51. this->PolicyStatusCMP0003 = cmPolicies::WARN;
  52. this->PolicyStatusCMP0004 = cmPolicies::WARN;
  53. this->PolicyStatusCMP0008 = cmPolicies::WARN;
  54. this->LinkLibrariesAnalyzed = false;
  55. this->HaveInstallRule = false;
  56. this->DLLPlatform = false;
  57. this->IsImportedTarget = false;
  58. }
  59. //----------------------------------------------------------------------------
  60. void cmTarget::DefineProperties(cmake *cm)
  61. {
  62. cm->DefineProperty
  63. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  64. "Should build tree targets have install tree rpaths.",
  65. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  66. "the target in the build tree with the INSTALL_RPATH. This takes "
  67. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  68. "before installation. "
  69. "This property is initialized by the value of the variable "
  70. "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
  71. cm->DefineProperty
  72. ("CLEAN_DIRECT_OUTPUT", cmProperty::TARGET,
  73. "Do not delete other variants of this target.",
  74. "When a library is built CMake by default generates code to remove "
  75. "any existing library using all possible names. This is needed "
  76. "to support libraries that switch between STATIC and SHARED by "
  77. "a user option. However when using OUTPUT_NAME to build a static "
  78. "and shared library of the same name using different logical target "
  79. "names the two targets will remove each other's files. This can be "
  80. "prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.");
  81. cm->DefineProperty
  82. ("COMPILE_FLAGS", cmProperty::TARGET,
  83. "Additional flags to use when compiling this target's sources.",
  84. "The COMPILE_FLAGS property sets additional compiler flags used "
  85. "to build sources within the target. Use COMPILE_DEFINITIONS "
  86. "to pass additional preprocessor definitions.");
  87. cm->DefineProperty
  88. ("COMPILE_DEFINITIONS", cmProperty::TARGET,
  89. "Preprocessor definitions for compiling a target's sources.",
  90. "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
  91. "definitions using the syntax VAR or VAR=value. Function-style "
  92. "definitions are not supported. CMake will automatically escape "
  93. "the value correctly for the native build system (note that CMake "
  94. "language syntax may require escapes to specify some values). "
  95. "This property may be set on a per-configuration basis using the name "
  96. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  97. "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
  98. "CMake will automatically drop some definitions that "
  99. "are not supported by the native build tool. "
  100. "The VS6 IDE does not support definition values with spaces "
  101. "(but NMake does).\n"
  102. "Dislaimer: Most native build tools have poor support for escaping "
  103. "certain values. CMake has work-arounds for many cases but some "
  104. "values may just not be possible to pass correctly. If a value "
  105. "does not seem to be escaped correctly, do not attempt to "
  106. "work-around the problem by adding escape sequences to the value. "
  107. "Your work-around may break in a future version of CMake that "
  108. "has improved escape support. Instead consider defining the macro "
  109. "in a (configured) header file. Then report the limitation.");
  110. cm->DefineProperty
  111. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
  112. "Per-configuration preprocessor definitions on a target.",
  113. "This is the configuration-specific version of COMPILE_DEFINITIONS.");
  114. cm->DefineProperty
  115. ("DEFINE_SYMBOL", cmProperty::TARGET,
  116. "Define a symbol when compiling this target's sources.",
  117. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  118. "compiling sources in a shared library. "
  119. "If not set here then it is set to target_EXPORTS by default "
  120. "(with some substitutions if the target is not a valid C "
  121. "identifier). This is useful for headers to know whether they are "
  122. "being included from inside their library our outside to properly "
  123. "setup dllexport/dllimport decorations. ");
  124. cm->DefineProperty
  125. ("DEBUG_POSTFIX", cmProperty::TARGET,
  126. "See target property <CONFIG>_POSTFIX.",
  127. "This property is a special case of the more-general <CONFIG>_POSTFIX "
  128. "property for the DEBUG configuration.");
  129. cm->DefineProperty
  130. ("<CONFIG>_POSTFIX", cmProperty::TARGET,
  131. "Postfix to append to the target file name for configuration <CONFIG>.",
  132. "When building with configuration <CONFIG> the value of this property "
  133. "is appended to the target file name built on disk. "
  134. "For non-executable targets, this property is initialized by the value "
  135. "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
  136. "created. "
  137. "This property is ignored on the Mac for Frameworks and App Bundles.");
  138. cm->DefineProperty
  139. ("EchoString", cmProperty::TARGET,
  140. "A message to be displayed when the target is built.",
  141. "A message to display on some generators (such as makefiles) when "
  142. "the target is built.");
  143. cm->DefineProperty
  144. ("FRAMEWORK", cmProperty::TARGET,
  145. "This target is a framework on the Mac.",
  146. "If a shared library target has this property set to true it will "
  147. "be built as a framework when built on the mac. It will have the "
  148. "directory structure required for a framework and will be suitable "
  149. "to be used with the -framework option");
  150. cm->DefineProperty
  151. ("HAS_CXX", cmProperty::TARGET,
  152. "Force a target to use the CXX linker.",
  153. "Setting HAS_CXX on a target will force the target to use the "
  154. "C++ linker (and C++ runtime libraries) for linking even if the "
  155. "target has no C++ code in it.");
  156. cm->DefineProperty
  157. ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
  158. "Specify #include line transforms for dependencies in a target.",
  159. "This property specifies rules to transform macro-like #include lines "
  160. "during implicit dependency scanning of C and C++ source files. "
  161. "The list of rules must be semicolon-separated with each entry of "
  162. "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
  163. "During dependency scanning occurrences of A_MACRO(...) on #include "
  164. "lines will be replaced by the value given with the macro argument "
  165. "substituted for '%'. For example, the entry\n"
  166. " MYDIR(%)=<mydir/%>\n"
  167. "will convert lines of the form\n"
  168. " #include MYDIR(myheader.h)\n"
  169. "to\n"
  170. " #include <mydir/myheader.h>\n"
  171. "allowing the dependency to be followed.\n"
  172. "This property applies to sources in the target on which it is set.");
  173. cm->DefineProperty
  174. ("IMPORT_PREFIX", cmProperty::TARGET,
  175. "What comes before the import library name.",
  176. "Similar to the target property PREFIX, but used for import libraries "
  177. "(typically corresponding to a DLL) instead of regular libraries. "
  178. "A target property that can be set to override the prefix "
  179. "(such as \"lib\") on an import library name.");
  180. cm->DefineProperty
  181. ("IMPORT_SUFFIX", cmProperty::TARGET,
  182. "What comes after the import library name.",
  183. "Similar to the target property SUFFIX, but used for import libraries "
  184. "(typically corresponding to a DLL) instead of regular libraries. "
  185. "A target property that can be set to override the suffix "
  186. "(such as \".lib\") on an import library name.");
  187. cm->DefineProperty
  188. ("IMPORTED", cmProperty::TARGET,
  189. "Read-only indication of whether a target is IMPORTED.",
  190. "The boolean value of this property is true for targets created with "
  191. "the IMPORTED option to add_executable or add_library. "
  192. "It is false for targets built within the project.");
  193. cm->DefineProperty
  194. ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
  195. "Configurations provided for an IMPORTED target.",
  196. "Lists configuration names available for an IMPORTED target. "
  197. "The names correspond to configurations defined in the project from "
  198. "which the target is imported. "
  199. "If the importing project uses a different set of configurations "
  200. "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
  201. "property. "
  202. "Ignored for non-imported targets.");
  203. cm->DefineProperty
  204. ("IMPORTED_IMPLIB", cmProperty::TARGET,
  205. "Full path to the import library for an IMPORTED target.",
  206. "Specifies the location of the \".lib\" part of a windows DLL. "
  207. "Ignored for non-imported targets.");
  208. cm->DefineProperty
  209. ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
  210. "Per-configuration version of IMPORTED_IMPLIB property.",
  211. "This property is used when loading settings for the <CONFIG> "
  212. "configuration of an imported target. "
  213. "Configuration names correspond to those provided by the project "
  214. "from which the target is imported.");
  215. cm->DefineProperty
  216. ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
  217. "Dependent shared libraries of an imported shared library.",
  218. "Shared libraries may be linked to other shared libraries as part "
  219. "of their implementation. On some platforms the linker searches "
  220. "for the dependent libraries of shared libraries they are including "
  221. "in the link. This property lists "
  222. "the dependent shared libraries of an imported library. The list "
  223. "should be disjoint from the list of interface libraries in the "
  224. "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
  225. "dependent shared libraries to be found at link time CMake uses this "
  226. "list to add appropriate files or paths to the link command line. "
  227. "Ignored for non-imported targets.");
  228. cm->DefineProperty
  229. ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  230. "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
  231. "This property is used when loading settings for the <CONFIG> "
  232. "configuration of an imported target. "
  233. "Configuration names correspond to those provided by the project "
  234. "from which the target is imported. "
  235. "If set, this property completely overrides the generic property "
  236. "for the named configuration.");
  237. cm->DefineProperty
  238. ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  239. "Transitive link interface of an IMPORTED target.",
  240. "Lists libraries whose interface is included when an IMPORTED library "
  241. "target is linked to another target. "
  242. "The libraries will be included on the link line for the target. "
  243. "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
  244. "to all imported target types, including STATIC libraries. "
  245. "This property is ignored for non-imported targets.");
  246. cm->DefineProperty
  247. ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  248. "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
  249. "This property is used when loading settings for the <CONFIG> "
  250. "configuration of an imported target. "
  251. "Configuration names correspond to those provided by the project "
  252. "from which the target is imported. "
  253. "If set, this property completely overrides the generic property "
  254. "for the named configuration.");
  255. cm->DefineProperty
  256. ("IMPORTED_LOCATION", cmProperty::TARGET,
  257. "Full path to the main file on disk for an IMPORTED target.",
  258. "Specifies the location of an IMPORTED target file on disk. "
  259. "For executables this is the location of the executable file. "
  260. "For bundles on OS X this is the location of the executable file "
  261. "inside Contents/MacOS under the application bundle folder. "
  262. "For static libraries and modules this is the location of the "
  263. "library or module. "
  264. "For shared libraries on non-DLL platforms this is the location of "
  265. "the shared library. "
  266. "For frameworks on OS X this is the location of the library file "
  267. "symlink just inside the framework folder. "
  268. "For DLLs this is the location of the \".dll\" part of the library. "
  269. "For UNKNOWN libraries this is the location of the file to be linked. "
  270. "Ignored for non-imported targets.");
  271. cm->DefineProperty
  272. ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
  273. "Per-configuration version of IMPORTED_LOCATION property.",
  274. "This property is used when loading settings for the <CONFIG> "
  275. "configuration of an imported target. "
  276. "Configuration names correspond to those provided by the project "
  277. "from which the target is imported.");
  278. cm->DefineProperty
  279. ("IMPORTED_SONAME", cmProperty::TARGET,
  280. "The \"soname\" of an IMPORTED target of shared library type.",
  281. "Specifies the \"soname\" embedded in an imported shared library. "
  282. "This is meaningful only on platforms supporting the feature. "
  283. "Ignored for non-imported targets.");
  284. cm->DefineProperty
  285. ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
  286. "Per-configuration version of IMPORTED_SONAME property.",
  287. "This property is used when loading settings for the <CONFIG> "
  288. "configuration of an imported target. "
  289. "Configuration names correspond to those provided by the project "
  290. "from which the target is imported.");
  291. cm->DefineProperty
  292. ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
  293. "Exclude the target from the all target.",
  294. "A property on a target that indicates if the target is excluded "
  295. "from the default build target. If it is not, then with a Makefile "
  296. "for example typing make will cause this target to be built. "
  297. "The same concept applies to the default build of other generators. "
  298. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  299. "undefined behavior.");
  300. cm->DefineProperty
  301. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  302. "Mac OSX directory name for installed targets.",
  303. "INSTALL_NAME_DIR is a string specifying the "
  304. "directory portion of the \"install_name\" field of shared libraries "
  305. "on Mac OSX to use in the installed targets. ");
  306. cm->DefineProperty
  307. ("INSTALL_RPATH", cmProperty::TARGET,
  308. "The rpath to use for installed targets.",
  309. "A semicolon-separated list specifying the rpath "
  310. "to use in installed targets (for platforms that support it). "
  311. "This property is initialized by the value of the variable "
  312. "CMAKE_INSTALL_RPATH if it is set when a target is created.");
  313. cm->DefineProperty
  314. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  315. "Add paths to linker search and installed rpath.",
  316. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  317. "append directories in the linker search path and outside the "
  318. "project to the INSTALL_RPATH. "
  319. "This property is initialized by the value of the variable "
  320. "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
  321. "created.");
  322. cm->DefineProperty
  323. ("LABELS", cmProperty::TARGET,
  324. "Specify a list of text labels associated with a target.",
  325. "Target label semantics are currently unspecified.");
  326. cm->DefineProperty
  327. ("LINK_FLAGS", cmProperty::TARGET,
  328. "Additional flags to use when linking this target.",
  329. "The LINK_FLAGS property can be used to add extra flags to the "
  330. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  331. "configuration <CONFIG>, "
  332. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  333. cm->DefineProperty
  334. ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
  335. "Per-configuration linker flags for a target.",
  336. "This is the configuration-specific version of LINK_FLAGS.");
  337. cm->DefineProperty
  338. ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
  339. "End a link line such that static system libraries are used.",
  340. "Some linkers support switches such as -Bstatic and -Bdynamic "
  341. "to determine whether to use static or shared libraries for -lXXX "
  342. "options. CMake uses these options to set the link type for "
  343. "libraries whose full paths are not known or (in some cases) are in "
  344. "implicit link directories for the platform. By default the "
  345. "linker search type is left at -Bdynamic by the end of the library "
  346. "list. This property switches the final linker search type to "
  347. "-Bstatic.");
  348. cm->DefineProperty
  349. ("LINKER_LANGUAGE", cmProperty::TARGET,
  350. "What tool to use for linking, based on language.",
  351. "The LINKER_LANGUAGE property is used to change the tool "
  352. "used to link an executable or shared library. The default is "
  353. "set the language to match the files in the library. CXX and C "
  354. "are common values for this property.");
  355. cm->DefineProperty
  356. ("LOCATION", cmProperty::TARGET,
  357. "Read-only location of a target on disk.",
  358. "For an imported target, this read-only property returns the value of "
  359. "the LOCATION_<CONFIG> property for an unspecified configuration "
  360. "<CONFIG> provided by the target.\n"
  361. "For a non-imported target, this property is provided for compatibility "
  362. "with CMake 2.4 and below. "
  363. "It was meant to get the location of an executable target's output file "
  364. "for use in add_custom_command. "
  365. "The path may contain a build-system-specific portion that "
  366. "is replaced at build time with the configuration getting built "
  367. "(such as \"$(ConfigurationName)\" in VS). "
  368. "In CMake 2.6 and above add_custom_command automatically recognizes a "
  369. "target name in its COMMAND and DEPENDS options and computes the "
  370. "target location. "
  371. "Therefore this property is not needed for creating custom commands.");
  372. cm->DefineProperty
  373. ("LOCATION_<CONFIG>", cmProperty::TARGET,
  374. "Read-only property providing a target location on disk.",
  375. "A read-only property that indicates where a target's main file is "
  376. "located on disk for the configuration <CONFIG>. "
  377. "The property is defined only for library and executable targets. "
  378. "An imported target may provide a set of configurations different "
  379. "from that of the importing project. "
  380. "By default CMake looks for an exact-match but otherwise uses an "
  381. "arbitrary available configuration. "
  382. "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
  383. "configurations explicitly.");
  384. cm->DefineProperty
  385. ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  386. "List public interface libraries for a shared library or executable.",
  387. "By default linking to a shared library target transitively "
  388. "links to targets with which the library itself was linked. "
  389. "For an executable with exports (see the ENABLE_EXPORTS property) "
  390. "no default transitive link dependencies are used. "
  391. "This property replaces the default transitive link dependencies with "
  392. "an explict list. "
  393. "When the target is linked into another target the libraries "
  394. "listed (and recursively their link interface libraries) will be "
  395. "provided to the other target also. "
  396. "If the list is empty then no transitive link dependencies will be "
  397. "incorporated when this target is linked into another target even if "
  398. "the default set is non-empty. "
  399. "This property is ignored for STATIC libraries.");
  400. cm->DefineProperty
  401. ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  402. "Per-configuration list of public interface libraries for a target.",
  403. "This is the configuration-specific version of "
  404. "LINK_INTERFACE_LIBRARIES. "
  405. "If set, this property completely overrides the generic property "
  406. "for the named configuration.");
  407. cm->DefineProperty
  408. ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
  409. "Map from project configuration to IMPORTED target's configuration.",
  410. "List configurations of an imported target that may be used for "
  411. "the current project's <CONFIG> configuration. "
  412. "Targets imported from another project may not provide the same set "
  413. "of configuration names available in the current project. "
  414. "Setting this property tells CMake what imported configurations are "
  415. "suitable for use when building the <CONFIG> configuration. "
  416. "The first configuration in the list found to be provided by the "
  417. "imported target is selected. If no matching configurations are "
  418. "available the imported target is considered to be not found. "
  419. "This property is ignored for non-imported targets.",
  420. false /* TODO: make this chained */ );
  421. cm->DefineProperty
  422. ("OUTPUT_NAME", cmProperty::TARGET,
  423. "Sets the real name of a target when it is built.",
  424. "Sets the real name of a target when it is built and "
  425. "can be used to help create two targets of the same name even though "
  426. "CMake requires unique logical target names. There is also a "
  427. "<CONFIG>_OUTPUT_NAME that can set the output name on a "
  428. "per-configuration basis.");
  429. cm->DefineProperty
  430. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  431. "Deprecated install support.",
  432. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  433. "old way to specify CMake scripts to run before and after "
  434. "installing a target. They are used only when the old "
  435. "INSTALL_TARGETS command is used to install the target. Use the "
  436. "INSTALL command instead.");
  437. cm->DefineProperty
  438. ("PREFIX", cmProperty::TARGET,
  439. "What comes before the library name.",
  440. "A target property that can be set to override the prefix "
  441. "(such as \"lib\") on a library name.");
  442. cm->DefineProperty
  443. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  444. "Deprecated install support.",
  445. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  446. "old way to specify CMake scripts to run before and after "
  447. "installing a target. They are used only when the old "
  448. "INSTALL_TARGETS command is used to install the target. Use the "
  449. "INSTALL command instead.");
  450. cm->DefineProperty
  451. ("PRIVATE_HEADER", cmProperty::TARGET,
  452. "Specify private header files in a FRAMEWORK shared library target.",
  453. "Shared library targets marked with the FRAMEWORK property generate "
  454. "frameworks on OS X and normal shared libraries on other platforms. "
  455. "This property may be set to a list of header files to be placed "
  456. "in the PrivateHeaders directory inside the framework folder. "
  457. "On non-Apple platforms these headers may be installed using the "
  458. "PRIVATE_HEADER option to the install(TARGETS) command.");
  459. cm->DefineProperty
  460. ("PUBLIC_HEADER", cmProperty::TARGET,
  461. "Specify public header files in a FRAMEWORK shared library target.",
  462. "Shared library targets marked with the FRAMEWORK property generate "
  463. "frameworks on OS X and normal shared libraries on other platforms. "
  464. "This property may be set to a list of header files to be placed "
  465. "in the Headers directory inside the framework folder. "
  466. "On non-Apple platforms these headers may be installed using the "
  467. "PUBLIC_HEADER option to the install(TARGETS) command.");
  468. cm->DefineProperty
  469. ("RESOURCE", cmProperty::TARGET,
  470. "Specify resource files in a FRAMEWORK shared library target.",
  471. "Shared library targets marked with the FRAMEWORK property generate "
  472. "frameworks on OS X and normal shared libraries on other platforms. "
  473. "This property may be set to a list of files to be placed "
  474. "in the Resources directory inside the framework folder. "
  475. "On non-Apple platforms these files may be installed using the "
  476. "RESOURCE option to the install(TARGETS) command.");
  477. cm->DefineProperty
  478. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  479. "Specify a launcher for compile rules.",
  480. "See the global property of the same name for details. "
  481. "This overrides the global and directory property for a target.",
  482. true);
  483. cm->DefineProperty
  484. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  485. "Specify a launcher for link rules.",
  486. "See the global property of the same name for details. "
  487. "This overrides the global and directory property for a target.",
  488. true);
  489. cm->DefineProperty
  490. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  491. "Specify a launcher for custom rules.",
  492. "See the global property of the same name for details. "
  493. "This overrides the global and directory property for a target.",
  494. true);
  495. cm->DefineProperty
  496. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  497. "Should rpaths be used for the build tree.",
  498. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  499. "generation of an rpath allowing the target to run from the "
  500. "build tree. "
  501. "This property is initialized by the value of the variable "
  502. "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
  503. cm->DefineProperty
  504. ("SOVERSION", cmProperty::TARGET,
  505. "What version number is this target.",
  506. "For shared libraries VERSION and SOVERSION can be used to specify "
  507. "the build version and api version respectively. When building or "
  508. "installing appropriate symlinks are created if the platform "
  509. "supports symlinks and the linker supports so-names. "
  510. "If only one of both is specified the missing is assumed to have "
  511. "the same version number. "
  512. "For shared libraries and executables on Windows the VERSION "
  513. "attribute is parsed to extract a \"major.minor\" version number. "
  514. "These numbers are used as the image version of the binary. ");
  515. cm->DefineProperty
  516. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  517. "Extra flags to use when linking static libraries.",
  518. "Extra flags to use when linking a static library.");
  519. cm->DefineProperty
  520. ("SUFFIX", cmProperty::TARGET,
  521. "What comes after the library name.",
  522. "A target property that can be set to override the suffix "
  523. "(such as \".so\") on a library name.");
  524. cm->DefineProperty
  525. ("TYPE", cmProperty::TARGET,
  526. "The type of the target.",
  527. "This read-only property can be used to test the type of the given "
  528. "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
  529. "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
  530. cm->DefineProperty
  531. ("VERSION", cmProperty::TARGET,
  532. "What version number is this target.",
  533. "For shared libraries VERSION and SOVERSION can be used to specify "
  534. "the build version and api version respectively. When building or "
  535. "installing appropriate symlinks are created if the platform "
  536. "supports symlinks and the linker supports so-names. "
  537. "If only one of both is specified the missing is assumed to have "
  538. "the same version number. "
  539. "For executables VERSION can be used to specify the build version. "
  540. "When building or installing appropriate symlinks are created if "
  541. "the platform supports symlinks. "
  542. "For shared libraries and executables on Windows the VERSION "
  543. "attribute is parsed to extract a \"major.minor\" version number. "
  544. "These numbers are used as the image version of the binary. ");
  545. cm->DefineProperty
  546. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  547. "Build an executable with a WinMain entry point on windows.",
  548. "When this property is set to true the executable when linked "
  549. "on Windows will be created with a WinMain() entry point instead "
  550. "of of just main()."
  551. "This makes it a GUI executable instead of a console application. "
  552. "See the CMAKE_MFC_FLAG variable documentation to configure use "
  553. "of MFC for WinMain executables.");
  554. cm->DefineProperty
  555. ("MACOSX_BUNDLE", cmProperty::TARGET,
  556. "Build an executable as an application bundle on Mac OS X.",
  557. "When this property is set to true the executable when built "
  558. "on Mac OS X will be created as an application bundle. "
  559. "This makes it a GUI executable that can be launched from "
  560. "the Finder. "
  561. "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
  562. "about creation of the Info.plist file for the application bundle.");
  563. cm->DefineProperty
  564. ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
  565. "Specify a custom Info.plist template for a Mac OS X App Bundle.",
  566. "An executable target with MACOSX_BUNDLE enabled will be built as an "
  567. "application bundle on Mac OS X. "
  568. "By default its Info.plist file is created by configuring a template "
  569. "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
  570. "This property specifies an alternative template file name which "
  571. "may be a full path.\n"
  572. "The following target properties may be set to specify content to "
  573. "be configured into the file:\n"
  574. " MACOSX_BUNDLE_INFO_STRING\n"
  575. " MACOSX_BUNDLE_ICON_FILE\n"
  576. " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
  577. " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
  578. " MACOSX_BUNDLE_BUNDLE_NAME\n"
  579. " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
  580. " MACOSX_BUNDLE_BUNDLE_VERSION\n"
  581. " MACOSX_BUNDLE_COPYRIGHT\n"
  582. "CMake variables of the same name may be set to affect all targets "
  583. "in a directory that do not have each specific property set. "
  584. "If a custom Info.plist is specified by this property it may of course "
  585. "hard-code all the settings instead of using the target properties.");
  586. cm->DefineProperty
  587. ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
  588. "Specify a custom Info.plist template for a Mac OS X Framework.",
  589. "An library target with FRAMEWORK enabled will be built as a "
  590. "framework on Mac OS X. "
  591. "By default its Info.plist file is created by configuring a template "
  592. "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
  593. "This property specifies an alternative template file name which "
  594. "may be a full path.\n"
  595. "The following target properties may be set to specify content to "
  596. "be configured into the file:\n"
  597. " MACOSX_FRAMEWORK_ICON_FILE\n"
  598. " MACOSX_FRAMEWORK_IDENTIFIER\n"
  599. " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
  600. " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
  601. "CMake variables of the same name may be set to affect all targets "
  602. "in a directory that do not have each specific property set. "
  603. "If a custom Info.plist is specified by this property it may of course "
  604. "hard-code all the settings instead of using the target properties.");
  605. cm->DefineProperty
  606. ("ENABLE_EXPORTS", cmProperty::TARGET,
  607. "Specify whether an executable exports symbols for loadable modules.",
  608. "Normally an executable does not export any symbols because it is "
  609. "the final program. It is possible for an executable to export "
  610. "symbols to be used by loadable modules. When this property is "
  611. "set to true CMake will allow other targets to \"link\" to the "
  612. "executable with the TARGET_LINK_LIBRARIES command. "
  613. "On all platforms a target-level dependency on the executable is "
  614. "created for targets that link to it. "
  615. "For non-DLL platforms the link rule is simply ignored since "
  616. "the dynamic loader will automatically bind symbols when the "
  617. "module is loaded. "
  618. "For DLL platforms an import library will be created for the "
  619. "exported symbols and then used for linking. "
  620. "All Windows-based systems including Cygwin are DLL platforms.");
  621. cm->DefineProperty
  622. ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
  623. "Specify output directory for Fortran modules provided by the target.",
  624. "If the target contains Fortran source files that provide modules "
  625. "and the compiler supports a module output directory this specifies "
  626. "the directory in which the modules will be placed. "
  627. "When this property is not set the modules will be placed in the "
  628. "build directory corresponding to the target's source directory. "
  629. "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
  630. "is created its value is used to initialize this property.");
  631. cm->DefineProperty
  632. ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
  633. "Set Xcode target attributes directly.",
  634. "Tell the Xcode generator to set '<an-attribute>' to a given value "
  635. "in the generated Xcode project. Ignored on other generators.");
  636. cm->DefineProperty
  637. ("GENERATOR_FILE_NAME", cmProperty::TARGET,
  638. "Generator's file for this target.",
  639. "An internal property used by some generators to record the name of "
  640. "project or dsp file associated with this target.");
  641. cm->DefineProperty
  642. ("SOURCES", cmProperty::TARGET,
  643. "Source names specified for a target.",
  644. "Read-only list of sources specified for a target. "
  645. "The names returned are suitable for passing to the "
  646. "set_source_files_properties command.");
  647. cm->DefineProperty
  648. ("PROJECT_LABEL", cmProperty::TARGET,
  649. "Change the name of a target in an IDE.",
  650. "Can be used to change the name of the target in an IDE "
  651. "like visual stuido. ");
  652. cm->DefineProperty
  653. ("VS_KEYWORD", cmProperty::TARGET,
  654. "Visual Studio project keyword.",
  655. "Can be set to change the visual studio keyword, for example "
  656. "QT integration works better if this is set to Qt4VSv1.0. ");
  657. cm->DefineProperty
  658. ("VS_SCC_PROVIDER", cmProperty::TARGET,
  659. "Visual Studio Source Code Control Provider.",
  660. "Can be set to change the visual studio source code control "
  661. "provider property.");
  662. cm->DefineProperty
  663. ("VS_SCC_LOCALPATH", cmProperty::TARGET,
  664. "Visual Studio Source Code Control Provider.",
  665. "Can be set to change the visual studio source code control "
  666. "local path property.");
  667. cm->DefineProperty
  668. ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
  669. "Visual Studio Source Code Control Project.",
  670. "Can be set to change the visual studio source code control "
  671. "project name property.");
  672. #if 0
  673. cm->DefineProperty
  674. ("OBJECT_FILES", cmProperty::TARGET,
  675. "Used to get the resulting list of object files that make up a "
  676. "target.",
  677. "This can be used to put object files from one library "
  678. "into another library. It is a read only property. It "
  679. "converts the source list for the target into a list of full "
  680. "paths to object names that will be produced by the target.");
  681. #endif
  682. #define CM_TARGET_FILE_TYPES_DOC \
  683. "There are three kinds of target files that may be built: " \
  684. "archive, library, and runtime. " \
  685. "Executables are always treated as runtime targets. " \
  686. "Static libraries are always treated as archive targets. " \
  687. "Module libraries are always treated as library targets. " \
  688. "For non-DLL platforms shared libraries are treated as library " \
  689. "targets. " \
  690. "For DLL platforms the DLL part of a shared library is treated as " \
  691. "a runtime target and the corresponding import library is treated as " \
  692. "an archive target. " \
  693. "All Windows-based systems including Cygwin are DLL platforms."
  694. cm->DefineProperty
  695. ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
  696. "Output directory in which to build ARCHIVE target files.",
  697. "This property specifies the directory into which archive target files "
  698. "should be built. "
  699. CM_TARGET_FILE_TYPES_DOC " "
  700. "This property is initialized by the value of the variable "
  701. "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
  702. cm->DefineProperty
  703. ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
  704. "Output directory in which to build LIBRARY target files.",
  705. "This property specifies the directory into which library target files "
  706. "should be built. "
  707. CM_TARGET_FILE_TYPES_DOC " "
  708. "This property is initialized by the value of the variable "
  709. "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
  710. cm->DefineProperty
  711. ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
  712. "Output directory in which to build RUNTIME target files.",
  713. "This property specifies the directory into which runtime target files "
  714. "should be built. "
  715. CM_TARGET_FILE_TYPES_DOC " "
  716. "This property is initialized by the value of the variable "
  717. "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
  718. // define some properties without documentation
  719. cm->DefineProperty("DEBUG_OUTPUT_NAME", cmProperty::TARGET,0,0);
  720. cm->DefineProperty("RELEASE_OUTPUT_NAME", cmProperty::TARGET,0,0);
  721. }
  722. void cmTarget::SetType(TargetType type, const char* name)
  723. {
  724. this->Name = name;
  725. if(type == cmTarget::INSTALL_FILES ||
  726. type == cmTarget::INSTALL_PROGRAMS ||
  727. type == cmTarget::INSTALL_DIRECTORY)
  728. {
  729. this->Makefile->
  730. IssueMessage(cmake::INTERNAL_ERROR,
  731. "SetType called on cmTarget for INSTALL_FILES, "
  732. "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
  733. return;
  734. }
  735. // only add dependency information for library targets
  736. this->TargetTypeValue = type;
  737. if(this->TargetTypeValue >= STATIC_LIBRARY
  738. && this->TargetTypeValue <= MODULE_LIBRARY)
  739. {
  740. this->RecordDependencies = true;
  741. }
  742. else
  743. {
  744. this->RecordDependencies = false;
  745. }
  746. }
  747. //----------------------------------------------------------------------------
  748. void cmTarget::SetMakefile(cmMakefile* mf)
  749. {
  750. // Set our makefile.
  751. this->Makefile = mf;
  752. // set the cmake instance of the properties
  753. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  754. // Check whether this is a DLL platform.
  755. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  756. this->Makefile->IsOn("CYGWIN") ||
  757. this->Makefile->IsOn("MINGW"));
  758. // Setup default property values.
  759. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  760. this->SetPropertyDefault("INSTALL_RPATH", "");
  761. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  762. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  763. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  764. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  765. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  766. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  767. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  768. // Collect the set of configuration types.
  769. std::vector<std::string> configNames;
  770. if(const char* configurationTypes =
  771. mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  772. {
  773. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  774. }
  775. else if(const char* buildType = mf->GetDefinition("CMAKE_BUILD_TYPE"))
  776. {
  777. if(*buildType)
  778. {
  779. configNames.push_back(buildType);
  780. }
  781. }
  782. // Setup per-configuration property default values.
  783. for(std::vector<std::string>::iterator ci = configNames.begin();
  784. ci != configNames.end(); ++ci)
  785. {
  786. // Initialize per-configuration name postfix property from the
  787. // variable only for non-executable targets. This preserves
  788. // compatibility with previous CMake versions in which executables
  789. // did not support this variable. Projects may still specify the
  790. // property directly. TODO: Make this depend on backwards
  791. // compatibility setting.
  792. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  793. {
  794. std::string property = cmSystemTools::UpperCase(*ci);
  795. property += "_POSTFIX";
  796. this->SetPropertyDefault(property.c_str(), 0);
  797. }
  798. }
  799. // Save the backtrace of target construction.
  800. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  801. // Record current policies for later use.
  802. this->PolicyStatusCMP0003 =
  803. this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
  804. this->PolicyStatusCMP0004 =
  805. this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
  806. this->PolicyStatusCMP0008 =
  807. this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
  808. }
  809. //----------------------------------------------------------------------------
  810. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  811. {
  812. return this->Internal->Backtrace;
  813. }
  814. //----------------------------------------------------------------------------
  815. std::string cmTarget::GetSupportDirectory() const
  816. {
  817. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  818. dir += cmake::GetCMakeFilesDirectory();
  819. dir += "/";
  820. dir += this->Name;
  821. dir += ".dir";
  822. return dir;
  823. }
  824. //----------------------------------------------------------------------------
  825. bool cmTarget::IsExecutableWithExports()
  826. {
  827. return (this->GetType() == cmTarget::EXECUTABLE &&
  828. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  829. }
  830. //----------------------------------------------------------------------------
  831. bool cmTarget::IsLinkable()
  832. {
  833. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  834. this->GetType() == cmTarget::SHARED_LIBRARY ||
  835. this->GetType() == cmTarget::MODULE_LIBRARY ||
  836. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  837. this->IsExecutableWithExports());
  838. }
  839. //----------------------------------------------------------------------------
  840. bool cmTarget::IsFrameworkOnApple()
  841. {
  842. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  843. this->Makefile->IsOn("APPLE") &&
  844. this->GetPropertyAsBool("FRAMEWORK"));
  845. }
  846. //----------------------------------------------------------------------------
  847. bool cmTarget::IsAppBundleOnApple()
  848. {
  849. return (this->GetType() == cmTarget::EXECUTABLE &&
  850. this->Makefile->IsOn("APPLE") &&
  851. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  852. }
  853. //----------------------------------------------------------------------------
  854. class cmTargetTraceDependencies
  855. {
  856. public:
  857. cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile);
  858. void Trace();
  859. private:
  860. cmTarget* Target;
  861. cmMakefile* Makefile;
  862. cmGlobalGenerator* GlobalGenerator;
  863. std::queue<cmStdString> DependencyQueue;
  864. std::set<cmStdString> DependenciesQueued;
  865. std::set<cmSourceFile*> TargetSources;
  866. void QueueOnce(std::string const& name);
  867. void QueueOnce(std::vector<std::string> const& names);
  868. void QueueDependencies(cmSourceFile* sf);
  869. bool IsUtility(std::string const& dep);
  870. void CheckCustomCommand(cmCustomCommand const& cc);
  871. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  872. };
  873. //----------------------------------------------------------------------------
  874. cmTargetTraceDependencies
  875. ::cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile):
  876. Target(target)
  877. {
  878. // Convenience.
  879. this->Makefile = this->Target->GetMakefile();
  880. this->GlobalGenerator =
  881. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  882. // Queue all the source files already specified for the target.
  883. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  884. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  885. si != sources.end(); ++si)
  886. {
  887. // Queue the source file itself in case it is generated.
  888. this->QueueOnce((*si)->GetFullPath());
  889. // Queue the dependencies of the source file in case they are
  890. // generated.
  891. this->QueueDependencies(*si);
  892. // Track the sources already known to the target.
  893. this->TargetSources.insert(*si);
  894. }
  895. // Queue the VS project file to check dependencies on the rule to
  896. // generate it.
  897. if(vsProjectFile)
  898. {
  899. this->QueueOnce(vsProjectFile);
  900. }
  901. // Queue pre-build, pre-link, and post-build rule dependencies.
  902. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  903. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  904. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  905. }
  906. //----------------------------------------------------------------------------
  907. void cmTargetTraceDependencies::Trace()
  908. {
  909. // Process one dependency at a time until the queue is empty.
  910. while(!this->DependencyQueue.empty())
  911. {
  912. // Get the next dependency in from queue.
  913. std::string dep = this->DependencyQueue.front();
  914. this->DependencyQueue.pop();
  915. // Check if we know how to generate this dependency.
  916. if(cmSourceFile* sf =
  917. this->Makefile->GetSourceFileWithOutput(dep.c_str()))
  918. {
  919. // Queue dependencies needed to generate this file.
  920. this->QueueDependencies(sf);
  921. // Make sure this file is in the target.
  922. if(this->TargetSources.insert(sf).second)
  923. {
  924. this->Target->AddSourceFile(sf);
  925. }
  926. }
  927. }
  928. }
  929. //----------------------------------------------------------------------------
  930. void cmTargetTraceDependencies::QueueOnce(std::string const& name)
  931. {
  932. if(this->DependenciesQueued.insert(name).second)
  933. {
  934. this->DependencyQueue.push(name);
  935. }
  936. }
  937. //----------------------------------------------------------------------------
  938. void
  939. cmTargetTraceDependencies::QueueOnce(std::vector<std::string> const& names)
  940. {
  941. for(std::vector<std::string>::const_iterator i = names.begin();
  942. i != names.end(); ++i)
  943. {
  944. this->QueueOnce(*i);
  945. }
  946. }
  947. //----------------------------------------------------------------------------
  948. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  949. {
  950. // Dependencies on targets (utilities) are supposed to be named by
  951. // just the target name. However for compatibility we support
  952. // naming the output file generated by the target (assuming there is
  953. // no output-name property which old code would not have set). In
  954. // that case the target name will be the file basename of the
  955. // dependency.
  956. std::string util = cmSystemTools::GetFilenameName(dep);
  957. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  958. {
  959. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  960. }
  961. // Check for a non-imported target with this name.
  962. if(cmTarget* t = this->GlobalGenerator->FindTarget(0, util.c_str()))
  963. {
  964. // If we find the target and the dep was given as a full path,
  965. // then make sure it was not a full path to something else, and
  966. // the fact that the name matched a target was just a coincidence.
  967. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  968. {
  969. // This is really only for compatibility so we do not need to
  970. // worry about configuration names and output names.
  971. std::string tLocation = t->GetLocation(0);
  972. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  973. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  974. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  975. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  976. if(depLocation == tLocation)
  977. {
  978. this->Target->AddUtility(util.c_str());
  979. return true;
  980. }
  981. }
  982. else
  983. {
  984. // The original name of the dependency was not a full path. It
  985. // must name a target, so add the target-level dependency.
  986. this->Target->AddUtility(util.c_str());
  987. return true;
  988. }
  989. }
  990. // The dependency does not name a target built in this project.
  991. return false;
  992. }
  993. //----------------------------------------------------------------------------
  994. void cmTargetTraceDependencies::QueueDependencies(cmSourceFile* sf)
  995. {
  996. // Queue dependency added explicitly by the user.
  997. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  998. {
  999. std::vector<std::string> objDeps;
  1000. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1001. this->QueueOnce(objDeps);
  1002. }
  1003. // Queue dependencies added programatically by commands.
  1004. this->QueueOnce(sf->GetDepends());
  1005. // Queue custom command dependencies.
  1006. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1007. {
  1008. this->CheckCustomCommand(*cc);
  1009. }
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. void
  1013. cmTargetTraceDependencies
  1014. ::CheckCustomCommand(cmCustomCommand const& cc)
  1015. {
  1016. // Transform command names that reference targets built in this
  1017. // project to corresponding target-level dependencies.
  1018. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1019. cit != cc.GetCommandLines().end(); ++cit)
  1020. {
  1021. std::string const& command = *cit->begin();
  1022. // Look for a non-imported target with this name.
  1023. if(cmTarget* t = this->GlobalGenerator->FindTarget(0, command.c_str()))
  1024. {
  1025. if(t->GetType() == cmTarget::EXECUTABLE)
  1026. {
  1027. // The command refers to an executable target built in
  1028. // this project. Add the target-level dependency to make
  1029. // sure the executable is up to date before this custom
  1030. // command possibly runs.
  1031. this->Target->AddUtility(command.c_str());
  1032. }
  1033. }
  1034. }
  1035. // Queue the custom command dependencies.
  1036. std::vector<std::string> const& depends = cc.GetDepends();
  1037. for(std::vector<std::string>::const_iterator di = depends.begin();
  1038. di != depends.end(); ++di)
  1039. {
  1040. std::string const& dep = *di;
  1041. if(!this->IsUtility(dep))
  1042. {
  1043. // The dependency does not name a target and may be a file we
  1044. // know how to generate. Queue it.
  1045. this->QueueOnce(dep);
  1046. }
  1047. }
  1048. }
  1049. //----------------------------------------------------------------------------
  1050. void
  1051. cmTargetTraceDependencies
  1052. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1053. {
  1054. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1055. cli != commands.end(); ++cli)
  1056. {
  1057. this->CheckCustomCommand(*cli);
  1058. }
  1059. }
  1060. //----------------------------------------------------------------------------
  1061. void cmTarget::TraceDependencies(const char* vsProjectFile)
  1062. {
  1063. // Use a helper object to trace the dependencies.
  1064. cmTargetTraceDependencies tracer(this, vsProjectFile);
  1065. tracer.Trace();
  1066. }
  1067. //----------------------------------------------------------------------------
  1068. bool cmTarget::FindSourceFiles()
  1069. {
  1070. for(std::vector<cmSourceFile*>::const_iterator
  1071. si = this->SourceFiles.begin();
  1072. si != this->SourceFiles.end(); ++si)
  1073. {
  1074. if((*si)->GetFullPath().empty())
  1075. {
  1076. return false;
  1077. }
  1078. }
  1079. return true;
  1080. }
  1081. //----------------------------------------------------------------------------
  1082. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1083. {
  1084. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1085. i != srcs.end(); ++i)
  1086. {
  1087. this->AddSource(i->c_str());
  1088. }
  1089. }
  1090. //----------------------------------------------------------------------------
  1091. cmSourceFile* cmTarget::AddSource(const char* s)
  1092. {
  1093. std::string src = s;
  1094. // For backwards compatibility replace varibles in source names.
  1095. // This should eventually be removed.
  1096. this->Makefile->ExpandVariablesInString(src);
  1097. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  1098. this->AddSourceFile(sf);
  1099. return sf;
  1100. }
  1101. //----------------------------------------------------------------------------
  1102. struct cmTarget::SourceFileFlags
  1103. cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
  1104. {
  1105. struct SourceFileFlags flags;
  1106. this->ConstructSourceFileFlags();
  1107. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1108. this->Internal->SourceFlagsMap.find(sf);
  1109. if(si != this->Internal->SourceFlagsMap.end())
  1110. {
  1111. flags = si->second;
  1112. }
  1113. return flags;
  1114. }
  1115. //----------------------------------------------------------------------------
  1116. void cmTarget::ConstructSourceFileFlags()
  1117. {
  1118. if(this->Internal->SourceFileFlagsConstructed)
  1119. {
  1120. return;
  1121. }
  1122. this->Internal->SourceFileFlagsConstructed = true;
  1123. // Process public headers to mark the source files.
  1124. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  1125. {
  1126. std::vector<std::string> relFiles;
  1127. cmSystemTools::ExpandListArgument(files, relFiles);
  1128. for(std::vector<std::string>::iterator it = relFiles.begin();
  1129. it != relFiles.end(); ++it)
  1130. {
  1131. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1132. {
  1133. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1134. flags.MacFolder = "Headers";
  1135. flags.Type = cmTarget::SourceFileTypePublicHeader;
  1136. }
  1137. }
  1138. }
  1139. // Process private headers after public headers so that they take
  1140. // precedence if a file is listed in both.
  1141. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  1142. {
  1143. std::vector<std::string> relFiles;
  1144. cmSystemTools::ExpandListArgument(files, relFiles);
  1145. for(std::vector<std::string>::iterator it = relFiles.begin();
  1146. it != relFiles.end(); ++it)
  1147. {
  1148. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1149. {
  1150. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1151. flags.MacFolder = "PrivateHeaders";
  1152. flags.Type = cmTarget::SourceFileTypePrivateHeader;
  1153. }
  1154. }
  1155. }
  1156. // Mark sources listed as resources.
  1157. if(const char* files = this->GetProperty("RESOURCE"))
  1158. {
  1159. std::vector<std::string> relFiles;
  1160. cmSystemTools::ExpandListArgument(files, relFiles);
  1161. for(std::vector<std::string>::iterator it = relFiles.begin();
  1162. it != relFiles.end(); ++it)
  1163. {
  1164. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1165. {
  1166. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1167. flags.MacFolder = "Resources";
  1168. flags.Type = cmTarget::SourceFileTypeResource;
  1169. }
  1170. }
  1171. }
  1172. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1173. // were not listed in one of the other lists.
  1174. std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
  1175. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1176. si != sources.end(); ++si)
  1177. {
  1178. cmSourceFile* sf = *si;
  1179. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1180. {
  1181. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1182. if(flags.Type == cmTarget::SourceFileTypeNormal)
  1183. {
  1184. flags.MacFolder = location;
  1185. if(strcmp(location, "Resources") == 0)
  1186. {
  1187. flags.Type = cmTarget::SourceFileTypeResource;
  1188. }
  1189. else
  1190. {
  1191. flags.Type = cmTarget::SourceFileTypeMacContent;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. }
  1197. //----------------------------------------------------------------------------
  1198. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  1199. const char *selfname,
  1200. const LinkLibraryVectorType& libs )
  1201. {
  1202. // Only add on libraries we haven't added on before.
  1203. // Assumption: the global link libraries could only grow, never shrink
  1204. LinkLibraryVectorType::const_iterator i = libs.begin();
  1205. i += this->PrevLinkedLibraries.size();
  1206. for( ; i != libs.end(); ++i )
  1207. {
  1208. // We call this so that the dependencies get written to the cache
  1209. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  1210. }
  1211. this->PrevLinkedLibraries = libs;
  1212. }
  1213. //----------------------------------------------------------------------------
  1214. void cmTarget::AddLinkDirectory(const char* d)
  1215. {
  1216. // Make sure we don't add unnecessary search directories.
  1217. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1218. {
  1219. this->LinkDirectories.push_back(d);
  1220. }
  1221. }
  1222. //----------------------------------------------------------------------------
  1223. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  1224. {
  1225. return this->LinkDirectories;
  1226. }
  1227. //----------------------------------------------------------------------------
  1228. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
  1229. {
  1230. // No configuration is always optimized.
  1231. if(!(config && *config))
  1232. {
  1233. return cmTarget::OPTIMIZED;
  1234. }
  1235. // Get the list of configurations considered to be DEBUG.
  1236. std::vector<std::string> const& debugConfigs =
  1237. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1238. // Check if any entry in the list matches this configuration.
  1239. std::string configUpper = cmSystemTools::UpperCase(config);
  1240. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  1241. i != debugConfigs.end(); ++i)
  1242. {
  1243. if(*i == configUpper)
  1244. {
  1245. return cmTarget::DEBUG;
  1246. }
  1247. }
  1248. // The current configuration is not a debug configuration.
  1249. return cmTarget::OPTIMIZED;
  1250. }
  1251. //----------------------------------------------------------------------------
  1252. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1253. const char* target )
  1254. {
  1255. // Clear the dependencies. The cache variable must exist iff we are
  1256. // recording dependency information for this target.
  1257. std::string depname = target;
  1258. depname += "_LIB_DEPENDS";
  1259. if (this->RecordDependencies)
  1260. {
  1261. mf.AddCacheDefinition(depname.c_str(), "",
  1262. "Dependencies for target", cmCacheManager::STATIC);
  1263. }
  1264. else
  1265. {
  1266. if (mf.GetDefinition( depname.c_str() ))
  1267. {
  1268. std::string message = "Target ";
  1269. message += target;
  1270. message += " has dependency information when it shouldn't.\n";
  1271. message += "Your cache is probably stale. Please remove the entry\n ";
  1272. message += depname;
  1273. message += "\nfrom the cache.";
  1274. cmSystemTools::Error( message.c_str() );
  1275. }
  1276. }
  1277. }
  1278. //----------------------------------------------------------------------------
  1279. void cmTarget::AddLinkLibrary(const std::string& lib,
  1280. LinkLibraryType llt)
  1281. {
  1282. this->AddFramework(lib.c_str(), llt);
  1283. cmTarget::LibraryID tmp;
  1284. tmp.first = lib;
  1285. tmp.second = llt;
  1286. this->LinkLibraries.push_back(tmp);
  1287. this->OriginalLinkLibraries.push_back(tmp);
  1288. }
  1289. //----------------------------------------------------------------------------
  1290. bool cmTarget::NameResolvesToFramework(const std::string& libname)
  1291. {
  1292. return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
  1293. NameResolvesToFramework(libname);
  1294. }
  1295. //----------------------------------------------------------------------------
  1296. bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
  1297. {
  1298. (void)llt; // TODO: What is this?
  1299. if(this->NameResolvesToFramework(libname.c_str()))
  1300. {
  1301. std::string frameworkDir = libname;
  1302. frameworkDir += "/../";
  1303. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1304. std::vector<std::string>::iterator i =
  1305. std::find(this->Frameworks.begin(),
  1306. this->Frameworks.end(), frameworkDir);
  1307. if(i == this->Frameworks.end())
  1308. {
  1309. this->Frameworks.push_back(frameworkDir);
  1310. }
  1311. return true;
  1312. }
  1313. return false;
  1314. }
  1315. //----------------------------------------------------------------------------
  1316. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1317. const char *target, const char* lib,
  1318. LinkLibraryType llt)
  1319. {
  1320. // Never add a self dependency, even if the user asks for it.
  1321. if(strcmp( target, lib ) == 0)
  1322. {
  1323. return;
  1324. }
  1325. this->AddFramework(lib, llt);
  1326. cmTarget::LibraryID tmp;
  1327. tmp.first = lib;
  1328. tmp.second = llt;
  1329. this->LinkLibraries.push_back( tmp );
  1330. this->OriginalLinkLibraries.push_back(tmp);
  1331. // Add the explicit dependency information for this target. This is
  1332. // simply a set of libraries separated by ";". There should always
  1333. // be a trailing ";". These library names are not canonical, in that
  1334. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1335. // We shouldn't remove duplicates here because external libraries
  1336. // may be purposefully duplicated to handle recursive dependencies,
  1337. // and we removing one instance will break the link line. Duplicates
  1338. // will be appropriately eliminated at emit time.
  1339. if(this->RecordDependencies)
  1340. {
  1341. std::string targetEntry = target;
  1342. targetEntry += "_LIB_DEPENDS";
  1343. std::string dependencies;
  1344. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  1345. if( old_val )
  1346. {
  1347. dependencies += old_val;
  1348. }
  1349. switch (llt)
  1350. {
  1351. case cmTarget::GENERAL:
  1352. dependencies += "general";
  1353. break;
  1354. case cmTarget::DEBUG:
  1355. dependencies += "debug";
  1356. break;
  1357. case cmTarget::OPTIMIZED:
  1358. dependencies += "optimized";
  1359. break;
  1360. }
  1361. dependencies += ";";
  1362. dependencies += lib;
  1363. dependencies += ";";
  1364. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  1365. "Dependencies for the target",
  1366. cmCacheManager::STATIC );
  1367. }
  1368. }
  1369. //----------------------------------------------------------------------------
  1370. void
  1371. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  1372. {
  1373. // There are two key parts of the dependency analysis: (1)
  1374. // determining the libraries in the link line, and (2) constructing
  1375. // the dependency graph for those libraries.
  1376. //
  1377. // The latter is done using the cache entries that record the
  1378. // dependencies of each library.
  1379. //
  1380. // The former is a more thorny issue, since it is not clear how to
  1381. // determine if two libraries listed on the link line refer to the a
  1382. // single library or not. For example, consider the link "libraries"
  1383. // /usr/lib/libtiff.so -ltiff
  1384. // Is this one library or two? The solution implemented here is the
  1385. // simplest (and probably the only practical) one: two libraries are
  1386. // the same if their "link strings" are identical. Thus, the two
  1387. // libraries above are considered distinct. This also means that for
  1388. // dependency analysis to be effective, the CMake user must specify
  1389. // libraries build by his project without using any linker flags or
  1390. // file extensions. That is,
  1391. // LINK_LIBRARIES( One Two )
  1392. // instead of
  1393. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1394. // The former is probably what most users would do, but it never
  1395. // hurts to document the assumptions. :-) Therefore, in the analysis
  1396. // code, the "canonical name" of a library is simply its name as
  1397. // given to a LINK_LIBRARIES command.
  1398. //
  1399. // Also, we will leave the original link line intact; we will just add any
  1400. // dependencies that were missing.
  1401. //
  1402. // There is a problem with recursive external libraries
  1403. // (i.e. libraries with no dependency information that are
  1404. // recursively dependent). We must make sure that the we emit one of
  1405. // the libraries twice to satisfy the recursion, but we shouldn't
  1406. // emit it more times than necessary. In particular, we must make
  1407. // sure that handling this improbable case doesn't cost us when
  1408. // dealing with the common case of non-recursive libraries. The
  1409. // solution is to assume that the recursion is satisfied at one node
  1410. // of the dependency tree. To illustrate, assume libA and libB are
  1411. // extrenal and mutually dependent. Suppose libX depends on
  1412. // libA, and libY on libA and libX. Then
  1413. // TARGET_LINK_LIBRARIES( Y X A B A )
  1414. // TARGET_LINK_LIBRARIES( X A B A )
  1415. // TARGET_LINK_LIBRARIES( Exec Y )
  1416. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1417. // specify the dependencies, since the mutual dependency of A and B
  1418. // is resolved *every time libA is specified*.
  1419. //
  1420. // Something like
  1421. // TARGET_LINK_LIBRARIES( Y X A B A )
  1422. // TARGET_LINK_LIBRARIES( X A B )
  1423. // TARGET_LINK_LIBRARIES( Exec Y )
  1424. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1425. // information is lost. This is because in some case (Y), the mutual
  1426. // dependency of A and B is listed, while in another other case (X),
  1427. // it is not. Depending on which line actually emits A, the mutual
  1428. // dependency may or may not be on the final link line. We can't
  1429. // handle this pathalogical case cleanly without emitting extra
  1430. // libraries for the normal cases. Besides, the dependency
  1431. // information for X is wrong anyway: if we build an executable
  1432. // depending on X alone, we would not have the mutual dependency on
  1433. // A and B resolved.
  1434. //
  1435. // IMPROVEMENTS:
  1436. // -- The current algorithm will not always pick the "optimal" link line
  1437. // when recursive dependencies are present. It will instead break the
  1438. // cycles at an aribtrary point. The majority of projects won't have
  1439. // cyclic dependencies, so this is probably not a big deal. Note that
  1440. // the link line is always correct, just not necessary optimal.
  1441. {
  1442. // Expand variables in link library names. This is for backwards
  1443. // compatibility with very early CMake versions and should
  1444. // eventually be removed. This code was moved here from the end of
  1445. // old source list processing code which was called just before this
  1446. // method.
  1447. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  1448. p != this->LinkLibraries.end(); ++p)
  1449. {
  1450. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1451. }
  1452. }
  1453. typedef std::vector< std::string > LinkLine;
  1454. // The dependency map.
  1455. DependencyMap dep_map;
  1456. // 1. Build the dependency graph
  1457. //
  1458. for(LinkLibraryVectorType::reverse_iterator lib
  1459. = this->LinkLibraries.rbegin();
  1460. lib != this->LinkLibraries.rend(); ++lib)
  1461. {
  1462. this->GatherDependencies( mf, *lib, dep_map);
  1463. }
  1464. // 2. Remove any dependencies that are already satisfied in the original
  1465. // link line.
  1466. //
  1467. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  1468. lib != this->LinkLibraries.end(); ++lib)
  1469. {
  1470. for( LinkLibraryVectorType::iterator lib2 = lib;
  1471. lib2 != this->LinkLibraries.end(); ++lib2)
  1472. {
  1473. this->DeleteDependency( dep_map, *lib, *lib2);
  1474. }
  1475. }
  1476. // 3. Create the new link line by simply emitting any dependencies that are
  1477. // missing. Start from the back and keep adding.
  1478. //
  1479. std::set<DependencyMap::key_type> done, visited;
  1480. std::vector<DependencyMap::key_type> newLinkLibraries;
  1481. for(LinkLibraryVectorType::reverse_iterator lib =
  1482. this->LinkLibraries.rbegin();
  1483. lib != this->LinkLibraries.rend(); ++lib)
  1484. {
  1485. // skip zero size library entries, this may happen
  1486. // if a variable expands to nothing.
  1487. if (lib->first.size() != 0)
  1488. {
  1489. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  1490. }
  1491. }
  1492. // 4. Add the new libraries to the link line.
  1493. //
  1494. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1495. newLinkLibraries.rbegin();
  1496. k != newLinkLibraries.rend(); ++k )
  1497. {
  1498. // get the llt from the dep_map
  1499. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  1500. }
  1501. this->LinkLibrariesAnalyzed = true;
  1502. }
  1503. //----------------------------------------------------------------------------
  1504. void cmTarget::InsertDependency( DependencyMap& depMap,
  1505. const LibraryID& lib,
  1506. const LibraryID& dep)
  1507. {
  1508. depMap[lib].push_back(dep);
  1509. }
  1510. //----------------------------------------------------------------------------
  1511. void cmTarget::DeleteDependency( DependencyMap& depMap,
  1512. const LibraryID& lib,
  1513. const LibraryID& dep)
  1514. {
  1515. // Make sure there is an entry in the map for lib. If so, delete all
  1516. // dependencies to dep. There may be repeated entries because of
  1517. // external libraries that are specified multiple times.
  1518. DependencyMap::iterator map_itr = depMap.find( lib );
  1519. if( map_itr != depMap.end() )
  1520. {
  1521. DependencyList& depList = map_itr->second;
  1522. DependencyList::iterator itr;
  1523. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  1524. depList.end() )
  1525. {
  1526. depList.erase( itr );
  1527. }
  1528. }
  1529. }
  1530. //----------------------------------------------------------------------------
  1531. void cmTarget::Emit(const LibraryID lib,
  1532. const DependencyMap& dep_map,
  1533. std::set<LibraryID>& emitted,
  1534. std::set<LibraryID>& visited,
  1535. DependencyList& link_line )
  1536. {
  1537. // It's already been emitted
  1538. if( emitted.find(lib) != emitted.end() )
  1539. {
  1540. return;
  1541. }
  1542. // Emit the dependencies only if this library node hasn't been
  1543. // visited before. If it has, then we have a cycle. The recursion
  1544. // that got us here should take care of everything.
  1545. if( visited.insert(lib).second )
  1546. {
  1547. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1548. {
  1549. const DependencyList& dep_on = dep_map.find( lib )->second;
  1550. DependencyList::const_reverse_iterator i;
  1551. // To cater for recursive external libraries, we must emit
  1552. // duplicates on this link line *unless* they were emitted by
  1553. // some other node, in which case we assume that the recursion
  1554. // was resolved then. We making the simplifying assumption that
  1555. // any duplicates on a single link line are on purpose, and must
  1556. // be preserved.
  1557. // This variable will keep track of the libraries that were
  1558. // emitted directory from the current node, and not from a
  1559. // recursive call. This way, if we come across a library that
  1560. // has already been emitted, we repeat it iff it has been
  1561. // emitted here.
  1562. std::set<DependencyMap::key_type> emitted_here;
  1563. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1564. {
  1565. if( emitted_here.find(*i) != emitted_here.end() )
  1566. {
  1567. // a repeat. Must emit.
  1568. emitted.insert(*i);
  1569. link_line.push_back( *i );
  1570. }
  1571. else
  1572. {
  1573. // Emit only if no-one else has
  1574. if( emitted.find(*i) == emitted.end() )
  1575. {
  1576. // emit dependencies
  1577. Emit( *i, dep_map, emitted, visited, link_line );
  1578. // emit self
  1579. emitted.insert(*i);
  1580. emitted_here.insert(*i);
  1581. link_line.push_back( *i );
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. //----------------------------------------------------------------------------
  1589. void cmTarget::GatherDependencies( const cmMakefile& mf,
  1590. const LibraryID& lib,
  1591. DependencyMap& dep_map)
  1592. {
  1593. // If the library is already in the dependency map, then it has
  1594. // already been fully processed.
  1595. if( dep_map.find(lib) != dep_map.end() )
  1596. {
  1597. return;
  1598. }
  1599. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  1600. if( deps && strcmp(deps,"") != 0 )
  1601. {
  1602. // Make sure this library is in the map, even if it has an empty
  1603. // set of dependencies. This distinguishes the case of explicitly
  1604. // no dependencies with that of unspecified dependencies.
  1605. dep_map[lib];
  1606. // Parse the dependency information, which is a set of
  1607. // type, library pairs separated by ";". There is always a trailing ";".
  1608. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1609. std::string depline = deps;
  1610. std::string::size_type start = 0;
  1611. std::string::size_type end;
  1612. end = depline.find( ";", start );
  1613. while( end != std::string::npos )
  1614. {
  1615. std::string l = depline.substr( start, end-start );
  1616. if( l.size() != 0 )
  1617. {
  1618. if (l == "debug")
  1619. {
  1620. llt = cmTarget::DEBUG;
  1621. }
  1622. else if (l == "optimized")
  1623. {
  1624. llt = cmTarget::OPTIMIZED;
  1625. }
  1626. else if (l == "general")
  1627. {
  1628. llt = cmTarget::GENERAL;
  1629. }
  1630. else
  1631. {
  1632. LibraryID lib2(l,llt);
  1633. this->InsertDependency( dep_map, lib, lib2);
  1634. this->GatherDependencies( mf, lib2, dep_map);
  1635. llt = cmTarget::GENERAL;
  1636. }
  1637. }
  1638. start = end+1; // skip the ;
  1639. end = depline.find( ";", start );
  1640. }
  1641. // cannot depend on itself
  1642. this->DeleteDependency( dep_map, lib, lib);
  1643. }
  1644. }
  1645. //----------------------------------------------------------------------------
  1646. void cmTarget::SetProperty(const char* prop, const char* value)
  1647. {
  1648. if (!prop)
  1649. {
  1650. return;
  1651. }
  1652. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  1653. // If imported information is being set, wipe out cached
  1654. // information.
  1655. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  1656. {
  1657. this->ImportInfoMap.clear();
  1658. }
  1659. }
  1660. //----------------------------------------------------------------------------
  1661. void cmTarget::AppendProperty(const char* prop, const char* value)
  1662. {
  1663. if (!prop)
  1664. {
  1665. return;
  1666. }
  1667. this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
  1668. // If imported information is being set, wipe out cached
  1669. // information.
  1670. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  1671. {
  1672. this->ImportInfoMap.clear();
  1673. }
  1674. }
  1675. //----------------------------------------------------------------------------
  1676. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  1677. const char* prop, const char* value, cmMakefile* context, bool imported
  1678. )
  1679. {
  1680. // Look for link-type keywords in the value.
  1681. static cmsys::RegularExpression
  1682. keys("(^|;)(debug|optimized|general)(;|$)");
  1683. if(!keys.find(value))
  1684. {
  1685. return;
  1686. }
  1687. // Support imported and non-imported versions of the property.
  1688. const char* base = (imported?
  1689. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  1690. "LINK_INTERFACE_LIBRARIES");
  1691. // Report an error.
  1692. cmOStringStream e;
  1693. e << "Property " << prop << " may not contain link-type keyword \""
  1694. << keys.match(2) << "\". "
  1695. << "The " << base << " property has a per-configuration "
  1696. << "version called " << base << "_<CONFIG> which may be "
  1697. << "used to specify per-configuration rules.";
  1698. if(!imported)
  1699. {
  1700. e << " "
  1701. << "Alternatively, an IMPORTED library may be created, configured "
  1702. << "with a per-configuration location, and then named in the "
  1703. << "property value. "
  1704. << "See the add_library command's IMPORTED mode for details."
  1705. << "\n"
  1706. << "If you have a list of libraries that already contains the "
  1707. << "keyword, use the target_link_libraries command with its "
  1708. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1709. << "The command automatically recognizes link-type keywords and sets "
  1710. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1711. << "properties accordingly.";
  1712. }
  1713. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1714. }
  1715. //----------------------------------------------------------------------------
  1716. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  1717. {
  1718. // Certain properties need checking.
  1719. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  1720. {
  1721. if(const char* value = this->GetProperty(prop))
  1722. {
  1723. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  1724. }
  1725. }
  1726. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  1727. {
  1728. if(const char* value = this->GetProperty(prop))
  1729. {
  1730. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  1731. }
  1732. }
  1733. }
  1734. //----------------------------------------------------------------------------
  1735. void cmTarget::MarkAsImported()
  1736. {
  1737. this->IsImportedTarget = true;
  1738. }
  1739. //----------------------------------------------------------------------------
  1740. std::string cmTarget::GetDirectory(const char* config, bool implib)
  1741. {
  1742. if (this->IsImported())
  1743. {
  1744. // Return the directory from which the target is imported.
  1745. return
  1746. cmSystemTools::GetFilenamePath(
  1747. this->ImportedGetFullPath(config, implib));
  1748. }
  1749. else
  1750. {
  1751. // Return the directory in which the target will be built.
  1752. if(config && *config)
  1753. {
  1754. // Add the configuration's subdirectory.
  1755. std::string dir = this->GetOutputDir(implib);
  1756. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  1757. AppendDirectoryForConfig("/", config, "", dir);
  1758. return dir;
  1759. }
  1760. else
  1761. {
  1762. return this->GetOutputDir(implib);
  1763. }
  1764. }
  1765. }
  1766. //----------------------------------------------------------------------------
  1767. const char* cmTarget::GetLocation(const char* config)
  1768. {
  1769. if (this->IsImported())
  1770. {
  1771. return this->ImportedGetLocation(config);
  1772. }
  1773. else
  1774. {
  1775. return this->NormalGetLocation(config);
  1776. }
  1777. }
  1778. //----------------------------------------------------------------------------
  1779. const char* cmTarget::ImportedGetLocation(const char* config)
  1780. {
  1781. this->Location = this->ImportedGetFullPath(config, false);
  1782. return this->Location.c_str();
  1783. }
  1784. //----------------------------------------------------------------------------
  1785. const char* cmTarget::NormalGetLocation(const char* config)
  1786. {
  1787. // Handle the configuration-specific case first.
  1788. if(config)
  1789. {
  1790. this->Location = this->GetFullPath(config, false);
  1791. return this->Location.c_str();
  1792. }
  1793. // Now handle the deprecated build-time configuration location.
  1794. this->Location = this->GetDirectory();
  1795. if(!this->Location.empty())
  1796. {
  1797. this->Location += "/";
  1798. }
  1799. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  1800. if(cfgid && strcmp(cfgid, ".") != 0)
  1801. {
  1802. this->Location += cfgid;
  1803. this->Location += "/";
  1804. }
  1805. if(this->IsAppBundleOnApple())
  1806. {
  1807. this->Location += this->GetFullName(config, false);
  1808. this->Location += ".app/Contents/MacOS/";
  1809. }
  1810. if(this->IsFrameworkOnApple())
  1811. {
  1812. this->Location += this->GetFullName(config, false);
  1813. this->Location += ".framework/Versions/";
  1814. this->Location += this->GetFrameworkVersion();
  1815. this->Location += "/";
  1816. }
  1817. this->Location += this->GetFullName(config, false);
  1818. return this->Location.c_str();
  1819. }
  1820. //----------------------------------------------------------------------------
  1821. void cmTarget::GetTargetVersion(int& major, int& minor)
  1822. {
  1823. int patch;
  1824. this->GetTargetVersion(false, major, minor, patch);
  1825. }
  1826. //----------------------------------------------------------------------------
  1827. void cmTarget::GetTargetVersion(bool soversion,
  1828. int& major, int& minor, int& patch)
  1829. {
  1830. // Set the default values.
  1831. major = 0;
  1832. minor = 0;
  1833. patch = 0;
  1834. // Look for a VERSION or SOVERSION property.
  1835. const char* prop = soversion? "SOVERSION" : "VERSION";
  1836. if(const char* version = this->GetProperty(prop))
  1837. {
  1838. // Try to parse the version number and store the results that were
  1839. // successfully parsed.
  1840. int parsed_major;
  1841. int parsed_minor;
  1842. int parsed_patch;
  1843. switch(sscanf(version, "%d.%d.%d",
  1844. &parsed_major, &parsed_minor, &parsed_patch))
  1845. {
  1846. case 3: patch = parsed_patch; // no break!
  1847. case 2: minor = parsed_minor; // no break!
  1848. case 1: major = parsed_major; // no break!
  1849. default: break;
  1850. }
  1851. }
  1852. }
  1853. //----------------------------------------------------------------------------
  1854. const char *cmTarget::GetProperty(const char* prop)
  1855. {
  1856. return this->GetProperty(prop, cmProperty::TARGET);
  1857. }
  1858. //----------------------------------------------------------------------------
  1859. void cmTarget::ComputeObjectFiles()
  1860. {
  1861. if (this->IsImported())
  1862. {
  1863. return;
  1864. }
  1865. #if 0
  1866. std::vector<std::string> dirs;
  1867. this->Makefile->GetLocalGenerator()->
  1868. GetTargetObjectFileDirectories(this,
  1869. dirs);
  1870. std::string objectFiles;
  1871. std::string objExtensionLookup1 = "CMAKE_";
  1872. std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
  1873. for(std::vector<std::string>::iterator d = dirs.begin();
  1874. d != dirs.end(); ++d)
  1875. {
  1876. for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
  1877. s != this->SourceFiles.end(); ++s)
  1878. {
  1879. cmSourceFile* sf = *s;
  1880. if(const char* lang = sf->GetLanguage())
  1881. {
  1882. std::string lookupObj = objExtensionLookup1 + lang;
  1883. lookupObj += objExtensionLookup2;
  1884. const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
  1885. if(obj)
  1886. {
  1887. if(objectFiles.size())
  1888. {
  1889. objectFiles += ";";
  1890. }
  1891. std::string objFile = *d;
  1892. objFile += "/";
  1893. objFile += this->Makefile->GetLocalGenerator()->
  1894. GetSourceObjectName(*sf);
  1895. objFile += obj;
  1896. objectFiles += objFile;
  1897. }
  1898. }
  1899. }
  1900. }
  1901. this->SetProperty("OBJECT_FILES", objectFiles.c_str());
  1902. #endif
  1903. }
  1904. //----------------------------------------------------------------------------
  1905. const char *cmTarget::GetProperty(const char* prop,
  1906. cmProperty::ScopeType scope)
  1907. {
  1908. if(!prop)
  1909. {
  1910. return 0;
  1911. }
  1912. // Watch for special "computed" properties that are dependent on
  1913. // other properties or variables. Always recompute them.
  1914. if(this->GetType() == cmTarget::EXECUTABLE ||
  1915. this->GetType() == cmTarget::STATIC_LIBRARY ||
  1916. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1917. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1918. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  1919. {
  1920. if(strcmp(prop,"LOCATION") == 0)
  1921. {
  1922. // Set the LOCATION property of the target.
  1923. //
  1924. // For an imported target this is the location of an arbitrary
  1925. // available configuration.
  1926. //
  1927. // For a non-imported target this is deprecated because it
  1928. // cannot take into account the per-configuration name of the
  1929. // target because the configuration type may not be known at
  1930. // CMake time.
  1931. this->SetProperty("LOCATION", this->GetLocation(0));
  1932. }
  1933. // Support "LOCATION_<CONFIG>".
  1934. if(strncmp(prop, "LOCATION_", 9) == 0)
  1935. {
  1936. std::string configName = prop+9;
  1937. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  1938. }
  1939. else
  1940. {
  1941. // Support "<CONFIG>_LOCATION" for compatiblity.
  1942. int len = static_cast<int>(strlen(prop));
  1943. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  1944. {
  1945. std::string configName(prop, len-9);
  1946. if(configName != "IMPORTED")
  1947. {
  1948. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  1949. }
  1950. }
  1951. }
  1952. }
  1953. if (strcmp(prop,"IMPORTED") == 0)
  1954. {
  1955. return this->IsImported()?"TRUE":"FALSE";
  1956. }
  1957. if(!strcmp(prop,"SOURCES"))
  1958. {
  1959. cmOStringStream ss;
  1960. const char* sep = "";
  1961. for(std::vector<cmSourceFile*>::const_iterator
  1962. i = this->SourceFiles.begin();
  1963. i != this->SourceFiles.end(); ++i)
  1964. {
  1965. // Separate from the previous list entries.
  1966. ss << sep;
  1967. sep = ";";
  1968. // Construct what is known about this source file location.
  1969. cmSourceFileLocation const& location = (*i)->GetLocation();
  1970. std::string sname = location.GetDirectory();
  1971. if(!sname.empty())
  1972. {
  1973. sname += "/";
  1974. }
  1975. sname += location.GetName();
  1976. // Append this list entry.
  1977. ss << sname;
  1978. }
  1979. this->SetProperty("SOURCES", ss.str().c_str());
  1980. }
  1981. // the type property returns what type the target is
  1982. if (!strcmp(prop,"TYPE"))
  1983. {
  1984. switch( this->GetType() )
  1985. {
  1986. case cmTarget::STATIC_LIBRARY:
  1987. return "STATIC_LIBRARY";
  1988. // break; /* unreachable */
  1989. case cmTarget::MODULE_LIBRARY:
  1990. return "MODULE_LIBRARY";
  1991. // break; /* unreachable */
  1992. case cmTarget::SHARED_LIBRARY:
  1993. return "SHARED_LIBRARY";
  1994. // break; /* unreachable */
  1995. case cmTarget::EXECUTABLE:
  1996. return "EXECUTABLE";
  1997. // break; /* unreachable */
  1998. case cmTarget::UTILITY:
  1999. return "UTILITY";
  2000. // break; /* unreachable */
  2001. case cmTarget::GLOBAL_TARGET:
  2002. return "GLOBAL_TARGET";
  2003. // break; /* unreachable */
  2004. case cmTarget::INSTALL_FILES:
  2005. return "INSTALL_FILES";
  2006. // break; /* unreachable */
  2007. case cmTarget::INSTALL_PROGRAMS:
  2008. return "INSTALL_PROGRAMS";
  2009. // break; /* unreachable */
  2010. case cmTarget::INSTALL_DIRECTORY:
  2011. return "INSTALL_DIRECTORY";
  2012. // break; /* unreachable */
  2013. case cmTarget::UNKNOWN_LIBRARY:
  2014. return "UNKNOWN_LIBRARY";
  2015. // break; /* unreachable */
  2016. }
  2017. return 0;
  2018. }
  2019. bool chain = false;
  2020. const char *retVal =
  2021. this->Properties.GetPropertyValue(prop, scope, chain);
  2022. if (chain)
  2023. {
  2024. return this->Makefile->GetProperty(prop,scope);
  2025. }
  2026. return retVal;
  2027. }
  2028. //----------------------------------------------------------------------------
  2029. bool cmTarget::GetPropertyAsBool(const char* prop)
  2030. {
  2031. return cmSystemTools::IsOn(this->GetProperty(prop));
  2032. }
  2033. //----------------------------------------------------------------------------
  2034. const char* cmTarget::GetLinkerLanguage(cmGlobalGenerator* gg)
  2035. {
  2036. if(this->GetProperty("HAS_CXX"))
  2037. {
  2038. const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", "CXX");
  2039. }
  2040. const char* linkerLang = this->GetProperty("LINKER_LANGUAGE");
  2041. if (linkerLang==0)
  2042. {
  2043. // if the property has not yet been set, collect all languages in the
  2044. // target and then find the language with the highest preference value
  2045. std::set<cmStdString> languages;
  2046. this->GetLanguages(languages);
  2047. std::string linkerLangList; // only used for the error message
  2048. int maxLinkerPref = 0;
  2049. bool multiplePreferedLanguages = false;
  2050. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  2051. sit != languages.end(); ++sit)
  2052. {
  2053. int linkerPref = gg->GetLinkerPreference(sit->c_str());
  2054. if ((linkerPref > maxLinkerPref) || (linkerLang==0))
  2055. {
  2056. maxLinkerPref = linkerPref;
  2057. linkerLang = sit->c_str();
  2058. linkerLangList = *sit;
  2059. multiplePreferedLanguages = false;
  2060. }
  2061. else if (linkerPref == maxLinkerPref)
  2062. {
  2063. linkerLangList += "; ";
  2064. linkerLangList += *sit;
  2065. multiplePreferedLanguages = true;
  2066. }
  2067. }
  2068. if (linkerLang!=0)
  2069. {
  2070. const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", linkerLang);
  2071. }
  2072. if (multiplePreferedLanguages)
  2073. {
  2074. cmOStringStream err;
  2075. err << "Error: Target " << this->Name << " contains multiple languages "
  2076. << "with the highest linker preference (" << maxLinkerPref << "): "
  2077. << linkerLangList << "\n"
  2078. << "You must set the LINKER_LANGUAGE property for this target.";
  2079. cmSystemTools::Error(err.str().c_str());
  2080. }
  2081. }
  2082. return this->GetProperty("LINKER_LANGUAGE");
  2083. }
  2084. //----------------------------------------------------------------------------
  2085. const char* cmTarget::GetCreateRuleVariable()
  2086. {
  2087. switch(this->GetType())
  2088. {
  2089. case cmTarget::STATIC_LIBRARY:
  2090. return "_CREATE_STATIC_LIBRARY";
  2091. case cmTarget::SHARED_LIBRARY:
  2092. return "_CREATE_SHARED_LIBRARY";
  2093. case cmTarget::MODULE_LIBRARY:
  2094. return "_CREATE_SHARED_MODULE";
  2095. case cmTarget::EXECUTABLE:
  2096. return "_LINK_EXECUTABLE";
  2097. default:
  2098. break;
  2099. }
  2100. return "";
  2101. }
  2102. //----------------------------------------------------------------------------
  2103. const char* cmTarget::GetSuffixVariableInternal(TargetType type,
  2104. bool implib)
  2105. {
  2106. switch(type)
  2107. {
  2108. case cmTarget::STATIC_LIBRARY:
  2109. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2110. case cmTarget::SHARED_LIBRARY:
  2111. return (implib
  2112. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2113. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2114. case cmTarget::MODULE_LIBRARY:
  2115. return (implib
  2116. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2117. : "CMAKE_SHARED_MODULE_SUFFIX");
  2118. case cmTarget::EXECUTABLE:
  2119. return (implib
  2120. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2121. : "CMAKE_EXECUTABLE_SUFFIX");
  2122. default:
  2123. break;
  2124. }
  2125. return "";
  2126. }
  2127. //----------------------------------------------------------------------------
  2128. const char* cmTarget::GetPrefixVariableInternal(TargetType type,
  2129. bool implib)
  2130. {
  2131. switch(type)
  2132. {
  2133. case cmTarget::STATIC_LIBRARY:
  2134. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2135. case cmTarget::SHARED_LIBRARY:
  2136. return (implib
  2137. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2138. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2139. case cmTarget::MODULE_LIBRARY:
  2140. return (implib
  2141. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2142. : "CMAKE_SHARED_MODULE_PREFIX");
  2143. case cmTarget::EXECUTABLE:
  2144. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  2145. default:
  2146. break;
  2147. }
  2148. return "";
  2149. }
  2150. //----------------------------------------------------------------------------
  2151. std::string cmTarget::GetPDBName(const char* config)
  2152. {
  2153. std::string prefix;
  2154. std::string base;
  2155. std::string suffix;
  2156. this->GetFullNameInternal(this->GetType(), config, false,
  2157. prefix, base, suffix);
  2158. return prefix+base+".pdb";
  2159. }
  2160. //----------------------------------------------------------------------------
  2161. std::string cmTarget::GetSOName(const char* config)
  2162. {
  2163. if(this->IsImported())
  2164. {
  2165. // Lookup the imported soname.
  2166. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2167. {
  2168. if(info->NoSOName)
  2169. {
  2170. // The imported library has no builtin soname so the name
  2171. // searched at runtime will be just the filename.
  2172. return cmSystemTools::GetFilenameName(info->Location);
  2173. }
  2174. else
  2175. {
  2176. // Use the soname given if any.
  2177. return info->SOName;
  2178. }
  2179. }
  2180. else
  2181. {
  2182. return "";
  2183. }
  2184. }
  2185. else
  2186. {
  2187. // Compute the soname that will be built.
  2188. std::string name;
  2189. std::string soName;
  2190. std::string realName;
  2191. std::string impName;
  2192. std::string pdbName;
  2193. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2194. return soName;
  2195. }
  2196. }
  2197. //----------------------------------------------------------------------------
  2198. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  2199. {
  2200. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  2201. {
  2202. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2203. {
  2204. return info->NoSOName;
  2205. }
  2206. }
  2207. return false;
  2208. }
  2209. //----------------------------------------------------------------------------
  2210. std::string cmTarget::NormalGetRealName(const char* config)
  2211. {
  2212. // This should not be called for imported targets.
  2213. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2214. // enforcement of the limited imported target API.
  2215. if(this->IsImported())
  2216. {
  2217. std::string msg = "NormalGetRealName called on imported target: ";
  2218. msg += this->GetName();
  2219. this->GetMakefile()->
  2220. IssueMessage(cmake::INTERNAL_ERROR,
  2221. msg.c_str());
  2222. }
  2223. if(this->GetType() == cmTarget::EXECUTABLE)
  2224. {
  2225. // Compute the real name that will be built.
  2226. std::string name;
  2227. std::string realName;
  2228. std::string impName;
  2229. std::string pdbName;
  2230. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2231. return realName;
  2232. }
  2233. else
  2234. {
  2235. // Compute the real name that will be built.
  2236. std::string name;
  2237. std::string soName;
  2238. std::string realName;
  2239. std::string impName;
  2240. std::string pdbName;
  2241. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2242. return realName;
  2243. }
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. std::string cmTarget::GetFullName(const char* config, bool implib)
  2247. {
  2248. if(this->IsImported())
  2249. {
  2250. return this->GetFullNameImported(config, implib);
  2251. }
  2252. else
  2253. {
  2254. return this->GetFullNameInternal(this->GetType(), config, implib);
  2255. }
  2256. }
  2257. //----------------------------------------------------------------------------
  2258. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  2259. {
  2260. return cmSystemTools::GetFilenameName(
  2261. this->ImportedGetFullPath(config, implib));
  2262. }
  2263. //----------------------------------------------------------------------------
  2264. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  2265. std::string& suffix, const char* config,
  2266. bool implib)
  2267. {
  2268. this->GetFullNameInternal(this->GetType(), config, implib,
  2269. prefix, base, suffix);
  2270. }
  2271. //----------------------------------------------------------------------------
  2272. std::string cmTarget::GetFullPath(const char* config, bool implib,
  2273. bool realname)
  2274. {
  2275. if(this->IsImported())
  2276. {
  2277. return this->ImportedGetFullPath(config, implib);
  2278. }
  2279. else
  2280. {
  2281. return this->NormalGetFullPath(config, implib, realname);
  2282. }
  2283. }
  2284. //----------------------------------------------------------------------------
  2285. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  2286. bool realname)
  2287. {
  2288. // Start with the output directory for the target.
  2289. std::string fpath = this->GetDirectory(config, implib);
  2290. fpath += "/";
  2291. if(this->IsAppBundleOnApple())
  2292. {
  2293. fpath += this->GetFullName(config, false);
  2294. fpath += ".app/Contents/MacOS/";
  2295. }
  2296. if(this->IsFrameworkOnApple())
  2297. {
  2298. fpath += this->GetFullName(config, false);
  2299. fpath += ".framework/Versions/";
  2300. fpath += this->GetFrameworkVersion();
  2301. fpath += "/";
  2302. }
  2303. // Add the full name of the target.
  2304. if(implib)
  2305. {
  2306. fpath += this->GetFullName(config, true);
  2307. }
  2308. else if(realname)
  2309. {
  2310. fpath += this->NormalGetRealName(config);
  2311. }
  2312. else
  2313. {
  2314. fpath += this->GetFullName(config, false);
  2315. }
  2316. return fpath;
  2317. }
  2318. //----------------------------------------------------------------------------
  2319. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  2320. {
  2321. std::string result;
  2322. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2323. {
  2324. result = implib? info->ImportLibrary : info->Location;
  2325. }
  2326. if(result.empty())
  2327. {
  2328. result = this->GetName();
  2329. result += "-NOTFOUND";
  2330. }
  2331. return result;
  2332. }
  2333. //----------------------------------------------------------------------------
  2334. std::string
  2335. cmTarget::GetFullNameInternal(TargetType type, const char* config,
  2336. bool implib)
  2337. {
  2338. std::string prefix;
  2339. std::string base;
  2340. std::string suffix;
  2341. this->GetFullNameInternal(type, config, implib, prefix, base, suffix);
  2342. return prefix+base+suffix;
  2343. }
  2344. //----------------------------------------------------------------------------
  2345. void cmTarget::GetFullNameInternal(TargetType type,
  2346. const char* config,
  2347. bool implib,
  2348. std::string& outPrefix,
  2349. std::string& outBase,
  2350. std::string& outSuffix)
  2351. {
  2352. // Use just the target name for non-main target types.
  2353. if(type != cmTarget::STATIC_LIBRARY &&
  2354. type != cmTarget::SHARED_LIBRARY &&
  2355. type != cmTarget::MODULE_LIBRARY &&
  2356. type != cmTarget::EXECUTABLE)
  2357. {
  2358. outPrefix = "";
  2359. outBase = this->GetName();
  2360. outSuffix = "";
  2361. return;
  2362. }
  2363. // Return an empty name for the import library if this platform
  2364. // does not support import libraries.
  2365. if(implib &&
  2366. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2367. {
  2368. outPrefix = "";
  2369. outBase = "";
  2370. outSuffix = "";
  2371. return;
  2372. }
  2373. // The implib option is only allowed for shared libraries, module
  2374. // libraries, and executables.
  2375. if(type != cmTarget::SHARED_LIBRARY &&
  2376. type != cmTarget::MODULE_LIBRARY &&
  2377. type != cmTarget::EXECUTABLE)
  2378. {
  2379. implib = false;
  2380. }
  2381. // Compute the full name for main target types.
  2382. const char* targetPrefix = (implib
  2383. ? this->GetProperty("IMPORT_PREFIX")
  2384. : this->GetProperty("PREFIX"));
  2385. const char* targetSuffix = (implib
  2386. ? this->GetProperty("IMPORT_SUFFIX")
  2387. : this->GetProperty("SUFFIX"));
  2388. const char* configPostfix = 0;
  2389. if(config && *config)
  2390. {
  2391. std::string configProp = cmSystemTools::UpperCase(config);
  2392. configProp += "_POSTFIX";
  2393. configPostfix = this->GetProperty(configProp.c_str());
  2394. // Mac application bundles and frameworks have no postfix.
  2395. if(configPostfix &&
  2396. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  2397. {
  2398. configPostfix = 0;
  2399. }
  2400. }
  2401. const char* prefixVar = this->GetPrefixVariableInternal(type, implib);
  2402. const char* suffixVar = this->GetSuffixVariableInternal(type, implib);
  2403. const char* ll =
  2404. this->GetLinkerLanguage(
  2405. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  2406. // first try language specific suffix
  2407. if(ll)
  2408. {
  2409. if(!targetSuffix && suffixVar && *suffixVar)
  2410. {
  2411. std::string langSuff = suffixVar + std::string("_") + ll;
  2412. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  2413. }
  2414. if(!targetPrefix && prefixVar && *prefixVar)
  2415. {
  2416. std::string langPrefix = prefixVar + std::string("_") + ll;
  2417. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  2418. }
  2419. }
  2420. // if there is no prefix on the target use the cmake definition
  2421. if(!targetPrefix && prefixVar)
  2422. {
  2423. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2424. }
  2425. // if there is no suffix on the target use the cmake definition
  2426. if(!targetSuffix && suffixVar)
  2427. {
  2428. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2429. }
  2430. // frameworks do not have a prefix or a suffix
  2431. if(this->IsFrameworkOnApple())
  2432. {
  2433. targetPrefix = 0;
  2434. targetSuffix = 0;
  2435. }
  2436. // Begin the final name with the prefix.
  2437. outPrefix = targetPrefix?targetPrefix:"";
  2438. // Append the target name or property-specified name.
  2439. const char* outName = 0;
  2440. if(config && *config)
  2441. {
  2442. std::string configProp = cmSystemTools::UpperCase(config);
  2443. configProp += "_OUTPUT_NAME";
  2444. outName = this->GetProperty(configProp.c_str());
  2445. }
  2446. if(!outName)
  2447. {
  2448. outName = this->GetProperty("OUTPUT_NAME");
  2449. }
  2450. if(outName)
  2451. {
  2452. outBase = outName;
  2453. }
  2454. else
  2455. {
  2456. outBase = this->GetName();
  2457. }
  2458. // Append the per-configuration postfix.
  2459. outBase += configPostfix?configPostfix:"";
  2460. // Name shared libraries with their version number on some platforms.
  2461. if(const char* version = this->GetProperty("VERSION"))
  2462. {
  2463. if(type == cmTarget::SHARED_LIBRARY && !implib &&
  2464. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2465. {
  2466. outBase += "-";
  2467. outBase += version;
  2468. }
  2469. }
  2470. // Append the suffix.
  2471. outSuffix = targetSuffix?targetSuffix:"";
  2472. }
  2473. //----------------------------------------------------------------------------
  2474. void cmTarget::GetLibraryNames(std::string& name,
  2475. std::string& soName,
  2476. std::string& realName,
  2477. std::string& impName,
  2478. std::string& pdbName,
  2479. const char* config)
  2480. {
  2481. // Get the names based on the real type of the library.
  2482. this->GetLibraryNamesInternal(name, soName, realName, impName, pdbName,
  2483. this->GetType(), config);
  2484. }
  2485. //----------------------------------------------------------------------------
  2486. void cmTarget::GetLibraryCleanNames(std::string& staticName,
  2487. std::string& sharedName,
  2488. std::string& sharedSOName,
  2489. std::string& sharedRealName,
  2490. std::string& importName,
  2491. std::string& pdbName,
  2492. const char* config)
  2493. {
  2494. // Get the name as if this were a static library.
  2495. std::string soName;
  2496. std::string realName;
  2497. std::string impName;
  2498. this->GetLibraryNamesInternal(staticName, soName, realName, impName,
  2499. pdbName, cmTarget::STATIC_LIBRARY, config);
  2500. // Get the names as if this were a shared library.
  2501. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  2502. {
  2503. // Since the real type is static then the user either specified
  2504. // STATIC or did not specify a type. In the former case the
  2505. // shared library will never be present. In the latter case the
  2506. // type will never be MODULE. Either way the only names that
  2507. // might have to be cleaned are the shared library names.
  2508. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  2509. importName, pdbName,
  2510. cmTarget::SHARED_LIBRARY, config);
  2511. }
  2512. else
  2513. {
  2514. // Use the name of the real type of the library (shared or module).
  2515. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  2516. importName, pdbName, this->GetType(),
  2517. config);
  2518. }
  2519. }
  2520. //----------------------------------------------------------------------------
  2521. void cmTarget::GetLibraryNamesInternal(std::string& name,
  2522. std::string& soName,
  2523. std::string& realName,
  2524. std::string& impName,
  2525. std::string& pdbName,
  2526. TargetType type,
  2527. const char* config)
  2528. {
  2529. // This should not be called for imported targets.
  2530. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2531. // enforcement of the limited imported target API.
  2532. if(this->IsImported())
  2533. {
  2534. std::string msg = "GetLibraryNamesInternal called on imported target: ";
  2535. msg += this->GetName();
  2536. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  2537. msg.c_str());
  2538. return;
  2539. }
  2540. // Construct the name of the soname flag variable for this language.
  2541. const char* ll =
  2542. this->GetLinkerLanguage(
  2543. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  2544. std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
  2545. if(ll)
  2546. {
  2547. sonameFlag += "_";
  2548. sonameFlag += ll;
  2549. }
  2550. sonameFlag += "_FLAG";
  2551. // Check for library version properties.
  2552. const char* version = this->GetProperty("VERSION");
  2553. const char* soversion = this->GetProperty("SOVERSION");
  2554. if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
  2555. !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
  2556. this->IsFrameworkOnApple())
  2557. {
  2558. // Versioning is supported only for shared libraries and modules,
  2559. // and then only when the platform supports an soname flag.
  2560. version = 0;
  2561. soversion = 0;
  2562. }
  2563. if(version && !soversion)
  2564. {
  2565. // The soversion must be set if the library version is set. Use
  2566. // the library version as the soversion.
  2567. soversion = version;
  2568. }
  2569. // Get the components of the library name.
  2570. std::string prefix;
  2571. std::string base;
  2572. std::string suffix;
  2573. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  2574. // The library name.
  2575. name = prefix+base+suffix;
  2576. // The library's soname.
  2577. #if defined(__APPLE__)
  2578. soName = prefix+base;
  2579. #else
  2580. soName = name;
  2581. #endif
  2582. if(soversion)
  2583. {
  2584. soName += ".";
  2585. soName += soversion;
  2586. }
  2587. #if defined(__APPLE__)
  2588. soName += suffix;
  2589. #endif
  2590. // The library's real name on disk.
  2591. #if defined(__APPLE__)
  2592. realName = prefix+base;
  2593. #else
  2594. realName = name;
  2595. #endif
  2596. if(version)
  2597. {
  2598. realName += ".";
  2599. realName += version;
  2600. }
  2601. else if(soversion)
  2602. {
  2603. realName += ".";
  2604. realName += soversion;
  2605. }
  2606. #if defined(__APPLE__)
  2607. realName += suffix;
  2608. #endif
  2609. // The import library name.
  2610. if(type == cmTarget::SHARED_LIBRARY ||
  2611. type == cmTarget::MODULE_LIBRARY)
  2612. {
  2613. impName = this->GetFullNameInternal(type, config, true);
  2614. }
  2615. else
  2616. {
  2617. impName = "";
  2618. }
  2619. // The program database file name.
  2620. pdbName = prefix+base+".pdb";
  2621. }
  2622. //----------------------------------------------------------------------------
  2623. void cmTarget::GetExecutableNames(std::string& name,
  2624. std::string& realName,
  2625. std::string& impName,
  2626. std::string& pdbName,
  2627. const char* config)
  2628. {
  2629. // Get the names based on the real type of the executable.
  2630. this->GetExecutableNamesInternal(name, realName, impName, pdbName,
  2631. this->GetType(), config);
  2632. }
  2633. //----------------------------------------------------------------------------
  2634. void cmTarget::GetExecutableCleanNames(std::string& name,
  2635. std::string& realName,
  2636. std::string& impName,
  2637. std::string& pdbName,
  2638. const char* config)
  2639. {
  2640. // Get the name and versioned name of this executable.
  2641. this->GetExecutableNamesInternal(name, realName, impName, pdbName,
  2642. cmTarget::EXECUTABLE, config);
  2643. }
  2644. //----------------------------------------------------------------------------
  2645. void cmTarget::GetExecutableNamesInternal(std::string& name,
  2646. std::string& realName,
  2647. std::string& impName,
  2648. std::string& pdbName,
  2649. TargetType type,
  2650. const char* config)
  2651. {
  2652. // This should not be called for imported targets.
  2653. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2654. // enforcement of the limited imported target API.
  2655. if(this->IsImported())
  2656. {
  2657. std::string msg =
  2658. "GetExecutableNamesInternal called on imported target: ";
  2659. msg += this->GetName();
  2660. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  2661. }
  2662. // This versioning is supported only for executables and then only
  2663. // when the platform supports symbolic links.
  2664. #if defined(_WIN32) && !defined(__CYGWIN__)
  2665. const char* version = 0;
  2666. #else
  2667. // Check for executable version properties.
  2668. const char* version = this->GetProperty("VERSION");
  2669. if(type != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2670. {
  2671. version = 0;
  2672. }
  2673. #endif
  2674. // Get the components of the executable name.
  2675. std::string prefix;
  2676. std::string base;
  2677. std::string suffix;
  2678. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  2679. // The executable name.
  2680. name = prefix+base+suffix;
  2681. // The executable's real name on disk.
  2682. #if defined(__CYGWIN__)
  2683. realName = prefix+base;
  2684. #else
  2685. realName = name;
  2686. #endif
  2687. if(version)
  2688. {
  2689. realName += "-";
  2690. realName += version;
  2691. }
  2692. #if defined(__CYGWIN__)
  2693. realName += suffix;
  2694. #endif
  2695. // The import library name.
  2696. impName = this->GetFullNameInternal(type, config, true);
  2697. // The program database file name.
  2698. pdbName = prefix+base+".pdb";
  2699. }
  2700. //----------------------------------------------------------------------------
  2701. void cmTarget::GenerateTargetManifest(const char* config)
  2702. {
  2703. cmMakefile* mf = this->Makefile;
  2704. cmLocalGenerator* lg = mf->GetLocalGenerator();
  2705. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  2706. // Get the names.
  2707. std::string name;
  2708. std::string soName;
  2709. std::string realName;
  2710. std::string impName;
  2711. std::string pdbName;
  2712. if(this->GetType() == cmTarget::EXECUTABLE)
  2713. {
  2714. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2715. }
  2716. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2717. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2718. this->GetType() == cmTarget::MODULE_LIBRARY)
  2719. {
  2720. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2721. }
  2722. else
  2723. {
  2724. return;
  2725. }
  2726. // Get the directory.
  2727. std::string dir = this->GetDirectory(config, false);
  2728. // Add each name.
  2729. std::string f;
  2730. if(!name.empty())
  2731. {
  2732. f = dir;
  2733. f += "/";
  2734. f += name;
  2735. gg->AddToManifest(config? config:"", f);
  2736. }
  2737. if(!soName.empty())
  2738. {
  2739. f = dir;
  2740. f += "/";
  2741. f += soName;
  2742. gg->AddToManifest(config? config:"", f);
  2743. }
  2744. if(!realName.empty())
  2745. {
  2746. f = dir;
  2747. f += "/";
  2748. f += realName;
  2749. gg->AddToManifest(config? config:"", f);
  2750. }
  2751. if(!pdbName.empty())
  2752. {
  2753. f = dir;
  2754. f += "/";
  2755. f += pdbName;
  2756. gg->AddToManifest(config? config:"", f);
  2757. }
  2758. if(!impName.empty())
  2759. {
  2760. f = this->GetDirectory(config, true);
  2761. f += "/";
  2762. f += impName;
  2763. gg->AddToManifest(config? config:"", f);
  2764. }
  2765. }
  2766. //----------------------------------------------------------------------------
  2767. void cmTarget::SetPropertyDefault(const char* property,
  2768. const char* default_value)
  2769. {
  2770. // Compute the name of the variable holding the default value.
  2771. std::string var = "CMAKE_";
  2772. var += property;
  2773. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  2774. {
  2775. this->SetProperty(property, value);
  2776. }
  2777. else if(default_value)
  2778. {
  2779. this->SetProperty(property, default_value);
  2780. }
  2781. }
  2782. //----------------------------------------------------------------------------
  2783. bool cmTarget::HaveBuildTreeRPATH()
  2784. {
  2785. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  2786. !this->LinkLibraries.empty());
  2787. }
  2788. //----------------------------------------------------------------------------
  2789. bool cmTarget::HaveInstallTreeRPATH()
  2790. {
  2791. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  2792. return install_rpath && *install_rpath;
  2793. }
  2794. //----------------------------------------------------------------------------
  2795. bool cmTarget::NeedRelinkBeforeInstall()
  2796. {
  2797. // Only executables and shared libraries can have an rpath and may
  2798. // need relinking.
  2799. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  2800. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  2801. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  2802. {
  2803. return false;
  2804. }
  2805. // If there is no install location this target will not be installed
  2806. // and therefore does not need relinking.
  2807. if(!this->GetHaveInstallRule())
  2808. {
  2809. return false;
  2810. }
  2811. // If skipping all rpaths completely then no relinking is needed.
  2812. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  2813. {
  2814. return false;
  2815. }
  2816. // If building with the install-tree rpath no relinking is needed.
  2817. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  2818. {
  2819. return false;
  2820. }
  2821. // If chrpath is going to be used no relinking is needed.
  2822. if(this->IsChrpathUsed())
  2823. {
  2824. return false;
  2825. }
  2826. // Check for rpath support on this platform.
  2827. if(const char* ll = this->GetLinkerLanguage(
  2828. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
  2829. {
  2830. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  2831. flagVar += ll;
  2832. flagVar += "_FLAG";
  2833. if(!this->Makefile->IsSet(flagVar.c_str()))
  2834. {
  2835. // There is no rpath support on this platform so nothing needs
  2836. // relinking.
  2837. return false;
  2838. }
  2839. }
  2840. else
  2841. {
  2842. // No linker language is known. This error will be reported by
  2843. // other code.
  2844. return false;
  2845. }
  2846. // If either a build or install tree rpath is set then the rpath
  2847. // will likely change between the build tree and install tree and
  2848. // this target must be relinked.
  2849. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  2850. }
  2851. //----------------------------------------------------------------------------
  2852. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  2853. bool for_xcode)
  2854. {
  2855. // If building directly for installation then the build tree install_name
  2856. // is the same as the install tree.
  2857. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  2858. {
  2859. return GetInstallNameDirForInstallTree(config, for_xcode);
  2860. }
  2861. // Use the build tree directory for the target.
  2862. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  2863. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  2864. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  2865. {
  2866. std::string dir = this->GetDirectory(config);
  2867. dir += "/";
  2868. if(this->IsFrameworkOnApple() && !for_xcode)
  2869. {
  2870. dir += this->GetFullName(config, false);
  2871. dir += ".framework/Versions/";
  2872. dir += this->GetFrameworkVersion();
  2873. dir += "/";
  2874. }
  2875. return dir;
  2876. }
  2877. else
  2878. {
  2879. return "";
  2880. }
  2881. }
  2882. //----------------------------------------------------------------------------
  2883. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  2884. bool for_xcode)
  2885. {
  2886. // Lookup the target property.
  2887. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  2888. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  2889. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  2890. install_name_dir && *install_name_dir)
  2891. {
  2892. std::string dir = install_name_dir;
  2893. dir += "/";
  2894. if(this->IsFrameworkOnApple() && !for_xcode)
  2895. {
  2896. dir += this->GetFullName(config, false);
  2897. dir += ".framework/Versions/";
  2898. dir += this->GetFrameworkVersion();
  2899. dir += "/";
  2900. }
  2901. return dir;
  2902. }
  2903. else
  2904. {
  2905. return "";
  2906. }
  2907. }
  2908. //----------------------------------------------------------------------------
  2909. const char* cmTarget::GetOutputTargetType(bool implib)
  2910. {
  2911. switch(this->GetType())
  2912. {
  2913. case cmTarget::SHARED_LIBRARY:
  2914. if(this->DLLPlatform)
  2915. {
  2916. if(implib)
  2917. {
  2918. // A DLL import library is treated as an archive target.
  2919. return "ARCHIVE";
  2920. }
  2921. else
  2922. {
  2923. // A DLL shared library is treated as a runtime target.
  2924. return "RUNTIME";
  2925. }
  2926. }
  2927. else
  2928. {
  2929. // For non-DLL platforms shared libraries are treated as
  2930. // library targets.
  2931. return "LIBRARY";
  2932. }
  2933. case cmTarget::STATIC_LIBRARY:
  2934. // Static libraries are always treated as archive targets.
  2935. return "ARCHIVE";
  2936. case cmTarget::MODULE_LIBRARY:
  2937. if(implib)
  2938. {
  2939. // Module libraries are always treated as library targets.
  2940. return "ARCHIVE";
  2941. }
  2942. else
  2943. {
  2944. // Module import libraries are treated as archive targets.
  2945. return "LIBRARY";
  2946. }
  2947. case cmTarget::EXECUTABLE:
  2948. if(implib)
  2949. {
  2950. // Executable import libraries are treated as archive targets.
  2951. return "ARCHIVE";
  2952. }
  2953. else
  2954. {
  2955. // Executables are always treated as runtime targets.
  2956. return "RUNTIME";
  2957. }
  2958. default:
  2959. break;
  2960. }
  2961. return "";
  2962. }
  2963. //----------------------------------------------------------------------------
  2964. std::string cmTarget::GetOutputDir(bool implib)
  2965. {
  2966. // The implib option is only allowed for shared libraries, module
  2967. // libraries, and executables.
  2968. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2969. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2970. this->GetType() != cmTarget::EXECUTABLE)
  2971. {
  2972. implib = false;
  2973. }
  2974. // Sanity check. Only generators on platforms supporting import
  2975. // libraries should be asking for the import library output
  2976. // directory.
  2977. if(implib &&
  2978. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2979. {
  2980. std::string msg = "GetOutputDir, imlib set but there is no "
  2981. "CMAKE_IMPORT_LIBRARY_SUFFIX for target: ";
  2982. msg += this->GetName();
  2983. this->GetMakefile()->
  2984. IssueMessage(cmake::INTERNAL_ERROR,
  2985. msg.c_str());
  2986. }
  2987. if(implib && !this->DLLPlatform)
  2988. {
  2989. std::string msg = "implib set for platform that does not "
  2990. " support DLL's for target: ";
  2991. msg += this->GetName();
  2992. this->GetMakefile()->
  2993. IssueMessage(cmake::INTERNAL_ERROR,
  2994. msg.c_str());
  2995. }
  2996. return this->ComputeBaseOutputDir(implib);
  2997. }
  2998. //----------------------------------------------------------------------------
  2999. std::string const& cmTarget::ComputeBaseOutputDir(bool implib)
  3000. {
  3001. // Select whether we are constructing the directory for the main
  3002. // target or the import library.
  3003. std::string& out = implib? this->BaseOutputDirImplib : this->BaseOutputDir;
  3004. // Return immediately if the directory has already been computed.
  3005. if(!out.empty())
  3006. {
  3007. return out;
  3008. }
  3009. // Look for a target property defining the target output directory
  3010. // based on the target type.
  3011. const char* propertyName = 0;
  3012. std::string propertyNameStr = this->GetOutputTargetType(implib);
  3013. if(!propertyNameStr.empty())
  3014. {
  3015. propertyNameStr += "_OUTPUT_DIRECTORY";
  3016. propertyName = propertyNameStr.c_str();
  3017. }
  3018. // Select an output directory.
  3019. if(const char* outdir = this->GetProperty(propertyName))
  3020. {
  3021. // Use the user-specified output directory.
  3022. out = outdir;
  3023. }
  3024. else if(this->GetType() == cmTarget::EXECUTABLE)
  3025. {
  3026. // Lookup the output path for executables.
  3027. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3028. }
  3029. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3030. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3031. this->GetType() == cmTarget::MODULE_LIBRARY)
  3032. {
  3033. // Lookup the output path for libraries.
  3034. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3035. }
  3036. if(out.empty())
  3037. {
  3038. // Default to the current output directory.
  3039. out = ".";
  3040. }
  3041. // Convert the output path to a full path in case it is
  3042. // specified as a relative path. Treat a relative path as
  3043. // relative to the current output directory for this makefile.
  3044. out = (cmSystemTools::CollapseFullPath
  3045. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3046. return out;
  3047. }
  3048. //----------------------------------------------------------------------------
  3049. std::string cmTarget::GetFrameworkVersion()
  3050. {
  3051. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3052. {
  3053. return fversion;
  3054. }
  3055. else if(const char* tversion = this->GetProperty("VERSION"))
  3056. {
  3057. return tversion;
  3058. }
  3059. else
  3060. {
  3061. return "A";
  3062. }
  3063. }
  3064. //----------------------------------------------------------------------------
  3065. const char* cmTarget::GetExportMacro()
  3066. {
  3067. // Define the symbol for targets that export symbols.
  3068. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3069. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3070. this->IsExecutableWithExports())
  3071. {
  3072. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3073. {
  3074. this->ExportMacro = custom_export_name;
  3075. }
  3076. else
  3077. {
  3078. std::string in = this->GetName();
  3079. in += "_EXPORTS";
  3080. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  3081. }
  3082. return this->ExportMacro.c_str();
  3083. }
  3084. else
  3085. {
  3086. return 0;
  3087. }
  3088. }
  3089. //----------------------------------------------------------------------------
  3090. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  3091. {
  3092. for(std::vector<cmSourceFile*>::const_iterator
  3093. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  3094. {
  3095. if(const char* lang = (*i)->GetLanguage())
  3096. {
  3097. languages.insert(lang);
  3098. }
  3099. }
  3100. }
  3101. //----------------------------------------------------------------------------
  3102. bool cmTarget::IsChrpathUsed()
  3103. {
  3104. #if defined(CMAKE_USE_ELF_PARSER)
  3105. // Only certain target types have an rpath.
  3106. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3107. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3108. this->GetType() == cmTarget::EXECUTABLE))
  3109. {
  3110. return false;
  3111. }
  3112. // If the target will not be installed we do not need to change its
  3113. // rpath.
  3114. if(!this->GetHaveInstallRule())
  3115. {
  3116. return false;
  3117. }
  3118. // Skip chrpath if skipping rpath altogether.
  3119. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3120. {
  3121. return false;
  3122. }
  3123. // Skip chrpath if it does not need to be changed at install time.
  3124. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3125. {
  3126. return false;
  3127. }
  3128. // Allow the user to disable builtin chrpath explicitly.
  3129. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  3130. {
  3131. return false;
  3132. }
  3133. // Enable if the rpath flag uses a separator and the target uses ELF
  3134. // binaries.
  3135. if(const char* ll = this->GetLinkerLanguage(
  3136. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
  3137. {
  3138. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3139. sepVar += ll;
  3140. sepVar += "_FLAG_SEP";
  3141. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  3142. if(sep && *sep)
  3143. {
  3144. // TODO: Add ELF check to ABI detection and get rid of
  3145. // CMAKE_EXECUTABLE_FORMAT.
  3146. if(const char* fmt =
  3147. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  3148. {
  3149. return strcmp(fmt, "ELF") == 0;
  3150. }
  3151. }
  3152. }
  3153. #endif
  3154. return false;
  3155. }
  3156. //----------------------------------------------------------------------------
  3157. cmTarget::ImportInfo const*
  3158. cmTarget::GetImportInfo(const char* config)
  3159. {
  3160. // There is no imported information for non-imported targets.
  3161. if(!this->IsImported())
  3162. {
  3163. return 0;
  3164. }
  3165. // Lookup/compute/cache the import information for this
  3166. // configuration.
  3167. std::string config_upper;
  3168. if(config && *config)
  3169. {
  3170. config_upper = cmSystemTools::UpperCase(config);
  3171. }
  3172. else
  3173. {
  3174. config_upper = "NOCONFIG";
  3175. }
  3176. ImportInfoMapType::const_iterator i =
  3177. this->ImportInfoMap.find(config_upper);
  3178. if(i == this->ImportInfoMap.end())
  3179. {
  3180. ImportInfo info;
  3181. this->ComputeImportInfo(config_upper, info);
  3182. ImportInfoMapType::value_type entry(config_upper, info);
  3183. i = this->ImportInfoMap.insert(entry).first;
  3184. }
  3185. // If the location is empty then the target is not available for
  3186. // this configuration.
  3187. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3188. {
  3189. return 0;
  3190. }
  3191. // Return the import information.
  3192. return &i->second;
  3193. }
  3194. //----------------------------------------------------------------------------
  3195. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3196. ImportInfo& info)
  3197. {
  3198. // This method finds information about an imported target from its
  3199. // properties. The "IMPORTED_" namespace is reserved for properties
  3200. // defined by the project exporting the target.
  3201. // Initialize members.
  3202. info.NoSOName = false;
  3203. // Track the configuration-specific property suffix.
  3204. std::string suffix = "_";
  3205. suffix += desired_config;
  3206. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3207. // library or an executable with exports.
  3208. bool allowImp =
  3209. this->DLLPlatform && (this->GetType() == cmTarget::SHARED_LIBRARY ||
  3210. this->IsExecutableWithExports());
  3211. // Look for a mapping from the current project's configuration to
  3212. // the imported project's configuration.
  3213. std::vector<std::string> mappedConfigs;
  3214. {
  3215. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3216. mapProp += desired_config;
  3217. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  3218. {
  3219. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3220. }
  3221. }
  3222. // If a mapping was found, check its configurations.
  3223. const char* loc = 0;
  3224. const char* imp = 0;
  3225. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3226. !loc && !imp && mci != mappedConfigs.end(); ++mci)
  3227. {
  3228. // Look for this configuration.
  3229. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  3230. std::string locProp = "IMPORTED_LOCATION_";
  3231. locProp += mcUpper;
  3232. loc = this->GetProperty(locProp.c_str());
  3233. if(allowImp)
  3234. {
  3235. std::string impProp = "IMPORTED_IMPLIB_";
  3236. impProp += mcUpper;
  3237. imp = this->GetProperty(impProp.c_str());
  3238. }
  3239. // If it was found, use it for all properties below.
  3240. if(loc || imp)
  3241. {
  3242. suffix = "_";
  3243. suffix += mcUpper;
  3244. }
  3245. }
  3246. // If we needed to find one of the mapped configurations but did not
  3247. // then the target is not found. The project does not want any
  3248. // other configuration.
  3249. if(!mappedConfigs.empty() && !loc && !imp)
  3250. {
  3251. return;
  3252. }
  3253. // If we have not yet found it then there are no mapped
  3254. // configurations. Look for an exact-match.
  3255. if(!loc && !imp)
  3256. {
  3257. std::string locProp = "IMPORTED_LOCATION";
  3258. locProp += suffix;
  3259. loc = this->GetProperty(locProp.c_str());
  3260. if(allowImp)
  3261. {
  3262. std::string impProp = "IMPORTED_IMPLIB";
  3263. impProp += suffix;
  3264. imp = this->GetProperty(impProp.c_str());
  3265. }
  3266. }
  3267. // If we have not yet found it then there are no mapped
  3268. // configurations and no exact match.
  3269. if(!loc && !imp)
  3270. {
  3271. // The suffix computed above is not useful.
  3272. suffix = "";
  3273. // Look for a configuration-less location. This may be set by
  3274. // manually-written code.
  3275. loc = this->GetProperty("IMPORTED_LOCATION");
  3276. if(allowImp)
  3277. {
  3278. imp = this->GetProperty("IMPORTED_IMPLIB");
  3279. }
  3280. }
  3281. // If we have not yet found it then the project is willing to try
  3282. // any available configuration.
  3283. if(!loc && !imp)
  3284. {
  3285. std::vector<std::string> availableConfigs;
  3286. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3287. {
  3288. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3289. }
  3290. for(std::vector<std::string>::const_iterator
  3291. aci = availableConfigs.begin();
  3292. !loc && !imp && aci != availableConfigs.end(); ++aci)
  3293. {
  3294. suffix = "_";
  3295. suffix += cmSystemTools::UpperCase(*aci);
  3296. std::string locProp = "IMPORTED_LOCATION";
  3297. locProp += suffix;
  3298. loc = this->GetProperty(locProp.c_str());
  3299. if(allowImp)
  3300. {
  3301. std::string impProp = "IMPORTED_IMPLIB";
  3302. impProp += suffix;
  3303. imp = this->GetProperty(impProp.c_str());
  3304. }
  3305. }
  3306. }
  3307. // If we have not yet found it then the target is not available.
  3308. if(!loc && !imp)
  3309. {
  3310. return;
  3311. }
  3312. // A provided configuration has been chosen. Load the
  3313. // configuration's properties.
  3314. // Get the location.
  3315. if(loc)
  3316. {
  3317. info.Location = loc;
  3318. }
  3319. else
  3320. {
  3321. std::string impProp = "IMPORTED_LOCATION";
  3322. impProp += suffix;
  3323. if(const char* config_location = this->GetProperty(impProp.c_str()))
  3324. {
  3325. info.Location = config_location;
  3326. }
  3327. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3328. {
  3329. info.Location = location;
  3330. }
  3331. }
  3332. // Get the soname.
  3333. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3334. {
  3335. std::string soProp = "IMPORTED_SONAME";
  3336. soProp += suffix;
  3337. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  3338. {
  3339. info.SOName = config_soname;
  3340. }
  3341. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3342. {
  3343. info.SOName = soname;
  3344. }
  3345. }
  3346. // Get the "no-soname" mark.
  3347. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3348. {
  3349. std::string soProp = "IMPORTED_NO_SONAME";
  3350. soProp += suffix;
  3351. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  3352. {
  3353. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3354. }
  3355. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3356. {
  3357. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3358. }
  3359. }
  3360. // Get the import library.
  3361. if(imp)
  3362. {
  3363. info.ImportLibrary = imp;
  3364. }
  3365. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3366. this->IsExecutableWithExports())
  3367. {
  3368. std::string impProp = "IMPORTED_IMPLIB";
  3369. impProp += suffix;
  3370. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  3371. {
  3372. info.ImportLibrary = config_implib;
  3373. }
  3374. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  3375. {
  3376. info.ImportLibrary = implib;
  3377. }
  3378. }
  3379. // Get the link interface.
  3380. {
  3381. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3382. linkProp += suffix;
  3383. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3384. {
  3385. cmSystemTools::ExpandListArgument(config_libs,
  3386. info.LinkInterface.Libraries);
  3387. }
  3388. else if(const char* libs =
  3389. this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
  3390. {
  3391. cmSystemTools::ExpandListArgument(libs,
  3392. info.LinkInterface.Libraries);
  3393. }
  3394. }
  3395. // Get the link dependencies.
  3396. {
  3397. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  3398. linkProp += suffix;
  3399. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3400. {
  3401. cmSystemTools::ExpandListArgument(config_libs,
  3402. info.LinkInterface.SharedDeps);
  3403. }
  3404. else if(const char* libs =
  3405. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  3406. {
  3407. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  3408. }
  3409. }
  3410. }
  3411. //----------------------------------------------------------------------------
  3412. cmTargetLinkInterface const* cmTarget::GetLinkInterface(const char* config)
  3413. {
  3414. // Imported targets have their own link interface.
  3415. if(this->IsImported())
  3416. {
  3417. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3418. {
  3419. return &info->LinkInterface;
  3420. }
  3421. return 0;
  3422. }
  3423. // Link interfaces are supported only for shared libraries and
  3424. // executables that export symbols.
  3425. if((this->GetType() != cmTarget::SHARED_LIBRARY &&
  3426. !this->IsExecutableWithExports()))
  3427. {
  3428. return 0;
  3429. }
  3430. // Lookup any existing link interface for this configuration.
  3431. std::map<cmStdString, cmTargetLinkInterface*>::iterator
  3432. i = this->LinkInterface.find(config?config:"");
  3433. if(i == this->LinkInterface.end())
  3434. {
  3435. // Compute the link interface for this configuration.
  3436. cmTargetLinkInterface* iface = this->ComputeLinkInterface(config);
  3437. // Store the information for this configuration.
  3438. std::map<cmStdString, cmTargetLinkInterface*>::value_type
  3439. entry(config?config:"", iface);
  3440. i = this->LinkInterface.insert(entry).first;
  3441. }
  3442. return i->second;
  3443. }
  3444. //----------------------------------------------------------------------------
  3445. cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config)
  3446. {
  3447. // Construct the property name suffix for this configuration.
  3448. std::string suffix = "_";
  3449. if(config && *config)
  3450. {
  3451. suffix += cmSystemTools::UpperCase(config);
  3452. }
  3453. else
  3454. {
  3455. suffix += "NOCONFIG";
  3456. }
  3457. // Lookup the link interface libraries.
  3458. const char* libs = 0;
  3459. {
  3460. // Lookup the per-configuration property.
  3461. std::string propName = "LINK_INTERFACE_LIBRARIES";
  3462. propName += suffix;
  3463. libs = this->GetProperty(propName.c_str());
  3464. // If not set, try the generic property.
  3465. if(!libs)
  3466. {
  3467. libs = this->GetProperty("LINK_INTERFACE_LIBRARIES");
  3468. }
  3469. }
  3470. // If still not set, there is no link interface.
  3471. if(!libs)
  3472. {
  3473. return 0;
  3474. }
  3475. // Allocate the interface.
  3476. cmTargetLinkInterface* iface = new cmTargetLinkInterface;
  3477. if(!iface)
  3478. {
  3479. return 0;
  3480. }
  3481. // Expand the list of libraries in the interface.
  3482. cmSystemTools::ExpandListArgument(libs, iface->Libraries);
  3483. // Now we need to construct a list of shared library dependencies
  3484. // not included in the interface.
  3485. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3486. {
  3487. // Use a set to keep track of what libraries have been emitted to
  3488. // either list.
  3489. std::set<cmStdString> emitted;
  3490. for(std::vector<std::string>::const_iterator
  3491. li = iface->Libraries.begin();
  3492. li != iface->Libraries.end(); ++li)
  3493. {
  3494. emitted.insert(*li);
  3495. }
  3496. // Compute which library configuration to link.
  3497. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  3498. // Construct the list of libs linked for this configuration.
  3499. cmTarget::LinkLibraryVectorType const& llibs =
  3500. this->GetOriginalLinkLibraries();
  3501. for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
  3502. li != llibs.end(); ++li)
  3503. {
  3504. // Skip entries that will resolve to the target itself, are empty,
  3505. // or are not meant for this configuration.
  3506. if(li->first == this->GetName() || li->first.empty() ||
  3507. !(li->second == cmTarget::GENERAL || li->second == linkType))
  3508. {
  3509. continue;
  3510. }
  3511. // Skip entries that have already been emitted into either list.
  3512. if(!emitted.insert(li->first).second)
  3513. {
  3514. continue;
  3515. }
  3516. // Add this entry if it is a shared library.
  3517. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->first.c_str()))
  3518. {
  3519. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  3520. {
  3521. iface->SharedDeps.push_back(li->first);
  3522. }
  3523. }
  3524. else
  3525. {
  3526. // TODO: Recognize shared library file names. Perhaps this
  3527. // should be moved to cmComputeLinkInformation, but that creates
  3528. // a chicken-and-egg problem since this list is needed for its
  3529. // construction.
  3530. }
  3531. }
  3532. }
  3533. // Return the completed interface.
  3534. return iface;
  3535. }
  3536. //----------------------------------------------------------------------------
  3537. cmComputeLinkInformation*
  3538. cmTarget::GetLinkInformation(const char* config)
  3539. {
  3540. // Lookup any existing information for this configuration.
  3541. std::map<cmStdString, cmComputeLinkInformation*>::iterator
  3542. i = this->LinkInformation.find(config?config:"");
  3543. if(i == this->LinkInformation.end())
  3544. {
  3545. // Compute information for this configuration.
  3546. cmComputeLinkInformation* info =
  3547. new cmComputeLinkInformation(this, config);
  3548. if(!info || !info->Compute())
  3549. {
  3550. delete info;
  3551. info = 0;
  3552. }
  3553. // Store the information for this configuration.
  3554. std::map<cmStdString, cmComputeLinkInformation*>::value_type
  3555. entry(config?config:"", info);
  3556. i = this->LinkInformation.insert(entry).first;
  3557. }
  3558. return i->second;
  3559. }
  3560. //----------------------------------------------------------------------------
  3561. cmTargetLinkInformationMap
  3562. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  3563. {
  3564. // Ideally cmTarget instances should never be copied. However until
  3565. // we can make a sweep to remove that, this copy constructor avoids
  3566. // allowing the resources (LinkInformation) from getting copied. In
  3567. // the worst case this will lead to extra cmComputeLinkInformation
  3568. // instances. We also enforce in debug mode that the map be emptied
  3569. // when copied.
  3570. static_cast<void>(r);
  3571. assert(r.empty());
  3572. }
  3573. //----------------------------------------------------------------------------
  3574. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  3575. {
  3576. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  3577. {
  3578. delete i->second;
  3579. }
  3580. }
  3581. //----------------------------------------------------------------------------
  3582. cmTargetLinkInterfaceMap
  3583. ::cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap const& r): derived()
  3584. {
  3585. // Ideally cmTarget instances should never be copied. However until
  3586. // we can make a sweep to remove that, this copy constructor avoids
  3587. // allowing the resources (LinkInterface) from getting copied. In
  3588. // the worst case this will lead to extra cmTargetLinkInterface
  3589. // instances. We also enforce in debug mode that the map be emptied
  3590. // when copied.
  3591. static_cast<void>(r);
  3592. assert(r.empty());
  3593. }
  3594. //----------------------------------------------------------------------------
  3595. cmTargetLinkInterfaceMap::~cmTargetLinkInterfaceMap()
  3596. {
  3597. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  3598. {
  3599. delete i->second;
  3600. }
  3601. }
  3602. //----------------------------------------------------------------------------
  3603. cmTargetInternalPointer::cmTargetInternalPointer()
  3604. {
  3605. this->Pointer = new cmTargetInternals;
  3606. }
  3607. //----------------------------------------------------------------------------
  3608. cmTargetInternalPointer
  3609. ::cmTargetInternalPointer(cmTargetInternalPointer const&)
  3610. {
  3611. // Ideally cmTarget instances should never be copied. However until
  3612. // we can make a sweep to remove that, this copy constructor avoids
  3613. // allowing the resources (Internals) to be copied.
  3614. this->Pointer = new cmTargetInternals;
  3615. }
  3616. //----------------------------------------------------------------------------
  3617. cmTargetInternalPointer::~cmTargetInternalPointer()
  3618. {
  3619. delete this->Pointer;
  3620. }
  3621. //----------------------------------------------------------------------------
  3622. cmTargetInternalPointer&
  3623. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  3624. {
  3625. if(this == &r) { return *this; } // avoid warning on HP about self check
  3626. // Ideally cmTarget instances should never be copied. However until
  3627. // we can make a sweep to remove that, this copy constructor avoids
  3628. // allowing the resources (Internals) to be copied.
  3629. cmTargetInternals* oldPointer = this->Pointer;
  3630. this->Pointer = new cmTargetInternals;
  3631. delete oldPointer;
  3632. return *this;
  3633. }