hikyuu2/hikyuu_pywrap/xmake.lua

111 lines
4.4 KiB
Lua
Raw Normal View History

2019-06-04 23:13:32 +08:00
add_requires("pybind11", {system = false, alias = "pybind11"})
2023-12-26 18:25:50 +08:00
2020-06-25 15:59:37 +08:00
target("core")
2020-04-08 00:24:12 +08:00
set_kind("shared")
2024-01-24 07:26:28 +08:00
set_default(false)
-- if is_mode("debug") then
-- set_default(false) --会默认禁用这个target的编译除非显示指定xmake build _hikyuu才会去编译但是target还存在里面的files会保留到vcproj
-- --set_enable(false) --set_enable(false)会彻底禁用这个target连target的meta也不会被加载vcproj不会保留它
-- end
2023-03-29 02:10:34 +08:00
2018-09-09 16:43:04 +08:00
add_deps("hikyuu")
add_packages("boost", "fmt", "spdlog", "flatbuffers", "pybind11")
if is_plat("windows") then
2020-06-25 15:59:37 +08:00
set_filename("core.pyd")
2020-08-01 18:52:56 +08:00
add_cxflags("-wd4251")
2018-09-21 01:08:43 +08:00
else
2020-06-25 15:59:37 +08:00
set_filename("core.so")
end
2023-03-29 02:10:34 +08:00
if is_plat("windows") and get_config("kind") == "shared" then
2023-03-29 02:10:34 +08:00
add_defines("HKU_API=__declspec(dllimport)")
2024-07-17 11:08:04 +08:00
add_defines("HKU_UTILS_API=__declspec(dllimport)")
2023-03-29 02:10:34 +08:00
add_cxflags("-wd4566")
end
local cc = get_config("cc")
local cxx = get_config("cxx")
if (cc and string.find(cc, "clang")) or (cxx and string.find(cxx, "clang")) then
add_cxflags("-Wno-error=parentheses-equality -Wno-error=missing-braces")
end
2024-08-21 14:59:00 +08:00
if is_plat("linux", "cross") then
add_rpathdirs("$ORIGIN", "$ORIGIN/cpp")
end
if is_plat("macosx") then
add_linkdirs("/usr/lib")
-- macosx 下不能主动链接 python所以需要使用如下编译选项
add_shflags("-undefined dynamic_lookup")
end
2023-03-29 02:10:34 +08:00
add_includedirs("../hikyuu_cpp")
2023-12-27 22:48:41 +08:00
add_files("./**.cpp")
2018-09-09 16:43:04 +08:00
2024-01-09 16:58:03 +08:00
on_load("windows", "linux", "macosx", function(target)
import("lib.detect.find_tool")
2024-01-09 18:40:30 +08:00
if is_plat("windows") then
-- detect installed python3
local python = assert(find_tool("python", {version = true}), "python not found, please install it first! note: python version must > 3.0")
assert(python.version > "3", python.version .. " python version must > 3.0, please use python3.0 or later!")
-- find python include and libs directory
local pydir = os.iorun("python -c \"import sys; print(sys.executable)\"")
pydir = path.directory(pydir)
if pydir:endswith("Scripts") then
-- if venv is activated, find the real python directory
file = io.open(pydir .. "/../pyvenv.cfg", "r")
for line in file:lines() do
if string.find(line, "home =") then
-- 使用 string.gmatch 函数抽取路径
for path in string.gmatch(line, "home = (.*)") do
pydir = path
end
end
end
file:close()
end
2024-01-09 18:43:24 +08:00
target:add("includedirs", pydir .. "/include")
target:add("linkdirs", pydir .. "/libs")
2024-01-09 18:40:30 +08:00
return
2024-01-09 16:58:03 +08:00
end
2024-01-09 18:40:30 +08:00
-- get python include directory.
2024-01-28 23:02:40 +08:00
local pydir = try { function () return os.iorun("python3-config --includes"):trim() end }
target:add("cxflags", pydir)
2024-01-09 16:58:03 +08:00
end)
2020-06-25 15:59:37 +08:00
after_build(function(target)
2020-08-15 00:24:35 +08:00
if is_plat("macosx") then
os.run(format("install_name_tool -change @rpath/libhikyuu.dylib @loader_path/libhikyuu.dylib %s/%s", target:targetdir(), "core.so"))
end
2020-06-25 15:59:37 +08:00
local dst_dir = "$(projectdir)/hikyuu/cpp/"
2024-01-26 05:34:35 +08:00
local dst_obj = dst_dir .. "core.so"
2024-01-29 19:16:03 +08:00
-- need xmake 445e43b40846b29b9abb1293b32b27b7104f54fa
2024-01-26 05:34:35 +08:00
if not is_plat("cross") then
2024-01-29 19:16:03 +08:00
local stmt = [[python -c 'import sys; v = sys.version_info; print(str(v.major)+str(v.minor))']]
local python_version = os.iorun(stmt):trim()
dst_obj = dst_dir .. "core" .. python_version
2024-01-26 05:34:35 +08:00
end
2024-01-26 04:46:44 +08:00
2020-09-14 00:18:57 +08:00
if is_plat("windows") then
2024-01-26 13:00:10 +08:00
os.cp(target:targetdir() .. '/core.pyd', dst_obj .. ".pyd")
os.cp(target:targetdir() .. '/*.dll', dst_dir)
2024-01-26 16:26:17 +08:00
os.cp(target:targetdir() .. '/hikyuu.lib', dst_dir)
2020-09-14 00:18:57 +08:00
elseif is_plat("macosx") then
2024-01-26 13:00:10 +08:00
os.cp(target:targetdir() .. '/core.so', dst_obj .. ".so")
2024-01-27 23:04:40 +08:00
os.cp(target:targetdir() .. '/*.dylib', dst_obj)
2020-09-14 00:18:57 +08:00
else
2024-01-27 23:02:16 +08:00
os.trycp(target:targetdir() .. '/*.so', dst_dir)
os.trycp(target:targetdir() .. '/*.so.*', dst_dir)
2024-01-26 05:34:35 +08:00
if not is_plat("cross") then
2024-01-27 23:02:16 +08:00
os.trymv(target:targetdir() .. '/core.so', dst_obj .. ".so")
2024-01-26 05:34:35 +08:00
end
2020-09-14 00:18:57 +08:00
end
2020-06-25 15:59:37 +08:00
end)
2018-09-09 16:43:04 +08:00