/Applications/CLI/Java/CMakeLists.txt

https://github.com/LinjieChen/Slicer-1 · CMake · 138 lines · 78 code · 27 blank · 33 comment · 9 complexity · 7e9083b8eeddb685f56c0dd0bc1e5fcb MD5 · raw file

  1. find_package( Java )
  2. # Since not all dashboard are running cmake 2.8.1, let's set the legacy variable
  3. if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_LESS "2.8.1")
  4. set(Java_JAVA_EXECUTABLE ${JAVA_RUNTIME})
  5. set(Java_JAVAC_EXECUTABLE ${JAVA_COMPILE})
  6. set(Java_JAR_EXECUTABLE ${JAVA_ARCHIVE})
  7. endif()
  8. if(NOT Java_JAVAC_EXECUTABLE)
  9. message(STATUS "Skipping installation of CLI/Application/Java - Set Java_JAVAC_EXECUTABLE variable to fix the problem")
  10. return()
  11. endif()
  12. project(JavaExamples Java )
  13. slicer3_set_plugins_output_path()
  14. set(build_type ".")
  15. if(WIN32 AND CMAKE_CONFIGURATION_TYPES)
  16. # Sadly, there is no way to know if the user picked Debug or Release
  17. # here, so we are going to have to stick to the value of CMAKE_BUILD_TYPE
  18. # if it has been set explicitly (by a dashboard for example), or the
  19. # first value in CMAKE_CONFIGURATION_TYPES (i.e. Debug)/
  20. if (Slicer_USE_KWWIDGETS)
  21. kwwidgets_get_cmake_build_type(build_type)
  22. endif (Slicer_USE_KWWIDGETS)
  23. endif(WIN32 AND CMAKE_CONFIGURATION_TYPES)
  24. #####################
  25. set (CLP HelloWorld)
  26. # If have the java compiler, try to compile the .java files
  27. if( Java_JAVAC_EXECUTABLE )
  28. # message (STATUS "Java run time = ${Java_JAVA_EXECUTABLE}, compiler = ${Java_JAVAC_EXECUTABLE}, jar = ${Java_JAR_EXECUTABLE}")
  29. # source files
  30. set( ${CLP}_JAR_SRCS Examples/${CLP}App.java)
  31. # class path
  32. if( WIN32 )
  33. set( ${CLP}_CLASSPATH
  34. ".\;../Examples\;${CMAKE_CURRENT_BINARY_DIR}" )
  35. else( WIN32 )
  36. set( ${CLP}_CLASSPATH
  37. ".:../Examples:${CMAKE_CURRENT_BINARY_DIR}" )
  38. endif( WIN32 )
  39. # message (STATUS "Adding custom java compile target: ${Java_JAVAC_EXECUTABLE} -d ${CMAKE_CURRENT_BINARY_DIR} -classpath ${${CLP}_CLASSPATH} ${${CLP}_JAR_SRCS}")
  40. add_custom_target( ${CLP}.jar.classes ALL
  41. ${Java_JAVAC_EXECUTABLE} -d ${CMAKE_CURRENT_BINARY_DIR} -classpath ${${CLP}_CLASSPATH} ${${CLP}_JAR_SRCS}
  42. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} )
  43. # message (STATUS "Adding a custom target to jar it up into the plug ins directory ${CMAKE_BINARY_DIR}/${Slicer_INSTALL_CLIMODULES_BIN_DIR}/${build_type}")
  44. add_custom_target( ${CLP}.jar ALL
  45. ${Java_JAR_EXECUTABLE} cvf ${CMAKE_BINARY_DIR}/${Slicer_CLIMODULES_BIN_DIR}/${build_type}/${CLP}.jar Examples
  46. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
  47. add_dependencies( ${CLP}.jar ${CLP}.jar.classes )
  48. # install the jar file
  49. install (
  50. FILES ${CMAKE_BINARY_DIR}/${Slicer_CLIMODULES_BIN_DIR}/${build_type}/${CLP}.jar
  51. DESTINATION ${Slicer_INSTALL_CLIMODULES_BIN_DIR}
  52. )
  53. #####
  54. # install the tcl file that runs the jar file like an executable CLI
  55. #####
  56. if (Slicer_SOURCE_DIR)
  57. # install each target in the production area (where it would appear in an
  58. # installation) and install each target in the developer area (for running
  59. # from a build)
  60. # message (STATUS "Installing ${CLP}.tcl")
  61. set(TARGETS
  62. ${CLP}.tcl
  63. )
  64. foreach(file ${TARGETS})
  65. configure_file(
  66. ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  67. ${CMAKE_BINARY_DIR}/${Slicer_CLIMODULES_BIN_DIR}/${build_type}/${file}
  68. COPYONLY
  69. )
  70. endforeach(file)
  71. # install(
  72. # FILES ${TARGETS}
  73. # DESTINATION ${CMAKE_BINARY_DIR}/${Slicer_INSTALL_CLIMODULES_BIN_DIR}/${build_type}
  74. # )
  75. install (
  76. FILES ${CMAKE_BINARY_DIR}/${Slicer_CLIMODULES_BIN_DIR}/${build_type}/${CLP}.tcl
  77. DESTINATION ${Slicer_INSTALL_CLIMODULES_BIN_DIR}
  78. )
  79. endif (Slicer_SOURCE_DIR)
  80. else( Java_JAVAC_EXECUTABLE)
  81. message (STATUS "Unable to compile java code, skipping installation of ${CLP}.jar and .tcl")
  82. endif( Java_JAVAC_EXECUTABLE )
  83. ##############
  84. # skip SPECTRE
  85. if (0)
  86. set (CLP SPECTRE)
  87. #####
  88. # install the tcl file that runs the jar file like an executable CLI
  89. #####
  90. if (Slicer_SOURCE_DIR)
  91. # install each target in the production area (where it would appear in an
  92. # installation) and install each target in the developer area (for running
  93. # from a build)
  94. set(TARGETS
  95. ${CLP}.tcl
  96. # SPECTRE_2010-04-01.jar
  97. SPECTRElite_2010-05-15.jar
  98. )
  99. foreach(file ${TARGETS})
  100. configure_file(
  101. ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  102. ${CMAKE_BINARY_DIR}/${Slicer_CLIMODULES_BIN_DIR}/${build_type}/${file}
  103. COPYONLY
  104. )
  105. endforeach(file)
  106. install(
  107. FILES ${TARGETS}
  108. DESTINATION ${CMAKE_BINARY_DIR}/${Slicer_INSTALL_CLIMODULES_BIN_DIR}/${build_type}
  109. )
  110. endif (Slicer_SOURCE_DIR)
  111. endif (0)