<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Is there any particular reason why you didn't generate the cpp files
    to the CMAKE_CURRENT_BINARY_DIR?&nbsp; That's generally the way to go for
    generated files - writing to the source tree falls under the "big
    no-no" category.<br>
    <br>
    You can create a custom target for the tolua files, with this
    function - not sure if it will give you the exact interaction with
    vs that you want, but it might be closer. The call will now be
    wrap_tolua(myLib TOLUA_WRAPPED_SRC math.pkg another.pkg) and it will
    create a target/project that shows all of the .pkg files as sources,
    for easy editing, and might let you right-click and build that way.&nbsp;
    (At the very least, a "build solution" should only re-wrap the pkgs
    that have changed.)<br>
    <br>
    <div>function(wrap_tolua targetname outvar)</div>
    <div>&nbsp;&nbsp; &nbsp;set(outfiles)</div>
    <div>&nbsp;&nbsp; &nbsp;foreach(in ${ARGN})</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(inAbs ${in} ABSOLUTE)</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(basename ${in} NAME_WE)</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(path ${in} PATH)</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;file(MAKE_DIRECTORY ${path}/generated)</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;set(outfile
      "${path}/generated/generated_${basename}.cpp")</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;list(APPEND outfiles "${outfile}")</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;add_custom_command(OUTPUT "${outfile}"</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMAND ${TOLUA_EXECUTABLE} -o "${outfile}" -n
      ${basename} "${inAbs}" -L "lua/access_hook.lua"</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEPENDS "${inAbs}"</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WORKING_DIRECTORY "${path}"</div>
    <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMENT "Wrapping ${basename} with tolua")</div>
    <div>&nbsp;&nbsp; &nbsp;endforeach()</div>
    <div>&nbsp;&nbsp; &nbsp;set(${outvar} ${outfiles} PARENT_SCOPE)<br>
      &nbsp;&nbsp;&nbsp; add_custom_target(${targetname}_tolua<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DEPENDS ${outfiles}<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SOURCES ${ARGN})<br>
    </div>
    <div>endfunction()</div>
    <br>
    <br>
    On 9/1/10 9:37 AM, Anders Backman wrote:
    <blockquote
      cite="mid:AANLkTimTYwwMhQehcxueHTiEQpMjEHK4jrK9ww2tO8fL@mail.gmail.com"
      type="cite">That was very close to what I wanted. But not to 100%,
      Im not sure if it is possible to get to what I really want:
      <div><br>
      </div>
      <div>On one hand, I get one build rule for each tolua file, but it
        was not associated to the actual tolua file. So I cannot do
        right click-&gt;compile on the .pkg file.</div>
      <div><br>
      </div>
      <div>I can however go further down, locate the matching rule,
        right click on that and compile.</div>
      <div>So for a large project with hundred of .pgk file, this is not
        optimal. I would like to be able to do ctrl+F7 to compile the
        current file for example...</div>
      <div><br>
      </div>
      <div>Some slight modifications was needed on the function:</div>
      <div><br>
      </div>
      <div>
        <div>FUNCTION (wrap_tolua outvar)</div>
        <div>&nbsp;&nbsp; &nbsp;set(outfiles)</div>
        <div>&nbsp;&nbsp; &nbsp;foreach(in ${ARGN})</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(inAbs ${in} ABSOLUTE)</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(basename ${in} NAME_WE)</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get_filename_component(path ${in} PATH)</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;file(MAKE_DIRECTORY ${path}/generated)</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;set(outfile
          "${path}/generated/generated_${basename}.cpp")</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;list(APPEND outfiles "${outfile}")</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;add_custom_command(OUTPUT "${outfile}"</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMAND ${TOLUA_EXECUTABLE} -o "${outfile}" -n
          ${basename} "${inAbs}" -L "lua/access_hook.lua"</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEPENDS "${inAbs}"</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WORKING_DIRECTORY "${path}"</div>
        <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMENT "Wrapping ${basename} with tolua")</div>
        <div>&nbsp;&nbsp; &nbsp;endforeach()</div>
        <div>&nbsp;&nbsp; &nbsp;set(${outvar} ${outfiles} PARENT_SCOPE)</div>
        <div>endfunction()</div>
        <div><br>
        </div>
        <div>So unless someone knows how to add a file to a library,
          associate it with a custom build command, this is what I have
          to stick to.</div>
        <div><br>
        </div>
        <div>/Anders</div>
        <br>
        <div class="gmail_quote">
          On Tue, Aug 31, 2010 at 10:38 PM, Ryan Pavlik <span dir="ltr">&lt;<a
              moz-do-not-send="true" href="mailto:rpavlik@iastate.edu">rpavlik@iastate.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 bgcolor="#ffffff" text="#000000"> You were close:<br>
              <br>
              here's a function to handle the wrapping - could stick
              this in the Findtolua.cmake file that you've hopefully
              made.<br>
              <br>
              function wrap_tolua(outvar)<br>
              &nbsp;&nbsp;&nbsp; set(outfiles)<br>
              &nbsp;&nbsp;&nbsp; foreach(in ${ARGN})<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get_filename_component(inAbs ${in} ABSOLUTE)<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get_filename_component(basename ${in} NAME_WE)<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set(outfile
              "${CMAKE_CURRENT_BINARY_DIR}/generated_${basename}.cpp")<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list(APPEND outfile "${outfile}")<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_custom_command(OUTPUT "${outfile}"<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; COMMAND ${TOLUA_EXECUTABLE} -o "${outfile}" -n
              ${basename} "${inAbs}"<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DEPENDS "${inAbs}"<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; COMMENT "Wrapping ${basename} with tolua")<br>
              &nbsp;&nbsp;&nbsp; endforeach()<br>
              &nbsp;&nbsp;&nbsp; set(${outvar} ${outfiles} PARENT_SCOPE)<br>
              endfunction()<br>
              <br>
              <br>
              Then, to do your example:<br>
              <br>
              find_package(tolua REQUIRED)<br>
              <br>
              wrap_tolua(TOLUA_WRAPPED_SRC math.pkg another.pkg)<br>
              add_library(myLib theMain.cpp ${TOLUA_WRAPPED_SRC})<br>
              <br>
              (This is similar to how Qt and FLTK builds take place.)<br>
              <br>
              Hope this helps!&nbsp; Please share your find module with this
              code added and tweaked, if needed - thanks!<br>
              <br>
              Ryan
              <div>
                <div class="h5"><br>
                  <br>
                  On 08/31/2010 02:44 PM, Anders Backman wrote: </div>
              </div>
              <blockquote type="cite">
                <div>
                  <div class="h5">Hi all.
                    <div><br>
                    </div>
                    <div>I have a directory of .pkg files to be
                      processed by tolua. This in turn generates a bunch
                      of cpp files, which I then link into a library.</div>
                    <div><br>
                    </div>
                    <div>My problem right now is that, I would like to
                      generate a project, where each .pkg is associated
                      with a custom command, so that I in visual studio
                      (for exampel) can "compile" each .pkg file
                      individually.</div>
                    <div><br>
                    </div>
                    <div>I have managed to create a library, and to get
                      all the generated cpp file associated to the
                      library+a custom target command which is executed
                      PRE_BUILD to the library.</div>
                    <div>But thats not quite what I would like. Because
                      then I cant just compile one .pkg file if I edit
                      it. Using the above approach, requires me to build
                      the whole project, which compiles ALL .pkg files
                      associated to it, not what I want. I want to setup
                      a proper dependency chain, so that If a .pkg file
                      is modified, the corresponding "generated"_xx.cpp
                      is generated, and the project is linked.</div>
                    <div><br>
                    </div>
                    <div>So I guess Im looking for something like:</div>
                    <div><br>
                    </div>
                    <div>add_library(myLib theMain.cpp&nbsp;</div>
                    <div>&nbsp;&nbsp; generated_math.cpp&nbsp;</div>
                    <div>&nbsp;&nbsp; math.pkg&nbsp;</div>
                    <div>)</div>
                    <div><br>
                    </div>
                    <div>
                      <div>set_source_files_properties(generated_math.cpp
                        GENERATED)</div>
                    </div>
                    <div><br>
                    </div>
                    <div>being able to tell CMake that .pkg files are
                      treated in a certain way:</div>
                    <div>The command that I want to execute for each
                      .pkg is:</div>
                    <div><br>
                    </div>
                    <div>tolua -o generated_math.cpp<span
                        style="white-space: pre-wrap;"> </span>-n math<span
                        style="white-space: pre-wrap;"> </span>math.pkg</div>
                    <div><br>
                    </div>
                    <div>So any hints on how to do this?</div>
                    <div>I can certainly do this in VisualStudio, adding
                      .pkg files to the project, and setting the build
                      events on it, but I need a portable solution...</div>
                    <div><br>
                    </div>
                    <div>/A<br>
                    </div>
                  </div>
                </div>
              </blockquote>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Ryan Pavlik
Human-Computer Interaction Graduate Student
Virtual Reality Applications Center
Iowa State University

<a class="moz-txt-link-freetext" href="http://academic.cleardefinition.com/">http://academic.cleardefinition.com/</a></pre>
  </body>
</html>