cmGeneratorTarget.cxx 146 KB

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