cmGeneratorTarget.cxx 69 KB

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