cmTarget.cxx 165 KB

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