UseJavaClassFilelist.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. UseJavaClassFilelist
  5. --------------------
  6. This script create a list of compiled Java class files to be added to
  7. a jar file. This avoids including cmake files which get created in
  8. the binary directory.
  9. #]=======================================================================]
  10. if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
  11. if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
  12. set(_JAVA_GLOBBED_FILES)
  13. if (CMAKE_JAR_CLASSES_PREFIX)
  14. foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
  15. message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}")
  16. file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class")
  17. if (_JAVA_GLOBBED_TMP_FILES)
  18. list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES})
  19. endif ()
  20. endforeach()
  21. else()
  22. file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class")
  23. endif ()
  24. set(_JAVA_CLASS_FILES)
  25. # file(GLOB_RECURSE foo RELATIVE) is broken so we need this.
  26. foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
  27. file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE})
  28. set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n)
  29. endforeach()
  30. # write to file
  31. file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES})
  32. else ()
  33. message(SEND_ERROR "FATAL: Java class output path doesn't exist")
  34. endif ()
  35. else ()
  36. message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH")
  37. endif ()