This commit is contained in:
ouczbs 2024-08-01 23:45:44 +08:00
parent 10423e024f
commit 0e1684de03
13 changed files with 112 additions and 31 deletions

View File

@ -1,4 +1,8 @@
#pragma once
#include "zlib.h"
ENGINE_API const char* engine();
inline Module engine_module{engine(), true};
#ifdef ENGINE_API_VAL
ENGINE_API inline Module engine_module{ engine(), false };
#else
ENGINE_API extern Module engine_module;
#endif

View File

@ -1,4 +1,5 @@
#pragma once
#include "zlib.h"
#include "core.h"
const char* asset();
inline Module asset_module{ asset(), false};

View File

@ -2,3 +2,13 @@
#include "zlib.h"
const char* core();
inline Module core_module{ core(), false};
struct ModuleManager;
struct ModuleManagerPtr {
ModuleManager* ptr;
ModuleManagerPtr();
};
CORE_API inline ModuleManagerPtr ms_instance;
struct ModuleManager {
ModuleManager();
static ModuleManager* Ptr();
};

View File

@ -3,3 +3,20 @@ const char* core()
{
return "core";
}
ModuleManager::ModuleManager()
{
std::cout << "ModuleManager::" << uintptr_t(this) << std::endl;
}
ModuleManager* ModuleManager::Ptr()
{
static ModuleManager module;
auto* ptr = &module;
return ptr;
}
ModuleManagerPtr::ModuleManagerPtr()
{
ptr = ModuleManager::Ptr();
}

View File

@ -8,8 +8,8 @@ struct Detail {
int del_count = 0;
};
struct Module;
inline Detail detail{};
inline std::vector<Module*>* pModuleList{};
ZLIB_API inline Detail detail;
ZLIB_API inline std::vector<Module*>* pModuleList;
struct Module {
std::string name;
bool kind;

View File

@ -6,3 +6,4 @@ target("zlib")
add_includedirs("include", {public = true})
add_packages("spdlog", {public = true})
add_rules("engine.api")
add_defines("ZLIB_API_TEST")

View File

@ -1,9 +0,0 @@
function main(target, name)
local api = string.upper(name) .. "_API"
if target:kind() == "static" then
target:add("defines", api .. "=", api .. "_VAL", {public = false})
else
target:add("defines", api.."=__declspec(dllimport)", {interface=true})
target:add("defines", api.."=__declspec(dllexport)", {public=false})
end
end

View File

@ -0,0 +1,37 @@
function find_exe_dir()
local os_name = os.host()
local arch_name = os.arch()
local mode_name = is_mode("debug") and "debug" or "release"
-- 构建生成目录路径
return path.join(os.projectdir(), "build", os_name, arch_name, mode_name)
end
function find_my_program(name, sdkdir, use_next)
import("lib.detect.find_file")
import("lib.detect.find_program")
import("lib.detect.find_tool")
local sdkdir = sdkdir or path.join(os.projectdir(), "tools")
local exedir = find_exe_dir()
local tool = find_tool(name, {pathes = {sdkdir, exedir, "/usr/local/bin"}})
local prog = tool and tool.program or find_program(name, {pathes = {sdkdir, exedir, "/usr/local/bin"}})
prog = prog or find_file(name, {sdkdir, exedir})
if (prog == nil) then
if os.host() ~= "windows" then
local outdata, errdata = os.iorun("which " .. name)
if (errdata ~= nil or errdata ~= "") then
prog = string.gsub(outdata, "%s+", "")
end
else
prog = find_file(name .. ".exe", {sdkdir})
end
end
if (prog == nil) then
if not use_next then
return find_my_program(name, path.join(sdkdir, name), true)
end
print(name .. " not found! under " .. sdkdir, exedir)
return
end
return {program = prog, sdkdir = sdkdir}
end

View File

@ -0,0 +1,23 @@
function add_define(target, name, is_static)
local api = string.upper(name) .. "_API"
if is_static then
target:add("defines", api .. "=", api .. "_VAL", {public = false})
else
target:add("defines", api.."=__declspec(dllimport)", {interface=true})
target:add("defines", api.."=__declspec(dllexport)", {public=false})
end
end
function main(target)
local name = target:name()
local is_static = target:kind() == "static"
add_define(target, name, is_static)
local deps = target:get("deps")
if not deps then return end
import("core.project.project")
for _,dep in ipairs(deps) do
local deptarget = project.target(dep)
if deptarget:kind() == "static" then
add_define(target, dep, is_static)
end
end
end

View File

@ -0,0 +1,5 @@
rule("engine.api")
on_config(function (target)
import("rule_api")
rule_api(target)
end)

View File

@ -1,16 +1,2 @@
rule("engine.api")
on_load(function (target)
print(target:name())
import("api_define")
api_define(target, target:name())
local deps = target:get("deps")
if not deps then return end
import("core.project.project")
local is_static = target:kind() == "static"
for _,name in ipairs(deps) do
local deptarget = project.target(name)
if deptarget:kind() == "static" then
api_define(target, name)
end
end
end)
includes("*/xmake.lua")
add_moduledirs(path.join(os.projectdir(), "engine/xmake/modules"))

View File

@ -1,4 +1,5 @@
#pragma once
#include "zlib.h"
#include "core.h"
VULKAN_API const char* vulkan();
inline Module vulkan_module{vulkan(), true};

View File

@ -1,4 +1,9 @@
#pragma once
#include "zlib.h"
#include "core.h"
ZWORLD_API const char* zworld();
inline Module zworld_module{zworld(), true};
#ifdef ZWORLD_API_VAL
ZWORLD_API inline Module zworld_module{ zworld(), false };
#else
ZWORLD_API extern Module zworld_module;
#endif