project(vehicles)

set(VEHICLES_SRC boat-big.blend boat.blend
	boat-gobbot.blend boat-sails.blend
	raft.blend tiny-boat.blend)
set(VEHICLE_OUTPUT_FILES)

foreach(VEHICLE_FILE ${VEHICLES_SRC})
	get_filename_component(FILE_NAME ${VEHICLE_FILE} NAME_WE)
	set(VEHICLE_OUTPUT_FILE ${CMAKE_BINARY_DIR}/resources/vehicles/${FILE_NAME}.glb)
	add_custom_command(
		OUTPUT ${VEHICLE_OUTPUT_FILE} ${CMAKE_BINARY_DIR}/resources/vehicles/${FILE_NAME}.scene
		COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/resources/vehicles
		COMMAND ${BLENDER} ${CMAKE_CURRENT_SOURCE_DIR}/${VEHICLE_FILE}
			-b -Y -P
			${CMAKE_SOURCE_DIR}/assets/blender/scripts/export_vehicles.py
			-- ${VEHICLE_OUTPUT_FILE}
		COMMAND ${CMAKE_COMMAND} -D FILE=${CMAKE_BINARY_DIR}/resources/vehicles/${FILE_NAME}.glb -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_file_size.cmake
		COMMAND ${CMAKE_COMMAND} -D FILE=${CMAKE_BINARY_DIR}/resources/vehicles/${FILE_NAME}.scene -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_file_size.cmake
		COMMAND touch ${VEHICLE_OUTPUT_FILE}
		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${VEHICLE_FILE} ${CMAKE_SOURCE_DIR}/assets/blender/scripts/export_vehicles.py)
	list(APPEND VEHICLE_OUTPUT_FILES ${VEHICLE_OUTPUT_FILE} ${CMAKE_BINARY_DIR}/resources/vehicles/${FILE_NAME}.scene)
endforeach()

add_custom_target(import_vehicles ALL DEPENDS ${VEHICLE_OUTPUT_FILES})
