cmTarget.cxx 163 KB

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