cmGeneratorTarget.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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 <queue>
  19. //----------------------------------------------------------------------------
  20. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t)
  21. {
  22. this->Makefile = this->Target->GetMakefile();
  23. this->LocalGenerator = this->Makefile->GetLocalGenerator();
  24. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  25. }
  26. //----------------------------------------------------------------------------
  27. int cmGeneratorTarget::GetType() const
  28. {
  29. return this->Target->GetType();
  30. }
  31. //----------------------------------------------------------------------------
  32. const char *cmGeneratorTarget::GetName() const
  33. {
  34. return this->Target->GetName();
  35. }
  36. //----------------------------------------------------------------------------
  37. const char *cmGeneratorTarget::GetProperty(const char *prop) const
  38. {
  39. return this->Target->GetProperty(prop);
  40. }
  41. //----------------------------------------------------------------------------
  42. std::vector<cmSourceFile*> const*
  43. cmGeneratorTarget::GetSourceDepends(cmSourceFile* sf) const
  44. {
  45. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  46. if(i != this->SourceEntries.end())
  47. {
  48. return &i->second.Depends;
  49. }
  50. return 0;
  51. }
  52. //----------------------------------------------------------------------------
  53. bool cmGeneratorTarget::IsSystemIncludeDirectory(const char *dir,
  54. const char *config) const
  55. {
  56. std::string config_upper;
  57. if(config && *config)
  58. {
  59. config_upper = cmSystemTools::UpperCase(config);
  60. }
  61. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  62. IncludeCacheType::const_iterator iter =
  63. this->SystemIncludesCache.find(config_upper);
  64. if (iter == this->SystemIncludesCache.end())
  65. {
  66. std::vector<std::string> result;
  67. for (std::set<cmStdString>::const_iterator
  68. it = this->Target->GetSystemIncludeDirectories().begin();
  69. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  70. {
  71. cmListFileBacktrace lfbt;
  72. cmGeneratorExpression ge(lfbt);
  73. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  74. this->GetName(),
  75. "INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  76. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  77. ->Evaluate(this->Makefile,
  78. config, false, this->Target,
  79. &dagChecker), result);
  80. }
  81. for(std::vector<std::string>::iterator li = result.begin();
  82. li != result.end(); ++li)
  83. {
  84. cmSystemTools::ConvertToUnixSlashes(*li);
  85. }
  86. IncludeCacheType::value_type entry(config_upper, result);
  87. iter = this->SystemIncludesCache.insert(entry).first;
  88. }
  89. if (std::find(iter->second.begin(),
  90. iter->second.end(), dir) != iter->second.end())
  91. {
  92. return true;
  93. }
  94. return false;
  95. }
  96. //----------------------------------------------------------------------------
  97. bool cmGeneratorTarget::GetPropertyAsBool(const char *prop) const
  98. {
  99. return this->Target->GetPropertyAsBool(prop);
  100. }
  101. //----------------------------------------------------------------------------
  102. std::vector<cmSourceFile*> const& cmGeneratorTarget::GetSourceFiles() const
  103. {
  104. return this->Target->GetSourceFiles();
  105. }
  106. //----------------------------------------------------------------------------
  107. void cmGeneratorTarget::ClassifySources()
  108. {
  109. cmsys::RegularExpression header(CM_HEADER_REGEX);
  110. cmTarget::TargetType targetType = this->Target->GetType();
  111. bool isObjLib = targetType == cmTarget::OBJECT_LIBRARY;
  112. std::vector<cmSourceFile*> badObjLib;
  113. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  114. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  115. si != sources.end(); ++si)
  116. {
  117. cmSourceFile* sf = *si;
  118. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  119. if(sf->GetCustomCommand())
  120. {
  121. this->CustomCommands.push_back(sf);
  122. }
  123. else if(targetType == cmTarget::UTILITY)
  124. {
  125. this->ExtraSources.push_back(sf);
  126. }
  127. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  128. {
  129. this->HeaderSources.push_back(sf);
  130. }
  131. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  132. {
  133. this->ExternalObjects.push_back(sf);
  134. if(isObjLib) { badObjLib.push_back(sf); }
  135. }
  136. else if(sf->GetLanguage())
  137. {
  138. this->ObjectSources.push_back(sf);
  139. }
  140. else if(ext == "def")
  141. {
  142. this->ModuleDefinitionFile = sf->GetFullPath();
  143. if(isObjLib) { badObjLib.push_back(sf); }
  144. }
  145. else if(ext == "idl")
  146. {
  147. this->IDLSources.push_back(sf);
  148. if(isObjLib) { badObjLib.push_back(sf); }
  149. }
  150. else if(ext == "resx")
  151. {
  152. // Build and save the name of the corresponding .h file
  153. // This relationship will be used later when building the project files.
  154. // Both names would have been auto generated from Visual Studio
  155. // where the user supplied the file name and Visual Studio
  156. // appended the suffix.
  157. std::string resx = sf->GetFullPath();
  158. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  159. this->ExpectedResxHeaders.insert(hFileName);
  160. this->ResxSources.push_back(sf);
  161. }
  162. else if(header.find(sf->GetFullPath().c_str()))
  163. {
  164. this->HeaderSources.push_back(sf);
  165. }
  166. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  167. {
  168. // We only get here if a source file is not an external object
  169. // and has an extension that is listed as an ignored file type.
  170. // No message or diagnosis should be given.
  171. this->ExtraSources.push_back(sf);
  172. }
  173. else
  174. {
  175. this->ExtraSources.push_back(sf);
  176. if(isObjLib && ext != "txt")
  177. {
  178. badObjLib.push_back(sf);
  179. }
  180. }
  181. }
  182. if(!badObjLib.empty())
  183. {
  184. cmOStringStream e;
  185. e << "OBJECT library \"" << this->Target->GetName() << "\" contains:\n";
  186. for(std::vector<cmSourceFile*>::iterator i = badObjLib.begin();
  187. i != badObjLib.end(); ++i)
  188. {
  189. e << " " << (*i)->GetLocation().GetName() << "\n";
  190. }
  191. e << "but may contain only headers and sources that compile.";
  192. this->GlobalGenerator->GetCMakeInstance()
  193. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  194. this->Target->GetBacktrace());
  195. }
  196. }
  197. //----------------------------------------------------------------------------
  198. void cmGeneratorTarget::LookupObjectLibraries()
  199. {
  200. std::vector<std::string> const& objLibs =
  201. this->Target->GetObjectLibraries();
  202. for(std::vector<std::string>::const_iterator oli = objLibs.begin();
  203. oli != objLibs.end(); ++oli)
  204. {
  205. std::string const& objLibName = *oli;
  206. if(cmTarget* objLib = this->Makefile->FindTargetToUse(objLibName.c_str()))
  207. {
  208. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  209. {
  210. if(this->Target->GetType() != cmTarget::EXECUTABLE &&
  211. this->Target->GetType() != cmTarget::STATIC_LIBRARY &&
  212. this->Target->GetType() != cmTarget::SHARED_LIBRARY &&
  213. this->Target->GetType() != cmTarget::MODULE_LIBRARY)
  214. {
  215. this->GlobalGenerator->GetCMakeInstance()
  216. ->IssueMessage(cmake::FATAL_ERROR,
  217. "Only executables and non-OBJECT libraries may "
  218. "reference target objects.",
  219. this->Target->GetBacktrace());
  220. return;
  221. }
  222. this->Target->AddUtility(objLib->GetName());
  223. this->ObjectLibraries.push_back(objLib);
  224. }
  225. else
  226. {
  227. cmOStringStream e;
  228. e << "Objects of target \"" << objLibName
  229. << "\" referenced but is not an OBJECT library.";
  230. this->GlobalGenerator->GetCMakeInstance()
  231. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  232. this->Target->GetBacktrace());
  233. return;
  234. }
  235. }
  236. else
  237. {
  238. cmOStringStream e;
  239. e << "Objects of target \"" << objLibName
  240. << "\" referenced but no such target exists.";
  241. this->GlobalGenerator->GetCMakeInstance()
  242. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  243. this->Target->GetBacktrace());
  244. return;
  245. }
  246. }
  247. }
  248. //----------------------------------------------------------------------------
  249. void
  250. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs) const
  251. {
  252. for(std::vector<cmTarget*>::const_iterator
  253. ti = this->ObjectLibraries.begin();
  254. ti != this->ObjectLibraries.end(); ++ti)
  255. {
  256. cmTarget* objLib = *ti;
  257. cmGeneratorTarget* ogt =
  258. this->GlobalGenerator->GetGeneratorTarget(objLib);
  259. for(std::vector<cmSourceFile*>::const_iterator
  260. si = ogt->ObjectSources.begin();
  261. si != ogt->ObjectSources.end(); ++si)
  262. {
  263. std::string obj = ogt->ObjectDirectory;
  264. obj += ogt->Objects[*si];
  265. objs.push_back(obj);
  266. }
  267. }
  268. }
  269. //----------------------------------------------------------------------------
  270. class cmTargetTraceDependencies
  271. {
  272. public:
  273. cmTargetTraceDependencies(cmGeneratorTarget* target);
  274. void Trace();
  275. private:
  276. cmTarget* Target;
  277. cmGeneratorTarget* GeneratorTarget;
  278. cmMakefile* Makefile;
  279. cmGlobalGenerator* GlobalGenerator;
  280. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  281. SourceEntry* CurrentEntry;
  282. std::queue<cmSourceFile*> SourceQueue;
  283. std::set<cmSourceFile*> SourcesQueued;
  284. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  285. NameMapType NameMap;
  286. void QueueSource(cmSourceFile* sf);
  287. void FollowName(std::string const& name);
  288. void FollowNames(std::vector<std::string> const& names);
  289. bool IsUtility(std::string const& dep);
  290. void CheckCustomCommand(cmCustomCommand const& cc);
  291. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  292. };
  293. //----------------------------------------------------------------------------
  294. cmTargetTraceDependencies
  295. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  296. Target(target->Target), GeneratorTarget(target)
  297. {
  298. // Convenience.
  299. this->Makefile = this->Target->GetMakefile();
  300. this->GlobalGenerator =
  301. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  302. this->CurrentEntry = 0;
  303. // Queue all the source files already specified for the target.
  304. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  305. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  306. si != sources.end(); ++si)
  307. {
  308. this->QueueSource(*si);
  309. }
  310. // Queue pre-build, pre-link, and post-build rule dependencies.
  311. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  312. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  313. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  314. }
  315. //----------------------------------------------------------------------------
  316. void cmTargetTraceDependencies::Trace()
  317. {
  318. // Process one dependency at a time until the queue is empty.
  319. while(!this->SourceQueue.empty())
  320. {
  321. // Get the next source from the queue.
  322. cmSourceFile* sf = this->SourceQueue.front();
  323. this->SourceQueue.pop();
  324. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  325. // Queue dependencies added explicitly by the user.
  326. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  327. {
  328. std::vector<std::string> objDeps;
  329. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  330. this->FollowNames(objDeps);
  331. }
  332. // Queue the source needed to generate this file, if any.
  333. this->FollowName(sf->GetFullPath());
  334. // Queue dependencies added programatically by commands.
  335. this->FollowNames(sf->GetDepends());
  336. // Queue custom command dependencies.
  337. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  338. {
  339. this->CheckCustomCommand(*cc);
  340. }
  341. }
  342. this->CurrentEntry = 0;
  343. }
  344. //----------------------------------------------------------------------------
  345. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  346. {
  347. if(this->SourcesQueued.insert(sf).second)
  348. {
  349. this->SourceQueue.push(sf);
  350. // Make sure this file is in the target.
  351. this->Target->AddSourceFile(sf);
  352. }
  353. }
  354. //----------------------------------------------------------------------------
  355. void cmTargetTraceDependencies::FollowName(std::string const& name)
  356. {
  357. NameMapType::iterator i = this->NameMap.find(name);
  358. if(i == this->NameMap.end())
  359. {
  360. // Check if we know how to generate this file.
  361. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  362. NameMapType::value_type entry(name, sf);
  363. i = this->NameMap.insert(entry).first;
  364. }
  365. if(cmSourceFile* sf = i->second)
  366. {
  367. // Record the dependency we just followed.
  368. if(this->CurrentEntry)
  369. {
  370. this->CurrentEntry->Depends.push_back(sf);
  371. }
  372. this->QueueSource(sf);
  373. }
  374. }
  375. //----------------------------------------------------------------------------
  376. void
  377. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  378. {
  379. for(std::vector<std::string>::const_iterator i = names.begin();
  380. i != names.end(); ++i)
  381. {
  382. this->FollowName(*i);
  383. }
  384. }
  385. //----------------------------------------------------------------------------
  386. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  387. {
  388. // Dependencies on targets (utilities) are supposed to be named by
  389. // just the target name. However for compatibility we support
  390. // naming the output file generated by the target (assuming there is
  391. // no output-name property which old code would not have set). In
  392. // that case the target name will be the file basename of the
  393. // dependency.
  394. std::string util = cmSystemTools::GetFilenameName(dep);
  395. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  396. {
  397. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  398. }
  399. // Check for a target with this name.
  400. if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
  401. {
  402. // If we find the target and the dep was given as a full path,
  403. // then make sure it was not a full path to something else, and
  404. // the fact that the name matched a target was just a coincidence.
  405. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  406. {
  407. if(t->GetType() >= cmTarget::EXECUTABLE &&
  408. t->GetType() <= cmTarget::MODULE_LIBRARY)
  409. {
  410. // This is really only for compatibility so we do not need to
  411. // worry about configuration names and output names.
  412. std::string tLocation = t->GetLocation(0);
  413. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  414. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  415. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  416. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  417. if(depLocation == tLocation)
  418. {
  419. this->Target->AddUtility(util.c_str());
  420. return true;
  421. }
  422. }
  423. }
  424. else
  425. {
  426. // The original name of the dependency was not a full path. It
  427. // must name a target, so add the target-level dependency.
  428. this->Target->AddUtility(util.c_str());
  429. return true;
  430. }
  431. }
  432. // The dependency does not name a target built in this project.
  433. return false;
  434. }
  435. //----------------------------------------------------------------------------
  436. void
  437. cmTargetTraceDependencies
  438. ::CheckCustomCommand(cmCustomCommand const& cc)
  439. {
  440. // Transform command names that reference targets built in this
  441. // project to corresponding target-level dependencies.
  442. cmGeneratorExpression ge(cc.GetBacktrace());
  443. // Add target-level dependencies referenced by generator expressions.
  444. std::set<cmTarget*> targets;
  445. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  446. cit != cc.GetCommandLines().end(); ++cit)
  447. {
  448. std::string const& command = *cit->begin();
  449. // Check for a target with this name.
  450. if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
  451. {
  452. if(t->GetType() == cmTarget::EXECUTABLE)
  453. {
  454. // The command refers to an executable target built in
  455. // this project. Add the target-level dependency to make
  456. // sure the executable is up to date before this custom
  457. // command possibly runs.
  458. this->Target->AddUtility(command.c_str());
  459. }
  460. }
  461. // Check for target references in generator expressions.
  462. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  463. cli != cit->end(); ++cli)
  464. {
  465. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  466. = ge.Parse(*cli);
  467. cge->Evaluate(this->Makefile, 0, true);
  468. std::set<cmTarget*> geTargets = cge->GetTargets();
  469. for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
  470. it != geTargets.end(); ++it)
  471. {
  472. targets.insert(*it);
  473. }
  474. }
  475. }
  476. for(std::set<cmTarget*>::iterator ti = targets.begin();
  477. ti != targets.end(); ++ti)
  478. {
  479. this->Target->AddUtility((*ti)->GetName());
  480. }
  481. // Queue the custom command dependencies.
  482. std::vector<std::string> const& depends = cc.GetDepends();
  483. for(std::vector<std::string>::const_iterator di = depends.begin();
  484. di != depends.end(); ++di)
  485. {
  486. std::string const& dep = *di;
  487. if(!this->IsUtility(dep))
  488. {
  489. // The dependency does not name a target and may be a file we
  490. // know how to generate. Queue it.
  491. this->FollowName(dep);
  492. }
  493. }
  494. }
  495. //----------------------------------------------------------------------------
  496. void
  497. cmTargetTraceDependencies
  498. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  499. {
  500. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  501. cli != commands.end(); ++cli)
  502. {
  503. this->CheckCustomCommand(*cli);
  504. }
  505. }
  506. //----------------------------------------------------------------------------
  507. void cmGeneratorTarget::TraceDependencies()
  508. {
  509. // CMake-generated targets have no dependencies to trace. Normally tracing
  510. // would find nothing anyway, but when building CMake itself the "install"
  511. // target command ends up referencing the "cmake" target but we do not
  512. // really want the dependency because "install" depend on "all" anyway.
  513. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  514. {
  515. return;
  516. }
  517. // Use a helper object to trace the dependencies.
  518. cmTargetTraceDependencies tracer(this);
  519. tracer.Trace();
  520. }
  521. //----------------------------------------------------------------------------
  522. void cmGeneratorTarget::GetAppleArchs(const char* config,
  523. std::vector<std::string>& archVec) const
  524. {
  525. const char* archs = 0;
  526. if(config && *config)
  527. {
  528. std::string defVarName = "OSX_ARCHITECTURES_";
  529. defVarName += cmSystemTools::UpperCase(config);
  530. archs = this->Target->GetProperty(defVarName.c_str());
  531. }
  532. if(!archs)
  533. {
  534. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  535. }
  536. if(archs)
  537. {
  538. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  539. }
  540. }
  541. //----------------------------------------------------------------------------
  542. const char* cmGeneratorTarget::GetCreateRuleVariable() const
  543. {
  544. switch(this->GetType())
  545. {
  546. case cmTarget::STATIC_LIBRARY:
  547. return "_CREATE_STATIC_LIBRARY";
  548. case cmTarget::SHARED_LIBRARY:
  549. return "_CREATE_SHARED_LIBRARY";
  550. case cmTarget::MODULE_LIBRARY:
  551. return "_CREATE_SHARED_MODULE";
  552. case cmTarget::EXECUTABLE:
  553. return "_LINK_EXECUTABLE";
  554. default:
  555. break;
  556. }
  557. return "";
  558. }
  559. //----------------------------------------------------------------------------
  560. std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
  561. const char *config)
  562. {
  563. return this->Target->GetIncludeDirectories(config);
  564. }
  565. //----------------------------------------------------------------------------
  566. void cmGeneratorTarget::GenerateTargetManifest(const char* config) const
  567. {
  568. if (this->Target->IsImported())
  569. {
  570. return;
  571. }
  572. cmMakefile* mf = this->Target->GetMakefile();
  573. cmLocalGenerator* lg = mf->GetLocalGenerator();
  574. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  575. // Get the names.
  576. std::string name;
  577. std::string soName;
  578. std::string realName;
  579. std::string impName;
  580. std::string pdbName;
  581. if(this->GetType() == cmTarget::EXECUTABLE)
  582. {
  583. this->Target->GetExecutableNames(name, realName, impName, pdbName,
  584. config);
  585. }
  586. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  587. this->GetType() == cmTarget::SHARED_LIBRARY ||
  588. this->GetType() == cmTarget::MODULE_LIBRARY)
  589. {
  590. this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
  591. config);
  592. }
  593. else
  594. {
  595. return;
  596. }
  597. // Get the directory.
  598. std::string dir = this->Target->GetDirectory(config, false);
  599. // Add each name.
  600. std::string f;
  601. if(!name.empty())
  602. {
  603. f = dir;
  604. f += "/";
  605. f += name;
  606. gg->AddToManifest(config? config:"", f);
  607. }
  608. if(!soName.empty())
  609. {
  610. f = dir;
  611. f += "/";
  612. f += soName;
  613. gg->AddToManifest(config? config:"", f);
  614. }
  615. if(!realName.empty())
  616. {
  617. f = dir;
  618. f += "/";
  619. f += realName;
  620. gg->AddToManifest(config? config:"", f);
  621. }
  622. if(!pdbName.empty())
  623. {
  624. f = dir;
  625. f += "/";
  626. f += pdbName;
  627. gg->AddToManifest(config? config:"", f);
  628. }
  629. if(!impName.empty())
  630. {
  631. f = this->Target->GetDirectory(config, true);
  632. f += "/";
  633. f += impName;
  634. gg->AddToManifest(config? config:"", f);
  635. }
  636. }