mirror of
https://github.com/YGGverse/hlsdk-portable.git
synced 2025-02-02 10:05:38 +00:00
premake5.lua: update (#196)
add arch suffix to library names change mechanism of checking header files existence add vgui-related options
This commit is contained in:
parent
b3804d5ad8
commit
6802cda932
@ -1,3 +1,5 @@
|
|||||||
|
local xash = require("xash")
|
||||||
|
|
||||||
workspace("hlsdk-xash3d")
|
workspace("hlsdk-xash3d")
|
||||||
configurations{"Debug", "Release"}
|
configurations{"Debug", "Release"}
|
||||||
language("C++")
|
language("C++")
|
||||||
@ -40,29 +42,76 @@ defines{"BARNACLE_FIX_VISIBILITY=0",
|
|||||||
"OEM_BUILD=0",
|
"OEM_BUILD=0",
|
||||||
"HLDEMO_BUILD=0"}
|
"HLDEMO_BUILD=0"}
|
||||||
|
|
||||||
|
newoption{trigger = "toolset-prefix", description = "Prefix for crosscompiler (should contain the final dash)"}
|
||||||
|
|
||||||
|
xash.prefix = _OPTIONS["toolset-prefix"]
|
||||||
|
xash.find_cxx_compiler()
|
||||||
|
|
||||||
newoption{trigger = "64bits", description = "Allow targetting 64-bit engine", default = false}
|
newoption{trigger = "64bits", description = "Allow targetting 64-bit engine", default = false}
|
||||||
newoption{trigger = "voicemgr", description = "Eable voice manager", default = false}
|
newoption{trigger = "voicemgr", description = "Enable voice manager", default = false}
|
||||||
newoption{trigger = "goldsrc", description = "Enable GoldSource engine support", default = false}
|
newoption{trigger = "goldsrc", description = "Enable GoldSource engine support", default = false}
|
||||||
newoption{trigger = "lto", description = "Enable Link Time Optimization", default = false}
|
newoption{trigger = "lto", description = "Enable Link Time Optimization", default = false}
|
||||||
|
|
||||||
if _OPTIONS["64bits"] then
|
newoption{trigger = "arch", description = "Destination arch", default = xash.get_arch(), allowed = {
|
||||||
architecture("x86_64")
|
{"amd64", ""},
|
||||||
else
|
{"x86", ""},
|
||||||
architecture("x86")
|
{"arm64", ""},
|
||||||
end
|
{"armv8_32l", ""},
|
||||||
|
{"armv7l", ""},
|
||||||
|
{"armv6l", ""},
|
||||||
|
{"armv5l", ""},
|
||||||
|
{"armv4l", ""},
|
||||||
|
{"armv8_32hf", ""},
|
||||||
|
{"armv7hf", ""},
|
||||||
|
{"armv6hf", ""},
|
||||||
|
{"armv5hf", ""},
|
||||||
|
{"armv4hf", ""},
|
||||||
|
{"mips64", ""},
|
||||||
|
{"mipsel", ""},
|
||||||
|
{"riscv32d", ""},
|
||||||
|
{"riscv32f", ""},
|
||||||
|
{"riscv64d", ""},
|
||||||
|
{"riscv64f", ""},
|
||||||
|
{"javascript", ""},
|
||||||
|
{"e2k", ""}
|
||||||
|
}}
|
||||||
|
|
||||||
if _OPTIONS["lto"] then
|
newoption{trigger = "bsd-flavour", description = "BSD flavour", allowed = {
|
||||||
flags{"LinkTimeOptimization"}
|
{"freebsd", ""},
|
||||||
end
|
{"openbsd", ""},
|
||||||
|
{"netbsd", ""}
|
||||||
|
}}
|
||||||
|
|
||||||
if os.findheader("tgmath.h") then
|
newoption{trigger = "vgui", description = "Enable VGUI1", default = false}
|
||||||
|
newoption{trigger = "novgui-motd", description = "Prefer non-VGUI MOTD when VGUI is enabled", default = false}
|
||||||
|
newoption{trigger = "novgui-scoreboard", description = "Prefer non-VGUI scoreboard when VGUI is enabled", default = false}
|
||||||
|
|
||||||
|
xash.bsd_flavour = _OPTIONS["bsd-flavour"]
|
||||||
|
|
||||||
|
if xash.is_cxx_header_exist("tgmath.h") then
|
||||||
defines{"HAVE_TGMATH_H"}
|
defines{"HAVE_TGMATH_H"}
|
||||||
end
|
end
|
||||||
|
|
||||||
if os.findheader("cmath") then
|
if xash.is_cxx_header_exist("cmath") then
|
||||||
defines{"HAVE_CMATH"}
|
defines{"HAVE_CMATH"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if xash.prefix then
|
||||||
|
gccprefix(xash.prefix)
|
||||||
|
end
|
||||||
|
|
||||||
|
if _OPTIONS["arch"] == "amd64" then
|
||||||
|
if not _OPTIONS["64bits"] then
|
||||||
|
xash.arch = "x86"
|
||||||
|
architecture(xash.arch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
targetsuffix(xash.get_lib_suffix())
|
||||||
|
|
||||||
|
filter("options:lto")
|
||||||
|
flags{"LinkTimeOptimization"}
|
||||||
|
|
||||||
filter("configurations:Release")
|
filter("configurations:Release")
|
||||||
optimize("Full")
|
optimize("Full")
|
||||||
symbols("Off")
|
symbols("Off")
|
||||||
@ -77,7 +126,7 @@ filter("toolset:msc")
|
|||||||
buildoptions{"/D_USING_V110_SDK71_", "/Zc:threadSafeInit-"}
|
buildoptions{"/D_USING_V110_SDK71_", "/Zc:threadSafeInit-"}
|
||||||
defines{"_CRT_SECURE_NO_WARNINGS=1", "_CRT_NONSTDC_NO_DEPRECATE=1"}
|
defines{"_CRT_SECURE_NO_WARNINGS=1", "_CRT_NONSTDC_NO_DEPRECATE=1"}
|
||||||
|
|
||||||
filter("toolset:gcc or clang")
|
filter("toolset:not msc")
|
||||||
visibility("Hidden")
|
visibility("Hidden")
|
||||||
defines{"stricmp=strcasecmp",
|
defines{"stricmp=strcasecmp",
|
||||||
"strnicmp=strncasecmp",
|
"strnicmp=strncasecmp",
|
||||||
@ -177,11 +226,11 @@ files{"dlls/agrunt.cpp",
|
|||||||
|
|
||||||
includedirs{"public"}
|
includedirs{"public"}
|
||||||
|
|
||||||
if _OPTIONS["voicemgr"] then
|
filter("options:voicemgr")
|
||||||
files{"game_shared/voice_gamemgr.cpp"}
|
files{"game_shared/voice_gamemgr.cpp"}
|
||||||
else
|
|
||||||
defines{"NO_VOICEGAMEMGR"}
|
filter("options:not voicemgr")
|
||||||
end
|
defines{"NO_VOICEGAMEMGR"}
|
||||||
|
|
||||||
filter("toolset:msc")
|
filter("toolset:msc")
|
||||||
buildoptions{"/def:" .. path.getabsolute("dlls/hl.def")}
|
buildoptions{"/def:" .. path.getabsolute("dlls/hl.def")}
|
||||||
@ -194,7 +243,6 @@ files{"cl_dll/hl/hl_baseentity.cpp",
|
|||||||
"cl_dll/hl/hl_objects.cpp",
|
"cl_dll/hl/hl_objects.cpp",
|
||||||
"cl_dll/hl/hl_weapons.cpp",
|
"cl_dll/hl/hl_weapons.cpp",
|
||||||
"cl_dll/GameStudioModelRenderer.cpp",
|
"cl_dll/GameStudioModelRenderer.cpp",
|
||||||
"cl_dll/MOTD.cpp",
|
|
||||||
"cl_dll/StudioModelRenderer.cpp",
|
"cl_dll/StudioModelRenderer.cpp",
|
||||||
"cl_dll/ammo.cpp",
|
"cl_dll/ammo.cpp",
|
||||||
"cl_dll/ammo_secondary.cpp",
|
"cl_dll/ammo_secondary.cpp",
|
||||||
@ -226,7 +274,6 @@ files{"cl_dll/hl/hl_baseentity.cpp",
|
|||||||
"cl_dll/overview.cpp",
|
"cl_dll/overview.cpp",
|
||||||
"cl_dll/parsemsg.cpp",
|
"cl_dll/parsemsg.cpp",
|
||||||
"cl_dll/saytext.cpp",
|
"cl_dll/saytext.cpp",
|
||||||
"cl_dll/scoreboard.cpp",
|
|
||||||
"cl_dll/status_icons.cpp",
|
"cl_dll/status_icons.cpp",
|
||||||
"cl_dll/statusbar.cpp",
|
"cl_dll/statusbar.cpp",
|
||||||
"cl_dll/studio_util.cpp",
|
"cl_dll/studio_util.cpp",
|
||||||
@ -237,18 +284,64 @@ files{"cl_dll/hl/hl_baseentity.cpp",
|
|||||||
"cl_dll/view.cpp"}
|
"cl_dll/view.cpp"}
|
||||||
|
|
||||||
includedirs{"cl_dll",
|
includedirs{"cl_dll",
|
||||||
"cl_dll/hl",
|
"cl_dll/hl"}
|
||||||
"utils/false_vgui/include"}
|
|
||||||
|
|
||||||
defines{"CLIENT_DLL"}
|
defines{"CLIENT_DLL"}
|
||||||
|
|
||||||
if _OPTIONS["goldsrc"] then
|
filter("options:goldsrc")
|
||||||
defines{"GOLDSOURCE_SUPPORT"}
|
defines{"GOLDSOURCE_SUPPORT"}
|
||||||
end
|
|
||||||
|
|
||||||
filter("system:Windows")
|
filter("options:vgui")
|
||||||
|
files{"cl_dll/vgui_int.cpp",
|
||||||
|
"cl_dll/vgui_ClassMenu.cpp",
|
||||||
|
"cl_dll/vgui_ConsolePanel.cpp",
|
||||||
|
"cl_dll/vgui_ControlConfigPanel.cpp",
|
||||||
|
"cl_dll/vgui_CustomObjects.cpp",
|
||||||
|
"cl_dll/vgui_MOTDWindow.cpp",
|
||||||
|
"cl_dll/vgui_SchemeManager.cpp",
|
||||||
|
"cl_dll/vgui_ScorePanel.cpp",
|
||||||
|
"cl_dll/vgui_TeamFortressViewport.cpp",
|
||||||
|
"cl_dll/vgui_SpectatorPanel.cpp",
|
||||||
|
"cl_dll/vgui_teammenu.cpp",
|
||||||
|
"cl_dll/voice_status.cpp",
|
||||||
|
"game_shared/vgui_checkbutton2.cpp",
|
||||||
|
"game_shared/vgui_grid.cpp",
|
||||||
|
"game_shared/vgui_helpers.cpp",
|
||||||
|
"game_shared/vgui_listbox.cpp",
|
||||||
|
"game_shared/vgui_loadtga.cpp",
|
||||||
|
"game_shared/vgui_scrollbar2.cpp",
|
||||||
|
"game_shared/vgui_slider2.cpp",
|
||||||
|
"game_shared/voice_banmgr.cpp"}
|
||||||
|
includedirs{"vgui-dev/include"}
|
||||||
|
defines{"USE_VGUI"}
|
||||||
|
|
||||||
|
filter{"options:vgui", "system:windows"}
|
||||||
|
libdirs{"vgui-dev/lib/win32_vc6/"}
|
||||||
|
|
||||||
|
filter{"options:vgui", "system:macosx"}
|
||||||
|
libdirs{"vgui-dev/lib"}
|
||||||
|
|
||||||
|
filter{"options:vgui", "system:windows or macosx"}
|
||||||
|
links{"vgui"}
|
||||||
|
|
||||||
|
filter{"options:vgui", "system:not windows or not macosx"}
|
||||||
|
linkoptions{path.getabsolute("vgui-dev/lib/vgui.so")}
|
||||||
|
|
||||||
|
filter{"options:vgui", "options:novgui-motd"}
|
||||||
|
defines{"USE_NOVGUI_MOTD"}
|
||||||
|
files{"cl_dll/MOTD.cpp"}
|
||||||
|
|
||||||
|
filter{"options:vgui", "options:novgui-scoreboard"}
|
||||||
|
defines{"USE_NOVGUI_SCOREBOARD"}
|
||||||
|
files{"cl_dll/scoreboard.cpp"}
|
||||||
|
|
||||||
|
filter("options:not vgui")
|
||||||
|
files{"cl_dll/MOTD.cpp",
|
||||||
|
"cl_dll/scoreboard.cpp"}
|
||||||
|
includedirs{"utils/false_vgui/include"}
|
||||||
|
|
||||||
|
filter("system:windows")
|
||||||
links{"user32", "winmm"}
|
links{"user32", "winmm"}
|
||||||
|
|
||||||
filter("system:not windows")
|
filter("system:not windows")
|
||||||
links{"dl"}
|
links{"dl"}
|
||||||
|
|
||||||
|
240
contrib/iZarif/xash.lua
Normal file
240
contrib/iZarif/xash.lua
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
local m = {}
|
||||||
|
local toolsets = {gcc = {}, clang = {}, mingw = {}, msc = {}}
|
||||||
|
local toolset = nil
|
||||||
|
local cxx = nil
|
||||||
|
|
||||||
|
function toolsets.gcc.is_cxx_compileable(code, include_dirs)
|
||||||
|
local include_dirs = include_dirs or {}
|
||||||
|
local code_file_path = _MAIN_SCRIPT_DIR .. "/tmp.cpp"
|
||||||
|
local code_file = io.open(code_file_path, "w")
|
||||||
|
|
||||||
|
code_file:write(code)
|
||||||
|
code_file:close()
|
||||||
|
|
||||||
|
local include_dirs_str = ""
|
||||||
|
|
||||||
|
for _, include_dir in ipairs(include_dirs) do
|
||||||
|
include_dirs_str = include_dirs_str .. "-I" .. include_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = string.format("%s %s -c %s", cxx, include_dirs_str, code_file_path)
|
||||||
|
local _, _, rc = os.execute(cmd)
|
||||||
|
local result = false
|
||||||
|
|
||||||
|
if rc == 0 then
|
||||||
|
result = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function toolsets.msc.is_cxx_compileable(code, include_dirs)
|
||||||
|
local include_dirs = include_dirs or {}
|
||||||
|
local code_file_path = _XASHAIN_SCRIPT_DIR .. "/tmp.cpp"
|
||||||
|
local code_file = io.open(code_file_path, "w")
|
||||||
|
|
||||||
|
code_file:write(code)
|
||||||
|
code_file:close()
|
||||||
|
|
||||||
|
local include_dirs_str = ""
|
||||||
|
|
||||||
|
for _, include_dir in ipairs(include_dirs) do
|
||||||
|
include_dirs_str = include_dirs_str .. "/I" .. include_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = string.format("%s %s /c %s", cxx, include_dirs_str, code_file_path)
|
||||||
|
local _, _, rc = os.execute(cmd)
|
||||||
|
local result = false
|
||||||
|
|
||||||
|
if rc == 0 then
|
||||||
|
result = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
toolsets.clang.is_cxx_compileable = toolsets.gcc.is_cxx_compileable
|
||||||
|
toolsets.mingw.is_cxx_compileable = toolsets.gcc.is_cxx_compileable
|
||||||
|
|
||||||
|
function m.is_cxx_symbol_defined(symbol, headers, include_dirs)
|
||||||
|
local headers = headers or {}
|
||||||
|
local include_dirs = include_dirs or {}
|
||||||
|
local code = ""
|
||||||
|
|
||||||
|
for _, header in ipairs(headers) do
|
||||||
|
code = code .. string.format("#include <%s>\n", header)
|
||||||
|
end
|
||||||
|
|
||||||
|
code = code .. string.format("#ifndef %s\n.\n#endif", symbol)
|
||||||
|
|
||||||
|
return m.is_cxx_compileable(code, include_dirs)
|
||||||
|
end
|
||||||
|
|
||||||
|
function m.is_cxx_header_exist(header, include_dirs)
|
||||||
|
local include_dirs = include_dirs or {}
|
||||||
|
local code = ""
|
||||||
|
|
||||||
|
code = code .. string.format("#include <%s>\n", header)
|
||||||
|
|
||||||
|
return m.is_cxx_compileable(code, include_dirs)
|
||||||
|
end
|
||||||
|
|
||||||
|
function m.get_arch()
|
||||||
|
local arch = m.arch
|
||||||
|
|
||||||
|
if not arch then
|
||||||
|
if m.is_cxx_symbol_defined("XASH_AMD64", {"build.h"}, {"public"}) then
|
||||||
|
arch = "amd64"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_X86", {"build.h"}, {"public"}) then
|
||||||
|
arch = "x86"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_ARM", {"build.h"}, {"public"}) then
|
||||||
|
if m.is_cxx_symbol_defined("XASH_64BIT", {"build.h"}, {"public"}) then
|
||||||
|
arch = "arm64"
|
||||||
|
else
|
||||||
|
arch = "armv"
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_ARMv8", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "8_32"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_ARMv7", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "7"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_ARMv6", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "6"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_ARMv5", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "5"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_ARMv4", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "4"
|
||||||
|
end
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_ARM_HARDFP", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "hf"
|
||||||
|
else
|
||||||
|
arch = arch .. "l"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_MIPS", {"build.h"}, {"public"}) then
|
||||||
|
arch = "mips"
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_64BIT", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "64"
|
||||||
|
end
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_LITTLE_ENDIAN", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "el"
|
||||||
|
end
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_RISCV", {"build.h"}, {"public"}) then
|
||||||
|
arch = "riscv"
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_64BIT", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "64"
|
||||||
|
else
|
||||||
|
arch = arch .. "32"
|
||||||
|
end
|
||||||
|
|
||||||
|
if m.is_cxx_symbol_defined("XASH_RISCV_DOUBLEFP", {"build.h"}, {"public"}) then
|
||||||
|
arch = arch .. "d"
|
||||||
|
else
|
||||||
|
arch = arch .. "f"
|
||||||
|
end
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_JS", {"build.h"}, {"public"}) then
|
||||||
|
arch = "javascript"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_E2K", {"build.h"}, {"public"}) then
|
||||||
|
arch = "e2k"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return arch
|
||||||
|
end
|
||||||
|
|
||||||
|
function m.get_os()
|
||||||
|
local dest_os = os.target()
|
||||||
|
|
||||||
|
if dest_os == "bsd" then
|
||||||
|
dest_os = m.bsd_flavour
|
||||||
|
|
||||||
|
if not dest_os then
|
||||||
|
if m.is_cxx_symbol_defined("XASH_FREEBSD", {"build.h"}, {"public"}) then
|
||||||
|
dest_os = "freebsd"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_NETBSD", {"build.h"}, {"public"}) then
|
||||||
|
dest_os = "netbsd"
|
||||||
|
elseif m.is_cxx_symbol_defined("XASH_OPENBSD", {"build.h"}, {"public"}) then
|
||||||
|
dest_os = "openbsd"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return dest_os
|
||||||
|
end
|
||||||
|
|
||||||
|
function m.get_lib_suffix()
|
||||||
|
local dest_os = m.get_os()
|
||||||
|
local arch = m.get_arch()
|
||||||
|
|
||||||
|
if dest_os == "windows" or dest_os == "linux" or dest_os == "macosx" then
|
||||||
|
dest_os = nil
|
||||||
|
elseif dest_os == "android" then
|
||||||
|
dest_os = nil
|
||||||
|
arch = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if arch == "x86" then
|
||||||
|
arch = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local suffix = ""
|
||||||
|
|
||||||
|
if dest_os and arch then
|
||||||
|
suffix = string.format("%s_%s", dest_os, arch)
|
||||||
|
elseif arch then
|
||||||
|
suffix = string.format("_%s", arch)
|
||||||
|
end
|
||||||
|
|
||||||
|
return suffix
|
||||||
|
end
|
||||||
|
|
||||||
|
function m.find_cxx_compiler()
|
||||||
|
local prefix = m.prefix or ""
|
||||||
|
local host_os = os.host()
|
||||||
|
|
||||||
|
toolset = _OPTIONS["cc"]
|
||||||
|
|
||||||
|
if not toolset then
|
||||||
|
if host_os == "windows" then
|
||||||
|
toolset = "msc"
|
||||||
|
elseif host_os == "macosx" then
|
||||||
|
toolset = "clang"
|
||||||
|
else
|
||||||
|
toolset = "gcc"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if toolset == "gcc" or "mingw" then
|
||||||
|
cxx = prefix .. "g++"
|
||||||
|
elseif toolset == "clang" then
|
||||||
|
cxx = prefix .. "clang++"
|
||||||
|
elseif toolset == "msc" then
|
||||||
|
cxx = "cl.exe"
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_found = false
|
||||||
|
|
||||||
|
if cxx then
|
||||||
|
local cmd = ""
|
||||||
|
|
||||||
|
if toolset == "msc" then
|
||||||
|
cmd = cxx .. " /HELP"
|
||||||
|
else
|
||||||
|
cmd = cxx .. " --help"
|
||||||
|
end
|
||||||
|
|
||||||
|
_, _, rc = os.execute(cmd)
|
||||||
|
|
||||||
|
if rc == 0 then
|
||||||
|
is_found = true
|
||||||
|
m.is_cxx_compileable = toolsets[toolset].is_cxx_compileable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return is_found
|
||||||
|
end
|
||||||
|
|
||||||
|
return m
|
Loading…
x
Reference in New Issue
Block a user