cmGeneratorTarget.cxx 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include <cmsys/hash_set.hxx>
  26. #define UNORDERED_SET cmsys::hash_set
  27. #else
  28. #define UNORDERED_SET std::set
  29. #endif
  30. class cmGeneratorTarget::TargetPropertyEntry {
  31. static cmLinkImplItem NoLinkImplItem;
  32. public:
  33. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  34. cmLinkImplItem const& item = NoLinkImplItem)
  35. : ge(cge), LinkImplItem(item)
  36. {}
  37. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  38. cmLinkImplItem const& LinkImplItem;
  39. };
  40. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  41. //----------------------------------------------------------------------------
  42. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  43. cmGeneratorTarget const* target, cmake *cm)
  44. {
  45. if(!badObjLib.empty())
  46. {
  47. std::ostringstream e;
  48. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  49. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  50. i != badObjLib.end(); ++i)
  51. {
  52. e << " " << (*i)->GetLocation().GetName() << "\n";
  53. }
  54. e << "but may contain only sources that compile, header files, and "
  55. "other files that would not affect linking of a normal library.";
  56. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  57. target->Target->GetBacktrace());
  58. }
  59. }
  60. struct ObjectSourcesTag {};
  61. struct CustomCommandsTag {};
  62. struct ExtraSourcesTag {};
  63. struct HeaderSourcesTag {};
  64. struct ExternalObjectsTag {};
  65. struct IDLSourcesTag {};
  66. struct ResxTag {};
  67. struct ModuleDefinitionFileTag {};
  68. struct AppManifestTag{};
  69. struct ManifestsTag{};
  70. struct CertificatesTag{};
  71. struct XamlTag{};
  72. template<typename Tag, typename OtherTag>
  73. struct IsSameTag
  74. {
  75. enum {
  76. Result = false
  77. };
  78. };
  79. template<typename Tag>
  80. struct IsSameTag<Tag, Tag>
  81. {
  82. enum {
  83. Result = true
  84. };
  85. };
  86. template<bool>
  87. struct DoAccept
  88. {
  89. template <typename T> static void Do(T&, cmSourceFile*) {}
  90. };
  91. template<>
  92. struct DoAccept<true>
  93. {
  94. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  95. {
  96. files.push_back(f);
  97. }
  98. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  99. {
  100. // Build and save the name of the corresponding .h file
  101. // This relationship will be used later when building the project files.
  102. // Both names would have been auto generated from Visual Studio
  103. // where the user supplied the file name and Visual Studio
  104. // appended the suffix.
  105. std::string resx = f->GetFullPath();
  106. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  107. data.ExpectedResxHeaders.insert(hFileName);
  108. data.ResxSources.push_back(f);
  109. }
  110. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  111. {
  112. // Build and save the name of the corresponding .h and .cpp file
  113. // This relationship will be used later when building the project files.
  114. // Both names would have been auto generated from Visual Studio
  115. // where the user supplied the file name and Visual Studio
  116. // appended the suffix.
  117. std::string xaml = f->GetFullPath();
  118. std::string hFileName = xaml + ".h";
  119. std::string cppFileName = xaml + ".cpp";
  120. data.ExpectedXamlHeaders.insert(hFileName);
  121. data.ExpectedXamlSources.insert(cppFileName);
  122. data.XamlSources.push_back(f);
  123. }
  124. static void Do(std::string& data, cmSourceFile* f)
  125. {
  126. data = f->GetFullPath();
  127. }
  128. };
  129. //----------------------------------------------------------------------------
  130. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  131. struct TagVisitor
  132. {
  133. DataType& Data;
  134. std::vector<cmSourceFile*> BadObjLibFiles;
  135. cmGeneratorTarget const* Target;
  136. cmGlobalGenerator *GlobalGenerator;
  137. cmsys::RegularExpression Header;
  138. bool IsObjLib;
  139. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  140. : Data(data), Target(target),
  141. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  142. Header(CM_HEADER_REGEX),
  143. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  144. {
  145. }
  146. ~TagVisitor()
  147. {
  148. reportBadObjLib(this->BadObjLibFiles, this->Target,
  149. this->GlobalGenerator->GetCMakeInstance());
  150. }
  151. void Accept(cmSourceFile *sf)
  152. {
  153. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  154. if(sf->GetCustomCommand())
  155. {
  156. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  157. }
  158. else if(this->Target->GetType() == cmTarget::UTILITY)
  159. {
  160. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  161. }
  162. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  163. {
  164. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  165. }
  166. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  167. {
  168. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  169. if(this->IsObjLib)
  170. {
  171. this->BadObjLibFiles.push_back(sf);
  172. }
  173. }
  174. else if(!sf->GetLanguage().empty())
  175. {
  176. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  177. }
  178. else if(ext == "def")
  179. {
  180. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  181. sf);
  182. if(this->IsObjLib)
  183. {
  184. this->BadObjLibFiles.push_back(sf);
  185. }
  186. }
  187. else if(ext == "idl")
  188. {
  189. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  190. if(this->IsObjLib)
  191. {
  192. this->BadObjLibFiles.push_back(sf);
  193. }
  194. }
  195. else if(ext == "resx")
  196. {
  197. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  198. }
  199. else if (ext == "appxmanifest")
  200. {
  201. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  202. }
  203. else if (ext == "manifest")
  204. {
  205. DoAccept<IsSameTag<Tag, ManifestsTag>::Result>::Do(this->Data, sf);
  206. }
  207. else if (ext == "pfx")
  208. {
  209. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  210. }
  211. else if (ext == "xaml")
  212. {
  213. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  214. }
  215. else if(this->Header.find(sf->GetFullPath().c_str()))
  216. {
  217. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  218. }
  219. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  220. {
  221. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  222. }
  223. else
  224. {
  225. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  226. }
  227. }
  228. };
  229. void CreatePropertyGeneratorExpressions(
  230. cmStringRange const& entries,
  231. cmBacktraceRange const& backtraces,
  232. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  233. bool evaluateForBuildsystem = false)
  234. {
  235. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  236. for (std::vector<std::string>::const_iterator it = entries.begin();
  237. it != entries.end(); ++it, ++btIt)
  238. {
  239. cmGeneratorExpression ge(*btIt);
  240. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  241. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  242. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  243. }
  244. }
  245. //----------------------------------------------------------------------------
  246. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  247. : Target(t),
  248. SourceFileFlagsConstructed(false),
  249. PolicyWarnedCMP0022(false),
  250. DebugIncludesDone(false),
  251. DebugCompileOptionsDone(false),
  252. DebugCompileFeaturesDone(false),
  253. DebugCompileDefinitionsDone(false)
  254. {
  255. this->Makefile = this->Target->GetMakefile();
  256. this->LocalGenerator = lg;
  257. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  258. CreatePropertyGeneratorExpressions(
  259. t->GetIncludeDirectoriesEntries(),
  260. t->GetIncludeDirectoriesBacktraces(),
  261. this->IncludeDirectoriesEntries);
  262. CreatePropertyGeneratorExpressions(
  263. t->GetCompileOptionsEntries(),
  264. t->GetCompileOptionsBacktraces(),
  265. this->CompileOptionsEntries);
  266. CreatePropertyGeneratorExpressions(
  267. t->GetCompileFeaturesEntries(),
  268. t->GetCompileFeaturesBacktraces(),
  269. this->CompileFeaturesEntries);
  270. CreatePropertyGeneratorExpressions(
  271. t->GetCompileDefinitionsEntries(),
  272. t->GetCompileDefinitionsBacktraces(),
  273. this->CompileDefinitionsEntries);
  274. }
  275. cmGeneratorTarget::~cmGeneratorTarget()
  276. {
  277. cmDeleteAll(this->IncludeDirectoriesEntries);
  278. cmDeleteAll(this->CompileOptionsEntries);
  279. cmDeleteAll(this->CompileFeaturesEntries);
  280. cmDeleteAll(this->CompileDefinitionsEntries);
  281. cmDeleteAll(this->LinkInformation);
  282. this->LinkInformation.clear();
  283. }
  284. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  285. {
  286. return this->LocalGenerator;
  287. }
  288. //----------------------------------------------------------------------------
  289. int cmGeneratorTarget::GetType() const
  290. {
  291. return this->Target->GetType();
  292. }
  293. //----------------------------------------------------------------------------
  294. std::string cmGeneratorTarget::GetName() const
  295. {
  296. return this->Target->GetName();
  297. }
  298. //----------------------------------------------------------------------------
  299. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  300. {
  301. return this->Target->GetProperty(prop);
  302. }
  303. //----------------------------------------------------------------------------
  304. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  305. bool implib) const
  306. {
  307. // Lookup/compute/cache the output name for this configuration.
  308. OutputNameKey key(config, implib);
  309. cmGeneratorTarget::OutputNameMapType::iterator i =
  310. this->OutputNameMap.find(key);
  311. if(i == this->OutputNameMap.end())
  312. {
  313. // Add empty name in map to detect potential recursion.
  314. OutputNameMapType::value_type entry(key, "");
  315. i = this->OutputNameMap.insert(entry).first;
  316. // Compute output name.
  317. std::vector<std::string> props;
  318. std::string type = this->Target->GetOutputTargetType(implib);
  319. std::string configUpper = cmSystemTools::UpperCase(config);
  320. if(!type.empty() && !configUpper.empty())
  321. {
  322. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  323. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  324. }
  325. if(!type.empty())
  326. {
  327. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  328. props.push_back(type + "_OUTPUT_NAME");
  329. }
  330. if(!configUpper.empty())
  331. {
  332. // OUTPUT_NAME_<CONFIG>
  333. props.push_back("OUTPUT_NAME_" + configUpper);
  334. // <CONFIG>_OUTPUT_NAME
  335. props.push_back(configUpper + "_OUTPUT_NAME");
  336. }
  337. // OUTPUT_NAME
  338. props.push_back("OUTPUT_NAME");
  339. std::string outName;
  340. for(std::vector<std::string>::const_iterator it = props.begin();
  341. it != props.end(); ++it)
  342. {
  343. if (const char* outNameProp = this->Target->GetProperty(*it))
  344. {
  345. outName = outNameProp;
  346. break;
  347. }
  348. }
  349. if(outName.empty())
  350. {
  351. outName = this->GetName();
  352. }
  353. // Now evaluate genex and update the previously-prepared map entry.
  354. cmGeneratorExpression ge;
  355. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  356. i->second = cge->Evaluate(this->Makefile, config);
  357. }
  358. else if(i->second.empty())
  359. {
  360. // An empty map entry indicates we have been called recursively
  361. // from the above block.
  362. this->Makefile->GetCMakeInstance()->IssueMessage(
  363. cmake::FATAL_ERROR,
  364. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  365. this->Target->GetBacktrace());
  366. }
  367. return i->second;
  368. }
  369. //----------------------------------------------------------------------------
  370. std::vector<cmSourceFile*> const*
  371. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  372. {
  373. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  374. if(i != this->SourceEntries.end())
  375. {
  376. return &i->second.Depends;
  377. }
  378. return 0;
  379. }
  380. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  381. const std::string& config,
  382. cmTarget *headTarget,
  383. cmGeneratorExpressionDAGChecker *dagChecker,
  384. std::vector<std::string>& result,
  385. bool excludeImported)
  386. {
  387. if (const char* dirs =
  388. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  389. {
  390. cmGeneratorExpression ge;
  391. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  392. ->Evaluate(mf,
  393. config, false, headTarget,
  394. depTgt, dagChecker), result);
  395. }
  396. if (!depTgt->IsImported() || excludeImported)
  397. {
  398. return;
  399. }
  400. if (const char* dirs =
  401. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  402. {
  403. cmGeneratorExpression ge;
  404. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  405. ->Evaluate(mf,
  406. config, false, headTarget,
  407. depTgt, dagChecker), result);
  408. }
  409. }
  410. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  411. { \
  412. std::vector<cmSourceFile*> sourceFiles; \
  413. this->Target->GetSourceFiles(sourceFiles, config); \
  414. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  415. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  416. si != sourceFiles.end(); ++si) \
  417. { \
  418. visitor.Accept(*si); \
  419. } \
  420. } \
  421. #define IMPLEMENT_VISIT(DATA) \
  422. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  423. #define EMPTY
  424. #define COMMA ,
  425. //----------------------------------------------------------------------------
  426. void
  427. cmGeneratorTarget
  428. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  429. const std::string& config) const
  430. {
  431. IMPLEMENT_VISIT(ObjectSources);
  432. if (!this->Objects.empty())
  433. {
  434. return;
  435. }
  436. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  437. it != data.end(); ++it)
  438. {
  439. this->Objects[*it];
  440. }
  441. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  442. }
  443. void cmGeneratorTarget::ComputeObjectMapping()
  444. {
  445. if(!this->Objects.empty())
  446. {
  447. return;
  448. }
  449. std::vector<std::string> configs;
  450. this->Makefile->GetConfigurations(configs);
  451. if (configs.empty())
  452. {
  453. configs.push_back("");
  454. }
  455. for(std::vector<std::string>::const_iterator ci = configs.begin();
  456. ci != configs.end(); ++ci)
  457. {
  458. std::vector<cmSourceFile const*> sourceFiles;
  459. this->GetObjectSources(sourceFiles, *ci);
  460. }
  461. }
  462. //----------------------------------------------------------------------------
  463. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  464. const std::string& config) const
  465. {
  466. if(!config.empty())
  467. {
  468. std::string featureConfig = feature;
  469. featureConfig += "_";
  470. featureConfig += cmSystemTools::UpperCase(config);
  471. if(const char* value = this->Target->GetProperty(featureConfig))
  472. {
  473. return value;
  474. }
  475. }
  476. if(const char* value = this->Target->GetProperty(feature))
  477. {
  478. return value;
  479. }
  480. return this->LocalGenerator->GetFeature(feature, config);
  481. }
  482. //----------------------------------------------------------------------------
  483. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  484. const std::string& config) const
  485. {
  486. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  487. }
  488. //----------------------------------------------------------------------------
  489. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  490. {
  491. this->ComputeObjectMapping();
  492. return this->Objects[file];
  493. }
  494. //----------------------------------------------------------------------------
  495. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  496. {
  497. this->ExplicitObjectName.insert(sf);
  498. }
  499. //----------------------------------------------------------------------------
  500. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  501. {
  502. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  503. std::set<cmSourceFile const*>::const_iterator it
  504. = this->ExplicitObjectName.find(file);
  505. return it != this->ExplicitObjectName.end();
  506. }
  507. //----------------------------------------------------------------------------
  508. void cmGeneratorTarget
  509. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  510. const std::string& config) const
  511. {
  512. IMPLEMENT_VISIT(IDLSources);
  513. }
  514. //----------------------------------------------------------------------------
  515. void
  516. cmGeneratorTarget
  517. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  518. const std::string& config) const
  519. {
  520. IMPLEMENT_VISIT(HeaderSources);
  521. }
  522. //----------------------------------------------------------------------------
  523. void cmGeneratorTarget
  524. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  525. const std::string& config) const
  526. {
  527. IMPLEMENT_VISIT(ExtraSources);
  528. }
  529. //----------------------------------------------------------------------------
  530. void
  531. cmGeneratorTarget
  532. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  533. const std::string& config) const
  534. {
  535. IMPLEMENT_VISIT(CustomCommands);
  536. }
  537. //----------------------------------------------------------------------------
  538. void
  539. cmGeneratorTarget
  540. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  541. const std::string& config) const
  542. {
  543. IMPLEMENT_VISIT(ExternalObjects);
  544. }
  545. //----------------------------------------------------------------------------
  546. void
  547. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  548. const std::string& config) const
  549. {
  550. ResxData data;
  551. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  552. srcs = data.ExpectedResxHeaders;
  553. }
  554. //----------------------------------------------------------------------------
  555. void cmGeneratorTarget
  556. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  557. const std::string& config) const
  558. {
  559. ResxData data;
  560. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  561. srcs = data.ResxSources;
  562. }
  563. //----------------------------------------------------------------------------
  564. void
  565. cmGeneratorTarget
  566. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  567. const std::string& config) const
  568. {
  569. IMPLEMENT_VISIT(AppManifest);
  570. }
  571. //----------------------------------------------------------------------------
  572. void
  573. cmGeneratorTarget
  574. ::GetManifests(std::vector<cmSourceFile const*>& data,
  575. const std::string& config) const
  576. {
  577. IMPLEMENT_VISIT(Manifests);
  578. }
  579. //----------------------------------------------------------------------------
  580. void
  581. cmGeneratorTarget
  582. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  583. const std::string& config) const
  584. {
  585. IMPLEMENT_VISIT(Certificates);
  586. }
  587. //----------------------------------------------------------------------------
  588. void
  589. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  590. const std::string& config) const
  591. {
  592. XamlData data;
  593. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  594. headers = data.ExpectedXamlHeaders;
  595. }
  596. //----------------------------------------------------------------------------
  597. void
  598. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  599. const std::string& config) const
  600. {
  601. XamlData data;
  602. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  603. srcs = data.ExpectedXamlSources;
  604. }
  605. //----------------------------------------------------------------------------
  606. void cmGeneratorTarget
  607. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  608. const std::string& config) const
  609. {
  610. XamlData data;
  611. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  612. srcs = data.XamlSources;
  613. }
  614. //----------------------------------------------------------------------------
  615. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  616. {
  617. static std::string location;
  618. if (this->Target->IsImported())
  619. {
  620. location = this->Target->ImportedGetFullPath(config, false);
  621. }
  622. else
  623. {
  624. location = this->GetFullPath(config, false);
  625. }
  626. return location.c_str();
  627. }
  628. bool cmGeneratorTarget::IsImported() const
  629. {
  630. return this->Target->IsImported();
  631. }
  632. //----------------------------------------------------------------------------
  633. const char* cmGeneratorTarget::GetLocationForBuild() const
  634. {
  635. static std::string location;
  636. if(this->IsImported())
  637. {
  638. location = this->Target->ImportedGetFullPath("", false);
  639. return location.c_str();
  640. }
  641. // Now handle the deprecated build-time configuration location.
  642. location = this->Target->GetDirectory();
  643. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  644. if(cfgid && strcmp(cfgid, ".") != 0)
  645. {
  646. location += "/";
  647. location += cfgid;
  648. }
  649. if(this->Target->IsAppBundleOnApple())
  650. {
  651. std::string macdir = this->BuildMacContentDirectory("", "",
  652. false);
  653. if(!macdir.empty())
  654. {
  655. location += "/";
  656. location += macdir;
  657. }
  658. }
  659. location += "/";
  660. location += this->GetFullName("", false);
  661. return location.c_str();
  662. }
  663. //----------------------------------------------------------------------------
  664. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  665. const std::string& config) const
  666. {
  667. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  668. std::string config_upper;
  669. if(!config.empty())
  670. {
  671. config_upper = cmSystemTools::UpperCase(config);
  672. }
  673. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  674. IncludeCacheType::const_iterator iter =
  675. this->SystemIncludesCache.find(config_upper);
  676. if (iter == this->SystemIncludesCache.end())
  677. {
  678. cmGeneratorExpressionDAGChecker dagChecker(
  679. this->GetName(),
  680. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  681. bool excludeImported
  682. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  683. std::vector<std::string> result;
  684. for (std::set<std::string>::const_iterator
  685. it = this->Target->GetSystemIncludeDirectories().begin();
  686. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  687. {
  688. cmGeneratorExpression ge;
  689. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  690. ->Evaluate(this->Makefile,
  691. config, false, this->Target,
  692. &dagChecker), result);
  693. }
  694. std::vector<cmTarget const*> const& deps =
  695. this->GetLinkImplementationClosure(config);
  696. for(std::vector<cmTarget const*>::const_iterator
  697. li = deps.begin(), le = deps.end(); li != le; ++li)
  698. {
  699. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  700. &dagChecker, result, excludeImported);
  701. }
  702. std::set<std::string> unique;
  703. for(std::vector<std::string>::iterator li = result.begin();
  704. li != result.end(); ++li)
  705. {
  706. cmSystemTools::ConvertToUnixSlashes(*li);
  707. unique.insert(*li);
  708. }
  709. result.clear();
  710. result.insert(result.end(), unique.begin(), unique.end());
  711. IncludeCacheType::value_type entry(config_upper, result);
  712. iter = this->SystemIncludesCache.insert(entry).first;
  713. }
  714. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  715. }
  716. //----------------------------------------------------------------------------
  717. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  718. {
  719. return this->Target->GetPropertyAsBool(prop);
  720. }
  721. //----------------------------------------------------------------------------
  722. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  723. const std::string& config) const
  724. {
  725. this->Target->GetSourceFiles(files, config);
  726. }
  727. //----------------------------------------------------------------------------
  728. std::string
  729. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  730. {
  731. std::string prefix;
  732. std::string base;
  733. std::string suffix;
  734. this->GetFullNameInternal(config, false, prefix, base, suffix);
  735. // Check for a per-configuration output directory target property.
  736. std::string configUpper = cmSystemTools::UpperCase(config);
  737. std::string configProp = "COMPILE_PDB_NAME_";
  738. configProp += configUpper;
  739. const char* config_name = this->Target->GetProperty(configProp);
  740. if(config_name && *config_name)
  741. {
  742. return prefix + config_name + ".pdb";
  743. }
  744. const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
  745. if(name && *name)
  746. {
  747. return prefix + name + ".pdb";
  748. }
  749. return "";
  750. }
  751. //----------------------------------------------------------------------------
  752. std::string
  753. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  754. {
  755. std::string dir = this->GetCompilePDBDirectory(config);
  756. std::string name = this->GetCompilePDBName(config);
  757. if(dir.empty() && !name.empty())
  758. {
  759. dir = this->Target->GetPDBDirectory(config);
  760. }
  761. if(!dir.empty())
  762. {
  763. dir += "/";
  764. }
  765. return dir + name;
  766. }
  767. //----------------------------------------------------------------------------
  768. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  769. {
  770. // soname is supported only for shared libraries and modules,
  771. // and then only when the platform supports an soname flag.
  772. return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
  773. !this->GetPropertyAsBool("NO_SONAME") &&
  774. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  775. }
  776. //----------------------------------------------------------------------------
  777. bool
  778. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  779. {
  780. // Only executables and shared libraries can have an rpath and may
  781. // need relinking.
  782. if(this->GetType() != cmTarget::EXECUTABLE &&
  783. this->GetType() != cmTarget::SHARED_LIBRARY &&
  784. this->GetType() != cmTarget::MODULE_LIBRARY)
  785. {
  786. return false;
  787. }
  788. // If there is no install location this target will not be installed
  789. // and therefore does not need relinking.
  790. if(!this->Target->GetHaveInstallRule())
  791. {
  792. return false;
  793. }
  794. // If skipping all rpaths completely then no relinking is needed.
  795. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  796. {
  797. return false;
  798. }
  799. // If building with the install-tree rpath no relinking is needed.
  800. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  801. {
  802. return false;
  803. }
  804. // If chrpath is going to be used no relinking is needed.
  805. if(this->IsChrpathUsed(config))
  806. {
  807. return false;
  808. }
  809. // Check for rpath support on this platform.
  810. std::string ll = this->GetLinkerLanguage(config);
  811. if(!ll.empty())
  812. {
  813. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  814. flagVar += ll;
  815. flagVar += "_FLAG";
  816. if(!this->Makefile->IsSet(flagVar))
  817. {
  818. // There is no rpath support on this platform so nothing needs
  819. // relinking.
  820. return false;
  821. }
  822. }
  823. else
  824. {
  825. // No linker language is known. This error will be reported by
  826. // other code.
  827. return false;
  828. }
  829. // If either a build or install tree rpath is set then the rpath
  830. // will likely change between the build tree and install tree and
  831. // this target must be relinked.
  832. return this->HaveBuildTreeRPATH(config)
  833. || this->Target->HaveInstallTreeRPATH();
  834. }
  835. //----------------------------------------------------------------------------
  836. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  837. {
  838. // Only certain target types have an rpath.
  839. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  840. this->GetType() == cmTarget::MODULE_LIBRARY ||
  841. this->GetType() == cmTarget::EXECUTABLE))
  842. {
  843. return false;
  844. }
  845. // If the target will not be installed we do not need to change its
  846. // rpath.
  847. if(!this->Target->GetHaveInstallRule())
  848. {
  849. return false;
  850. }
  851. // Skip chrpath if skipping rpath altogether.
  852. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  853. {
  854. return false;
  855. }
  856. // Skip chrpath if it does not need to be changed at install time.
  857. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  858. {
  859. return false;
  860. }
  861. // Allow the user to disable builtin chrpath explicitly.
  862. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  863. {
  864. return false;
  865. }
  866. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  867. {
  868. return true;
  869. }
  870. #if defined(CMAKE_USE_ELF_PARSER)
  871. // Enable if the rpath flag uses a separator and the target uses ELF
  872. // binaries.
  873. std::string ll = this->GetLinkerLanguage(config);
  874. if(!ll.empty())
  875. {
  876. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  877. sepVar += ll;
  878. sepVar += "_FLAG_SEP";
  879. const char* sep = this->Makefile->GetDefinition(sepVar);
  880. if(sep && *sep)
  881. {
  882. // TODO: Add ELF check to ABI detection and get rid of
  883. // CMAKE_EXECUTABLE_FORMAT.
  884. if(const char* fmt =
  885. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  886. {
  887. return strcmp(fmt, "ELF") == 0;
  888. }
  889. }
  890. }
  891. #endif
  892. static_cast<void>(config);
  893. return false;
  894. }
  895. //----------------------------------------------------------------------------
  896. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  897. {
  898. if(this->Target->IsImported())
  899. {
  900. // Lookup the imported soname.
  901. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  902. {
  903. if(info->NoSOName)
  904. {
  905. // The imported library has no builtin soname so the name
  906. // searched at runtime will be just the filename.
  907. return cmSystemTools::GetFilenameName(info->Location);
  908. }
  909. else
  910. {
  911. // Use the soname given if any.
  912. if(info->SOName.find("@rpath/") == 0)
  913. {
  914. return info->SOName.substr(6);
  915. }
  916. return info->SOName;
  917. }
  918. }
  919. else
  920. {
  921. return "";
  922. }
  923. }
  924. else
  925. {
  926. // Compute the soname that will be built.
  927. std::string name;
  928. std::string soName;
  929. std::string realName;
  930. std::string impName;
  931. std::string pdbName;
  932. this->GetLibraryNames(name, soName, realName,
  933. impName, pdbName, config);
  934. return soName;
  935. }
  936. }
  937. //----------------------------------------------------------------------------
  938. std::string
  939. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  940. bool contentOnly) const
  941. {
  942. std::string fpath = this->GetFullName(config, false);
  943. fpath += ".app";
  944. if(!this->Makefile->PlatformIsAppleIos())
  945. {
  946. fpath += "/Contents";
  947. if(!contentOnly)
  948. fpath += "/MacOS";
  949. }
  950. return fpath;
  951. }
  952. //----------------------------------------------------------------------------
  953. bool cmGeneratorTarget::IsBundleOnApple() const
  954. {
  955. return this->Target->IsFrameworkOnApple()
  956. || this->Target->IsAppBundleOnApple()
  957. || this->Target->IsCFBundleOnApple();
  958. }
  959. //----------------------------------------------------------------------------
  960. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  961. bool contentOnly) const
  962. {
  963. std::string fpath;
  964. fpath += this->GetOutputName(config, false);
  965. fpath += ".";
  966. const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
  967. if (!ext)
  968. {
  969. if (this->Target->IsXCTestOnApple())
  970. {
  971. ext = "xctest";
  972. }
  973. else
  974. {
  975. ext = "bundle";
  976. }
  977. }
  978. fpath += ext;
  979. if(!this->Makefile->PlatformIsAppleIos())
  980. {
  981. fpath += "/Contents";
  982. if(!contentOnly)
  983. fpath += "/MacOS";
  984. }
  985. return fpath;
  986. }
  987. //----------------------------------------------------------------------------
  988. std::string
  989. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  990. bool rootDir) const
  991. {
  992. std::string fpath;
  993. fpath += this->GetOutputName(config, false);
  994. fpath += ".framework";
  995. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  996. {
  997. fpath += "/Versions/";
  998. fpath += this->Target->GetFrameworkVersion();
  999. }
  1000. return fpath;
  1001. }
  1002. //----------------------------------------------------------------------------
  1003. std::string
  1004. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  1005. {
  1006. if(this->Target->IsImported())
  1007. {
  1008. return this->Target->GetFullNameImported(config, implib);
  1009. }
  1010. else
  1011. {
  1012. return this->GetFullNameInternal(config, implib);
  1013. }
  1014. }
  1015. //----------------------------------------------------------------------------
  1016. std::string
  1017. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1018. const std::string& config) const
  1019. {
  1020. // If building directly for installation then the build tree install_name
  1021. // is the same as the install tree.
  1022. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1023. {
  1024. return this->GetInstallNameDirForInstallTree();
  1025. }
  1026. // Use the build tree directory for the target.
  1027. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1028. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1029. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  1030. {
  1031. std::string dir;
  1032. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1033. {
  1034. dir = "@rpath";
  1035. }
  1036. else
  1037. {
  1038. dir = this->Target->GetDirectory(config);
  1039. }
  1040. dir += "/";
  1041. return dir;
  1042. }
  1043. else
  1044. {
  1045. return "";
  1046. }
  1047. }
  1048. //----------------------------------------------------------------------------
  1049. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1050. {
  1051. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1052. {
  1053. std::string dir;
  1054. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1055. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1056. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  1057. {
  1058. if(install_name_dir && *install_name_dir)
  1059. {
  1060. dir = install_name_dir;
  1061. dir += "/";
  1062. }
  1063. }
  1064. if(!install_name_dir)
  1065. {
  1066. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1067. {
  1068. dir = "@rpath/";
  1069. }
  1070. }
  1071. return dir;
  1072. }
  1073. else
  1074. {
  1075. return "";
  1076. }
  1077. }
  1078. //----------------------------------------------------------------------------
  1079. class cmTargetCollectLinkLanguages
  1080. {
  1081. public:
  1082. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1083. const std::string& config,
  1084. UNORDERED_SET<std::string>& languages,
  1085. cmTarget const* head):
  1086. Config(config), Languages(languages), HeadTarget(head),
  1087. Makefile(target->Target->GetMakefile()), Target(target)
  1088. { this->Visited.insert(target->Target); }
  1089. void Visit(cmLinkItem const& item)
  1090. {
  1091. if(!item.Target)
  1092. {
  1093. if(item.find("::") != std::string::npos)
  1094. {
  1095. bool noMessage = false;
  1096. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1097. std::stringstream e;
  1098. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1099. {
  1100. case cmPolicies::WARN:
  1101. {
  1102. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1103. messageType = cmake::AUTHOR_WARNING;
  1104. }
  1105. break;
  1106. case cmPolicies::OLD:
  1107. noMessage = true;
  1108. case cmPolicies::REQUIRED_IF_USED:
  1109. case cmPolicies::REQUIRED_ALWAYS:
  1110. case cmPolicies::NEW:
  1111. // Issue the fatal message.
  1112. break;
  1113. }
  1114. if(!noMessage)
  1115. {
  1116. e << "Target \"" << this->Target->GetName()
  1117. << "\" links to target \"" << item
  1118. << "\" but the target was not found. Perhaps a find_package() "
  1119. "call is missing for an IMPORTED target, or an ALIAS target is "
  1120. "missing?";
  1121. this->Makefile->GetCMakeInstance()->IssueMessage(
  1122. messageType, e.str(), this->Target->Target->GetBacktrace());
  1123. }
  1124. }
  1125. return;
  1126. }
  1127. if(!this->Visited.insert(item.Target).second)
  1128. {
  1129. return;
  1130. }
  1131. cmGeneratorTarget* gtgt =
  1132. this->Target->GetLocalGenerator()->GetGlobalGenerator()
  1133. ->GetGeneratorTarget(item.Target);
  1134. cmLinkInterface const* iface =
  1135. gtgt->GetLinkInterface(this->Config, this->HeadTarget);
  1136. if(!iface) { return; }
  1137. for(std::vector<std::string>::const_iterator
  1138. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1139. {
  1140. this->Languages.insert(*li);
  1141. }
  1142. for(std::vector<cmLinkItem>::const_iterator
  1143. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1144. {
  1145. this->Visit(*li);
  1146. }
  1147. }
  1148. private:
  1149. std::string Config;
  1150. UNORDERED_SET<std::string>& Languages;
  1151. cmTarget const* HeadTarget;
  1152. cmMakefile* Makefile;
  1153. const cmGeneratorTarget* Target;
  1154. std::set<cmTarget const*> Visited;
  1155. };
  1156. //----------------------------------------------------------------------------
  1157. cmGeneratorTarget::LinkClosure const*
  1158. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1159. {
  1160. std::string key(cmSystemTools::UpperCase(config));
  1161. LinkClosureMapType::iterator
  1162. i = this->LinkClosureMap.find(key);
  1163. if(i == this->LinkClosureMap.end())
  1164. {
  1165. LinkClosure lc;
  1166. this->ComputeLinkClosure(config, lc);
  1167. LinkClosureMapType::value_type entry(key, lc);
  1168. i = this->LinkClosureMap.insert(entry).first;
  1169. }
  1170. return &i->second;
  1171. }
  1172. //----------------------------------------------------------------------------
  1173. class cmTargetSelectLinker
  1174. {
  1175. int Preference;
  1176. cmGeneratorTarget const* Target;
  1177. cmMakefile* Makefile;
  1178. cmGlobalGenerator* GG;
  1179. std::set<std::string> Preferred;
  1180. public:
  1181. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1182. : Preference(0), Target(target)
  1183. {
  1184. this->Makefile = this->Target->Makefile;
  1185. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1186. }
  1187. void Consider(const char* lang)
  1188. {
  1189. int preference = this->GG->GetLinkerPreference(lang);
  1190. if(preference > this->Preference)
  1191. {
  1192. this->Preference = preference;
  1193. this->Preferred.clear();
  1194. }
  1195. if(preference == this->Preference)
  1196. {
  1197. this->Preferred.insert(lang);
  1198. }
  1199. }
  1200. std::string Choose()
  1201. {
  1202. if(this->Preferred.empty())
  1203. {
  1204. return "";
  1205. }
  1206. else if(this->Preferred.size() > 1)
  1207. {
  1208. std::stringstream e;
  1209. e << "Target " << this->Target->GetName()
  1210. << " contains multiple languages with the highest linker preference"
  1211. << " (" << this->Preference << "):\n";
  1212. for(std::set<std::string>::const_iterator
  1213. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1214. {
  1215. e << " " << *li << "\n";
  1216. }
  1217. e << "Set the LINKER_LANGUAGE property for this target.";
  1218. cmake* cm = this->Makefile->GetCMakeInstance();
  1219. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1220. this->Target->Target->GetBacktrace());
  1221. }
  1222. return *this->Preferred.begin();
  1223. }
  1224. };
  1225. //----------------------------------------------------------------------------
  1226. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1227. LinkClosure& lc) const
  1228. {
  1229. // Get languages built in this target.
  1230. UNORDERED_SET<std::string> languages;
  1231. cmLinkImplementation const* impl =
  1232. this->GetLinkImplementation(config);
  1233. assert(impl);
  1234. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1235. li != impl->Languages.end(); ++li)
  1236. {
  1237. languages.insert(*li);
  1238. }
  1239. // Add interface languages from linked targets.
  1240. cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
  1241. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1242. li != impl->Libraries.end(); ++li)
  1243. {
  1244. cll.Visit(*li);
  1245. }
  1246. // Store the transitive closure of languages.
  1247. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1248. li != languages.end(); ++li)
  1249. {
  1250. lc.Languages.push_back(*li);
  1251. }
  1252. // Choose the language whose linker should be used.
  1253. if(this->GetProperty("HAS_CXX"))
  1254. {
  1255. lc.LinkerLanguage = "CXX";
  1256. }
  1257. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1258. {
  1259. lc.LinkerLanguage = linkerLang;
  1260. }
  1261. else
  1262. {
  1263. // Find the language with the highest preference value.
  1264. cmTargetSelectLinker tsl(this);
  1265. // First select from the languages compiled directly in this target.
  1266. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1267. li != impl->Languages.end(); ++li)
  1268. {
  1269. tsl.Consider(li->c_str());
  1270. }
  1271. // Now consider languages that propagate from linked targets.
  1272. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1273. sit != languages.end(); ++sit)
  1274. {
  1275. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1276. if(this->Makefile->IsOn(propagates))
  1277. {
  1278. tsl.Consider(sit->c_str());
  1279. }
  1280. }
  1281. lc.LinkerLanguage = tsl.Choose();
  1282. }
  1283. }
  1284. //----------------------------------------------------------------------------
  1285. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1286. std::string& base,
  1287. std::string& suffix,
  1288. const std::string& config,
  1289. bool implib) const
  1290. {
  1291. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1292. }
  1293. //----------------------------------------------------------------------------
  1294. std::string
  1295. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1296. const std::string& config,
  1297. bool contentOnly) const
  1298. {
  1299. std::string fpath = base;
  1300. if(this->Target->IsAppBundleOnApple())
  1301. {
  1302. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1303. }
  1304. if(this->Target->IsFrameworkOnApple())
  1305. {
  1306. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1307. }
  1308. if(this->Target->IsCFBundleOnApple())
  1309. {
  1310. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1311. }
  1312. return fpath;
  1313. }
  1314. //----------------------------------------------------------------------------
  1315. std::string
  1316. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1317. bool implib) const
  1318. {
  1319. // Start with the output directory for the target.
  1320. std::string fpath = this->Target->GetDirectory(config, implib);
  1321. fpath += "/";
  1322. bool contentOnly = true;
  1323. if(this->Target->IsFrameworkOnApple())
  1324. {
  1325. // additional files with a framework go into the version specific
  1326. // directory
  1327. contentOnly = false;
  1328. }
  1329. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1330. return fpath;
  1331. }
  1332. //----------------------------------------------------------------------------
  1333. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1334. const std::string& config) const
  1335. {
  1336. // There is no compile information for imported targets.
  1337. if(this->IsImported())
  1338. {
  1339. return 0;
  1340. }
  1341. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  1342. {
  1343. std::string msg = "cmTarget::GetCompileInfo called for ";
  1344. msg += this->GetName();
  1345. msg += " which has type ";
  1346. msg += cmTarget::GetTargetTypeName(this->Target->GetType());
  1347. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1348. return 0;
  1349. }
  1350. // Lookup/compute/cache the compile information for this configuration.
  1351. std::string config_upper;
  1352. if(!config.empty())
  1353. {
  1354. config_upper = cmSystemTools::UpperCase(config);
  1355. }
  1356. CompileInfoMapType::const_iterator i =
  1357. this->CompileInfoMap.find(config_upper);
  1358. if(i == this->CompileInfoMap.end())
  1359. {
  1360. CompileInfo info;
  1361. this->Target
  1362. ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1363. CompileInfoMapType::value_type entry(config_upper, info);
  1364. i = this->CompileInfoMap.insert(entry).first;
  1365. }
  1366. return &i->second;
  1367. }
  1368. //----------------------------------------------------------------------------
  1369. std::string
  1370. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1371. {
  1372. std::string data;
  1373. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1374. return data;
  1375. }
  1376. //----------------------------------------------------------------------------
  1377. void
  1378. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1379. const std::string &config) const
  1380. {
  1381. std::vector<cmSourceFile const*> objectFiles;
  1382. this->GetExternalObjects(objectFiles, config);
  1383. std::vector<cmTarget*> objectLibraries;
  1384. for(std::vector<cmSourceFile const*>::const_iterator
  1385. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1386. {
  1387. std::string objLib = (*it)->GetObjectLibrary();
  1388. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  1389. {
  1390. objectLibraries.push_back(tgt);
  1391. }
  1392. }
  1393. std::vector<cmTarget*>::const_iterator end
  1394. = cmRemoveDuplicates(objectLibraries);
  1395. for(std::vector<cmTarget*>::const_iterator
  1396. ti = objectLibraries.begin();
  1397. ti != end; ++ti)
  1398. {
  1399. cmTarget* objLib = *ti;
  1400. cmGeneratorTarget* ogt =
  1401. this->GlobalGenerator->GetGeneratorTarget(objLib);
  1402. std::vector<cmSourceFile const*> objectSources;
  1403. ogt->GetObjectSources(objectSources, config);
  1404. for(std::vector<cmSourceFile const*>::const_iterator
  1405. si = objectSources.begin();
  1406. si != objectSources.end(); ++si)
  1407. {
  1408. std::string obj = ogt->ObjectDirectory;
  1409. obj += ogt->Objects[*si];
  1410. objs.push_back(obj);
  1411. }
  1412. }
  1413. }
  1414. //----------------------------------------------------------------------------
  1415. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1416. const std::string& config) const
  1417. {
  1418. const char *prop
  1419. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1420. config);
  1421. if (!prop)
  1422. {
  1423. return;
  1424. }
  1425. cmGeneratorExpression ge;
  1426. cmGeneratorExpressionDAGChecker dagChecker(
  1427. this->GetName(),
  1428. "AUTOUIC_OPTIONS", 0, 0);
  1429. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1430. ->Evaluate(this->Makefile,
  1431. config,
  1432. false,
  1433. this->Target,
  1434. &dagChecker),
  1435. result);
  1436. }
  1437. //----------------------------------------------------------------------------
  1438. void processILibs(const std::string& config,
  1439. cmTarget const* headTarget,
  1440. cmLinkItem const& item,
  1441. cmGlobalGenerator* gg,
  1442. std::vector<cmTarget const*>& tgts,
  1443. std::set<cmTarget const*>& emitted)
  1444. {
  1445. if (item.Target && emitted.insert(item.Target).second)
  1446. {
  1447. tgts.push_back(item.Target);
  1448. cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target);
  1449. if(cmLinkInterfaceLibraries const* iface =
  1450. gt->GetLinkInterfaceLibraries(config, headTarget, true))
  1451. {
  1452. for(std::vector<cmLinkItem>::const_iterator
  1453. it = iface->Libraries.begin();
  1454. it != iface->Libraries.end(); ++it)
  1455. {
  1456. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1457. }
  1458. }
  1459. }
  1460. }
  1461. //----------------------------------------------------------------------------
  1462. const std::vector<const cmTarget*>&
  1463. cmGeneratorTarget::GetLinkImplementationClosure(
  1464. const std::string& config) const
  1465. {
  1466. LinkImplClosure& tgts =
  1467. this->LinkImplClosureMap[config];
  1468. if(!tgts.Done)
  1469. {
  1470. tgts.Done = true;
  1471. std::set<cmTarget const*> emitted;
  1472. cmLinkImplementationLibraries const* impl
  1473. = this->Target->GetLinkImplementationLibraries(config);
  1474. for(std::vector<cmLinkImplItem>::const_iterator
  1475. it = impl->Libraries.begin();
  1476. it != impl->Libraries.end(); ++it)
  1477. {
  1478. processILibs(config, this->Target, *it,
  1479. this->LocalGenerator->GetGlobalGenerator(),
  1480. tgts , emitted);
  1481. }
  1482. }
  1483. return tgts;
  1484. }
  1485. //----------------------------------------------------------------------------
  1486. class cmTargetTraceDependencies
  1487. {
  1488. public:
  1489. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1490. void Trace();
  1491. private:
  1492. cmTarget* Target;
  1493. cmGeneratorTarget* GeneratorTarget;
  1494. cmMakefile* Makefile;
  1495. cmGlobalGenerator const* GlobalGenerator;
  1496. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1497. SourceEntry* CurrentEntry;
  1498. std::queue<cmSourceFile*> SourceQueue;
  1499. std::set<cmSourceFile*> SourcesQueued;
  1500. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1501. NameMapType NameMap;
  1502. std::vector<std::string> NewSources;
  1503. void QueueSource(cmSourceFile* sf);
  1504. void FollowName(std::string const& name);
  1505. void FollowNames(std::vector<std::string> const& names);
  1506. bool IsUtility(std::string const& dep);
  1507. void CheckCustomCommand(cmCustomCommand const& cc);
  1508. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1509. void FollowCommandDepends(cmCustomCommand const& cc,
  1510. const std::string& config,
  1511. std::set<std::string>& emitted);
  1512. };
  1513. //----------------------------------------------------------------------------
  1514. cmTargetTraceDependencies
  1515. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  1516. Target(target->Target), GeneratorTarget(target)
  1517. {
  1518. // Convenience.
  1519. this->Makefile = this->Target->GetMakefile();
  1520. this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
  1521. this->CurrentEntry = 0;
  1522. // Queue all the source files already specified for the target.
  1523. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1524. {
  1525. std::vector<std::string> configs;
  1526. this->Makefile->GetConfigurations(configs);
  1527. if (configs.empty())
  1528. {
  1529. configs.push_back("");
  1530. }
  1531. std::set<cmSourceFile*> emitted;
  1532. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1533. ci != configs.end(); ++ci)
  1534. {
  1535. std::vector<cmSourceFile*> sources;
  1536. this->Target->GetSourceFiles(sources, *ci);
  1537. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1538. si != sources.end(); ++si)
  1539. {
  1540. cmSourceFile* sf = *si;
  1541. const std::set<cmTarget const*> tgts =
  1542. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1543. if (tgts.find(this->Target) != tgts.end())
  1544. {
  1545. std::ostringstream e;
  1546. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1547. << "\"\ndepends on the sources of a target it is used in. This "
  1548. "is a dependency loop and is not allowed.";
  1549. this->GeneratorTarget
  1550. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1551. return;
  1552. }
  1553. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  1554. {
  1555. this->SourceQueue.push(sf);
  1556. }
  1557. }
  1558. }
  1559. }
  1560. // Queue pre-build, pre-link, and post-build rule dependencies.
  1561. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1562. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1563. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1564. }
  1565. //----------------------------------------------------------------------------
  1566. void cmTargetTraceDependencies::Trace()
  1567. {
  1568. // Process one dependency at a time until the queue is empty.
  1569. while(!this->SourceQueue.empty())
  1570. {
  1571. // Get the next source from the queue.
  1572. cmSourceFile* sf = this->SourceQueue.front();
  1573. this->SourceQueue.pop();
  1574. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  1575. // Queue dependencies added explicitly by the user.
  1576. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1577. {
  1578. std::vector<std::string> objDeps;
  1579. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1580. for(std::vector<std::string>::iterator odi = objDeps.begin();
  1581. odi != objDeps.end(); ++odi)
  1582. {
  1583. if (cmSystemTools::FileIsFullPath(*odi))
  1584. {
  1585. *odi = cmSystemTools::CollapseFullPath(*odi);
  1586. }
  1587. }
  1588. this->FollowNames(objDeps);
  1589. }
  1590. // Queue the source needed to generate this file, if any.
  1591. this->FollowName(sf->GetFullPath());
  1592. // Queue dependencies added programatically by commands.
  1593. this->FollowNames(sf->GetDepends());
  1594. // Queue custom command dependencies.
  1595. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1596. {
  1597. this->CheckCustomCommand(*cc);
  1598. }
  1599. }
  1600. this->CurrentEntry = 0;
  1601. this->Target->AddTracedSources(this->NewSources);
  1602. }
  1603. //----------------------------------------------------------------------------
  1604. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1605. {
  1606. if(this->SourcesQueued.insert(sf).second)
  1607. {
  1608. this->SourceQueue.push(sf);
  1609. // Make sure this file is in the target at the end.
  1610. this->NewSources.push_back(sf->GetFullPath());
  1611. }
  1612. }
  1613. //----------------------------------------------------------------------------
  1614. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1615. {
  1616. NameMapType::iterator i = this->NameMap.find(name);
  1617. if(i == this->NameMap.end())
  1618. {
  1619. // Check if we know how to generate this file.
  1620. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1621. NameMapType::value_type entry(name, sf);
  1622. i = this->NameMap.insert(entry).first;
  1623. }
  1624. if(cmSourceFile* sf = i->second)
  1625. {
  1626. // Record the dependency we just followed.
  1627. if(this->CurrentEntry)
  1628. {
  1629. this->CurrentEntry->Depends.push_back(sf);
  1630. }
  1631. this->QueueSource(sf);
  1632. }
  1633. }
  1634. //----------------------------------------------------------------------------
  1635. void
  1636. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1637. {
  1638. for(std::vector<std::string>::const_iterator i = names.begin();
  1639. i != names.end(); ++i)
  1640. {
  1641. this->FollowName(*i);
  1642. }
  1643. }
  1644. //----------------------------------------------------------------------------
  1645. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1646. {
  1647. // Dependencies on targets (utilities) are supposed to be named by
  1648. // just the target name. However for compatibility we support
  1649. // naming the output file generated by the target (assuming there is
  1650. // no output-name property which old code would not have set). In
  1651. // that case the target name will be the file basename of the
  1652. // dependency.
  1653. std::string util = cmSystemTools::GetFilenameName(dep);
  1654. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1655. {
  1656. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1657. }
  1658. // Check for a target with this name.
  1659. if(cmGeneratorTarget* t
  1660. = this->Makefile->FindGeneratorTargetToUse(util))
  1661. {
  1662. // If we find the target and the dep was given as a full path,
  1663. // then make sure it was not a full path to something else, and
  1664. // the fact that the name matched a target was just a coincidence.
  1665. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1666. {
  1667. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1668. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1669. {
  1670. // This is really only for compatibility so we do not need to
  1671. // worry about configuration names and output names.
  1672. std::string tLocation = t->GetLocationForBuild();
  1673. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1674. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1675. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1676. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1677. if(depLocation == tLocation)
  1678. {
  1679. this->Target->AddUtility(util);
  1680. return true;
  1681. }
  1682. }
  1683. }
  1684. else
  1685. {
  1686. // The original name of the dependency was not a full path. It
  1687. // must name a target, so add the target-level dependency.
  1688. this->Target->AddUtility(util);
  1689. return true;
  1690. }
  1691. }
  1692. // The dependency does not name a target built in this project.
  1693. return false;
  1694. }
  1695. //----------------------------------------------------------------------------
  1696. void
  1697. cmTargetTraceDependencies
  1698. ::CheckCustomCommand(cmCustomCommand const& cc)
  1699. {
  1700. // Transform command names that reference targets built in this
  1701. // project to corresponding target-level dependencies.
  1702. cmGeneratorExpression ge(cc.GetBacktrace());
  1703. // Add target-level dependencies referenced by generator expressions.
  1704. std::set<cmTarget*> targets;
  1705. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1706. cit != cc.GetCommandLines().end(); ++cit)
  1707. {
  1708. std::string const& command = *cit->begin();
  1709. // Check for a target with this name.
  1710. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1711. {
  1712. if(t->GetType() == cmTarget::EXECUTABLE)
  1713. {
  1714. // The command refers to an executable target built in
  1715. // this project. Add the target-level dependency to make
  1716. // sure the executable is up to date before this custom
  1717. // command possibly runs.
  1718. this->Target->AddUtility(command);
  1719. }
  1720. }
  1721. // Check for target references in generator expressions.
  1722. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1723. cli != cit->end(); ++cli)
  1724. {
  1725. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1726. = ge.Parse(*cli);
  1727. cge->Evaluate(this->Makefile, "", true);
  1728. std::set<cmTarget*> geTargets = cge->GetTargets();
  1729. targets.insert(geTargets.begin(), geTargets.end());
  1730. }
  1731. }
  1732. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1733. ti != targets.end(); ++ti)
  1734. {
  1735. this->Target->AddUtility((*ti)->GetName());
  1736. }
  1737. // Queue the custom command dependencies.
  1738. std::vector<std::string> configs;
  1739. std::set<std::string> emitted;
  1740. this->Makefile->GetConfigurations(configs);
  1741. if (configs.empty())
  1742. {
  1743. configs.push_back("");
  1744. }
  1745. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1746. ci != configs.end(); ++ci)
  1747. {
  1748. this->FollowCommandDepends(cc, *ci, emitted);
  1749. }
  1750. }
  1751. //----------------------------------------------------------------------------
  1752. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1753. const std::string& config,
  1754. std::set<std::string>& emitted)
  1755. {
  1756. cmCustomCommandGenerator ccg(cc, config,
  1757. this->GeneratorTarget->LocalGenerator);
  1758. const std::vector<std::string>& depends = ccg.GetDepends();
  1759. for(std::vector<std::string>::const_iterator di = depends.begin();
  1760. di != depends.end(); ++di)
  1761. {
  1762. std::string const& dep = *di;
  1763. if(emitted.insert(dep).second)
  1764. {
  1765. if(!this->IsUtility(dep))
  1766. {
  1767. // The dependency does not name a target and may be a file we
  1768. // know how to generate. Queue it.
  1769. this->FollowName(dep);
  1770. }
  1771. }
  1772. }
  1773. }
  1774. //----------------------------------------------------------------------------
  1775. void
  1776. cmTargetTraceDependencies
  1777. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1778. {
  1779. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1780. cli != commands.end(); ++cli)
  1781. {
  1782. this->CheckCustomCommand(*cli);
  1783. }
  1784. }
  1785. //----------------------------------------------------------------------------
  1786. void cmGeneratorTarget::TraceDependencies()
  1787. {
  1788. // CMake-generated targets have no dependencies to trace. Normally tracing
  1789. // would find nothing anyway, but when building CMake itself the "install"
  1790. // target command ends up referencing the "cmake" target but we do not
  1791. // really want the dependency because "install" depend on "all" anyway.
  1792. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1793. {
  1794. return;
  1795. }
  1796. // Use a helper object to trace the dependencies.
  1797. cmTargetTraceDependencies tracer(this);
  1798. tracer.Trace();
  1799. }
  1800. std::string
  1801. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  1802. {
  1803. if(CompileInfo const* info = this->GetCompileInfo(config))
  1804. {
  1805. return info->CompilePdbDir;
  1806. }
  1807. return "";
  1808. }
  1809. //----------------------------------------------------------------------------
  1810. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1811. std::vector<std::string>& archVec) const
  1812. {
  1813. const char* archs = 0;
  1814. if(!config.empty())
  1815. {
  1816. std::string defVarName = "OSX_ARCHITECTURES_";
  1817. defVarName += cmSystemTools::UpperCase(config);
  1818. archs = this->Target->GetProperty(defVarName);
  1819. }
  1820. if(!archs)
  1821. {
  1822. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1823. }
  1824. if(archs)
  1825. {
  1826. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1827. }
  1828. }
  1829. //----------------------------------------------------------------------------
  1830. std::string
  1831. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1832. std::string const& config) const
  1833. {
  1834. switch(this->GetType())
  1835. {
  1836. case cmTarget::STATIC_LIBRARY:
  1837. {
  1838. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1839. if(this->GetFeatureAsBool(
  1840. "INTERPROCEDURAL_OPTIMIZATION", config))
  1841. {
  1842. std::string varIPO = var + "_IPO";
  1843. if(this->Makefile->GetDefinition(varIPO))
  1844. {
  1845. return varIPO;
  1846. }
  1847. }
  1848. return var;
  1849. }
  1850. case cmTarget::SHARED_LIBRARY:
  1851. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1852. case cmTarget::MODULE_LIBRARY:
  1853. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1854. case cmTarget::EXECUTABLE:
  1855. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1856. default:
  1857. break;
  1858. }
  1859. return "";
  1860. }
  1861. //----------------------------------------------------------------------------
  1862. static void processIncludeDirectories(cmGeneratorTarget const* tgt,
  1863. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  1864. std::vector<std::string> &includes,
  1865. UNORDERED_SET<std::string> &uniqueIncludes,
  1866. cmGeneratorExpressionDAGChecker *dagChecker,
  1867. const std::string& config, bool debugIncludes,
  1868. const std::string& language)
  1869. {
  1870. cmMakefile *mf = tgt->Target->GetMakefile();
  1871. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  1872. it = entries.begin(), end = entries.end(); it != end; ++it)
  1873. {
  1874. cmLinkImplItem const& item = (*it)->LinkImplItem;
  1875. std::string const& targetName = item;
  1876. bool const fromImported = item.Target && item.Target->IsImported();
  1877. bool const checkCMP0027 = item.FromGenex;
  1878. std::vector<std::string> entryIncludes;
  1879. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1880. config,
  1881. false,
  1882. tgt->Target,
  1883. dagChecker, language),
  1884. entryIncludes);
  1885. std::string usedIncludes;
  1886. for(std::vector<std::string>::iterator
  1887. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1888. {
  1889. if (fromImported
  1890. && !cmSystemTools::FileExists(li->c_str()))
  1891. {
  1892. std::ostringstream e;
  1893. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1894. if (checkCMP0027)
  1895. {
  1896. switch(tgt->Target->GetPolicyStatusCMP0027())
  1897. {
  1898. case cmPolicies::WARN:
  1899. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  1900. case cmPolicies::OLD:
  1901. messageType = cmake::AUTHOR_WARNING;
  1902. break;
  1903. case cmPolicies::REQUIRED_ALWAYS:
  1904. case cmPolicies::REQUIRED_IF_USED:
  1905. case cmPolicies::NEW:
  1906. break;
  1907. }
  1908. }
  1909. e << "Imported target \"" << targetName << "\" includes "
  1910. "non-existent path\n \"" << *li << "\"\nin its "
  1911. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1912. "* The path was deleted, renamed, or moved to another "
  1913. "location.\n"
  1914. "* An install or uninstall procedure did not complete "
  1915. "successfully.\n"
  1916. "* The installation package was faulty and references files it "
  1917. "does not provide.\n";
  1918. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  1919. return;
  1920. }
  1921. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1922. {
  1923. std::ostringstream e;
  1924. bool noMessage = false;
  1925. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1926. if (!targetName.empty())
  1927. {
  1928. e << "Target \"" << targetName << "\" contains relative "
  1929. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1930. " \"" << *li << "\"";
  1931. }
  1932. else
  1933. {
  1934. switch(tgt->Target->GetPolicyStatusCMP0021())
  1935. {
  1936. case cmPolicies::WARN:
  1937. {
  1938. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  1939. messageType = cmake::AUTHOR_WARNING;
  1940. }
  1941. break;
  1942. case cmPolicies::OLD:
  1943. noMessage = true;
  1944. case cmPolicies::REQUIRED_IF_USED:
  1945. case cmPolicies::REQUIRED_ALWAYS:
  1946. case cmPolicies::NEW:
  1947. // Issue the fatal message.
  1948. break;
  1949. }
  1950. e << "Found relative path while evaluating include directories of "
  1951. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1952. }
  1953. if (!noMessage)
  1954. {
  1955. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  1956. if (messageType == cmake::FATAL_ERROR)
  1957. {
  1958. return;
  1959. }
  1960. }
  1961. }
  1962. if (!cmSystemTools::IsOff(li->c_str()))
  1963. {
  1964. cmSystemTools::ConvertToUnixSlashes(*li);
  1965. }
  1966. std::string inc = *li;
  1967. if(uniqueIncludes.insert(inc).second)
  1968. {
  1969. includes.push_back(inc);
  1970. if (debugIncludes)
  1971. {
  1972. usedIncludes += " * " + inc + "\n";
  1973. }
  1974. }
  1975. }
  1976. if (!usedIncludes.empty())
  1977. {
  1978. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1979. std::string("Used includes for target ")
  1980. + tgt->GetName() + ":\n"
  1981. + usedIncludes, (*it)->ge->GetBacktrace());
  1982. }
  1983. }
  1984. }
  1985. //----------------------------------------------------------------------------
  1986. static void AddInterfaceEntries(
  1987. cmGeneratorTarget const* thisTarget, std::string const& config,
  1988. std::string const& prop,
  1989. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  1990. {
  1991. if(cmLinkImplementationLibraries const* impl =
  1992. thisTarget->Target->GetLinkImplementationLibraries(config))
  1993. {
  1994. for (std::vector<cmLinkImplItem>::const_iterator
  1995. it = impl->Libraries.begin(), end = impl->Libraries.end();
  1996. it != end; ++it)
  1997. {
  1998. if(it->Target)
  1999. {
  2000. std::string genex =
  2001. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  2002. cmGeneratorExpression ge(it->Backtrace);
  2003. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  2004. cge->SetEvaluateForBuildsystem(true);
  2005. entries.push_back(
  2006. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  2007. }
  2008. }
  2009. }
  2010. }
  2011. //----------------------------------------------------------------------------
  2012. std::vector<std::string>
  2013. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  2014. const std::string& lang) const
  2015. {
  2016. std::vector<std::string> includes;
  2017. UNORDERED_SET<std::string> uniqueIncludes;
  2018. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2019. "INCLUDE_DIRECTORIES", 0, 0);
  2020. std::vector<std::string> debugProperties;
  2021. const char *debugProp =
  2022. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2023. if (debugProp)
  2024. {
  2025. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2026. }
  2027. bool debugIncludes = !this->DebugIncludesDone
  2028. && std::find(debugProperties.begin(),
  2029. debugProperties.end(),
  2030. "INCLUDE_DIRECTORIES")
  2031. != debugProperties.end();
  2032. if (this->Makefile->IsConfigured())
  2033. {
  2034. this->DebugIncludesDone = true;
  2035. }
  2036. processIncludeDirectories(this,
  2037. this->IncludeDirectoriesEntries,
  2038. includes,
  2039. uniqueIncludes,
  2040. &dagChecker,
  2041. config,
  2042. debugIncludes,
  2043. lang);
  2044. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2045. linkInterfaceIncludeDirectoriesEntries;
  2046. AddInterfaceEntries(
  2047. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2048. linkInterfaceIncludeDirectoriesEntries);
  2049. if(this->Makefile->IsOn("APPLE"))
  2050. {
  2051. cmLinkImplementationLibraries const* impl =
  2052. this->Target->GetLinkImplementationLibraries(config);
  2053. for(std::vector<cmLinkImplItem>::const_iterator
  2054. it = impl->Libraries.begin();
  2055. it != impl->Libraries.end(); ++it)
  2056. {
  2057. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2058. static cmsys::RegularExpression
  2059. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2060. if(!frameworkCheck.find(libDir))
  2061. {
  2062. continue;
  2063. }
  2064. libDir = frameworkCheck.match(1);
  2065. cmGeneratorExpression ge;
  2066. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2067. ge.Parse(libDir.c_str());
  2068. linkInterfaceIncludeDirectoriesEntries
  2069. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2070. }
  2071. }
  2072. processIncludeDirectories(this,
  2073. linkInterfaceIncludeDirectoriesEntries,
  2074. includes,
  2075. uniqueIncludes,
  2076. &dagChecker,
  2077. config,
  2078. debugIncludes,
  2079. lang);
  2080. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2081. return includes;
  2082. }
  2083. //----------------------------------------------------------------------------
  2084. static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
  2085. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2086. std::vector<std::string> &options,
  2087. UNORDERED_SET<std::string> &uniqueOptions,
  2088. cmGeneratorExpressionDAGChecker *dagChecker,
  2089. const std::string& config, bool debugOptions, const char *logName,
  2090. std::string const& language)
  2091. {
  2092. cmMakefile *mf = tgt->Target->GetMakefile();
  2093. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2094. it = entries.begin(), end = entries.end(); it != end; ++it)
  2095. {
  2096. std::vector<std::string> entryOptions;
  2097. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2098. config,
  2099. false,
  2100. tgt->Target,
  2101. dagChecker,
  2102. language),
  2103. entryOptions);
  2104. std::string usedOptions;
  2105. for(std::vector<std::string>::iterator
  2106. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2107. {
  2108. std::string const& opt = *li;
  2109. if(uniqueOptions.insert(opt).second)
  2110. {
  2111. options.push_back(opt);
  2112. if (debugOptions)
  2113. {
  2114. usedOptions += " * " + opt + "\n";
  2115. }
  2116. }
  2117. }
  2118. if (!usedOptions.empty())
  2119. {
  2120. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2121. std::string("Used compile ") + logName
  2122. + std::string(" for target ")
  2123. + tgt->GetName() + ":\n"
  2124. + usedOptions, (*it)->ge->GetBacktrace());
  2125. }
  2126. }
  2127. }
  2128. //----------------------------------------------------------------------------
  2129. static void processCompileOptions(cmGeneratorTarget const* tgt,
  2130. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2131. std::vector<std::string> &options,
  2132. UNORDERED_SET<std::string> &uniqueOptions,
  2133. cmGeneratorExpressionDAGChecker *dagChecker,
  2134. const std::string& config, bool debugOptions,
  2135. std::string const& language)
  2136. {
  2137. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2138. dagChecker, config, debugOptions, "options",
  2139. language);
  2140. }
  2141. //----------------------------------------------------------------------------
  2142. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string> &result,
  2143. const std::string& config,
  2144. const std::string& language) const
  2145. {
  2146. UNORDERED_SET<std::string> uniqueOptions;
  2147. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2148. "COMPILE_OPTIONS", 0, 0);
  2149. std::vector<std::string> debugProperties;
  2150. const char *debugProp =
  2151. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2152. if (debugProp)
  2153. {
  2154. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2155. }
  2156. bool debugOptions = !this->DebugCompileOptionsDone
  2157. && std::find(debugProperties.begin(),
  2158. debugProperties.end(),
  2159. "COMPILE_OPTIONS")
  2160. != debugProperties.end();
  2161. if (this->Makefile->IsConfigured())
  2162. {
  2163. this->DebugCompileOptionsDone = true;
  2164. }
  2165. processCompileOptions(this,
  2166. this->CompileOptionsEntries,
  2167. result,
  2168. uniqueOptions,
  2169. &dagChecker,
  2170. config,
  2171. debugOptions,
  2172. language);
  2173. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2174. linkInterfaceCompileOptionsEntries;
  2175. AddInterfaceEntries(
  2176. this, config, "INTERFACE_COMPILE_OPTIONS",
  2177. linkInterfaceCompileOptionsEntries);
  2178. processCompileOptions(this,
  2179. linkInterfaceCompileOptionsEntries,
  2180. result,
  2181. uniqueOptions,
  2182. &dagChecker,
  2183. config,
  2184. debugOptions,
  2185. language);
  2186. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2187. }
  2188. //----------------------------------------------------------------------------
  2189. static void processCompileFeatures(cmGeneratorTarget const* tgt,
  2190. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2191. std::vector<std::string> &options,
  2192. UNORDERED_SET<std::string> &uniqueOptions,
  2193. cmGeneratorExpressionDAGChecker *dagChecker,
  2194. const std::string& config, bool debugOptions)
  2195. {
  2196. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2197. dagChecker, config, debugOptions, "features",
  2198. std::string());
  2199. }
  2200. //----------------------------------------------------------------------------
  2201. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string> &result,
  2202. const std::string& config) const
  2203. {
  2204. UNORDERED_SET<std::string> uniqueFeatures;
  2205. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2206. "COMPILE_FEATURES",
  2207. 0, 0);
  2208. std::vector<std::string> debugProperties;
  2209. const char *debugProp =
  2210. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2211. if (debugProp)
  2212. {
  2213. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2214. }
  2215. bool debugFeatures = !this->DebugCompileFeaturesDone
  2216. && std::find(debugProperties.begin(),
  2217. debugProperties.end(),
  2218. "COMPILE_FEATURES")
  2219. != debugProperties.end();
  2220. if (this->Makefile->IsConfigured())
  2221. {
  2222. this->DebugCompileFeaturesDone = true;
  2223. }
  2224. processCompileFeatures(this,
  2225. this->CompileFeaturesEntries,
  2226. result,
  2227. uniqueFeatures,
  2228. &dagChecker,
  2229. config,
  2230. debugFeatures);
  2231. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2232. linkInterfaceCompileFeaturesEntries;
  2233. AddInterfaceEntries(
  2234. this, config, "INTERFACE_COMPILE_FEATURES",
  2235. linkInterfaceCompileFeaturesEntries);
  2236. processCompileFeatures(this,
  2237. linkInterfaceCompileFeaturesEntries,
  2238. result,
  2239. uniqueFeatures,
  2240. &dagChecker,
  2241. config,
  2242. debugFeatures);
  2243. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. static void processCompileDefinitions(cmGeneratorTarget const* tgt,
  2247. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2248. std::vector<std::string> &options,
  2249. UNORDERED_SET<std::string> &uniqueOptions,
  2250. cmGeneratorExpressionDAGChecker *dagChecker,
  2251. const std::string& config, bool debugOptions,
  2252. std::string const& language)
  2253. {
  2254. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2255. dagChecker, config, debugOptions,
  2256. "definitions", language);
  2257. }
  2258. //----------------------------------------------------------------------------
  2259. void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2260. const std::string& config,
  2261. const std::string& language) const
  2262. {
  2263. UNORDERED_SET<std::string> uniqueOptions;
  2264. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2265. "COMPILE_DEFINITIONS", 0, 0);
  2266. std::vector<std::string> debugProperties;
  2267. const char *debugProp =
  2268. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2269. if (debugProp)
  2270. {
  2271. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2272. }
  2273. bool debugDefines = !this->DebugCompileDefinitionsDone
  2274. && std::find(debugProperties.begin(),
  2275. debugProperties.end(),
  2276. "COMPILE_DEFINITIONS")
  2277. != debugProperties.end();
  2278. if (this->Makefile->IsConfigured())
  2279. {
  2280. this->DebugCompileDefinitionsDone = true;
  2281. }
  2282. processCompileDefinitions(this,
  2283. this->CompileDefinitionsEntries,
  2284. list,
  2285. uniqueOptions,
  2286. &dagChecker,
  2287. config,
  2288. debugDefines,
  2289. language);
  2290. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2291. linkInterfaceCompileDefinitionsEntries;
  2292. AddInterfaceEntries(
  2293. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2294. linkInterfaceCompileDefinitionsEntries);
  2295. if (!config.empty())
  2296. {
  2297. std::string configPropName = "COMPILE_DEFINITIONS_"
  2298. + cmSystemTools::UpperCase(config);
  2299. const char *configProp = this->Target->GetProperty(configPropName);
  2300. if (configProp)
  2301. {
  2302. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2303. {
  2304. case cmPolicies::WARN:
  2305. {
  2306. std::ostringstream e;
  2307. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2308. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING,
  2309. e.str());
  2310. }
  2311. case cmPolicies::OLD:
  2312. {
  2313. cmGeneratorExpression ge;
  2314. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2315. ge.Parse(configProp);
  2316. linkInterfaceCompileDefinitionsEntries
  2317. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2318. }
  2319. break;
  2320. case cmPolicies::NEW:
  2321. case cmPolicies::REQUIRED_ALWAYS:
  2322. case cmPolicies::REQUIRED_IF_USED:
  2323. break;
  2324. }
  2325. }
  2326. }
  2327. processCompileDefinitions(this,
  2328. linkInterfaceCompileDefinitionsEntries,
  2329. list,
  2330. uniqueOptions,
  2331. &dagChecker,
  2332. config,
  2333. debugDefines,
  2334. language);
  2335. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2336. }
  2337. //----------------------------------------------------------------------------
  2338. void cmGeneratorTarget::ComputeTargetManifest(
  2339. const std::string& config) const
  2340. {
  2341. if (this->Target->IsImported())
  2342. {
  2343. return;
  2344. }
  2345. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2346. // Get the names.
  2347. std::string name;
  2348. std::string soName;
  2349. std::string realName;
  2350. std::string impName;
  2351. std::string pdbName;
  2352. if(this->GetType() == cmTarget::EXECUTABLE)
  2353. {
  2354. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2355. }
  2356. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2357. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2358. this->GetType() == cmTarget::MODULE_LIBRARY)
  2359. {
  2360. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  2361. config);
  2362. }
  2363. else
  2364. {
  2365. return;
  2366. }
  2367. // Get the directory.
  2368. std::string dir = this->Target->GetDirectory(config, false);
  2369. // Add each name.
  2370. std::string f;
  2371. if(!name.empty())
  2372. {
  2373. f = dir;
  2374. f += "/";
  2375. f += name;
  2376. gg->AddToManifest(f);
  2377. }
  2378. if(!soName.empty())
  2379. {
  2380. f = dir;
  2381. f += "/";
  2382. f += soName;
  2383. gg->AddToManifest(f);
  2384. }
  2385. if(!realName.empty())
  2386. {
  2387. f = dir;
  2388. f += "/";
  2389. f += realName;
  2390. gg->AddToManifest(f);
  2391. }
  2392. if(!pdbName.empty())
  2393. {
  2394. f = dir;
  2395. f += "/";
  2396. f += pdbName;
  2397. gg->AddToManifest(f);
  2398. }
  2399. if(!impName.empty())
  2400. {
  2401. f = this->Target->GetDirectory(config, true);
  2402. f += "/";
  2403. f += impName;
  2404. gg->AddToManifest(f);
  2405. }
  2406. }
  2407. //----------------------------------------------------------------------------
  2408. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2409. bool implib, bool realname) const
  2410. {
  2411. if(this->Target->IsImported())
  2412. {
  2413. return this->Target->ImportedGetFullPath(config, implib);
  2414. }
  2415. else
  2416. {
  2417. return this->NormalGetFullPath(config, implib, realname);
  2418. }
  2419. }
  2420. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  2421. bool implib,
  2422. bool realname) const
  2423. {
  2424. std::string fpath = this->Target->GetDirectory(config, implib);
  2425. fpath += "/";
  2426. if(this->Target->IsAppBundleOnApple())
  2427. {
  2428. fpath = this->BuildMacContentDirectory(fpath, config, false);
  2429. fpath += "/";
  2430. }
  2431. // Add the full name of the target.
  2432. if(implib)
  2433. {
  2434. fpath += this->GetFullName(config, true);
  2435. }
  2436. else if(realname)
  2437. {
  2438. fpath += this->NormalGetRealName(config);
  2439. }
  2440. else
  2441. {
  2442. fpath += this->GetFullName(config, false);
  2443. }
  2444. return fpath;
  2445. }
  2446. //----------------------------------------------------------------------------
  2447. std::string
  2448. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  2449. {
  2450. // This should not be called for imported targets.
  2451. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2452. // enforcement of the limited imported target API.
  2453. if(this->Target->IsImported())
  2454. {
  2455. std::string msg = "NormalGetRealName called on imported target: ";
  2456. msg += this->GetName();
  2457. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2458. }
  2459. if(this->GetType() == cmTarget::EXECUTABLE)
  2460. {
  2461. // Compute the real name that will be built.
  2462. std::string name;
  2463. std::string realName;
  2464. std::string impName;
  2465. std::string pdbName;
  2466. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2467. return realName;
  2468. }
  2469. else
  2470. {
  2471. // Compute the real name that will be built.
  2472. std::string name;
  2473. std::string soName;
  2474. std::string realName;
  2475. std::string impName;
  2476. std::string pdbName;
  2477. this->GetLibraryNames(name, soName, realName,
  2478. impName, pdbName, config);
  2479. return realName;
  2480. }
  2481. }
  2482. //----------------------------------------------------------------------------
  2483. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  2484. std::string& soName,
  2485. std::string& realName,
  2486. std::string& impName,
  2487. std::string& pdbName,
  2488. const std::string& config) const
  2489. {
  2490. // This should not be called for imported targets.
  2491. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2492. // enforcement of the limited imported target API.
  2493. if(this->Target->IsImported())
  2494. {
  2495. std::string msg = "GetLibraryNames called on imported target: ";
  2496. msg += this->GetName();
  2497. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  2498. msg);
  2499. return;
  2500. }
  2501. // Check for library version properties.
  2502. const char* version = this->GetProperty("VERSION");
  2503. const char* soversion = this->GetProperty("SOVERSION");
  2504. if(!this->HasSOName(config) ||
  2505. this->Target->IsFrameworkOnApple())
  2506. {
  2507. // Versioning is supported only for shared libraries and modules,
  2508. // and then only when the platform supports an soname flag.
  2509. version = 0;
  2510. soversion = 0;
  2511. }
  2512. if(version && !soversion)
  2513. {
  2514. // The soversion must be set if the library version is set. Use
  2515. // the library version as the soversion.
  2516. soversion = version;
  2517. }
  2518. if(!version && soversion)
  2519. {
  2520. // Use the soversion as the library version.
  2521. version = soversion;
  2522. }
  2523. // Get the components of the library name.
  2524. std::string prefix;
  2525. std::string base;
  2526. std::string suffix;
  2527. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2528. // The library name.
  2529. name = prefix+base+suffix;
  2530. if(this->Target->IsFrameworkOnApple())
  2531. {
  2532. realName = prefix;
  2533. if(!this->Makefile->PlatformIsAppleIos())
  2534. {
  2535. realName += "Versions/";
  2536. realName += this->Target->GetFrameworkVersion();
  2537. realName += "/";
  2538. }
  2539. realName += base;
  2540. soName = realName;
  2541. }
  2542. else
  2543. {
  2544. // The library's soname.
  2545. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  2546. name, soversion);
  2547. // The library's real name on disk.
  2548. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  2549. name, version);
  2550. }
  2551. // The import library name.
  2552. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2553. this->GetType() == cmTarget::MODULE_LIBRARY)
  2554. {
  2555. impName = this->GetFullNameInternal(config, true);
  2556. }
  2557. else
  2558. {
  2559. impName = "";
  2560. }
  2561. // The program database file name.
  2562. pdbName = this->GetPDBName(config);
  2563. }
  2564. //----------------------------------------------------------------------------
  2565. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2566. std::string& realName,
  2567. std::string& impName,
  2568. std::string& pdbName,
  2569. const std::string& config) const
  2570. {
  2571. // This should not be called for imported targets.
  2572. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2573. // enforcement of the limited imported target API.
  2574. if(this->Target->IsImported())
  2575. {
  2576. std::string msg =
  2577. "GetExecutableNames called on imported target: ";
  2578. msg += this->GetName();
  2579. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2580. }
  2581. // This versioning is supported only for executables and then only
  2582. // when the platform supports symbolic links.
  2583. #if defined(_WIN32) && !defined(__CYGWIN__)
  2584. const char* version = 0;
  2585. #else
  2586. // Check for executable version properties.
  2587. const char* version = this->GetProperty("VERSION");
  2588. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2589. {
  2590. version = 0;
  2591. }
  2592. #endif
  2593. // Get the components of the executable name.
  2594. std::string prefix;
  2595. std::string base;
  2596. std::string suffix;
  2597. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2598. // The executable name.
  2599. name = prefix+base+suffix;
  2600. // The executable's real name on disk.
  2601. #if defined(__CYGWIN__)
  2602. realName = prefix+base;
  2603. #else
  2604. realName = name;
  2605. #endif
  2606. if(version)
  2607. {
  2608. realName += "-";
  2609. realName += version;
  2610. }
  2611. #if defined(__CYGWIN__)
  2612. realName += suffix;
  2613. #endif
  2614. // The import library name.
  2615. impName = this->GetFullNameInternal(config, true);
  2616. // The program database file name.
  2617. pdbName = this->GetPDBName(config);
  2618. }
  2619. //----------------------------------------------------------------------------
  2620. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2621. bool implib) const
  2622. {
  2623. std::string prefix;
  2624. std::string base;
  2625. std::string suffix;
  2626. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2627. return prefix+base+suffix;
  2628. }
  2629. //----------------------------------------------------------------------------
  2630. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2631. bool implib,
  2632. std::string& outPrefix,
  2633. std::string& outBase,
  2634. std::string& outSuffix) const
  2635. {
  2636. // Use just the target name for non-main target types.
  2637. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2638. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2639. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2640. this->GetType() != cmTarget::EXECUTABLE)
  2641. {
  2642. outPrefix = "";
  2643. outBase = this->GetName();
  2644. outSuffix = "";
  2645. return;
  2646. }
  2647. // Return an empty name for the import library if this platform
  2648. // does not support import libraries.
  2649. if(implib &&
  2650. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2651. {
  2652. outPrefix = "";
  2653. outBase = "";
  2654. outSuffix = "";
  2655. return;
  2656. }
  2657. // The implib option is only allowed for shared libraries, module
  2658. // libraries, and executables.
  2659. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2660. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2661. this->GetType() != cmTarget::EXECUTABLE)
  2662. {
  2663. implib = false;
  2664. }
  2665. // Compute the full name for main target types.
  2666. const char* targetPrefix = (implib
  2667. ? this->GetProperty("IMPORT_PREFIX")
  2668. : this->GetProperty("PREFIX"));
  2669. const char* targetSuffix = (implib
  2670. ? this->GetProperty("IMPORT_SUFFIX")
  2671. : this->GetProperty("SUFFIX"));
  2672. const char* configPostfix = 0;
  2673. if(!config.empty())
  2674. {
  2675. std::string configProp = cmSystemTools::UpperCase(config);
  2676. configProp += "_POSTFIX";
  2677. configPostfix = this->GetProperty(configProp);
  2678. // Mac application bundles and frameworks have no postfix.
  2679. if(configPostfix &&
  2680. (this->Target->IsAppBundleOnApple()
  2681. || this->Target->IsFrameworkOnApple()))
  2682. {
  2683. configPostfix = 0;
  2684. }
  2685. }
  2686. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2687. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2688. // Check for language-specific default prefix and suffix.
  2689. std::string ll = this->GetLinkerLanguage(config);
  2690. if(!ll.empty())
  2691. {
  2692. if(!targetSuffix && suffixVar && *suffixVar)
  2693. {
  2694. std::string langSuff = suffixVar + std::string("_") + ll;
  2695. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2696. }
  2697. if(!targetPrefix && prefixVar && *prefixVar)
  2698. {
  2699. std::string langPrefix = prefixVar + std::string("_") + ll;
  2700. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2701. }
  2702. }
  2703. // if there is no prefix on the target use the cmake definition
  2704. if(!targetPrefix && prefixVar)
  2705. {
  2706. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2707. }
  2708. // if there is no suffix on the target use the cmake definition
  2709. if(!targetSuffix && suffixVar)
  2710. {
  2711. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2712. }
  2713. // frameworks have directory prefix but no suffix
  2714. std::string fw_prefix;
  2715. if(this->Target->IsFrameworkOnApple())
  2716. {
  2717. fw_prefix = this->GetOutputName(config, false);
  2718. fw_prefix += ".framework/";
  2719. targetPrefix = fw_prefix.c_str();
  2720. targetSuffix = 0;
  2721. }
  2722. if(this->Target->IsCFBundleOnApple())
  2723. {
  2724. fw_prefix = this->GetCFBundleDirectory(config, false);
  2725. fw_prefix += "/";
  2726. targetPrefix = fw_prefix.c_str();
  2727. targetSuffix = 0;
  2728. }
  2729. // Begin the final name with the prefix.
  2730. outPrefix = targetPrefix?targetPrefix:"";
  2731. // Append the target name or property-specified name.
  2732. outBase += this->GetOutputName(config, implib);
  2733. // Append the per-configuration postfix.
  2734. outBase += configPostfix?configPostfix:"";
  2735. // Name shared libraries with their version number on some platforms.
  2736. if(const char* soversion = this->GetProperty("SOVERSION"))
  2737. {
  2738. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2739. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2740. {
  2741. outBase += "-";
  2742. outBase += soversion;
  2743. }
  2744. }
  2745. // Append the suffix.
  2746. outSuffix = targetSuffix?targetSuffix:"";
  2747. }
  2748. //----------------------------------------------------------------------------
  2749. std::string
  2750. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  2751. {
  2752. return this->GetLinkClosure(config)->LinkerLanguage;
  2753. }
  2754. //----------------------------------------------------------------------------
  2755. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2756. {
  2757. std::string prefix;
  2758. std::string base;
  2759. std::string suffix;
  2760. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2761. std::vector<std::string> props;
  2762. std::string configUpper =
  2763. cmSystemTools::UpperCase(config);
  2764. if(!configUpper.empty())
  2765. {
  2766. // PDB_NAME_<CONFIG>
  2767. props.push_back("PDB_NAME_" + configUpper);
  2768. }
  2769. // PDB_NAME
  2770. props.push_back("PDB_NAME");
  2771. for(std::vector<std::string>::const_iterator i = props.begin();
  2772. i != props.end(); ++i)
  2773. {
  2774. if(const char* outName = this->GetProperty(*i))
  2775. {
  2776. base = outName;
  2777. break;
  2778. }
  2779. }
  2780. return prefix+base+".pdb";
  2781. }
  2782. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  2783. cmTarget const* t2) const
  2784. {
  2785. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2786. if (nameResult == 0)
  2787. {
  2788. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  2789. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  2790. }
  2791. return nameResult < 0;
  2792. }
  2793. //----------------------------------------------------------------------------
  2794. struct cmGeneratorTarget::SourceFileFlags
  2795. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2796. {
  2797. struct SourceFileFlags flags;
  2798. this->ConstructSourceFileFlags();
  2799. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  2800. this->SourceFlagsMap.find(sf);
  2801. if(si != this->SourceFlagsMap.end())
  2802. {
  2803. flags = si->second;
  2804. }
  2805. else
  2806. {
  2807. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  2808. // were not listed in one of the other lists.
  2809. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  2810. {
  2811. flags.MacFolder = location;
  2812. if(strcmp(location, "Resources") == 0)
  2813. {
  2814. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2815. }
  2816. else
  2817. {
  2818. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  2819. }
  2820. }
  2821. }
  2822. return flags;
  2823. }
  2824. //----------------------------------------------------------------------------
  2825. void cmGeneratorTarget::ConstructSourceFileFlags() const
  2826. {
  2827. if(this->SourceFileFlagsConstructed)
  2828. {
  2829. return;
  2830. }
  2831. this->SourceFileFlagsConstructed = true;
  2832. // Process public headers to mark the source files.
  2833. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  2834. {
  2835. std::vector<std::string> relFiles;
  2836. cmSystemTools::ExpandListArgument(files, relFiles);
  2837. for(std::vector<std::string>::iterator it = relFiles.begin();
  2838. it != relFiles.end(); ++it)
  2839. {
  2840. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2841. {
  2842. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2843. flags.MacFolder = "Headers";
  2844. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  2845. }
  2846. }
  2847. }
  2848. // Process private headers after public headers so that they take
  2849. // precedence if a file is listed in both.
  2850. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  2851. {
  2852. std::vector<std::string> relFiles;
  2853. cmSystemTools::ExpandListArgument(files, relFiles);
  2854. for(std::vector<std::string>::iterator it = relFiles.begin();
  2855. it != relFiles.end(); ++it)
  2856. {
  2857. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2858. {
  2859. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2860. flags.MacFolder = "PrivateHeaders";
  2861. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  2862. }
  2863. }
  2864. }
  2865. // Mark sources listed as resources.
  2866. if(const char* files = this->Target->GetProperty("RESOURCE"))
  2867. {
  2868. std::vector<std::string> relFiles;
  2869. cmSystemTools::ExpandListArgument(files, relFiles);
  2870. for(std::vector<std::string>::iterator it = relFiles.begin();
  2871. it != relFiles.end(); ++it)
  2872. {
  2873. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2874. {
  2875. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2876. flags.MacFolder = "Resources";
  2877. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2878. }
  2879. }
  2880. }
  2881. }
  2882. //----------------------------------------------------------------------------
  2883. const cmGeneratorTarget::CompatibleInterfacesBase&
  2884. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  2885. {
  2886. cmGeneratorTarget::CompatibleInterfaces& compat =
  2887. this->CompatibleInterfacesMap[config];
  2888. if(!compat.Done)
  2889. {
  2890. compat.Done = true;
  2891. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  2892. compat.PropsString.insert("AUTOUIC_OPTIONS");
  2893. std::vector<cmTarget const*> const& deps =
  2894. this->GetLinkImplementationClosure(config);
  2895. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  2896. li != deps.end(); ++li)
  2897. {
  2898. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  2899. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  2900. { \
  2901. std::vector<std::string> props; \
  2902. cmSystemTools::ExpandListArgument(prop, props); \
  2903. compat.Props##x.insert(props.begin(), props.end()); \
  2904. }
  2905. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  2906. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  2907. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  2908. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  2909. #undef CM_READ_COMPATIBLE_INTERFACE
  2910. }
  2911. }
  2912. return compat;
  2913. }
  2914. //----------------------------------------------------------------------------
  2915. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  2916. const std::string &p, const std::string& config) const
  2917. {
  2918. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2919. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2920. {
  2921. return false;
  2922. }
  2923. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  2924. }
  2925. //----------------------------------------------------------------------------
  2926. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  2927. const std::string &p, const std::string& config) const
  2928. {
  2929. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2930. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2931. {
  2932. return false;
  2933. }
  2934. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  2935. }
  2936. //----------------------------------------------------------------------------
  2937. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  2938. const std::string &p, const std::string& config) const
  2939. {
  2940. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2941. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2942. {
  2943. return false;
  2944. }
  2945. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  2946. }
  2947. //----------------------------------------------------------------------------
  2948. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  2949. const std::string &p, const std::string& config) const
  2950. {
  2951. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2952. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2953. {
  2954. return false;
  2955. }
  2956. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  2957. }
  2958. enum CompatibleType
  2959. {
  2960. BoolType,
  2961. StringType,
  2962. NumberMinType,
  2963. NumberMaxType
  2964. };
  2965. template<typename PropertyType>
  2966. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2967. const std::string& prop,
  2968. const std::string& config,
  2969. CompatibleType,
  2970. PropertyType *);
  2971. template<>
  2972. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2973. const std::string& prop,
  2974. const std::string& config,
  2975. CompatibleType, bool *)
  2976. {
  2977. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  2978. }
  2979. template<>
  2980. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2981. const std::string& prop,
  2982. const std::string& config,
  2983. CompatibleType t,
  2984. const char **)
  2985. {
  2986. switch(t)
  2987. {
  2988. case BoolType:
  2989. assert(0 && "String compatibility check function called for boolean");
  2990. return 0;
  2991. case StringType:
  2992. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  2993. case NumberMinType:
  2994. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  2995. case NumberMaxType:
  2996. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  2997. }
  2998. assert(0 && "Unreachable!");
  2999. return 0;
  3000. }
  3001. //----------------------------------------------------------------------------
  3002. template<typename PropertyType>
  3003. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3004. cmTarget const* dependee,
  3005. const std::string& propName,
  3006. std::set<std::string> &emitted,
  3007. const std::string& config,
  3008. CompatibleType t,
  3009. PropertyType *)
  3010. {
  3011. const char *prop = dependee->GetProperty(propName);
  3012. if (!prop)
  3013. {
  3014. return;
  3015. }
  3016. std::vector<std::string> props;
  3017. cmSystemTools::ExpandListArgument(prop, props);
  3018. std::string pdir =
  3019. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  3020. pdir += "/Help/prop_tgt/";
  3021. for(std::vector<std::string>::iterator pi = props.begin();
  3022. pi != props.end(); ++pi)
  3023. {
  3024. std::string pname = cmSystemTools::HelpFileName(*pi);
  3025. std::string pfile = pdir + pname + ".rst";
  3026. if(cmSystemTools::FileExists(pfile.c_str(), true))
  3027. {
  3028. std::ostringstream e;
  3029. e << "Target \"" << dependee->GetName() << "\" has property \""
  3030. << *pi << "\" listed in its " << propName << " property. "
  3031. "This is not allowed. Only user-defined properties may appear "
  3032. "listed in the " << propName << " property.";
  3033. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  3034. return;
  3035. }
  3036. if(emitted.insert(*pi).second)
  3037. {
  3038. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  3039. t, 0);
  3040. if (cmSystemTools::GetErrorOccuredFlag())
  3041. {
  3042. return;
  3043. }
  3044. }
  3045. }
  3046. }
  3047. static std::string intersect(const std::set<std::string> &s1,
  3048. const std::set<std::string> &s2)
  3049. {
  3050. std::set<std::string> intersect;
  3051. std::set_intersection(s1.begin(),s1.end(),
  3052. s2.begin(),s2.end(),
  3053. std::inserter(intersect,intersect.begin()));
  3054. if (!intersect.empty())
  3055. {
  3056. return *intersect.begin();
  3057. }
  3058. return "";
  3059. }
  3060. static std::string intersect(const std::set<std::string> &s1,
  3061. const std::set<std::string> &s2,
  3062. const std::set<std::string> &s3)
  3063. {
  3064. std::string result;
  3065. result = intersect(s1, s2);
  3066. if (!result.empty())
  3067. return result;
  3068. result = intersect(s1, s3);
  3069. if (!result.empty())
  3070. return result;
  3071. return intersect(s2, s3);
  3072. }
  3073. static std::string intersect(const std::set<std::string> &s1,
  3074. const std::set<std::string> &s2,
  3075. const std::set<std::string> &s3,
  3076. const std::set<std::string> &s4)
  3077. {
  3078. std::string result;
  3079. result = intersect(s1, s2);
  3080. if (!result.empty())
  3081. return result;
  3082. result = intersect(s1, s3);
  3083. if (!result.empty())
  3084. return result;
  3085. result = intersect(s1, s4);
  3086. if (!result.empty())
  3087. return result;
  3088. return intersect(s2, s3, s4);
  3089. }
  3090. //----------------------------------------------------------------------------
  3091. void cmGeneratorTarget::CheckPropertyCompatibility(
  3092. cmComputeLinkInformation *info, const std::string& config) const
  3093. {
  3094. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  3095. std::set<std::string> emittedBools;
  3096. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3097. std::set<std::string> emittedStrings;
  3098. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3099. std::set<std::string> emittedMinNumbers;
  3100. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3101. std::set<std::string> emittedMaxNumbers;
  3102. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3103. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  3104. deps.begin(); li != deps.end(); ++li)
  3105. {
  3106. if (!li->Target)
  3107. {
  3108. continue;
  3109. }
  3110. checkPropertyConsistency<bool>(this, li->Target,
  3111. strBool,
  3112. emittedBools, config, BoolType, 0);
  3113. if (cmSystemTools::GetErrorOccuredFlag())
  3114. {
  3115. return;
  3116. }
  3117. checkPropertyConsistency<const char *>(this, li->Target,
  3118. strString,
  3119. emittedStrings, config,
  3120. StringType, 0);
  3121. if (cmSystemTools::GetErrorOccuredFlag())
  3122. {
  3123. return;
  3124. }
  3125. checkPropertyConsistency<const char *>(this, li->Target,
  3126. strNumMin,
  3127. emittedMinNumbers, config,
  3128. NumberMinType, 0);
  3129. if (cmSystemTools::GetErrorOccuredFlag())
  3130. {
  3131. return;
  3132. }
  3133. checkPropertyConsistency<const char *>(this, li->Target,
  3134. strNumMax,
  3135. emittedMaxNumbers, config,
  3136. NumberMaxType, 0);
  3137. if (cmSystemTools::GetErrorOccuredFlag())
  3138. {
  3139. return;
  3140. }
  3141. }
  3142. std::string prop = intersect(emittedBools,
  3143. emittedStrings,
  3144. emittedMinNumbers,
  3145. emittedMaxNumbers);
  3146. if (!prop.empty())
  3147. {
  3148. // Use a sorted std::vector to keep the error message sorted.
  3149. std::vector<std::string> props;
  3150. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3151. if (i != emittedBools.end())
  3152. {
  3153. props.push_back(strBool);
  3154. }
  3155. i = emittedStrings.find(prop);
  3156. if (i != emittedStrings.end())
  3157. {
  3158. props.push_back(strString);
  3159. }
  3160. i = emittedMinNumbers.find(prop);
  3161. if (i != emittedMinNumbers.end())
  3162. {
  3163. props.push_back(strNumMin);
  3164. }
  3165. i = emittedMaxNumbers.find(prop);
  3166. if (i != emittedMaxNumbers.end())
  3167. {
  3168. props.push_back(strNumMax);
  3169. }
  3170. std::sort(props.begin(), props.end());
  3171. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3172. propsString += " and the " + props.back();
  3173. std::ostringstream e;
  3174. e << "Property \"" << prop << "\" appears in both the "
  3175. << propsString <<
  3176. " property in the dependencies of target \"" << this->GetName() <<
  3177. "\". This is not allowed. A property may only require compatibility "
  3178. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  3179. "string interpretation, but not a mixture.";
  3180. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3181. }
  3182. }
  3183. //----------------------------------------------------------------------------
  3184. std::string compatibilityType(CompatibleType t)
  3185. {
  3186. switch(t)
  3187. {
  3188. case BoolType:
  3189. return "Boolean compatibility";
  3190. case StringType:
  3191. return "String compatibility";
  3192. case NumberMaxType:
  3193. return "Numeric maximum compatibility";
  3194. case NumberMinType:
  3195. return "Numeric minimum compatibility";
  3196. }
  3197. assert(0 && "Unreachable!");
  3198. return "";
  3199. }
  3200. //----------------------------------------------------------------------------
  3201. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3202. {
  3203. switch(t)
  3204. {
  3205. case BoolType:
  3206. case StringType:
  3207. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3208. case NumberMaxType:
  3209. case NumberMinType:
  3210. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3211. }
  3212. assert(0 && "Unreachable!");
  3213. return "";
  3214. }
  3215. //----------------------------------------------------------------------------
  3216. template<typename PropertyType>
  3217. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  3218. //----------------------------------------------------------------------------
  3219. template<>
  3220. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  3221. {
  3222. return tgt->GetPropertyAsBool(prop);
  3223. }
  3224. //----------------------------------------------------------------------------
  3225. template<>
  3226. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  3227. const std::string& prop)
  3228. {
  3229. return tgt->GetProperty(prop);
  3230. }
  3231. template<typename PropertyType>
  3232. std::string valueAsString(PropertyType);
  3233. template<>
  3234. std::string valueAsString<bool>(bool value)
  3235. {
  3236. return value ? "TRUE" : "FALSE";
  3237. }
  3238. template<>
  3239. std::string valueAsString<const char*>(const char* value)
  3240. {
  3241. return value ? value : "(unset)";
  3242. }
  3243. template<typename PropertyType>
  3244. PropertyType impliedValue(PropertyType);
  3245. template<>
  3246. bool impliedValue<bool>(bool)
  3247. {
  3248. return false;
  3249. }
  3250. template<>
  3251. const char* impliedValue<const char*>(const char*)
  3252. {
  3253. return "";
  3254. }
  3255. //----------------------------------------------------------------------------
  3256. template<typename PropertyType>
  3257. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3258. PropertyType rhs,
  3259. CompatibleType t);
  3260. //----------------------------------------------------------------------------
  3261. template<>
  3262. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3263. CompatibleType)
  3264. {
  3265. return std::make_pair(lhs == rhs, lhs);
  3266. }
  3267. //----------------------------------------------------------------------------
  3268. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  3269. const char *rhs)
  3270. {
  3271. const bool b = strcmp(lhs, rhs) == 0;
  3272. return std::make_pair(b, b ? lhs : 0);
  3273. }
  3274. //----------------------------------------------------------------------------
  3275. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  3276. const char *rhs,
  3277. CompatibleType t)
  3278. {
  3279. char *pEnd;
  3280. const char* const null_ptr = 0;
  3281. long lnum = strtol(lhs, &pEnd, 0);
  3282. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  3283. {
  3284. return std::pair<bool, const char*>(false, null_ptr);
  3285. }
  3286. long rnum = strtol(rhs, &pEnd, 0);
  3287. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  3288. {
  3289. return std::pair<bool, const char*>(false, null_ptr);
  3290. }
  3291. if (t == NumberMaxType)
  3292. {
  3293. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3294. }
  3295. else
  3296. {
  3297. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3298. }
  3299. }
  3300. //----------------------------------------------------------------------------
  3301. template<>
  3302. std::pair<bool, const char*> consistentProperty(const char *lhs,
  3303. const char *rhs,
  3304. CompatibleType t)
  3305. {
  3306. if (!lhs && !rhs)
  3307. {
  3308. return std::make_pair(true, lhs);
  3309. }
  3310. if (!lhs)
  3311. {
  3312. return std::make_pair(true, rhs);
  3313. }
  3314. if (!rhs)
  3315. {
  3316. return std::make_pair(true, lhs);
  3317. }
  3318. const char* const null_ptr = 0;
  3319. switch(t)
  3320. {
  3321. case BoolType:
  3322. assert(0 && "consistentProperty for strings called with BoolType");
  3323. return std::pair<bool, const char*>(false, null_ptr);
  3324. case StringType:
  3325. return consistentStringProperty(lhs, rhs);
  3326. case NumberMinType:
  3327. case NumberMaxType:
  3328. return consistentNumberProperty(lhs, rhs, t);
  3329. }
  3330. assert(0 && "Unreachable!");
  3331. return std::pair<bool, const char*>(false, null_ptr);
  3332. }
  3333. //----------------------------------------------------------------------------
  3334. template<typename PropertyType>
  3335. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3336. const std::string &p,
  3337. const std::string& config,
  3338. const char *defaultValue,
  3339. CompatibleType t,
  3340. PropertyType *)
  3341. {
  3342. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  3343. const bool explicitlySet = tgt->Target->GetProperties()
  3344. .find(p)
  3345. != tgt->Target->GetProperties().end();
  3346. const bool impliedByUse =
  3347. tgt->Target->IsNullImpliedByLinkLibraries(p);
  3348. assert((impliedByUse ^ explicitlySet)
  3349. || (!impliedByUse && !explicitlySet));
  3350. std::vector<cmTarget const*> const& deps =
  3351. tgt->GetLinkImplementationClosure(config);
  3352. if(deps.empty())
  3353. {
  3354. return propContent;
  3355. }
  3356. bool propInitialized = explicitlySet;
  3357. std::string report = " * Target \"";
  3358. report += tgt->GetName();
  3359. if (explicitlySet)
  3360. {
  3361. report += "\" has property content \"";
  3362. report += valueAsString<PropertyType>(propContent);
  3363. report += "\"\n";
  3364. }
  3365. else if (impliedByUse)
  3366. {
  3367. report += "\" property is implied by use.\n";
  3368. }
  3369. else
  3370. {
  3371. report += "\" property not set.\n";
  3372. }
  3373. std::string interfaceProperty = "INTERFACE_" + p;
  3374. for(std::vector<cmTarget const*>::const_iterator li =
  3375. deps.begin();
  3376. li != deps.end(); ++li)
  3377. {
  3378. // An error should be reported if one dependency
  3379. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3380. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3381. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3382. // with a dependency.
  3383. cmTarget const* theTarget = *li;
  3384. const bool ifaceIsSet = theTarget->GetProperties()
  3385. .find(interfaceProperty)
  3386. != theTarget->GetProperties().end();
  3387. PropertyType ifacePropContent =
  3388. getTypedProperty<PropertyType>(theTarget,
  3389. interfaceProperty);
  3390. std::string reportEntry;
  3391. if (ifaceIsSet)
  3392. {
  3393. reportEntry += " * Target \"";
  3394. reportEntry += theTarget->GetName();
  3395. reportEntry += "\" property value \"";
  3396. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3397. reportEntry += "\" ";
  3398. }
  3399. if (explicitlySet)
  3400. {
  3401. if (ifaceIsSet)
  3402. {
  3403. std::pair<bool, PropertyType> consistent =
  3404. consistentProperty(propContent,
  3405. ifacePropContent, t);
  3406. report += reportEntry;
  3407. report += compatibilityAgree(t, propContent != consistent.second);
  3408. if (!consistent.first)
  3409. {
  3410. std::ostringstream e;
  3411. e << "Property " << p << " on target \""
  3412. << tgt->GetName() << "\" does\nnot match the "
  3413. "INTERFACE_" << p << " property requirement\nof "
  3414. "dependency \"" << theTarget->GetName() << "\".\n";
  3415. cmSystemTools::Error(e.str().c_str());
  3416. break;
  3417. }
  3418. else
  3419. {
  3420. propContent = consistent.second;
  3421. continue;
  3422. }
  3423. }
  3424. else
  3425. {
  3426. // Explicitly set on target and not set in iface. Can't disagree.
  3427. continue;
  3428. }
  3429. }
  3430. else if (impliedByUse)
  3431. {
  3432. propContent = impliedValue<PropertyType>(propContent);
  3433. if (ifaceIsSet)
  3434. {
  3435. std::pair<bool, PropertyType> consistent =
  3436. consistentProperty(propContent,
  3437. ifacePropContent, t);
  3438. report += reportEntry;
  3439. report += compatibilityAgree(t, propContent != consistent.second);
  3440. if (!consistent.first)
  3441. {
  3442. std::ostringstream e;
  3443. e << "Property " << p << " on target \""
  3444. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  3445. << " because it was used to determine the link libraries\n"
  3446. "already. The INTERFACE_" << p << " property on\ndependency \""
  3447. << theTarget->GetName() << "\" is in conflict.\n";
  3448. cmSystemTools::Error(e.str().c_str());
  3449. break;
  3450. }
  3451. else
  3452. {
  3453. propContent = consistent.second;
  3454. continue;
  3455. }
  3456. }
  3457. else
  3458. {
  3459. // Implicitly set on target and not set in iface. Can't disagree.
  3460. continue;
  3461. }
  3462. }
  3463. else
  3464. {
  3465. if (ifaceIsSet)
  3466. {
  3467. if (propInitialized)
  3468. {
  3469. std::pair<bool, PropertyType> consistent =
  3470. consistentProperty(propContent,
  3471. ifacePropContent, t);
  3472. report += reportEntry;
  3473. report += compatibilityAgree(t, propContent != consistent.second);
  3474. if (!consistent.first)
  3475. {
  3476. std::ostringstream e;
  3477. e << "The INTERFACE_" << p << " property of \""
  3478. << theTarget->GetName() << "\" does\nnot agree with the value "
  3479. "of " << p << " already determined\nfor \""
  3480. << tgt->GetName() << "\".\n";
  3481. cmSystemTools::Error(e.str().c_str());
  3482. break;
  3483. }
  3484. else
  3485. {
  3486. propContent = consistent.second;
  3487. continue;
  3488. }
  3489. }
  3490. else
  3491. {
  3492. report += reportEntry + "(Interface set)\n";
  3493. propContent = ifacePropContent;
  3494. propInitialized = true;
  3495. }
  3496. }
  3497. else
  3498. {
  3499. // Not set. Nothing to agree on.
  3500. continue;
  3501. }
  3502. }
  3503. }
  3504. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  3505. report, compatibilityType(t));
  3506. return propContent;
  3507. }
  3508. //----------------------------------------------------------------------------
  3509. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  3510. const std::string &p, const std::string& config) const
  3511. {
  3512. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  3513. "FALSE",
  3514. BoolType, 0);
  3515. }
  3516. //----------------------------------------------------------------------------
  3517. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  3518. const std::string &p,
  3519. const std::string& config) const
  3520. {
  3521. return checkInterfacePropertyCompatibility<const char *>(this,
  3522. p,
  3523. config,
  3524. "empty",
  3525. StringType, 0);
  3526. }
  3527. //----------------------------------------------------------------------------
  3528. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  3529. const std::string &p,
  3530. const std::string& config) const
  3531. {
  3532. return checkInterfacePropertyCompatibility<const char *>(this,
  3533. p,
  3534. config,
  3535. "empty",
  3536. NumberMinType, 0);
  3537. }
  3538. //----------------------------------------------------------------------------
  3539. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3540. const std::string &p,
  3541. const std::string& config) const
  3542. {
  3543. return checkInterfacePropertyCompatibility<const char *>(this,
  3544. p,
  3545. config,
  3546. "empty",
  3547. NumberMaxType, 0);
  3548. }
  3549. //----------------------------------------------------------------------------
  3550. cmComputeLinkInformation*
  3551. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  3552. {
  3553. // Lookup any existing information for this configuration.
  3554. std::string key(cmSystemTools::UpperCase(config));
  3555. cmTargetLinkInformationMap::iterator
  3556. i = this->LinkInformation.find(key);
  3557. if(i == this->LinkInformation.end())
  3558. {
  3559. // Compute information for this configuration.
  3560. cmComputeLinkInformation* info =
  3561. new cmComputeLinkInformation(this, config);
  3562. if(!info || !info->Compute())
  3563. {
  3564. delete info;
  3565. info = 0;
  3566. }
  3567. // Store the information for this configuration.
  3568. cmTargetLinkInformationMap::value_type entry(key, info);
  3569. i = this->LinkInformation.insert(entry).first;
  3570. if (info)
  3571. {
  3572. this->CheckPropertyCompatibility(info, config);
  3573. }
  3574. }
  3575. return i->second;
  3576. }
  3577. //----------------------------------------------------------------------------
  3578. void
  3579. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  3580. const std::string &result,
  3581. const std::string &report,
  3582. const std::string &compatibilityType) const
  3583. {
  3584. std::vector<std::string> debugProperties;
  3585. const char *debugProp = this->Target->GetMakefile()
  3586. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  3587. if (debugProp)
  3588. {
  3589. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3590. }
  3591. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  3592. && std::find(debugProperties.begin(),
  3593. debugProperties.end(),
  3594. p)
  3595. != debugProperties.end();
  3596. if (this->Target->GetMakefile()->IsConfigured())
  3597. {
  3598. this->DebugCompatiblePropertiesDone[p] = true;
  3599. }
  3600. if (!debugOrigin)
  3601. {
  3602. return;
  3603. }
  3604. std::string areport = compatibilityType;
  3605. areport += std::string(" of property \"") + p + "\" for target \"";
  3606. areport += std::string(this->GetName());
  3607. areport += "\" (result: \"";
  3608. areport += result;
  3609. areport += "\"):\n" + report;
  3610. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3611. }
  3612. //----------------------------------------------------------------------------
  3613. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3614. std::vector<cmLinkItem>& items) const
  3615. {
  3616. for(std::vector<std::string>::const_iterator i = names.begin();
  3617. i != names.end(); ++i)
  3618. {
  3619. std::string name = this->Target->CheckCMP0004(*i);
  3620. if(name == this->GetName() || name.empty())
  3621. {
  3622. continue;
  3623. }
  3624. items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
  3625. }
  3626. }
  3627. //----------------------------------------------------------------------------
  3628. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  3629. std::string const& value,
  3630. std::string const& config,
  3631. cmTarget const* headTarget,
  3632. bool usage_requirements_only,
  3633. std::vector<cmLinkItem>& items,
  3634. bool& hadHeadSensitiveCondition) const
  3635. {
  3636. cmGeneratorExpression ge;
  3637. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3638. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3639. // link dependencies that are otherwise excluded from usage requirements.
  3640. if(usage_requirements_only)
  3641. {
  3642. dagChecker.SetTransitivePropertiesOnly();
  3643. }
  3644. std::vector<std::string> libs;
  3645. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3646. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3647. this->Makefile,
  3648. config,
  3649. false,
  3650. headTarget,
  3651. this->Target, &dagChecker), libs);
  3652. this->LookupLinkItems(libs, items);
  3653. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3654. }
  3655. //----------------------------------------------------------------------------
  3656. cmLinkInterface const*
  3657. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  3658. cmTarget const* head) const
  3659. {
  3660. // Imported targets have their own link interface.
  3661. if(this->IsImported())
  3662. {
  3663. return this->GetImportLinkInterface(config, head, false);
  3664. }
  3665. // Link interfaces are not supported for executables that do not
  3666. // export symbols.
  3667. if(this->GetType() == cmTarget::EXECUTABLE &&
  3668. !this->Target->IsExecutableWithExports())
  3669. {
  3670. return 0;
  3671. }
  3672. // Lookup any existing link interface for this configuration.
  3673. cmHeadToLinkInterfaceMap& hm =
  3674. this->GetHeadToLinkInterfaceMap(config);
  3675. // If the link interface does not depend on the head target
  3676. // then return the one we computed first.
  3677. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3678. {
  3679. return &hm.begin()->second;
  3680. }
  3681. cmOptionalLinkInterface& iface = hm[head];
  3682. if(!iface.LibrariesDone)
  3683. {
  3684. iface.LibrariesDone = true;
  3685. this->ComputeLinkInterfaceLibraries(
  3686. config, iface, head, false);
  3687. }
  3688. if(!iface.AllDone)
  3689. {
  3690. iface.AllDone = true;
  3691. if(iface.Exists)
  3692. {
  3693. this->ComputeLinkInterface(config, iface, head);
  3694. }
  3695. }
  3696. return iface.Exists? &iface : 0;
  3697. }
  3698. //----------------------------------------------------------------------------
  3699. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  3700. cmOptionalLinkInterface &iface,
  3701. cmTarget const* headTarget) const
  3702. {
  3703. if(iface.ExplicitLibraries)
  3704. {
  3705. if(this->GetType() == cmTarget::SHARED_LIBRARY
  3706. || this->GetType() == cmTarget::STATIC_LIBRARY
  3707. || this->GetType() == cmTarget::INTERFACE_LIBRARY)
  3708. {
  3709. // Shared libraries may have runtime implementation dependencies
  3710. // on other shared libraries that are not in the interface.
  3711. UNORDERED_SET<std::string> emitted;
  3712. for(std::vector<cmLinkItem>::const_iterator
  3713. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3714. {
  3715. emitted.insert(*li);
  3716. }
  3717. if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
  3718. {
  3719. cmLinkImplementation const* impl =
  3720. this->GetLinkImplementation(config);
  3721. for(std::vector<cmLinkImplItem>::const_iterator
  3722. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3723. {
  3724. if(emitted.insert(*li).second)
  3725. {
  3726. if(li->Target)
  3727. {
  3728. // This is a runtime dependency on another shared library.
  3729. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  3730. {
  3731. iface.SharedDeps.push_back(*li);
  3732. }
  3733. }
  3734. else
  3735. {
  3736. // TODO: Recognize shared library file names. Perhaps this
  3737. // should be moved to cmComputeLinkInformation, but that creates
  3738. // a chicken-and-egg problem since this list is needed for its
  3739. // construction.
  3740. }
  3741. }
  3742. }
  3743. }
  3744. }
  3745. }
  3746. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3747. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3748. {
  3749. // The link implementation is the default link interface.
  3750. cmLinkImplementationLibraries const*
  3751. impl = this->Target->GetLinkImplementationLibrariesInternal(config,
  3752. headTarget);
  3753. iface.ImplementationIsInterface = true;
  3754. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3755. }
  3756. if(this->Target->LinkLanguagePropagatesToDependents())
  3757. {
  3758. // Targets using this archive need its language runtime libraries.
  3759. if(cmLinkImplementation const* impl =
  3760. this->GetLinkImplementation(config))
  3761. {
  3762. iface.Languages = impl->Languages;
  3763. }
  3764. }
  3765. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3766. {
  3767. // Construct the property name suffix for this configuration.
  3768. std::string suffix = "_";
  3769. if(!config.empty())
  3770. {
  3771. suffix += cmSystemTools::UpperCase(config);
  3772. }
  3773. else
  3774. {
  3775. suffix += "NOCONFIG";
  3776. }
  3777. // How many repetitions are needed if this library has cyclic
  3778. // dependencies?
  3779. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3780. propName += suffix;
  3781. if(const char* config_reps = this->GetProperty(propName))
  3782. {
  3783. sscanf(config_reps, "%u", &iface.Multiplicity);
  3784. }
  3785. else if(const char* reps =
  3786. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  3787. {
  3788. sscanf(reps, "%u", &iface.Multiplicity);
  3789. }
  3790. }
  3791. }
  3792. //----------------------------------------------------------------------------
  3793. const cmLinkInterfaceLibraries *
  3794. cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
  3795. cmTarget const* head,
  3796. bool usage_requirements_only) const
  3797. {
  3798. // Imported targets have their own link interface.
  3799. if(this->IsImported())
  3800. {
  3801. return this->GetImportLinkInterface(config, head,
  3802. usage_requirements_only);
  3803. }
  3804. // Link interfaces are not supported for executables that do not
  3805. // export symbols.
  3806. if(this->GetType() == cmTarget::EXECUTABLE &&
  3807. !this->Target->IsExecutableWithExports())
  3808. {
  3809. return 0;
  3810. }
  3811. // Lookup any existing link interface for this configuration.
  3812. std::string CONFIG = cmSystemTools::UpperCase(config);
  3813. cmHeadToLinkInterfaceMap& hm =
  3814. (usage_requirements_only ?
  3815. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3816. this->GetHeadToLinkInterfaceMap(config));
  3817. // If the link interface does not depend on the head target
  3818. // then return the one we computed first.
  3819. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3820. {
  3821. return &hm.begin()->second;
  3822. }
  3823. cmOptionalLinkInterface& iface = hm[head];
  3824. if(!iface.LibrariesDone)
  3825. {
  3826. iface.LibrariesDone = true;
  3827. this->ComputeLinkInterfaceLibraries(
  3828. config, iface, head, usage_requirements_only);
  3829. }
  3830. return iface.Exists? &iface : 0;
  3831. }
  3832. //----------------------------------------------------------------------------
  3833. void
  3834. cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  3835. const std::string& config,
  3836. cmOptionalLinkInterface& iface,
  3837. cmTarget const* headTarget,
  3838. bool usage_requirements_only) const
  3839. {
  3840. // Construct the property name suffix for this configuration.
  3841. std::string suffix = "_";
  3842. if(!config.empty())
  3843. {
  3844. suffix += cmSystemTools::UpperCase(config);
  3845. }
  3846. else
  3847. {
  3848. suffix += "NOCONFIG";
  3849. }
  3850. // An explicit list of interface libraries may be set for shared
  3851. // libraries and executables that export symbols.
  3852. const char* explicitLibraries = 0;
  3853. std::string linkIfaceProp;
  3854. if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  3855. this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  3856. {
  3857. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  3858. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  3859. explicitLibraries = this->GetProperty(linkIfaceProp);
  3860. }
  3861. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3862. this->Target->IsExecutableWithExports())
  3863. {
  3864. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  3865. // shared lib or executable.
  3866. // Lookup the per-configuration property.
  3867. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3868. linkIfaceProp += suffix;
  3869. explicitLibraries = this->GetProperty(linkIfaceProp);
  3870. // If not set, try the generic property.
  3871. if(!explicitLibraries)
  3872. {
  3873. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3874. explicitLibraries = this->GetProperty(linkIfaceProp);
  3875. }
  3876. }
  3877. if(explicitLibraries &&
  3878. this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3879. !this->PolicyWarnedCMP0022)
  3880. {
  3881. // Compare the explicitly set old link interface properties to the
  3882. // preferred new link interface property one and warn if different.
  3883. const char* newExplicitLibraries =
  3884. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  3885. if (newExplicitLibraries
  3886. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  3887. {
  3888. std::ostringstream w;
  3889. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3890. "Target \"" << this->GetName() << "\" has an "
  3891. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  3892. linkIfaceProp << " properties."
  3893. "\n"
  3894. "INTERFACE_LINK_LIBRARIES:\n"
  3895. " " << newExplicitLibraries << "\n" <<
  3896. linkIfaceProp << ":\n"
  3897. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  3898. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3899. this->PolicyWarnedCMP0022 = true;
  3900. }
  3901. }
  3902. // There is no implicit link interface for executables or modules
  3903. // so if none was explicitly set then there is no link interface.
  3904. if(!explicitLibraries &&
  3905. (this->GetType() == cmTarget::EXECUTABLE ||
  3906. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  3907. {
  3908. return;
  3909. }
  3910. iface.Exists = true;
  3911. iface.ExplicitLibraries = explicitLibraries;
  3912. if(explicitLibraries)
  3913. {
  3914. // The interface libraries have been explicitly set.
  3915. this->ExpandLinkItems(linkIfaceProp, explicitLibraries,
  3916. config,
  3917. headTarget, usage_requirements_only,
  3918. iface.Libraries,
  3919. iface.HadHeadSensitiveCondition);
  3920. }
  3921. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3922. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3923. // If CMP0022 is NEW then the plain tll signature sets the
  3924. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  3925. // cleared the property explicitly and we should not fall back
  3926. // to the link implementation.
  3927. {
  3928. // The link implementation is the default link interface.
  3929. cmLinkImplementationLibraries const* impl =
  3930. this->Target->GetLinkImplementationLibrariesInternal(config,
  3931. headTarget);
  3932. iface.Libraries.insert(iface.Libraries.end(),
  3933. impl->Libraries.begin(), impl->Libraries.end());
  3934. if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3935. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  3936. {
  3937. // Compare the link implementation fallback link interface to the
  3938. // preferred new link interface property and warn if different.
  3939. std::vector<cmLinkItem> ifaceLibs;
  3940. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  3941. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  3942. {
  3943. bool hadHeadSensitiveConditionDummy = false;
  3944. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  3945. headTarget, usage_requirements_only,
  3946. ifaceLibs, hadHeadSensitiveConditionDummy);
  3947. }
  3948. if (ifaceLibs != iface.Libraries)
  3949. {
  3950. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  3951. std::string newLibraries = cmJoin(ifaceLibs, ";");
  3952. if(oldLibraries.empty())
  3953. { oldLibraries = "(empty)"; }
  3954. if(newLibraries.empty())
  3955. { newLibraries = "(empty)"; }
  3956. std::ostringstream w;
  3957. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3958. "Target \"" << this->GetName() << "\" has an "
  3959. "INTERFACE_LINK_LIBRARIES property. "
  3960. "This should be preferred as the source of the link interface "
  3961. "for this library but because CMP0022 is not set CMake is "
  3962. "ignoring the property and using the link implementation "
  3963. "as the link interface instead."
  3964. "\n"
  3965. "INTERFACE_LINK_LIBRARIES:\n"
  3966. " " << newLibraries << "\n"
  3967. "Link implementation:\n"
  3968. " " << oldLibraries << "\n";
  3969. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3970. this->PolicyWarnedCMP0022 = true;
  3971. }
  3972. }
  3973. }
  3974. }
  3975. //----------------------------------------------------------------------------
  3976. const cmLinkInterface *
  3977. cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
  3978. cmTarget const* headTarget,
  3979. bool usage_requirements_only) const
  3980. {
  3981. cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config);
  3982. if(!info)
  3983. {
  3984. return 0;
  3985. }
  3986. std::string CONFIG = cmSystemTools::UpperCase(config);
  3987. cmHeadToLinkInterfaceMap& hm =
  3988. (usage_requirements_only ?
  3989. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3990. this->GetHeadToLinkInterfaceMap(config));
  3991. // If the link interface does not depend on the head target
  3992. // then return the one we computed first.
  3993. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3994. {
  3995. return &hm.begin()->second;
  3996. }
  3997. cmOptionalLinkInterface& iface = hm[headTarget];
  3998. if(!iface.AllDone)
  3999. {
  4000. iface.AllDone = true;
  4001. iface.Multiplicity = info->Multiplicity;
  4002. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4003. this->ExpandLinkItems(info->LibrariesProp, info->Libraries,
  4004. config,
  4005. headTarget, usage_requirements_only,
  4006. iface.Libraries,
  4007. iface.HadHeadSensitiveCondition);
  4008. std::vector<std::string> deps;
  4009. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4010. this->LookupLinkItems(deps, iface.SharedDeps);
  4011. }
  4012. return &iface;
  4013. }
  4014. cmHeadToLinkInterfaceMap&
  4015. cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
  4016. {
  4017. std::string CONFIG = cmSystemTools::UpperCase(config);
  4018. return this->LinkInterfaceMap[CONFIG];
  4019. }
  4020. cmHeadToLinkInterfaceMap&
  4021. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  4022. const std::string &config) const
  4023. {
  4024. std::string CONFIG = cmSystemTools::UpperCase(config);
  4025. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  4026. }
  4027. //----------------------------------------------------------------------------
  4028. const cmLinkImplementation *
  4029. cmGeneratorTarget::GetLinkImplementation(const std::string& config) const
  4030. {
  4031. // There is no link implementation for imported targets.
  4032. if(this->Target->IsImported())
  4033. {
  4034. return 0;
  4035. }
  4036. cmOptionalLinkImplementation& impl = this->Target->GetLinkImplMap(config);
  4037. if(!impl.LibrariesDone)
  4038. {
  4039. impl.LibrariesDone = true;
  4040. this->Target->ComputeLinkImplementationLibraries(config, impl,
  4041. this->Target);
  4042. }
  4043. if(!impl.LanguagesDone)
  4044. {
  4045. impl.LanguagesDone = true;
  4046. this->ComputeLinkImplementationLanguages(config, impl);
  4047. }
  4048. return &impl;
  4049. }
  4050. //----------------------------------------------------------------------------
  4051. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  4052. std::vector<cmSourceFile*>& files) const
  4053. {
  4054. std::vector<std::string> configs;
  4055. this->Makefile->GetConfigurations(configs);
  4056. if (configs.empty())
  4057. {
  4058. configs.push_back("");
  4059. }
  4060. std::vector<std::string>::const_iterator it = configs.begin();
  4061. const std::string& firstConfig = *it;
  4062. this->Target->GetSourceFiles(files, firstConfig);
  4063. for ( ; it != configs.end(); ++it)
  4064. {
  4065. std::vector<cmSourceFile*> configFiles;
  4066. this->Target->GetSourceFiles(configFiles, *it);
  4067. if (configFiles != files)
  4068. {
  4069. std::string firstConfigFiles;
  4070. const char* sep = "";
  4071. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  4072. fi != files.end(); ++fi)
  4073. {
  4074. firstConfigFiles += sep;
  4075. firstConfigFiles += (*fi)->GetFullPath();
  4076. sep = "\n ";
  4077. }
  4078. std::string thisConfigFiles;
  4079. sep = "";
  4080. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  4081. fi != configFiles.end(); ++fi)
  4082. {
  4083. thisConfigFiles += sep;
  4084. thisConfigFiles += (*fi)->GetFullPath();
  4085. sep = "\n ";
  4086. }
  4087. std::ostringstream e;
  4088. e << "Target \"" << this->GetName()
  4089. << "\" has source files which vary by "
  4090. "configuration. This is not supported by the \""
  4091. << this->GlobalGenerator->GetName()
  4092. << "\" generator.\n"
  4093. "Config \"" << firstConfig << "\":\n"
  4094. " " << firstConfigFiles << "\n"
  4095. "Config \"" << *it << "\":\n"
  4096. " " << thisConfigFiles << "\n";
  4097. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  4098. return false;
  4099. }
  4100. }
  4101. return true;
  4102. }
  4103. //----------------------------------------------------------------------------
  4104. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  4105. const std::string& config) const
  4106. {
  4107. std::vector<cmSourceFile*> sourceFiles;
  4108. this->GetSourceFiles(sourceFiles, config);
  4109. for(std::vector<cmSourceFile*>::const_iterator
  4110. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  4111. {
  4112. const std::string& lang = (*i)->GetLanguage();
  4113. if(!lang.empty())
  4114. {
  4115. languages.insert(lang);
  4116. }
  4117. }
  4118. std::vector<cmGeneratorTarget*> objectLibraries;
  4119. std::vector<cmSourceFile const*> externalObjects;
  4120. if (!this->Makefile->IsConfigured())
  4121. {
  4122. std::vector<cmTarget*> objectTargets;
  4123. this->Target->GetObjectLibrariesCMP0026(objectTargets);
  4124. objectLibraries.reserve(objectTargets.size());
  4125. for (std::vector<cmTarget*>::const_iterator it = objectTargets.begin();
  4126. it != objectTargets.end(); ++it)
  4127. {
  4128. objectLibraries.push_back(this->GlobalGenerator
  4129. ->GetGeneratorTarget(*it));
  4130. }
  4131. }
  4132. else
  4133. {
  4134. this->GetExternalObjects(externalObjects, config);
  4135. for(std::vector<cmSourceFile const*>::const_iterator
  4136. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  4137. {
  4138. std::string objLib = (*i)->GetObjectLibrary();
  4139. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  4140. {
  4141. objectLibraries.push_back(this->GlobalGenerator
  4142. ->GetGeneratorTarget(tgt));
  4143. }
  4144. }
  4145. }
  4146. for(std::vector<cmGeneratorTarget*>::const_iterator
  4147. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  4148. {
  4149. (*i)->GetLanguages(languages, config);
  4150. }
  4151. }
  4152. //----------------------------------------------------------------------------
  4153. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  4154. const std::string& config,
  4155. cmOptionalLinkImplementation& impl) const
  4156. {
  4157. // This target needs runtime libraries for its source languages.
  4158. std::set<std::string> languages;
  4159. // Get languages used in our source files.
  4160. this->GetLanguages(languages, config);
  4161. // Copy the set of langauges to the link implementation.
  4162. impl.Languages.insert(impl.Languages.begin(),
  4163. languages.begin(), languages.end());
  4164. }
  4165. //----------------------------------------------------------------------------
  4166. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  4167. {
  4168. if (this->Target->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  4169. {
  4170. return false;
  4171. }
  4172. if(cmLinkImplementationLibraries const* impl =
  4173. this->Target->GetLinkImplementationLibraries(config))
  4174. {
  4175. return !impl->Libraries.empty();
  4176. }
  4177. return false;
  4178. }