Ticket #1516: premake_flags.diff

File premake_flags.diff, 9.5 KB (added by leper, 12 years ago)
  • build/premake/premake4.lua

     
    1010newoption { trigger = "without-nvtt", description = "Disable use of NVTT" }
    1111newoption { trigger = "without-tests", description = "Disable generation of test projects" }
    1212newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" }
     13newoption { trigger = "minimal-flags", description = "Only set compiler/linker flags that are really needed" }
     14newoption { trigger = "disable-preset-flags", description = "Disable all preset compiler/linker flags" }
    1315newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" }
    1416newoption { trigger = "with-system-enet", description = "Search standard paths for libenet, instead of using bundled copy" }
    1517newoption { trigger = "with-system-mozjs185", description = "Search standard paths for libmozjs185, instead of using bundled copy" }
     
    135137function project_set_build_flags()
    136138
    137139    flags { "Symbols", "NoEditAndContinue" }
    138     if not _OPTIONS["icc"] then
     140    if not _OPTIONS["icc"] and not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
    139141        -- adds the -Wall compiler flag
    140142        flags { "ExtraWarnings" } -- this causes far too many warnings/remarks on ICC
    141143    end
     
    144146        defines { "DEBUG" }
    145147
    146148    configuration "Release"
    147         flags { "OptimizeSpeed" }
     149        if not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
     150            flags { "OptimizeSpeed" }
     151        end
    148152        defines { "NDEBUG", "CONFIG_FINAL=1" }
    149153
    150154    configuration { }
     
    176180        flags { "NativeWChar" }
    177181
    178182    else    -- *nix
    179         if _OPTIONS["icc"] then
     183        if _OPTIONS["icc"] and not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
    180184            buildoptions {
    181185                "-w1",
    182186                -- "-Wabi",
     
    190194                "-wd1292" -- avoid lots of 'attribute "__nonnull__" ignored'
    191195            }
    192196            configuration "Debug"
    193                 buildoptions { "-O0" } -- ICC defaults to -O2
     197                if not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
     198                    buildoptions { "-O0" } -- ICC defaults to -O2
     199                end
    194200            configuration { }
    195201            if os.is("macosx") then
    196202                linkoptions { "-multiply_defined","suppress" }
    197203            end
    198204        else
    199             buildoptions {
    200                 -- enable most of the standard warnings
    201                 "-Wno-switch",      -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
    202                 "-Wno-reorder",     -- order of initialization list in constructors (lots of noise)
    203                 "-Wno-invalid-offsetof",    -- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
    204 
    205                 "-Wextra",
    206                 "-Wno-missing-field-initializers",  -- (this is common in external headers we can't fix)
    207 
    208                 -- add some other useful warnings that need to be enabled explicitly
    209                 "-Wunused-parameter",
    210                 "-Wredundant-decls",    -- (useful for finding some multiply-included header files)
    211                 -- "-Wformat=2",        -- (useful sometimes, but a bit noisy, so skip it by default)
    212                 -- "-Wcast-qual",       -- (useful for checking const-correctness, but a bit noisy, so skip it by default)
    213                 "-Wnon-virtual-dtor",   -- (sometimes noisy but finds real bugs)
    214                 "-Wundef",              -- (useful for finding macro name typos)
    215 
    216                 -- enable security features (stack checking etc) that shouldn't have
    217                 -- a significant effect on performance and can catch bugs
    218                 "-fstack-protector-all",
    219                 "-D_FORTIFY_SOURCE=2",
    220 
    221                 -- always enable strict aliasing (useful in debug builds because of the warnings)
    222                 "-fstrict-aliasing",
    223 
    224                 -- do something (?) so that ccache can handle compilation with PCH enabled
    225                 "-fpch-preprocess",
    226 
    227                 -- don't omit frame pointers (for now), because performance will be impacted
    228                 -- negatively by the way this breaks profilers more than it will be impacted
    229                 -- positively by the optimisation
    230                 "-fno-omit-frame-pointer"
    231             }
     205            -- TODO maybe move some of them out of there
     206            if not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
     207                buildoptions {
     208                    -- enable most of the standard warnings
     209                    "-Wno-switch",      -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
     210                    "-Wno-reorder",     -- order of initialization list in constructors (lots of noise)
     211                    "-Wno-invalid-offsetof",    -- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
     212
     213                    "-Wextra",
     214                    "-Wno-missing-field-initializers",  -- (this is common in external headers we can't fix)
     215
     216                    -- add some other useful warnings that need to be enabled explicitly
     217                    "-Wunused-parameter",
     218                    "-Wredundant-decls",    -- (useful for finding some multiply-included header files)
     219                    -- "-Wformat=2",        -- (useful sometimes, but a bit noisy, so skip it by default)
     220                    -- "-Wcast-qual",       -- (useful for checking const-correctness, but a bit noisy, so skip it by default)
     221                    "-Wnon-virtual-dtor",   -- (sometimes noisy but finds real bugs)
     222                    "-Wundef",              -- (useful for finding macro name typos)
     223
     224                    -- enable security features (stack checking etc) that shouldn't have
     225                    -- a significant effect on performance and can catch bugs
     226                    "-fstack-protector-all",
     227                    "-D_FORTIFY_SOURCE=2",
     228
     229                    -- always enable strict aliasing (useful in debug builds because of the warnings)
     230                    "-fstrict-aliasing",
     231
     232                    -- do something (?) so that ccache can handle compilation with PCH enabled
     233                    "-fpch-preprocess",
     234
     235                    -- don't omit frame pointers (for now), because performance will be impacted
     236                    -- negatively by the way this breaks profilers more than it will be impacted
     237                    -- positively by the optimisation
     238                    "-fno-omit-frame-pointer"
     239                }
     240            end
    232241
    233             if arch == "x86" or arch == "amd64" then
     242            if (arch == "x86" or arch == "amd64") and not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
    234243                buildoptions {
    235244                    -- enable SSE intrinsics
    236245                    "-msse"
     
    245254                buildoptions { "-mthumb -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp" }
    246255            end
    247256
    248             if os.is("linux") or os.is("bsd") then
     257            if (os.is("linux") or os.is("bsd")) and not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
    249258                linkoptions { "-Wl,--no-undefined", "-Wl,--as-needed" }
    250259            end
    251260
     
    256265
    257266            -- To support intrinsics like __sync_bool_compare_and_swap on x86
    258267            -- we need to set -march to something that supports them
    259             if arch == "x86" then
     268            if arch == "x86" and not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
    260269                buildoptions { "-march=i686" }
    261270            end
    262271
     
    267276            end
    268277        end
    269278
    270         buildoptions {
    271             -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
    272             -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
    273             "-fvisibility=hidden"
    274         }
     279        if not (_OPTIONS["minimal-flags"] or _OPTIONS["disable-preset-flags"]) then
     280            buildoptions {
     281                -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
     282                -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
     283                "-fvisibility=hidden"
     284            }
     285        end
    275286
    276287        -- X11 includes may be installed in one of a gadzillion of three places
    277288        -- Famous last words: "You can't include too much! ;-)"
     
    292303            defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] }
    293304        end
    294305
    295         if os.is("linux") or os.is("bsd") then
     306        if (os.is("linux") or os.is("bsd")) and not _OPTIONS["with-system-mozjs185"] then
     307        -- TODO add "minimal-flags" and/or "disable-preset-flags" here
    296308            -- To use our local SpiderMonkey library, it needs to be part of the
    297309            -- runtime dynamic linker path. Add it with -rpath to make sure it gets found.
    298310            if _OPTIONS["libdir"] then
     
    841853        -- install_name settings aren't really supported yet by premake, but there are plans for the future.
    842854        -- we currently use this hack to work around some bugs with wrong install_names.
    843855        if target_type == "SharedLib" then
    844             linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }       
     856            linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
    845857        end
    846858    end
    847859
     
    10081020
    10091021        -- FCollada is not aliasing-safe, so disallow dangerous optimisations
    10101022        -- (TODO: It'd be nice to fix FCollada, but that looks hard)
    1011         buildoptions { "-fno-strict-aliasing" }
     1023        if not _OPTIONS["disable-preset-flags"] then
     1024            buildoptions { "-fno-strict-aliasing" }
     1025        end
    10121026
    10131027        buildoptions { "-rdynamic" }
    10141028        linkoptions { "-rdynamic" }
     
    10181032            links { "c", }
    10191033        end
    10201034
    1021         buildoptions { "-fno-strict-aliasing" }
     1035        if not _OPTIONS["disable-preset-flags"] then
     1036            buildoptions { "-fno-strict-aliasing" }
     1037        end
    10221038
    10231039        buildoptions { "-rdynamic" }
    10241040        linkoptions { "-rdynamic" }
     
    10291045        -- install_name settings aren't really supported yet by premake, but there are plans for the future.
    10301046        -- we currently use this hack to work around some bugs with wrong install_names.
    10311047        if target_type == "SharedLib" then
    1032             linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }       
     1048            linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
    10331049        end
    10341050
    1035         buildoptions { "-fno-strict-aliasing" }
     1051        if not _OPTIONS["disable-preset-flags"] then
     1052            buildoptions { "-fno-strict-aliasing" }
     1053        end
    10361054
    10371055        -- On OSX, fcollada uses a few utility functions from coreservices
    10381056        linkoptions { "-framework CoreServices" }