cmake: Fix CTest custom commands

This commit is related to:
 - https://github.com/NixOS/nixpkgs/issues/762
 - http://public.kitware.com/Bug/view.php?id=13887
And fixes a bug present in recent CMake versions.

The fix should be integrated in the next CMake release.