<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
James Bigler wrote:
<blockquote
 cite="mid:1b8d590e0904081245i5fe73d54pdb38e2e804b93b55@mail.gmail.com"
 type="cite">
  <pre wrap="">On Wed, Apr 8, 2009 at 1:01 PM, Jon Schewe <a class="moz-txt-link-rfc2396E" href="mailto:jschewe@bbn.com">&lt;jschewe@bbn.com&gt;</a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Bill Hoffman wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">Jon Schewe wrote:
      </pre>
      <blockquote type="cite">
        <pre wrap="">I recently started using cmake and find it generally to be a nice tool,
however I'm rather frustrated with it now. Can someone please tell me
how to get cmake to conditionally create a file as part of executing a
target? What I want to do looks like this, but apparently
add_custom_command only can execute shell scripts, so I'm not sure how
one can use these nice commands for writing files.

        </pre>
      </blockquote>
      <pre wrap="">custom command can run any program you want??   You can even run cmake
-P and run a cmake script.
      </pre>
      <blockquote type="cite">
        <pre wrap="">FUNCTION(build_includes)
  FILE(WRITE unit_test_includes.hpp "// Autogenerated - do not edit\n")
  FOREACH(test ${TESTS})
    FILE(APPEND unit_test_includes.hpp "#include \"${test}\"\n")
  ENDFOREACH(test)
ENDFUNCTION(build_includes)

        </pre>
      </blockquote>
      <pre wrap="">Put that in a file mycmake.cmake
      </pre>
      <blockquote type="cite">
        <pre wrap="">ADD_CUSTOM_COMMAND(OUTPUT unit_test_includes.hpp
                           COMMAND build_includes
                                     DEPENDS ${TESTS}
                                     COMMENT "Building
unit_test_includes.hpp"
                                     )
        </pre>
      </blockquote>
      <pre wrap="">Run ${CMAKE_COMMAND} -P mycmake.cmake as the COMMAND for your custom
command.

      </pre>
    </blockquote>
    <pre wrap="">OK, so I can't put it all in the same file? I'd rather not have people
needing to chase down multiple files to figure out what's going on. With
make I can just put any function call inside the body of a target.

    </pre>
  </blockquote>
  <pre wrap=""><!---->
You can't do that, because the command is run at build time not
configure time.  In order to run CMake code at build time you need to
run cmake at build time.  Hence Bill's suggestion that you put the
cmake code into a script that cmake processes at build time.
  </pre>
</blockquote>
OK, that's fair. I have been equating cmake with make and that's not
the case. I need to remember that cmake builds makefiles which are then
executed by cmake. So unless cmake translated it's commands all into
make (which I suppose it could), then one needs to call cmake again to
use these cmake commands.<br>
<br>
<pre class="moz-signature" cols="72">-- 
Jon Schewe | Research Scientist
BBN Technologies | <a class="moz-txt-link-freetext" href="http://www.bbn.com">http://www.bbn.com</a>
952-545-5720 - Office
612-210-8818 - Cell
</pre>
</body>
</html>