set (SRC
  DegViewerPlugin.java
  RawPlugin.java
  ImagePlugin.java 
  PlanarLidarPlugin.java
)
if (NOT SRC)
  return ()
endif ()

#include_directories (${LCM_JAR} ${LCMTYPES_JAR})
#add_library (plugin ${SRC})
#add_dependencies (plugin lcmtypes.jar)

set (CLASS_FILES "")
foreach (FILE ${SRC})
  string (REPLACE ".java" ".class" CLASS_FILE ${FILE})
  set (CLASS_FILES ${CLASS_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${CLASS_FILE})
endforeach ()

set (PLUGIN_JAR "${LIBRARY_OUTPUT_PATH}/plugin.jar")
set (CLASSPATH "${CLASSPATH}:${PLUGIN_JAR}" PARENT_SCOPE)

add_custom_target (foo)

# compile class definitions
add_custom_command (
  OUTPUT ${CLASS_FILES}
  COMMAND ${CMAKE_Java_COMPILER} -classpath ${CLASSPATH} -d ${CMAKE_CURRENT_BINARY_DIR} ${SRC}
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  COMMENT "Generating target plugin.jar class files"
  )


# build plugin.jar
add_custom_target (plugin.jar ALL
  COMMAND ${CMAKE_Java_ARCHIVE} cf ${PLUGIN_JAR} plugin
  DEPENDS ${CLASS_FILES}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  )
add_dependencies (plugin.jar ${LCMTYPE_JAR_TARGETS})

# tag all auto-gen files for deletion with a clean build
#file (GLOB CLEAN "${CMAKE_CURRENT_BINARY_DIR}/plugin/*.class")
set (CLEAN ${CLEAN} ${PLUGIN_JAR})
set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN}")
