cmExportLibraryDependencies.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "cmExportLibraryDependencies.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmake.h"
  18. #include <memory> // auto_ptr
  19. // cmExecutableCommand
  20. bool cmExportLibraryDependenciesCommand::InitialPass(std::vector<std::string> const& args)
  21. {
  22. // First argument is the name of the test
  23. // Second argument is the name of the executable to run (a target or external
  24. // program)
  25. // Remaining arguments are the arguments to pass to the executable
  26. if(args.size() < 1 )
  27. {
  28. this->SetError("called with incorrect number of arguments");
  29. return false;
  30. }
  31. // store the arguments for the final pass
  32. // also expand any CMake variables
  33. m_Args = args;
  34. return true;
  35. }
  36. void cmExportLibraryDependenciesCommand::FinalPass()
  37. {
  38. // don't do anything if local mode
  39. if(m_Makefile->GetLocal())
  40. {
  41. return;
  42. }
  43. // Create a full path filename for output
  44. std::string fname = m_Args[0];
  45. bool append = false;
  46. if(m_Args.size() > 1)
  47. {
  48. if(m_Args[1] == "APPEND")
  49. {
  50. append = true;
  51. }
  52. }
  53. // Use copy-if-different if not appending.
  54. std::ostream* foutPtr;
  55. std::auto_ptr<cmGeneratedFileStream> foutNew;
  56. if(append)
  57. {
  58. foutPtr = new std::ofstream(fname.c_str(), std::ios::app);
  59. }
  60. else
  61. {
  62. std::auto_ptr<cmGeneratedFileStream> ap(
  63. new cmGeneratedFileStream(fname.c_str()));
  64. foutNew = ap;
  65. foutPtr = &foutNew->GetStream();
  66. }
  67. std::ostream& fout = *foutPtr;
  68. if (!fout)
  69. {
  70. cmSystemTools::Error("Error Writing ", fname.c_str());
  71. cmSystemTools::ReportLastSystemError("");
  72. return;
  73. }
  74. cmake* cm = m_Makefile->GetCMakeInstance();
  75. cmGlobalGenerator* global = cm->GetGlobalGenerator();
  76. std::vector<cmLocalGenerator *> locals;
  77. global->GetLocalGenerators(locals);
  78. std::string libDepName;
  79. for(std::vector<cmLocalGenerator *>::iterator i = locals.begin();
  80. i != locals.end(); ++i)
  81. {
  82. cmLocalGenerator* gen = *i;
  83. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  84. std::vector<std::string> depends;
  85. const char *defType;
  86. for(cmTargets::const_iterator l = tgts.begin();
  87. l != tgts.end(); ++l)
  88. {
  89. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  90. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  91. {
  92. libDepName = l->first;
  93. libDepName += "_LIB_DEPENDS";
  94. const char* def = m_Makefile->GetDefinition(libDepName.c_str());
  95. if(def)
  96. {
  97. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  98. // now for each dependency, check for link type
  99. cmSystemTools::ExpandListArgument(def, depends);
  100. for(std::vector<std::string>::const_iterator d = depends.begin();
  101. d != depends.end(); ++d)
  102. {
  103. libDepName = *d;
  104. libDepName += "_LINK_TYPE";
  105. defType = m_Makefile->GetDefinition(libDepName.c_str());
  106. libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
  107. if(defType)
  108. {
  109. fout << "SET(" << libDepName << " \"" << defType << "\")\n";
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. return;
  117. }