cmGeneratorTarget.cxx 43 KB

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