cmGeneratorTarget.cxx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  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 "assert.h"
  23. //----------------------------------------------------------------------------
  24. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  25. cmTarget *target, cmake *cm)
  26. {
  27. if(!badObjLib.empty())
  28. {
  29. std::ostringstream e;
  30. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  31. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  32. i != badObjLib.end(); ++i)
  33. {
  34. e << " " << (*i)->GetLocation().GetName() << "\n";
  35. }
  36. e << "but may contain only sources that compile, header files, and "
  37. "other files that would not affect linking of a normal library.";
  38. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  39. target->GetBacktrace());
  40. }
  41. }
  42. struct ObjectSourcesTag {};
  43. struct CustomCommandsTag {};
  44. struct ExtraSourcesTag {};
  45. struct HeaderSourcesTag {};
  46. struct ExternalObjectsTag {};
  47. struct IDLSourcesTag {};
  48. struct ResxTag {};
  49. struct ModuleDefinitionFileTag {};
  50. struct AppManifestTag{};
  51. struct CertificatesTag{};
  52. struct XamlTag{};
  53. template<typename Tag, typename OtherTag>
  54. struct IsSameTag
  55. {
  56. enum {
  57. Result = false
  58. };
  59. };
  60. template<typename Tag>
  61. struct IsSameTag<Tag, Tag>
  62. {
  63. enum {
  64. Result = true
  65. };
  66. };
  67. template<bool>
  68. struct DoAccept
  69. {
  70. template <typename T> static void Do(T&, cmSourceFile*) {}
  71. };
  72. template<>
  73. struct DoAccept<true>
  74. {
  75. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  76. {
  77. files.push_back(f);
  78. }
  79. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  80. {
  81. // Build and save the name of the corresponding .h file
  82. // This relationship will be used later when building the project files.
  83. // Both names would have been auto generated from Visual Studio
  84. // where the user supplied the file name and Visual Studio
  85. // appended the suffix.
  86. std::string resx = f->GetFullPath();
  87. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  88. data.ExpectedResxHeaders.insert(hFileName);
  89. data.ResxSources.push_back(f);
  90. }
  91. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  92. {
  93. // Build and save the name of the corresponding .h and .cpp file
  94. // This relationship will be used later when building the project files.
  95. // Both names would have been auto generated from Visual Studio
  96. // where the user supplied the file name and Visual Studio
  97. // appended the suffix.
  98. std::string xaml = f->GetFullPath();
  99. std::string hFileName = xaml + ".h";
  100. std::string cppFileName = xaml + ".cpp";
  101. data.ExpectedXamlHeaders.insert(hFileName);
  102. data.ExpectedXamlSources.insert(cppFileName);
  103. data.XamlSources.push_back(f);
  104. }
  105. static void Do(std::string& data, cmSourceFile* f)
  106. {
  107. data = f->GetFullPath();
  108. }
  109. };
  110. //----------------------------------------------------------------------------
  111. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  112. struct TagVisitor
  113. {
  114. DataType& Data;
  115. std::vector<cmSourceFile*> BadObjLibFiles;
  116. cmTarget *Target;
  117. cmGlobalGenerator *GlobalGenerator;
  118. cmsys::RegularExpression Header;
  119. bool IsObjLib;
  120. TagVisitor(cmTarget *target, DataType& data)
  121. : Data(data), Target(target),
  122. GlobalGenerator(target->GetMakefile()->GetGlobalGenerator()),
  123. Header(CM_HEADER_REGEX),
  124. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  125. {
  126. }
  127. ~TagVisitor()
  128. {
  129. reportBadObjLib(this->BadObjLibFiles, this->Target,
  130. this->GlobalGenerator->GetCMakeInstance());
  131. }
  132. void Accept(cmSourceFile *sf)
  133. {
  134. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  135. if(sf->GetCustomCommand())
  136. {
  137. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  138. }
  139. else if(this->Target->GetType() == cmTarget::UTILITY)
  140. {
  141. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  142. }
  143. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  144. {
  145. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  146. }
  147. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  148. {
  149. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  150. if(this->IsObjLib)
  151. {
  152. this->BadObjLibFiles.push_back(sf);
  153. }
  154. }
  155. else if(!sf->GetLanguage().empty())
  156. {
  157. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  158. }
  159. else if(ext == "def")
  160. {
  161. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  162. sf);
  163. if(this->IsObjLib)
  164. {
  165. this->BadObjLibFiles.push_back(sf);
  166. }
  167. }
  168. else if(ext == "idl")
  169. {
  170. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  171. if(this->IsObjLib)
  172. {
  173. this->BadObjLibFiles.push_back(sf);
  174. }
  175. }
  176. else if(ext == "resx")
  177. {
  178. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  179. }
  180. else if (ext == "appxmanifest")
  181. {
  182. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  183. }
  184. else if (ext == "pfx")
  185. {
  186. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  187. }
  188. else if (ext == "xaml")
  189. {
  190. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  191. }
  192. else if(this->Header.find(sf->GetFullPath().c_str()))
  193. {
  194. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  195. }
  196. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  197. {
  198. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  199. }
  200. else
  201. {
  202. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  203. }
  204. }
  205. };
  206. //----------------------------------------------------------------------------
  207. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  208. : Target(t),
  209. SourceFileFlagsConstructed(false)
  210. {
  211. this->Makefile = this->Target->GetMakefile();
  212. this->LocalGenerator = lg;
  213. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  214. }
  215. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  216. {
  217. return this->LocalGenerator;
  218. }
  219. //----------------------------------------------------------------------------
  220. int cmGeneratorTarget::GetType() const
  221. {
  222. return this->Target->GetType();
  223. }
  224. //----------------------------------------------------------------------------
  225. std::string cmGeneratorTarget::GetName() const
  226. {
  227. return this->Target->GetName();
  228. }
  229. //----------------------------------------------------------------------------
  230. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  231. {
  232. return this->Target->GetProperty(prop);
  233. }
  234. //----------------------------------------------------------------------------
  235. std::vector<cmSourceFile*> const*
  236. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  237. {
  238. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  239. if(i != this->SourceEntries.end())
  240. {
  241. return &i->second.Depends;
  242. }
  243. return 0;
  244. }
  245. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  246. const std::string& config,
  247. cmTarget *headTarget,
  248. cmGeneratorExpressionDAGChecker *dagChecker,
  249. std::vector<std::string>& result,
  250. bool excludeImported)
  251. {
  252. if (const char* dirs =
  253. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  254. {
  255. cmGeneratorExpression ge;
  256. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  257. ->Evaluate(mf,
  258. config, false, headTarget,
  259. depTgt, dagChecker), result);
  260. }
  261. if (!depTgt->IsImported() || excludeImported)
  262. {
  263. return;
  264. }
  265. if (const char* dirs =
  266. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  267. {
  268. cmGeneratorExpression ge;
  269. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  270. ->Evaluate(mf,
  271. config, false, headTarget,
  272. depTgt, dagChecker), result);
  273. }
  274. }
  275. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  276. { \
  277. std::vector<cmSourceFile*> sourceFiles; \
  278. this->Target->GetSourceFiles(sourceFiles, config); \
  279. TagVisitor<DATA ## Tag DATATYPE> visitor(this->Target, data); \
  280. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  281. si != sourceFiles.end(); ++si) \
  282. { \
  283. visitor.Accept(*si); \
  284. } \
  285. } \
  286. #define IMPLEMENT_VISIT(DATA) \
  287. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  288. #define EMPTY
  289. #define COMMA ,
  290. //----------------------------------------------------------------------------
  291. void
  292. cmGeneratorTarget
  293. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  294. const std::string& config) const
  295. {
  296. IMPLEMENT_VISIT(ObjectSources);
  297. if (!this->Objects.empty())
  298. {
  299. return;
  300. }
  301. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  302. it != data.end(); ++it)
  303. {
  304. this->Objects[*it];
  305. }
  306. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  307. }
  308. void cmGeneratorTarget::ComputeObjectMapping()
  309. {
  310. if(!this->Objects.empty())
  311. {
  312. return;
  313. }
  314. std::vector<std::string> configs;
  315. this->Makefile->GetConfigurations(configs);
  316. if (configs.empty())
  317. {
  318. configs.push_back("");
  319. }
  320. for(std::vector<std::string>::const_iterator ci = configs.begin();
  321. ci != configs.end(); ++ci)
  322. {
  323. std::vector<cmSourceFile const*> sourceFiles;
  324. this->GetObjectSources(sourceFiles, *ci);
  325. }
  326. }
  327. //----------------------------------------------------------------------------
  328. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  329. const std::string& config) const
  330. {
  331. if(!config.empty())
  332. {
  333. std::string featureConfig = feature;
  334. featureConfig += "_";
  335. featureConfig += cmSystemTools::UpperCase(config);
  336. if(const char* value = this->Target->GetProperty(featureConfig))
  337. {
  338. return value;
  339. }
  340. }
  341. if(const char* value = this->Target->GetProperty(feature))
  342. {
  343. return value;
  344. }
  345. return this->LocalGenerator->GetFeature(feature, config);
  346. }
  347. //----------------------------------------------------------------------------
  348. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  349. const std::string& config) const
  350. {
  351. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  352. }
  353. //----------------------------------------------------------------------------
  354. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  355. {
  356. this->ComputeObjectMapping();
  357. return this->Objects[file];
  358. }
  359. //----------------------------------------------------------------------------
  360. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  361. {
  362. this->ExplicitObjectName.insert(sf);
  363. }
  364. //----------------------------------------------------------------------------
  365. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  366. {
  367. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  368. std::set<cmSourceFile const*>::const_iterator it
  369. = this->ExplicitObjectName.find(file);
  370. return it != this->ExplicitObjectName.end();
  371. }
  372. //----------------------------------------------------------------------------
  373. void cmGeneratorTarget
  374. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  375. const std::string& config) const
  376. {
  377. IMPLEMENT_VISIT(IDLSources);
  378. }
  379. //----------------------------------------------------------------------------
  380. void
  381. cmGeneratorTarget
  382. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  383. const std::string& config) const
  384. {
  385. IMPLEMENT_VISIT(HeaderSources);
  386. }
  387. //----------------------------------------------------------------------------
  388. void cmGeneratorTarget
  389. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  390. const std::string& config) const
  391. {
  392. IMPLEMENT_VISIT(ExtraSources);
  393. }
  394. //----------------------------------------------------------------------------
  395. void
  396. cmGeneratorTarget
  397. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  398. const std::string& config) const
  399. {
  400. IMPLEMENT_VISIT(CustomCommands);
  401. }
  402. //----------------------------------------------------------------------------
  403. void
  404. cmGeneratorTarget
  405. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  406. const std::string& config) const
  407. {
  408. IMPLEMENT_VISIT(ExternalObjects);
  409. }
  410. //----------------------------------------------------------------------------
  411. void
  412. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  413. const std::string& config) const
  414. {
  415. ResxData data;
  416. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  417. srcs = data.ExpectedResxHeaders;
  418. }
  419. //----------------------------------------------------------------------------
  420. void cmGeneratorTarget
  421. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  422. const std::string& config) const
  423. {
  424. ResxData data;
  425. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  426. srcs = data.ResxSources;
  427. }
  428. //----------------------------------------------------------------------------
  429. void
  430. cmGeneratorTarget
  431. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  432. const std::string& config) const
  433. {
  434. IMPLEMENT_VISIT(AppManifest);
  435. }
  436. //----------------------------------------------------------------------------
  437. void
  438. cmGeneratorTarget
  439. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  440. const std::string& config) const
  441. {
  442. IMPLEMENT_VISIT(Certificates);
  443. }
  444. //----------------------------------------------------------------------------
  445. void
  446. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  447. const std::string& config) const
  448. {
  449. XamlData data;
  450. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  451. headers = data.ExpectedXamlHeaders;
  452. }
  453. //----------------------------------------------------------------------------
  454. void
  455. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  456. const std::string& config) const
  457. {
  458. XamlData data;
  459. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  460. srcs = data.ExpectedXamlSources;
  461. }
  462. //----------------------------------------------------------------------------
  463. void cmGeneratorTarget
  464. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  465. const std::string& config) const
  466. {
  467. XamlData data;
  468. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  469. srcs = data.XamlSources;
  470. }
  471. //----------------------------------------------------------------------------
  472. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  473. {
  474. static std::string location;
  475. if (this->Target->IsImported())
  476. {
  477. location = this->Target->ImportedGetFullPath(config, false);
  478. }
  479. else
  480. {
  481. location = this->GetFullPath(config, false);
  482. }
  483. return location.c_str();
  484. }
  485. bool cmGeneratorTarget::IsImported() const
  486. {
  487. return this->Target->IsImported();
  488. }
  489. //----------------------------------------------------------------------------
  490. const char* cmGeneratorTarget::GetLocationForBuild() const
  491. {
  492. static std::string location;
  493. if(this->IsImported())
  494. {
  495. location = this->Target->ImportedGetFullPath("", false);
  496. return location.c_str();
  497. }
  498. // Now handle the deprecated build-time configuration location.
  499. location = this->Target->GetDirectory();
  500. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  501. if(cfgid && strcmp(cfgid, ".") != 0)
  502. {
  503. location += "/";
  504. location += cfgid;
  505. }
  506. if(this->Target->IsAppBundleOnApple())
  507. {
  508. std::string macdir = this->Target->BuildMacContentDirectory("", "",
  509. false);
  510. if(!macdir.empty())
  511. {
  512. location += "/";
  513. location += macdir;
  514. }
  515. }
  516. location += "/";
  517. location += this->Target->GetFullName("", false);
  518. return location.c_str();
  519. }
  520. //----------------------------------------------------------------------------
  521. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  522. const std::string& config) const
  523. {
  524. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  525. std::string config_upper;
  526. if(!config.empty())
  527. {
  528. config_upper = cmSystemTools::UpperCase(config);
  529. }
  530. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  531. IncludeCacheType::const_iterator iter =
  532. this->SystemIncludesCache.find(config_upper);
  533. if (iter == this->SystemIncludesCache.end())
  534. {
  535. cmGeneratorExpressionDAGChecker dagChecker(
  536. this->GetName(),
  537. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  538. bool excludeImported
  539. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  540. std::vector<std::string> result;
  541. for (std::set<std::string>::const_iterator
  542. it = this->Target->GetSystemIncludeDirectories().begin();
  543. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  544. {
  545. cmGeneratorExpression ge;
  546. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  547. ->Evaluate(this->Makefile,
  548. config, false, this->Target,
  549. &dagChecker), result);
  550. }
  551. std::vector<cmTarget const*> const& deps =
  552. this->Target->GetLinkImplementationClosure(config);
  553. for(std::vector<cmTarget const*>::const_iterator
  554. li = deps.begin(), le = deps.end(); li != le; ++li)
  555. {
  556. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  557. &dagChecker, result, excludeImported);
  558. }
  559. std::set<std::string> unique;
  560. for(std::vector<std::string>::iterator li = result.begin();
  561. li != result.end(); ++li)
  562. {
  563. cmSystemTools::ConvertToUnixSlashes(*li);
  564. unique.insert(*li);
  565. }
  566. result.clear();
  567. result.insert(result.end(), unique.begin(), unique.end());
  568. IncludeCacheType::value_type entry(config_upper, result);
  569. iter = this->SystemIncludesCache.insert(entry).first;
  570. }
  571. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  572. }
  573. //----------------------------------------------------------------------------
  574. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  575. {
  576. return this->Target->GetPropertyAsBool(prop);
  577. }
  578. //----------------------------------------------------------------------------
  579. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  580. const std::string& config) const
  581. {
  582. this->Target->GetSourceFiles(files, config);
  583. }
  584. //----------------------------------------------------------------------------
  585. std::string
  586. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  587. {
  588. std::string data;
  589. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  590. return data;
  591. }
  592. //----------------------------------------------------------------------------
  593. void
  594. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  595. const std::string &config) const
  596. {
  597. std::vector<cmSourceFile const*> objectFiles;
  598. this->GetExternalObjects(objectFiles, config);
  599. std::vector<cmTarget*> objectLibraries;
  600. for(std::vector<cmSourceFile const*>::const_iterator
  601. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  602. {
  603. std::string objLib = (*it)->GetObjectLibrary();
  604. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  605. {
  606. objectLibraries.push_back(tgt);
  607. }
  608. }
  609. std::vector<cmTarget*>::const_iterator end
  610. = cmRemoveDuplicates(objectLibraries);
  611. for(std::vector<cmTarget*>::const_iterator
  612. ti = objectLibraries.begin();
  613. ti != end; ++ti)
  614. {
  615. cmTarget* objLib = *ti;
  616. cmGeneratorTarget* ogt =
  617. this->GlobalGenerator->GetGeneratorTarget(objLib);
  618. std::vector<cmSourceFile const*> objectSources;
  619. ogt->GetObjectSources(objectSources, config);
  620. for(std::vector<cmSourceFile const*>::const_iterator
  621. si = objectSources.begin();
  622. si != objectSources.end(); ++si)
  623. {
  624. std::string obj = ogt->ObjectDirectory;
  625. obj += ogt->Objects[*si];
  626. objs.push_back(obj);
  627. }
  628. }
  629. }
  630. //----------------------------------------------------------------------------
  631. class cmTargetTraceDependencies
  632. {
  633. public:
  634. cmTargetTraceDependencies(cmGeneratorTarget* target);
  635. void Trace();
  636. private:
  637. cmTarget* Target;
  638. cmGeneratorTarget* GeneratorTarget;
  639. cmMakefile* Makefile;
  640. cmGlobalGenerator const* GlobalGenerator;
  641. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  642. SourceEntry* CurrentEntry;
  643. std::queue<cmSourceFile*> SourceQueue;
  644. std::set<cmSourceFile*> SourcesQueued;
  645. typedef std::map<std::string, cmSourceFile*> NameMapType;
  646. NameMapType NameMap;
  647. std::vector<std::string> NewSources;
  648. void QueueSource(cmSourceFile* sf);
  649. void FollowName(std::string const& name);
  650. void FollowNames(std::vector<std::string> const& names);
  651. bool IsUtility(std::string const& dep);
  652. void CheckCustomCommand(cmCustomCommand const& cc);
  653. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  654. void FollowCommandDepends(cmCustomCommand const& cc,
  655. const std::string& config,
  656. std::set<std::string>& emitted);
  657. };
  658. //----------------------------------------------------------------------------
  659. cmTargetTraceDependencies
  660. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  661. Target(target->Target), GeneratorTarget(target)
  662. {
  663. // Convenience.
  664. this->Makefile = this->Target->GetMakefile();
  665. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  666. this->CurrentEntry = 0;
  667. // Queue all the source files already specified for the target.
  668. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  669. {
  670. std::vector<std::string> configs;
  671. this->Makefile->GetConfigurations(configs);
  672. if (configs.empty())
  673. {
  674. configs.push_back("");
  675. }
  676. std::set<cmSourceFile*> emitted;
  677. for(std::vector<std::string>::const_iterator ci = configs.begin();
  678. ci != configs.end(); ++ci)
  679. {
  680. std::vector<cmSourceFile*> sources;
  681. this->Target->GetSourceFiles(sources, *ci);
  682. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  683. si != sources.end(); ++si)
  684. {
  685. cmSourceFile* sf = *si;
  686. const std::set<cmTarget const*> tgts =
  687. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  688. if (tgts.find(this->Target) != tgts.end())
  689. {
  690. std::ostringstream e;
  691. e << "Evaluation output file\n \"" << sf->GetFullPath()
  692. << "\"\ndepends on the sources of a target it is used in. This "
  693. "is a dependency loop and is not allowed.";
  694. this->GeneratorTarget
  695. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  696. return;
  697. }
  698. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  699. {
  700. this->SourceQueue.push(sf);
  701. }
  702. }
  703. }
  704. }
  705. // Queue pre-build, pre-link, and post-build rule dependencies.
  706. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  707. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  708. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  709. }
  710. //----------------------------------------------------------------------------
  711. void cmTargetTraceDependencies::Trace()
  712. {
  713. // Process one dependency at a time until the queue is empty.
  714. while(!this->SourceQueue.empty())
  715. {
  716. // Get the next source from the queue.
  717. cmSourceFile* sf = this->SourceQueue.front();
  718. this->SourceQueue.pop();
  719. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  720. // Queue dependencies added explicitly by the user.
  721. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  722. {
  723. std::vector<std::string> objDeps;
  724. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  725. for(std::vector<std::string>::iterator odi = objDeps.begin();
  726. odi != objDeps.end(); ++odi)
  727. {
  728. if (cmSystemTools::FileIsFullPath(*odi))
  729. {
  730. *odi = cmSystemTools::CollapseFullPath(*odi);
  731. }
  732. }
  733. this->FollowNames(objDeps);
  734. }
  735. // Queue the source needed to generate this file, if any.
  736. this->FollowName(sf->GetFullPath());
  737. // Queue dependencies added programatically by commands.
  738. this->FollowNames(sf->GetDepends());
  739. // Queue custom command dependencies.
  740. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  741. {
  742. this->CheckCustomCommand(*cc);
  743. }
  744. }
  745. this->CurrentEntry = 0;
  746. this->Target->AddTracedSources(this->NewSources);
  747. }
  748. //----------------------------------------------------------------------------
  749. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  750. {
  751. if(this->SourcesQueued.insert(sf).second)
  752. {
  753. this->SourceQueue.push(sf);
  754. // Make sure this file is in the target at the end.
  755. this->NewSources.push_back(sf->GetFullPath());
  756. }
  757. }
  758. //----------------------------------------------------------------------------
  759. void cmTargetTraceDependencies::FollowName(std::string const& name)
  760. {
  761. NameMapType::iterator i = this->NameMap.find(name);
  762. if(i == this->NameMap.end())
  763. {
  764. // Check if we know how to generate this file.
  765. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  766. NameMapType::value_type entry(name, sf);
  767. i = this->NameMap.insert(entry).first;
  768. }
  769. if(cmSourceFile* sf = i->second)
  770. {
  771. // Record the dependency we just followed.
  772. if(this->CurrentEntry)
  773. {
  774. this->CurrentEntry->Depends.push_back(sf);
  775. }
  776. this->QueueSource(sf);
  777. }
  778. }
  779. //----------------------------------------------------------------------------
  780. void
  781. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  782. {
  783. for(std::vector<std::string>::const_iterator i = names.begin();
  784. i != names.end(); ++i)
  785. {
  786. this->FollowName(*i);
  787. }
  788. }
  789. //----------------------------------------------------------------------------
  790. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  791. {
  792. // Dependencies on targets (utilities) are supposed to be named by
  793. // just the target name. However for compatibility we support
  794. // naming the output file generated by the target (assuming there is
  795. // no output-name property which old code would not have set). In
  796. // that case the target name will be the file basename of the
  797. // dependency.
  798. std::string util = cmSystemTools::GetFilenameName(dep);
  799. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  800. {
  801. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  802. }
  803. // Check for a target with this name.
  804. if(cmGeneratorTarget* t
  805. = this->Makefile->FindGeneratorTargetToUse(util))
  806. {
  807. // If we find the target and the dep was given as a full path,
  808. // then make sure it was not a full path to something else, and
  809. // the fact that the name matched a target was just a coincidence.
  810. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  811. {
  812. if(t->GetType() >= cmTarget::EXECUTABLE &&
  813. t->GetType() <= cmTarget::MODULE_LIBRARY)
  814. {
  815. // This is really only for compatibility so we do not need to
  816. // worry about configuration names and output names.
  817. std::string tLocation = t->GetLocationForBuild();
  818. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  819. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  820. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  821. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  822. if(depLocation == tLocation)
  823. {
  824. this->Target->AddUtility(util);
  825. return true;
  826. }
  827. }
  828. }
  829. else
  830. {
  831. // The original name of the dependency was not a full path. It
  832. // must name a target, so add the target-level dependency.
  833. this->Target->AddUtility(util);
  834. return true;
  835. }
  836. }
  837. // The dependency does not name a target built in this project.
  838. return false;
  839. }
  840. //----------------------------------------------------------------------------
  841. void
  842. cmTargetTraceDependencies
  843. ::CheckCustomCommand(cmCustomCommand const& cc)
  844. {
  845. // Transform command names that reference targets built in this
  846. // project to corresponding target-level dependencies.
  847. cmGeneratorExpression ge(cc.GetBacktrace());
  848. // Add target-level dependencies referenced by generator expressions.
  849. std::set<cmTarget*> targets;
  850. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  851. cit != cc.GetCommandLines().end(); ++cit)
  852. {
  853. std::string const& command = *cit->begin();
  854. // Check for a target with this name.
  855. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  856. {
  857. if(t->GetType() == cmTarget::EXECUTABLE)
  858. {
  859. // The command refers to an executable target built in
  860. // this project. Add the target-level dependency to make
  861. // sure the executable is up to date before this custom
  862. // command possibly runs.
  863. this->Target->AddUtility(command);
  864. }
  865. }
  866. // Check for target references in generator expressions.
  867. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  868. cli != cit->end(); ++cli)
  869. {
  870. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  871. = ge.Parse(*cli);
  872. cge->Evaluate(this->Makefile, "", true);
  873. std::set<cmTarget*> geTargets = cge->GetTargets();
  874. targets.insert(geTargets.begin(), geTargets.end());
  875. }
  876. }
  877. for(std::set<cmTarget*>::iterator ti = targets.begin();
  878. ti != targets.end(); ++ti)
  879. {
  880. this->Target->AddUtility((*ti)->GetName());
  881. }
  882. // Queue the custom command dependencies.
  883. std::vector<std::string> configs;
  884. std::set<std::string> emitted;
  885. this->Makefile->GetConfigurations(configs);
  886. if (configs.empty())
  887. {
  888. configs.push_back("");
  889. }
  890. for(std::vector<std::string>::const_iterator ci = configs.begin();
  891. ci != configs.end(); ++ci)
  892. {
  893. this->FollowCommandDepends(cc, *ci, emitted);
  894. }
  895. }
  896. //----------------------------------------------------------------------------
  897. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  898. const std::string& config,
  899. std::set<std::string>& emitted)
  900. {
  901. cmCustomCommandGenerator ccg(cc, config,
  902. this->GeneratorTarget->LocalGenerator);
  903. const std::vector<std::string>& depends = ccg.GetDepends();
  904. for(std::vector<std::string>::const_iterator di = depends.begin();
  905. di != depends.end(); ++di)
  906. {
  907. std::string const& dep = *di;
  908. if(emitted.insert(dep).second)
  909. {
  910. if(!this->IsUtility(dep))
  911. {
  912. // The dependency does not name a target and may be a file we
  913. // know how to generate. Queue it.
  914. this->FollowName(dep);
  915. }
  916. }
  917. }
  918. }
  919. //----------------------------------------------------------------------------
  920. void
  921. cmTargetTraceDependencies
  922. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  923. {
  924. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  925. cli != commands.end(); ++cli)
  926. {
  927. this->CheckCustomCommand(*cli);
  928. }
  929. }
  930. //----------------------------------------------------------------------------
  931. void cmGeneratorTarget::TraceDependencies()
  932. {
  933. // CMake-generated targets have no dependencies to trace. Normally tracing
  934. // would find nothing anyway, but when building CMake itself the "install"
  935. // target command ends up referencing the "cmake" target but we do not
  936. // really want the dependency because "install" depend on "all" anyway.
  937. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  938. {
  939. return;
  940. }
  941. // Use a helper object to trace the dependencies.
  942. cmTargetTraceDependencies tracer(this);
  943. tracer.Trace();
  944. }
  945. //----------------------------------------------------------------------------
  946. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  947. std::vector<std::string>& archVec) const
  948. {
  949. const char* archs = 0;
  950. if(!config.empty())
  951. {
  952. std::string defVarName = "OSX_ARCHITECTURES_";
  953. defVarName += cmSystemTools::UpperCase(config);
  954. archs = this->Target->GetProperty(defVarName);
  955. }
  956. if(!archs)
  957. {
  958. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  959. }
  960. if(archs)
  961. {
  962. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  963. }
  964. }
  965. //----------------------------------------------------------------------------
  966. std::string
  967. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  968. std::string const& config) const
  969. {
  970. switch(this->GetType())
  971. {
  972. case cmTarget::STATIC_LIBRARY:
  973. {
  974. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  975. if(this->GetFeatureAsBool(
  976. "INTERPROCEDURAL_OPTIMIZATION", config))
  977. {
  978. std::string varIPO = var + "_IPO";
  979. if(this->Makefile->GetDefinition(varIPO))
  980. {
  981. return varIPO;
  982. }
  983. }
  984. return var;
  985. }
  986. case cmTarget::SHARED_LIBRARY:
  987. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  988. case cmTarget::MODULE_LIBRARY:
  989. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  990. case cmTarget::EXECUTABLE:
  991. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  992. default:
  993. break;
  994. }
  995. return "";
  996. }
  997. //----------------------------------------------------------------------------
  998. std::vector<std::string>
  999. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1000. const std::string& lang) const
  1001. {
  1002. return this->Target->GetIncludeDirectories(config, lang);
  1003. }
  1004. //----------------------------------------------------------------------------
  1005. void cmGeneratorTarget::GenerateTargetManifest(
  1006. const std::string& config) const
  1007. {
  1008. if (this->Target->IsImported())
  1009. {
  1010. return;
  1011. }
  1012. cmMakefile* mf = this->Target->GetMakefile();
  1013. cmGlobalGenerator* gg = mf->GetGlobalGenerator();
  1014. // Get the names.
  1015. std::string name;
  1016. std::string soName;
  1017. std::string realName;
  1018. std::string impName;
  1019. std::string pdbName;
  1020. if(this->GetType() == cmTarget::EXECUTABLE)
  1021. {
  1022. this->Target->GetExecutableNames(name, realName, impName, pdbName,
  1023. config);
  1024. }
  1025. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1026. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1027. this->GetType() == cmTarget::MODULE_LIBRARY)
  1028. {
  1029. this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
  1030. config);
  1031. }
  1032. else
  1033. {
  1034. return;
  1035. }
  1036. // Get the directory.
  1037. std::string dir = this->Target->GetDirectory(config, false);
  1038. // Add each name.
  1039. std::string f;
  1040. if(!name.empty())
  1041. {
  1042. f = dir;
  1043. f += "/";
  1044. f += name;
  1045. gg->AddToManifest(config, f);
  1046. }
  1047. if(!soName.empty())
  1048. {
  1049. f = dir;
  1050. f += "/";
  1051. f += soName;
  1052. gg->AddToManifest(config, f);
  1053. }
  1054. if(!realName.empty())
  1055. {
  1056. f = dir;
  1057. f += "/";
  1058. f += realName;
  1059. gg->AddToManifest(config, f);
  1060. }
  1061. if(!pdbName.empty())
  1062. {
  1063. f = dir;
  1064. f += "/";
  1065. f += pdbName;
  1066. gg->AddToManifest(config, f);
  1067. }
  1068. if(!impName.empty())
  1069. {
  1070. f = this->Target->GetDirectory(config, true);
  1071. f += "/";
  1072. f += impName;
  1073. gg->AddToManifest(config, f);
  1074. }
  1075. }
  1076. //----------------------------------------------------------------------------
  1077. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1078. bool implib, bool realname) const
  1079. {
  1080. if(this->Target->IsImported())
  1081. {
  1082. return this->Target->ImportedGetFullPath(config, implib);
  1083. }
  1084. else
  1085. {
  1086. return this->NormalGetFullPath(config, implib, realname);
  1087. }
  1088. }
  1089. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1090. bool implib,
  1091. bool realname) const
  1092. {
  1093. std::string fpath = this->Target->GetDirectory(config, implib);
  1094. fpath += "/";
  1095. if(this->Target->IsAppBundleOnApple())
  1096. {
  1097. fpath = this->Target->BuildMacContentDirectory(fpath, config, false);
  1098. fpath += "/";
  1099. }
  1100. // Add the full name of the target.
  1101. if(implib)
  1102. {
  1103. fpath += this->Target->GetFullName(config, true);
  1104. }
  1105. else if(realname)
  1106. {
  1107. fpath += this->NormalGetRealName(config);
  1108. }
  1109. else
  1110. {
  1111. fpath += this->Target->GetFullName(config, false);
  1112. }
  1113. return fpath;
  1114. }
  1115. //----------------------------------------------------------------------------
  1116. std::string
  1117. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1118. {
  1119. // This should not be called for imported targets.
  1120. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1121. // enforcement of the limited imported target API.
  1122. if(this->Target->IsImported())
  1123. {
  1124. std::string msg = "NormalGetRealName called on imported target: ";
  1125. msg += this->GetName();
  1126. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1127. }
  1128. if(this->GetType() == cmTarget::EXECUTABLE)
  1129. {
  1130. // Compute the real name that will be built.
  1131. std::string name;
  1132. std::string realName;
  1133. std::string impName;
  1134. std::string pdbName;
  1135. this->Target->GetExecutableNames(name, realName, impName, pdbName, config);
  1136. return realName;
  1137. }
  1138. else
  1139. {
  1140. // Compute the real name that will be built.
  1141. std::string name;
  1142. std::string soName;
  1143. std::string realName;
  1144. std::string impName;
  1145. std::string pdbName;
  1146. this->Target->GetLibraryNames(name, soName, realName,
  1147. impName, pdbName, config);
  1148. return realName;
  1149. }
  1150. }
  1151. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  1152. cmTarget const* t2) const
  1153. {
  1154. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  1155. if (nameResult == 0)
  1156. {
  1157. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  1158. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  1159. }
  1160. return nameResult < 0;
  1161. }
  1162. //----------------------------------------------------------------------------
  1163. struct cmGeneratorTarget::SourceFileFlags
  1164. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  1165. {
  1166. struct SourceFileFlags flags;
  1167. this->ConstructSourceFileFlags();
  1168. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1169. this->SourceFlagsMap.find(sf);
  1170. if(si != this->SourceFlagsMap.end())
  1171. {
  1172. flags = si->second;
  1173. }
  1174. else
  1175. {
  1176. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1177. // were not listed in one of the other lists.
  1178. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1179. {
  1180. flags.MacFolder = location;
  1181. if(strcmp(location, "Resources") == 0)
  1182. {
  1183. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1184. }
  1185. else
  1186. {
  1187. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  1188. }
  1189. }
  1190. }
  1191. return flags;
  1192. }
  1193. //----------------------------------------------------------------------------
  1194. void cmGeneratorTarget::ConstructSourceFileFlags() const
  1195. {
  1196. if(this->SourceFileFlagsConstructed)
  1197. {
  1198. return;
  1199. }
  1200. this->SourceFileFlagsConstructed = true;
  1201. // Process public headers to mark the source files.
  1202. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  1203. {
  1204. std::vector<std::string> relFiles;
  1205. cmSystemTools::ExpandListArgument(files, relFiles);
  1206. for(std::vector<std::string>::iterator it = relFiles.begin();
  1207. it != relFiles.end(); ++it)
  1208. {
  1209. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1210. {
  1211. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1212. flags.MacFolder = "Headers";
  1213. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  1214. }
  1215. }
  1216. }
  1217. // Process private headers after public headers so that they take
  1218. // precedence if a file is listed in both.
  1219. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  1220. {
  1221. std::vector<std::string> relFiles;
  1222. cmSystemTools::ExpandListArgument(files, relFiles);
  1223. for(std::vector<std::string>::iterator it = relFiles.begin();
  1224. it != relFiles.end(); ++it)
  1225. {
  1226. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1227. {
  1228. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1229. flags.MacFolder = "PrivateHeaders";
  1230. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  1231. }
  1232. }
  1233. }
  1234. // Mark sources listed as resources.
  1235. if(const char* files = this->Target->GetProperty("RESOURCE"))
  1236. {
  1237. std::vector<std::string> relFiles;
  1238. cmSystemTools::ExpandListArgument(files, relFiles);
  1239. for(std::vector<std::string>::iterator it = relFiles.begin();
  1240. it != relFiles.end(); ++it)
  1241. {
  1242. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1243. {
  1244. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1245. flags.MacFolder = "Resources";
  1246. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1247. }
  1248. }
  1249. }
  1250. }