You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.5 KiB

22 years ago
22 years ago
22 years ago
  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. bool cmExportLibraryDependenciesCommand
  20. ::InitialPass(std::vector<std::string> const& args)
  21. {
  22. if(args.size() < 1 )
  23. {
  24. this->SetError("called with incorrect number of arguments");
  25. return false;
  26. }
  27. // store the arguments for the final pass
  28. this->Filename = args[0];
  29. this->Append = false;
  30. if(args.size() > 1)
  31. {
  32. if(args[1] == "APPEND")
  33. {
  34. this->Append = true;
  35. }
  36. }
  37. return true;
  38. }
  39. void cmExportLibraryDependenciesCommand::FinalPass()
  40. {
  41. // export_library_dependencies() shouldn't modify anything
  42. // ensure this by calling a const method
  43. this->ConstFinalPass();
  44. }
  45. void cmExportLibraryDependenciesCommand::ConstFinalPass() const
  46. {
  47. // Use copy-if-different if not appending.
  48. cmsys::auto_ptr<std::ofstream> foutPtr;
  49. if(this->Append)
  50. {
  51. cmsys::auto_ptr<std::ofstream> ap(
  52. new std::ofstream(this->Filename.c_str(), std::ios::app));
  53. foutPtr = ap;
  54. }
  55. else
  56. {
  57. cmsys::auto_ptr<cmGeneratedFileStream> ap(
  58. new cmGeneratedFileStream(this->Filename.c_str(), true));
  59. ap->SetCopyIfDifferent(true);
  60. foutPtr = ap;
  61. }
  62. std::ostream& fout = *foutPtr.get();
  63. if (!fout)
  64. {
  65. cmSystemTools::Error("Error Writing ", this->Filename.c_str());
  66. cmSystemTools::ReportLastSystemError("");
  67. return;
  68. }
  69. const cmake* cm = this->Makefile->GetCMakeInstance();
  70. const cmGlobalGenerator* global = cm->GetGlobalGenerator();
  71. const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
  72. std::string libDepName;
  73. for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
  74. i != locals.end(); ++i)
  75. {
  76. const cmLocalGenerator* gen = *i;
  77. const cmTargets &tgts = gen->GetMakefile()->GetTargets();
  78. std::vector<std::string> depends;
  79. const char *defType;
  80. for(cmTargets::const_iterator l = tgts.begin();
  81. l != tgts.end(); ++l)
  82. {
  83. libDepName = l->first;
  84. libDepName += "_LIB_DEPENDS";
  85. const char* def = this->Makefile->GetDefinition(libDepName.c_str());
  86. if(def)
  87. {
  88. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  89. // now for each dependency, check for link type
  90. cmSystemTools::ExpandListArgument(def, depends);
  91. for(std::vector<std::string>::const_iterator d = depends.begin();
  92. d != depends.end(); ++d)
  93. {
  94. libDepName = *d;
  95. libDepName += "_LINK_TYPE";
  96. defType = this->Makefile->GetDefinition(libDepName.c_str());
  97. libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
  98. if(defType)
  99. {
  100. fout << "SET(" << libDepName << " \"" << defType << "\")\n";
  101. }
  102. }
  103. }
  104. }
  105. }
  106. return;
  107. }