cmTarget.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmTarget.h"
  14. #include "cmMakefile.h"
  15. #include "cmSourceFile.h"
  16. #include <map>
  17. #include <set>
  18. #include <queue>
  19. #include <stdlib.h> // required for atof
  20. void cmTarget::SetType(TargetType type)
  21. {
  22. // only add dependency information for library targets
  23. m_TargetType = type;
  24. if(m_TargetType >= STATIC_LIBRARY && m_TargetType <= MODULE_LIBRARY) {
  25. m_RecordDependencies = true;
  26. } else {
  27. m_RecordDependencies = false;
  28. }
  29. }
  30. void cmTarget::TraceVSDependencies(std::string projFile,
  31. cmMakefile *makefile)
  32. {
  33. // get the classes from the source lists then add them to the groups
  34. std::vector<cmSourceFile*> & classes = this->GetSourceFiles();
  35. // use a deck to keep track of processed source files
  36. std::queue<std::string> srcFilesToProcess;
  37. std::set<std::string> srcFilesQueued;
  38. std::string name;
  39. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  40. i != classes.end(); ++i)
  41. {
  42. std::string name = (*i)->GetSourceName();
  43. if ((*i)->GetSourceExtension() != "rule")
  44. {
  45. name += ".";
  46. name += (*i)->GetSourceExtension();
  47. }
  48. srcFilesToProcess.push(name);
  49. srcFilesQueued.insert(name);
  50. }
  51. // add in the project file itself
  52. srcFilesToProcess.push(projFile);
  53. srcFilesQueued.insert(projFile);
  54. // add in the library depends for cusotm targets
  55. if (this->GetType() == cmTarget::UTILITY)
  56. {
  57. for (std::vector<cmCustomCommand>::iterator ic =
  58. this->GetPostBuildCommands().begin();
  59. ic != this->GetPostBuildCommands().end(); ++ic)
  60. {
  61. cmCustomCommand &c = *ic;
  62. for (std::vector<std::string>::iterator i = c.GetDepends().begin();
  63. i != c.GetDepends().end(); ++i)
  64. {
  65. srcFilesToProcess.push(*i);
  66. srcFilesQueued.insert(name);
  67. }
  68. }
  69. }
  70. while (!srcFilesToProcess.empty())
  71. {
  72. // is this source the output of a custom command
  73. cmSourceFile* outsf =
  74. makefile->GetSourceFileWithOutput(srcFilesToProcess.front().c_str());
  75. if (outsf)
  76. {
  77. // is it not already in the target?
  78. if (std::find(classes.begin(),classes.end(),outsf) == classes.end())
  79. {
  80. // then add the source to this target and add it to the queue
  81. classes.push_back(outsf);
  82. std::string name = outsf->GetSourceName();
  83. if (outsf->GetSourceExtension() != "rule")
  84. {
  85. name += ".";
  86. name += outsf->GetSourceExtension();
  87. }
  88. std::string temp =
  89. cmSystemTools::GetFilenamePath(outsf->GetFullPath());
  90. temp += "/";
  91. temp += name;
  92. // if it hasn't been processed
  93. if (srcFilesQueued.find(temp) == srcFilesQueued.end())
  94. {
  95. srcFilesToProcess.push(temp);
  96. srcFilesQueued.insert(temp);
  97. }
  98. }
  99. // add its dependencies to the list to check
  100. unsigned int i;
  101. for (i = 0; i < outsf->GetCustomCommand()->GetDepends().size(); ++i)
  102. {
  103. std::string dep = cmSystemTools::GetFilenameName(
  104. outsf->GetCustomCommand()->GetDepends()[i]);
  105. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  106. {
  107. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  108. }
  109. // watch for target dependencies,
  110. std::string libPath = dep + "_CMAKE_PATH";
  111. const char* cacheValue = makefile->GetDefinition(libPath.c_str());
  112. if (cacheValue)
  113. {
  114. // add the depend as a utility on the target
  115. this->AddUtility(dep.c_str());
  116. }
  117. else
  118. {
  119. if (srcFilesQueued.find(outsf->GetCustomCommand()->GetDepends()[i])
  120. == srcFilesQueued.end())
  121. {
  122. srcFilesToProcess.push(outsf->GetCustomCommand()->GetDepends()[i]);
  123. srcFilesQueued.insert(outsf->GetCustomCommand()->GetDepends()[i]);
  124. }
  125. }
  126. }
  127. }
  128. // finished with this SF move to the next
  129. srcFilesToProcess.pop();
  130. }
  131. }
  132. void cmTarget::GenerateSourceFilesFromSourceLists( cmMakefile &mf)
  133. {
  134. // this is only done for non install targets
  135. if ((this->m_TargetType == cmTarget::INSTALL_FILES)
  136. || (this->m_TargetType == cmTarget::INSTALL_PROGRAMS))
  137. {
  138. return;
  139. }
  140. // for each src lists add the classes
  141. for (std::vector<std::string>::const_iterator s = m_SourceLists.begin();
  142. s != m_SourceLists.end(); ++s)
  143. {
  144. int done = 0;
  145. // replace any variables
  146. std::string temps = *s;
  147. mf.ExpandVariablesInString(temps);
  148. // Next if one wasn't found then assume it is a single class
  149. // check to see if it is an existing source file
  150. if (!done && mf.GetSource(temps.c_str()))
  151. {
  152. m_SourceFiles.push_back(mf.GetSource(temps.c_str()));
  153. done = 1;
  154. }
  155. // if it wasn't a source file listed with the makefile
  156. // see if it is a variable. This is for old CMake 1.2 compatability
  157. // where a source list would be passed into here, by making it
  158. // a vector we need to possibly lookup the variable to maintain
  159. // CMake 1.2 compatability.
  160. const char* versionValue
  161. = mf.GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  162. if (!done)
  163. {
  164. if (!versionValue || atof(versionValue) <= 1.2)
  165. {
  166. const char* varValue =
  167. mf.GetDefinition(temps.c_str());
  168. // if the definition exists
  169. if (varValue)
  170. {
  171. std::vector<std::string> args;
  172. cmSystemTools::ExpandListArgument(varValue, args);
  173. unsigned int i;
  174. for (i = 0; i < args.size(); ++i)
  175. {
  176. if (mf.GetSource(args[i].c_str()))
  177. {
  178. m_SourceFiles.push_back(mf.GetSource(args[i].c_str()));
  179. }
  180. else
  181. {
  182. cmSourceFile file;
  183. file.SetProperty("ABSTRACT","0");
  184. file.SetName(args[i].c_str(), mf.GetCurrentDirectory(),
  185. mf.GetSourceExtensions(),
  186. mf.GetHeaderExtensions());
  187. m_SourceFiles.push_back(mf.AddSource(file));
  188. }
  189. }
  190. done = 1;
  191. }
  192. }
  193. }
  194. // if we still are not done, try to create the SourceFile structure
  195. if (!done)
  196. {
  197. cmSourceFile file;
  198. file.SetProperty("ABSTRACT","0");
  199. file.SetName(temps.c_str(), mf.GetCurrentDirectory(),
  200. mf.GetSourceExtensions(),
  201. mf.GetHeaderExtensions());
  202. m_SourceFiles.push_back(mf.AddSource(file));
  203. }
  204. }
  205. // expand any link library variables whle we are at it
  206. LinkLibraries::iterator p = m_LinkLibraries.begin();
  207. for (;p != m_LinkLibraries.end(); ++p)
  208. {
  209. mf.ExpandVariablesInString(p->first);
  210. }
  211. }
  212. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  213. const char *selfname,
  214. const LinkLibraries& libs )
  215. {
  216. // Only add on libraries we haven't added on before.
  217. // Assumption: the global link libraries could only grow, never shrink
  218. LinkLibraries::const_iterator i = libs.begin();
  219. i += m_PrevLinkedLibraries.size();
  220. for( ; i != libs.end(); ++i )
  221. {
  222. // We call this so that the dependencies get written to the cache
  223. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  224. }
  225. m_PrevLinkedLibraries = libs;
  226. }
  227. void cmTarget::AddLinkDirectory(const char* d)
  228. {
  229. // Make sure we don't add unnecessary search directories.
  230. if( std::find( m_LinkDirectories.begin(), m_LinkDirectories.end(), d )
  231. == m_LinkDirectories.end() )
  232. m_LinkDirectories.push_back( d );
  233. }
  234. void cmTarget::ClearDependencyInformation( cmMakefile& mf, const char* target )
  235. {
  236. // Clear the dependencies. The cache variable must exist iff we are
  237. // recording dependency information for this target.
  238. std::string depname = target;
  239. depname += "_LIB_DEPENDS";
  240. if (m_RecordDependencies)
  241. {
  242. mf.AddCacheDefinition(depname.c_str(), "",
  243. "Dependencies for target", cmCacheManager::STATIC);
  244. }
  245. else
  246. {
  247. if (mf.GetDefinition( depname.c_str() ))
  248. {
  249. std::string message = "Target ";
  250. message += target;
  251. message += " has dependency information when it shouldn't.\n";
  252. message += "Your cache is probably stale. Please remove the entry\n ";
  253. message += depname;
  254. message += "\nfrom the cache.";
  255. cmSystemTools::Error( message.c_str() );
  256. }
  257. }
  258. }
  259. void cmTarget::AddLinkLibrary(const std::string& lib,
  260. LinkLibraryType llt)
  261. {
  262. m_LinkLibraries.push_back( std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt) );
  263. }
  264. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  265. const char *target, const char* lib,
  266. LinkLibraryType llt)
  267. {
  268. // Never add a self dependency, even if the user asks for it.
  269. if(strcmp( target, lib ) == 0)
  270. {
  271. return;
  272. }
  273. m_LinkLibraries.push_back( std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt) );
  274. if(llt != cmTarget::GENERAL)
  275. {
  276. std::string linkTypeName = lib;
  277. linkTypeName += "_LINK_TYPE";
  278. switch(llt)
  279. {
  280. case cmTarget::DEBUG:
  281. mf.AddCacheDefinition(linkTypeName.c_str(),
  282. "debug", "Library is used for debug links only",
  283. cmCacheManager::STATIC);
  284. break;
  285. case cmTarget::OPTIMIZED:
  286. mf.AddCacheDefinition(linkTypeName.c_str(),
  287. "optimized", "Library is used for debug links only",
  288. cmCacheManager::STATIC);
  289. break;
  290. case cmTarget::GENERAL: break;
  291. }
  292. }
  293. // Add the explicit dependency information for this target. This is
  294. // simply a set of libraries separated by ";". There should always
  295. // be a trailing ";". These library names are not canonical, in that
  296. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  297. // We shouldn't remove duplicates here because external libraries
  298. // may be purposefully duplicated to handle recursive dependencies,
  299. // and we removing one instance will break the link line. Duplicates
  300. // will be appropriately eliminated at emit time.
  301. if(m_RecordDependencies)
  302. {
  303. std::string targetEntry = target;
  304. targetEntry += "_LIB_DEPENDS";
  305. std::string dependencies;
  306. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  307. if( old_val )
  308. {
  309. dependencies += old_val;
  310. }
  311. dependencies += lib;
  312. dependencies += ";";
  313. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  314. "Dependencies for the target",
  315. cmCacheManager::STATIC );
  316. }
  317. }
  318. bool cmTarget::HasCxx() const
  319. {
  320. for(std::vector<cmSourceFile*>::const_iterator i = m_SourceFiles.begin();
  321. i != m_SourceFiles.end(); ++i)
  322. {
  323. if(cmSystemTools::GetFileFormat((*i)->GetSourceExtension().c_str())
  324. == cmSystemTools::CXX_FILE_FORMAT)
  325. {
  326. return true;
  327. }
  328. }
  329. return false;
  330. }
  331. void
  332. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  333. {
  334. // There are two key parts of the dependency analysis: (1)
  335. // determining the libraries in the link line, and (2) constructing
  336. // the dependency graph for those libraries.
  337. //
  338. // The latter is done using the cache entries that record the
  339. // dependencies of each library.
  340. //
  341. // The former is a more thorny issue, since it is not clear how to
  342. // determine if two libraries listed on the link line refer to the a
  343. // single library or not. For example, consider the link "libraries"
  344. // /usr/lib/libtiff.so -ltiff
  345. // Is this one library or two? The solution implemented here is the
  346. // simplest (and probably the only practical) one: two libraries are
  347. // the same if their "link strings" are identical. Thus, the two
  348. // libraries above are considered distinct. This also means that for
  349. // dependency analysis to be effective, the CMake user must specify
  350. // libraries build by his project without using any linker flags or
  351. // file extensions. That is,
  352. // LINK_LIBRARIES( One Two )
  353. // instead of
  354. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  355. // The former is probably what most users would do, but it never
  356. // hurts to document the assumptions. :-) Therefore, in the analysis
  357. // code, the "canonical name" of a library is simply its name as
  358. // given to a LINK_LIBRARIES command.
  359. //
  360. // Also, we will leave the original link line intact; we will just add any
  361. // dependencies that were missing.
  362. //
  363. // There is a problem with recursive external libraries
  364. // (i.e. libraries with no dependency information that are
  365. // recursively dependent). We must make sure that the we emit one of
  366. // the libraries twice to satisfy the recursion, but we shouldn't
  367. // emit it more times than necessary. In particular, we must make
  368. // sure that handling this improbable case doesn't cost us when
  369. // dealing with the common case of non-recursive libraries. The
  370. // solution is to assume that the recursion is satisfied at one node
  371. // of the dependency tree. To illustrate, assume libA and libB are
  372. // extrenal and mutually dependent. Suppose libX depends on
  373. // libA, and libY on libA and libX. Then
  374. // TARGET_LINK_LIBRARIES( Y X A B A )
  375. // TARGET_LINK_LIBRARIES( X A B A )
  376. // TARGET_LINK_LIBRARIES( Exec Y )
  377. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  378. // specify the dependencies, since the mutual dependency of A and B
  379. // is resolved *every time libA is specified*.
  380. //
  381. // Something like
  382. // TARGET_LINK_LIBRARIES( Y X A B A )
  383. // TARGET_LINK_LIBRARIES( X A B )
  384. // TARGET_LINK_LIBRARIES( Exec Y )
  385. // would result in "-lY -lX -lA -lB", and the mutual dependency
  386. // information is lost. This is because in some case (Y), the mutual
  387. // dependency of A and B is listed, while in another other case (X),
  388. // it is not. Depending on which line actually emits A, the mutual
  389. // dependency may or may not be on the final link line. We can't
  390. // handle this pathalogical case cleanly without emitting extra
  391. // libraries for the normal cases. Besides, the dependency
  392. // information for X is wrong anyway: if we build an executable
  393. // depending on X alone, we would not have the mutual dependency on
  394. // A and B resolved.
  395. //
  396. // IMPROVEMENTS:
  397. // -- The current algorithm will not always pick the "optimal" link line
  398. // when recursive dependencies are present. It will instead break the
  399. // cycles at an aribtrary point. The majority of projects won't have
  400. // cyclic dependencies, so this is probably not a big deal. Note that
  401. // the link line is always correct, just not necessary optimal.
  402. typedef std::vector< std::string > LinkLine;
  403. // The dependency map.
  404. DependencyMap dep_map;
  405. // If LIBRARY_OUTPUT_PATH is not set, then we must add search paths
  406. // for all the new libraries added by the dependency analysis.
  407. const char* libOutPath = mf.GetDefinition("LIBRARY_OUTPUT_PATH");
  408. bool addLibDirs = (libOutPath==0 || strcmp(libOutPath,"")==0);
  409. // 1. Build the dependency graph
  410. //
  411. for(LinkLibraries::reverse_iterator lib = m_LinkLibraries.rbegin();
  412. lib != m_LinkLibraries.rend(); ++lib)
  413. {
  414. this->GatherDependencies( mf, lib->first, dep_map );
  415. }
  416. // 2. Remove any dependencies that are already satisfied in the original
  417. // link line.
  418. //
  419. for(LinkLibraries::iterator lib = m_LinkLibraries.begin();
  420. lib != m_LinkLibraries.end(); ++lib)
  421. {
  422. for( LinkLibraries::iterator lib2 = lib;
  423. lib2 != m_LinkLibraries.end(); ++lib2)
  424. {
  425. DeleteDependency( dep_map, lib->first, lib2->first );
  426. }
  427. }
  428. // 3. Create the new link line by simply emitting any dependencies that are
  429. // missing. Start from the back and keep adding.
  430. //
  431. std::set<cmStdString> done, visited;
  432. std::vector<std::string> newLinkLibraries;
  433. for(LinkLibraries::reverse_iterator lib = m_LinkLibraries.rbegin();
  434. lib != m_LinkLibraries.rend(); ++lib)
  435. {
  436. // skip zero size library entries, this may happen
  437. // if a variable expands to nothing.
  438. if (lib->first.size() != 0)
  439. {
  440. Emit( lib->first, dep_map, done, visited, newLinkLibraries );
  441. }
  442. }
  443. // 4. Add the new libraries to the link line.
  444. //
  445. for( std::vector<std::string>::reverse_iterator k = newLinkLibraries.rbegin();
  446. k != newLinkLibraries.rend(); ++k )
  447. {
  448. if( addLibDirs )
  449. {
  450. // who the hell knows what this is, I think that K contains the
  451. // name of a library but ... Ken
  452. // k contains the same stuff that are on the LINK_LIBRARIES
  453. // commands. Normally, they would just be library names. -- Amitha.
  454. std::string libPathStr = *k + "_CMAKE_PATH";
  455. const char* libpath = mf.GetDefinition( libPathStr.c_str() );
  456. if( libpath )
  457. {
  458. // Don't add a link directory that is already present.
  459. if(std::find(m_LinkDirectories.begin(),
  460. m_LinkDirectories.end(), libpath) == m_LinkDirectories.end())
  461. {
  462. m_LinkDirectories.push_back(libpath);
  463. }
  464. }
  465. }
  466. std::string linkType = *k;
  467. linkType += "_LINK_TYPE";
  468. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  469. const char* linkTypeString = mf.GetDefinition( linkType.c_str() );
  470. if(linkTypeString)
  471. {
  472. if(strcmp(linkTypeString, "debug") == 0)
  473. {
  474. llt = cmTarget::DEBUG;
  475. }
  476. if(strcmp(linkTypeString, "optimized") == 0)
  477. {
  478. llt = cmTarget::OPTIMIZED;
  479. }
  480. }
  481. m_LinkLibraries.push_back( std::make_pair(*k,llt) );
  482. }
  483. }
  484. void cmTarget::InsertDependency( DependencyMap& depMap,
  485. const cmStdString& lib,
  486. const cmStdString& dep ) const
  487. {
  488. depMap[lib].push_back(dep);
  489. }
  490. void cmTarget::DeleteDependency( DependencyMap& depMap,
  491. const cmStdString& lib,
  492. const cmStdString& dep ) const
  493. {
  494. // Make sure there is an entry in the map for lib. If so, delete all
  495. // dependencies to dep. There may be repeated entries because of
  496. // external libraries that are specified multiple times.
  497. DependencyMap::iterator map_itr = depMap.find( lib );
  498. if( map_itr != depMap.end() )
  499. {
  500. DependencyList& depList = map_itr->second;
  501. DependencyList::iterator itr;
  502. while( (itr = std::find(depList.begin(), depList.end(), dep)) != depList.end() )
  503. {
  504. depList.erase( itr );
  505. }
  506. }
  507. }
  508. void cmTarget::Emit( const std::string& lib,
  509. const DependencyMap& dep_map,
  510. std::set<cmStdString>& emitted,
  511. std::set<cmStdString>& visited,
  512. std::vector<std::string>& link_line ) const
  513. {
  514. // It's already been emitted
  515. if( emitted.find(lib) != emitted.end() )
  516. return;
  517. // Emit the dependencies only if this library node hasn't been
  518. // visited before. If it has, then we have a cycle. The recursion
  519. // that got us here should take care of everything.
  520. if( visited.insert(lib).second )
  521. {
  522. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  523. {
  524. const DependencyList& dep_on = dep_map.find( lib )->second;
  525. DependencyList::const_reverse_iterator i;
  526. // To cater for recursive external libraries, we must emit
  527. // duplicates on this link line *unless* they were emitted by
  528. // some other node, in which case we assume that the recursion
  529. // was resolved then. We making the simplifying assumption that
  530. // any duplicates on a single link line are on purpose, and must
  531. // be preserved.
  532. // This variable will keep track of the libraries that were
  533. // emitted directory from the current node, and not from a
  534. // recursive call. This way, if we come across a library that
  535. // has already been emitted, we repeat it iff it has been
  536. // emitted here.
  537. std::set<cmStdString> emitted_here;
  538. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  539. {
  540. if( emitted_here.find(*i) != emitted_here.end() )
  541. {
  542. // a repeat. Must emit.
  543. emitted.insert(*i);
  544. link_line.push_back( *i );
  545. }
  546. else
  547. {
  548. // Emit only if no-one else has
  549. if( emitted.find(*i) == emitted.end() )
  550. {
  551. // emit dependencies
  552. Emit( *i, dep_map, emitted, visited, link_line );
  553. // emit self
  554. emitted.insert(*i);
  555. emitted_here.insert(*i);
  556. link_line.push_back( *i );
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. void cmTarget::GatherDependencies( const cmMakefile& mf,
  564. const std::string& lib,
  565. DependencyMap& dep_map )
  566. {
  567. // If the library is already in the dependency map, then it has
  568. // already been fully processed.
  569. if( dep_map.find(lib) != dep_map.end() )
  570. return;
  571. const char* deps = mf.GetDefinition( (lib+"_LIB_DEPENDS").c_str() );
  572. if( deps && strcmp(deps,"") != 0 )
  573. {
  574. // Make sure this library is in the map, even if it has an empty
  575. // set of dependencies. This distinguishes the case of explicitly
  576. // no dependencies with that of unspecified dependencies.
  577. dep_map[lib];
  578. // Parse the dependency information, which is simply a set of
  579. // libraries separated by ";". There is always a trailing ";".
  580. std::string depline = deps;
  581. std::string::size_type start = 0;
  582. std::string::size_type end;
  583. end = depline.find( ";", start );
  584. while( end != std::string::npos )
  585. {
  586. std::string l = depline.substr( start, end-start );
  587. if( l.size() != 0 )
  588. {
  589. InsertDependency( dep_map, lib, l );
  590. GatherDependencies( mf, l, dep_map );
  591. }
  592. start = end+1; // skip the ;
  593. end = depline.find( ";", start );
  594. }
  595. DeleteDependency( dep_map, lib, lib); // cannot depend on itself
  596. }
  597. }
  598. void cmTarget::SetProperty(const char* prop, const char* value)
  599. {
  600. if (!prop)
  601. {
  602. return;
  603. }
  604. if (!value)
  605. {
  606. value = "NOTFOUND";
  607. }
  608. m_Properties[prop] = value;
  609. }
  610. const char *cmTarget::GetProperty(const char* prop) const
  611. {
  612. std::map<cmStdString,cmStdString>::const_iterator i =
  613. m_Properties.find(prop);
  614. if (i != m_Properties.end())
  615. {
  616. return i->second.c_str();
  617. }
  618. return 0;
  619. }
  620. bool cmTarget::GetPropertyAsBool(const char* prop) const
  621. {
  622. std::map<cmStdString,cmStdString>::const_iterator i =
  623. m_Properties.find(prop);
  624. if (i != m_Properties.end())
  625. {
  626. return cmSystemTools::IsOn(i->second.c_str());
  627. }
  628. return false;
  629. }