This script will work for your simple input. It will require extra escaping work if you need to embed double quotes or backslashes. And I do not claim it is correct for all arbitrary input. But.... it&#39;s a starting point, in the CMake language. Let me know if it gives you any troubles.<div>
<br></div><div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">set</span>(input_file <span style="color: #da2e24">&quot;<a href="http://square.cl">square.cl</a>&quot;</span>)</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">set</span>(output_file <span style="color: #da2e24">&quot;square.h&quot;</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Read the whole input file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">READ</span><span style="color: #000000"> </span>&quot;${input_file}&quot;<span style="color: #000000"> contents)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Split it into lines:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#    (insert line-ending &#39;E&#39; chars to allow lines to be blank or end with</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#     semi-colons but still be iterate-able via CMake foreach...)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>&quot;;&quot;<span style="color: #000000"> </span>&quot;\\\\;&quot;<span style="color: #000000"> contents </span>&quot;${contents}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>&quot;\n&quot;<span style="color: #000000"> </span>&quot;E;&quot;<span style="color: #000000"> contents </span>&quot;${contents}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Open output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">WRITE</span><span style="color: #000000"> </span>&quot;${output_file}&quot;</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span>&quot;const char *KernelSource =\n&quot;<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Send each line to output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">foreach</span>(lineE ${contents})</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"><span style="color: #000000">  </span># Get rid of the trailing &#39;E&#39;:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  <span style="color: #008419">#</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>&quot;^(.*)E$&quot;<span style="color: #000000"> </span>&quot;\\1&quot;<span style="color: #000000"> line </span>&quot;${lineE}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">APPEND</span><span style="color: #000000"> </span>&quot;${output_file}&quot;</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">    </span>&quot;  \&quot;${line}\&quot;\n&quot;<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #c22a9f">endforeach<span style="color: #000000">()</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Close output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">APPEND</span><span style="color: #000000"> </span>&quot;${output_file}&quot;</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span>&quot;;\n&quot;<span style="color: #000000">)</span></p><div><font class="Apple-style-span" face="Menlo" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br>
</span></font></div></div><div><br></div><div>Cheers,</div><div>David</div><div><br><br><div class="gmail_quote">On Tue, Jun 15, 2010 at 5:24 PM, David Cole <span dir="ltr">&lt;<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div><div></div><div class="h5">On Tue, Jun 15, 2010 at 5:13 PM, Daniel Blezek <span dir="ltr">&lt;<a href="mailto:Blezek.Daniel@mayo.edu" target="_blank">Blezek.Daniel@mayo.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">




<div>
<font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size:11pt">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 &lt; 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 = &quot;\n&quot; \<br>
&quot;__kernel square(                                                       \n&quot; \<br>
&quot;   __global float* input,                                              \n&quot; \<br>
&quot;   __global float* output,                                             \n&quot; \<br>
&quot;   const unsigned int count)                                           \n&quot; \<br>
&quot;{                                                                      \n&quot; \<br>
&quot;   int i = get_global_id(0);                                           \n&quot; \<br>
&quot;   if(i &lt; count)                                                       \n&quot; \<br>
&quot;       output[i] = input[i] * input[i];                                \n&quot; \<br>
&quot;}                                                                      \n&quot; \<br>
&quot;\n&quot;;<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></span></font></div></blockquote></div></div><div><br><br>It is. CMake can definitely do that. I know I&#39;ve written code like this somewhere... I have to dash off at the moment, but when I get back to a computer, I&#39;ll see if I can look it up and pass along a function that does something similar.<br>

<br>Unless somebody else beats me to it. :-)<br><br>- David<br></div></div><br>
</blockquote></div><br></div>