UseJavaClassFilelist.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # This script create a list of compiled Java class files to be added to a
  3. # jar file. This avoids including cmake files which get created in the
  4. # binary directory.
  5. #
  6. #=============================================================================
  7. # Copyright 2010-2011 Andreas schneider <[email protected]>
  8. #
  9. # Distributed under the OSI-approved BSD License (the "License");
  10. # see accompanying file Copyright.txt for details.
  11. #
  12. # This software is distributed WITHOUT ANY WARRANTY; without even the
  13. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. # See the License for more information.
  15. #=============================================================================
  16. # (To distribute this file outside of CMake, substitute the full
  17. # License text for the above reference.)
  18. if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
  19. if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
  20. set(_JAVA_GLOBBED_FILES)
  21. if (CMAKE_JAR_CLASSES_PREFIX)
  22. foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
  23. message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}")
  24. file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class")
  25. if (_JAVA_GLOBBED_TMP_FILES)
  26. list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES})
  27. endif (_JAVA_GLOBBED_TMP_FILES)
  28. endforeach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
  29. else()
  30. file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class")
  31. endif (CMAKE_JAR_CLASSES_PREFIX)
  32. set(_JAVA_CLASS_FILES)
  33. # file(GLOB_RECURSE foo RELATIVE) is broken so we need this.
  34. foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
  35. file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE})
  36. set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n)
  37. endforeach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
  38. # write to file
  39. file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES})
  40. else (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
  41. message(SEND_ERROR "FATAL: Java class output path doesn't exist")
  42. endif (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
  43. else (CMAKE_JAVA_CLASS_OUTPUT_PATH)
  44. message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH")
  45. endif (CMAKE_JAVA_CLASS_OUTPUT_PATH)