In the end I went with the script method I'd suggested in my question. Id did this because it meant that I could keep the cli file within the component, add it to the correct location when the component installed and remove it on uninstall.
I did this by adding a new cli folder to the root of my component, which contained the cli file I wanted to add com_mycomponent_cron.php
.
Then in the script file, pointed to by the <scriptfile>script.php</scriptfile>
in the components manifest xml, I added the following to both the install and update methods.
function install($parent)
{
$source = \JPath::clean($parent->getParent()->getPath('source') . '/cli/com_mycomponent_cron.php');
if ( !file_exists($source) ) {
throw new RuntimeException('File cli/com_mycomponent_cron.php does not exist', 500);
}
$dest = \JPath::clean(JPATH_ROOT . '/cli/com_mycomponent_cron.php');
//attempt to copy the file
if ( !\JFile::copy($source,$dest) ) {
throw new RuntimeException('Could not copy com_mycomponent_cron.php to cli folder.',500);
}
}
and for the uninstall method I have this:
function uninstall($parent)
{
$cli_script_path = \JPath::clean(JPATH_ROOT . '/cli/com_mycomponent_cron.php');
if ( file_exists($cli_script_path) ) {
\JFile::delete($cli_script_path);
}
}
I've decided not to accept @Sharky's answer or mark my own as correct, as I don't think either are the 'correct' Joomla way to do things. Although I suspect that there probably isn't a 'correct' way.