cmGeneratorTarget.cxx 92 KB

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