cmTarget.cxx 166 KB

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