You are on page 1of 5

-- Author: Jeff Morgan -- Desc : Premake file to generate proj.

I'm no good with lua, so please -suggest possible improvements. --This file loops over the clients and libraries table inorder to -generate client, lib, and test projects for the SqueakyClean -engine. --To generate a solution from this file, bring up a command prompt in -the directory this file is located in and enter the command: ->premake4 vs2010 --To clean the solution enter the command: ->premake4 clean --To add a library, enter it's name in the Libraries table. The -test file will be created automatically. --To add a client, enter it's name in the Clients table. The first -project will be the startup project in Visual Studio (I think). --To add external dependencies, insert libraries' include and lib -folder into include_dirs and lib_dirs, respectively. --For more information on using premake enter the command: ->premake4 --help --Alternatively, check out the premake quick start guide: -http://industriousone.com/premake-quick-start ------------------------------------------------------------------------------------------------------------------------------------------------------------ Variables for paths to files, in case project layout changes local working_dir = "./" local doc_dir = "./Docs/" local asset_dir = "./Assets/" local source_dir = "./Source/" local temp_dir = "./Temp/" local lib_dir = "./Lib/" local game_dir = "./Game/" local test_dir = "./Test/" local proj_dir = "./Proj/" -- Table of paths to external libraries' include folder local include_dirs = { "Source", "$(EXTERNALSROOT)/gmock-1.6.0/include", -- "Dependencies/gmock/include", "Dependencies/tinyxml/include", } -- Table of paths to external libraries' lib folder local lib_dirs = { "Lib", "$(EXTERNALSROOT)/gmock-1.6.0/msvc/2010/$(Configuration)", --"Dependencies/gmock/lib", "Dependencies/tinyxml/lib", } -- Table of flags for different game configuration -- possible flag values can be found at

-- http://industriousone.com/flags local debug_flags = { "Symbols", "NoMinimalRebuild", "NoEditAndContinue", "FloatFast", "WinMain", "NoIncrementalLink", "StaticRuntime" } local release_flags = { "Symbols", "NoMinimalRebuild", "NoEditAndContinue", "FloatFast", "Optimize", "WinMain", "StaticRuntime" } -- Table of preprocessor definitions for different game configuration local debug_defines = { "_DEBUG", "_CRT_SECURE_NO_WARNINGS" } local release_defines = { "NDEBUG", "_CRT_SECURE_NO_WARNINGS" } -- Table of Client projects to create. These names should have the -- same name as the folder the project's source code is located in local clients = { } -- Table of Library and Test projects to create. These names should have the -- same name as the folder the project's source code is located in. -- Ex. To create a Math and MathTest library, insert 'Math' into the -table and make sure that the source code for the library and test -are in source_dir/Math/ and test_dir/MathTest/ respectively. local libraries = { "Meta", "Example", "Utilities", } -- Search through all directories and subdirectories of path and return all of t hem -- t - file directory table (to be filled) -- paht - the string name of the directory to search function FindDirectoriesRecursive( t, path ) for dir in io.popen([[dir ]] .. path .. [[ /b /ad]]):lines() do table.insert(t, path .. "\\" .. dir) FindDirectoriesRecursive(t, path .. "\\" .. dir) end end -- Opens file and stores all project dependencies into a table

-- filename - the file to read from -- ret - table of dependencies as strings function ReadDependencies( filename ) t = {} for line in io.lines( filename ) do table.insert( t, line ) end return t end -- This function sets up a visual studio project -- proj_name : the name of the new proj -- proj_type : the type of the project, possible values @ http://industriousone. com/kind -- loc_path : the output dir for the vs proj -- pch_file : the name of the precompiled header without extensions -- file_dir : the directory this project's source is located in -- out_dir : th output file for the .exe, .lib, or .dll file function SetUpProj( proj_name, proj_type, loc_path, pch_file, file_dir, out_dir ) kind( proj_type ) -- Sets the project's type language( "C++" ) -- Sets the project's language location( loc_path ) -- Sets where the project is created libdirs( lib_dirs ) -- Sets where the project looks for dependen cies objdir( temp_dir ) -- Sets where the compiled files are store targetdir( out_dir .. _ACTION ) -- Sets where the .exe, .lib, or .dll is sto red includedirs( include_dirs ) -- Sets where the project looks for includes debugdir( working_dir ) -- Sets the working directory for the projec t links( ReadDependencies( file_dir .. proj_name .. "/" .. proj_name .. "Depende ncies.txt" ) ) -- Set up a filter for the code directories = {} FindDirectoriesRecursive(directories, string.sub( file_dir, 3, string.len( file_dir ) - 1) .. "\\" .. proj_name ) vpaths( { ["Precompiled"] = { "**/*Precompiled.hpp", "**/*Precompiled.cpp" } } ) vpaths( { ["Main"] = { "**/*main.cpp", "**/*Main.cpp" } } ) vpaths( { ["Data"] = { "**/*.txt" } } ) for _,folder in ipairs(directories) do vpaths( { [string.sub(folder, string.len(file_dir .. proj_name) )] = {folder .. "/**.hpp", folder .. "/**.cpp", folder .. "/**.inl"}} ) end -- include all files following these patterns files( { file_dir .. proj_name .. "/**.hpp", file_dir .. proj_name .. "/**.cpp", file_dir .. proj_name .. "/**.inl", file_dir .. proj_name .. "/**.txt" } )

-- include a precompiled header the fullpath should NOT be specified pchheader( proj_name .. pch_file .. ".hpp" ) -- set the pch creator, specified by fullpath name pchsource( file_dir .. proj_name .. "/" .. proj_name .. pch_file .. ".cpp" ) -- set build options opt = "/FI" .. proj_name .. pch_file .. ".hpp" -- force include precompiled h eader buildoptions( { opt } ) -- apply build options to proj ect --linkoptions( { "/NODEFAULTLIB:libcmtd.lib" } ) -- apply build option to igno re libcmtd --linkoptions( { "/NODEFAULTLIB:libcmt.lib" } ) -- apply build option to ignore libcmt configuration( "Debug" ) -- all following commands appl y to debug defines( { debug_defines } ) flags( { debug_flags } ) configuration( "Release" ) -- all followi ng commands apply to release defines( { release_defines } ) flags( { release_flags } ) end -- checking for nil lets --help action work if _ACTION ~= nil then -- Create Solution solution "SqueakyClean" configurations { "Debug", "Release" } ns here location( proj_dir.. _ACTION ) is created --postbuildcommands { "\"$(TargetPath)\"" } ild if _ACTION == "clean" then os.rmdir( "./Lib" ) os.rmdir( "./Temp" ) os.rmdir( "./Game" ) os.rmdir( "./Proj" ) end

-- define all configuratio -- Sets where the solition -- actions to run after bu

-- steps to perform on clean action -- portable rm

-- create clients, libraries, and tests for j = 1,3 do -- set default variable names precompiled_name = "Precompiled" if j == 1 then --create client projects app_type = "WindowedApp" location_path = proj_dir .. _ACTION .. "/Clients/" for i, proj in ipairs( clients ) do project( proj ) links( libraries ) SetUpProj( proj, app_type, location_path, precompiled_name, so urce_dir, game_dir ) end elseif j == 2 then --create test projects app_type = "ConsoleApp" location_path = proj_dir .. _ACTION .. "/Tests/" precompiled_name = "Precompiled"

for i, proj in ipairs( libraries ) do project_name = proj .. "Test" project( project_name ) links( proj ) SetUpProj( project_name, app_type, location_path, precompiled_name, test _dir, lib_dir ) end elseif j == 3 then --create library projects app_type = "StaticLib" location_path = proj_dir .. _ACTION .. "/Libs/" for i, proj in ipairs( libraries ) do project( proj ) SetUpProj( proj, app_type, location_path, precompiled_name, source _dir, lib_dir ) end end -- if/else end -- outer for loop end -- action is nil check

You might also like