<HTML>
<HEAD>
<TITLE>Re: [CMake] Converting a OpenCL program into a C++ header?</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi Stefan,<BR>
<BR>
Yes, I’ve done this sort of thing with Lua (which is built as part of our code), but I’d prefer to do this with CMake to avoid the extra headache of maintaining my code. I suspect it’s just a few lines (but knowing the right few lines is the key).<BR>
<BR>
Thanks,<BR>
-dan<BR>
<BR>
<BR>
On 6/15/10 4:33 PM, "Stefan Buschmann" <<a href="s_buschmann@gmx.de">s_buschmann@gmx.de</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Am 15.06.2010 23:13, schrieb Daniel Blezek: <BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> Converting a OpenCL program into a C++ header? Hi,<BR>
<BR>
We would like to convert an OpenCL program written in a separate file to a C++ header (essentially a long string).<BR>
<BR>
For example, if my OpenCL program is in the file Square.cl<BR>
<BR>
__kernel square( <BR>
__global float* input, <BR>
__global float* output, <BR>
const unsigned int count) <BR>
{ <BR>
int i = get_global_id(0); <BR>
if(i < count) <BR>
output[i] = input[i] * input[i]; <BR>
} <BR>
<BR>
I’d like to turn it into something like this in Square.h:<BR>
<BR>
const char *KernelSource = "\n" \<BR>
"__kernel square( \n" \<BR>
" __global float* input, \n" \<BR>
" __global float* output, \n" \<BR>
" const unsigned int count) \n" \<BR>
"{ \n" \<BR>
" int i = get_global_id(0); \n" \<BR>
" if(i < count) \n" \<BR>
" output[i] = input[i] * input[i]; \n" \<BR>
"} \n" \<BR>
"\n";<BR>
<BR>
So that my OpenCL code can be directly compiled into my executable. This is also useful for OpenGL shaders.<BR>
<BR>
The question: is this something that CMake could do? If so, any examples where to begin looking?<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>You could write a little application that reads in the source file and generates the header file just as in your example. Then you could use CMake to execute that application e.g. using add_custom_command() before building your executables that include the generated header files. You could even build the tool itself as a dependency first.<BR>
<BR>
Hope that helps...<BR>
<BR>
Stefan<BR>
<BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>_______________________________________________<BR>
Powered by www.kitware.com<BR>
<BR>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
<BR>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a><BR>
<BR>
Follow this link to subscribe/unsubscribe:<BR>
<a href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
</SPAN></FONT></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>-- <BR>
<B>Daniel Blezek, PhD<BR>
</B>Medical Imaging Informatics Innovation Center<BR>
<BR>
P 127 or (77) 8 8886<BR>
T 507 538 8886<BR>
E <a href="blezek.daniel@mayo.edu">blezek.daniel@mayo.edu</a><BR>
<BR>
Mayo Clinic<BR>
200 First St. S.W.<BR>
Harwick SL-44<BR>
Rochester, MN 55905<BR>
mayoclinic.org<BR>
<BR>
</SPAN></FONT>
</BODY>
</HTML>