I need to generate some files during the build. How do I do this ?

I need to build an executable which is used later on during the build to generate files. How do I do this ?

Let's say the executable is called genembed. Then use KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})to create the executable. The RUN_UNINSTALLED option is important, because the executable has to run from the build dir and has to link to the libraries in the builddir. To achieve this, the executable is compiled with RPATH set accordingly and a wrapper shell script, named just like the executable but with the suffix ".sh" is created. This shell scripts sets up LD_LIBRARY_PATH and the calls the actual executable.
Use this wrapper shell script in the ADD_CUSTOM_COMMAND() as described above.
You can find out the name and exact location by querying the property WRAPPER_SCRIPT. Here's a full example taken from kdelibs/kstyles/keramik/ :

build the executable

kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})

get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)