[CMake] Associating files with command
Anders Backman
andersb at cs.umu.se
Wed Sep 1 10:37:55 EDT 2010
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:
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->compile on
the .pkg file.
I can however go further down, locate the matching rule, right click on that
and compile.
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...
Some slight modifications was needed on the function:
FUNCTION (wrap_tolua outvar)
set(outfiles)
foreach(in ${ARGN})
get_filename_component(inAbs ${in} ABSOLUTE)
get_filename_component(basename ${in} NAME_WE)
get_filename_component(path ${in} PATH)
file(MAKE_DIRECTORY ${path}/generated)
set(outfile "${path}/generated/generated_${basename}.cpp")
list(APPEND outfiles "${outfile}")
add_custom_command(OUTPUT "${outfile}"
COMMAND ${TOLUA_EXECUTABLE} -o "${outfile}" -n ${basename}
"${inAbs}" -L "lua/access_hook.lua"
DEPENDS "${inAbs}"
WORKING_DIRECTORY "${path}"
COMMENT "Wrapping ${basename} with tolua")
endforeach()
set(${outvar} ${outfiles} PARENT_SCOPE)
endfunction()
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.
/Anders
On Tue, Aug 31, 2010 at 10:38 PM, Ryan Pavlik <rpavlik at iastate.edu> wrote:
> You were close:
>
> here's a function to handle the wrapping - could stick this in the
> Findtolua.cmake file that you've hopefully made.
>
> function wrap_tolua(outvar)
> set(outfiles)
> foreach(in ${ARGN})
> get_filename_component(inAbs ${in} ABSOLUTE)
> get_filename_component(basename ${in} NAME_WE)
> set(outfile
> "${CMAKE_CURRENT_BINARY_DIR}/generated_${basename}.cpp")
> list(APPEND outfile "${outfile}")
> add_custom_command(OUTPUT "${outfile}"
> COMMAND ${TOLUA_EXECUTABLE} -o "${outfile}" -n ${basename}
> "${inAbs}"
> DEPENDS "${inAbs}"
> COMMENT "Wrapping ${basename} with tolua")
> endforeach()
> set(${outvar} ${outfiles} PARENT_SCOPE)
> endfunction()
>
>
> Then, to do your example:
>
> find_package(tolua REQUIRED)
>
> wrap_tolua(TOLUA_WRAPPED_SRC math.pkg another.pkg)
> add_library(myLib theMain.cpp ${TOLUA_WRAPPED_SRC})
>
> (This is similar to how Qt and FLTK builds take place.)
>
> Hope this helps! Please share your find module with this code added and
> tweaked, if needed - thanks!
>
> Ryan
>
>
> On 08/31/2010 02:44 PM, Anders Backman wrote:
>
> Hi all.
>
> 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.
>
> 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.
>
> 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.
> 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.
>
> So I guess Im looking for something like:
>
> add_library(myLib theMain.cpp
> generated_math.cpp
> math.pkg
> )
>
> set_source_files_properties(generated_math.cpp GENERATED)
>
> being able to tell CMake that .pkg files are treated in a certain way:
> The command that I want to execute for each .pkg is:
>
> tolua -o generated_math.cpp -n math math.pkg
>
> So any hints on how to do this?
> 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...
>
> /A
>
>
> _______________________________________________
> Powered by www.kitware.com
>
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:http://www.cmake.org/mailman/listinfo/cmake
>
>
> --
> Ryan Pavlik
> HCI Graduate Student
> Virtual Reality Applications Center
> Iowa State University
> http://academic.cleardefinition.comhttp://rpavlik.youcanbook.me
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100901/d2491c69/attachment.htm>
More information about the CMake
mailing list