cmTarget.cxx 172 KB

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