cmGeneratorTarget.cxx 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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 cmGeneratorTarget::GetSOName(const std::string& config) const
  586. {
  587. if(this->Target->IsImported())
  588. {
  589. // Lookup the imported soname.
  590. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  591. {
  592. if(info->NoSOName)
  593. {
  594. // The imported library has no builtin soname so the name
  595. // searched at runtime will be just the filename.
  596. return cmSystemTools::GetFilenameName(info->Location);
  597. }
  598. else
  599. {
  600. // Use the soname given if any.
  601. if(info->SOName.find("@rpath/") == 0)
  602. {
  603. return info->SOName.substr(6);
  604. }
  605. return info->SOName;
  606. }
  607. }
  608. else
  609. {
  610. return "";
  611. }
  612. }
  613. else
  614. {
  615. // Compute the soname that will be built.
  616. std::string name;
  617. std::string soName;
  618. std::string realName;
  619. std::string impName;
  620. std::string pdbName;
  621. this->Target->GetLibraryNames(name, soName, realName,
  622. impName, pdbName, config);
  623. return soName;
  624. }
  625. }
  626. //----------------------------------------------------------------------------
  627. std::string
  628. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  629. {
  630. std::string data;
  631. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  632. return data;
  633. }
  634. //----------------------------------------------------------------------------
  635. void
  636. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  637. const std::string &config) const
  638. {
  639. std::vector<cmSourceFile const*> objectFiles;
  640. this->GetExternalObjects(objectFiles, config);
  641. std::vector<cmTarget*> objectLibraries;
  642. for(std::vector<cmSourceFile const*>::const_iterator
  643. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  644. {
  645. std::string objLib = (*it)->GetObjectLibrary();
  646. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  647. {
  648. objectLibraries.push_back(tgt);
  649. }
  650. }
  651. std::vector<cmTarget*>::const_iterator end
  652. = cmRemoveDuplicates(objectLibraries);
  653. for(std::vector<cmTarget*>::const_iterator
  654. ti = objectLibraries.begin();
  655. ti != end; ++ti)
  656. {
  657. cmTarget* objLib = *ti;
  658. cmGeneratorTarget* ogt =
  659. this->GlobalGenerator->GetGeneratorTarget(objLib);
  660. std::vector<cmSourceFile const*> objectSources;
  661. ogt->GetObjectSources(objectSources, config);
  662. for(std::vector<cmSourceFile const*>::const_iterator
  663. si = objectSources.begin();
  664. si != objectSources.end(); ++si)
  665. {
  666. std::string obj = ogt->ObjectDirectory;
  667. obj += ogt->Objects[*si];
  668. objs.push_back(obj);
  669. }
  670. }
  671. }
  672. //----------------------------------------------------------------------------
  673. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  674. const std::string& config) const
  675. {
  676. const char *prop
  677. = this->Target->
  678. GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  679. config);
  680. if (!prop)
  681. {
  682. return;
  683. }
  684. cmGeneratorExpression ge;
  685. cmGeneratorExpressionDAGChecker dagChecker(
  686. this->GetName(),
  687. "AUTOUIC_OPTIONS", 0, 0);
  688. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  689. ->Evaluate(this->Makefile,
  690. config,
  691. false,
  692. this->Target,
  693. &dagChecker),
  694. result);
  695. }
  696. //----------------------------------------------------------------------------
  697. class cmTargetTraceDependencies
  698. {
  699. public:
  700. cmTargetTraceDependencies(cmGeneratorTarget* target);
  701. void Trace();
  702. private:
  703. cmTarget* Target;
  704. cmGeneratorTarget* GeneratorTarget;
  705. cmMakefile* Makefile;
  706. cmGlobalGenerator const* GlobalGenerator;
  707. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  708. SourceEntry* CurrentEntry;
  709. std::queue<cmSourceFile*> SourceQueue;
  710. std::set<cmSourceFile*> SourcesQueued;
  711. typedef std::map<std::string, cmSourceFile*> NameMapType;
  712. NameMapType NameMap;
  713. std::vector<std::string> NewSources;
  714. void QueueSource(cmSourceFile* sf);
  715. void FollowName(std::string const& name);
  716. void FollowNames(std::vector<std::string> const& names);
  717. bool IsUtility(std::string const& dep);
  718. void CheckCustomCommand(cmCustomCommand const& cc);
  719. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  720. void FollowCommandDepends(cmCustomCommand const& cc,
  721. const std::string& config,
  722. std::set<std::string>& emitted);
  723. };
  724. //----------------------------------------------------------------------------
  725. cmTargetTraceDependencies
  726. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  727. Target(target->Target), GeneratorTarget(target)
  728. {
  729. // Convenience.
  730. this->Makefile = this->Target->GetMakefile();
  731. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  732. this->CurrentEntry = 0;
  733. // Queue all the source files already specified for the target.
  734. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  735. {
  736. std::vector<std::string> configs;
  737. this->Makefile->GetConfigurations(configs);
  738. if (configs.empty())
  739. {
  740. configs.push_back("");
  741. }
  742. std::set<cmSourceFile*> emitted;
  743. for(std::vector<std::string>::const_iterator ci = configs.begin();
  744. ci != configs.end(); ++ci)
  745. {
  746. std::vector<cmSourceFile*> sources;
  747. this->Target->GetSourceFiles(sources, *ci);
  748. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  749. si != sources.end(); ++si)
  750. {
  751. cmSourceFile* sf = *si;
  752. const std::set<cmTarget const*> tgts =
  753. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  754. if (tgts.find(this->Target) != tgts.end())
  755. {
  756. std::ostringstream e;
  757. e << "Evaluation output file\n \"" << sf->GetFullPath()
  758. << "\"\ndepends on the sources of a target it is used in. This "
  759. "is a dependency loop and is not allowed.";
  760. this->GeneratorTarget
  761. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  762. return;
  763. }
  764. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  765. {
  766. this->SourceQueue.push(sf);
  767. }
  768. }
  769. }
  770. }
  771. // Queue pre-build, pre-link, and post-build rule dependencies.
  772. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  773. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  774. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  775. }
  776. //----------------------------------------------------------------------------
  777. void cmTargetTraceDependencies::Trace()
  778. {
  779. // Process one dependency at a time until the queue is empty.
  780. while(!this->SourceQueue.empty())
  781. {
  782. // Get the next source from the queue.
  783. cmSourceFile* sf = this->SourceQueue.front();
  784. this->SourceQueue.pop();
  785. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  786. // Queue dependencies added explicitly by the user.
  787. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  788. {
  789. std::vector<std::string> objDeps;
  790. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  791. for(std::vector<std::string>::iterator odi = objDeps.begin();
  792. odi != objDeps.end(); ++odi)
  793. {
  794. if (cmSystemTools::FileIsFullPath(*odi))
  795. {
  796. *odi = cmSystemTools::CollapseFullPath(*odi);
  797. }
  798. }
  799. this->FollowNames(objDeps);
  800. }
  801. // Queue the source needed to generate this file, if any.
  802. this->FollowName(sf->GetFullPath());
  803. // Queue dependencies added programatically by commands.
  804. this->FollowNames(sf->GetDepends());
  805. // Queue custom command dependencies.
  806. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  807. {
  808. this->CheckCustomCommand(*cc);
  809. }
  810. }
  811. this->CurrentEntry = 0;
  812. this->Target->AddTracedSources(this->NewSources);
  813. }
  814. //----------------------------------------------------------------------------
  815. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  816. {
  817. if(this->SourcesQueued.insert(sf).second)
  818. {
  819. this->SourceQueue.push(sf);
  820. // Make sure this file is in the target at the end.
  821. this->NewSources.push_back(sf->GetFullPath());
  822. }
  823. }
  824. //----------------------------------------------------------------------------
  825. void cmTargetTraceDependencies::FollowName(std::string const& name)
  826. {
  827. NameMapType::iterator i = this->NameMap.find(name);
  828. if(i == this->NameMap.end())
  829. {
  830. // Check if we know how to generate this file.
  831. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  832. NameMapType::value_type entry(name, sf);
  833. i = this->NameMap.insert(entry).first;
  834. }
  835. if(cmSourceFile* sf = i->second)
  836. {
  837. // Record the dependency we just followed.
  838. if(this->CurrentEntry)
  839. {
  840. this->CurrentEntry->Depends.push_back(sf);
  841. }
  842. this->QueueSource(sf);
  843. }
  844. }
  845. //----------------------------------------------------------------------------
  846. void
  847. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  848. {
  849. for(std::vector<std::string>::const_iterator i = names.begin();
  850. i != names.end(); ++i)
  851. {
  852. this->FollowName(*i);
  853. }
  854. }
  855. //----------------------------------------------------------------------------
  856. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  857. {
  858. // Dependencies on targets (utilities) are supposed to be named by
  859. // just the target name. However for compatibility we support
  860. // naming the output file generated by the target (assuming there is
  861. // no output-name property which old code would not have set). In
  862. // that case the target name will be the file basename of the
  863. // dependency.
  864. std::string util = cmSystemTools::GetFilenameName(dep);
  865. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  866. {
  867. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  868. }
  869. // Check for a target with this name.
  870. if(cmGeneratorTarget* t
  871. = this->Makefile->FindGeneratorTargetToUse(util))
  872. {
  873. // If we find the target and the dep was given as a full path,
  874. // then make sure it was not a full path to something else, and
  875. // the fact that the name matched a target was just a coincidence.
  876. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  877. {
  878. if(t->GetType() >= cmTarget::EXECUTABLE &&
  879. t->GetType() <= cmTarget::MODULE_LIBRARY)
  880. {
  881. // This is really only for compatibility so we do not need to
  882. // worry about configuration names and output names.
  883. std::string tLocation = t->GetLocationForBuild();
  884. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  885. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  886. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  887. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  888. if(depLocation == tLocation)
  889. {
  890. this->Target->AddUtility(util);
  891. return true;
  892. }
  893. }
  894. }
  895. else
  896. {
  897. // The original name of the dependency was not a full path. It
  898. // must name a target, so add the target-level dependency.
  899. this->Target->AddUtility(util);
  900. return true;
  901. }
  902. }
  903. // The dependency does not name a target built in this project.
  904. return false;
  905. }
  906. //----------------------------------------------------------------------------
  907. void
  908. cmTargetTraceDependencies
  909. ::CheckCustomCommand(cmCustomCommand const& cc)
  910. {
  911. // Transform command names that reference targets built in this
  912. // project to corresponding target-level dependencies.
  913. cmGeneratorExpression ge(cc.GetBacktrace());
  914. // Add target-level dependencies referenced by generator expressions.
  915. std::set<cmTarget*> targets;
  916. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  917. cit != cc.GetCommandLines().end(); ++cit)
  918. {
  919. std::string const& command = *cit->begin();
  920. // Check for a target with this name.
  921. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  922. {
  923. if(t->GetType() == cmTarget::EXECUTABLE)
  924. {
  925. // The command refers to an executable target built in
  926. // this project. Add the target-level dependency to make
  927. // sure the executable is up to date before this custom
  928. // command possibly runs.
  929. this->Target->AddUtility(command);
  930. }
  931. }
  932. // Check for target references in generator expressions.
  933. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  934. cli != cit->end(); ++cli)
  935. {
  936. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  937. = ge.Parse(*cli);
  938. cge->Evaluate(this->Makefile, "", true);
  939. std::set<cmTarget*> geTargets = cge->GetTargets();
  940. targets.insert(geTargets.begin(), geTargets.end());
  941. }
  942. }
  943. for(std::set<cmTarget*>::iterator ti = targets.begin();
  944. ti != targets.end(); ++ti)
  945. {
  946. this->Target->AddUtility((*ti)->GetName());
  947. }
  948. // Queue the custom command dependencies.
  949. std::vector<std::string> configs;
  950. std::set<std::string> emitted;
  951. this->Makefile->GetConfigurations(configs);
  952. if (configs.empty())
  953. {
  954. configs.push_back("");
  955. }
  956. for(std::vector<std::string>::const_iterator ci = configs.begin();
  957. ci != configs.end(); ++ci)
  958. {
  959. this->FollowCommandDepends(cc, *ci, emitted);
  960. }
  961. }
  962. //----------------------------------------------------------------------------
  963. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  964. const std::string& config,
  965. std::set<std::string>& emitted)
  966. {
  967. cmCustomCommandGenerator ccg(cc, config,
  968. this->GeneratorTarget->LocalGenerator);
  969. const std::vector<std::string>& depends = ccg.GetDepends();
  970. for(std::vector<std::string>::const_iterator di = depends.begin();
  971. di != depends.end(); ++di)
  972. {
  973. std::string const& dep = *di;
  974. if(emitted.insert(dep).second)
  975. {
  976. if(!this->IsUtility(dep))
  977. {
  978. // The dependency does not name a target and may be a file we
  979. // know how to generate. Queue it.
  980. this->FollowName(dep);
  981. }
  982. }
  983. }
  984. }
  985. //----------------------------------------------------------------------------
  986. void
  987. cmTargetTraceDependencies
  988. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  989. {
  990. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  991. cli != commands.end(); ++cli)
  992. {
  993. this->CheckCustomCommand(*cli);
  994. }
  995. }
  996. //----------------------------------------------------------------------------
  997. void cmGeneratorTarget::TraceDependencies()
  998. {
  999. // CMake-generated targets have no dependencies to trace. Normally tracing
  1000. // would find nothing anyway, but when building CMake itself the "install"
  1001. // target command ends up referencing the "cmake" target but we do not
  1002. // really want the dependency because "install" depend on "all" anyway.
  1003. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1004. {
  1005. return;
  1006. }
  1007. // Use a helper object to trace the dependencies.
  1008. cmTargetTraceDependencies tracer(this);
  1009. tracer.Trace();
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1013. std::vector<std::string>& archVec) const
  1014. {
  1015. const char* archs = 0;
  1016. if(!config.empty())
  1017. {
  1018. std::string defVarName = "OSX_ARCHITECTURES_";
  1019. defVarName += cmSystemTools::UpperCase(config);
  1020. archs = this->Target->GetProperty(defVarName);
  1021. }
  1022. if(!archs)
  1023. {
  1024. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1025. }
  1026. if(archs)
  1027. {
  1028. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1029. }
  1030. }
  1031. //----------------------------------------------------------------------------
  1032. std::string
  1033. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1034. std::string const& config) const
  1035. {
  1036. switch(this->GetType())
  1037. {
  1038. case cmTarget::STATIC_LIBRARY:
  1039. {
  1040. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1041. if(this->GetFeatureAsBool(
  1042. "INTERPROCEDURAL_OPTIMIZATION", config))
  1043. {
  1044. std::string varIPO = var + "_IPO";
  1045. if(this->Makefile->GetDefinition(varIPO))
  1046. {
  1047. return varIPO;
  1048. }
  1049. }
  1050. return var;
  1051. }
  1052. case cmTarget::SHARED_LIBRARY:
  1053. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1054. case cmTarget::MODULE_LIBRARY:
  1055. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1056. case cmTarget::EXECUTABLE:
  1057. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1058. default:
  1059. break;
  1060. }
  1061. return "";
  1062. }
  1063. //----------------------------------------------------------------------------
  1064. std::vector<std::string>
  1065. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1066. const std::string& lang) const
  1067. {
  1068. return this->Target->GetIncludeDirectories(config, lang);
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. void cmGeneratorTarget::GenerateTargetManifest(
  1072. const std::string& config) const
  1073. {
  1074. if (this->Target->IsImported())
  1075. {
  1076. return;
  1077. }
  1078. cmMakefile* mf = this->Target->GetMakefile();
  1079. cmGlobalGenerator* gg = mf->GetGlobalGenerator();
  1080. // Get the names.
  1081. std::string name;
  1082. std::string soName;
  1083. std::string realName;
  1084. std::string impName;
  1085. std::string pdbName;
  1086. if(this->GetType() == cmTarget::EXECUTABLE)
  1087. {
  1088. this->Target->GetExecutableNames(name, realName, impName, pdbName,
  1089. config);
  1090. }
  1091. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1092. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1093. this->GetType() == cmTarget::MODULE_LIBRARY)
  1094. {
  1095. this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
  1096. config);
  1097. }
  1098. else
  1099. {
  1100. return;
  1101. }
  1102. // Get the directory.
  1103. std::string dir = this->Target->GetDirectory(config, false);
  1104. // Add each name.
  1105. std::string f;
  1106. if(!name.empty())
  1107. {
  1108. f = dir;
  1109. f += "/";
  1110. f += name;
  1111. gg->AddToManifest(f);
  1112. }
  1113. if(!soName.empty())
  1114. {
  1115. f = dir;
  1116. f += "/";
  1117. f += soName;
  1118. gg->AddToManifest(f);
  1119. }
  1120. if(!realName.empty())
  1121. {
  1122. f = dir;
  1123. f += "/";
  1124. f += realName;
  1125. gg->AddToManifest(f);
  1126. }
  1127. if(!pdbName.empty())
  1128. {
  1129. f = dir;
  1130. f += "/";
  1131. f += pdbName;
  1132. gg->AddToManifest(f);
  1133. }
  1134. if(!impName.empty())
  1135. {
  1136. f = this->Target->GetDirectory(config, true);
  1137. f += "/";
  1138. f += impName;
  1139. gg->AddToManifest(f);
  1140. }
  1141. }
  1142. //----------------------------------------------------------------------------
  1143. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1144. bool implib, bool realname) const
  1145. {
  1146. if(this->Target->IsImported())
  1147. {
  1148. return this->Target->ImportedGetFullPath(config, implib);
  1149. }
  1150. else
  1151. {
  1152. return this->NormalGetFullPath(config, implib, realname);
  1153. }
  1154. }
  1155. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1156. bool implib,
  1157. bool realname) const
  1158. {
  1159. std::string fpath = this->Target->GetDirectory(config, implib);
  1160. fpath += "/";
  1161. if(this->Target->IsAppBundleOnApple())
  1162. {
  1163. fpath = this->Target->BuildMacContentDirectory(fpath, config, false);
  1164. fpath += "/";
  1165. }
  1166. // Add the full name of the target.
  1167. if(implib)
  1168. {
  1169. fpath += this->Target->GetFullName(config, true);
  1170. }
  1171. else if(realname)
  1172. {
  1173. fpath += this->NormalGetRealName(config);
  1174. }
  1175. else
  1176. {
  1177. fpath += this->Target->GetFullName(config, false);
  1178. }
  1179. return fpath;
  1180. }
  1181. //----------------------------------------------------------------------------
  1182. std::string
  1183. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1184. {
  1185. // This should not be called for imported targets.
  1186. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1187. // enforcement of the limited imported target API.
  1188. if(this->Target->IsImported())
  1189. {
  1190. std::string msg = "NormalGetRealName called on imported target: ";
  1191. msg += this->GetName();
  1192. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1193. }
  1194. if(this->GetType() == cmTarget::EXECUTABLE)
  1195. {
  1196. // Compute the real name that will be built.
  1197. std::string name;
  1198. std::string realName;
  1199. std::string impName;
  1200. std::string pdbName;
  1201. this->Target->GetExecutableNames(name, realName, impName, pdbName, config);
  1202. return realName;
  1203. }
  1204. else
  1205. {
  1206. // Compute the real name that will be built.
  1207. std::string name;
  1208. std::string soName;
  1209. std::string realName;
  1210. std::string impName;
  1211. std::string pdbName;
  1212. this->Target->GetLibraryNames(name, soName, realName,
  1213. impName, pdbName, config);
  1214. return realName;
  1215. }
  1216. }
  1217. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  1218. cmTarget const* t2) const
  1219. {
  1220. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  1221. if (nameResult == 0)
  1222. {
  1223. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  1224. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  1225. }
  1226. return nameResult < 0;
  1227. }
  1228. //----------------------------------------------------------------------------
  1229. struct cmGeneratorTarget::SourceFileFlags
  1230. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  1231. {
  1232. struct SourceFileFlags flags;
  1233. this->ConstructSourceFileFlags();
  1234. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1235. this->SourceFlagsMap.find(sf);
  1236. if(si != this->SourceFlagsMap.end())
  1237. {
  1238. flags = si->second;
  1239. }
  1240. else
  1241. {
  1242. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1243. // were not listed in one of the other lists.
  1244. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1245. {
  1246. flags.MacFolder = location;
  1247. if(strcmp(location, "Resources") == 0)
  1248. {
  1249. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1250. }
  1251. else
  1252. {
  1253. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  1254. }
  1255. }
  1256. }
  1257. return flags;
  1258. }
  1259. //----------------------------------------------------------------------------
  1260. void cmGeneratorTarget::ConstructSourceFileFlags() const
  1261. {
  1262. if(this->SourceFileFlagsConstructed)
  1263. {
  1264. return;
  1265. }
  1266. this->SourceFileFlagsConstructed = true;
  1267. // Process public headers to mark the source files.
  1268. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  1269. {
  1270. std::vector<std::string> relFiles;
  1271. cmSystemTools::ExpandListArgument(files, relFiles);
  1272. for(std::vector<std::string>::iterator it = relFiles.begin();
  1273. it != relFiles.end(); ++it)
  1274. {
  1275. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1276. {
  1277. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1278. flags.MacFolder = "Headers";
  1279. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  1280. }
  1281. }
  1282. }
  1283. // Process private headers after public headers so that they take
  1284. // precedence if a file is listed in both.
  1285. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  1286. {
  1287. std::vector<std::string> relFiles;
  1288. cmSystemTools::ExpandListArgument(files, relFiles);
  1289. for(std::vector<std::string>::iterator it = relFiles.begin();
  1290. it != relFiles.end(); ++it)
  1291. {
  1292. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1293. {
  1294. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1295. flags.MacFolder = "PrivateHeaders";
  1296. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  1297. }
  1298. }
  1299. }
  1300. // Mark sources listed as resources.
  1301. if(const char* files = this->Target->GetProperty("RESOURCE"))
  1302. {
  1303. std::vector<std::string> relFiles;
  1304. cmSystemTools::ExpandListArgument(files, relFiles);
  1305. for(std::vector<std::string>::iterator it = relFiles.begin();
  1306. it != relFiles.end(); ++it)
  1307. {
  1308. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1309. {
  1310. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1311. flags.MacFolder = "Resources";
  1312. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1313. }
  1314. }
  1315. }
  1316. }