This commit is contained in:
ouczbs 2024-08-02 22:14:00 +08:00
parent 0e1684de03
commit d71b9a90a0
7 changed files with 50 additions and 10 deletions

View File

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

View File

@ -21,6 +21,7 @@ struct Module {
if (!pModuleList) {
pModuleList = new std::vector<Module*>;
}
auto ptr = this;
pModuleList->push_back(this);
std::string kind_str = kind ? std::string("shared") : std::string("static");
std::cout << detail.count << ":" << uintptr_t(&zlog::zlog) << "::" << name << ":" << kind_str << std::endl;

View File

@ -1,5 +1,6 @@
#include "api.h"
ENGINE_API Module engine_module{ engine(), true };
ENGINE_API inline Module engine_module_hello{ "engine_module_hello", true };
const char* engine()
{
return "engine";

View File

@ -7,8 +7,8 @@ target("engine")
add_includedirs("modules/asset/include", {public = true})
add_includedirs("modules/core/include", {public = true})
add_includedirs("modules/zlib/include", {public = true})
add_deps("asset", "zlib", "core")
add_rules("engine.api")
add_deps("asset", "zlib", "core", { inherit = false})
add_rules("engine.api", {inherit = false})
includes("xmake/xmake.lua")
includes("modules/*/xmake.lua")

View File

@ -1,10 +1,22 @@
import("core.project.project")
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})
target:add("defines", api.."=__declspec(dllexport)", api .. "_VAL", {public=false})
end
end
function add_packages(target, deptarget)
local packs = deptarget:get("packages")
if packs and #packs > 0 then
local packages = {}
for _,v in ipairs(packs) do
table.insert(packages, v)
end
table.insert(packages, {public = true})
target:add("packages", unpack(packages))
end
end
function main(target)
@ -13,11 +25,37 @@ function main(target)
add_define(target, name, is_static)
local deps = target:get("deps")
if not deps then return end
import("core.project.project")
local inherit = target:extraconf("rules", "engine.api", "inherit")
local linkdirs = {}
for _,dep in ipairs(deps) do
local deptarget = project.target(dep)
if deptarget:kind() == "static" then
add_define(target, dep, is_static)
add_packages(target, deptarget)
if inherit == false then
target:add("links", dep)
local dir = deptarget:targetdir()
if not linkdirs[dir] then
target:add("linkdirs", dir)
linkdirs[dir] = true
end
end
end
end
-- local real_deps = {}
-- local links = {}
-- for _,dep in ipairs(deps) do
-- local deptarget = project.target(dep)
-- if deptarget:kind() == "static" then
-- add_define(target, dep, is_static)
-- --add_packages(target, deptarget)
-- table.insert(links, dep)
-- elseif is_link then
-- table.insert(real_deps, dep)
-- end
-- end
-- if is_link then
-- --target:add("links", links)
-- --target:set("deps", real_deps)
-- end
end

View File

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

View File

@ -2,5 +2,7 @@
const char* vulkan()
{
auto c1 = engine_module_hello.name.c_str();
auto c2 = zlib_module.name.c_str();
return "vulkan";
}