cmGeneratorTarget.cxx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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);
  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);
  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. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
  246. {
  247. this->Target->GetSourceFiles(files);
  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*> sources;
  257. this->Target->GetSourceFiles(sources);
  258. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  259. si != sources.end(); ++si)
  260. {
  261. cmSourceFile* sf = *si;
  262. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  263. if(sf->GetCustomCommand())
  264. {
  265. this->CustomCommands.push_back(sf);
  266. }
  267. else if(targetType == cmTarget::UTILITY)
  268. {
  269. this->ExtraSources.push_back(sf);
  270. }
  271. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  272. {
  273. this->HeaderSources.push_back(sf);
  274. }
  275. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  276. {
  277. this->ExternalObjects.push_back(sf);
  278. if(isObjLib) { badObjLib.push_back(sf); }
  279. }
  280. else if(sf->GetLanguage())
  281. {
  282. this->ObjectSources.push_back(sf);
  283. }
  284. else if(ext == "def")
  285. {
  286. this->ModuleDefinitionFile = sf->GetFullPath();
  287. if(isObjLib) { badObjLib.push_back(sf); }
  288. }
  289. else if(ext == "idl")
  290. {
  291. this->IDLSources.push_back(sf);
  292. if(isObjLib) { badObjLib.push_back(sf); }
  293. }
  294. else if(ext == "resx")
  295. {
  296. // Build and save the name of the corresponding .h file
  297. // This relationship will be used later when building the project files.
  298. // Both names would have been auto generated from Visual Studio
  299. // where the user supplied the file name and Visual Studio
  300. // appended the suffix.
  301. std::string resx = sf->GetFullPath();
  302. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  303. this->ExpectedResxHeaders.insert(hFileName);
  304. this->ResxSources.push_back(sf);
  305. }
  306. else if(header.find(sf->GetFullPath().c_str()))
  307. {
  308. this->HeaderSources.push_back(sf);
  309. }
  310. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  311. {
  312. // We only get here if a source file is not an external object
  313. // and has an extension that is listed as an ignored file type.
  314. // No message or diagnosis should be given.
  315. this->ExtraSources.push_back(sf);
  316. }
  317. else
  318. {
  319. this->ExtraSources.push_back(sf);
  320. if(isObjLib && ext != "txt")
  321. {
  322. badObjLib.push_back(sf);
  323. }
  324. }
  325. }
  326. if(!badObjLib.empty())
  327. {
  328. cmOStringStream e;
  329. e << "OBJECT library \"" << this->Target->GetName() << "\" contains:\n";
  330. for(std::vector<cmSourceFile*>::iterator i = badObjLib.begin();
  331. i != badObjLib.end(); ++i)
  332. {
  333. e << " " << (*i)->GetLocation().GetName() << "\n";
  334. }
  335. e << "but may contain only headers and sources that compile.";
  336. this->GlobalGenerator->GetCMakeInstance()
  337. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  338. this->Target->GetBacktrace());
  339. }
  340. }
  341. //----------------------------------------------------------------------------
  342. void cmGeneratorTarget::LookupObjectLibraries()
  343. {
  344. std::vector<std::string> const& objLibs =
  345. this->Target->GetObjectLibraries();
  346. for(std::vector<std::string>::const_iterator oli = objLibs.begin();
  347. oli != objLibs.end(); ++oli)
  348. {
  349. std::string const& objLibName = *oli;
  350. if(cmTarget* objLib = this->Makefile->FindTargetToUse(objLibName))
  351. {
  352. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  353. {
  354. if(this->Target->GetType() != cmTarget::EXECUTABLE &&
  355. this->Target->GetType() != cmTarget::STATIC_LIBRARY &&
  356. this->Target->GetType() != cmTarget::SHARED_LIBRARY &&
  357. this->Target->GetType() != cmTarget::MODULE_LIBRARY)
  358. {
  359. this->GlobalGenerator->GetCMakeInstance()
  360. ->IssueMessage(cmake::FATAL_ERROR,
  361. "Only executables and non-OBJECT libraries may "
  362. "reference target objects.",
  363. this->Target->GetBacktrace());
  364. return;
  365. }
  366. this->Target->AddUtility(objLib->GetName());
  367. this->ObjectLibraries.push_back(objLib);
  368. }
  369. else
  370. {
  371. cmOStringStream e;
  372. e << "Objects of target \"" << objLibName
  373. << "\" referenced but is not an OBJECT library.";
  374. this->GlobalGenerator->GetCMakeInstance()
  375. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  376. this->Target->GetBacktrace());
  377. return;
  378. }
  379. }
  380. else
  381. {
  382. cmOStringStream e;
  383. e << "Objects of target \"" << objLibName
  384. << "\" referenced but no such target exists.";
  385. this->GlobalGenerator->GetCMakeInstance()
  386. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  387. this->Target->GetBacktrace());
  388. return;
  389. }
  390. }
  391. }
  392. //----------------------------------------------------------------------------
  393. void
  394. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs) const
  395. {
  396. for(std::vector<cmTarget*>::const_iterator
  397. ti = this->ObjectLibraries.begin();
  398. ti != this->ObjectLibraries.end(); ++ti)
  399. {
  400. cmTarget* objLib = *ti;
  401. cmGeneratorTarget* ogt =
  402. this->GlobalGenerator->GetGeneratorTarget(objLib);
  403. for(std::vector<cmSourceFile*>::const_iterator
  404. si = ogt->ObjectSources.begin();
  405. si != ogt->ObjectSources.end(); ++si)
  406. {
  407. std::string obj = ogt->ObjectDirectory;
  408. obj += ogt->Objects[*si];
  409. objs.push_back(obj);
  410. }
  411. }
  412. }
  413. //----------------------------------------------------------------------------
  414. class cmTargetTraceDependencies
  415. {
  416. public:
  417. cmTargetTraceDependencies(cmGeneratorTarget* target);
  418. void Trace();
  419. private:
  420. cmTarget* Target;
  421. cmGeneratorTarget* GeneratorTarget;
  422. cmMakefile* Makefile;
  423. cmGlobalGenerator const* GlobalGenerator;
  424. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  425. SourceEntry* CurrentEntry;
  426. std::queue<cmSourceFile*> SourceQueue;
  427. std::set<cmSourceFile*> SourcesQueued;
  428. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  429. NameMapType NameMap;
  430. void QueueSource(cmSourceFile* sf);
  431. void FollowName(std::string const& name);
  432. void FollowNames(std::vector<std::string> const& names);
  433. bool IsUtility(std::string const& dep);
  434. void CheckCustomCommand(cmCustomCommand const& cc);
  435. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  436. };
  437. //----------------------------------------------------------------------------
  438. cmTargetTraceDependencies
  439. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  440. Target(target->Target), GeneratorTarget(target)
  441. {
  442. // Convenience.
  443. this->Makefile = this->Target->GetMakefile();
  444. this->GlobalGenerator =
  445. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  446. this->CurrentEntry = 0;
  447. // Queue all the source files already specified for the target.
  448. std::vector<cmSourceFile*> sources;
  449. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  450. {
  451. this->Target->GetSourceFiles(sources);
  452. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  453. si != sources.end(); ++si)
  454. {
  455. this->QueueSource(*si);
  456. }
  457. }
  458. // Queue pre-build, pre-link, and post-build rule dependencies.
  459. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  460. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  461. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  462. }
  463. //----------------------------------------------------------------------------
  464. void cmTargetTraceDependencies::Trace()
  465. {
  466. // Process one dependency at a time until the queue is empty.
  467. while(!this->SourceQueue.empty())
  468. {
  469. // Get the next source from the queue.
  470. cmSourceFile* sf = this->SourceQueue.front();
  471. this->SourceQueue.pop();
  472. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  473. // Queue dependencies added explicitly by the user.
  474. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  475. {
  476. std::vector<std::string> objDeps;
  477. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  478. this->FollowNames(objDeps);
  479. }
  480. // Queue the source needed to generate this file, if any.
  481. this->FollowName(sf->GetFullPath());
  482. // Queue dependencies added programatically by commands.
  483. this->FollowNames(sf->GetDepends());
  484. // Queue custom command dependencies.
  485. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  486. {
  487. this->CheckCustomCommand(*cc);
  488. }
  489. }
  490. this->CurrentEntry = 0;
  491. }
  492. //----------------------------------------------------------------------------
  493. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  494. {
  495. if(this->SourcesQueued.insert(sf).second)
  496. {
  497. this->SourceQueue.push(sf);
  498. // Make sure this file is in the target.
  499. this->Target->AddSourceFile(sf);
  500. }
  501. }
  502. //----------------------------------------------------------------------------
  503. void cmTargetTraceDependencies::FollowName(std::string const& name)
  504. {
  505. NameMapType::iterator i = this->NameMap.find(name);
  506. if(i == this->NameMap.end())
  507. {
  508. // Check if we know how to generate this file.
  509. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  510. NameMapType::value_type entry(name, sf);
  511. i = this->NameMap.insert(entry).first;
  512. }
  513. if(cmSourceFile* sf = i->second)
  514. {
  515. // Record the dependency we just followed.
  516. if(this->CurrentEntry)
  517. {
  518. this->CurrentEntry->Depends.push_back(sf);
  519. }
  520. this->QueueSource(sf);
  521. }
  522. }
  523. //----------------------------------------------------------------------------
  524. void
  525. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  526. {
  527. for(std::vector<std::string>::const_iterator i = names.begin();
  528. i != names.end(); ++i)
  529. {
  530. this->FollowName(*i);
  531. }
  532. }
  533. //----------------------------------------------------------------------------
  534. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  535. {
  536. // Dependencies on targets (utilities) are supposed to be named by
  537. // just the target name. However for compatibility we support
  538. // naming the output file generated by the target (assuming there is
  539. // no output-name property which old code would not have set). In
  540. // that case the target name will be the file basename of the
  541. // dependency.
  542. std::string util = cmSystemTools::GetFilenameName(dep);
  543. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  544. {
  545. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  546. }
  547. // Check for a target with this name.
  548. if(cmTarget* t = this->Makefile->FindTargetToUse(util))
  549. {
  550. // If we find the target and the dep was given as a full path,
  551. // then make sure it was not a full path to something else, and
  552. // the fact that the name matched a target was just a coincidence.
  553. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  554. {
  555. if(t->GetType() >= cmTarget::EXECUTABLE &&
  556. t->GetType() <= cmTarget::MODULE_LIBRARY)
  557. {
  558. // This is really only for compatibility so we do not need to
  559. // worry about configuration names and output names.
  560. std::string tLocation = t->GetLocation(0);
  561. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  562. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  563. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  564. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  565. if(depLocation == tLocation)
  566. {
  567. this->Target->AddUtility(util.c_str());
  568. return true;
  569. }
  570. }
  571. }
  572. else
  573. {
  574. // The original name of the dependency was not a full path. It
  575. // must name a target, so add the target-level dependency.
  576. this->Target->AddUtility(util.c_str());
  577. return true;
  578. }
  579. }
  580. // The dependency does not name a target built in this project.
  581. return false;
  582. }
  583. //----------------------------------------------------------------------------
  584. void
  585. cmTargetTraceDependencies
  586. ::CheckCustomCommand(cmCustomCommand const& cc)
  587. {
  588. // Transform command names that reference targets built in this
  589. // project to corresponding target-level dependencies.
  590. cmGeneratorExpression ge(cc.GetBacktrace());
  591. // Add target-level dependencies referenced by generator expressions.
  592. std::set<cmTarget*> targets;
  593. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  594. cit != cc.GetCommandLines().end(); ++cit)
  595. {
  596. std::string const& command = *cit->begin();
  597. // Check for a target with this name.
  598. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  599. {
  600. if(t->GetType() == cmTarget::EXECUTABLE)
  601. {
  602. // The command refers to an executable target built in
  603. // this project. Add the target-level dependency to make
  604. // sure the executable is up to date before this custom
  605. // command possibly runs.
  606. this->Target->AddUtility(command.c_str());
  607. }
  608. }
  609. // Check for target references in generator expressions.
  610. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  611. cli != cit->end(); ++cli)
  612. {
  613. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  614. = ge.Parse(*cli);
  615. cge->Evaluate(this->Makefile, 0, true);
  616. std::set<cmTarget*> geTargets = cge->GetTargets();
  617. for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
  618. it != geTargets.end(); ++it)
  619. {
  620. targets.insert(*it);
  621. }
  622. }
  623. }
  624. for(std::set<cmTarget*>::iterator ti = targets.begin();
  625. ti != targets.end(); ++ti)
  626. {
  627. this->Target->AddUtility((*ti)->GetName());
  628. }
  629. // Queue the custom command dependencies.
  630. std::vector<std::string> const& depends = cc.GetDepends();
  631. for(std::vector<std::string>::const_iterator di = depends.begin();
  632. di != depends.end(); ++di)
  633. {
  634. std::string const& dep = *di;
  635. if(!this->IsUtility(dep))
  636. {
  637. // The dependency does not name a target and may be a file we
  638. // know how to generate. Queue it.
  639. this->FollowName(dep);
  640. }
  641. }
  642. }
  643. //----------------------------------------------------------------------------
  644. void
  645. cmTargetTraceDependencies
  646. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  647. {
  648. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  649. cli != commands.end(); ++cli)
  650. {
  651. this->CheckCustomCommand(*cli);
  652. }
  653. }
  654. //----------------------------------------------------------------------------
  655. void cmGeneratorTarget::TraceDependencies()
  656. {
  657. // CMake-generated targets have no dependencies to trace. Normally tracing
  658. // would find nothing anyway, but when building CMake itself the "install"
  659. // target command ends up referencing the "cmake" target but we do not
  660. // really want the dependency because "install" depend on "all" anyway.
  661. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  662. {
  663. return;
  664. }
  665. // Use a helper object to trace the dependencies.
  666. cmTargetTraceDependencies tracer(this);
  667. tracer.Trace();
  668. }
  669. //----------------------------------------------------------------------------
  670. void cmGeneratorTarget::GetAppleArchs(const char* config,
  671. std::vector<std::string>& archVec) const
  672. {
  673. const char* archs = 0;
  674. if(config && *config)
  675. {
  676. std::string defVarName = "OSX_ARCHITECTURES_";
  677. defVarName += cmSystemTools::UpperCase(config);
  678. archs = this->Target->GetProperty(defVarName.c_str());
  679. }
  680. if(!archs)
  681. {
  682. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  683. }
  684. if(archs)
  685. {
  686. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  687. }
  688. }
  689. //----------------------------------------------------------------------------
  690. const char* cmGeneratorTarget::GetCreateRuleVariable() const
  691. {
  692. switch(this->GetType())
  693. {
  694. case cmTarget::STATIC_LIBRARY:
  695. return "_CREATE_STATIC_LIBRARY";
  696. case cmTarget::SHARED_LIBRARY:
  697. return "_CREATE_SHARED_LIBRARY";
  698. case cmTarget::MODULE_LIBRARY:
  699. return "_CREATE_SHARED_MODULE";
  700. case cmTarget::EXECUTABLE:
  701. return "_LINK_EXECUTABLE";
  702. default:
  703. break;
  704. }
  705. return "";
  706. }
  707. //----------------------------------------------------------------------------
  708. std::vector<std::string>
  709. cmGeneratorTarget::GetIncludeDirectories(const char *config) const
  710. {
  711. return this->Target->GetIncludeDirectories(config);
  712. }
  713. //----------------------------------------------------------------------------
  714. void cmGeneratorTarget::GenerateTargetManifest(const char* config) const
  715. {
  716. if (this->Target->IsImported())
  717. {
  718. return;
  719. }
  720. cmMakefile* mf = this->Target->GetMakefile();
  721. cmLocalGenerator* lg = mf->GetLocalGenerator();
  722. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  723. // Get the names.
  724. std::string name;
  725. std::string soName;
  726. std::string realName;
  727. std::string impName;
  728. std::string pdbName;
  729. if(this->GetType() == cmTarget::EXECUTABLE)
  730. {
  731. this->Target->GetExecutableNames(name, realName, impName, pdbName,
  732. config);
  733. }
  734. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  735. this->GetType() == cmTarget::SHARED_LIBRARY ||
  736. this->GetType() == cmTarget::MODULE_LIBRARY)
  737. {
  738. this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
  739. config);
  740. }
  741. else
  742. {
  743. return;
  744. }
  745. // Get the directory.
  746. std::string dir = this->Target->GetDirectory(config, false);
  747. // Add each name.
  748. std::string f;
  749. if(!name.empty())
  750. {
  751. f = dir;
  752. f += "/";
  753. f += name;
  754. gg->AddToManifest(config? config:"", f);
  755. }
  756. if(!soName.empty())
  757. {
  758. f = dir;
  759. f += "/";
  760. f += soName;
  761. gg->AddToManifest(config? config:"", f);
  762. }
  763. if(!realName.empty())
  764. {
  765. f = dir;
  766. f += "/";
  767. f += realName;
  768. gg->AddToManifest(config? config:"", f);
  769. }
  770. if(!pdbName.empty())
  771. {
  772. f = dir;
  773. f += "/";
  774. f += pdbName;
  775. gg->AddToManifest(config? config:"", f);
  776. }
  777. if(!impName.empty())
  778. {
  779. f = this->Target->GetDirectory(config, true);
  780. f += "/";
  781. f += impName;
  782. gg->AddToManifest(config? config:"", f);
  783. }
  784. }
  785. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  786. cmTarget const* t2) const
  787. {
  788. int nameResult = strcmp(t1->GetName(), t2->GetName());
  789. if (nameResult == 0)
  790. {
  791. return strcmp(t1->GetMakefile()->GetStartOutputDirectory(),
  792. t2->GetMakefile()->GetStartOutputDirectory()) < 0;
  793. }
  794. return nameResult < 0;
  795. }