cmGeneratorTarget.cxx 28 KB

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