cmTarget.cxx 165 KB

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