Search code examples
resourcespremake

handling non-sourcecode files in premake


my project, which is a game, consists of several source files, and several resources like images, maps, models, etc. Some of them need to be processed by a program, for example I would like to convert all the images from png to dds. Since my build is an out of source build, I would like to have all my resources build into the build folder, so that for shipping, I only need to pack the build folder.

how do I do that?


Solution

  • If you are using a 4.x version of Premake, I'm afraid there isn't a simple solution. You can embed data (copy them to the output directory)

    configuration "**.png"
       buildaction "Copy"
    

    If you want to build them, what I would do is to copy them, and then use a "post-build" command to take care of converting the files and cleaning up. For instance :

    configuration ""
        postbuildcommands { "premake --file=build_resources.lua build" }
    

    Of course, what you put in build_resources.lua is up to you, and you can even use the same script as the one you use to create your project. You just have to define the build action and what it does (basically parse the output folder, and compile every png's to dds', then clean the png's. You will probably also have to add options to specify your platform / configuration to the build script.

    Now, if you're using the latest versions of premake (found here : http://sourceforge.net/projects/premake/files/Premake/nightlies/) you can achieve this a lot more easily :

    -- filter is the equivalent of 'configuration' in Premake 5.
    -- configuration is still supported for backward compatibility, but it
    -- will be removed eventually, so better start using 'filter' :)
    filter "files:**.png"
    
        -- this is simply a message shown in the Visual Studio output
        buildmessage "converting %{file.relpath} to dds ..."
    
        -- this is the actual custom compilation command
        buildcommands {
            "ddsconverter --input=%{file.abspath} --output=%{cfg.linktarget.directory}"
        }
    

    For more informations, see here : https://bitbucket.org/premake/premake-dev/wiki/buildcommands

    And for informations on tokens (the %{xxx} things which allows you to use the paths known to premake without writing them) : https://bitbucket.org/premake/premake-dev/wiki/Tokens