cmGeneratorTarget.cxx 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505
  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. //----------------------------------------------------------------------------
  31. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  32. cmGeneratorTarget const* target, cmake *cm)
  33. {
  34. if(!badObjLib.empty())
  35. {
  36. std::ostringstream e;
  37. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  38. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  39. i != badObjLib.end(); ++i)
  40. {
  41. e << " " << (*i)->GetLocation().GetName() << "\n";
  42. }
  43. e << "but may contain only sources that compile, header files, and "
  44. "other files that would not affect linking of a normal library.";
  45. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  46. target->Target->GetBacktrace());
  47. }
  48. }
  49. struct ObjectSourcesTag {};
  50. struct CustomCommandsTag {};
  51. struct ExtraSourcesTag {};
  52. struct HeaderSourcesTag {};
  53. struct ExternalObjectsTag {};
  54. struct IDLSourcesTag {};
  55. struct ResxTag {};
  56. struct ModuleDefinitionFileTag {};
  57. struct AppManifestTag{};
  58. struct CertificatesTag{};
  59. struct XamlTag{};
  60. template<typename Tag, typename OtherTag>
  61. struct IsSameTag
  62. {
  63. enum {
  64. Result = false
  65. };
  66. };
  67. template<typename Tag>
  68. struct IsSameTag<Tag, Tag>
  69. {
  70. enum {
  71. Result = true
  72. };
  73. };
  74. template<bool>
  75. struct DoAccept
  76. {
  77. template <typename T> static void Do(T&, cmSourceFile*) {}
  78. };
  79. template<>
  80. struct DoAccept<true>
  81. {
  82. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  83. {
  84. files.push_back(f);
  85. }
  86. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  87. {
  88. // Build and save the name of the corresponding .h file
  89. // This relationship will be used later when building the project files.
  90. // Both names would have been auto generated from Visual Studio
  91. // where the user supplied the file name and Visual Studio
  92. // appended the suffix.
  93. std::string resx = f->GetFullPath();
  94. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  95. data.ExpectedResxHeaders.insert(hFileName);
  96. data.ResxSources.push_back(f);
  97. }
  98. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  99. {
  100. // Build and save the name of the corresponding .h and .cpp 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 xaml = f->GetFullPath();
  106. std::string hFileName = xaml + ".h";
  107. std::string cppFileName = xaml + ".cpp";
  108. data.ExpectedXamlHeaders.insert(hFileName);
  109. data.ExpectedXamlSources.insert(cppFileName);
  110. data.XamlSources.push_back(f);
  111. }
  112. static void Do(std::string& data, cmSourceFile* f)
  113. {
  114. data = f->GetFullPath();
  115. }
  116. };
  117. //----------------------------------------------------------------------------
  118. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  119. struct TagVisitor
  120. {
  121. DataType& Data;
  122. std::vector<cmSourceFile*> BadObjLibFiles;
  123. cmGeneratorTarget const* Target;
  124. cmGlobalGenerator *GlobalGenerator;
  125. cmsys::RegularExpression Header;
  126. bool IsObjLib;
  127. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  128. : Data(data), Target(target),
  129. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  130. Header(CM_HEADER_REGEX),
  131. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  132. {
  133. }
  134. ~TagVisitor()
  135. {
  136. reportBadObjLib(this->BadObjLibFiles, this->Target,
  137. this->GlobalGenerator->GetCMakeInstance());
  138. }
  139. void Accept(cmSourceFile *sf)
  140. {
  141. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  142. if(sf->GetCustomCommand())
  143. {
  144. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  145. }
  146. else if(this->Target->GetType() == cmTarget::UTILITY)
  147. {
  148. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  149. }
  150. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  151. {
  152. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  153. }
  154. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  155. {
  156. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  157. if(this->IsObjLib)
  158. {
  159. this->BadObjLibFiles.push_back(sf);
  160. }
  161. }
  162. else if(!sf->GetLanguage().empty())
  163. {
  164. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  165. }
  166. else if(ext == "def")
  167. {
  168. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  169. sf);
  170. if(this->IsObjLib)
  171. {
  172. this->BadObjLibFiles.push_back(sf);
  173. }
  174. }
  175. else if(ext == "idl")
  176. {
  177. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  178. if(this->IsObjLib)
  179. {
  180. this->BadObjLibFiles.push_back(sf);
  181. }
  182. }
  183. else if(ext == "resx")
  184. {
  185. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  186. }
  187. else if (ext == "appxmanifest")
  188. {
  189. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  190. }
  191. else if (ext == "pfx")
  192. {
  193. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  194. }
  195. else if (ext == "xaml")
  196. {
  197. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  198. }
  199. else if(this->Header.find(sf->GetFullPath().c_str()))
  200. {
  201. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  202. }
  203. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  204. {
  205. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  206. }
  207. else
  208. {
  209. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  210. }
  211. }
  212. };
  213. //----------------------------------------------------------------------------
  214. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  215. : Target(t),
  216. SourceFileFlagsConstructed(false)
  217. {
  218. this->Makefile = this->Target->GetMakefile();
  219. this->LocalGenerator = lg;
  220. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  221. }
  222. cmGeneratorTarget::~cmGeneratorTarget()
  223. {
  224. cmDeleteAll(this->LinkInformation);
  225. this->LinkInformation.clear();
  226. }
  227. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  228. {
  229. return this->LocalGenerator;
  230. }
  231. //----------------------------------------------------------------------------
  232. int cmGeneratorTarget::GetType() const
  233. {
  234. return this->Target->GetType();
  235. }
  236. //----------------------------------------------------------------------------
  237. std::string cmGeneratorTarget::GetName() const
  238. {
  239. return this->Target->GetName();
  240. }
  241. //----------------------------------------------------------------------------
  242. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  243. {
  244. return this->Target->GetProperty(prop);
  245. }
  246. //----------------------------------------------------------------------------
  247. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  248. bool implib) const
  249. {
  250. // Lookup/compute/cache the output name for this configuration.
  251. OutputNameKey key(config, implib);
  252. cmGeneratorTarget::OutputNameMapType::iterator i =
  253. this->OutputNameMap.find(key);
  254. if(i == this->OutputNameMap.end())
  255. {
  256. // Add empty name in map to detect potential recursion.
  257. OutputNameMapType::value_type entry(key, "");
  258. i = this->OutputNameMap.insert(entry).first;
  259. // Compute output name.
  260. std::vector<std::string> props;
  261. std::string type = this->Target->GetOutputTargetType(implib);
  262. std::string configUpper = cmSystemTools::UpperCase(config);
  263. if(!type.empty() && !configUpper.empty())
  264. {
  265. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  266. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  267. }
  268. if(!type.empty())
  269. {
  270. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  271. props.push_back(type + "_OUTPUT_NAME");
  272. }
  273. if(!configUpper.empty())
  274. {
  275. // OUTPUT_NAME_<CONFIG>
  276. props.push_back("OUTPUT_NAME_" + configUpper);
  277. // <CONFIG>_OUTPUT_NAME
  278. props.push_back(configUpper + "_OUTPUT_NAME");
  279. }
  280. // OUTPUT_NAME
  281. props.push_back("OUTPUT_NAME");
  282. std::string outName;
  283. for(std::vector<std::string>::const_iterator it = props.begin();
  284. it != props.end(); ++it)
  285. {
  286. if (const char* outNameProp = this->Target->GetProperty(*it))
  287. {
  288. outName = outNameProp;
  289. break;
  290. }
  291. }
  292. if(outName.empty())
  293. {
  294. outName = this->GetName();
  295. }
  296. // Now evaluate genex and update the previously-prepared map entry.
  297. cmGeneratorExpression ge;
  298. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  299. i->second = cge->Evaluate(this->Makefile, config);
  300. }
  301. else if(i->second.empty())
  302. {
  303. // An empty map entry indicates we have been called recursively
  304. // from the above block.
  305. this->Makefile->GetCMakeInstance()->IssueMessage(
  306. cmake::FATAL_ERROR,
  307. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  308. this->Target->GetBacktrace());
  309. }
  310. return i->second;
  311. }
  312. //----------------------------------------------------------------------------
  313. std::vector<cmSourceFile*> const*
  314. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  315. {
  316. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  317. if(i != this->SourceEntries.end())
  318. {
  319. return &i->second.Depends;
  320. }
  321. return 0;
  322. }
  323. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  324. const std::string& config,
  325. cmTarget *headTarget,
  326. cmGeneratorExpressionDAGChecker *dagChecker,
  327. std::vector<std::string>& result,
  328. bool excludeImported)
  329. {
  330. if (const char* dirs =
  331. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  332. {
  333. cmGeneratorExpression ge;
  334. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  335. ->Evaluate(mf,
  336. config, false, headTarget,
  337. depTgt, dagChecker), result);
  338. }
  339. if (!depTgt->IsImported() || excludeImported)
  340. {
  341. return;
  342. }
  343. if (const char* dirs =
  344. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  345. {
  346. cmGeneratorExpression ge;
  347. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  348. ->Evaluate(mf,
  349. config, false, headTarget,
  350. depTgt, dagChecker), result);
  351. }
  352. }
  353. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  354. { \
  355. std::vector<cmSourceFile*> sourceFiles; \
  356. this->Target->GetSourceFiles(sourceFiles, config); \
  357. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  358. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  359. si != sourceFiles.end(); ++si) \
  360. { \
  361. visitor.Accept(*si); \
  362. } \
  363. } \
  364. #define IMPLEMENT_VISIT(DATA) \
  365. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  366. #define EMPTY
  367. #define COMMA ,
  368. //----------------------------------------------------------------------------
  369. void
  370. cmGeneratorTarget
  371. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  372. const std::string& config) const
  373. {
  374. IMPLEMENT_VISIT(ObjectSources);
  375. if (!this->Objects.empty())
  376. {
  377. return;
  378. }
  379. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  380. it != data.end(); ++it)
  381. {
  382. this->Objects[*it];
  383. }
  384. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  385. }
  386. void cmGeneratorTarget::ComputeObjectMapping()
  387. {
  388. if(!this->Objects.empty())
  389. {
  390. return;
  391. }
  392. std::vector<std::string> configs;
  393. this->Makefile->GetConfigurations(configs);
  394. if (configs.empty())
  395. {
  396. configs.push_back("");
  397. }
  398. for(std::vector<std::string>::const_iterator ci = configs.begin();
  399. ci != configs.end(); ++ci)
  400. {
  401. std::vector<cmSourceFile const*> sourceFiles;
  402. this->GetObjectSources(sourceFiles, *ci);
  403. }
  404. }
  405. //----------------------------------------------------------------------------
  406. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  407. const std::string& config) const
  408. {
  409. if(!config.empty())
  410. {
  411. std::string featureConfig = feature;
  412. featureConfig += "_";
  413. featureConfig += cmSystemTools::UpperCase(config);
  414. if(const char* value = this->Target->GetProperty(featureConfig))
  415. {
  416. return value;
  417. }
  418. }
  419. if(const char* value = this->Target->GetProperty(feature))
  420. {
  421. return value;
  422. }
  423. return this->LocalGenerator->GetFeature(feature, config);
  424. }
  425. //----------------------------------------------------------------------------
  426. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  427. const std::string& config) const
  428. {
  429. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  430. }
  431. //----------------------------------------------------------------------------
  432. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  433. {
  434. this->ComputeObjectMapping();
  435. return this->Objects[file];
  436. }
  437. //----------------------------------------------------------------------------
  438. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  439. {
  440. this->ExplicitObjectName.insert(sf);
  441. }
  442. //----------------------------------------------------------------------------
  443. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  444. {
  445. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  446. std::set<cmSourceFile const*>::const_iterator it
  447. = this->ExplicitObjectName.find(file);
  448. return it != this->ExplicitObjectName.end();
  449. }
  450. //----------------------------------------------------------------------------
  451. void cmGeneratorTarget
  452. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  453. const std::string& config) const
  454. {
  455. IMPLEMENT_VISIT(IDLSources);
  456. }
  457. //----------------------------------------------------------------------------
  458. void
  459. cmGeneratorTarget
  460. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  461. const std::string& config) const
  462. {
  463. IMPLEMENT_VISIT(HeaderSources);
  464. }
  465. //----------------------------------------------------------------------------
  466. void cmGeneratorTarget
  467. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  468. const std::string& config) const
  469. {
  470. IMPLEMENT_VISIT(ExtraSources);
  471. }
  472. //----------------------------------------------------------------------------
  473. void
  474. cmGeneratorTarget
  475. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  476. const std::string& config) const
  477. {
  478. IMPLEMENT_VISIT(CustomCommands);
  479. }
  480. //----------------------------------------------------------------------------
  481. void
  482. cmGeneratorTarget
  483. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  484. const std::string& config) const
  485. {
  486. IMPLEMENT_VISIT(ExternalObjects);
  487. }
  488. //----------------------------------------------------------------------------
  489. void
  490. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  491. const std::string& config) const
  492. {
  493. ResxData data;
  494. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  495. srcs = data.ExpectedResxHeaders;
  496. }
  497. //----------------------------------------------------------------------------
  498. void cmGeneratorTarget
  499. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  500. const std::string& config) const
  501. {
  502. ResxData data;
  503. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  504. srcs = data.ResxSources;
  505. }
  506. //----------------------------------------------------------------------------
  507. void
  508. cmGeneratorTarget
  509. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  510. const std::string& config) const
  511. {
  512. IMPLEMENT_VISIT(AppManifest);
  513. }
  514. //----------------------------------------------------------------------------
  515. void
  516. cmGeneratorTarget
  517. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  518. const std::string& config) const
  519. {
  520. IMPLEMENT_VISIT(Certificates);
  521. }
  522. //----------------------------------------------------------------------------
  523. void
  524. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  525. const std::string& config) const
  526. {
  527. XamlData data;
  528. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  529. headers = data.ExpectedXamlHeaders;
  530. }
  531. //----------------------------------------------------------------------------
  532. void
  533. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  534. const std::string& config) const
  535. {
  536. XamlData data;
  537. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  538. srcs = data.ExpectedXamlSources;
  539. }
  540. //----------------------------------------------------------------------------
  541. void cmGeneratorTarget
  542. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  543. const std::string& config) const
  544. {
  545. XamlData data;
  546. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  547. srcs = data.XamlSources;
  548. }
  549. //----------------------------------------------------------------------------
  550. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  551. {
  552. static std::string location;
  553. if (this->Target->IsImported())
  554. {
  555. location = this->Target->ImportedGetFullPath(config, false);
  556. }
  557. else
  558. {
  559. location = this->GetFullPath(config, false);
  560. }
  561. return location.c_str();
  562. }
  563. bool cmGeneratorTarget::IsImported() const
  564. {
  565. return this->Target->IsImported();
  566. }
  567. //----------------------------------------------------------------------------
  568. const char* cmGeneratorTarget::GetLocationForBuild() const
  569. {
  570. static std::string location;
  571. if(this->IsImported())
  572. {
  573. location = this->Target->ImportedGetFullPath("", false);
  574. return location.c_str();
  575. }
  576. // Now handle the deprecated build-time configuration location.
  577. location = this->Target->GetDirectory();
  578. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  579. if(cfgid && strcmp(cfgid, ".") != 0)
  580. {
  581. location += "/";
  582. location += cfgid;
  583. }
  584. if(this->Target->IsAppBundleOnApple())
  585. {
  586. std::string macdir = this->BuildMacContentDirectory("", "",
  587. false);
  588. if(!macdir.empty())
  589. {
  590. location += "/";
  591. location += macdir;
  592. }
  593. }
  594. location += "/";
  595. location += this->GetFullName("", false);
  596. return location.c_str();
  597. }
  598. //----------------------------------------------------------------------------
  599. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  600. const std::string& config) const
  601. {
  602. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  603. std::string config_upper;
  604. if(!config.empty())
  605. {
  606. config_upper = cmSystemTools::UpperCase(config);
  607. }
  608. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  609. IncludeCacheType::const_iterator iter =
  610. this->SystemIncludesCache.find(config_upper);
  611. if (iter == this->SystemIncludesCache.end())
  612. {
  613. cmGeneratorExpressionDAGChecker dagChecker(
  614. this->GetName(),
  615. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  616. bool excludeImported
  617. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  618. std::vector<std::string> result;
  619. for (std::set<std::string>::const_iterator
  620. it = this->Target->GetSystemIncludeDirectories().begin();
  621. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  622. {
  623. cmGeneratorExpression ge;
  624. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  625. ->Evaluate(this->Makefile,
  626. config, false, this->Target,
  627. &dagChecker), result);
  628. }
  629. std::vector<cmTarget const*> const& deps =
  630. this->GetLinkImplementationClosure(config);
  631. for(std::vector<cmTarget const*>::const_iterator
  632. li = deps.begin(), le = deps.end(); li != le; ++li)
  633. {
  634. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  635. &dagChecker, result, excludeImported);
  636. }
  637. std::set<std::string> unique;
  638. for(std::vector<std::string>::iterator li = result.begin();
  639. li != result.end(); ++li)
  640. {
  641. cmSystemTools::ConvertToUnixSlashes(*li);
  642. unique.insert(*li);
  643. }
  644. result.clear();
  645. result.insert(result.end(), unique.begin(), unique.end());
  646. IncludeCacheType::value_type entry(config_upper, result);
  647. iter = this->SystemIncludesCache.insert(entry).first;
  648. }
  649. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  650. }
  651. //----------------------------------------------------------------------------
  652. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  653. {
  654. return this->Target->GetPropertyAsBool(prop);
  655. }
  656. //----------------------------------------------------------------------------
  657. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  658. const std::string& config) const
  659. {
  660. this->Target->GetSourceFiles(files, config);
  661. }
  662. //----------------------------------------------------------------------------
  663. std::string
  664. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  665. {
  666. std::string prefix;
  667. std::string base;
  668. std::string suffix;
  669. this->GetFullNameInternal(config, false, prefix, base, suffix);
  670. // Check for a per-configuration output directory target property.
  671. std::string configUpper = cmSystemTools::UpperCase(config);
  672. std::string configProp = "COMPILE_PDB_NAME_";
  673. configProp += configUpper;
  674. const char* config_name = this->Target->GetProperty(configProp);
  675. if(config_name && *config_name)
  676. {
  677. return prefix + config_name + ".pdb";
  678. }
  679. const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
  680. if(name && *name)
  681. {
  682. return prefix + name + ".pdb";
  683. }
  684. return "";
  685. }
  686. //----------------------------------------------------------------------------
  687. std::string
  688. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  689. {
  690. std::string dir = this->GetCompilePDBDirectory(config);
  691. std::string name = this->GetCompilePDBName(config);
  692. if(dir.empty() && !name.empty())
  693. {
  694. dir = this->Target->GetPDBDirectory(config);
  695. }
  696. if(!dir.empty())
  697. {
  698. dir += "/";
  699. }
  700. return dir + name;
  701. }
  702. //----------------------------------------------------------------------------
  703. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  704. {
  705. // soname is supported only for shared libraries and modules,
  706. // and then only when the platform supports an soname flag.
  707. return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
  708. !this->GetPropertyAsBool("NO_SONAME") &&
  709. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  710. }
  711. //----------------------------------------------------------------------------
  712. bool
  713. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  714. {
  715. // Only executables and shared libraries can have an rpath and may
  716. // need relinking.
  717. if(this->GetType() != cmTarget::EXECUTABLE &&
  718. this->GetType() != cmTarget::SHARED_LIBRARY &&
  719. this->GetType() != cmTarget::MODULE_LIBRARY)
  720. {
  721. return false;
  722. }
  723. // If there is no install location this target will not be installed
  724. // and therefore does not need relinking.
  725. if(!this->Target->GetHaveInstallRule())
  726. {
  727. return false;
  728. }
  729. // If skipping all rpaths completely then no relinking is needed.
  730. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  731. {
  732. return false;
  733. }
  734. // If building with the install-tree rpath no relinking is needed.
  735. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  736. {
  737. return false;
  738. }
  739. // If chrpath is going to be used no relinking is needed.
  740. if(this->IsChrpathUsed(config))
  741. {
  742. return false;
  743. }
  744. // Check for rpath support on this platform.
  745. std::string ll = this->GetLinkerLanguage(config);
  746. if(!ll.empty())
  747. {
  748. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  749. flagVar += ll;
  750. flagVar += "_FLAG";
  751. if(!this->Makefile->IsSet(flagVar))
  752. {
  753. // There is no rpath support on this platform so nothing needs
  754. // relinking.
  755. return false;
  756. }
  757. }
  758. else
  759. {
  760. // No linker language is known. This error will be reported by
  761. // other code.
  762. return false;
  763. }
  764. // If either a build or install tree rpath is set then the rpath
  765. // will likely change between the build tree and install tree and
  766. // this target must be relinked.
  767. return this->Target->HaveBuildTreeRPATH(config)
  768. || this->Target->HaveInstallTreeRPATH();
  769. }
  770. //----------------------------------------------------------------------------
  771. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  772. {
  773. // Only certain target types have an rpath.
  774. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  775. this->GetType() == cmTarget::MODULE_LIBRARY ||
  776. this->GetType() == cmTarget::EXECUTABLE))
  777. {
  778. return false;
  779. }
  780. // If the target will not be installed we do not need to change its
  781. // rpath.
  782. if(!this->Target->GetHaveInstallRule())
  783. {
  784. return false;
  785. }
  786. // Skip chrpath if skipping rpath altogether.
  787. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  788. {
  789. return false;
  790. }
  791. // Skip chrpath if it does not need to be changed at install time.
  792. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  793. {
  794. return false;
  795. }
  796. // Allow the user to disable builtin chrpath explicitly.
  797. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  798. {
  799. return false;
  800. }
  801. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  802. {
  803. return true;
  804. }
  805. #if defined(CMAKE_USE_ELF_PARSER)
  806. // Enable if the rpath flag uses a separator and the target uses ELF
  807. // binaries.
  808. std::string ll = this->GetLinkerLanguage(config);
  809. if(!ll.empty())
  810. {
  811. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  812. sepVar += ll;
  813. sepVar += "_FLAG_SEP";
  814. const char* sep = this->Makefile->GetDefinition(sepVar);
  815. if(sep && *sep)
  816. {
  817. // TODO: Add ELF check to ABI detection and get rid of
  818. // CMAKE_EXECUTABLE_FORMAT.
  819. if(const char* fmt =
  820. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  821. {
  822. return strcmp(fmt, "ELF") == 0;
  823. }
  824. }
  825. }
  826. #endif
  827. static_cast<void>(config);
  828. return false;
  829. }
  830. //----------------------------------------------------------------------------
  831. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  832. {
  833. if(this->Target->IsImported())
  834. {
  835. // Lookup the imported soname.
  836. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  837. {
  838. if(info->NoSOName)
  839. {
  840. // The imported library has no builtin soname so the name
  841. // searched at runtime will be just the filename.
  842. return cmSystemTools::GetFilenameName(info->Location);
  843. }
  844. else
  845. {
  846. // Use the soname given if any.
  847. if(info->SOName.find("@rpath/") == 0)
  848. {
  849. return info->SOName.substr(6);
  850. }
  851. return info->SOName;
  852. }
  853. }
  854. else
  855. {
  856. return "";
  857. }
  858. }
  859. else
  860. {
  861. // Compute the soname that will be built.
  862. std::string name;
  863. std::string soName;
  864. std::string realName;
  865. std::string impName;
  866. std::string pdbName;
  867. this->GetLibraryNames(name, soName, realName,
  868. impName, pdbName, config);
  869. return soName;
  870. }
  871. }
  872. //----------------------------------------------------------------------------
  873. std::string
  874. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  875. bool contentOnly) const
  876. {
  877. std::string fpath = this->GetFullName(config, false);
  878. fpath += ".app";
  879. if(!this->Makefile->PlatformIsAppleIos())
  880. {
  881. fpath += "/Contents";
  882. if(!contentOnly)
  883. fpath += "/MacOS";
  884. }
  885. return fpath;
  886. }
  887. //----------------------------------------------------------------------------
  888. bool cmGeneratorTarget::IsBundleOnApple() const
  889. {
  890. return this->Target->IsFrameworkOnApple()
  891. || this->Target->IsAppBundleOnApple()
  892. || this->Target->IsCFBundleOnApple();
  893. }
  894. //----------------------------------------------------------------------------
  895. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  896. bool contentOnly) const
  897. {
  898. std::string fpath;
  899. fpath += this->GetOutputName(config, false);
  900. fpath += ".";
  901. const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
  902. if (!ext)
  903. {
  904. if (this->Target->IsXCTestOnApple())
  905. {
  906. ext = "xctest";
  907. }
  908. else
  909. {
  910. ext = "bundle";
  911. }
  912. }
  913. fpath += ext;
  914. if(!this->Makefile->PlatformIsAppleIos())
  915. {
  916. fpath += "/Contents";
  917. if(!contentOnly)
  918. fpath += "/MacOS";
  919. }
  920. return fpath;
  921. }
  922. //----------------------------------------------------------------------------
  923. std::string
  924. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  925. bool rootDir) const
  926. {
  927. std::string fpath;
  928. fpath += this->GetOutputName(config, false);
  929. fpath += ".framework";
  930. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  931. {
  932. fpath += "/Versions/";
  933. fpath += this->Target->GetFrameworkVersion();
  934. }
  935. return fpath;
  936. }
  937. //----------------------------------------------------------------------------
  938. std::string
  939. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  940. {
  941. if(this->Target->IsImported())
  942. {
  943. return this->Target->GetFullNameImported(config, implib);
  944. }
  945. else
  946. {
  947. return this->GetFullNameInternal(config, implib);
  948. }
  949. }
  950. //----------------------------------------------------------------------------
  951. std::string
  952. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  953. const std::string& config) const
  954. {
  955. // If building directly for installation then the build tree install_name
  956. // is the same as the install tree.
  957. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  958. {
  959. return this->GetInstallNameDirForInstallTree();
  960. }
  961. // Use the build tree directory for the target.
  962. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  963. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  964. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  965. {
  966. std::string dir;
  967. if(this->Target->MacOSXRpathInstallNameDirDefault())
  968. {
  969. dir = "@rpath";
  970. }
  971. else
  972. {
  973. dir = this->Target->GetDirectory(config);
  974. }
  975. dir += "/";
  976. return dir;
  977. }
  978. else
  979. {
  980. return "";
  981. }
  982. }
  983. //----------------------------------------------------------------------------
  984. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  985. {
  986. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  987. {
  988. std::string dir;
  989. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  990. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  991. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  992. {
  993. if(install_name_dir && *install_name_dir)
  994. {
  995. dir = install_name_dir;
  996. dir += "/";
  997. }
  998. }
  999. if(!install_name_dir)
  1000. {
  1001. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1002. {
  1003. dir = "@rpath/";
  1004. }
  1005. }
  1006. return dir;
  1007. }
  1008. else
  1009. {
  1010. return "";
  1011. }
  1012. }
  1013. //----------------------------------------------------------------------------
  1014. class cmTargetCollectLinkLanguages
  1015. {
  1016. public:
  1017. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1018. const std::string& config,
  1019. UNORDERED_SET<std::string>& languages,
  1020. cmTarget const* head):
  1021. Config(config), Languages(languages), HeadTarget(head),
  1022. Makefile(target->Target->GetMakefile()), Target(target)
  1023. { this->Visited.insert(target->Target); }
  1024. void Visit(cmLinkItem const& item)
  1025. {
  1026. if(!item.Target)
  1027. {
  1028. if(item.find("::") != std::string::npos)
  1029. {
  1030. bool noMessage = false;
  1031. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1032. std::stringstream e;
  1033. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1034. {
  1035. case cmPolicies::WARN:
  1036. {
  1037. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1038. messageType = cmake::AUTHOR_WARNING;
  1039. }
  1040. break;
  1041. case cmPolicies::OLD:
  1042. noMessage = true;
  1043. case cmPolicies::REQUIRED_IF_USED:
  1044. case cmPolicies::REQUIRED_ALWAYS:
  1045. case cmPolicies::NEW:
  1046. // Issue the fatal message.
  1047. break;
  1048. }
  1049. if(!noMessage)
  1050. {
  1051. e << "Target \"" << this->Target->GetName()
  1052. << "\" links to target \"" << item
  1053. << "\" but the target was not found. Perhaps a find_package() "
  1054. "call is missing for an IMPORTED target, or an ALIAS target is "
  1055. "missing?";
  1056. this->Makefile->GetCMakeInstance()->IssueMessage(
  1057. messageType, e.str(), this->Target->Target->GetBacktrace());
  1058. }
  1059. }
  1060. return;
  1061. }
  1062. if(!this->Visited.insert(item.Target).second)
  1063. {
  1064. return;
  1065. }
  1066. cmGeneratorTarget* gtgt =
  1067. this->Target->GetLocalGenerator()->GetGlobalGenerator()
  1068. ->GetGeneratorTarget(item.Target);
  1069. cmLinkInterface const* iface =
  1070. gtgt->GetLinkInterface(this->Config, this->HeadTarget);
  1071. if(!iface) { return; }
  1072. for(std::vector<std::string>::const_iterator
  1073. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1074. {
  1075. this->Languages.insert(*li);
  1076. }
  1077. for(std::vector<cmLinkItem>::const_iterator
  1078. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1079. {
  1080. this->Visit(*li);
  1081. }
  1082. }
  1083. private:
  1084. std::string Config;
  1085. UNORDERED_SET<std::string>& Languages;
  1086. cmTarget const* HeadTarget;
  1087. cmMakefile* Makefile;
  1088. const cmGeneratorTarget* Target;
  1089. std::set<cmTarget const*> Visited;
  1090. };
  1091. //----------------------------------------------------------------------------
  1092. cmGeneratorTarget::LinkClosure const*
  1093. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1094. {
  1095. std::string key(cmSystemTools::UpperCase(config));
  1096. LinkClosureMapType::iterator
  1097. i = this->LinkClosureMap.find(key);
  1098. if(i == this->LinkClosureMap.end())
  1099. {
  1100. LinkClosure lc;
  1101. this->ComputeLinkClosure(config, lc);
  1102. LinkClosureMapType::value_type entry(key, lc);
  1103. i = this->LinkClosureMap.insert(entry).first;
  1104. }
  1105. return &i->second;
  1106. }
  1107. //----------------------------------------------------------------------------
  1108. class cmTargetSelectLinker
  1109. {
  1110. int Preference;
  1111. cmGeneratorTarget const* Target;
  1112. cmMakefile* Makefile;
  1113. cmGlobalGenerator* GG;
  1114. std::set<std::string> Preferred;
  1115. public:
  1116. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1117. : Preference(0), Target(target)
  1118. {
  1119. this->Makefile = this->Target->Makefile;
  1120. this->GG = this->Makefile->GetGlobalGenerator();
  1121. }
  1122. void Consider(const char* lang)
  1123. {
  1124. int preference = this->GG->GetLinkerPreference(lang);
  1125. if(preference > this->Preference)
  1126. {
  1127. this->Preference = preference;
  1128. this->Preferred.clear();
  1129. }
  1130. if(preference == this->Preference)
  1131. {
  1132. this->Preferred.insert(lang);
  1133. }
  1134. }
  1135. std::string Choose()
  1136. {
  1137. if(this->Preferred.empty())
  1138. {
  1139. return "";
  1140. }
  1141. else if(this->Preferred.size() > 1)
  1142. {
  1143. std::stringstream e;
  1144. e << "Target " << this->Target->GetName()
  1145. << " contains multiple languages with the highest linker preference"
  1146. << " (" << this->Preference << "):\n";
  1147. for(std::set<std::string>::const_iterator
  1148. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1149. {
  1150. e << " " << *li << "\n";
  1151. }
  1152. e << "Set the LINKER_LANGUAGE property for this target.";
  1153. cmake* cm = this->Makefile->GetCMakeInstance();
  1154. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1155. this->Target->Target->GetBacktrace());
  1156. }
  1157. return *this->Preferred.begin();
  1158. }
  1159. };
  1160. //----------------------------------------------------------------------------
  1161. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1162. LinkClosure& lc) const
  1163. {
  1164. // Get languages built in this target.
  1165. UNORDERED_SET<std::string> languages;
  1166. cmTarget::LinkImplementation const* impl =
  1167. this->Target->GetLinkImplementation(config);
  1168. assert(impl);
  1169. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1170. li != impl->Languages.end(); ++li)
  1171. {
  1172. languages.insert(*li);
  1173. }
  1174. // Add interface languages from linked targets.
  1175. cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
  1176. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1177. li != impl->Libraries.end(); ++li)
  1178. {
  1179. cll.Visit(*li);
  1180. }
  1181. // Store the transitive closure of languages.
  1182. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1183. li != languages.end(); ++li)
  1184. {
  1185. lc.Languages.push_back(*li);
  1186. }
  1187. // Choose the language whose linker should be used.
  1188. if(this->GetProperty("HAS_CXX"))
  1189. {
  1190. lc.LinkerLanguage = "CXX";
  1191. }
  1192. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1193. {
  1194. lc.LinkerLanguage = linkerLang;
  1195. }
  1196. else
  1197. {
  1198. // Find the language with the highest preference value.
  1199. cmTargetSelectLinker tsl(this);
  1200. // First select from the languages compiled directly in this target.
  1201. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1202. li != impl->Languages.end(); ++li)
  1203. {
  1204. tsl.Consider(li->c_str());
  1205. }
  1206. // Now consider languages that propagate from linked targets.
  1207. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1208. sit != languages.end(); ++sit)
  1209. {
  1210. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1211. if(this->Makefile->IsOn(propagates))
  1212. {
  1213. tsl.Consider(sit->c_str());
  1214. }
  1215. }
  1216. lc.LinkerLanguage = tsl.Choose();
  1217. }
  1218. }
  1219. //----------------------------------------------------------------------------
  1220. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1221. std::string& base,
  1222. std::string& suffix,
  1223. const std::string& config,
  1224. bool implib) const
  1225. {
  1226. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1227. }
  1228. //----------------------------------------------------------------------------
  1229. std::string
  1230. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1231. const std::string& config,
  1232. bool contentOnly) const
  1233. {
  1234. std::string fpath = base;
  1235. if(this->Target->IsAppBundleOnApple())
  1236. {
  1237. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1238. }
  1239. if(this->Target->IsFrameworkOnApple())
  1240. {
  1241. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1242. }
  1243. if(this->Target->IsCFBundleOnApple())
  1244. {
  1245. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1246. }
  1247. return fpath;
  1248. }
  1249. //----------------------------------------------------------------------------
  1250. std::string
  1251. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1252. bool implib) const
  1253. {
  1254. // Start with the output directory for the target.
  1255. std::string fpath = this->Target->GetDirectory(config, implib);
  1256. fpath += "/";
  1257. bool contentOnly = true;
  1258. if(this->Target->IsFrameworkOnApple())
  1259. {
  1260. // additional files with a framework go into the version specific
  1261. // directory
  1262. contentOnly = false;
  1263. }
  1264. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1265. return fpath;
  1266. }
  1267. //----------------------------------------------------------------------------
  1268. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1269. const std::string& config) const
  1270. {
  1271. // There is no compile information for imported targets.
  1272. if(this->IsImported())
  1273. {
  1274. return 0;
  1275. }
  1276. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  1277. {
  1278. std::string msg = "cmTarget::GetCompileInfo called for ";
  1279. msg += this->GetName();
  1280. msg += " which has type ";
  1281. msg += cmTarget::GetTargetTypeName(this->Target->GetType());
  1282. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1283. return 0;
  1284. }
  1285. // Lookup/compute/cache the compile information for this configuration.
  1286. std::string config_upper;
  1287. if(!config.empty())
  1288. {
  1289. config_upper = cmSystemTools::UpperCase(config);
  1290. }
  1291. CompileInfoMapType::const_iterator i =
  1292. this->CompileInfoMap.find(config_upper);
  1293. if(i == this->CompileInfoMap.end())
  1294. {
  1295. CompileInfo info;
  1296. this->Target
  1297. ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1298. CompileInfoMapType::value_type entry(config_upper, info);
  1299. i = this->CompileInfoMap.insert(entry).first;
  1300. }
  1301. return &i->second;
  1302. }
  1303. //----------------------------------------------------------------------------
  1304. std::string
  1305. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1306. {
  1307. std::string data;
  1308. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1309. return data;
  1310. }
  1311. //----------------------------------------------------------------------------
  1312. void
  1313. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1314. const std::string &config) const
  1315. {
  1316. std::vector<cmSourceFile const*> objectFiles;
  1317. this->GetExternalObjects(objectFiles, config);
  1318. std::vector<cmTarget*> objectLibraries;
  1319. for(std::vector<cmSourceFile const*>::const_iterator
  1320. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1321. {
  1322. std::string objLib = (*it)->GetObjectLibrary();
  1323. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  1324. {
  1325. objectLibraries.push_back(tgt);
  1326. }
  1327. }
  1328. std::vector<cmTarget*>::const_iterator end
  1329. = cmRemoveDuplicates(objectLibraries);
  1330. for(std::vector<cmTarget*>::const_iterator
  1331. ti = objectLibraries.begin();
  1332. ti != end; ++ti)
  1333. {
  1334. cmTarget* objLib = *ti;
  1335. cmGeneratorTarget* ogt =
  1336. this->GlobalGenerator->GetGeneratorTarget(objLib);
  1337. std::vector<cmSourceFile const*> objectSources;
  1338. ogt->GetObjectSources(objectSources, config);
  1339. for(std::vector<cmSourceFile const*>::const_iterator
  1340. si = objectSources.begin();
  1341. si != objectSources.end(); ++si)
  1342. {
  1343. std::string obj = ogt->ObjectDirectory;
  1344. obj += ogt->Objects[*si];
  1345. objs.push_back(obj);
  1346. }
  1347. }
  1348. }
  1349. //----------------------------------------------------------------------------
  1350. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1351. const std::string& config) const
  1352. {
  1353. const char *prop
  1354. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1355. config);
  1356. if (!prop)
  1357. {
  1358. return;
  1359. }
  1360. cmGeneratorExpression ge;
  1361. cmGeneratorExpressionDAGChecker dagChecker(
  1362. this->GetName(),
  1363. "AUTOUIC_OPTIONS", 0, 0);
  1364. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1365. ->Evaluate(this->Makefile,
  1366. config,
  1367. false,
  1368. this->Target,
  1369. &dagChecker),
  1370. result);
  1371. }
  1372. //----------------------------------------------------------------------------
  1373. void processILibs(const std::string& config,
  1374. cmTarget const* headTarget,
  1375. cmLinkItem const& item,
  1376. std::vector<cmTarget const*>& tgts,
  1377. std::set<cmTarget const*>& emitted)
  1378. {
  1379. if (item.Target && emitted.insert(item.Target).second)
  1380. {
  1381. tgts.push_back(item.Target);
  1382. if(cmLinkInterfaceLibraries const* iface =
  1383. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  1384. {
  1385. for(std::vector<cmLinkItem>::const_iterator
  1386. it = iface->Libraries.begin();
  1387. it != iface->Libraries.end(); ++it)
  1388. {
  1389. processILibs(config, headTarget, *it, tgts, emitted);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. //----------------------------------------------------------------------------
  1395. const std::vector<const cmTarget*>&
  1396. cmGeneratorTarget::GetLinkImplementationClosure(
  1397. const std::string& config) const
  1398. {
  1399. LinkImplClosure& tgts =
  1400. this->LinkImplClosureMap[config];
  1401. if(!tgts.Done)
  1402. {
  1403. tgts.Done = true;
  1404. std::set<cmTarget const*> emitted;
  1405. cmLinkImplementationLibraries const* impl
  1406. = this->Target->GetLinkImplementationLibraries(config);
  1407. for(std::vector<cmLinkImplItem>::const_iterator
  1408. it = impl->Libraries.begin();
  1409. it != impl->Libraries.end(); ++it)
  1410. {
  1411. processILibs(config, this->Target, *it, tgts , emitted);
  1412. }
  1413. }
  1414. return tgts;
  1415. }
  1416. //----------------------------------------------------------------------------
  1417. class cmTargetTraceDependencies
  1418. {
  1419. public:
  1420. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1421. void Trace();
  1422. private:
  1423. cmTarget* Target;
  1424. cmGeneratorTarget* GeneratorTarget;
  1425. cmMakefile* Makefile;
  1426. cmGlobalGenerator const* GlobalGenerator;
  1427. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1428. SourceEntry* CurrentEntry;
  1429. std::queue<cmSourceFile*> SourceQueue;
  1430. std::set<cmSourceFile*> SourcesQueued;
  1431. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1432. NameMapType NameMap;
  1433. std::vector<std::string> NewSources;
  1434. void QueueSource(cmSourceFile* sf);
  1435. void FollowName(std::string const& name);
  1436. void FollowNames(std::vector<std::string> const& names);
  1437. bool IsUtility(std::string const& dep);
  1438. void CheckCustomCommand(cmCustomCommand const& cc);
  1439. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1440. void FollowCommandDepends(cmCustomCommand const& cc,
  1441. const std::string& config,
  1442. std::set<std::string>& emitted);
  1443. };
  1444. //----------------------------------------------------------------------------
  1445. cmTargetTraceDependencies
  1446. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  1447. Target(target->Target), GeneratorTarget(target)
  1448. {
  1449. // Convenience.
  1450. this->Makefile = this->Target->GetMakefile();
  1451. this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
  1452. this->CurrentEntry = 0;
  1453. // Queue all the source files already specified for the target.
  1454. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1455. {
  1456. std::vector<std::string> configs;
  1457. this->Makefile->GetConfigurations(configs);
  1458. if (configs.empty())
  1459. {
  1460. configs.push_back("");
  1461. }
  1462. std::set<cmSourceFile*> emitted;
  1463. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1464. ci != configs.end(); ++ci)
  1465. {
  1466. std::vector<cmSourceFile*> sources;
  1467. this->Target->GetSourceFiles(sources, *ci);
  1468. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1469. si != sources.end(); ++si)
  1470. {
  1471. cmSourceFile* sf = *si;
  1472. const std::set<cmTarget const*> tgts =
  1473. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1474. if (tgts.find(this->Target) != tgts.end())
  1475. {
  1476. std::ostringstream e;
  1477. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1478. << "\"\ndepends on the sources of a target it is used in. This "
  1479. "is a dependency loop and is not allowed.";
  1480. this->GeneratorTarget
  1481. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1482. return;
  1483. }
  1484. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  1485. {
  1486. this->SourceQueue.push(sf);
  1487. }
  1488. }
  1489. }
  1490. }
  1491. // Queue pre-build, pre-link, and post-build rule dependencies.
  1492. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1493. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1494. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1495. }
  1496. //----------------------------------------------------------------------------
  1497. void cmTargetTraceDependencies::Trace()
  1498. {
  1499. // Process one dependency at a time until the queue is empty.
  1500. while(!this->SourceQueue.empty())
  1501. {
  1502. // Get the next source from the queue.
  1503. cmSourceFile* sf = this->SourceQueue.front();
  1504. this->SourceQueue.pop();
  1505. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  1506. // Queue dependencies added explicitly by the user.
  1507. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1508. {
  1509. std::vector<std::string> objDeps;
  1510. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1511. for(std::vector<std::string>::iterator odi = objDeps.begin();
  1512. odi != objDeps.end(); ++odi)
  1513. {
  1514. if (cmSystemTools::FileIsFullPath(*odi))
  1515. {
  1516. *odi = cmSystemTools::CollapseFullPath(*odi);
  1517. }
  1518. }
  1519. this->FollowNames(objDeps);
  1520. }
  1521. // Queue the source needed to generate this file, if any.
  1522. this->FollowName(sf->GetFullPath());
  1523. // Queue dependencies added programatically by commands.
  1524. this->FollowNames(sf->GetDepends());
  1525. // Queue custom command dependencies.
  1526. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1527. {
  1528. this->CheckCustomCommand(*cc);
  1529. }
  1530. }
  1531. this->CurrentEntry = 0;
  1532. this->Target->AddTracedSources(this->NewSources);
  1533. }
  1534. //----------------------------------------------------------------------------
  1535. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1536. {
  1537. if(this->SourcesQueued.insert(sf).second)
  1538. {
  1539. this->SourceQueue.push(sf);
  1540. // Make sure this file is in the target at the end.
  1541. this->NewSources.push_back(sf->GetFullPath());
  1542. }
  1543. }
  1544. //----------------------------------------------------------------------------
  1545. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1546. {
  1547. NameMapType::iterator i = this->NameMap.find(name);
  1548. if(i == this->NameMap.end())
  1549. {
  1550. // Check if we know how to generate this file.
  1551. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1552. NameMapType::value_type entry(name, sf);
  1553. i = this->NameMap.insert(entry).first;
  1554. }
  1555. if(cmSourceFile* sf = i->second)
  1556. {
  1557. // Record the dependency we just followed.
  1558. if(this->CurrentEntry)
  1559. {
  1560. this->CurrentEntry->Depends.push_back(sf);
  1561. }
  1562. this->QueueSource(sf);
  1563. }
  1564. }
  1565. //----------------------------------------------------------------------------
  1566. void
  1567. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1568. {
  1569. for(std::vector<std::string>::const_iterator i = names.begin();
  1570. i != names.end(); ++i)
  1571. {
  1572. this->FollowName(*i);
  1573. }
  1574. }
  1575. //----------------------------------------------------------------------------
  1576. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1577. {
  1578. // Dependencies on targets (utilities) are supposed to be named by
  1579. // just the target name. However for compatibility we support
  1580. // naming the output file generated by the target (assuming there is
  1581. // no output-name property which old code would not have set). In
  1582. // that case the target name will be the file basename of the
  1583. // dependency.
  1584. std::string util = cmSystemTools::GetFilenameName(dep);
  1585. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1586. {
  1587. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1588. }
  1589. // Check for a target with this name.
  1590. if(cmGeneratorTarget* t
  1591. = this->Makefile->FindGeneratorTargetToUse(util))
  1592. {
  1593. // If we find the target and the dep was given as a full path,
  1594. // then make sure it was not a full path to something else, and
  1595. // the fact that the name matched a target was just a coincidence.
  1596. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1597. {
  1598. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1599. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1600. {
  1601. // This is really only for compatibility so we do not need to
  1602. // worry about configuration names and output names.
  1603. std::string tLocation = t->GetLocationForBuild();
  1604. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1605. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1606. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1607. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1608. if(depLocation == tLocation)
  1609. {
  1610. this->Target->AddUtility(util);
  1611. return true;
  1612. }
  1613. }
  1614. }
  1615. else
  1616. {
  1617. // The original name of the dependency was not a full path. It
  1618. // must name a target, so add the target-level dependency.
  1619. this->Target->AddUtility(util);
  1620. return true;
  1621. }
  1622. }
  1623. // The dependency does not name a target built in this project.
  1624. return false;
  1625. }
  1626. //----------------------------------------------------------------------------
  1627. void
  1628. cmTargetTraceDependencies
  1629. ::CheckCustomCommand(cmCustomCommand const& cc)
  1630. {
  1631. // Transform command names that reference targets built in this
  1632. // project to corresponding target-level dependencies.
  1633. cmGeneratorExpression ge(cc.GetBacktrace());
  1634. // Add target-level dependencies referenced by generator expressions.
  1635. std::set<cmTarget*> targets;
  1636. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1637. cit != cc.GetCommandLines().end(); ++cit)
  1638. {
  1639. std::string const& command = *cit->begin();
  1640. // Check for a target with this name.
  1641. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1642. {
  1643. if(t->GetType() == cmTarget::EXECUTABLE)
  1644. {
  1645. // The command refers to an executable target built in
  1646. // this project. Add the target-level dependency to make
  1647. // sure the executable is up to date before this custom
  1648. // command possibly runs.
  1649. this->Target->AddUtility(command);
  1650. }
  1651. }
  1652. // Check for target references in generator expressions.
  1653. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1654. cli != cit->end(); ++cli)
  1655. {
  1656. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1657. = ge.Parse(*cli);
  1658. cge->Evaluate(this->Makefile, "", true);
  1659. std::set<cmTarget*> geTargets = cge->GetTargets();
  1660. targets.insert(geTargets.begin(), geTargets.end());
  1661. }
  1662. }
  1663. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1664. ti != targets.end(); ++ti)
  1665. {
  1666. this->Target->AddUtility((*ti)->GetName());
  1667. }
  1668. // Queue the custom command dependencies.
  1669. std::vector<std::string> configs;
  1670. std::set<std::string> emitted;
  1671. this->Makefile->GetConfigurations(configs);
  1672. if (configs.empty())
  1673. {
  1674. configs.push_back("");
  1675. }
  1676. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1677. ci != configs.end(); ++ci)
  1678. {
  1679. this->FollowCommandDepends(cc, *ci, emitted);
  1680. }
  1681. }
  1682. //----------------------------------------------------------------------------
  1683. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1684. const std::string& config,
  1685. std::set<std::string>& emitted)
  1686. {
  1687. cmCustomCommandGenerator ccg(cc, config,
  1688. this->GeneratorTarget->LocalGenerator);
  1689. const std::vector<std::string>& depends = ccg.GetDepends();
  1690. for(std::vector<std::string>::const_iterator di = depends.begin();
  1691. di != depends.end(); ++di)
  1692. {
  1693. std::string const& dep = *di;
  1694. if(emitted.insert(dep).second)
  1695. {
  1696. if(!this->IsUtility(dep))
  1697. {
  1698. // The dependency does not name a target and may be a file we
  1699. // know how to generate. Queue it.
  1700. this->FollowName(dep);
  1701. }
  1702. }
  1703. }
  1704. }
  1705. //----------------------------------------------------------------------------
  1706. void
  1707. cmTargetTraceDependencies
  1708. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1709. {
  1710. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1711. cli != commands.end(); ++cli)
  1712. {
  1713. this->CheckCustomCommand(*cli);
  1714. }
  1715. }
  1716. //----------------------------------------------------------------------------
  1717. void cmGeneratorTarget::TraceDependencies()
  1718. {
  1719. // CMake-generated targets have no dependencies to trace. Normally tracing
  1720. // would find nothing anyway, but when building CMake itself the "install"
  1721. // target command ends up referencing the "cmake" target but we do not
  1722. // really want the dependency because "install" depend on "all" anyway.
  1723. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1724. {
  1725. return;
  1726. }
  1727. // Use a helper object to trace the dependencies.
  1728. cmTargetTraceDependencies tracer(this);
  1729. tracer.Trace();
  1730. }
  1731. std::string
  1732. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  1733. {
  1734. if(CompileInfo const* info = this->GetCompileInfo(config))
  1735. {
  1736. return info->CompilePdbDir;
  1737. }
  1738. return "";
  1739. }
  1740. //----------------------------------------------------------------------------
  1741. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1742. std::vector<std::string>& archVec) const
  1743. {
  1744. const char* archs = 0;
  1745. if(!config.empty())
  1746. {
  1747. std::string defVarName = "OSX_ARCHITECTURES_";
  1748. defVarName += cmSystemTools::UpperCase(config);
  1749. archs = this->Target->GetProperty(defVarName);
  1750. }
  1751. if(!archs)
  1752. {
  1753. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1754. }
  1755. if(archs)
  1756. {
  1757. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1758. }
  1759. }
  1760. //----------------------------------------------------------------------------
  1761. std::string
  1762. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1763. std::string const& config) const
  1764. {
  1765. switch(this->GetType())
  1766. {
  1767. case cmTarget::STATIC_LIBRARY:
  1768. {
  1769. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1770. if(this->GetFeatureAsBool(
  1771. "INTERPROCEDURAL_OPTIMIZATION", config))
  1772. {
  1773. std::string varIPO = var + "_IPO";
  1774. if(this->Makefile->GetDefinition(varIPO))
  1775. {
  1776. return varIPO;
  1777. }
  1778. }
  1779. return var;
  1780. }
  1781. case cmTarget::SHARED_LIBRARY:
  1782. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1783. case cmTarget::MODULE_LIBRARY:
  1784. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1785. case cmTarget::EXECUTABLE:
  1786. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1787. default:
  1788. break;
  1789. }
  1790. return "";
  1791. }
  1792. //----------------------------------------------------------------------------
  1793. std::vector<std::string>
  1794. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1795. const std::string& lang) const
  1796. {
  1797. return this->Target->GetIncludeDirectories(config, lang);
  1798. }
  1799. //----------------------------------------------------------------------------
  1800. void cmGeneratorTarget::GenerateTargetManifest(
  1801. const std::string& config) const
  1802. {
  1803. if (this->Target->IsImported())
  1804. {
  1805. return;
  1806. }
  1807. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  1808. // Get the names.
  1809. std::string name;
  1810. std::string soName;
  1811. std::string realName;
  1812. std::string impName;
  1813. std::string pdbName;
  1814. if(this->GetType() == cmTarget::EXECUTABLE)
  1815. {
  1816. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1817. }
  1818. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1819. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1820. this->GetType() == cmTarget::MODULE_LIBRARY)
  1821. {
  1822. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  1823. config);
  1824. }
  1825. else
  1826. {
  1827. return;
  1828. }
  1829. // Get the directory.
  1830. std::string dir = this->Target->GetDirectory(config, false);
  1831. // Add each name.
  1832. std::string f;
  1833. if(!name.empty())
  1834. {
  1835. f = dir;
  1836. f += "/";
  1837. f += name;
  1838. gg->AddToManifest(f);
  1839. }
  1840. if(!soName.empty())
  1841. {
  1842. f = dir;
  1843. f += "/";
  1844. f += soName;
  1845. gg->AddToManifest(f);
  1846. }
  1847. if(!realName.empty())
  1848. {
  1849. f = dir;
  1850. f += "/";
  1851. f += realName;
  1852. gg->AddToManifest(f);
  1853. }
  1854. if(!pdbName.empty())
  1855. {
  1856. f = dir;
  1857. f += "/";
  1858. f += pdbName;
  1859. gg->AddToManifest(f);
  1860. }
  1861. if(!impName.empty())
  1862. {
  1863. f = this->Target->GetDirectory(config, true);
  1864. f += "/";
  1865. f += impName;
  1866. gg->AddToManifest(f);
  1867. }
  1868. }
  1869. //----------------------------------------------------------------------------
  1870. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1871. bool implib, bool realname) const
  1872. {
  1873. if(this->Target->IsImported())
  1874. {
  1875. return this->Target->ImportedGetFullPath(config, implib);
  1876. }
  1877. else
  1878. {
  1879. return this->NormalGetFullPath(config, implib, realname);
  1880. }
  1881. }
  1882. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1883. bool implib,
  1884. bool realname) const
  1885. {
  1886. std::string fpath = this->Target->GetDirectory(config, implib);
  1887. fpath += "/";
  1888. if(this->Target->IsAppBundleOnApple())
  1889. {
  1890. fpath = this->BuildMacContentDirectory(fpath, config, false);
  1891. fpath += "/";
  1892. }
  1893. // Add the full name of the target.
  1894. if(implib)
  1895. {
  1896. fpath += this->GetFullName(config, true);
  1897. }
  1898. else if(realname)
  1899. {
  1900. fpath += this->NormalGetRealName(config);
  1901. }
  1902. else
  1903. {
  1904. fpath += this->GetFullName(config, false);
  1905. }
  1906. return fpath;
  1907. }
  1908. //----------------------------------------------------------------------------
  1909. std::string
  1910. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1911. {
  1912. // This should not be called for imported targets.
  1913. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1914. // enforcement of the limited imported target API.
  1915. if(this->Target->IsImported())
  1916. {
  1917. std::string msg = "NormalGetRealName called on imported target: ";
  1918. msg += this->GetName();
  1919. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1920. }
  1921. if(this->GetType() == cmTarget::EXECUTABLE)
  1922. {
  1923. // Compute the real name that will be built.
  1924. std::string name;
  1925. std::string realName;
  1926. std::string impName;
  1927. std::string pdbName;
  1928. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1929. return realName;
  1930. }
  1931. else
  1932. {
  1933. // Compute the real name that will be built.
  1934. std::string name;
  1935. std::string soName;
  1936. std::string realName;
  1937. std::string impName;
  1938. std::string pdbName;
  1939. this->GetLibraryNames(name, soName, realName,
  1940. impName, pdbName, config);
  1941. return realName;
  1942. }
  1943. }
  1944. //----------------------------------------------------------------------------
  1945. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  1946. std::string& soName,
  1947. std::string& realName,
  1948. std::string& impName,
  1949. std::string& pdbName,
  1950. const std::string& config) const
  1951. {
  1952. // This should not be called for imported targets.
  1953. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1954. // enforcement of the limited imported target API.
  1955. if(this->Target->IsImported())
  1956. {
  1957. std::string msg = "GetLibraryNames called on imported target: ";
  1958. msg += this->GetName();
  1959. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  1960. msg);
  1961. return;
  1962. }
  1963. // Check for library version properties.
  1964. const char* version = this->GetProperty("VERSION");
  1965. const char* soversion = this->GetProperty("SOVERSION");
  1966. if(!this->HasSOName(config) ||
  1967. this->Target->IsFrameworkOnApple())
  1968. {
  1969. // Versioning is supported only for shared libraries and modules,
  1970. // and then only when the platform supports an soname flag.
  1971. version = 0;
  1972. soversion = 0;
  1973. }
  1974. if(version && !soversion)
  1975. {
  1976. // The soversion must be set if the library version is set. Use
  1977. // the library version as the soversion.
  1978. soversion = version;
  1979. }
  1980. if(!version && soversion)
  1981. {
  1982. // Use the soversion as the library version.
  1983. version = soversion;
  1984. }
  1985. // Get the components of the library name.
  1986. std::string prefix;
  1987. std::string base;
  1988. std::string suffix;
  1989. this->GetFullNameInternal(config, false, prefix, base, suffix);
  1990. // The library name.
  1991. name = prefix+base+suffix;
  1992. if(this->Target->IsFrameworkOnApple())
  1993. {
  1994. realName = prefix;
  1995. if(!this->Makefile->PlatformIsAppleIos())
  1996. {
  1997. realName += "Versions/";
  1998. realName += this->Target->GetFrameworkVersion();
  1999. realName += "/";
  2000. }
  2001. realName += base;
  2002. soName = realName;
  2003. }
  2004. else
  2005. {
  2006. // The library's soname.
  2007. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  2008. name, soversion);
  2009. // The library's real name on disk.
  2010. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  2011. name, version);
  2012. }
  2013. // The import library name.
  2014. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2015. this->GetType() == cmTarget::MODULE_LIBRARY)
  2016. {
  2017. impName = this->GetFullNameInternal(config, true);
  2018. }
  2019. else
  2020. {
  2021. impName = "";
  2022. }
  2023. // The program database file name.
  2024. pdbName = this->GetPDBName(config);
  2025. }
  2026. //----------------------------------------------------------------------------
  2027. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2028. std::string& realName,
  2029. std::string& impName,
  2030. std::string& pdbName,
  2031. const std::string& config) const
  2032. {
  2033. // This should not be called for imported targets.
  2034. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2035. // enforcement of the limited imported target API.
  2036. if(this->Target->IsImported())
  2037. {
  2038. std::string msg =
  2039. "GetExecutableNames called on imported target: ";
  2040. msg += this->GetName();
  2041. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2042. }
  2043. // This versioning is supported only for executables and then only
  2044. // when the platform supports symbolic links.
  2045. #if defined(_WIN32) && !defined(__CYGWIN__)
  2046. const char* version = 0;
  2047. #else
  2048. // Check for executable version properties.
  2049. const char* version = this->GetProperty("VERSION");
  2050. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2051. {
  2052. version = 0;
  2053. }
  2054. #endif
  2055. // Get the components of the executable name.
  2056. std::string prefix;
  2057. std::string base;
  2058. std::string suffix;
  2059. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2060. // The executable name.
  2061. name = prefix+base+suffix;
  2062. // The executable's real name on disk.
  2063. #if defined(__CYGWIN__)
  2064. realName = prefix+base;
  2065. #else
  2066. realName = name;
  2067. #endif
  2068. if(version)
  2069. {
  2070. realName += "-";
  2071. realName += version;
  2072. }
  2073. #if defined(__CYGWIN__)
  2074. realName += suffix;
  2075. #endif
  2076. // The import library name.
  2077. impName = this->GetFullNameInternal(config, true);
  2078. // The program database file name.
  2079. pdbName = this->GetPDBName(config);
  2080. }
  2081. //----------------------------------------------------------------------------
  2082. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2083. bool implib) const
  2084. {
  2085. std::string prefix;
  2086. std::string base;
  2087. std::string suffix;
  2088. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2089. return prefix+base+suffix;
  2090. }
  2091. //----------------------------------------------------------------------------
  2092. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2093. bool implib,
  2094. std::string& outPrefix,
  2095. std::string& outBase,
  2096. std::string& outSuffix) const
  2097. {
  2098. // Use just the target name for non-main target types.
  2099. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2100. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2101. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2102. this->GetType() != cmTarget::EXECUTABLE)
  2103. {
  2104. outPrefix = "";
  2105. outBase = this->GetName();
  2106. outSuffix = "";
  2107. return;
  2108. }
  2109. // Return an empty name for the import library if this platform
  2110. // does not support import libraries.
  2111. if(implib &&
  2112. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2113. {
  2114. outPrefix = "";
  2115. outBase = "";
  2116. outSuffix = "";
  2117. return;
  2118. }
  2119. // The implib option is only allowed for shared libraries, module
  2120. // libraries, and executables.
  2121. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2122. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2123. this->GetType() != cmTarget::EXECUTABLE)
  2124. {
  2125. implib = false;
  2126. }
  2127. // Compute the full name for main target types.
  2128. const char* targetPrefix = (implib
  2129. ? this->GetProperty("IMPORT_PREFIX")
  2130. : this->GetProperty("PREFIX"));
  2131. const char* targetSuffix = (implib
  2132. ? this->GetProperty("IMPORT_SUFFIX")
  2133. : this->GetProperty("SUFFIX"));
  2134. const char* configPostfix = 0;
  2135. if(!config.empty())
  2136. {
  2137. std::string configProp = cmSystemTools::UpperCase(config);
  2138. configProp += "_POSTFIX";
  2139. configPostfix = this->GetProperty(configProp);
  2140. // Mac application bundles and frameworks have no postfix.
  2141. if(configPostfix &&
  2142. (this->Target->IsAppBundleOnApple()
  2143. || this->Target->IsFrameworkOnApple()))
  2144. {
  2145. configPostfix = 0;
  2146. }
  2147. }
  2148. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2149. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2150. // Check for language-specific default prefix and suffix.
  2151. std::string ll = this->GetLinkerLanguage(config);
  2152. if(!ll.empty())
  2153. {
  2154. if(!targetSuffix && suffixVar && *suffixVar)
  2155. {
  2156. std::string langSuff = suffixVar + std::string("_") + ll;
  2157. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2158. }
  2159. if(!targetPrefix && prefixVar && *prefixVar)
  2160. {
  2161. std::string langPrefix = prefixVar + std::string("_") + ll;
  2162. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2163. }
  2164. }
  2165. // if there is no prefix on the target use the cmake definition
  2166. if(!targetPrefix && prefixVar)
  2167. {
  2168. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2169. }
  2170. // if there is no suffix on the target use the cmake definition
  2171. if(!targetSuffix && suffixVar)
  2172. {
  2173. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2174. }
  2175. // frameworks have directory prefix but no suffix
  2176. std::string fw_prefix;
  2177. if(this->Target->IsFrameworkOnApple())
  2178. {
  2179. fw_prefix = this->GetOutputName(config, false);
  2180. fw_prefix += ".framework/";
  2181. targetPrefix = fw_prefix.c_str();
  2182. targetSuffix = 0;
  2183. }
  2184. if(this->Target->IsCFBundleOnApple())
  2185. {
  2186. fw_prefix = this->GetCFBundleDirectory(config, false);
  2187. fw_prefix += "/";
  2188. targetPrefix = fw_prefix.c_str();
  2189. targetSuffix = 0;
  2190. }
  2191. // Begin the final name with the prefix.
  2192. outPrefix = targetPrefix?targetPrefix:"";
  2193. // Append the target name or property-specified name.
  2194. outBase += this->GetOutputName(config, implib);
  2195. // Append the per-configuration postfix.
  2196. outBase += configPostfix?configPostfix:"";
  2197. // Name shared libraries with their version number on some platforms.
  2198. if(const char* soversion = this->GetProperty("SOVERSION"))
  2199. {
  2200. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2201. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2202. {
  2203. outBase += "-";
  2204. outBase += soversion;
  2205. }
  2206. }
  2207. // Append the suffix.
  2208. outSuffix = targetSuffix?targetSuffix:"";
  2209. }
  2210. //----------------------------------------------------------------------------
  2211. std::string
  2212. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  2213. {
  2214. return this->GetLinkClosure(config)->LinkerLanguage;
  2215. }
  2216. //----------------------------------------------------------------------------
  2217. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2218. {
  2219. std::string prefix;
  2220. std::string base;
  2221. std::string suffix;
  2222. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2223. std::vector<std::string> props;
  2224. std::string configUpper =
  2225. cmSystemTools::UpperCase(config);
  2226. if(!configUpper.empty())
  2227. {
  2228. // PDB_NAME_<CONFIG>
  2229. props.push_back("PDB_NAME_" + configUpper);
  2230. }
  2231. // PDB_NAME
  2232. props.push_back("PDB_NAME");
  2233. for(std::vector<std::string>::const_iterator i = props.begin();
  2234. i != props.end(); ++i)
  2235. {
  2236. if(const char* outName = this->GetProperty(*i))
  2237. {
  2238. base = outName;
  2239. break;
  2240. }
  2241. }
  2242. return prefix+base+".pdb";
  2243. }
  2244. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  2245. cmTarget const* t2) const
  2246. {
  2247. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2248. if (nameResult == 0)
  2249. {
  2250. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  2251. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  2252. }
  2253. return nameResult < 0;
  2254. }
  2255. //----------------------------------------------------------------------------
  2256. struct cmGeneratorTarget::SourceFileFlags
  2257. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2258. {
  2259. struct SourceFileFlags flags;
  2260. this->ConstructSourceFileFlags();
  2261. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  2262. this->SourceFlagsMap.find(sf);
  2263. if(si != this->SourceFlagsMap.end())
  2264. {
  2265. flags = si->second;
  2266. }
  2267. else
  2268. {
  2269. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  2270. // were not listed in one of the other lists.
  2271. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  2272. {
  2273. flags.MacFolder = location;
  2274. if(strcmp(location, "Resources") == 0)
  2275. {
  2276. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2277. }
  2278. else
  2279. {
  2280. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  2281. }
  2282. }
  2283. }
  2284. return flags;
  2285. }
  2286. //----------------------------------------------------------------------------
  2287. void cmGeneratorTarget::ConstructSourceFileFlags() const
  2288. {
  2289. if(this->SourceFileFlagsConstructed)
  2290. {
  2291. return;
  2292. }
  2293. this->SourceFileFlagsConstructed = true;
  2294. // Process public headers to mark the source files.
  2295. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  2296. {
  2297. std::vector<std::string> relFiles;
  2298. cmSystemTools::ExpandListArgument(files, relFiles);
  2299. for(std::vector<std::string>::iterator it = relFiles.begin();
  2300. it != relFiles.end(); ++it)
  2301. {
  2302. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2303. {
  2304. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2305. flags.MacFolder = "Headers";
  2306. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  2307. }
  2308. }
  2309. }
  2310. // Process private headers after public headers so that they take
  2311. // precedence if a file is listed in both.
  2312. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  2313. {
  2314. std::vector<std::string> relFiles;
  2315. cmSystemTools::ExpandListArgument(files, relFiles);
  2316. for(std::vector<std::string>::iterator it = relFiles.begin();
  2317. it != relFiles.end(); ++it)
  2318. {
  2319. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2320. {
  2321. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2322. flags.MacFolder = "PrivateHeaders";
  2323. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  2324. }
  2325. }
  2326. }
  2327. // Mark sources listed as resources.
  2328. if(const char* files = this->Target->GetProperty("RESOURCE"))
  2329. {
  2330. std::vector<std::string> relFiles;
  2331. cmSystemTools::ExpandListArgument(files, relFiles);
  2332. for(std::vector<std::string>::iterator it = relFiles.begin();
  2333. it != relFiles.end(); ++it)
  2334. {
  2335. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2336. {
  2337. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2338. flags.MacFolder = "Resources";
  2339. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2340. }
  2341. }
  2342. }
  2343. }
  2344. //----------------------------------------------------------------------------
  2345. const cmGeneratorTarget::CompatibleInterfacesBase&
  2346. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  2347. {
  2348. cmGeneratorTarget::CompatibleInterfaces& compat =
  2349. this->CompatibleInterfacesMap[config];
  2350. if(!compat.Done)
  2351. {
  2352. compat.Done = true;
  2353. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  2354. compat.PropsString.insert("AUTOUIC_OPTIONS");
  2355. std::vector<cmTarget const*> const& deps =
  2356. this->GetLinkImplementationClosure(config);
  2357. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  2358. li != deps.end(); ++li)
  2359. {
  2360. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  2361. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  2362. { \
  2363. std::vector<std::string> props; \
  2364. cmSystemTools::ExpandListArgument(prop, props); \
  2365. compat.Props##x.insert(props.begin(), props.end()); \
  2366. }
  2367. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  2368. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  2369. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  2370. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  2371. #undef CM_READ_COMPATIBLE_INTERFACE
  2372. }
  2373. }
  2374. return compat;
  2375. }
  2376. //----------------------------------------------------------------------------
  2377. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  2378. const std::string &p, const std::string& config) const
  2379. {
  2380. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2381. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2382. {
  2383. return false;
  2384. }
  2385. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  2386. }
  2387. //----------------------------------------------------------------------------
  2388. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  2389. const std::string &p, const std::string& config) const
  2390. {
  2391. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2392. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2393. {
  2394. return false;
  2395. }
  2396. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  2397. }
  2398. //----------------------------------------------------------------------------
  2399. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  2400. const std::string &p, const std::string& config) const
  2401. {
  2402. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2403. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2404. {
  2405. return false;
  2406. }
  2407. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  2408. }
  2409. //----------------------------------------------------------------------------
  2410. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  2411. const std::string &p, const std::string& config) const
  2412. {
  2413. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2414. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2415. {
  2416. return false;
  2417. }
  2418. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  2419. }
  2420. enum CompatibleType
  2421. {
  2422. BoolType,
  2423. StringType,
  2424. NumberMinType,
  2425. NumberMaxType
  2426. };
  2427. template<typename PropertyType>
  2428. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2429. const std::string& prop,
  2430. const std::string& config,
  2431. CompatibleType,
  2432. PropertyType *);
  2433. template<>
  2434. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2435. const std::string& prop,
  2436. const std::string& config,
  2437. CompatibleType, bool *)
  2438. {
  2439. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  2440. }
  2441. template<>
  2442. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2443. const std::string& prop,
  2444. const std::string& config,
  2445. CompatibleType t,
  2446. const char **)
  2447. {
  2448. switch(t)
  2449. {
  2450. case BoolType:
  2451. assert(0 && "String compatibility check function called for boolean");
  2452. return 0;
  2453. case StringType:
  2454. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  2455. case NumberMinType:
  2456. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  2457. case NumberMaxType:
  2458. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  2459. }
  2460. assert(0 && "Unreachable!");
  2461. return 0;
  2462. }
  2463. //----------------------------------------------------------------------------
  2464. template<typename PropertyType>
  2465. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  2466. cmTarget const* dependee,
  2467. const std::string& propName,
  2468. std::set<std::string> &emitted,
  2469. const std::string& config,
  2470. CompatibleType t,
  2471. PropertyType *)
  2472. {
  2473. const char *prop = dependee->GetProperty(propName);
  2474. if (!prop)
  2475. {
  2476. return;
  2477. }
  2478. std::vector<std::string> props;
  2479. cmSystemTools::ExpandListArgument(prop, props);
  2480. std::string pdir =
  2481. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  2482. pdir += "/Help/prop_tgt/";
  2483. for(std::vector<std::string>::iterator pi = props.begin();
  2484. pi != props.end(); ++pi)
  2485. {
  2486. std::string pname = cmSystemTools::HelpFileName(*pi);
  2487. std::string pfile = pdir + pname + ".rst";
  2488. if(cmSystemTools::FileExists(pfile.c_str(), true))
  2489. {
  2490. std::ostringstream e;
  2491. e << "Target \"" << dependee->GetName() << "\" has property \""
  2492. << *pi << "\" listed in its " << propName << " property. "
  2493. "This is not allowed. Only user-defined properties may appear "
  2494. "listed in the " << propName << " property.";
  2495. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  2496. return;
  2497. }
  2498. if(emitted.insert(*pi).second)
  2499. {
  2500. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  2501. t, 0);
  2502. if (cmSystemTools::GetErrorOccuredFlag())
  2503. {
  2504. return;
  2505. }
  2506. }
  2507. }
  2508. }
  2509. static std::string intersect(const std::set<std::string> &s1,
  2510. const std::set<std::string> &s2)
  2511. {
  2512. std::set<std::string> intersect;
  2513. std::set_intersection(s1.begin(),s1.end(),
  2514. s2.begin(),s2.end(),
  2515. std::inserter(intersect,intersect.begin()));
  2516. if (!intersect.empty())
  2517. {
  2518. return *intersect.begin();
  2519. }
  2520. return "";
  2521. }
  2522. static std::string intersect(const std::set<std::string> &s1,
  2523. const std::set<std::string> &s2,
  2524. const std::set<std::string> &s3)
  2525. {
  2526. std::string result;
  2527. result = intersect(s1, s2);
  2528. if (!result.empty())
  2529. return result;
  2530. result = intersect(s1, s3);
  2531. if (!result.empty())
  2532. return result;
  2533. return intersect(s2, s3);
  2534. }
  2535. static std::string intersect(const std::set<std::string> &s1,
  2536. const std::set<std::string> &s2,
  2537. const std::set<std::string> &s3,
  2538. const std::set<std::string> &s4)
  2539. {
  2540. std::string result;
  2541. result = intersect(s1, s2);
  2542. if (!result.empty())
  2543. return result;
  2544. result = intersect(s1, s3);
  2545. if (!result.empty())
  2546. return result;
  2547. result = intersect(s1, s4);
  2548. if (!result.empty())
  2549. return result;
  2550. return intersect(s2, s3, s4);
  2551. }
  2552. //----------------------------------------------------------------------------
  2553. void cmGeneratorTarget::CheckPropertyCompatibility(
  2554. cmComputeLinkInformation *info, const std::string& config) const
  2555. {
  2556. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  2557. std::set<std::string> emittedBools;
  2558. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  2559. std::set<std::string> emittedStrings;
  2560. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  2561. std::set<std::string> emittedMinNumbers;
  2562. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  2563. std::set<std::string> emittedMaxNumbers;
  2564. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  2565. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  2566. deps.begin(); li != deps.end(); ++li)
  2567. {
  2568. if (!li->Target)
  2569. {
  2570. continue;
  2571. }
  2572. checkPropertyConsistency<bool>(this, li->Target,
  2573. strBool,
  2574. emittedBools, config, BoolType, 0);
  2575. if (cmSystemTools::GetErrorOccuredFlag())
  2576. {
  2577. return;
  2578. }
  2579. checkPropertyConsistency<const char *>(this, li->Target,
  2580. strString,
  2581. emittedStrings, config,
  2582. StringType, 0);
  2583. if (cmSystemTools::GetErrorOccuredFlag())
  2584. {
  2585. return;
  2586. }
  2587. checkPropertyConsistency<const char *>(this, li->Target,
  2588. strNumMin,
  2589. emittedMinNumbers, config,
  2590. NumberMinType, 0);
  2591. if (cmSystemTools::GetErrorOccuredFlag())
  2592. {
  2593. return;
  2594. }
  2595. checkPropertyConsistency<const char *>(this, li->Target,
  2596. strNumMax,
  2597. emittedMaxNumbers, config,
  2598. NumberMaxType, 0);
  2599. if (cmSystemTools::GetErrorOccuredFlag())
  2600. {
  2601. return;
  2602. }
  2603. }
  2604. std::string prop = intersect(emittedBools,
  2605. emittedStrings,
  2606. emittedMinNumbers,
  2607. emittedMaxNumbers);
  2608. if (!prop.empty())
  2609. {
  2610. // Use a sorted std::vector to keep the error message sorted.
  2611. std::vector<std::string> props;
  2612. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  2613. if (i != emittedBools.end())
  2614. {
  2615. props.push_back(strBool);
  2616. }
  2617. i = emittedStrings.find(prop);
  2618. if (i != emittedStrings.end())
  2619. {
  2620. props.push_back(strString);
  2621. }
  2622. i = emittedMinNumbers.find(prop);
  2623. if (i != emittedMinNumbers.end())
  2624. {
  2625. props.push_back(strNumMin);
  2626. }
  2627. i = emittedMaxNumbers.find(prop);
  2628. if (i != emittedMaxNumbers.end())
  2629. {
  2630. props.push_back(strNumMax);
  2631. }
  2632. std::sort(props.begin(), props.end());
  2633. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  2634. propsString += " and the " + props.back();
  2635. std::ostringstream e;
  2636. e << "Property \"" << prop << "\" appears in both the "
  2637. << propsString <<
  2638. " property in the dependencies of target \"" << this->GetName() <<
  2639. "\". This is not allowed. A property may only require compatibility "
  2640. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  2641. "string interpretation, but not a mixture.";
  2642. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  2643. }
  2644. }
  2645. //----------------------------------------------------------------------------
  2646. std::string compatibilityType(CompatibleType t)
  2647. {
  2648. switch(t)
  2649. {
  2650. case BoolType:
  2651. return "Boolean compatibility";
  2652. case StringType:
  2653. return "String compatibility";
  2654. case NumberMaxType:
  2655. return "Numeric maximum compatibility";
  2656. case NumberMinType:
  2657. return "Numeric minimum compatibility";
  2658. }
  2659. assert(0 && "Unreachable!");
  2660. return "";
  2661. }
  2662. //----------------------------------------------------------------------------
  2663. std::string compatibilityAgree(CompatibleType t, bool dominant)
  2664. {
  2665. switch(t)
  2666. {
  2667. case BoolType:
  2668. case StringType:
  2669. return dominant ? "(Disagree)\n" : "(Agree)\n";
  2670. case NumberMaxType:
  2671. case NumberMinType:
  2672. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  2673. }
  2674. assert(0 && "Unreachable!");
  2675. return "";
  2676. }
  2677. //----------------------------------------------------------------------------
  2678. template<typename PropertyType>
  2679. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  2680. //----------------------------------------------------------------------------
  2681. template<>
  2682. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  2683. {
  2684. return tgt->GetPropertyAsBool(prop);
  2685. }
  2686. //----------------------------------------------------------------------------
  2687. template<>
  2688. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  2689. const std::string& prop)
  2690. {
  2691. return tgt->GetProperty(prop);
  2692. }
  2693. template<typename PropertyType>
  2694. std::string valueAsString(PropertyType);
  2695. template<>
  2696. std::string valueAsString<bool>(bool value)
  2697. {
  2698. return value ? "TRUE" : "FALSE";
  2699. }
  2700. template<>
  2701. std::string valueAsString<const char*>(const char* value)
  2702. {
  2703. return value ? value : "(unset)";
  2704. }
  2705. template<typename PropertyType>
  2706. PropertyType impliedValue(PropertyType);
  2707. template<>
  2708. bool impliedValue<bool>(bool)
  2709. {
  2710. return false;
  2711. }
  2712. template<>
  2713. const char* impliedValue<const char*>(const char*)
  2714. {
  2715. return "";
  2716. }
  2717. //----------------------------------------------------------------------------
  2718. template<typename PropertyType>
  2719. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  2720. PropertyType rhs,
  2721. CompatibleType t);
  2722. //----------------------------------------------------------------------------
  2723. template<>
  2724. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  2725. CompatibleType)
  2726. {
  2727. return std::make_pair(lhs == rhs, lhs);
  2728. }
  2729. //----------------------------------------------------------------------------
  2730. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  2731. const char *rhs)
  2732. {
  2733. const bool b = strcmp(lhs, rhs) == 0;
  2734. return std::make_pair(b, b ? lhs : 0);
  2735. }
  2736. //----------------------------------------------------------------------------
  2737. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  2738. const char *rhs,
  2739. CompatibleType t)
  2740. {
  2741. char *pEnd;
  2742. const char* const null_ptr = 0;
  2743. long lnum = strtol(lhs, &pEnd, 0);
  2744. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  2745. {
  2746. return std::pair<bool, const char*>(false, null_ptr);
  2747. }
  2748. long rnum = strtol(rhs, &pEnd, 0);
  2749. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  2750. {
  2751. return std::pair<bool, const char*>(false, null_ptr);
  2752. }
  2753. if (t == NumberMaxType)
  2754. {
  2755. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  2756. }
  2757. else
  2758. {
  2759. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  2760. }
  2761. }
  2762. //----------------------------------------------------------------------------
  2763. template<>
  2764. std::pair<bool, const char*> consistentProperty(const char *lhs,
  2765. const char *rhs,
  2766. CompatibleType t)
  2767. {
  2768. if (!lhs && !rhs)
  2769. {
  2770. return std::make_pair(true, lhs);
  2771. }
  2772. if (!lhs)
  2773. {
  2774. return std::make_pair(true, rhs);
  2775. }
  2776. if (!rhs)
  2777. {
  2778. return std::make_pair(true, lhs);
  2779. }
  2780. const char* const null_ptr = 0;
  2781. switch(t)
  2782. {
  2783. case BoolType:
  2784. assert(0 && "consistentProperty for strings called with BoolType");
  2785. return std::pair<bool, const char*>(false, null_ptr);
  2786. case StringType:
  2787. return consistentStringProperty(lhs, rhs);
  2788. case NumberMinType:
  2789. case NumberMaxType:
  2790. return consistentNumberProperty(lhs, rhs, t);
  2791. }
  2792. assert(0 && "Unreachable!");
  2793. return std::pair<bool, const char*>(false, null_ptr);
  2794. }
  2795. //----------------------------------------------------------------------------
  2796. template<typename PropertyType>
  2797. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  2798. const std::string &p,
  2799. const std::string& config,
  2800. const char *defaultValue,
  2801. CompatibleType t,
  2802. PropertyType *)
  2803. {
  2804. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  2805. const bool explicitlySet = tgt->Target->GetProperties()
  2806. .find(p)
  2807. != tgt->Target->GetProperties().end();
  2808. const bool impliedByUse =
  2809. tgt->Target->IsNullImpliedByLinkLibraries(p);
  2810. assert((impliedByUse ^ explicitlySet)
  2811. || (!impliedByUse && !explicitlySet));
  2812. std::vector<cmTarget const*> const& deps =
  2813. tgt->GetLinkImplementationClosure(config);
  2814. if(deps.empty())
  2815. {
  2816. return propContent;
  2817. }
  2818. bool propInitialized = explicitlySet;
  2819. std::string report = " * Target \"";
  2820. report += tgt->GetName();
  2821. if (explicitlySet)
  2822. {
  2823. report += "\" has property content \"";
  2824. report += valueAsString<PropertyType>(propContent);
  2825. report += "\"\n";
  2826. }
  2827. else if (impliedByUse)
  2828. {
  2829. report += "\" property is implied by use.\n";
  2830. }
  2831. else
  2832. {
  2833. report += "\" property not set.\n";
  2834. }
  2835. std::string interfaceProperty = "INTERFACE_" + p;
  2836. for(std::vector<cmTarget const*>::const_iterator li =
  2837. deps.begin();
  2838. li != deps.end(); ++li)
  2839. {
  2840. // An error should be reported if one dependency
  2841. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  2842. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  2843. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  2844. // with a dependency.
  2845. cmTarget const* theTarget = *li;
  2846. const bool ifaceIsSet = theTarget->GetProperties()
  2847. .find(interfaceProperty)
  2848. != theTarget->GetProperties().end();
  2849. PropertyType ifacePropContent =
  2850. getTypedProperty<PropertyType>(theTarget,
  2851. interfaceProperty);
  2852. std::string reportEntry;
  2853. if (ifaceIsSet)
  2854. {
  2855. reportEntry += " * Target \"";
  2856. reportEntry += theTarget->GetName();
  2857. reportEntry += "\" property value \"";
  2858. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  2859. reportEntry += "\" ";
  2860. }
  2861. if (explicitlySet)
  2862. {
  2863. if (ifaceIsSet)
  2864. {
  2865. std::pair<bool, PropertyType> consistent =
  2866. consistentProperty(propContent,
  2867. ifacePropContent, t);
  2868. report += reportEntry;
  2869. report += compatibilityAgree(t, propContent != consistent.second);
  2870. if (!consistent.first)
  2871. {
  2872. std::ostringstream e;
  2873. e << "Property " << p << " on target \""
  2874. << tgt->GetName() << "\" does\nnot match the "
  2875. "INTERFACE_" << p << " property requirement\nof "
  2876. "dependency \"" << theTarget->GetName() << "\".\n";
  2877. cmSystemTools::Error(e.str().c_str());
  2878. break;
  2879. }
  2880. else
  2881. {
  2882. propContent = consistent.second;
  2883. continue;
  2884. }
  2885. }
  2886. else
  2887. {
  2888. // Explicitly set on target and not set in iface. Can't disagree.
  2889. continue;
  2890. }
  2891. }
  2892. else if (impliedByUse)
  2893. {
  2894. propContent = impliedValue<PropertyType>(propContent);
  2895. if (ifaceIsSet)
  2896. {
  2897. std::pair<bool, PropertyType> consistent =
  2898. consistentProperty(propContent,
  2899. ifacePropContent, t);
  2900. report += reportEntry;
  2901. report += compatibilityAgree(t, propContent != consistent.second);
  2902. if (!consistent.first)
  2903. {
  2904. std::ostringstream e;
  2905. e << "Property " << p << " on target \""
  2906. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  2907. << " because it was used to determine the link libraries\n"
  2908. "already. The INTERFACE_" << p << " property on\ndependency \""
  2909. << theTarget->GetName() << "\" is in conflict.\n";
  2910. cmSystemTools::Error(e.str().c_str());
  2911. break;
  2912. }
  2913. else
  2914. {
  2915. propContent = consistent.second;
  2916. continue;
  2917. }
  2918. }
  2919. else
  2920. {
  2921. // Implicitly set on target and not set in iface. Can't disagree.
  2922. continue;
  2923. }
  2924. }
  2925. else
  2926. {
  2927. if (ifaceIsSet)
  2928. {
  2929. if (propInitialized)
  2930. {
  2931. std::pair<bool, PropertyType> consistent =
  2932. consistentProperty(propContent,
  2933. ifacePropContent, t);
  2934. report += reportEntry;
  2935. report += compatibilityAgree(t, propContent != consistent.second);
  2936. if (!consistent.first)
  2937. {
  2938. std::ostringstream e;
  2939. e << "The INTERFACE_" << p << " property of \""
  2940. << theTarget->GetName() << "\" does\nnot agree with the value "
  2941. "of " << p << " already determined\nfor \""
  2942. << tgt->GetName() << "\".\n";
  2943. cmSystemTools::Error(e.str().c_str());
  2944. break;
  2945. }
  2946. else
  2947. {
  2948. propContent = consistent.second;
  2949. continue;
  2950. }
  2951. }
  2952. else
  2953. {
  2954. report += reportEntry + "(Interface set)\n";
  2955. propContent = ifacePropContent;
  2956. propInitialized = true;
  2957. }
  2958. }
  2959. else
  2960. {
  2961. // Not set. Nothing to agree on.
  2962. continue;
  2963. }
  2964. }
  2965. }
  2966. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  2967. report, compatibilityType(t));
  2968. return propContent;
  2969. }
  2970. //----------------------------------------------------------------------------
  2971. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  2972. const std::string &p, const std::string& config) const
  2973. {
  2974. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  2975. "FALSE",
  2976. BoolType, 0);
  2977. }
  2978. //----------------------------------------------------------------------------
  2979. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  2980. const std::string &p,
  2981. const std::string& config) const
  2982. {
  2983. return checkInterfacePropertyCompatibility<const char *>(this,
  2984. p,
  2985. config,
  2986. "empty",
  2987. StringType, 0);
  2988. }
  2989. //----------------------------------------------------------------------------
  2990. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  2991. const std::string &p,
  2992. const std::string& config) const
  2993. {
  2994. return checkInterfacePropertyCompatibility<const char *>(this,
  2995. p,
  2996. config,
  2997. "empty",
  2998. NumberMinType, 0);
  2999. }
  3000. //----------------------------------------------------------------------------
  3001. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3002. const std::string &p,
  3003. const std::string& config) const
  3004. {
  3005. return checkInterfacePropertyCompatibility<const char *>(this,
  3006. p,
  3007. config,
  3008. "empty",
  3009. NumberMaxType, 0);
  3010. }
  3011. //----------------------------------------------------------------------------
  3012. cmComputeLinkInformation*
  3013. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  3014. {
  3015. // Lookup any existing information for this configuration.
  3016. std::string key(cmSystemTools::UpperCase(config));
  3017. cmTargetLinkInformationMap::iterator
  3018. i = this->LinkInformation.find(key);
  3019. if(i == this->LinkInformation.end())
  3020. {
  3021. // Compute information for this configuration.
  3022. cmComputeLinkInformation* info =
  3023. new cmComputeLinkInformation(this, config);
  3024. if(!info || !info->Compute())
  3025. {
  3026. delete info;
  3027. info = 0;
  3028. }
  3029. // Store the information for this configuration.
  3030. cmTargetLinkInformationMap::value_type entry(key, info);
  3031. i = this->LinkInformation.insert(entry).first;
  3032. if (info)
  3033. {
  3034. this->CheckPropertyCompatibility(info, config);
  3035. }
  3036. }
  3037. return i->second;
  3038. }
  3039. //----------------------------------------------------------------------------
  3040. void
  3041. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  3042. const std::string &result,
  3043. const std::string &report,
  3044. const std::string &compatibilityType) const
  3045. {
  3046. std::vector<std::string> debugProperties;
  3047. const char *debugProp = this->Target->GetMakefile()
  3048. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  3049. if (debugProp)
  3050. {
  3051. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3052. }
  3053. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  3054. && std::find(debugProperties.begin(),
  3055. debugProperties.end(),
  3056. p)
  3057. != debugProperties.end();
  3058. if (this->Target->GetMakefile()->IsConfigured())
  3059. {
  3060. this->DebugCompatiblePropertiesDone[p] = true;
  3061. }
  3062. if (!debugOrigin)
  3063. {
  3064. return;
  3065. }
  3066. std::string areport = compatibilityType;
  3067. areport += std::string(" of property \"") + p + "\" for target \"";
  3068. areport += std::string(this->GetName());
  3069. areport += "\" (result: \"";
  3070. areport += result;
  3071. areport += "\"):\n" + report;
  3072. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3073. }
  3074. //----------------------------------------------------------------------------
  3075. cmLinkInterface const*
  3076. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  3077. cmTarget const* head) const
  3078. {
  3079. // Imported targets have their own link interface.
  3080. if(this->IsImported())
  3081. {
  3082. return this->Target->GetImportLinkInterface(config, head, false);
  3083. }
  3084. // Link interfaces are not supported for executables that do not
  3085. // export symbols.
  3086. if(this->GetType() == cmTarget::EXECUTABLE &&
  3087. !this->Target->IsExecutableWithExports())
  3088. {
  3089. return 0;
  3090. }
  3091. // Lookup any existing link interface for this configuration.
  3092. cmHeadToLinkInterfaceMap& hm =
  3093. this->Target->GetHeadToLinkInterfaceMap(config);
  3094. // If the link interface does not depend on the head target
  3095. // then return the one we computed first.
  3096. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3097. {
  3098. return &hm.begin()->second;
  3099. }
  3100. cmOptionalLinkInterface& iface = hm[head];
  3101. if(!iface.LibrariesDone)
  3102. {
  3103. iface.LibrariesDone = true;
  3104. this->Target->ComputeLinkInterfaceLibraries(
  3105. config, iface, head, false);
  3106. }
  3107. if(!iface.AllDone)
  3108. {
  3109. iface.AllDone = true;
  3110. if(iface.Exists)
  3111. {
  3112. this->ComputeLinkInterface(config, iface, head);
  3113. }
  3114. }
  3115. return iface.Exists? &iface : 0;
  3116. }
  3117. //----------------------------------------------------------------------------
  3118. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  3119. cmOptionalLinkInterface &iface,
  3120. cmTarget const* headTarget) const
  3121. {
  3122. if(iface.ExplicitLibraries)
  3123. {
  3124. if(this->GetType() == cmTarget::SHARED_LIBRARY
  3125. || this->GetType() == cmTarget::STATIC_LIBRARY
  3126. || this->GetType() == cmTarget::INTERFACE_LIBRARY)
  3127. {
  3128. // Shared libraries may have runtime implementation dependencies
  3129. // on other shared libraries that are not in the interface.
  3130. UNORDERED_SET<std::string> emitted;
  3131. for(std::vector<cmLinkItem>::const_iterator
  3132. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3133. {
  3134. emitted.insert(*li);
  3135. }
  3136. if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
  3137. {
  3138. cmTarget::LinkImplementation const* impl =
  3139. this->Target->GetLinkImplementation(config);
  3140. for(std::vector<cmLinkImplItem>::const_iterator
  3141. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3142. {
  3143. if(emitted.insert(*li).second)
  3144. {
  3145. if(li->Target)
  3146. {
  3147. // This is a runtime dependency on another shared library.
  3148. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  3149. {
  3150. iface.SharedDeps.push_back(*li);
  3151. }
  3152. }
  3153. else
  3154. {
  3155. // TODO: Recognize shared library file names. Perhaps this
  3156. // should be moved to cmComputeLinkInformation, but that creates
  3157. // a chicken-and-egg problem since this list is needed for its
  3158. // construction.
  3159. }
  3160. }
  3161. }
  3162. }
  3163. }
  3164. }
  3165. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3166. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3167. {
  3168. // The link implementation is the default link interface.
  3169. cmLinkImplementationLibraries const*
  3170. impl = this->Target->GetLinkImplementationLibrariesInternal(config,
  3171. headTarget);
  3172. iface.ImplementationIsInterface = true;
  3173. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3174. }
  3175. if(this->Target->LinkLanguagePropagatesToDependents())
  3176. {
  3177. // Targets using this archive need its language runtime libraries.
  3178. if(cmTarget::LinkImplementation const* impl =
  3179. this->Target->GetLinkImplementation(config))
  3180. {
  3181. iface.Languages = impl->Languages;
  3182. }
  3183. }
  3184. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3185. {
  3186. // Construct the property name suffix for this configuration.
  3187. std::string suffix = "_";
  3188. if(!config.empty())
  3189. {
  3190. suffix += cmSystemTools::UpperCase(config);
  3191. }
  3192. else
  3193. {
  3194. suffix += "NOCONFIG";
  3195. }
  3196. // How many repetitions are needed if this library has cyclic
  3197. // dependencies?
  3198. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3199. propName += suffix;
  3200. if(const char* config_reps = this->GetProperty(propName))
  3201. {
  3202. sscanf(config_reps, "%u", &iface.Multiplicity);
  3203. }
  3204. else if(const char* reps =
  3205. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  3206. {
  3207. sscanf(reps, "%u", &iface.Multiplicity);
  3208. }
  3209. }
  3210. }