Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve xmake #148

Open
wants to merge 1 commit into
base: xmake
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions 3rdParty/glfw/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ target("glfw")
add_headerfiles("glfw3.h", "glfw3native.h")
add_filegroups("include", {rootdir = "./", files = {"*.h"}})

if is_os("windows") then
add_packages("vulkansdk")

if is_plat("windows") then
add_files("src/context.c",
"src/egl_context.c",
"src/init.c",
Expand All @@ -25,10 +27,13 @@ target("glfw")
"src/win32_window.c",
"src/window.c")

add_syslinks("Shell32.lib",
"Gdi32.lib")
add_syslinks("user32", "shell32", "gdi32")
else
print("glfw TODO")
-- TODO: add wayland support
add_deps("libx11", "libxrandr", "libxrender", "libxinerama", "libxfixes", "libxcursor", "libxi", "libxext")
add_syslinks("dl", "pthread")
add_defines("_GLFW_X11")
end

-- add_filegroups("include", {rootdir = "./", files = {"src/*.h"}})
4 changes: 2 additions & 2 deletions 3rdParty/rtaudio/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ target("rtaudio")
add_files("*.cpp")
add_filegroups("src", {rootdir = "./"})

if is_os("windows") then
if is_plat("windows") then
add_defines("__WINDOWS_WASAPI__",
"_CRT_SECURE_NO_WARNINGS")

add_syslinks("Ole32.lib")
add_syslinks("ole32")
else
print("rtaudio TODO")
end
2 changes: 1 addition & 1 deletion 3rdParty/tinydbr/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target("tinydbr")

add_filegroups("src", {rootdir = "./"})

if is_os("windows") then
if is_plat("windows") then
add_headerfiles("windows/*.h")
add_files("windows/*.cpp")
else
Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/zydis/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target("zycore")
add_filegroups("src", {rootdir = "dependencies/zycore/src/"})
add_filegroups("include", {rootdir = "dependencies/zycore/include/Zycore/"})

if is_os("windows") then
if is_plat("windows") then
add_defines("WINVER=0x0502",
"_WIN32_WINNT=0x0502",
"NTDDI_VERSION=0x05020000",
Expand Down Expand Up @@ -39,7 +39,7 @@ target("zydis")
add_files("src/**.c")
add_filegroups("include", {rootdir = "include/Zydis/"})

if is_os("windows") then
if is_plat("windows") then
add_defines("WINVER=0x0502",
"_WIN32_WINNT=0x0502",
"NTDDI_VERSION=0x05020000",
Expand Down
32 changes: 0 additions & 32 deletions GPCS4/ImportLibs.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions Xmake/llvm.lua

This file was deleted.

69 changes: 33 additions & 36 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
set_project("GPCS4")
set_version("0.2.3")
set_xmakever("2.8.1")

add_rules("mode.release", "mode.debug")

-- Only support x64
set_plat(os.host())
set_arch("x64")
set_allowedplats("windows")
set_allowedarchs("x64")
set_allowedmodes("debug", "release")

-- Only support clang
if is_os("windows") then
if is_plat("windows") then
set_toolchains("clang-cl")

if is_mode("debug") then
Expand All @@ -27,18 +28,19 @@ else
end


-- includes("3rdParty/glfw")
-- includes("3rdParty/rtaudio")
-- includes("3rdParty/zydis")
-- includes("3rdParty/tinydbr")
includes("3rdParty/glfw")
includes("3rdParty/rtaudio")
includes("3rdParty/zydis")
includes("3rdParty/tinydbr")

if is_os("windows") then
if is_plat("windows") then
includes("3rdParty/winpthreads")
end

includes("xmake")

target("GPCS4")
set_kind("binary")
add_rules("module.program")
set_languages("c11", "cxx17")

-- C/C++ Flags
Expand All @@ -50,13 +52,13 @@ target("GPCS4")
"-Wno-microsoft-enum-forward-reference",
"-Wno-nonportable-include-path")
if is_mode("release") then
add_cxxflags("-flto=thin")
-- add_cxxflags("-flto=thin")
end

-- C/C++ Defines
add_defines("FMT_HEADER_ONLY")

if is_os("windows") then
if is_plat("windows") then
add_defines("GPCS4_WINDOWS")
add_defines("__PTW32_STATIC_LIB",
"_CRT_SECURE_NO_WARNINGS")
Expand All @@ -68,16 +70,6 @@ target("GPCS4")
add_defines("GPCS4_DEBUG")
end

-- Include and Souce Files
if is_os("windows") then
on_load(function (target)
import("xmake.llvm")
target:add("includedirs", llvm.find_include())
end)

add_includedirs("$(env VULKAN_SDK)/Include")
end

add_includedirs("GPCS4/",
"GPCS4/Emulator",
"GPCS4/Algorithm",
Expand All @@ -96,25 +88,30 @@ target("GPCS4")
add_headerfiles("GPCS4/**.h")
add_files("GPCS4/**.cpp", "GPCS4/**.c")

local shader_path = "GPCS4/Graphics/Sce/Shaders"
add_rules("module.shader", {outputdir = path.join(os.projectdir(), shader_path)})
add_files(path.join(shader_path, "*.vert"))
add_files(path.join(shader_path, "*.frag"))

-- linked libraries
if is_os("windows") then
add_linkdirs("$(env VULKAN_SDK)/Lib")
add_links("vulkan-1.lib")
add_syslinks("ksuser.lib",
"mfplat.lib",
"mfuuid.lib",
"wmcodecdspuuid.lib",
"legacy_stdio_definitions.lib",
"user32.lib")
if is_plat("windows") then
add_syslinks("ksuser",
"mfplat",
"mfuuid",
"wmcodecdspuuid",
"legacy_stdio_definitions",
"user32")
else
print("gpcs4 TODO")
end

-- add_deps("glfw")
-- add_deps("rtaudio")
-- add_deps("zydis")
-- add_deps("tinydbr")
add_packages("vulkansdk")

add_deps("glfw")
add_deps("rtaudio")
add_deps("zydis")
add_deps("tinydbr")

if is_os("windows") then
if is_plat("windows") then
add_deps("winpthreads")
end
5 changes: 5 additions & 0 deletions xmake/option.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
option("test")
set_default(false)
set_showmenu(true)
set_description("Enable test (default: false)")
option_end()
7 changes: 7 additions & 0 deletions xmake/package.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_requires("glslang", {configs = {binaryonly = true}})

add_requires("vulkansdk")

if is_mode("release") and is_plat("windows") then
add_requires("vc-ltl5")
end
23 changes: 23 additions & 0 deletions xmake/rule/debug.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rule("debug.asan")
on_load(function (target)
if not is_mode("debug") then
return
end

target:add("cxflags", "-fsanitize=address")
target:add("mxflags", "-fsanitize=address")
target:add("ldflags", "-fsanitize=address")
target:add("shflags", "-fsanitize=address")

if not target:get("symbols") then
target:set("symbols", "debug")
end

local msvc = target:toolchain("msvc")
if target:kind() == "binary" and msvc then
import("lib.detect.find_tool")

local cl = assert(find_tool("cl", {envs = msvc:runenvs()}), "cl not found!")
target:add("runenvs", "Path", path.directory(cl.program))
end
end)
47 changes: 47 additions & 0 deletions xmake/rule/module.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
rule("module.program")
on_load(function (target)
target:set("kind", "binary")
target:set("rundir", "$(projectdir)")
if target:is_plat("windows") and target:get("runtimes") == "MT" then
target:add("packages", "vc-ltl5")
end
end)

after_link(function (target)
local enabled = target:extraconf("rules", "module.program", "upx")
if (not enabled) or (not is_mode("release")) then
return
end

import("core.project.depend")

local targetfile = target:targetfile()
depend.on_changed(function ()
local file = path.join("build", path.filename(targetfile))
local upx = assert(import("lib.detect.find_tool")("upx"), "upx not found!")

os.tryrm(file)
os.vrunv(upx.program, {targetfile, "-o", file})
end, {files = targetfile})
end)

rule("module.shader")
set_extensions(".vert", ".tesc", ".tese", ".geom", ".comp", ".frag", ".comp", ".mesh", ".task", ".rgen", ".rint", ".rahit", ".rchit", ".rmiss", ".rcall", ".glsl")

before_buildcmd_file(function (target, batchcmds, sourcefile, opt)
import("lib.detect.find_tool")

local glslc = assert(find_tool("glslc"), "glslc not found!")
local outputdir = target:extraconf("rules", "module.shader", "outputdir") or path.join(target:autogendir(), "rules", "module.shader")
local headerfile = path.join(outputdir, path.basename(sourcefile) .. ".h")

batchcmds:show_progress(opt.progress, "${color.build.object}generating shader header %s", sourcefile)
batchcmds:mkdir(outputdir)

batchcmds:vrunv(glslc.program, {"-mfmt=num", "-o", path(headerfile), path(sourcefile)})

-- add deps
batchcmds:add_depfiles(sourcefile)
batchcmds:set_depmtime(os.mtime(headerfile))
batchcmds:set_depcache(target:dependfile(headerfile))
end)
8 changes: 8 additions & 0 deletions xmake/task.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
task("test")
on_run(function ()
os.exec("xmake f -m debug --test=y")
os.exec("xmake build -g test")
os.exec("xmake run -g test")
end)

set_menu{}
10 changes: 10 additions & 0 deletions xmake/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- third party libraries
includes("package.lua")
-- project option
includes("option.lua")
-- unit test script
includes("task.lua")
-- project module config
includes("rule/module.lua")
-- project debug tool
includes("rule/debug.lua")