I want to achieve the equivalent of C++ #define foo "bar" but I don't want the value "bar" to be part of my code repository, and the value will depend on whether the build is Debug or Release.
How can I do this?
NB: I like the idea of using the following in CMakeLists.txt add_compile_definitions(foo="bar") but I don't know how to supply "bar" from the Qt Creator build settings.
Presumably I'd add a Key/Value pair but what would I put?

You need a 2 step process:
For your example:
MYPROJECT_FOOand Value tobar-DMYPROJECT_FOO:STRING=bartarget_compile_definitions(mytarget PUBLIC foo="${MYPROJECT_FOO}")(As advised by Guillaume Racicot it's better to apply the definition to a single target, as opposed to the entire project, which would be
add_compile_definitions(foo="${MYPROJECT_FOO}").)See also Qt Creator documentation CMake Build Configuration: Modifying Variable Values.
Thanks to Guillaume Racicot for deeper explanation of how CMake cache variables can be used.