CMakeLists.txt 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. find_package(Java REQUIRED)
  2. find_package(JNI REQUIRED)
  3. # Allow the Java compiler flags to be set using an environment variable
  4. if(NOT DEFINED CMAKE_JAVA_COMPILE_FLAGS AND DEFINED ENV{JAVAFLAGS})
  5. set(CMAKE_JAVA_COMPILE_FLAGS $ENV{JAVAFLAGS})
  6. endif()
  7. include(UseJava)
  8. set(CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS} -J-Dfile.encoding=UTF8")
  9. message(STATUS "CMAKE_JAVA_COMPILE_FLAGS = ${CMAKE_JAVA_COMPILE_FLAGS}")
  10. string(REGEX REPLACE " " ";" CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS}")
  11. set(JAVAARGS "" CACHE STRING "Additional arguments to pass to java when running unit tests (example: -d32)")
  12. message(STATUS "JAVAARGS = ${JAVAARGS}")
  13. set(JAVA_SOURCES org/libjpegturbo/turbojpeg/TJ.java
  14. org/libjpegturbo/turbojpeg/TJCompressor.java
  15. org/libjpegturbo/turbojpeg/TJCustomFilter.java
  16. org/libjpegturbo/turbojpeg/TJDecompressor.java
  17. org/libjpegturbo/turbojpeg/TJException.java
  18. org/libjpegturbo/turbojpeg/TJScalingFactor.java
  19. org/libjpegturbo/turbojpeg/TJTransform.java
  20. org/libjpegturbo/turbojpeg/TJTransformer.java
  21. org/libjpegturbo/turbojpeg/YUVImage.java
  22. TJUnitTest.java
  23. TJExample.java
  24. TJBench.java)
  25. set(TURBOJPEG_DLL_NAME "turbojpeg")
  26. if(MINGW)
  27. set(TURBOJPEG_DLL_NAME "libturbojpeg")
  28. endif()
  29. if(WIN32)
  30. configure_file(org/libjpegturbo/turbojpeg/TJLoader-win.java.in
  31. ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
  32. else()
  33. configure_file(org/libjpegturbo/turbojpeg/TJLoader-unix.java.in
  34. ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
  35. endif()
  36. set(JAVA_SOURCES ${JAVA_SOURCES}
  37. ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
  38. if(MSYS)
  39. # UGLY HACK ALERT: If we don't do this, then UseJava.cmake will separate
  40. # class path members with a semicolon, which is interpreted as a command
  41. # separator by the MSYS shell.
  42. set(CMAKE_HOST_SYSTEM_NAME_BAK ${CMAKE_HOST_SYSTEM_NAME})
  43. set(CMAKE_HOST_SYSTEM_NAME "MSYS")
  44. endif()
  45. add_jar(turbojpeg-java ${JAVA_SOURCES} OUTPUT_NAME turbojpeg
  46. ENTRY_POINT TJExample)
  47. if(MSYS)
  48. set(CMAKE_HOST_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME_BAK})
  49. endif()
  50. add_custom_target(javadoc COMMAND
  51. javadoc -notimestamp -d ${CMAKE_CURRENT_SOURCE_DIR}/doc -sourcepath ${CMAKE_CURRENT_SOURCE_DIR} org.libjpegturbo.turbojpeg)
  52. set(JAVACLASSPATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/turbojpeg-java.dir)
  53. if(Java_VERSION_MAJOR GREATER 9)
  54. add_custom_target(javah
  55. COMMAND javac -h ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH}
  56. -d ${CMAKE_CURRENT_BINARY_DIR}/__unused
  57. ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJ.java
  58. ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJCompressor.java
  59. ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJDecompressor.java
  60. ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJTransformer.java)
  61. else()
  62. add_custom_target(javah
  63. COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJ
  64. COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJCompressor
  65. COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJDecompressor
  66. COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJTransformer)
  67. endif()
  68. if(NOT DEFINED CMAKE_INSTALL_DEFAULT_JAVADIR)
  69. set(CMAKE_INSTALL_DEFAULT_JAVADIR "<CMAKE_INSTALL_DATAROOTDIR>/java")
  70. endif()
  71. GNUInstallDirs_set_install_dir(JAVADIR
  72. "The directory into which Java classes should be installed")
  73. GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_JAVADIR
  74. CMAKE_INSTALL_JAVADIR)
  75. set(CMAKE_INSTALL_JAVADIR ${CMAKE_INSTALL_JAVADIR} PARENT_SCOPE)
  76. set(CMAKE_INSTALL_FULL_JAVADIR ${CMAKE_INSTALL_FULL_JAVADIR} PARENT_SCOPE)
  77. report_directory(JAVADIR)
  78. install_jar(turbojpeg-java ${CMAKE_INSTALL_JAVADIR})
  79. mark_as_advanced(CLEAR CMAKE_INSTALL_JAVADIR)