cmVTKWrapJavaCommand.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 "cmVTKWrapJavaCommand.h"
  14. // cmVTKWrapJavaCommand
  15. bool cmVTKWrapJavaCommand::InitialPass(std::vector<std::string> const& argsIn)
  16. {
  17. if(argsIn.size() < 3 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::vector<std::string> args;
  23. m_Makefile->ExpandSourceListArguments(argsIn, args, 2);
  24. // Now check and see if the value has been stored in the cache
  25. // already, if so use that value and don't look for the program
  26. if(!m_Makefile->IsOn("VTK_WRAP_JAVA"))
  27. {
  28. return true;
  29. }
  30. // what is the current source dir
  31. std::string cdir = m_Makefile->GetCurrentDirectory();
  32. // keep the library name
  33. m_LibraryName = args[0];
  34. m_SourceList = args[1];
  35. std::string sourceListValue;
  36. // was the list already populated
  37. const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
  38. if (def)
  39. {
  40. sourceListValue = def;
  41. }
  42. // Prepare java dependency file
  43. std::string resultDirectory = "${VTK_JAVA_HOME}";
  44. std::string res = m_Makefile->GetCurrentOutputDirectory();
  45. std::string depFileName = res + "/JavaDependencies.cmake";
  46. ofstream depFile(depFileName.c_str());
  47. depFile << "# This file is automatically generated by CMake VTK_WRAP_JAVA"
  48. << std::endl << std::endl;
  49. depFile << "SET(VTK_JAVA_DEPENDENCIES ${VTK_JAVA_DEPENDENCIES}" << std::endl;
  50. // get the list of classes for this library
  51. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  52. j != args.end(); ++j)
  53. {
  54. cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
  55. // if we should wrap the class
  56. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  57. {
  58. cmSourceFile file;
  59. if (curr)
  60. {
  61. file.SetProperty("ABSTRACT",curr->GetProperty("ABSTRACT"));
  62. }
  63. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  64. std::string newName = srcName + "Java";
  65. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  66. "cxx",false);
  67. std::string hname = cdir + "/" + srcName + ".h";
  68. m_WrapHeaders.push_back(hname);
  69. // add starting depends
  70. file.GetDepends().push_back(hname);
  71. m_WrapClasses.push_back(file);
  72. m_OriginalNames.push_back(srcName);
  73. if (sourceListValue.size() > 0)
  74. {
  75. sourceListValue += ";";
  76. }
  77. sourceListValue += newName + ".cxx";
  78. // Write file to java dependency file
  79. std::string jafaFile = resultDirectory + "/" + srcName + ".java";
  80. depFile << " " << jafaFile << std::endl;
  81. }
  82. }
  83. // Finalize java dependency file
  84. depFile << ")" << std::endl;
  85. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  86. return true;
  87. }
  88. void cmVTKWrapJavaCommand::FinalPass()
  89. {
  90. // first we add the rules for all the .h to Java.cxx files
  91. size_t lastClass = m_WrapClasses.size();
  92. std::vector<std::string> depends;
  93. std::vector<std::string> depends2;
  94. std::vector<std::string> alldepends;
  95. std::vector<std::string> empty;
  96. std::string wjava = "${VTK_WRAP_JAVA_EXE}";
  97. std::string pjava = "${VTK_PARSE_JAVA_EXE}";
  98. std::string hints = "${VTK_WRAP_HINTS}";
  99. std::string resultDirectory = "${VTK_JAVA_HOME}";
  100. m_Makefile->ExpandVariablesInString(hints);
  101. // wrap all the .h files
  102. depends.push_back(wjava);
  103. depends2.push_back(pjava);
  104. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  105. {
  106. depends.push_back(hints);
  107. depends2.push_back(hints);
  108. }
  109. for(size_t classNum = 0; classNum < lastClass; classNum++)
  110. {
  111. m_Makefile->AddSource(m_WrapClasses[classNum]);
  112. // wrap java
  113. std::string res = m_Makefile->GetCurrentOutputDirectory();
  114. res += "/";
  115. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  116. std::string res2 = resultDirectory + "/" +
  117. m_OriginalNames[classNum] + ".java";
  118. std::vector<std::string> args;
  119. args.push_back(m_WrapHeaders[classNum]);
  120. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  121. {
  122. args.push_back(hints);
  123. }
  124. args.push_back((m_WrapClasses[classNum].GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  125. args.push_back(res);
  126. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  127. wjava.c_str(), args, depends,
  128. res.c_str(), m_LibraryName.c_str());
  129. std::vector<std::string> args2;
  130. args2.push_back(m_WrapHeaders[classNum]);
  131. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  132. {
  133. args2.push_back(hints);
  134. }
  135. args2.push_back((m_WrapClasses[classNum].GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  136. args2.push_back(res2);
  137. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  138. pjava.c_str(), args2, depends2,
  139. res2.c_str(), m_LibraryName.c_str());
  140. alldepends.push_back(res2);
  141. }
  142. m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
  143. "",
  144. "",
  145. true,
  146. alldepends,
  147. empty);
  148. }