cmTarget.cxx 133 KB

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