cmGeneratorTarget.cxx 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  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->Target->BuildMacContentDirectory("", "",
  515. false);
  516. if(!macdir.empty())
  517. {
  518. location += "/";
  519. location += macdir;
  520. }
  521. }
  522. location += "/";
  523. location += this->Target->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->Target->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. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  643. {
  644. if(this->Target->IsImported())
  645. {
  646. // Lookup the imported soname.
  647. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  648. {
  649. if(info->NoSOName)
  650. {
  651. // The imported library has no builtin soname so the name
  652. // searched at runtime will be just the filename.
  653. return cmSystemTools::GetFilenameName(info->Location);
  654. }
  655. else
  656. {
  657. // Use the soname given if any.
  658. if(info->SOName.find("@rpath/") == 0)
  659. {
  660. return info->SOName.substr(6);
  661. }
  662. return info->SOName;
  663. }
  664. }
  665. else
  666. {
  667. return "";
  668. }
  669. }
  670. else
  671. {
  672. // Compute the soname that will be built.
  673. std::string name;
  674. std::string soName;
  675. std::string realName;
  676. std::string impName;
  677. std::string pdbName;
  678. this->GetLibraryNames(name, soName, realName,
  679. impName, pdbName, config);
  680. return soName;
  681. }
  682. }
  683. //----------------------------------------------------------------------------
  684. std::string
  685. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  686. {
  687. std::string data;
  688. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  689. return data;
  690. }
  691. //----------------------------------------------------------------------------
  692. void
  693. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  694. const std::string &config) const
  695. {
  696. std::vector<cmSourceFile const*> objectFiles;
  697. this->GetExternalObjects(objectFiles, config);
  698. std::vector<cmTarget*> objectLibraries;
  699. for(std::vector<cmSourceFile const*>::const_iterator
  700. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  701. {
  702. std::string objLib = (*it)->GetObjectLibrary();
  703. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  704. {
  705. objectLibraries.push_back(tgt);
  706. }
  707. }
  708. std::vector<cmTarget*>::const_iterator end
  709. = cmRemoveDuplicates(objectLibraries);
  710. for(std::vector<cmTarget*>::const_iterator
  711. ti = objectLibraries.begin();
  712. ti != end; ++ti)
  713. {
  714. cmTarget* objLib = *ti;
  715. cmGeneratorTarget* ogt =
  716. this->GlobalGenerator->GetGeneratorTarget(objLib);
  717. std::vector<cmSourceFile const*> objectSources;
  718. ogt->GetObjectSources(objectSources, config);
  719. for(std::vector<cmSourceFile const*>::const_iterator
  720. si = objectSources.begin();
  721. si != objectSources.end(); ++si)
  722. {
  723. std::string obj = ogt->ObjectDirectory;
  724. obj += ogt->Objects[*si];
  725. objs.push_back(obj);
  726. }
  727. }
  728. }
  729. //----------------------------------------------------------------------------
  730. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  731. const std::string& config) const
  732. {
  733. const char *prop
  734. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  735. config);
  736. if (!prop)
  737. {
  738. return;
  739. }
  740. cmGeneratorExpression ge;
  741. cmGeneratorExpressionDAGChecker dagChecker(
  742. this->GetName(),
  743. "AUTOUIC_OPTIONS", 0, 0);
  744. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  745. ->Evaluate(this->Makefile,
  746. config,
  747. false,
  748. this->Target,
  749. &dagChecker),
  750. result);
  751. }
  752. //----------------------------------------------------------------------------
  753. void processILibs(const std::string& config,
  754. cmTarget const* headTarget,
  755. cmLinkItem const& item,
  756. std::vector<cmTarget const*>& tgts,
  757. std::set<cmTarget const*>& emitted)
  758. {
  759. if (item.Target && emitted.insert(item.Target).second)
  760. {
  761. tgts.push_back(item.Target);
  762. if(cmTarget::LinkInterfaceLibraries const* iface =
  763. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  764. {
  765. for(std::vector<cmLinkItem>::const_iterator
  766. it = iface->Libraries.begin();
  767. it != iface->Libraries.end(); ++it)
  768. {
  769. processILibs(config, headTarget, *it, tgts, emitted);
  770. }
  771. }
  772. }
  773. }
  774. //----------------------------------------------------------------------------
  775. const std::vector<const cmTarget*>&
  776. cmGeneratorTarget::GetLinkImplementationClosure(
  777. const std::string& config) const
  778. {
  779. LinkImplClosure& tgts =
  780. this->LinkImplClosureMap[config];
  781. if(!tgts.Done)
  782. {
  783. tgts.Done = true;
  784. std::set<cmTarget const*> emitted;
  785. cmTarget::LinkImplementationLibraries const* impl
  786. = this->Target->GetLinkImplementationLibraries(config);
  787. for(std::vector<cmLinkImplItem>::const_iterator
  788. it = impl->Libraries.begin();
  789. it != impl->Libraries.end(); ++it)
  790. {
  791. processILibs(config, this->Target, *it, tgts , emitted);
  792. }
  793. }
  794. return tgts;
  795. }
  796. //----------------------------------------------------------------------------
  797. class cmTargetTraceDependencies
  798. {
  799. public:
  800. cmTargetTraceDependencies(cmGeneratorTarget* target);
  801. void Trace();
  802. private:
  803. cmTarget* Target;
  804. cmGeneratorTarget* GeneratorTarget;
  805. cmMakefile* Makefile;
  806. cmGlobalGenerator const* GlobalGenerator;
  807. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  808. SourceEntry* CurrentEntry;
  809. std::queue<cmSourceFile*> SourceQueue;
  810. std::set<cmSourceFile*> SourcesQueued;
  811. typedef std::map<std::string, cmSourceFile*> NameMapType;
  812. NameMapType NameMap;
  813. std::vector<std::string> NewSources;
  814. void QueueSource(cmSourceFile* sf);
  815. void FollowName(std::string const& name);
  816. void FollowNames(std::vector<std::string> const& names);
  817. bool IsUtility(std::string const& dep);
  818. void CheckCustomCommand(cmCustomCommand const& cc);
  819. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  820. void FollowCommandDepends(cmCustomCommand const& cc,
  821. const std::string& config,
  822. std::set<std::string>& emitted);
  823. };
  824. //----------------------------------------------------------------------------
  825. cmTargetTraceDependencies
  826. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  827. Target(target->Target), GeneratorTarget(target)
  828. {
  829. // Convenience.
  830. this->Makefile = this->Target->GetMakefile();
  831. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  832. this->CurrentEntry = 0;
  833. // Queue all the source files already specified for the target.
  834. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  835. {
  836. std::vector<std::string> configs;
  837. this->Makefile->GetConfigurations(configs);
  838. if (configs.empty())
  839. {
  840. configs.push_back("");
  841. }
  842. std::set<cmSourceFile*> emitted;
  843. for(std::vector<std::string>::const_iterator ci = configs.begin();
  844. ci != configs.end(); ++ci)
  845. {
  846. std::vector<cmSourceFile*> sources;
  847. this->Target->GetSourceFiles(sources, *ci);
  848. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  849. si != sources.end(); ++si)
  850. {
  851. cmSourceFile* sf = *si;
  852. const std::set<cmTarget const*> tgts =
  853. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  854. if (tgts.find(this->Target) != tgts.end())
  855. {
  856. std::ostringstream e;
  857. e << "Evaluation output file\n \"" << sf->GetFullPath()
  858. << "\"\ndepends on the sources of a target it is used in. This "
  859. "is a dependency loop and is not allowed.";
  860. this->GeneratorTarget
  861. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  862. return;
  863. }
  864. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  865. {
  866. this->SourceQueue.push(sf);
  867. }
  868. }
  869. }
  870. }
  871. // Queue pre-build, pre-link, and post-build rule dependencies.
  872. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  873. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  874. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  875. }
  876. //----------------------------------------------------------------------------
  877. void cmTargetTraceDependencies::Trace()
  878. {
  879. // Process one dependency at a time until the queue is empty.
  880. while(!this->SourceQueue.empty())
  881. {
  882. // Get the next source from the queue.
  883. cmSourceFile* sf = this->SourceQueue.front();
  884. this->SourceQueue.pop();
  885. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  886. // Queue dependencies added explicitly by the user.
  887. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  888. {
  889. std::vector<std::string> objDeps;
  890. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  891. for(std::vector<std::string>::iterator odi = objDeps.begin();
  892. odi != objDeps.end(); ++odi)
  893. {
  894. if (cmSystemTools::FileIsFullPath(*odi))
  895. {
  896. *odi = cmSystemTools::CollapseFullPath(*odi);
  897. }
  898. }
  899. this->FollowNames(objDeps);
  900. }
  901. // Queue the source needed to generate this file, if any.
  902. this->FollowName(sf->GetFullPath());
  903. // Queue dependencies added programatically by commands.
  904. this->FollowNames(sf->GetDepends());
  905. // Queue custom command dependencies.
  906. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  907. {
  908. this->CheckCustomCommand(*cc);
  909. }
  910. }
  911. this->CurrentEntry = 0;
  912. this->Target->AddTracedSources(this->NewSources);
  913. }
  914. //----------------------------------------------------------------------------
  915. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  916. {
  917. if(this->SourcesQueued.insert(sf).second)
  918. {
  919. this->SourceQueue.push(sf);
  920. // Make sure this file is in the target at the end.
  921. this->NewSources.push_back(sf->GetFullPath());
  922. }
  923. }
  924. //----------------------------------------------------------------------------
  925. void cmTargetTraceDependencies::FollowName(std::string const& name)
  926. {
  927. NameMapType::iterator i = this->NameMap.find(name);
  928. if(i == this->NameMap.end())
  929. {
  930. // Check if we know how to generate this file.
  931. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  932. NameMapType::value_type entry(name, sf);
  933. i = this->NameMap.insert(entry).first;
  934. }
  935. if(cmSourceFile* sf = i->second)
  936. {
  937. // Record the dependency we just followed.
  938. if(this->CurrentEntry)
  939. {
  940. this->CurrentEntry->Depends.push_back(sf);
  941. }
  942. this->QueueSource(sf);
  943. }
  944. }
  945. //----------------------------------------------------------------------------
  946. void
  947. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  948. {
  949. for(std::vector<std::string>::const_iterator i = names.begin();
  950. i != names.end(); ++i)
  951. {
  952. this->FollowName(*i);
  953. }
  954. }
  955. //----------------------------------------------------------------------------
  956. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  957. {
  958. // Dependencies on targets (utilities) are supposed to be named by
  959. // just the target name. However for compatibility we support
  960. // naming the output file generated by the target (assuming there is
  961. // no output-name property which old code would not have set). In
  962. // that case the target name will be the file basename of the
  963. // dependency.
  964. std::string util = cmSystemTools::GetFilenameName(dep);
  965. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  966. {
  967. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  968. }
  969. // Check for a target with this name.
  970. if(cmGeneratorTarget* t
  971. = this->Makefile->FindGeneratorTargetToUse(util))
  972. {
  973. // If we find the target and the dep was given as a full path,
  974. // then make sure it was not a full path to something else, and
  975. // the fact that the name matched a target was just a coincidence.
  976. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  977. {
  978. if(t->GetType() >= cmTarget::EXECUTABLE &&
  979. t->GetType() <= cmTarget::MODULE_LIBRARY)
  980. {
  981. // This is really only for compatibility so we do not need to
  982. // worry about configuration names and output names.
  983. std::string tLocation = t->GetLocationForBuild();
  984. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  985. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  986. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  987. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  988. if(depLocation == tLocation)
  989. {
  990. this->Target->AddUtility(util);
  991. return true;
  992. }
  993. }
  994. }
  995. else
  996. {
  997. // The original name of the dependency was not a full path. It
  998. // must name a target, so add the target-level dependency.
  999. this->Target->AddUtility(util);
  1000. return true;
  1001. }
  1002. }
  1003. // The dependency does not name a target built in this project.
  1004. return false;
  1005. }
  1006. //----------------------------------------------------------------------------
  1007. void
  1008. cmTargetTraceDependencies
  1009. ::CheckCustomCommand(cmCustomCommand const& cc)
  1010. {
  1011. // Transform command names that reference targets built in this
  1012. // project to corresponding target-level dependencies.
  1013. cmGeneratorExpression ge(cc.GetBacktrace());
  1014. // Add target-level dependencies referenced by generator expressions.
  1015. std::set<cmTarget*> targets;
  1016. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1017. cit != cc.GetCommandLines().end(); ++cit)
  1018. {
  1019. std::string const& command = *cit->begin();
  1020. // Check for a target with this name.
  1021. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1022. {
  1023. if(t->GetType() == cmTarget::EXECUTABLE)
  1024. {
  1025. // The command refers to an executable target built in
  1026. // this project. Add the target-level dependency to make
  1027. // sure the executable is up to date before this custom
  1028. // command possibly runs.
  1029. this->Target->AddUtility(command);
  1030. }
  1031. }
  1032. // Check for target references in generator expressions.
  1033. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1034. cli != cit->end(); ++cli)
  1035. {
  1036. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1037. = ge.Parse(*cli);
  1038. cge->Evaluate(this->Makefile, "", true);
  1039. std::set<cmTarget*> geTargets = cge->GetTargets();
  1040. targets.insert(geTargets.begin(), geTargets.end());
  1041. }
  1042. }
  1043. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1044. ti != targets.end(); ++ti)
  1045. {
  1046. this->Target->AddUtility((*ti)->GetName());
  1047. }
  1048. // Queue the custom command dependencies.
  1049. std::vector<std::string> configs;
  1050. std::set<std::string> emitted;
  1051. this->Makefile->GetConfigurations(configs);
  1052. if (configs.empty())
  1053. {
  1054. configs.push_back("");
  1055. }
  1056. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1057. ci != configs.end(); ++ci)
  1058. {
  1059. this->FollowCommandDepends(cc, *ci, emitted);
  1060. }
  1061. }
  1062. //----------------------------------------------------------------------------
  1063. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1064. const std::string& config,
  1065. std::set<std::string>& emitted)
  1066. {
  1067. cmCustomCommandGenerator ccg(cc, config,
  1068. this->GeneratorTarget->LocalGenerator);
  1069. const std::vector<std::string>& depends = ccg.GetDepends();
  1070. for(std::vector<std::string>::const_iterator di = depends.begin();
  1071. di != depends.end(); ++di)
  1072. {
  1073. std::string const& dep = *di;
  1074. if(emitted.insert(dep).second)
  1075. {
  1076. if(!this->IsUtility(dep))
  1077. {
  1078. // The dependency does not name a target and may be a file we
  1079. // know how to generate. Queue it.
  1080. this->FollowName(dep);
  1081. }
  1082. }
  1083. }
  1084. }
  1085. //----------------------------------------------------------------------------
  1086. void
  1087. cmTargetTraceDependencies
  1088. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1089. {
  1090. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1091. cli != commands.end(); ++cli)
  1092. {
  1093. this->CheckCustomCommand(*cli);
  1094. }
  1095. }
  1096. //----------------------------------------------------------------------------
  1097. void cmGeneratorTarget::TraceDependencies()
  1098. {
  1099. // CMake-generated targets have no dependencies to trace. Normally tracing
  1100. // would find nothing anyway, but when building CMake itself the "install"
  1101. // target command ends up referencing the "cmake" target but we do not
  1102. // really want the dependency because "install" depend on "all" anyway.
  1103. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1104. {
  1105. return;
  1106. }
  1107. // Use a helper object to trace the dependencies.
  1108. cmTargetTraceDependencies tracer(this);
  1109. tracer.Trace();
  1110. }
  1111. //----------------------------------------------------------------------------
  1112. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1113. std::vector<std::string>& archVec) const
  1114. {
  1115. const char* archs = 0;
  1116. if(!config.empty())
  1117. {
  1118. std::string defVarName = "OSX_ARCHITECTURES_";
  1119. defVarName += cmSystemTools::UpperCase(config);
  1120. archs = this->Target->GetProperty(defVarName);
  1121. }
  1122. if(!archs)
  1123. {
  1124. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1125. }
  1126. if(archs)
  1127. {
  1128. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1129. }
  1130. }
  1131. //----------------------------------------------------------------------------
  1132. std::string
  1133. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1134. std::string const& config) const
  1135. {
  1136. switch(this->GetType())
  1137. {
  1138. case cmTarget::STATIC_LIBRARY:
  1139. {
  1140. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1141. if(this->GetFeatureAsBool(
  1142. "INTERPROCEDURAL_OPTIMIZATION", config))
  1143. {
  1144. std::string varIPO = var + "_IPO";
  1145. if(this->Makefile->GetDefinition(varIPO))
  1146. {
  1147. return varIPO;
  1148. }
  1149. }
  1150. return var;
  1151. }
  1152. case cmTarget::SHARED_LIBRARY:
  1153. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1154. case cmTarget::MODULE_LIBRARY:
  1155. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1156. case cmTarget::EXECUTABLE:
  1157. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1158. default:
  1159. break;
  1160. }
  1161. return "";
  1162. }
  1163. //----------------------------------------------------------------------------
  1164. std::vector<std::string>
  1165. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1166. const std::string& lang) const
  1167. {
  1168. return this->Target->GetIncludeDirectories(config, lang);
  1169. }
  1170. //----------------------------------------------------------------------------
  1171. void cmGeneratorTarget::GenerateTargetManifest(
  1172. const std::string& config) const
  1173. {
  1174. if (this->Target->IsImported())
  1175. {
  1176. return;
  1177. }
  1178. cmMakefile* mf = this->Target->GetMakefile();
  1179. cmGlobalGenerator* gg = mf->GetGlobalGenerator();
  1180. // Get the names.
  1181. std::string name;
  1182. std::string soName;
  1183. std::string realName;
  1184. std::string impName;
  1185. std::string pdbName;
  1186. if(this->GetType() == cmTarget::EXECUTABLE)
  1187. {
  1188. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1189. }
  1190. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1191. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1192. this->GetType() == cmTarget::MODULE_LIBRARY)
  1193. {
  1194. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  1195. config);
  1196. }
  1197. else
  1198. {
  1199. return;
  1200. }
  1201. // Get the directory.
  1202. std::string dir = this->Target->GetDirectory(config, false);
  1203. // Add each name.
  1204. std::string f;
  1205. if(!name.empty())
  1206. {
  1207. f = dir;
  1208. f += "/";
  1209. f += name;
  1210. gg->AddToManifest(f);
  1211. }
  1212. if(!soName.empty())
  1213. {
  1214. f = dir;
  1215. f += "/";
  1216. f += soName;
  1217. gg->AddToManifest(f);
  1218. }
  1219. if(!realName.empty())
  1220. {
  1221. f = dir;
  1222. f += "/";
  1223. f += realName;
  1224. gg->AddToManifest(f);
  1225. }
  1226. if(!pdbName.empty())
  1227. {
  1228. f = dir;
  1229. f += "/";
  1230. f += pdbName;
  1231. gg->AddToManifest(f);
  1232. }
  1233. if(!impName.empty())
  1234. {
  1235. f = this->Target->GetDirectory(config, true);
  1236. f += "/";
  1237. f += impName;
  1238. gg->AddToManifest(f);
  1239. }
  1240. }
  1241. //----------------------------------------------------------------------------
  1242. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1243. bool implib, bool realname) const
  1244. {
  1245. if(this->Target->IsImported())
  1246. {
  1247. return this->Target->ImportedGetFullPath(config, implib);
  1248. }
  1249. else
  1250. {
  1251. return this->NormalGetFullPath(config, implib, realname);
  1252. }
  1253. }
  1254. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1255. bool implib,
  1256. bool realname) const
  1257. {
  1258. std::string fpath = this->Target->GetDirectory(config, implib);
  1259. fpath += "/";
  1260. if(this->Target->IsAppBundleOnApple())
  1261. {
  1262. fpath = this->Target->BuildMacContentDirectory(fpath, config, false);
  1263. fpath += "/";
  1264. }
  1265. // Add the full name of the target.
  1266. if(implib)
  1267. {
  1268. fpath += this->Target->GetFullName(config, true);
  1269. }
  1270. else if(realname)
  1271. {
  1272. fpath += this->NormalGetRealName(config);
  1273. }
  1274. else
  1275. {
  1276. fpath += this->Target->GetFullName(config, false);
  1277. }
  1278. return fpath;
  1279. }
  1280. //----------------------------------------------------------------------------
  1281. std::string
  1282. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1283. {
  1284. // This should not be called for imported targets.
  1285. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1286. // enforcement of the limited imported target API.
  1287. if(this->Target->IsImported())
  1288. {
  1289. std::string msg = "NormalGetRealName called on imported target: ";
  1290. msg += this->GetName();
  1291. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1292. }
  1293. if(this->GetType() == cmTarget::EXECUTABLE)
  1294. {
  1295. // Compute the real name that will be built.
  1296. std::string name;
  1297. std::string realName;
  1298. std::string impName;
  1299. std::string pdbName;
  1300. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1301. return realName;
  1302. }
  1303. else
  1304. {
  1305. // Compute the real name that will be built.
  1306. std::string name;
  1307. std::string soName;
  1308. std::string realName;
  1309. std::string impName;
  1310. std::string pdbName;
  1311. this->GetLibraryNames(name, soName, realName,
  1312. impName, pdbName, config);
  1313. return realName;
  1314. }
  1315. }
  1316. //----------------------------------------------------------------------------
  1317. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  1318. std::string& soName,
  1319. std::string& realName,
  1320. std::string& impName,
  1321. std::string& pdbName,
  1322. const std::string& config) const
  1323. {
  1324. // This should not be called for imported targets.
  1325. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1326. // enforcement of the limited imported target API.
  1327. if(this->Target->IsImported())
  1328. {
  1329. std::string msg = "GetLibraryNames called on imported target: ";
  1330. msg += this->GetName();
  1331. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  1332. msg);
  1333. return;
  1334. }
  1335. // Check for library version properties.
  1336. const char* version = this->GetProperty("VERSION");
  1337. const char* soversion = this->GetProperty("SOVERSION");
  1338. if(!this->HasSOName(config) ||
  1339. this->Target->IsFrameworkOnApple())
  1340. {
  1341. // Versioning is supported only for shared libraries and modules,
  1342. // and then only when the platform supports an soname flag.
  1343. version = 0;
  1344. soversion = 0;
  1345. }
  1346. if(version && !soversion)
  1347. {
  1348. // The soversion must be set if the library version is set. Use
  1349. // the library version as the soversion.
  1350. soversion = version;
  1351. }
  1352. if(!version && soversion)
  1353. {
  1354. // Use the soversion as the library version.
  1355. version = soversion;
  1356. }
  1357. // Get the components of the library name.
  1358. std::string prefix;
  1359. std::string base;
  1360. std::string suffix;
  1361. this->Target->GetFullNameInternal(config, false, prefix, base, suffix);
  1362. // The library name.
  1363. name = prefix+base+suffix;
  1364. if(this->Target->IsFrameworkOnApple())
  1365. {
  1366. realName = prefix;
  1367. realName += "Versions/";
  1368. realName += this->Target->GetFrameworkVersion();
  1369. realName += "/";
  1370. realName += base;
  1371. soName = realName;
  1372. }
  1373. else
  1374. {
  1375. // The library's soname.
  1376. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  1377. name, soversion);
  1378. // The library's real name on disk.
  1379. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  1380. name, version);
  1381. }
  1382. // The import library name.
  1383. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  1384. this->GetType() == cmTarget::MODULE_LIBRARY)
  1385. {
  1386. impName = this->Target->GetFullNameInternal(config, true);
  1387. }
  1388. else
  1389. {
  1390. impName = "";
  1391. }
  1392. // The program database file name.
  1393. pdbName = this->GetPDBName(config);
  1394. }
  1395. //----------------------------------------------------------------------------
  1396. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  1397. std::string& realName,
  1398. std::string& impName,
  1399. std::string& pdbName,
  1400. const std::string& config) const
  1401. {
  1402. // This should not be called for imported targets.
  1403. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1404. // enforcement of the limited imported target API.
  1405. if(this->Target->IsImported())
  1406. {
  1407. std::string msg =
  1408. "GetExecutableNames called on imported target: ";
  1409. msg += this->GetName();
  1410. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1411. }
  1412. // This versioning is supported only for executables and then only
  1413. // when the platform supports symbolic links.
  1414. #if defined(_WIN32) && !defined(__CYGWIN__)
  1415. const char* version = 0;
  1416. #else
  1417. // Check for executable version properties.
  1418. const char* version = this->GetProperty("VERSION");
  1419. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  1420. {
  1421. version = 0;
  1422. }
  1423. #endif
  1424. // Get the components of the executable name.
  1425. std::string prefix;
  1426. std::string base;
  1427. std::string suffix;
  1428. this->Target->GetFullNameInternal(config, false, prefix, base, suffix);
  1429. // The executable name.
  1430. name = prefix+base+suffix;
  1431. // The executable's real name on disk.
  1432. #if defined(__CYGWIN__)
  1433. realName = prefix+base;
  1434. #else
  1435. realName = name;
  1436. #endif
  1437. if(version)
  1438. {
  1439. realName += "-";
  1440. realName += version;
  1441. }
  1442. #if defined(__CYGWIN__)
  1443. realName += suffix;
  1444. #endif
  1445. // The import library name.
  1446. impName = this->Target->GetFullNameInternal(config, true);
  1447. // The program database file name.
  1448. pdbName = this->GetPDBName(config);
  1449. }
  1450. //----------------------------------------------------------------------------
  1451. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  1452. {
  1453. std::string prefix;
  1454. std::string base;
  1455. std::string suffix;
  1456. this->Target->GetFullNameInternal(config, false, prefix, base, suffix);
  1457. std::vector<std::string> props;
  1458. std::string configUpper =
  1459. cmSystemTools::UpperCase(config);
  1460. if(!configUpper.empty())
  1461. {
  1462. // PDB_NAME_<CONFIG>
  1463. props.push_back("PDB_NAME_" + configUpper);
  1464. }
  1465. // PDB_NAME
  1466. props.push_back("PDB_NAME");
  1467. for(std::vector<std::string>::const_iterator i = props.begin();
  1468. i != props.end(); ++i)
  1469. {
  1470. if(const char* outName = this->GetProperty(*i))
  1471. {
  1472. base = outName;
  1473. break;
  1474. }
  1475. }
  1476. return prefix+base+".pdb";
  1477. }
  1478. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  1479. cmTarget const* t2) const
  1480. {
  1481. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  1482. if (nameResult == 0)
  1483. {
  1484. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  1485. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  1486. }
  1487. return nameResult < 0;
  1488. }
  1489. //----------------------------------------------------------------------------
  1490. struct cmGeneratorTarget::SourceFileFlags
  1491. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  1492. {
  1493. struct SourceFileFlags flags;
  1494. this->ConstructSourceFileFlags();
  1495. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1496. this->SourceFlagsMap.find(sf);
  1497. if(si != this->SourceFlagsMap.end())
  1498. {
  1499. flags = si->second;
  1500. }
  1501. else
  1502. {
  1503. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1504. // were not listed in one of the other lists.
  1505. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1506. {
  1507. flags.MacFolder = location;
  1508. if(strcmp(location, "Resources") == 0)
  1509. {
  1510. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1511. }
  1512. else
  1513. {
  1514. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  1515. }
  1516. }
  1517. }
  1518. return flags;
  1519. }
  1520. //----------------------------------------------------------------------------
  1521. void cmGeneratorTarget::ConstructSourceFileFlags() const
  1522. {
  1523. if(this->SourceFileFlagsConstructed)
  1524. {
  1525. return;
  1526. }
  1527. this->SourceFileFlagsConstructed = true;
  1528. // Process public headers to mark the source files.
  1529. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  1530. {
  1531. std::vector<std::string> relFiles;
  1532. cmSystemTools::ExpandListArgument(files, relFiles);
  1533. for(std::vector<std::string>::iterator it = relFiles.begin();
  1534. it != relFiles.end(); ++it)
  1535. {
  1536. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1537. {
  1538. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1539. flags.MacFolder = "Headers";
  1540. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  1541. }
  1542. }
  1543. }
  1544. // Process private headers after public headers so that they take
  1545. // precedence if a file is listed in both.
  1546. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  1547. {
  1548. std::vector<std::string> relFiles;
  1549. cmSystemTools::ExpandListArgument(files, relFiles);
  1550. for(std::vector<std::string>::iterator it = relFiles.begin();
  1551. it != relFiles.end(); ++it)
  1552. {
  1553. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1554. {
  1555. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1556. flags.MacFolder = "PrivateHeaders";
  1557. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  1558. }
  1559. }
  1560. }
  1561. // Mark sources listed as resources.
  1562. if(const char* files = this->Target->GetProperty("RESOURCE"))
  1563. {
  1564. std::vector<std::string> relFiles;
  1565. cmSystemTools::ExpandListArgument(files, relFiles);
  1566. for(std::vector<std::string>::iterator it = relFiles.begin();
  1567. it != relFiles.end(); ++it)
  1568. {
  1569. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1570. {
  1571. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1572. flags.MacFolder = "Resources";
  1573. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1574. }
  1575. }
  1576. }
  1577. }
  1578. //----------------------------------------------------------------------------
  1579. const cmGeneratorTarget::CompatibleInterfacesBase&
  1580. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  1581. {
  1582. cmGeneratorTarget::CompatibleInterfaces& compat =
  1583. this->CompatibleInterfacesMap[config];
  1584. if(!compat.Done)
  1585. {
  1586. compat.Done = true;
  1587. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  1588. compat.PropsString.insert("AUTOUIC_OPTIONS");
  1589. std::vector<cmTarget const*> const& deps =
  1590. this->GetLinkImplementationClosure(config);
  1591. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  1592. li != deps.end(); ++li)
  1593. {
  1594. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  1595. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  1596. { \
  1597. std::vector<std::string> props; \
  1598. cmSystemTools::ExpandListArgument(prop, props); \
  1599. compat.Props##x.insert(props.begin(), props.end()); \
  1600. }
  1601. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  1602. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  1603. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  1604. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  1605. #undef CM_READ_COMPATIBLE_INTERFACE
  1606. }
  1607. }
  1608. return compat;
  1609. }
  1610. //----------------------------------------------------------------------------
  1611. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  1612. const std::string &p, const std::string& config) const
  1613. {
  1614. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1615. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1616. {
  1617. return false;
  1618. }
  1619. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  1620. }
  1621. //----------------------------------------------------------------------------
  1622. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  1623. const std::string &p, const std::string& config) const
  1624. {
  1625. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1626. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1627. {
  1628. return false;
  1629. }
  1630. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  1631. }
  1632. //----------------------------------------------------------------------------
  1633. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  1634. const std::string &p, const std::string& config) const
  1635. {
  1636. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1637. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1638. {
  1639. return false;
  1640. }
  1641. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  1642. }
  1643. //----------------------------------------------------------------------------
  1644. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  1645. const std::string &p, const std::string& config) const
  1646. {
  1647. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1648. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1649. {
  1650. return false;
  1651. }
  1652. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  1653. }
  1654. enum CompatibleType
  1655. {
  1656. BoolType,
  1657. StringType,
  1658. NumberMinType,
  1659. NumberMaxType
  1660. };
  1661. template<typename PropertyType>
  1662. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1663. const std::string& prop,
  1664. const std::string& config,
  1665. CompatibleType,
  1666. PropertyType *);
  1667. template<>
  1668. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1669. const std::string& prop,
  1670. const std::string& config,
  1671. CompatibleType, bool *)
  1672. {
  1673. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  1674. }
  1675. template<>
  1676. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1677. const std::string& prop,
  1678. const std::string& config,
  1679. CompatibleType t,
  1680. const char **)
  1681. {
  1682. switch(t)
  1683. {
  1684. case BoolType:
  1685. assert(0 && "String compatibility check function called for boolean");
  1686. return 0;
  1687. case StringType:
  1688. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  1689. case NumberMinType:
  1690. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  1691. case NumberMaxType:
  1692. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  1693. }
  1694. assert(0 && "Unreachable!");
  1695. return 0;
  1696. }
  1697. //----------------------------------------------------------------------------
  1698. template<typename PropertyType>
  1699. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  1700. cmTarget const* dependee,
  1701. const std::string& propName,
  1702. std::set<std::string> &emitted,
  1703. const std::string& config,
  1704. CompatibleType t,
  1705. PropertyType *)
  1706. {
  1707. const char *prop = dependee->GetProperty(propName);
  1708. if (!prop)
  1709. {
  1710. return;
  1711. }
  1712. std::vector<std::string> props;
  1713. cmSystemTools::ExpandListArgument(prop, props);
  1714. std::string pdir =
  1715. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  1716. pdir += "/Help/prop_tgt/";
  1717. for(std::vector<std::string>::iterator pi = props.begin();
  1718. pi != props.end(); ++pi)
  1719. {
  1720. std::string pname = cmSystemTools::HelpFileName(*pi);
  1721. std::string pfile = pdir + pname + ".rst";
  1722. if(cmSystemTools::FileExists(pfile.c_str(), true))
  1723. {
  1724. std::ostringstream e;
  1725. e << "Target \"" << dependee->GetName() << "\" has property \""
  1726. << *pi << "\" listed in its " << propName << " property. "
  1727. "This is not allowed. Only user-defined properties may appear "
  1728. "listed in the " << propName << " property.";
  1729. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  1730. return;
  1731. }
  1732. if(emitted.insert(*pi).second)
  1733. {
  1734. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  1735. t, 0);
  1736. if (cmSystemTools::GetErrorOccuredFlag())
  1737. {
  1738. return;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. static std::string intersect(const std::set<std::string> &s1,
  1744. const std::set<std::string> &s2)
  1745. {
  1746. std::set<std::string> intersect;
  1747. std::set_intersection(s1.begin(),s1.end(),
  1748. s2.begin(),s2.end(),
  1749. std::inserter(intersect,intersect.begin()));
  1750. if (!intersect.empty())
  1751. {
  1752. return *intersect.begin();
  1753. }
  1754. return "";
  1755. }
  1756. static std::string intersect(const std::set<std::string> &s1,
  1757. const std::set<std::string> &s2,
  1758. const std::set<std::string> &s3)
  1759. {
  1760. std::string result;
  1761. result = intersect(s1, s2);
  1762. if (!result.empty())
  1763. return result;
  1764. result = intersect(s1, s3);
  1765. if (!result.empty())
  1766. return result;
  1767. return intersect(s2, s3);
  1768. }
  1769. static std::string intersect(const std::set<std::string> &s1,
  1770. const std::set<std::string> &s2,
  1771. const std::set<std::string> &s3,
  1772. const std::set<std::string> &s4)
  1773. {
  1774. std::string result;
  1775. result = intersect(s1, s2);
  1776. if (!result.empty())
  1777. return result;
  1778. result = intersect(s1, s3);
  1779. if (!result.empty())
  1780. return result;
  1781. result = intersect(s1, s4);
  1782. if (!result.empty())
  1783. return result;
  1784. return intersect(s2, s3, s4);
  1785. }
  1786. //----------------------------------------------------------------------------
  1787. void cmGeneratorTarget::CheckPropertyCompatibility(
  1788. cmComputeLinkInformation *info, const std::string& config) const
  1789. {
  1790. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  1791. std::set<std::string> emittedBools;
  1792. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  1793. std::set<std::string> emittedStrings;
  1794. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  1795. std::set<std::string> emittedMinNumbers;
  1796. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  1797. std::set<std::string> emittedMaxNumbers;
  1798. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  1799. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  1800. deps.begin(); li != deps.end(); ++li)
  1801. {
  1802. if (!li->Target)
  1803. {
  1804. continue;
  1805. }
  1806. checkPropertyConsistency<bool>(this, li->Target,
  1807. strBool,
  1808. emittedBools, config, BoolType, 0);
  1809. if (cmSystemTools::GetErrorOccuredFlag())
  1810. {
  1811. return;
  1812. }
  1813. checkPropertyConsistency<const char *>(this, li->Target,
  1814. strString,
  1815. emittedStrings, config,
  1816. StringType, 0);
  1817. if (cmSystemTools::GetErrorOccuredFlag())
  1818. {
  1819. return;
  1820. }
  1821. checkPropertyConsistency<const char *>(this, li->Target,
  1822. strNumMin,
  1823. emittedMinNumbers, config,
  1824. NumberMinType, 0);
  1825. if (cmSystemTools::GetErrorOccuredFlag())
  1826. {
  1827. return;
  1828. }
  1829. checkPropertyConsistency<const char *>(this, li->Target,
  1830. strNumMax,
  1831. emittedMaxNumbers, config,
  1832. NumberMaxType, 0);
  1833. if (cmSystemTools::GetErrorOccuredFlag())
  1834. {
  1835. return;
  1836. }
  1837. }
  1838. std::string prop = intersect(emittedBools,
  1839. emittedStrings,
  1840. emittedMinNumbers,
  1841. emittedMaxNumbers);
  1842. if (!prop.empty())
  1843. {
  1844. // Use a sorted std::vector to keep the error message sorted.
  1845. std::vector<std::string> props;
  1846. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  1847. if (i != emittedBools.end())
  1848. {
  1849. props.push_back(strBool);
  1850. }
  1851. i = emittedStrings.find(prop);
  1852. if (i != emittedStrings.end())
  1853. {
  1854. props.push_back(strString);
  1855. }
  1856. i = emittedMinNumbers.find(prop);
  1857. if (i != emittedMinNumbers.end())
  1858. {
  1859. props.push_back(strNumMin);
  1860. }
  1861. i = emittedMaxNumbers.find(prop);
  1862. if (i != emittedMaxNumbers.end())
  1863. {
  1864. props.push_back(strNumMax);
  1865. }
  1866. std::sort(props.begin(), props.end());
  1867. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  1868. propsString += " and the " + props.back();
  1869. std::ostringstream e;
  1870. e << "Property \"" << prop << "\" appears in both the "
  1871. << propsString <<
  1872. " property in the dependencies of target \"" << this->GetName() <<
  1873. "\". This is not allowed. A property may only require compatibility "
  1874. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  1875. "string interpretation, but not a mixture.";
  1876. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1877. }
  1878. }
  1879. //----------------------------------------------------------------------------
  1880. std::string compatibilityType(CompatibleType t)
  1881. {
  1882. switch(t)
  1883. {
  1884. case BoolType:
  1885. return "Boolean compatibility";
  1886. case StringType:
  1887. return "String compatibility";
  1888. case NumberMaxType:
  1889. return "Numeric maximum compatibility";
  1890. case NumberMinType:
  1891. return "Numeric minimum compatibility";
  1892. }
  1893. assert(0 && "Unreachable!");
  1894. return "";
  1895. }
  1896. //----------------------------------------------------------------------------
  1897. std::string compatibilityAgree(CompatibleType t, bool dominant)
  1898. {
  1899. switch(t)
  1900. {
  1901. case BoolType:
  1902. case StringType:
  1903. return dominant ? "(Disagree)\n" : "(Agree)\n";
  1904. case NumberMaxType:
  1905. case NumberMinType:
  1906. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  1907. }
  1908. assert(0 && "Unreachable!");
  1909. return "";
  1910. }
  1911. //----------------------------------------------------------------------------
  1912. template<typename PropertyType>
  1913. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  1914. //----------------------------------------------------------------------------
  1915. template<>
  1916. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  1917. {
  1918. return tgt->GetPropertyAsBool(prop);
  1919. }
  1920. //----------------------------------------------------------------------------
  1921. template<>
  1922. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  1923. const std::string& prop)
  1924. {
  1925. return tgt->GetProperty(prop);
  1926. }
  1927. template<typename PropertyType>
  1928. std::string valueAsString(PropertyType);
  1929. template<>
  1930. std::string valueAsString<bool>(bool value)
  1931. {
  1932. return value ? "TRUE" : "FALSE";
  1933. }
  1934. template<>
  1935. std::string valueAsString<const char*>(const char* value)
  1936. {
  1937. return value ? value : "(unset)";
  1938. }
  1939. template<typename PropertyType>
  1940. PropertyType impliedValue(PropertyType);
  1941. template<>
  1942. bool impliedValue<bool>(bool)
  1943. {
  1944. return false;
  1945. }
  1946. template<>
  1947. const char* impliedValue<const char*>(const char*)
  1948. {
  1949. return "";
  1950. }
  1951. //----------------------------------------------------------------------------
  1952. template<typename PropertyType>
  1953. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  1954. PropertyType rhs,
  1955. CompatibleType t);
  1956. //----------------------------------------------------------------------------
  1957. template<>
  1958. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  1959. CompatibleType)
  1960. {
  1961. return std::make_pair(lhs == rhs, lhs);
  1962. }
  1963. //----------------------------------------------------------------------------
  1964. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  1965. const char *rhs)
  1966. {
  1967. const bool b = strcmp(lhs, rhs) == 0;
  1968. return std::make_pair(b, b ? lhs : 0);
  1969. }
  1970. //----------------------------------------------------------------------------
  1971. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  1972. const char *rhs,
  1973. CompatibleType t)
  1974. {
  1975. char *pEnd;
  1976. const char* const null_ptr = 0;
  1977. long lnum = strtol(lhs, &pEnd, 0);
  1978. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  1979. {
  1980. return std::pair<bool, const char*>(false, null_ptr);
  1981. }
  1982. long rnum = strtol(rhs, &pEnd, 0);
  1983. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  1984. {
  1985. return std::pair<bool, const char*>(false, null_ptr);
  1986. }
  1987. if (t == NumberMaxType)
  1988. {
  1989. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  1990. }
  1991. else
  1992. {
  1993. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  1994. }
  1995. }
  1996. //----------------------------------------------------------------------------
  1997. template<>
  1998. std::pair<bool, const char*> consistentProperty(const char *lhs,
  1999. const char *rhs,
  2000. CompatibleType t)
  2001. {
  2002. if (!lhs && !rhs)
  2003. {
  2004. return std::make_pair(true, lhs);
  2005. }
  2006. if (!lhs)
  2007. {
  2008. return std::make_pair(true, rhs);
  2009. }
  2010. if (!rhs)
  2011. {
  2012. return std::make_pair(true, lhs);
  2013. }
  2014. const char* const null_ptr = 0;
  2015. switch(t)
  2016. {
  2017. case BoolType:
  2018. assert(0 && "consistentProperty for strings called with BoolType");
  2019. return std::pair<bool, const char*>(false, null_ptr);
  2020. case StringType:
  2021. return consistentStringProperty(lhs, rhs);
  2022. case NumberMinType:
  2023. case NumberMaxType:
  2024. return consistentNumberProperty(lhs, rhs, t);
  2025. }
  2026. assert(0 && "Unreachable!");
  2027. return std::pair<bool, const char*>(false, null_ptr);
  2028. }
  2029. //----------------------------------------------------------------------------
  2030. template<typename PropertyType>
  2031. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  2032. const std::string &p,
  2033. const std::string& config,
  2034. const char *defaultValue,
  2035. CompatibleType t,
  2036. PropertyType *)
  2037. {
  2038. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  2039. const bool explicitlySet = tgt->Target->GetProperties()
  2040. .find(p)
  2041. != tgt->Target->GetProperties().end();
  2042. const bool impliedByUse =
  2043. tgt->Target->IsNullImpliedByLinkLibraries(p);
  2044. assert((impliedByUse ^ explicitlySet)
  2045. || (!impliedByUse && !explicitlySet));
  2046. std::vector<cmTarget const*> const& deps =
  2047. tgt->GetLinkImplementationClosure(config);
  2048. if(deps.empty())
  2049. {
  2050. return propContent;
  2051. }
  2052. bool propInitialized = explicitlySet;
  2053. std::string report = " * Target \"";
  2054. report += tgt->GetName();
  2055. if (explicitlySet)
  2056. {
  2057. report += "\" has property content \"";
  2058. report += valueAsString<PropertyType>(propContent);
  2059. report += "\"\n";
  2060. }
  2061. else if (impliedByUse)
  2062. {
  2063. report += "\" property is implied by use.\n";
  2064. }
  2065. else
  2066. {
  2067. report += "\" property not set.\n";
  2068. }
  2069. std::string interfaceProperty = "INTERFACE_" + p;
  2070. for(std::vector<cmTarget const*>::const_iterator li =
  2071. deps.begin();
  2072. li != deps.end(); ++li)
  2073. {
  2074. // An error should be reported if one dependency
  2075. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  2076. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  2077. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  2078. // with a dependency.
  2079. cmTarget const* theTarget = *li;
  2080. const bool ifaceIsSet = theTarget->GetProperties()
  2081. .find(interfaceProperty)
  2082. != theTarget->GetProperties().end();
  2083. PropertyType ifacePropContent =
  2084. getTypedProperty<PropertyType>(theTarget,
  2085. interfaceProperty);
  2086. std::string reportEntry;
  2087. if (ifaceIsSet)
  2088. {
  2089. reportEntry += " * Target \"";
  2090. reportEntry += theTarget->GetName();
  2091. reportEntry += "\" property value \"";
  2092. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  2093. reportEntry += "\" ";
  2094. }
  2095. if (explicitlySet)
  2096. {
  2097. if (ifaceIsSet)
  2098. {
  2099. std::pair<bool, PropertyType> consistent =
  2100. consistentProperty(propContent,
  2101. ifacePropContent, t);
  2102. report += reportEntry;
  2103. report += compatibilityAgree(t, propContent != consistent.second);
  2104. if (!consistent.first)
  2105. {
  2106. std::ostringstream e;
  2107. e << "Property " << p << " on target \""
  2108. << tgt->GetName() << "\" does\nnot match the "
  2109. "INTERFACE_" << p << " property requirement\nof "
  2110. "dependency \"" << theTarget->GetName() << "\".\n";
  2111. cmSystemTools::Error(e.str().c_str());
  2112. break;
  2113. }
  2114. else
  2115. {
  2116. propContent = consistent.second;
  2117. continue;
  2118. }
  2119. }
  2120. else
  2121. {
  2122. // Explicitly set on target and not set in iface. Can't disagree.
  2123. continue;
  2124. }
  2125. }
  2126. else if (impliedByUse)
  2127. {
  2128. propContent = impliedValue<PropertyType>(propContent);
  2129. if (ifaceIsSet)
  2130. {
  2131. std::pair<bool, PropertyType> consistent =
  2132. consistentProperty(propContent,
  2133. ifacePropContent, t);
  2134. report += reportEntry;
  2135. report += compatibilityAgree(t, propContent != consistent.second);
  2136. if (!consistent.first)
  2137. {
  2138. std::ostringstream e;
  2139. e << "Property " << p << " on target \""
  2140. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  2141. << " because it was used to determine the link libraries\n"
  2142. "already. The INTERFACE_" << p << " property on\ndependency \""
  2143. << theTarget->GetName() << "\" is in conflict.\n";
  2144. cmSystemTools::Error(e.str().c_str());
  2145. break;
  2146. }
  2147. else
  2148. {
  2149. propContent = consistent.second;
  2150. continue;
  2151. }
  2152. }
  2153. else
  2154. {
  2155. // Implicitly set on target and not set in iface. Can't disagree.
  2156. continue;
  2157. }
  2158. }
  2159. else
  2160. {
  2161. if (ifaceIsSet)
  2162. {
  2163. if (propInitialized)
  2164. {
  2165. std::pair<bool, PropertyType> consistent =
  2166. consistentProperty(propContent,
  2167. ifacePropContent, t);
  2168. report += reportEntry;
  2169. report += compatibilityAgree(t, propContent != consistent.second);
  2170. if (!consistent.first)
  2171. {
  2172. std::ostringstream e;
  2173. e << "The INTERFACE_" << p << " property of \""
  2174. << theTarget->GetName() << "\" does\nnot agree with the value "
  2175. "of " << p << " already determined\nfor \""
  2176. << tgt->GetName() << "\".\n";
  2177. cmSystemTools::Error(e.str().c_str());
  2178. break;
  2179. }
  2180. else
  2181. {
  2182. propContent = consistent.second;
  2183. continue;
  2184. }
  2185. }
  2186. else
  2187. {
  2188. report += reportEntry + "(Interface set)\n";
  2189. propContent = ifacePropContent;
  2190. propInitialized = true;
  2191. }
  2192. }
  2193. else
  2194. {
  2195. // Not set. Nothing to agree on.
  2196. continue;
  2197. }
  2198. }
  2199. }
  2200. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  2201. report, compatibilityType(t));
  2202. return propContent;
  2203. }
  2204. //----------------------------------------------------------------------------
  2205. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  2206. const std::string &p, const std::string& config) const
  2207. {
  2208. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  2209. "FALSE",
  2210. BoolType, 0);
  2211. }
  2212. //----------------------------------------------------------------------------
  2213. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  2214. const std::string &p,
  2215. const std::string& config) const
  2216. {
  2217. return checkInterfacePropertyCompatibility<const char *>(this,
  2218. p,
  2219. config,
  2220. "empty",
  2221. StringType, 0);
  2222. }
  2223. //----------------------------------------------------------------------------
  2224. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  2225. const std::string &p,
  2226. const std::string& config) const
  2227. {
  2228. return checkInterfacePropertyCompatibility<const char *>(this,
  2229. p,
  2230. config,
  2231. "empty",
  2232. NumberMinType, 0);
  2233. }
  2234. //----------------------------------------------------------------------------
  2235. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  2236. const std::string &p,
  2237. const std::string& config) const
  2238. {
  2239. return checkInterfacePropertyCompatibility<const char *>(this,
  2240. p,
  2241. config,
  2242. "empty",
  2243. NumberMaxType, 0);
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. cmComputeLinkInformation*
  2247. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  2248. {
  2249. // Lookup any existing information for this configuration.
  2250. std::string key(cmSystemTools::UpperCase(config));
  2251. cmTargetLinkInformationMap::iterator
  2252. i = this->LinkInformation.find(key);
  2253. if(i == this->LinkInformation.end())
  2254. {
  2255. // Compute information for this configuration.
  2256. cmComputeLinkInformation* info =
  2257. new cmComputeLinkInformation(this->Target, config);
  2258. if(!info || !info->Compute())
  2259. {
  2260. delete info;
  2261. info = 0;
  2262. }
  2263. // Store the information for this configuration.
  2264. cmTargetLinkInformationMap::value_type entry(key, info);
  2265. i = this->LinkInformation.insert(entry).first;
  2266. if (info)
  2267. {
  2268. this->CheckPropertyCompatibility(info, config);
  2269. }
  2270. }
  2271. return i->second;
  2272. }
  2273. //----------------------------------------------------------------------------
  2274. void
  2275. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  2276. const std::string &result,
  2277. const std::string &report,
  2278. const std::string &compatibilityType) const
  2279. {
  2280. std::vector<std::string> debugProperties;
  2281. const char *debugProp = this->Target->GetMakefile()
  2282. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2283. if (debugProp)
  2284. {
  2285. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2286. }
  2287. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  2288. && std::find(debugProperties.begin(),
  2289. debugProperties.end(),
  2290. p)
  2291. != debugProperties.end();
  2292. if (this->Target->GetMakefile()->IsConfigured())
  2293. {
  2294. this->DebugCompatiblePropertiesDone[p] = true;
  2295. }
  2296. if (!debugOrigin)
  2297. {
  2298. return;
  2299. }
  2300. std::string areport = compatibilityType;
  2301. areport += std::string(" of property \"") + p + "\" for target \"";
  2302. areport += std::string(this->GetName());
  2303. areport += "\" (result: \"";
  2304. areport += result;
  2305. areport += "\"):\n" + report;
  2306. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  2307. }