set(tarball   foo-1.2.3.tar.gz)
set(output ${CMAKE_CURRENT_SOURCE_DIR}/foo-1.2.3)

add_custom_command(OUTPUT ${output}
    COMMAND ${CMAKE_COMMAND} -E tar zxf ${tarball}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Unpacking ${tarball}")

add_custom_target( untarFoo DEPENDS ${output} )

add_dependencies( untar untarFoo )
