Only run C preprocessor in cmake?

arsenm picture arsenm · Aug 25, 2010 · Viewed 8.3k times · Source

I'm trying to use cmake to simplify distributing my OpenCL program. I have a kernel file which includes several headers and other source files, and I want to have a single self contained executable.

My plan is to have cmake run the C preprocessor on the kernel source, turning the cl file and its includes into a single unit which is easier to work with.

I can use add_custom_command to do it by calling gcc/clang with -E, but then I don't get the flags to include the right directories to find the various header files in the command, and I don't see an easy way to find all current include directories to use in the custom call to the compiler.

Is there a way to run only the C preprocessor on a file with the current cmake environment?

Answer

Tadeusz A. Kadłubowski picture Tadeusz A. Kadłubowski · May 14, 2012

CMake automatically generates make targets for preprocessing files. For each foo.c in your project there's a foo.i make target that will run only the preprocessor (with all the relevant -D and -I flags etc.). Run make help to see all other potentially useful targets that CMake generates in your makefiles.

BTW, I can't see how this "single unit" will be easier to work with for you.