cmExportLibraryDependencies.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <cmsys/auto_ptr.hxx>
  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. this->Args = args;
  34. return true;
  35. }
  36. void cmExportLibraryDependenciesCommand::FinalPass()
  37. {
  38. // Create a full path filename for output
  39. std::string fname = this->Args[0];
  40. bool append = false;
  41. if(this->Args.size() > 1)
  42. {
  43. if(this->Args[1] == "APPEND")
  44. {
  45. append = true;
  46. }
  47. }
  48. // Use copy-if-different if not appending.
  49. cmsys::auto_ptr<std::ofstream> foutPtr;
  50. if(append)
  51. {
  52. cmsys::auto_ptr<std::ofstream> ap(
  53. new std::ofstream(fname.c_str(), std::ios::app));
  54. foutPtr = ap;
  55. }
  56. else
  57. {
  58. cmsys::auto_ptr<cmGeneratedFileStream> ap(
  59. new cmGeneratedFileStream(fname.c_str(), true));
  60. ap->SetCopyIfDifferent(true);
  61. foutPtr = ap;
  62. }
  63. std::ostream& fout = *foutPtr.get();
  64. if (!fout)
  65. {
  66. cmSystemTools::Error("Error Writing ", fname.c_str());
  67. cmSystemTools::ReportLastSystemError("");
  68. return;
  69. }
  70. cmake* cm = this->Makefile->GetCMakeInstance();
  71. cmGlobalGenerator* global = cm->GetGlobalGenerator();
  72. std::vector<cmLocalGenerator *> locals;
  73. global->GetLocalGenerators(locals);
  74. std::string libDepName;
  75. for(std::vector<cmLocalGenerator *>::iterator i = locals.begin();
  76. i != locals.end(); ++i)
  77. {
  78. cmLocalGenerator* gen = *i;
  79. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  80. std::vector<std::string> depends;
  81. const char *defType;
  82. for(cmTargets::iterator l = tgts.begin();
  83. l != tgts.end(); ++l)
  84. {
  85. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  86. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  87. {
  88. libDepName = l->first;
  89. libDepName += "_LIB_DEPENDS";
  90. const char* def = this->Makefile->GetDefinition(libDepName.c_str());
  91. if(def)
  92. {
  93. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  94. // now for each dependency, check for link type
  95. cmSystemTools::ExpandListArgument(def, depends);
  96. for(std::vector<std::string>::const_iterator d = depends.begin();
  97. d != depends.end(); ++d)
  98. {
  99. libDepName = *d;
  100. libDepName += "_LINK_TYPE";
  101. defType = this->Makefile->GetDefinition(libDepName.c_str());
  102. libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
  103. if(defType)
  104. {
  105. fout << "SET(" << libDepName << " \"" << defType << "\")\n";
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. return;
  113. }