foreach (PACKAGE ${LCM_PACKAGES})

  # round up .lcm definition files
  file (GLOB LCM_DEFS "${LCM_DEFS_DIR}/${PACKAGE}/*.lcm")

  # emit java lcmtypes
  set (LCM_TYPES_JAVA  "")
  set (LCM_TYPES_CLASS "")
  foreach (LCM_DEF ${LCM_DEFS})

    string (REPLACE ".lcm" "" LCM_TYPE ${LCM_DEF})
    string (REPLACE "${LCM_DEFS_DIR}/${PACKAGE}/${PACKAGE}_" "" LCM_TYPE ${LCM_TYPE})

    set (LCM_TYPE_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE}/${LCM_TYPE}.java")
    set (LCM_TYPE_CLASS "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${LCM_TYPE}.class")

    add_custom_command (
      OUTPUT ${LCM_TYPE_JAVA}
      COMMAND ${LCM_GEN} ${LCM_DEF} --lazy -j
      DEPENDS ${LCM_DEF}
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      )

    set (LCM_TYPES_JAVA  ${LCM_TYPES_JAVA}  ${LCM_TYPE_JAVA})
    set (LCM_TYPES_CLASS ${LCM_TYPES_CLASS} ${LCM_TYPE_CLASS})

  endforeach ()

  #include_directories (${LCM_JAR})
  #add_library (${PACKAGE}.jar ${LCM_TYPES_JAVA})

  set (JAR "${LIBRARY_OUTPUT_PATH}/${PACKAGE}.jar")
  set (JARS ${JARS} "${LIBRARY_OUTPUT_PATH}/${PACKAGE}.jar")
  set (CLASSPATH "${CLASSPATH}:${JAR}")
  set (LCMTYPE_JAR_TARGETS ${LCMTYPE_JAR_TARGETS} ${PACKAGE}.jar)

  # compile class definitions
  add_custom_command (
    OUTPUT ${LCM_TYPES_CLASS}
    COMMAND ${CMAKE_Java_COMPILER} -classpath ${CLASSPATH} -d ${CMAKE_CURRENT_BINARY_DIR} ${LCM_TYPES_JAVA}
    DEPENDS ${LCM_TYPES_JAVA}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Generating target ${PACKAGE}.jar class files"
    )

  # build ${PACKAGE}.jar
  add_custom_target (${PACKAGE}.jar ALL
    COMMAND ${CMAKE_Java_ARCHIVE} cf ${JAR} ${PACKAGE}
    DEPENDS ${LCM_TYPES_CLASS}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    )

endforeach () #foreach (PACKAGE ${LCM_PACKAGES})

# tag jar files for deletion with a clean build
set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${JARS}")

set (CLASSPATH "${CLASSPATH}" PARENT_SCOPE)
set (LCMTYPE_JAR_TARGETS ${LCMTYPE_JAR_TARGETS} PARENT_SCOPE)
