foreach (PACKAGE ${LCM_PACKAGES})

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

  # emit python lcmtypes
  set (LCM_SRC "")
  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_PY "${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE}/${LCM_TYPE}.py")

    add_custom_command (
      OUTPUT ${LCM_TYPE_PY}
      COMMAND ${LCM_GEN} ${LCM_DEF} --lazy -p
      DEPENDS ${LCM_DEF}
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      )

    set (LCM_SRC ${LCM_SRC} ${LCM_TYPE_PY})

  endforeach ()

  add_custom_command (
    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE}/__init__.py
    DEPENDS ${LCM_SRC}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )

  add_custom_target (${PACKAGE}.py ALL 
    DEPENDS ${LCM_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE}/__init__.py
    )

endforeach ()
