This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9830 for ps


Ignore:
Timestamp:
07/15/11 19:56:57 (13 years ago)
Author:
philip
Message:

Premake4 build scripts for the game, from Yves (plus minor tweaks)

Location:
ps/trunk/build
Files:
1 edited
4 copied

Legend:

Unmodified
Added
Removed
  • ps/trunk/build/premake/extern_libs4.lua

    r9827 r9830  
    1 -- this file provides package_add_extern_libs, which takes care of the
     1-- this file provides project_add_extern_libs, which takes care of the
    22-- dirty details of adding the libraries' include and lib paths.
    33--
    44-- TYPICAL TASK: add new library. Instructions:
    55-- 1) add a new extern_lib_defs entry
    6 -- 2) add library name to extern_libs tables in premake.lua for all 'packages' that want to use it
     6-- 2) add library name to extern_libs tables in premake.lua for all 'projects' that want to use it
    77
    88
    99-- directory in which all library subdirectories reside.
    10 libraries_dir = "../../../libraries/"
    11 
    12 local function add_extern_lib_paths(extern_lib)
    13     -- Add '<libraries root>/<libraryname>/lib' and '/include' to the includepaths and libpaths
    14    
    15     -- Often, the headers in libraries/ are windows-specific (always, except
    16     -- for cxxtest and fcollada). So don't add the include dir unless on
    17     -- windows or processing one of those libs.
    18     if OS == "windows" or
    19         extern_lib == "cxxtest" or
    20         extern_lib == "fcollada" or
    21         extern_lib == "valgrind" or
    22         (extern_lib == "enet" and not options["with-system-enet"]) or
    23         (extern_lib == "nvtt" and not options["with-system-nvtt"])
    24     then
    25         tinsert(package.includepaths, libraries_dir .. extern_lib .. "/include")
    26         -- Insert libs at pos=1 (i.e. the front of the list) so they take
    27         -- precedence over system libraries
    28         tinsert(package.libpaths, 1, libraries_dir .. extern_lib .. "/lib")
    29     end
    30 
    31 end
    32 
    33 -- For unixes: add buildflags and linkflags from the given pkg-config module.
    34 local function pkgconfig(lib)
    35     tinsert(package.buildoptions, "`pkg-config "..lib.." --cflags`")
    36     tinsert(package.gnu_external, "`pkg-config "..lib.." --libs`")
    37 end
    38 
    39 -- library definitions
    40 -- in a perfect world, libraries would have a common installation template,
    41 -- i.e. location of include directory, naming convention for .lib, etc.
    42 -- this table provides a means of working around each library's differences.
    43 --
    44 -- the default assumptions are:
    45 -- * extern_lib (name of library [string]) is subdirectory of libraries_dir;
    46 -- * this directory contains include and lib subdirectories which hold the
    47 --   appendant files
    48 -- * debug import library and DLL are distinguished with a "d" suffix
    49 -- * the library should be marked for delay-loading.
    50 --
    51 -- the following options can override these:
    52 -- * win_names: table of import library / DLL names (no extension) when
    53 --   running on Windows.
    54 -- * unix_names: as above; shared object names when running on non-Windows.
    55 -- * osx_names: as above; for OS X specificall (overrides unix_names if both are
    56 --   specified)
    57 -- * linux_names: ditto for Linux (overrides unix_names if both given)
    58 --
    59 -- win- and unix-names are 'required'; if not specified, no linking against the
    60 -- library happens on platforms whose *_names are missing.
    61 -- (rationale: this allows for libraries that do not link against anything,
    62 -- e.g. Boost).
    63 --
    64 -- * dbg_suffix: changes the debug suffix from the above default.
    65 --   can be "" to indicate the library doesn't have a debug build;
    66 --   in that case, the same library (without suffix) is used in
    67 --   all build configurations.
    68 -- * no_delayload: indicate the library is not to be delay-loaded.
    69 --   this is necessary for some libraries that do not support it,
    70 --   e.g. Xerces (which is so stupid as to export variables).
    71 -- * add_func: a function that overrides everything else. responsible for
    72 --   setting include and library paths, adding .links (linker input), and
    73 --   arranging for delay-loading. this is necessary e.g. for wxWidgets,
    74 --   which is unfortunately totally incompatible with our
    75 --   library installation rules.
    76 -- * depends: a table of external libraries that this library depends on
    77 -- * defines: a table of symbols to define
    78 extern_lib_defs = {
    79     boost = {
    80         unix_names = { "boost_signals-mt", "boost_filesystem-mt", "boost_system-mt" },
    81         osx_names = { "boost_signals-mt", "boost_filesystem-mt", "boost_system-mt" }
    82     },
    83     cryptopp = {
    84         win_names  = { "cryptopp" },
    85         unix_names = { "cryptopp" },
    86     },
    87     cxxtest = {
    88     },
    89     misc = {
    90     },
    91     comsuppw = {
    92         win_names  = { "comsuppw" },
    93         dbg_suffix = "d",
    94         no_delayload = 1
    95     },
    96     devil = {
    97         unix_names = { "IL", "ILU" },
    98     },
    99     dl = {
    100         win_names  = { },
    101         unix_names = { "dl" },
    102     },
    103     enet = {
    104         win_names  = { "enet" },
    105         unix_names = { "enet" },
    106     },
    107     fcollada = {
    108         add_func = function()
    109             tinsert(package.includepaths, libraries_dir.."fcollada/include")
    110             tinsert(package.libpaths, libraries_dir.."fcollada/lib")
    111             if OS == "windows" then
    112                 tinsert(package.config["Debug"  ].links, "FColladaD")
    113                 tinsert(package.config["Testing"].links, "FCollada")
    114                 tinsert(package.config["Release"].links, "FCollada")
    115             else
    116                 tinsert(package.config["Debug"  ].links, "FColladaSD")
    117                 tinsert(package.config["Testing"].links, "FColladaSR")
    118                 tinsert(package.config["Release"].links, "FColladaSR")
    119             end
    120         end,
    121     },
    122     ffmpeg = {
    123         win_names  = { "avcodec-51", "avformat-51", "avutil-49", "swscale-0" },
    124         unix_names = { "avcodec", "avformat", "avutil" },
    125         dbg_suffix = "",
    126     },
    127     libcurl = {
    128         win_names  = { "libcurl" },
    129         unix_names = { "curl" },
    130     },
    131     libjpg = {
    132         win_names  = { "jpeg-6b" },
    133         unix_names = { "jpeg" },
    134     },
    135     libpng = {
    136         win_names  = { "libpng14" },
    137         unix_names = { "png" },
    138     },
    139     libxml2 = {
    140         add_func = function()
    141             if OS == "windows" then
    142                 tinsert(package.includepaths, libraries_dir.."libxml2/include")
    143                 tinsert(package.libpaths, libraries_dir.."libxml2/lib")
    144                 tinsert(package.config["Debug"  ].links, "libxml2")
    145                 tinsert(package.config["Testing"].links, "libxml2")
    146                 tinsert(package.config["Release"].links, "libxml2")
    147             else
    148                 pkgconfig("libxml-2.0")
    149                 -- libxml2 needs _REENTRANT or __MT__ for thread support;
    150                 -- OS X doesn't get either set by default, so do it manually
    151                 if OS == "macosx" then
    152                     tinsert(package.defines, "_REENTRANT")
    153                 end
    154             end
    155         end,
    156     },
    157     nvtt = {
    158         win_names  = { "nvtt" },
    159         unix_names = { "nvcore", "nvmath", "nvimage", "nvtt" },
    160         defines = { "NVTT_SHARED=1" },
    161         dbg_suffix = "", -- for performance we always use the Release-mode version
    162     },
    163     openal = {
    164         win_names  = { "openal32" },
    165         unix_names = { "openal" },
    166         osx_frameworks = { "OpenAL" },
    167         dbg_suffix = "",
    168     },
    169     opengl = {
    170         win_names  = { "opengl32", "gdi32" },
    171         unix_names = { "GL", "X11" },
    172         osx_frameworks = { "OpenGL" },
    173         dbg_suffix = "",
    174     },
    175     sdl = {
    176         add_func = function()
    177             add_extern_lib_paths("sdl")
    178             if OS ~= "windows" then
    179                 -- "pkg-config sdl --libs" appears to include both static and dynamic libs
    180                 -- when on MacPorts, which is bad, so use sdl-config instead
    181                 tinsert(package.buildoptions, "`sdl-config --cflags`")
    182                 tinsert(package.gnu_external, "`sdl-config --libs`")
    183             end
    184         end
    185     },
    186     spidermonkey = {
    187         add_func = function()
    188             if OS == "windows" then
    189                 include_dir = "include-win32"
    190             else
    191                 include_dir = "include-unix"
    192             end
    193             tinsert(package.config["Debug"  ].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/debug")
    194             tinsert(package.config["Testing"].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/debug")
    195             tinsert(package.config["Release"].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/release")
    196             tinsert(package.libpaths, libraries_dir.."spidermonkey-tip/lib")
    197             tinsert(package.config["Debug"  ].links, "mozjs-ps-debug")
    198             tinsert(package.config["Testing"].links, "mozjs-ps-release")
    199             tinsert(package.config["Release"].links, "mozjs-ps-release")
    200         end,
    201     },
    202     valgrind = {
    203     },
    204     vorbis = {
    205         win_names  = { "vorbisfile" },
    206         unix_names = { "vorbisfile" },
    207         dbg_suffix = "_d",
    208     },
    209     wxwidgets = {
    210         add_func = function()
    211             if OS == "windows" then
    212                 tinsert(package.includepaths, libraries_dir.."wxwidgets/include/msvc")
    213                 tinsert(package.includepaths, libraries_dir.."wxwidgets/include")
    214                 tinsert(package.libpaths, libraries_dir.."wxwidgets/lib/vc_lib")
    215                 tinsert(package.config["Debug"  ].links, "wxmsw28ud_gl")
    216                 tinsert(package.config["Testing"].links, "wxmsw28ud_gl")
    217                 tinsert(package.config["Release"].links, "wxmsw28u_gl")
    218             else
    219                 tinsert(package.buildoptions, "`wx-config --unicode=yes --cxxflags`")
    220                 tinsert(package.gnu_external, "`wx-config --unicode=yes --libs std,gl`")
    221             end
    222         end,
    223     },
    224     x11 = {
    225         win_names  = { },
    226         unix_names = { "X11" },
    227     },
    228     xerces = {
    229         win_names  = { "xerces-c_2" },
    230         unix_names = { "xerces-c" },
    231         no_delayload = 1,
    232     },
    233     zlib = {
    234         win_names  = { "zlib1" },
    235         unix_names = { "z" },
    236     },
    237 }
    238 
     10libraries_dir = rootdir.."/libraries/"
     11
     12local function add_default_lib_paths(extern_lib)
     13    libdirs { libraries_dir .. extern_lib .. "/lib" }
     14end
     15
     16local function add_default_include_paths(extern_lib)
     17    includedirs { libraries_dir .. extern_lib .. "/include" }
     18end
     19
     20
     21-- For unixes: add buildflags and linkflags using pkg-config or another similar command.
     22-- By default, pkg-config is used. Other commands can be passed as "alternative_cmd".
     23-- Running such commands at build/linktime does not work on all environments.
     24-- For those environments where it does not work, we already run it now.
     25-- Any better ideas?
     26local function pkgconfig_cflags(lib, alternative_cmd)
     27    local cmd_cflags = ""
     28    local result_cflags
     29    if not alternative_cmd then
     30        cmd_cflags = "pkg-config "..lib.." --cflags"
     31    else
     32        cmd_cflags = alternative_cmd
     33    end
     34
     35    if _ACTION == "xcode3" then
     36        result_cflags = string.gsub(os.capture(cmd_cflags), "\n", "")
     37        buildoptions { result_cflags }
     38    else
     39        buildoptions { "`"..cmd_cflags.."`" }
     40    end
     41end
     42
     43local function pkgconfig_libs(lib, alternative_cmd)
     44    local cmd_libs = ""
     45    local result_libs
     46    if not alternative_cmd then
     47        cmd_libs = "pkg-config "..lib.." --libs"
     48    else
     49        cmd_libs = alternative_cmd
     50    end
     51
     52    if _ACTION == "xcode3" then
     53        -- The syntax of -Wl with the comma separated list doesn't work and -Wl apparently isn't needed in xcode.
     54        -- This is a hack, but it works...
     55        result_libs = string.gsub(os.capture(cmd_libs), "-Wl", "")
     56        result_libs = string.gsub(result_libs, ",", " ")
     57        result_libs = string.gsub(result_libs, "\n", "")
     58        linkoptions { result_libs }
     59    else
     60        gnuexternals { "`"..cmd_libs.."`" }
     61    end
     62end
     63
     64function os.capture(cmd)
     65    local f = io.popen(cmd, 'r')
     66    local s = f:read('*a')
     67    return s
     68end
    23969
    24070local function add_delayload(name, suffix, def)
     
    24373        return
    24474    end
    245    
     75
    24676    -- currently only supported by VC; nothing to do on other platforms.
    247     if OS ~= "windows" then
     77    if not os.is("windows") then
    24878        return
    24979    end
     
    25181    -- no extra debug version; use same library in all configs
    25282    if suffix == "" then
    253         tinsert(package.linkoptions, "/DELAYLOAD:"..name..".dll")
     83        linkoptions { "/DELAYLOAD:"..name..".dll" }
    25484    -- extra debug version available; use in debug/testing config
    25585    else
     
    25787        local cmd     = "/DELAYLOAD:" .. name .. ".dll"
    25888
    259         tinsert(package.config["Debug"  ].linkoptions, dbg_cmd)
     89        configuration "Debug"
     90            linkoptions { dbg_cmd }
    26091        -- 'Testing' config uses 'Debug' DLLs
    261         tinsert(package.config["Testing"].linkoptions, dbg_cmd)
    262         tinsert(package.config["Release"].linkoptions, cmd)
    263     end
    264 
    265 end
    266 
    267 local function add_extern_lib(extern_lib, def)
    268 
    269     add_extern_lib_paths(extern_lib)
     92        configuration "Testing"
     93            linkoptions { dbg_cmd }
     94        configuration "Release"
     95            linkoptions { cmd }
     96        configuration { }
     97    end
     98
     99end
     100
     101local function add_default_links(def)
    270102
    271103    -- careful: make sure to only use *_names when on the correct platform.
    272104    local names = {}
    273     if OS == "windows" then
     105    if os.is("windows") then
    274106        if def.win_names then
    275107            names = def.win_names
    276108        end
    277     elseif OS == "linux" and def.linux_names then
     109    elseif os.is("linux") and def.linux_names then
    278110        names = def.linux_names
    279     elseif OS == "macosx" and def.osx_names then
     111    elseif os.is("macosx") and def.osx_names then
    280112        names = def.osx_names
    281113    elseif def.unix_names then
     
    291123    -- (to be more specific, they do, but the two are binary compatible;
    292124    -- usually only one type - debug or release - is installed at a time).
    293     if OS ~= "windows" then
     125    if not os.is("windows") then
    294126        suffix = ""
    295     end
    296 
    297     if def.defines then
    298         tinsert(package.defines, def.defines)
    299127    end
    300128
    301129    -- OS X "Frameworks" need to be added in a special way to the link
    302130    -- i.e. by linkoptions += "-framework ..."
    303     if OS == "macosx" and def.osx_frameworks then
     131    if os.is("macosx") and def.osx_frameworks then
    304132        for i,name in pairs(def.osx_frameworks) do
    305             tinsert(package.linkoptions, "-framework " .. name)
     133            linkoptions { "-framework " .. name }
    306134        end
    307135    else
    308136        for i,name in pairs(names) do
    309             tinsert(package.config["Debug"  ].links, name .. suffix)
     137            configuration "Debug"
     138                links { name .. suffix }
    310139            -- 'Testing' config uses 'Debug' DLLs
    311             tinsert(package.config["Testing"].links, name .. suffix)
    312             tinsert(package.config["Release"].links, name)
    313    
     140            configuration "Testing"
     141                links { name .. suffix }
     142            configuration "Release"
     143                links { name }
     144            configuration { }
     145
    314146            add_delayload(name, suffix, def)
    315147        end
     
    317149end
    318150
    319 
    320 -- add a set of external libraries to the package; takes care of
     151-- Library definitions
     152-- In a perfect world, libraries would have a common installation template,
     153-- i.e. location of include directory, naming convention for .lib, etc.
     154-- this table provides a means of working around each library's differences.
     155--
     156-- The basic approach is defining two functions per library:
     157--
     158-- 1. compile_settings
     159-- This function should set all settings requred during the compile-phase like
     160-- includedirs, defines etc...
     161--
     162-- 2. link_settings
     163-- This function should set all settings required during the link-phase like
     164-- libdirs, linkflag etc...
     165--
     166-- The main reason for separating those settings is different linking behaviour
     167-- on osx and xcode. For more details, read the comment in project_add_extern_libs.
     168--
     169-- There are some helper functions for the most common tasks. You should use them
     170-- if they can be used in your situation to make the definitions more consistent and
     171-- use their default beviours as a guideline.
     172--
     173--
     174-- add_default_lib_paths(extern_lib)
     175--      Description: Add '<libraries root>/<libraryname>/lib'to the libpaths
     176--      Parameters:
     177--          * extern_lib: <libraryname> to be used in the libpath.
     178--
     179-- add_default_include_paths(extern_lib)
     180--      Description: Add '<libraries root>/<libraryname>/include' to the includepaths
     181--      Parameters:
     182--          * extern_lib: <libraryname> to be used in the libpath.
     183--
     184-- add_default_links
     185--      Description: Adds links to libraries and configures delayloading.
     186--      If the *_names parameter for a plattform is missing, no linking will be done
     187--      on that plattform.
     188--      The default assumptions are:
     189--      * debug import library and DLL are distinguished with a "d" suffix
     190--      * the library should be marked for delay-loading.
     191--      Parameters:
     192--      * win_names: table of import library / DLL names (no extension) when
     193--        running on Windows.
     194--      * unix_names: as above; shared object names when running on non-Windows.
     195--      * osx_names: as above; for OS X specificall (overrides unix_names if both are
     196--        specified)
     197--      * linux_names: ditto for Linux (overrides unix_names if both given)
     198--      * dbg_suffix: changes the debug suffix from the above default.
     199--        can be "" to indicate the library doesn't have a debug build;
     200--        in that case, the same library (without suffix) is used in
     201--        all build configurations.
     202--      * no_delayload: indicate the library is not to be delay-loaded.
     203--        this is necessary for some libraries that do not support it,
     204--        e.g. Xerces (which is so stupid as to export variables).
     205
     206extern_lib_defs = {
     207    boost = {
     208        compile_settings = function()
     209            if os.is("windows") then
     210                add_default_include_paths("boost")
     211            end
     212        end,
     213        link_settings = function()
     214            if os.is("windows") then
     215                add_default_lib_paths("boost")
     216            end
     217            add_default_links({
     218                unix_names = { "boost_signals-mt", "boost_filesystem-mt", "boost_system-mt" },
     219                osx_names = { "boost_signals-mt", "boost_filesystem-mt", "boost_system-mt" },
     220            })
     221        end,
     222    },
     223    cryptopp = {
     224        compile_settings = function()
     225            if os.is("windows") then
     226                add_default_include_paths("cryptopp")
     227            end
     228        end,
     229        link_settings = function()
     230            if os.is("windows") then
     231                add_default_lib_paths("cryptopp")
     232            end
     233            add_default_links({
     234                win_names  = { "cryptopp" },
     235                unix_names = { "cryptopp" },
     236            })
     237        end,
     238    },
     239    cxxtest = {
     240        compile_settings = function()
     241            add_default_include_paths("cxxtest")
     242        end,
     243        link_settings = function()
     244            add_default_lib_paths("cxxtest")
     245        end,
     246    },
     247    comsuppw = {
     248        link_settings = function()
     249            add_default_links({
     250                win_names = { "comsuppw" },
     251                dbg_suffix = "d",
     252                no_delayload = 1,
     253            })
     254        end,
     255    },
     256    devil = {
     257        compile_settings = function()
     258            if os.is("windows") then
     259                add_default_include_paths("devil")
     260            end
     261        end,
     262        link_settings = function()
     263            -- On Windows, it uses #pragma comment(lib ...) to link the library,
     264            -- so we only need to include the library-search-path
     265            if os.is("windows") then
     266                add_default_lib_paths("devil")
     267            end
     268            add_default_links({
     269                unix_names = { "IL", "ILU" },
     270            })
     271        end,
     272    },
     273    enet = {
     274        compile_settings = function()
     275            if not _OPTIONS["with-system-enet"] then
     276                add_default_include_paths("enet")
     277            end
     278        end,
     279        link_settings = function()
     280            if not _OPTIONS["with-system-enet"] then
     281                add_default_lib_paths("enet")
     282            end
     283            add_default_links({
     284                win_names  = { "enet" },
     285                unix_names = { "enet" },
     286            })
     287        end,
     288    },
     289    fcollada = {
     290        compile_settings = function()
     291            add_default_include_paths("fcollada")
     292        end,
     293        link_settings = function()
     294            add_default_lib_paths("fcollada")
     295            if os.is("windows") then
     296                configuration "Debug"
     297                    links { "FColladaD" }
     298                configuration "Testing"
     299                    links { "FCollada" }
     300                configuration "Release"
     301                    links { "FCollada" }
     302                configuration { }
     303            else
     304                configuration "Debug"
     305                    links { "FColladaSD" }
     306                configuration "Testing"
     307                    links { "FColladaSR" }
     308                configuration "Release"
     309                    links { "FColladaSR" }
     310                configuration { }
     311            end
     312        end,
     313    },
     314    ffmpeg = {
     315        compile_settings = function()
     316            if os.is("windows") then
     317                add_default_include_paths("ffmpeg")
     318            end
     319        end,
     320        link_settings = function()
     321            if os.is("windows") then
     322                add_default_lib_paths("ffmpeg")
     323            end
     324            add_default_links({
     325                win_names = { "avcodec-51", "avformat-51", "avutil-49", "swscale-0" },
     326                unix_names = { "avcodec", "avformat", "avutil" },
     327                dbg_suffix = "",
     328            })
     329        end,
     330    },
     331    libcurl = {
     332        compile_settings = function()
     333            if os.is("windows") then
     334                add_default_include_paths("libcurl")
     335            end
     336        end,
     337        link_settings = function()
     338            if os.is("windows") then
     339                add_default_lib_paths("libcurl")
     340            end
     341            add_default_links({
     342                win_names  = { "libcurl" },
     343                unix_names = { "curl" },
     344            })
     345        end,
     346    },
     347    libjpg = {
     348        compile_settings = function()
     349            if os.is("windows") then
     350                add_default_include_paths("libjpg")
     351            end
     352        end,
     353        link_settings = function()
     354            if os.is("windows") then
     355                add_default_lib_paths("libjpg")
     356            end
     357            add_default_links({
     358                win_names  = { "jpeg-6b" },
     359                unix_names = { "jpeg" },
     360            })
     361        end,
     362    },
     363    libpng = {
     364        compile_settings = function()
     365            if os.is("windows") then
     366                add_default_include_paths("libpng")
     367            end
     368        end,
     369        link_settings = function()
     370            if os.is("windows") then
     371                add_default_lib_paths("libpng")
     372            end
     373            add_default_links({
     374                win_names  = { "libpng14" },
     375                unix_names = { "png" },
     376            })
     377        end,
     378    },
     379    libxml2 = {
     380        compile_settings = function()
     381            if os.is("windows") then
     382                add_default_include_paths("libxml2")
     383            else
     384                pkgconfig_cflags("libxml-2.0")
     385                -- libxml2 needs _REENTRANT or __MT__ for thread support;
     386                -- OS X doesn't get either set by default, so do it manually
     387                if os.is("macosx") then
     388                    defines { "_REENTRANT" }
     389                end
     390            end
     391        end,
     392        link_settings = function()
     393            if os.is("windows") then
     394                add_default_lib_paths("libxml2")
     395                configuration "Debug"
     396                    links { "libxml2" }
     397                configuration "Testing"
     398                    links { "libxml2" }
     399                configuration "Release"
     400                    links { "libxml2" }
     401                configuration { }
     402            else
     403                pkgconfig_libs("libxml-2.0")
     404            end
     405        end,
     406    },
     407    nvtt = {
     408        compile_settings = function()
     409            if not _OPTIONS["with-system-nvtt"] then
     410                add_default_include_paths("nvtt")
     411            end
     412            defines { "NVTT_SHARED=1" }
     413        end,
     414        link_settings = function()
     415            if not _OPTIONS["with-system-nvtt"] then
     416                add_default_lib_paths("nvtt")
     417            end
     418            add_default_links({
     419                win_names  = { "nvtt" },
     420                unix_names = { "nvcore", "nvmath", "nvimage", "nvtt" },
     421                dbg_suffix = "", -- for performance we always use the release-mode version
     422            })
     423        end,
     424    },
     425    openal = {
     426        compile_settings = function()
     427            if os.is("windows") then
     428                add_default_include_paths("openal")
     429            end
     430        end,
     431        link_settings = function()
     432            if os.is("windows") then
     433                add_default_lib_paths("openal")
     434            end
     435            add_default_links({
     436                win_names  = { "openal32" },
     437                unix_names = { "openal" },
     438                osx_frameworks = { "OpenAL" },
     439                dbg_suffix = "",
     440            })
     441        end,
     442    },
     443    opengl = {
     444        compile_settings = function()
     445            if os.is("windows") then
     446                add_default_include_paths("opengl")
     447            end
     448        end,
     449        link_settings = function()
     450            if os.is("windows") then
     451                add_default_lib_paths("opengl")
     452            end
     453            add_default_links({
     454                win_names  = { "opengl32", "gdi32" },
     455                unix_names = { "GL", "X11" },
     456                osx_frameworks = { "OpenGL" },
     457                dbg_suffix = "",
     458                no_delayload = 1, -- delayload seems to cause errors on startup
     459            })
     460        end,
     461    },
     462    sdl = {
     463        compile_settings = function()
     464            if os.is("windows") then
     465                add_default_include_paths("sdl")
     466            else
     467                -- "pkg-config sdl --libs" appears to include both static and dynamic libs
     468                -- when on MacPorts, which is bad, so use sdl-config instead
     469                pkgconfig_cflags(nil, "sdl-config --cflags")
     470            end
     471        end,
     472        link_settings = function()
     473            if os.is("windows") then
     474                add_default_lib_paths("sdl")
     475            else
     476                pkgconfig_libs(nil, "sdl-config --libs")
     477            end
     478        end,
     479    },
     480    spidermonkey = {
     481        compile_settings = function()
     482            if os.is("windows") then
     483                include_dir = "include-win32"
     484            else
     485                include_dir = "include-unix"
     486            end
     487            configuration "Debug"
     488                includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/debug" }
     489            configuration "Testing"
     490                includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/debug" }
     491            configuration "Release"
     492                includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/release" }
     493            configuration { }
     494        end,
     495        link_settings = function()
     496            configuration "Debug"
     497                links { "mozjs-ps-debug" }
     498            configuration "Testing"
     499                links { "mozjs-ps-debug" }
     500            configuration "Release"
     501                links { "mozjs-ps-release" }
     502            configuration { }
     503            add_default_lib_paths("spidermonkey-tip")
     504        end,
     505    },
     506    valgrind = {
     507        compile_settings = function()
     508            add_default_include_paths("valgrind")
     509        end,
     510        link_settings = function()
     511            add_default_lib_paths("valgrind")
     512        end,
     513    },
     514    vorbis = {
     515        compile_settings = function()
     516            if os.is("windows") then
     517                add_default_include_paths("vorbis")
     518            end
     519        end,
     520        link_settings = function()
     521            if os.is("windows") then
     522                add_default_lib_paths("vorbis")
     523            end
     524            add_default_links({
     525                win_names  = { "vorbisfile" },
     526                unix_names = { "vorbisfile" },
     527                dbg_suffix = "_d",
     528            })
     529        end,
     530    },
     531    wxwidgets = {
     532        compile_settings = function()
     533            if os.is("windows") then
     534                includedirs { libraries_dir.."wxwidgets/include/msvc" }
     535                add_default_include_paths("wxwidgets")
     536            else
     537                pkgconfig_cflags(nil, "wx-config --unicode=yes --cxxflags")
     538            end
     539        end,
     540        link_settings = function()
     541            if os.is("windows") then
     542                libdirs { libraries_dir.."wxwidgets/lib/vc_lib" }
     543                configuration "Debug"
     544                    links { "wxmsw28ud_gl" }
     545                configuration "Testing"
     546                    links { "wxmsw28ud_gl" }
     547                configuration "Release"
     548                    links { "wxmsw28u_gl" }
     549                configuration { }
     550            else
     551                pkgconfig_libs(nil, "wx-config --unicode=yes --libs std,gl")
     552            end
     553        end,
     554    },
     555    x11 = {
     556        link_settings = function()
     557            add_default_links({
     558                win_names  = { },
     559                unix_names = { "X11" },
     560            })
     561        end,
     562    },
     563    xerces = {
     564        compile_settings = function()
     565            if os.is("windows") then
     566                add_default_include_paths("xerces")
     567            end
     568        end,
     569        link_settings = function()
     570            if os.is("windows") then
     571                add_default_lib_paths("xerces")
     572            end
     573            add_default_links({
     574                win_names  = { "xerces-c_2" },
     575                unix_names = { "xerces-c" },
     576                no_delayload = 1,
     577            })
     578        end,
     579    },
     580    zlib = {
     581        compile_settings = function()
     582            if os.is("windows") then
     583                add_default_include_paths("zlib")
     584            end
     585        end,
     586        link_settings = function()
     587            if os.is("windows") then
     588                add_default_lib_paths("zlib")
     589            end
     590            add_default_links({
     591                win_names  = { "zlib1" },
     592                unix_names = { "z" },
     593            })
     594        end,
     595    },
     596}
     597
     598
     599-- add a set of external libraries to the project; takes care of
    321600-- include / lib path and linking against the import library.
    322601-- extern_libs: table of library names [string]
    323 function package_add_extern_libs(extern_libs)
    324 
    325     local function add_with_deps(libs, lib)
    326         local def = extern_lib_defs[lib]
    327         assert(def, "external library " .. lib .. " not defined")
    328         tinsert(libs, lib)
    329         if def.depends then
    330             for i,dep in pairs(def.depends) do
    331                 add_with_deps(libs, dep)
    332             end
     602-- target_type: String defining the projects kind [string]
     603function project_add_extern_libs(extern_libs, target_type)
     604
     605    for i,extern_lib in pairs(extern_libs) do
     606        local def = extern_lib_defs[extern_lib]
     607        assert(def, "external library " .. extern_lib .. " not defined")
     608
     609        if def.compile_settings then
     610            def.compile_settings()
    333611        end
    334     end
    335 
    336     local libs = {}
    337 
    338     for i,extern_lib in pairs(extern_libs) do
    339         add_with_deps(libs, extern_lib)
    340     end
    341 
    342     for i,extern_lib in pairs(libs) do
    343         local def = extern_lib_defs[extern_lib]
    344 
    345         if def.add_func then
    346             def.add_func()
    347         else
    348             add_extern_lib(extern_lib, def)
     612
     613        -- Linking to external libraries will only be done in the main executable and not in the
     614        -- static libraries. Premake would silently skip linking into static libraries for some
     615        -- actions anyway (e.g. vs2010).
     616        -- On osx using xcode, if this linking would be defined in the static libraries, it would fail to
     617        -- link if only dylibs are available. If both *.a and *.dylib are available, it would link statically.
     618        -- I couldn't find any problems with that approach.
     619        if target_type ~= "StaticLib" and def.link_settings then
     620            def.link_settings()
    349621        end
    350622    end
    351623
    352     if OS == "macosx" then
     624    if os.is("macosx") then
    353625        -- MacPorts uses /opt/local as the prefix for most of its libraries,
    354626        -- which isn't on the default compiler's default include path.
     
    356628        -- our versions take precedence over the system versions (especially
    357629        -- for SpiderMonkey), which means we have to do it per-config
    358         tinsert(package.config["Debug"  ].includepaths, "/opt/local/include")
    359         tinsert(package.config["Testing"].includepaths, "/opt/local/include")
    360         tinsert(package.config["Release"].includepaths, "/opt/local/include")
    361         tinsert(package.config["Debug"  ].libpaths, "/opt/local/lib")
    362         tinsert(package.config["Testing"].libpaths, "/opt/local/lib")
    363         tinsert(package.config["Release"].libpaths, "/opt/local/lib")
    364     end
    365 end
     630        configuration "Debug"
     631            includedirs { "/opt/local/include" }
     632            libdirs { "/opt/local/lib" }
     633        configuration "Testing"
     634            includedirs { "/opt/local/include" }
     635            libdirs { "/opt/local/lib" }
     636        configuration "Release"
     637            includedirs { "/opt/local/include" }
     638            libdirs { "/opt/local/lib" }
     639        configuration { }
     640    end
     641end
  • ps/trunk/build/premake/premake4.lua

    r9827 r9830  
    1 addoption("atlas", "Include Atlas scenario editor packages")
    2 addoption("collada", "Include COLLADA packages (requires FCollada library)")
    3 addoption("coverage", "Enable code coverage data collection (GCC only)")
    4 addoption("aoe3ed", "Include AoE3Ed")
    5 addoption("icc", "Use Intel C++ Compiler (Linux only; should use either \"--cc icc\" or --without-pch too, and then set CXX=icpc before calling make)")
    6 addoption("outpath", "Location for generated project files")
    7 addoption("without-tests", "Disable generation of test projects")
    8 addoption("without-pch", "Disable generation and usage of precompiled headers")
    9 addoption("with-system-nvtt", "Search standard paths for the nvidia-texture-tools library, instead of using bundled copy")
    10 addoption("with-system-enet", "Search standard paths for libenet, instead of using bundled copy")
    11 addoption("bindir", "Directory for executables (typically '/usr/games'); default is to be relocatable")
    12 addoption("datadir", "Directory for data files (typically '/usr/share/games/0ad'); default is ../data/ relative to executable")
    13 addoption("libdir", "Directory for libraries (typically '/usr/lib/games/0ad'); default is ./ relative to executable")
    14 
    15 dofile("functions.lua")
    16 dofile("extern_libs.lua")
     1newoption { trigger = "atlas", description = "Include Atlas scenario editor projects" }
     2newoption { trigger = "collada", description = "Include COLLADA projects (requires FCollada library)" }
     3newoption { trigger = "coverage", description = "Enable code coverage data collection (GCC only)" }
     4newoption { trigger = "aoe3ed", description = "Include AoE3Ed" }
     5newoption { trigger = "icc", description = "Use Intel C++ Compiler (Linux only; should use either \"--cc icc\" or --without-pch too, and then set CXX=icpc before calling make)" }
     6newoption { trigger = "outpath", description = "Location for generated project files" }
     7newoption { trigger = "without-tests", description = "Disable generation of test projects" }
     8newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" }
     9newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" }
     10newoption { trigger = "with-system-enet", description = "Search standard paths for libenet, instead of using bundled copy" }
     11newoption { trigger = "bindir", description = "Directory for executables (typically '/usr/games'); default is to be relocatable" }
     12newoption { trigger = "datadir", description = "Directory for data files (typically '/usr/share/games/0ad'); default is ../data/ relative to executable" }
     13newoption { trigger = "libdir", description = "Directory for libraries (typically '/usr/lib/games/0ad'); default is ./ relative to executable" }
     14
     15-- Root directory of project checkout relative to this .lua file
     16rootdir = "../.."
     17
     18dofile("extern_libs4.lua")
    1719
    1820-- detect CPU architecture (simplistic, currently only supports x86 and amd64)
    1921arch = "x86"
    20 if OS == "windows" then
     22if os.is("windows") then
    2123    if os.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then
    2224        arch = "amd64"
     
    4143end
    4244
    43 -- Set up the Project
    44 project.name = "pyrogenesis"
    45 project.bindir   = "../../binaries/system"
    46 project.libdir   = "../../binaries/system"
    47 project.debugdir = "../../binaries/system"
    48 if not options["outpath"] then
     45
     46-- Set up the Solution
     47solution "pyrogenesis"
     48targetdir(rootdir.."/binaries/system")
     49libdirs(rootdir.."/binaries/system")
     50if not _OPTIONS["outpath"] then
    4951    error("You must specify the 'outpath' parameter")
    5052end
    51 project.path = options["outpath"]
    52 project.configs = { "Debug", "Release", "Testing" }
    53 
    54 if OS == "windows" then
    55     project.nasmpath = "../../build/bin/nasm.exe"
    56     project.cxxtestpath = "../../build/bin/cxxtestgen.exe"
     53location(_OPTIONS["outpath"])
     54configurations { "Release", "Debug", "Testing" }
     55
     56-- Get some environement specific information used later.
     57if os.is("windows") then
     58    nasmpath(rootdir.."/build/bin/nasm.exe")
     59    lcxxtestpath = rootdir.."/build/bin/cxxtestgen.exe"
    5760    has_broken_pch = false
    5861else
    59     project.cxxtestpath = "../../build/bin/cxxtestgen.pl"
    60     if OS == "linux" and arch == "amd64" then
    61         -- Hack for amd64 linux - tell nasm to product 64-bit elf.
    62         project.nasmformat = "elf64"
    63     elseif OS == "macosx" and arch == "amd64" then
    64         project.nasmformat = "macho64"
     62
     63    lcxxtestpath = rootdir.."/build/bin/cxxtestgen.pl"
     64
     65    if os.is("linux") and arch == "amd64" then
     66        nasmformat "elf64"
     67    elseif os.is("macosx") and arch == "amd64" then
     68        nasmformat "macho64"
     69    elseif os.is("macosx") then
     70        nasmformat "macho"
     71    else
     72        nasmformat "elf"
    6573    end
    6674
     
    7179    -- do the test in this build script instead (which is kind of ugly - please fix if
    7280    -- you have a better idea)
    73     if not options["icc"] then
     81    if not _OPTIONS["icc"] then
    7482        os.execute("gcc -dumpversion > .gccver.tmp")
    7583        local f = io.open(".gccver.tmp", "r")
     
    8593end
    8694
    87 source_root = "../../../source/" -- default for most projects - overridden by local in others
    88 
    89 -- Rationale: packages should not have any additional include paths except for
     95source_root = rootdir.."/source/" -- default for most projects - overridden by local in others
     96
     97-- Rationale: projects should not have any additional include paths except for
    9098-- those required by external libraries. Instead, we should always write the
    9199-- full relative path, e.g. #include "maths/Vector3d.h". This avoids confusion
     
    93101
    94102
    95 -- packages: engine static libs, main exe, atlas, atlas frontends, test.
    96 
     103-- projects: engine static libs, main exe, atlas, atlas frontends, test.
    97104
    98105--------------------------------------------------------------------------------
    99 -- package helper functions
     106-- project helper functions
    100107--------------------------------------------------------------------------------
    101108
    102 function package_set_target(package_name)
     109function project_set_target(project_name)
    103110
    104111    -- Note: On Windows, ".exe" is added on the end, on unices the name is used directly
    105     package.config["Debug"  ].target = package_name.."_dbg"
    106     package.config["Testing"].target = package_name.."_test"
    107     package.config["Release"].target = package_name
    108 
    109     local obj_dir_prefix = "obj/"..package_name.."_"
    110     package.config["Debug"  ].objdir = obj_dir_prefix.."Debug"
    111     package.config["Testing"].objdir = obj_dir_prefix.."Test"
    112     package.config["Release"].objdir = obj_dir_prefix.."Release"
    113 end
    114 
    115 
    116 function package_set_build_flags()
    117 
    118     package.buildflags = { "with-symbols", "no-edit-and-continue" }
    119     if not options["icc"] then
     112
     113    local obj_dir_prefix = _OPTIONS["outpath"].."/obj/"..project_name.."_"
     114
     115    configuration "Debug"
     116        objdir(obj_dir_prefix.."Debug")
     117        targetsuffix("_dbg")
     118
     119    configuration "Testing"
     120        objdir(obj_dir_prefix.."Test")
     121        targetsuffix("_test")
     122
     123    configuration "Release"
     124        objdir(obj_dir_prefix.."Release")
     125
     126    configuration { }
     127
     128end
     129
     130
     131function project_set_build_flags()
     132
     133    flags { "Symbols", "NoEditAndContinue" }
     134    if not _OPTIONS["icc"] then
    120135        -- adds the -Wall compiler flag
    121         tinsert(package.buildflags, "extra-warnings") -- this causes far too many warnings/remarks on ICC
    122     end
    123 
    124     -- PremakeWiki says with-symbols and optimize are automatically set for
    125     -- Debug and Release builds, respectively. doesn't happen though, so do it manually.
    126 
    127     package.config["Debug"].defines = { "DEBUG" }
    128 
    129     package.config["Testing"].buildflags = { "no-runtime-checks" }
    130     package.config["Testing"].defines = { "TESTING" }
    131 
    132     package.config["Release"].buildflags = { "no-runtime-checks", "optimize-speed" }
    133     package.config["Release"].defines = { "NDEBUG", "CONFIG_FINAL=1" }
    134 
    135     -- required for the lowlevel library. must be set from all packages that use it, otherwise it assumes it is
     136        flags { "ExtraWarnings" } -- this causes far too many warnings/remarks on ICC
     137    end
     138
     139    configuration "Debug"
     140        defines { "DEBUG" }
     141
     142    configuration "Testing"
     143        defines { "TESTING" }
     144
     145    configuration "Release"
     146        flags { "OptimizeSpeed" }
     147        defines { "NDEBUG", "CONFIG_FINAL=1" }
     148
     149    configuration { }
     150
     151    -- required for the lowlevel library. must be set from all projects that use it, otherwise it assumes it is
    136152    -- being used as a DLL (which is currently not the case in 0ad)
    137     tinsert(package.defines, "LIB_STATIC_LINK")
    138    
     153    defines { "LIB_STATIC_LINK" }
     154
    139155    -- various platform-specific build flags
    140     if OS == "windows" then
     156    if os.is("windows") then
    141157
    142158        -- use native wchar_t type (not typedef to unsigned short)
    143         tinsert(package.buildflags, "native-wchar_t")
     159        flags { "NativeWChar" }
    144160
    145161    else    -- *nix
    146         if options["icc"] then
    147             tinsert(package.buildoptions, {
     162        if _OPTIONS["icc"] then
     163            buildoptions {
    148164                "-w1",
    149165                -- "-Wabi",
     
    155171                "-Wunknown-pragmas",
    156172                "-Wunused-function",
    157                 "-wd1292", -- avoid lots of 'attribute "__nonnull__" ignored'
    158             })
    159             tinsert(package.config["Debug"].buildoptions, {
    160                 "-O0", -- ICC defaults to -O2
    161             })
    162             if OS == "macosx" then
    163                 tinsert(package.linkoptions, {"-multiply_defined","suppress"})
     173                "-wd1292" -- avoid lots of 'attribute "__nonnull__" ignored'
     174            }
     175            configuration "Debug"
     176                buildoptions { "-O0" } -- ICC defaults to -O2
     177            configuration { }
     178            if os.is("macosx") then
     179                linkoptions { "-multiply_defined","suppress" }
    164180            end
    165181        else
    166             tinsert(package.buildoptions, {
     182            buildoptions {
    167183                -- enable most of the standard warnings
    168184                "-Wno-switch",      -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
     
    198214                -- negatively by the way this breaks profilers more than it will be impacted
    199215                -- positively by the optimisation
    200                 "-fno-omit-frame-pointer",
    201             })
    202 
    203             if OS == "linux" then
    204                 tinsert(package.linkoptions, {
    205                     "-Wl,--no-undefined",
    206                     "-Wl,--as-needed",
    207                 })
     216                "-fno-omit-frame-pointer"
     217            }
     218
     219            if os.is("linux") then
     220                linkoptions { "-Wl,--no-undefined", "-Wl,--as-needed" }
    208221            end
    209222
    210             if options["coverage"] then
    211                 tinsert(package.buildoptions, {"-fprofile-arcs", "-ftest-coverage"})
    212                 tinsert(package.links, "gcov")
     223            if _OPTIONS["coverage"] then
     224                buildoptions { "-fprofile-arcs", "-ftest-coverage" }
     225                links { "gcov" }
    213226            end
    214227
     
    216229            -- we need to set -march to something that supports them
    217230            if arch == "x86" then
    218                 tinsert(package.buildoptions, "-march=i686")
     231                buildoptions { "-march=i686" }
    219232            end
    220233
    221234            -- We don't want to require SSE2 everywhere yet, but OS X headers do
    222235            -- require it (and Intel Macs always have it) so enable it here
    223             if OS == "macosx" then
    224                 tinsert(package.buildoptions, "-msse2")
     236            if os.is("macosx") then
     237                buildoptions { "-msse2" }
    225238            end
    226239        end
    227240
    228         tinsert(package.buildoptions, {
     241        buildoptions {
    229242            -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
    230243            -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
    231             "-fvisibility=hidden",
    232         })
     244            "-fvisibility=hidden"
     245        }
    233246
    234247        -- X11 includes may be installed in one of a gadzillion of three places
    235248        -- Famous last words: "You can't include too much! ;-)"
    236         package.includepaths = {
     249        includedirs {
    237250            "/usr/X11R6/include/X11",
    238251            "/usr/X11R6/include",
    239252            "/usr/include/X11"
    240253        }
    241         package.libpaths = {
    242             "/usr/X11R6/lib"
    243         }
    244 
    245         if options["bindir"] then
    246             tinsert(package.defines, "INSTALLED_BINDIR=" .. options["bindir"])
     254        libdirs { "/usr/X11R6/lib" }
     255
     256        if _OPTIONS["bindir"] then
     257            defines { "INSTALLED_BINDIR=" .. _OPTIONS["bindir"] }
    247258        end
    248         if options["datadir"] then
    249             tinsert(package.defines, "INSTALLED_DATADIR=" .. options["datadir"])
     259        if _OPTIONS["datadir"] then
     260            defines { "INSTALLED_DATADIR=" .. _OPTIONS["datadir"] }
    250261        end
    251         if options["libdir"] then
    252             tinsert(package.defines, "INSTALLED_LIBDIR=" .. options["libdir"])
     262        if _OPTIONS["libdir"] then
     263            defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] }
    253264        end
    254265
    255         if OS == "linux" then
     266        if os.is("linux") then
    256267            -- To use our local SpiderMonkey library, it needs to be part of the
    257268            -- runtime dynamic linker path. Add it with -rpath to make sure it gets found.
    258             if options["libdir"] then
    259                 tinsert(package.linkoptions, {"-Wl,-rpath=" .. options["libdir"]})
     269            if _OPTIONS["libdir"] then
     270                linkoptions {"-Wl,-rpath=" .. _OPTIONS["libdir"] }
    260271            else
    261272                -- Add the executable path:
    262                 tinsert(package.linkoptions, {"-Wl,-rpath='$$ORIGIN'"}) -- use Makefile escaping of '$'
     273                linkoptions { "-Wl,-rpath='$$ORIGIN'" } -- use Makefile escaping of '$'
    263274            end
    264275        end
     
    268279
    269280
    270 -- create a package and set the attributes that are common to all packages.
    271 function package_create(package_name, target_type)
    272 
    273     -- Note: don't store in local variable. A global variable needs to
    274     -- be set for Premake's use; it is implicitly used in e.g. matchfiles()
    275     package = newpackage()
    276     package.path = project.path
    277     package.language = "c++"
    278     package.name = package_name
    279     package.kind = target_type
    280 
    281     package.includepaths = {}
    282 
    283     package_set_target(package_name)
    284     package_set_build_flags()
    285 
    286     return package
    287 end
    288 
    289 
     281-- create a project and set the attributes that are common to all projects.
     282function project_create(project_name, target_type)
     283
     284    project(project_name)
     285    language "C++"
     286    kind(target_type)
     287
     288    project_set_target(project_name)
     289    project_set_build_flags()
     290end
     291
     292
     293-- source_root: rel_source_dirs and rel_include_dirs are relative to this directory
     294-- rel_source_dirs: A table of subdirectories. All source files in these directories are added.
     295-- rel_include_dirs: A table of subdirectories to be included.
    290296-- extra_params: table including zero or more of the following:
    291 -- * no_default_pch: (any type) prevents adding the PCH include dir.
    292 --   see setup_static_lib_package() for explanation of this scheme and rationale.
     297-- * no_pch: If specified, no precompiled headers are used for this project.
     298-- * pch_dir: If specified, this directory will be used for precompiled headers instead of the default
     299--   <source_root>/pch/<projectname>/.
    293300-- * extra_files: table of filenames (relative to source_root) to add to project
    294301-- * extra_links: table of library names to add to link step
    295 function package_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
    296 
    297     -- We don't want the VC project to be deeply nested (once for each
    298     -- folder in source_root). Therefore, remove the source_root
    299     -- directory from the filenames (where those
    300     -- names are used by Premake to construct the project tree), but set
    301     -- 'trimprefix' (with Premake altered to recognise that) so the project
    302     -- will still point to the correct filenames.
    303     package.trimprefix = source_root
    304     package.files = sourcesfromdirs(source_root, rel_source_dirs)
     302function project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
     303
     304    for i,v in pairs(rel_source_dirs) do
     305        local prefix = source_root..v.."/"
     306        files { prefix.."*.cpp", prefix.."*.h", prefix.."*.inl", prefix.."*.js", prefix.."*.asm" }
     307    end
    305308
    306309    -- Put the project-specific PCH directory at the start of the
    307310    -- include path, so '#include "precompiled.h"' will look in
    308311    -- there first
    309     if not extra_params["no_default_pch"] then
    310         tinsert(package.includepaths, source_root .. "pch/" .. package.name)
    311     end
    312 
    313     -- next is source root dir, for absolute (nonrelative) includes
    314     -- (e.g. "lib/precompiled.h")
    315     tinsert(package.includepaths, source_root)
    316 
    317     for i,v in pairs(rel_include_dirs) do
    318         tinsert(package.includepaths, source_root .. v)
    319     end
    320 
    321 
    322     if extra_params["extra_files"] then
    323         for i,v in pairs(extra_params["extra_files"]) do
    324             tinsert(package.files, source_root .. v)
    325         end
    326     end
    327 
    328     if extra_params["extra_links"] then
    329         listconcat(package.links, extra_params["extra_links"])
    330     end
    331 
    332 end
    333 
    334 -- Detect and set up PCH for the current package
    335 function package_setup_pch(pch_dir, header, source)
    336     if OS == "windows" or not options["without-pch"] then
    337         package.pchheader = header -- "precompiled.h"
    338         package.pchsource = source -- "precompiled.cpp"
    339         if pch_dir then
    340             tinsert(package.files, {
    341                 pch_dir..header,
    342                 pch_dir..source
    343             })
    344         end
    345         for i,v in pairs(project.configs) do
    346             tinsert(package.config[v].defines, "USING_PCH")
    347         end
    348     end
    349 end
    350 
    351 --------------------------------------------------------------------------------
    352 -- engine static libraries
    353 --------------------------------------------------------------------------------
    354 
    355 -- the engine is split up into several static libraries. this eases separate
    356 -- distribution of those components, reduces dependencies a bit, and can
    357 -- also speed up builds.
    358 -- more to the point, it is necessary to efficiently support a separate
    359 -- test executable that also includes much of the game code.
    360 
    361 -- names of all static libs created. automatically added to the
    362 -- main app project later (see explanation at end of this file)
    363 static_lib_names = {}
    364 
    365 -- set up one of the static libraries into which the main engine code is split.
    366 -- extra_params: see package_add_contents().
    367 -- note: rel_source_dirs and rel_include_dirs are relative to global source_root.
    368 function setup_static_lib_package (package_name, rel_source_dirs, extern_libs, extra_params)
    369 
    370     package_create(package_name, "lib")
    371     package_add_contents(source_root, rel_source_dirs, {}, extra_params)
    372     package_add_extern_libs(extern_libs)
    373 
    374     if not extra_params["no_default_link"] then
    375         tinsert(static_lib_names, package_name)
    376     end
    377 
    378     if OS == "windows" then
    379         tinsert(package.buildflags, "no-rtti")
    380     end
     312    local pch_dir
     313    if not extra_params["pch_dir"] then
     314        pch_dir = source_root .. "pch/" .. project().name .. "/"
     315    else
     316        pch_dir = extra_params["pch_dir"]
     317    end
     318    includedirs { pch_dir }
    381319
    382320    -- Precompiled Headers
    383321    -- rationale: we need one PCH per static lib, since one global header would
    384322    -- increase dependencies. To that end, we can either include them as
    385     -- "packagedir/precompiled.h", or add "source/PCH/packagedir" to the
     323    -- "projectdir/precompiled.h", or add "source/PCH/projectdir" to the
    386324    -- include path and put the PCH there. The latter is better because
    387     -- many packages contain several dirs and it's unclear where there the
     325    -- many projects contain several dirs and it's unclear where there the
    388326    -- PCH should be stored. This way is also a bit easier to use in that
    389327    -- source files always include "precompiled.h".
     
    393331    -- * precompiled.cpp (needed to "Create" the PCH) also goes in
    394332    --   the abovementioned dir.
    395     if not extra_params["no_default_pch"] then
    396         pch_dir = source_root.."pch/"..package_name.."/"
    397         package_setup_pch(pch_dir, "precompiled.h", "precompiled.cpp")
    398     end
    399 end
     333    if (not _OPTIONS["without-pch"] and not extra_params["no_pch"]) then
     334        pchheader(pch_dir.."precompiled.h")
     335        pchsource(pch_dir.."precompiled.cpp")
     336        defines { "USING_PCH" }
     337        files { pch_dir.."precompiled.h", pch_dir.."precompiled.cpp" }
     338    else
     339        flags { "NoPCH" }
     340    end
     341
     342    -- next is source root dir, for absolute (nonrelative) includes
     343    -- (e.g. "lib/precompiled.h")
     344    includedirs { source_root }
     345
     346    for i,v in pairs(rel_include_dirs) do
     347        includedirs { source_root .. v }
     348    end
     349
     350    if extra_params["extra_files"] then
     351        for i,v in pairs(extra_params["extra_files"]) do
     352            -- .rc files are only needed on Windows
     353            if path.getextension(v) ~= ".rc" or os.is("windows") then
     354                files { source_root .. v }
     355            end
     356        end
     357    end
     358
     359    if extra_params["extra_links"] then
     360        links { extra_params["extra_links"] }
     361    end
     362end
     363
     364
     365--------------------------------------------------------------------------------
     366-- engine static libraries
     367--------------------------------------------------------------------------------
     368
     369-- the engine is split up into several static libraries. this eases separate
     370-- distribution of those components, reduces dependencies a bit, and can
     371-- also speed up builds.
     372-- more to the point, it is necessary to efficiently support a separate
     373-- test executable that also includes much of the game code.
     374
     375-- names of all static libs created. automatically added to the
     376-- main app project later (see explanation at end of this file)
     377static_lib_names = {}
     378
     379-- set up one of the static libraries into which the main engine code is split.
     380-- extra_params:
     381--  no_default_link: If specified, linking won't be done by default.
     382--  For the rest of extra_params, see project_add_contents().
     383-- note: rel_source_dirs and rel_include_dirs are relative to global source_root.
     384function setup_static_lib_project (project_name, rel_source_dirs, extern_libs, extra_params)
     385
     386    local target_type = "StaticLib"
     387    project_create(project_name, target_type)
     388    project_add_contents(source_root, rel_source_dirs, {}, extra_params)
     389    project_add_extern_libs(extern_libs, target_type)
     390
     391    if not extra_params["no_default_link"] then
     392        table.insert(static_lib_names, project_name)
     393    end
     394
     395    if os.is("windows") then
     396        flags { "NoRTTI" }
     397    end
     398end
     399
    400400
    401401-- this is where the source tree is chopped up into static libs.
    402 -- can be changed very easily; just copy+paste a new setup_static_lib_package,
     402-- can be changed very easily; just copy+paste a new setup_static_lib_project,
    403403-- or remove existing ones. static libs are automagically added to
    404404-- main_exe link step.
     
    410410    local extern_libs = {}
    411411
    412    
     412
    413413    source_dirs = {
    414414        "network",
     
    419419        "boost",    -- dragged in via server->simulation.h->random
    420420    }
    421     setup_static_lib_package("network", source_dirs, extern_libs, {})
     421    setup_static_lib_project("network", source_dirs, extern_libs, {})
    422422
    423423
     
    436436        "spidermonkey",
    437437    }
    438     setup_static_lib_package("simulation2", source_dirs, extern_libs, {})
     438    setup_static_lib_project("simulation2", source_dirs, extern_libs, {})
    439439
    440440
     
    447447        "valgrind",
    448448    }
    449     setup_static_lib_package("scriptinterface", source_dirs, extern_libs, {})
     449    setup_static_lib_project("scriptinterface", source_dirs, extern_libs, {})
    450450
    451451
     
    471471        "libcurl",
    472472    }
    473     setup_static_lib_package("engine", source_dirs, extern_libs, {})
     473    setup_static_lib_project("engine", source_dirs, extern_libs, {})
    474474
    475475
     
    486486        "boost"
    487487    }
    488     setup_static_lib_package("graphics", source_dirs, extern_libs, {})
     488    setup_static_lib_project("graphics", source_dirs, extern_libs, {})
    489489
    490490
     
    499499        "spidermonkey"
    500500    }
    501     setup_static_lib_package("atlas", source_dirs, extern_libs, {})
     501    setup_static_lib_project("atlas", source_dirs, extern_libs, {})
    502502
    503503
     
    506506        "gui/scripting"
    507507    }
    508     if OS == "windows" then -- add JS files to allow VS find-in-solution and VA open-file-in-workspace
    509         tinsert(source_dirs, "../binaries/data/mods/public/gui/test")
    510     end
    511508    extern_libs = {
    512509        "spidermonkey",
     
    515512        "boost"
    516513    }
    517     setup_static_lib_package("gui", source_dirs, extern_libs, {})
     514    setup_static_lib_project("gui", source_dirs, extern_libs, {})
    518515
    519516
     
    551548    -- CPU architecture-specific
    552549    if arch == "amd64" then
    553         tinsert(source_dirs, "lib/sysdep/arch/amd64");
    554         tinsert(source_dirs, "lib/sysdep/arch/x86_x64");
     550        table.insert(source_dirs, "lib/sysdep/arch/amd64");
     551        table.insert(source_dirs, "lib/sysdep/arch/x86_x64");
    555552    else
    556         tinsert(source_dirs, "lib/sysdep/arch/ia32");
    557         tinsert(source_dirs, "lib/sysdep/arch/x86_x64");
    558     end
    559    
     553        table.insert(source_dirs, "lib/sysdep/arch/ia32");
     554        table.insert(source_dirs, "lib/sysdep/arch/x86_x64");
     555    end
     556
    560557    -- OS-specific
    561558    sysdep_dirs = {
    562559        linux = { "lib/sysdep/os/linux", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" },
    563         -- note: RC file must be added to main_exe package.
     560        -- note: RC file must be added to main_exe project.
    564561        -- note: don't add "lib/sysdep/os/win/aken.cpp" because that must be compiled with the DDK.
    565562        windows = { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" },
    566563        macosx = { "lib/sysdep/os/osx", "lib/sysdep/os/unix" },
    567564    }
    568     for i,v in pairs(sysdep_dirs[OS]) do
    569         tinsert(source_dirs, v);
     565    for i,v in pairs(sysdep_dirs[os.get()]) do
     566        table.insert(source_dirs, v);
    570567    end
    571568
    572569    -- runtime-library-specific
    573     if options["target"] == "gnu" then
    574         tinsert(source_dirs, "lib/sysdep/rtl/gcc");
     570    if _ACTION == "vs2005" or _ACTION == "vs2008" or _ACTION == "vs2010" then
     571        table.insert(source_dirs, "lib/sysdep/rtl/msc");
    575572    else
    576         tinsert(source_dirs, "lib/sysdep/rtl/msc");
    577     end
    578 
    579     setup_static_lib_package("lowlevel", source_dirs, extern_libs, {})
     573        table.insert(source_dirs, "lib/sysdep/rtl/gcc");
     574    end
     575
     576    setup_static_lib_project("lowlevel", source_dirs, extern_libs, {})
    580577
    581578
     
    585582        "cxxtest",
    586583    }
     584
    587585    -- 'real' implementations, to be linked against the main executable
    588     setup_static_lib_package("mocks_real", {}, extern_libs, { no_default_link = 1, no_default_pch = 1 })
    589     listconcat(package.files, matchfiles(source_root.."mocks/*.h", source_root.."mocks/*_real.cpp"))
     586    -- (files are added manually and not with setup_static_lib_project
     587    -- because not all files in the directory are included)
     588    setup_static_lib_project("mocks_real", {}, extern_libs, { no_default_link = 1, no_pch = 1 })
     589    files { "mocks/*.h", source_root.."mocks/*_real.cpp" }
    590590    -- 'test' implementations, to be linked against the test executable
    591     setup_static_lib_package("mocks_test", {}, extern_libs, { no_default_link = 1, no_default_pch = 1 })
    592     listconcat(package.files, matchfiles(source_root.."mocks/*.h", source_root.."mocks/*_test.cpp"))
    593 end
    594 
     591    setup_static_lib_project("mocks_test", {}, extern_libs, { no_default_link = 1, no_pch = 1 })
     592    files { source_root.."mocks/*.h", source_root.."mocks/*_test.cpp" }
     593end
    595594
    596595--------------------------------------------------------------------------------
     
    627626function setup_main_exe ()
    628627
    629     package_create("pyrogenesis", "winexe")
    630 
    631     -- For VS2005, tell the linker to use the libraries' .obj files instead of
    632     -- the .lib, to allow incremental linking.
    633     -- (Reduces re-link time from ~20 seconds to ~2 secs)
    634     tinsert(package.buildflags, "use-library-dep-inputs")
     628    local target_type = "WindowedApp"
     629    project_create("pyrogenesis", target_type)
     630
     631    links { "mocks_real" }
    635632
    636633    local extra_params = {
    637634        extra_files = { "main.cpp" },
    638     }
    639     package_add_contents(source_root, {}, {}, extra_params)
    640 
    641     package_add_extern_libs(used_extern_libs)
    642 
    643     tinsert(package.links, "mocks_real")
     635        no_pch = 1
     636    }
     637    project_add_contents(source_root, {}, {}, extra_params)
     638    project_add_extern_libs(used_extern_libs, target_type)
    644639
    645640    -- Platform Specifics
    646     if OS == "windows" then
    647 
    648         tinsert(package.files, source_root.."lib/sysdep/os/win/icon.rc")
     641    if os.is("windows") then
     642
     643        files { source_root.."lib/sysdep/os/win/icon.rc" }
    649644        -- from "lowlevel" static lib; must be added here to be linked in
    650         tinsert(package.files, source_root.."lib/sysdep/os/win/error_dialog.rc")
    651 
    652         -- VS2005 generates its own manifest, but earlier ones need us to add it manually
    653         if (options["target"] == "vs2002" or options["target"] == "vs2003") then
    654             tinsert(package.files, source_root.."lib/sysdep/os/win/manifest.rc")
    655         end
    656 
    657         tinsert(package.buildflags, "no-rtti")
    658 
    659         -- this seems to be required when using vcbuild but not the IDE (?!)
    660         tinsert(package.links, "ws2_32")
    661 
    662         package.linkoptions = {
     645        files { source_root.."lib/sysdep/os/win/error_dialog.rc" }
     646
     647        flags { "NoRTTI" }
     648
     649        linkoptions {
    663650            -- wraps main thread in a __try block(see wseh.cpp). replace with mainCRTStartup if that's undesired.
    664651            "/ENTRY:wseh_EntryPoint",
     
    667654            "/INCLUDE:_wstartup_InitAndRegisterShutdown",
    668655
    669             -- delay loading of various Windows DLLs (not specific to any of the
    670             -- external libraries; those are handled separately)
    671             "/DELAYLOAD:ws2_32.dll",
    672            
    673656            -- allow manual unload of delay-loaded DLLs
    674657            "/DELAY:UNLOAD",
    675658
    676659            -- see manifest.cpp
    677             -- (we need to use &quot; because Premake emits this string directly
    678             -- into a double-quoted attribute value in the project XML files
    679             -- with no automatic escaping)
    680             "&quot;/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'&quot;",
     660            "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\""
    681661        }
    682662
    683663        -- see manifest.cpp
    684         package.config["Debug"].linkoptions = {
    685             "&quot;/manifestdependency:type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.4053' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'&quot;",
    686         }
    687         package.config["Release"].linkoptions = {
    688             "&quot;/manifestdependency:type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.4053' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'&quot;",
    689         }
    690 
    691     elseif OS == "linux" then
     664        configuration "Debug"
     665            linkoptions { "\"/manifestdependency:type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.4053' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'\"" }
     666        configuration "Release"
     667            linkoptions { "\"/manifestdependency:type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.4053' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'\"" }
     668        configuration { }
     669
     670    elseif os.is("linux") then
    692671
    693672        -- Libraries
    694         tinsert(package.links, {
     673        links {
    695674            "fam",
    696675            -- Utilities
     
    698677            -- Dynamic libraries (needed for linking for gold)
    699678            "dl",
    700         })
     679        }
    701680
    702681        -- Threading support
    703         tinsert(package.buildoptions, "-pthread")
    704         tinsert(package.linkoptions, "-pthread")
    705    
     682        buildoptions { "-pthread" }
     683        linkoptions { "-pthread" }
     684
    706685        -- For debug_resolve_symbol
    707         package.config["Debug"].linkoptions = { "-rdynamic" }
    708         package.config["Testing"].linkoptions = { "-rdynamic" }
    709     elseif OS == "macosx" then
    710         -- Libraries
    711         tinsert(package.links, {            -- Utilities
    712             "pthread"
    713         })
     686        configuration "Debug"
     687            linkoptions { "-rdynamic" }
     688        configuration "Testing"
     689            linkoptions { "-rdynamic" }
     690        configuration { }
     691
     692    elseif os.is("macosx") then
     693        links { "pthread" }
    714694    end
    715695end
     
    720700--------------------------------------------------------------------------------
    721701
    722 -- setup a typical Atlas component package
    723 -- extra_params: as in package_add_contents; also zero or more of the following:
    724 -- * pch: (any type) set precompiled.h and .cpp as PCH
    725 function setup_atlas_package(package_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
    726 
    727     local source_root = "../../../source/tools/atlas/" .. package_name .. "/"
    728     package_create(package_name, target_type)
    729 
    730     -- Don't add the default 'sourceroot/pch/projectname' for finding PCH files
    731     extra_params["no_default_pch"] = 1
    732 
    733     package_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
    734     package_add_extern_libs(extern_libs)
    735 
    736     if extra_params["pch"] then
    737         package_setup_pch(nil, "precompiled.h", "precompiled.cpp");
    738     end
    739 
    740     if options["aoe3ed"] then
    741         tinsert(package.defines, "USE_AOE3ED")
     702-- setup a typical Atlas component project
     703-- extra_params, rel_source_dirs and rel_include_dirs: as in project_add_contents;
     704function setup_atlas_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
     705
     706    local source_root = rootdir.."/source/tools/atlas/" .. project_name .. "/"
     707    project_create(project_name, target_type)
     708
     709    -- if not specified, the default for atlas pch files is in the project root.
     710    if not extra_params["pch_dir"] then
     711        extra_params["pch_dir"] = source_root
     712    end
     713
     714    project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
     715    project_add_extern_libs(extern_libs, target_type)
     716
     717    if _OPTIONS["aoe3ed"] then
     718        defines { "USE_AOE3ED" }
    742719    end
    743720
    744721    -- Platform Specifics
    745     if OS == "windows" then
    746 
    747         tinsert(package.defines, "_UNICODE")
    748 
     722    if os.is("windows") then
     723        defines { "_UNICODE" }
    749724        -- Link to required libraries
    750         package.links = { "winmm", "comctl32", "rpcrt4", "delayimp", "ws2_32" }
    751 
     725        links { "winmm", "comctl32", "rpcrt4", "delayimp", "ws2_32" }
    752726        -- required to use WinMain() on Windows, otherwise will default to main()
    753         tinsert(package.buildflags, "no-main")
    754 
    755         if extra_params["extra_links"] then
    756             listconcat(package.links, extra_params["extra_links"])
    757         end
    758 
    759     elseif OS == "linux" then
    760         tinsert(package.buildoptions, "-rdynamic")
    761         tinsert(package.buildoptions, "-fPIC")
    762         tinsert(package.linkoptions, "-fPIC")
    763         tinsert(package.linkoptions, "-rdynamic")
    764 
    765         if extra_params["no_unused_warnings"] then
    766                 if not options["icc"] then
    767                     tinsert(package.buildoptions, "-Wno-unused-parameter")
    768                 end
    769         end
    770     end
    771 
    772 end
    773 
    774 
    775 -- build all Atlas component packages
    776 function setup_atlas_packages()
    777 
    778     setup_atlas_package("AtlasObject", "lib",
     727        flags { "WinMain" }
     728
     729    elseif os.is("linux") then
     730        buildoptions { "-rdynamic", "-fPIC" }
     731        linkoptions { "-fPIC", "-rdynamic" }
     732    end
     733
     734end
     735
     736
     737-- build all Atlas component projects
     738function setup_atlas_projects()
     739
     740    setup_atlas_project("AtlasObject", "StaticLib",
    779741    {   -- src
    780         ""
     742        "."
    781743    },{ -- include
    782744    },{ -- extern_libs
     
    786748        "wxwidgets"
    787749    },{ -- extra_params
     750        no_pch = 1
    788751    })
    789752
    790     setup_atlas_package("AtlasScript", "lib",
     753    setup_atlas_project("AtlasScript", "StaticLib",
    791754    {   -- src
    792         ""
     755        "."
    793756    },{ -- include
    794757        ".."
     
    799762        "wxwidgets",
    800763    },{ -- extra_params
     764        no_pch = 1
    801765    })
    802766
     
    834798        "AtlasScript",
    835799    }
    836     if options["aoe3ed"] then
    837         tinsert(atlas_src, "ArchiveViewer")
    838         tinsert(atlas_src, "FileConverter")
    839         tinsert(atlas_extra_links, "DatafileIO")
    840         tinsert(atlas_extra_links, "xerces-c")
    841     end
    842 
    843     setup_atlas_package("AtlasUI", "dll", atlas_src,
     800    if _OPTIONS["aoe3ed"] then
     801        table.insert(atlas_src, "ArchiveViewer")
     802        table.insert(atlas_src, "FileConverter")
     803        table.insert(atlas_extra_links, "DatafileIO")
     804        table.insert(atlas_extra_links, "xerces-c")
     805    end
     806
     807    setup_atlas_project("AtlasUI", "SharedLib", atlas_src,
    844808    {   -- include
    845809        "..",
     
    858822        "zlib",
    859823    },{ -- extra_params
    860         pch = (not has_broken_pch),
     824        pch_dir = rootdir.."/source/tools/atlas/AtlasUI/Misc/",
     825        no_pch = (has_broken_pch),
    861826        extra_links = atlas_extra_links,
    862827        extra_files = { "Misc/atlas.rc" }
    863828    })
    864829
    865     if options["aoe3ed"] then
    866         setup_atlas_package("DatafileIO", "lib",
     830    if _OPTIONS["aoe3ed"] then
     831        setup_atlas_project("DatafileIO", "StaticLib",
    867832        {   -- src
    868             "",
     833            ".",
    869834            "BAR",
    870835            "DDT",
     
    878843            "zlib"
    879844        },{ -- extra_params
    880             pch = 1,
    881845        })
    882846    end
     
    885849
    886850
    887 -- Atlas 'frontend' tool-launching packages
    888 function setup_atlas_frontend_package (package_name)
    889 
    890     package_create(package_name, "winexe")
    891     package_add_extern_libs({
     851-- Atlas 'frontend' tool-launching projects
     852function setup_atlas_frontend_project (project_name)
     853
     854    local target_type = "WindowedApp"
     855    project_create(project_name, target_type)
     856    project_add_extern_libs({
    892857        "spidermonkey",
    893     })
    894 
    895     local source_root = "../../../source/tools/atlas/AtlasFrontends/"
    896     package.files = {
    897         source_root..package_name..".cpp",
    898         source_root..package_name..".rc"
    899     }
    900     package.trimprefix = source_root
    901     package.includepaths = { source_root .. ".." }
     858    },
     859    target_type)
     860
     861    local source_root = rootdir.."/source/tools/atlas/AtlasFrontends/"
     862    files { source_root..project_name..".cpp" }
     863
     864    if os.is("windows") then
     865        files { source_root..project_name..".rc" }
     866    end
     867
     868    includedirs { source_root .. ".." }
    902869
    903870    -- Platform Specifics
    904     if OS == "windows" then
    905         tinsert(package.defines, "_UNICODE")
     871    if os.is("windows") then
     872        defines { "_UNICODE" }
    906873
    907874        -- required to use WinMain() on Windows, otherwise will default to main()
    908         tinsert(package.buildflags, "no-main")
     875        flags { "WinMain" }
    909876
    910877    else -- Non-Windows, = Unix
    911         if options["aoe3ed"] then
    912             tinsert(package.links, "DatafileIO")
     878        if _OPTIONS["aoe3ed"] then
     879            links { "DatafileIO" }
    913880        end
    914         tinsert(package.links, "AtlasObject")
    915     end
    916 
    917     tinsert(package.links, "AtlasUI")
     881        links { "AtlasObject" }
     882    end
     883
     884    links { "AtlasUI" }
    918885
    919886end
    920887
    921888function setup_atlas_frontends()
    922     setup_atlas_frontend_package("ActorEditor")
    923     setup_atlas_frontend_package("ColourTester")
    924     if options["aoe3ed"] then
    925         setup_atlas_frontend_package("ArchiveViewer")
    926         setup_atlas_frontend_package("FileConverter")
     889    setup_atlas_frontend_project("ActorEditor")
     890    setup_atlas_frontend_project("ColourTester")
     891    if _OPTIONS["aoe3ed"] then
     892        setup_atlas_frontend_project("ArchiveViewer")
     893        setup_atlas_frontend_project("FileConverter")
    927894    end
    928895end
     
    933900--------------------------------------------------------------------------------
    934901
    935 function setup_collada_package(package_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
    936 
    937     package_create(package_name, target_type)
    938 
    939     -- Don't add the default 'sourceroot/pch/projectname' for finding PCH files
    940     extra_params["no_default_pch"] = 1
    941 
    942     package_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
    943     package_add_extern_libs(extern_libs)
    944 
    945     if extra_params["pch"] then
    946         package_setup_pch(nil, "precompiled.h", "precompiled.cpp");
    947     end
     902function setup_collada_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
     903
     904    project_create(project_name, target_type)
     905    local source_root = source_root.."collada/"
     906    extra_params["pch_dir"] = source_root
     907    project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
     908    project_add_extern_libs(extern_libs, target_type)
    948909
    949910    -- Platform Specifics
    950     if OS == "windows" then
    951 
     911    if os.is("windows") then
    952912        -- required to use WinMain() on Windows, otherwise will default to main()
    953         tinsert(package.buildflags, "no-main")
    954 
    955         if extra_params["extra_links"] then
    956             listconcat(package.links, extra_params["extra_links"])
    957         end
    958     end
    959 
    960     if OS == "linux" then
    961         tinsert(package.defines, "LINUX");
     913        flags { "WinMain" }
     914
     915    elseif os.is("linux") then
     916        defines { "LINUX" }
     917
     918        links {
     919            "dl",
     920        }
    962921
    963922        -- FCollada is not aliasing-safe, so disallow dangerous optimisations
    964923        -- (TODO: It'd be nice to fix FCollada, but that looks hard)
    965         tinsert(package.buildoptions, "-fno-strict-aliasing")
    966 
    967         tinsert(package.buildoptions, "-rdynamic")
    968         tinsert(package.linkoptions, "-rdynamic")
    969     elseif OS == "macosx" then
    970         -- define MACOS-something?
     924        buildoptions { "-fno-strict-aliasing" }
     925
     926        buildoptions { "-rdynamic" }
     927        linkoptions { "-rdynamic" }
     928
     929    elseif os.is("macosx") then
     930        -- define MACOS-something?
     931
     932        buildoptions { "-fno-strict-aliasing" }
    971933
    972934        -- On OSX, fcollada uses a few utility functions from coreservices
    973         tinsert(package.linkoptions, "-framework CoreServices")
    974     end
    975 
    976 end
    977 
    978 -- build all Collada component packages
    979 function setup_collada_packages()
    980 
    981     setup_collada_package("Collada", "dll",
     935        linkoptions { "-framework CoreServices" }
     936    end
     937
     938end
     939
     940-- build all Collada component projects
     941function setup_collada_projects()
     942
     943    setup_collada_project("Collada", "SharedLib",
    982944    {   -- src
    983         "collada"
     945        "."
    984946    },{ -- include
    985947    },{ -- extern_libs
    986948        "fcollada",
    987         "dl",
    988         "libxml2",
     949        "libxml2"
    989950    },{ -- extra_params
    990         pch = 1,
    991951    })
    992952
     
    998958--------------------------------------------------------------------------------
    999959
    1000 function get_all_test_files(root, src_files, hdr_files)
    1001 
    1002     -- note: lua doesn't have any directory handling functions at all, ugh.
    1003     -- premake's matchrecursive on patterns like *tests*.h doesn't work -
    1004     -- apparently it applies them to filenames, not the complete path.
    1005     -- our workaround is to enumerate all files and manually filter out the
    1006     -- desired */tests/* files. this is a bit slow, but hey.
    1007 
    1008     local all_files = matchrecursive(root .. "*.h")
     960-- Cxxtestgen needs to create .cpp files from the .h files before they can be compiled.
     961-- By default we are using prebuildcommands, but we are also using customizations of premake
     962-- for makefiles. The reason is that premake currently has a bug with makefiles and parallel
     963-- builds (e.g. -j5). It's not guaranteed that prebuildcommands always run before building.
     964-- All the *.cpp and *.h files need to be added to files no matter if prebuildcommands
     965-- or customizations are used.
     966-- If no customizations are implemented for a specific action (e.g. vs2010), passing the
     967-- parameters won't have any effects.
     968function configure_cxxtestgen()
     969
     970    local lcxxtestrootfile = source_root.."test_root.cpp"
     971    files { lcxxtestrootfile }
     972
     973    -- Define the options used for cxxtestgen
     974    local lcxxtestoptions = "--have-std"
     975    local lcxxtestrootoptions = "--have-std"
     976    if os.is("windows") then
     977        lcxxtestrootoptions = lcxxtestrootoptions .. " --gui=PsTestWrapper --runner=Win32ODSPrinter"
     978    else
     979        lcxxtestrootoptions = lcxxtestrootoptions .. " --gui=PsTestWrapper --runner=ErrorPrinter"
     980    end
     981
     982    -- Precompiled headers - the header is added to all generated .cpp files
     983    -- note that the header isn't actually precompiled here, only #included
     984    -- so that the build stage can use it as a precompiled header.
     985    local include = " --include=precompiled.h"
     986    lcxxtestrootoptions = lcxxtestrootoptions .. include
     987    lcxxtestoptions = lcxxtestoptions .. include
     988
     989    -- Set all the parameters used in our cxxtestgen customization in premake.
     990    cxxtestrootfile(lcxxtestrootfile)
     991    cxxtestpath(lcxxtestpath)
     992    cxxtestrootoptions(lcxxtestrootoptions)
     993    cxxtestoptions(lcxxtestoptions)
     994
     995    -- On windows we have to use backlashes in our paths. We don't have to take care
     996    -- of that for the parameters passed to our cxxtestgen customizations.
     997    if os.is("windows") then
     998        lcxxtestrootfile = path.translate(lcxxtestrootfile, "\\")
     999        lcxxtestpath = path.translate(lcxxtestpath, "\\")
     1000        -- The file paths needs to be made relative to the project directory
     1001        lcxxtestrootfile = "..\\" .. lcxxtestrootfile
     1002        lcxxtestpath = "..\\" .. lcxxtestpath
     1003    end
     1004
     1005    if _ACTION ~= "gmake" and _ACTION ~= "vs2010" then
     1006        prebuildcommands { lcxxtestpath.." --root "..lcxxtestrootoptions.." -o "..lcxxtestrootfile }
     1007    end
     1008
     1009    -- Find header files in 'test' subdirectories
     1010    local all_files = os.matchfiles(source_root .. "**/tests/*.h")
    10091011    for i,v in pairs(all_files) do
    1010         -- header file in subdirectory test
    1011         if string.sub(v, -2) == ".h" and string.find(v, "/tests/") then
    1012             -- don't include sysdep tests on the wrong sys
    1013             -- don't include Atlas tests unless Atlas is being built
    1014             if not (string.find(v, "/sysdep/os/win/") and OS ~= "windows") and
    1015                not (string.find(v, "/tools/atlas/") and not options["atlas"])
    1016             then
    1017                 tinsert(hdr_files, v)
    1018                 -- add the corresponding source file immediately, instead of
    1019                 -- waiting for it to appear after cxxtestgen. this avoids
    1020                 -- having to recreate workspace 2x after adding a test.
    1021                 tinsert(src_files, string.sub(v, 1, -3) .. ".cpp")
     1012        -- Don't include sysdep tests on the wrong sys
     1013        -- Don't include Atlas tests unless Atlas is being built
     1014        if not (string.find(v, "/sysdep/os/win/") and not os.is("windows")) and
     1015           not (string.find(v, "/tools/atlas/") and not _OPTIONS["atlas"])
     1016        then
     1017            local src_file = string.sub(v, 1, -3) .. ".cpp"
     1018            cxxtestsrcfiles { src_file }
     1019            files { src_file }
     1020            cxxtesthdrfiles { v }
     1021
     1022            if _ACTION ~= "gmake" and _ACTION ~= "vs2010" then
     1023                if os.is("windows") then
     1024                    src_file = path.translate(src_file, "\\")
     1025                    v = path.translate(v, "\\")
     1026                    -- The file paths need to be made relative to the project directory
     1027                    src_file = "..\\" .. src_file
     1028                    v = "..\\" .. v
     1029                end
     1030                prebuildcommands { lcxxtestpath.." --part "..lcxxtestoptions.." -o "..src_file.." "..v }
    10221031            end
    10231032        end
    1024     end
    1025    
     1033
     1034
     1035    end
    10261036end
    10271037
     
    10291039function setup_tests()
    10301040
    1031     local src_files = {}
    1032     local hdr_files = {}
    1033     get_all_test_files(source_root, src_files, hdr_files)
    1034 
    1035 
    1036     package_create("test_gen", "cxxtestgen")
    1037     package.files = hdr_files
    1038     package.rootfile = source_root .. "test_root.cpp"
    1039     package.testoptions = "--have-std"
    1040     package.rootoptions = "--have-std"
    1041     if OS == "windows" then
    1042         package.rootoptions = package.rootoptions .. " --gui=PsTestWrapper --runner=Win32ODSPrinter"
    1043     else
    1044         package.rootoptions = package.rootoptions .. " --gui=PsTestWrapper --runner=ErrorPrinter"
    1045     end
    1046     -- precompiled headers - the header is added to all generated .cpp files
    1047     -- note that the header isn't actually precompiled here, only #included
    1048     -- so that the build stage can use it as a precompiled header.
    1049     include = " --include=precompiled.h"
    1050     package.rootoptions = package.rootoptions .. include
    1051     package.testoptions = package.testoptions .. include
    1052     tinsert(package.buildflags, "no-manifest")
    1053 
    1054     package_create("test", "winexe")
    1055     links = static_lib_names
    1056     tinsert(links, "test_gen")
    1057     if options["atlas"] then
    1058         tinsert(links, "AtlasObject")
    1059         package_add_extern_libs({"wxwidgets"})
     1041    local target_type = "WindowedApp"
     1042    project_create("test", target_type)
     1043
     1044    configure_cxxtestgen()
     1045
     1046    links { static_lib_names }
     1047    links { "mocks_test" }
     1048    if _OPTIONS["atlas"] then
     1049        links { "AtlasObject" }
     1050        project_add_extern_libs({"wxwidgets"}, target_type)
    10601051    end
    10611052    extra_params = {
    1062         extra_files = { "test_root.cpp", "test_setup.cpp" },
    1063         extra_links = links,
    1064     }
    1065     package_add_contents(source_root, {}, {}, extra_params)
    1066     -- note: these are not relative to source_root and therefore can't be included via package_add_contents.
    1067     listconcat(package.files, src_files)
    1068     package_add_extern_libs(used_extern_libs)
    1069     tinsert(package.links, "mocks_test")
    1070 
    1071     if OS == "windows" then
     1053        extra_files = { "test_setup.cpp" },
     1054    }
     1055
     1056    project_add_contents(source_root, {}, {}, extra_params)
     1057    project_add_extern_libs(used_extern_libs, target_type)
     1058
     1059    if os.is("windows") then
    10721060        -- from "lowlevel" static lib; must be added here to be linked in
    1073         tinsert(package.files, source_root.."lib/sysdep/os/win/error_dialog.rc")
    1074 
    1075         tinsert(package.buildflags, "no-rtti")
    1076 
    1077         -- this seems to be required when using vcbuild but not the IDE (?!)
    1078         tinsert(package.links, "ws2_32")
     1061        files { source_root.."lib/sysdep/os/win/error_dialog.rc" }
     1062
     1063        flags { "NoRTTI" }
    10791064
    10801065        -- see wstartup.h
    1081         tinsert(package.linkoptions, "/INCLUDE:_wstartup_InitAndRegisterShutdown")
    1082 
    1083     elseif OS == "linux" then
    1084 
    1085         tinsert(package.links, {
     1066        linkoptions { "/INCLUDE:_wstartup_InitAndRegisterShutdown" }
     1067
     1068    elseif os.is("linux") then
     1069
     1070        links {
    10861071            "fam",
    10871072            -- Utilities
     
    10891074            -- Dynamic libraries (needed for linking for gold)
    10901075            "dl",
    1091         })
     1076        }
    10921077
    10931078        -- Threading support
    1094         tinsert(package.buildoptions, "-pthread")
    1095         tinsert(package.linkoptions, "-pthread")
     1079        buildoptions { "-pthread" }
     1080        linkoptions { "-pthread" }
    10961081
    10971082        -- For debug_resolve_symbol
    1098         package.config["Debug"].linkoptions = { "-rdynamic" }
    1099         package.config["Testing"].linkoptions = { "-rdynamic" }
    1100    
    1101         tinsert(package.includepaths, source_root .. "pch/test/")
    1102     end
    1103 
    1104     package_setup_pch(
    1105         source_root .. "pch/test/",
    1106         "precompiled.h",
    1107         "precompiled.cpp");
    1108 
    1109     tinsert(package.buildflags, "use-library-dep-inputs")
    1110 
    1111 end
    1112 
    1113 
    1114 
     1083        configuration "Debug"
     1084            linkoptions { "-rdynamic" }
     1085        configuration "Testing"
     1086            linkoptions { "-rdynamic" }
     1087        configuration { }
     1088
     1089        includedirs { source_root .. "pch/test/" }
     1090    end
     1091end
    11151092
    11161093-- must come first, so that VC sets it as the default project and therefore
     
    11181095setup_main_exe()
    11191096
    1120     -- save package global variable for later (will be overwritten by setup_all_libs)
    1121     main_exe_package = package
    1122 
    11231097setup_all_libs()
    11241098
    1125     -- HACK: add the static libs to the main EXE project. only now (after
    1126     -- setup_all_libs has run) are the lib names known. cannot move
    1127     -- setup_main_exe to run after setup_all_libs (see comment above).
    1128     -- we also don't want to hardcode the names - that would require more
    1129     -- work when changing the static lib breakdown.
    1130     listconcat(main_exe_package.links, static_lib_names)
    1131 
    1132 if options["atlas"] then
    1133     setup_atlas_packages()
     1099-- add the static libs to the main EXE project. only now (after
     1100-- setup_all_libs has run) are the lib names known. cannot move
     1101-- setup_main_exe to run after setup_all_libs (see comment above).
     1102-- we also don't want to hardcode the names - that would require more
     1103-- work when changing the static lib breakdown.
     1104project("pyrogenesis") -- Set the main project active
     1105    links { static_lib_names }
     1106
     1107if _OPTIONS["atlas"] then
     1108    setup_atlas_projects()
    11341109    setup_atlas_frontends()
    11351110end
    11361111
    1137 if options["collada"] then
    1138     setup_collada_packages()
    1139 end
    1140 
    1141 if not options["without-tests"] then
     1112if _OPTIONS["collada"] then
     1113    setup_collada_projects()
     1114end
     1115
     1116if not _OPTIONS["without-tests"] then
    11421117    setup_tests()
    11431118end
  • ps/trunk/build/workspaces/clean-workspaces.sh

    r8633 r9830  
    2020echo "Cleaning build output..."
    2121
    22 # Remove workspaces/gcc
     22# Remove workspaces/gcc if present
    2323rm -rf ./gcc
     24# Remove workspaces/xcode3 if present
     25rm -rf ./xcode3
    2426
    2527echo
  • ps/trunk/build/workspaces/update-workspaces-new.bat

    r9827 r9830  
    22rem ** Create Visual Studio Workspaces on Windows **
    33
    4 if not exist vc2005\pyrogenesis.sln mkdir vc2005
    5 if not exist vc2008\pyrogenesis.sln mkdir vc2008
    6 
    7 rem VC2002 and VC2003 removed because no one is using it and generating it wastes time.
    8 rem it's entirely analogous to other cmdlines - just copy+paste if needed again.
    9 
    104cd ..\premake
    11 
    12 if not exist ..\workspaces\vc2005\SKIP_PREMAKE_HERE premake --collada --target vs2005 --outpath ../workspaces/vc2005 %*
    13 if not exist ..\workspaces\vc2008\SKIP_PREMAKE_HERE premake --collada --target vs2008 --outpath ../workspaces/vc2008 %*
    14 
     5if not exist ..\workspaces\vc2005\SKIP_PREMAKE_HERE premake4\bin\release\premake4 --outpath="../workspaces/vc2005" --collada vs2005 %*
     6if not exist ..\workspaces\vc2008\SKIP_PREMAKE_HERE premake4\bin\release\premake4 --outpath="../workspaces/vc2008" --collada vs2008 %*
     7if not exist ..\workspaces\vc2010\SKIP_PREMAKE_HERE premake4\bin\release\premake4 --outpath="../workspaces/vc2010" --collada vs2010 %*
    158cd ..\workspaces
  • ps/trunk/build/workspaces/update-workspaces-new.sh

    r9827 r9830  
    3131    --disable-atlas ) enable_atlas=false ;;
    3232    -j* ) JOBS=$i ;;
    33     * ) premake_args="${premake_args} $i"
     33    # Assume any other --options are for Premake
     34    --* ) premake_args="${premake_args} $i" ;;
    3435  esac
    3536done
     
    6162echo
    6263
    63 # Make sure workspaces/gcc exists.
    64 mkdir -p gcc
    65 
    6664# Now build premake and run it to create the makefiles
    67 cd ../premake
    68 make -C src ${JOBS} || die "Premake build failed"
     65cd ../premake/premake4
     66make -C build/gmake.unix ${JOBS} || die "Premake build failed"
    6967
    7068echo
     69
     70cd ..
    7171
    7272# If we're in bash then make HOSTTYPE available to Premake, for primitive arch-detection
    7373export HOSTTYPE="$HOSTTYPE"
    7474
    75 src/bin/premake --outpath ../workspaces/gcc ${premake_args} --target gnu || die "Premake failed"
     75premake4/bin/release/premake4 --file="premake4.lua" --outpath="../workspaces/gcc/" ${premake_args} gmake || die "Premake failed"
     76
     77# Also generate xcode3 workspaces if on OS X
     78if [ "`uname -s`" = "Darwin" ]
     79then
     80  premake4/bin/release/premake4 --file="premake4.lua" --outpath="../workspaces/xcode3" ${premake_args} xcode3 || die "Premake failed"
     81fi
Note: See TracChangeset for help on using the changeset viewer.