hikyuu2/hikyuu_pywrap/xmake.lua

95 lines
3.8 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
2023-10-15 00:30:45 +08:00
add_options("stackstrace")
2018-09-09 16:43:04 +08:00
add_deps("hikyuu")
2023-12-27 18:46:32 +08:00
add_packages("boost", "fmt", "spdlog", "flatbuffers", "pybind11", "cpp-httplib")
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)")
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
add_includedirs("../hikyuu_cpp")
2023-12-27 22:48:41 +08:00
add_files("./**.cpp")
2018-09-09 16:43:04 +08:00
2020-06-25 15:59:37 +08:00
add_rpathdirs("$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib")
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)
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.
local pydir = nil;
if os.getenv("CONDA_PREFIX") ~= nil then
local py3config = os.getenv("CONDA_PREFIX") .. "/bin/python3-config"
pydir = try { function () return os.iorun(py3config .. " --includes"):trim() end }
else
pydir = try { function () return os.iorun("python3-config --includes"):trim() end }
end
2024-01-09 18:40:30 +08:00
assert(pydir, "python3-config not found!")
2024-01-09 18:43:24 +08:00
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"
if not is_plat("cross") then
import("lib.detect.find_tool")
local python = assert(find_tool("python", {version = true}), "python not found, please install it first! note: python version must > 3.0")
local tmp = string.split(python.version, "%.")
dst_obj = dst_dir .. "core" .. tmp[1] .. tmp[2]
end
-- print(dst_obj)
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)
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")
2020-09-30 21:57:15 +08:00
os.cp(target:targetdir() .. '/libhikyuu.dylib', dst_dir)
2020-09-14 00:18:57 +08:00
else
os.trycp(target:targetdir() .. '/*.so.*', dst_dir)
2024-01-26 05:34:35 +08:00
if not is_plat("cross") then
2024-01-26 13:00:10 +08:00
os.trycp(target:targetdir() .. '/*.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