cross support (continue)

This commit is contained in:
fasiondog 2023-03-26 17:27:51 +08:00
parent 1225ec4243
commit f0d87f7b09
10 changed files with 33 additions and 585 deletions

View File

@ -20,8 +20,8 @@ int main(int argc, char* argv[]) {
#endif
// 配置文件的位置自行修改
// hikyuu_init("C:\\Users\\admin\\.hikyuu\\hikyuu.ini");
hikyuu_init("/home/fasiondog/.hikyuu/hikyuu.ini");
hikyuu_init("C:\\Users\\admin\\.hikyuu\\hikyuu.ini");
// hikyuu_init("/home/fasiondog/.hikyuu/hikyuu.ini");
StockManager& sm = StockManager::instance();

View File

@ -69,24 +69,11 @@ target("hikyuu")
add_links("boost_system")
end
if is_plat("windows") then
-- nng 静态链接需要的系统库
add_syslinks("ws2_32", "advapi32")
end
-- add files
add_files("./**.cpp")
add_headerfiles("../(hikyuu/**.h)|**doc.h")
-- on_load(function(target)
-- assert(os.getenv("BOOST_ROOT"), [[Missing environment variable: BOOST_ROOT
-- You need to specify where the boost headers is via the BOOST_ROOT variable!]])
-- assert(os.getenv("BOOST_LIB"), [[Missing environment variable: BOOST_LIB
-- You need to specify where the boost library is via the BOOST_LIB variable!]])
-- end)
before_build(function(target)
if is_plat("macosx") then
if not os.exists("/usr/local/include/mysql") then

View File

@ -40,7 +40,7 @@ target("unit-test")
set_kind("binary")
set_default(false)
add_packages("fmt", "spdlog", "doctest", "mysql", "sqlite3")
add_packages("boost", "fmt", "spdlog", "doctest", "mysql", "sqlite3")
add_includedirs("..")
@ -64,9 +64,9 @@ target("unit-test")
add_deps("hikyuu")
if is_plat("linux") or is_plat("macosx") then
add_links("boost_unit_test_framework")
add_links("boost_filesystem")
add_links("boost_serialization")
-- add_links("boost_unit_test_framework")
-- add_links("boost_filesystem")
-- add_links("boost_serialization")
add_links("sqlite3")
add_shflags("-Wl,-rpath=$ORIGIN", "-Wl,-rpath=$ORIGIN/../lib")
end
@ -86,7 +86,7 @@ target("small-test")
set_kind("binary")
set_default(false)
add_packages("fmt", "spdlog", "doctest", "mysql", "sqlite3")
add_packages("boost", "fmt", "spdlog", "doctest", "mysql", "sqlite3")
add_includedirs("..")
--add_defines("BOOST_TEST_DYN_LINK")
@ -111,9 +111,9 @@ target("small-test")
add_deps("hikyuu")
if is_plat("linux") or is_plat("macosx") then
add_links("boost_unit_test_framework")
add_links("boost_filesystem")
add_links("boost_atomic")
-- add_links("boost_unit_test_framework")
-- add_links("boost_filesystem")
-- add_links("boost_atomic")
add_shflags("-Wl,-rpath=$ORIGIN", "-Wl,-rpath=$ORIGIN/../lib")
end

View File

@ -1,37 +0,0 @@
package("flatbuffers")
set_homepage("http://google.github.io/flatbuffers/")
set_description("FlatBuffers is a cross platform serialization library architected for maximum memory efficiency.")
set_license("Apache-2.0")
add_urls("https://github.com/google/flatbuffers/archive/$(version).zip",
"https://github.com/google/flatbuffers.git")
add_versions("v1.12.0", "4b8b21adbfe8a74b90604161afcf87c125a26b86c99327e7a04525080606536c")
add_versions("v2.0.0", "ffd68aebdfb300c9e82582ea38bf4aa9ce65c77344c94d5047f3be754cc756ea")
add_versions("v23.1.21", "48597d6a6f8ca67a02ae8d8494b3bfc9136eb93da60a538d5bfc024f7c564f97")
add_deps("cmake")
on_install("windows", "linux", "macosx", "mingw", "android", "iphoneos", "cross", function(package)
local configs = {"-DFLATBUFFERS_BUILD_TESTS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=" .. (package:config("shared") and "ON" or "OFF"))
if package:is_cross() then
table.insert(configs, "-DFLATBUFFERS_BUILD_FLATC=OFF")
table.insert(configs, "-DFLATBUFFERS_BUILD_FLATHASH=OFF")
end
import("package.tools.cmake").install(package, configs)
package:addenv("PATH", "bin")
end)
on_test(function(package)
if not package:is_cross() then
os.vrun("flatc --version")
end
assert(package:check_cxxsnippets({test = [[
void test() {
flatbuffers::FlatBufferBuilder builder;
builder.CreateString("MyMonster");
flatbuffers::DetachedBuffer dtbuilder = builder.Release();
}
]]}, {configs = {languages = "c++14"}, includes = "flatbuffers/flatbuffers.h"}))
end)

View File

@ -1,74 +0,0 @@
package("nng")
set_homepage("https://github.com/nanomsg/nng")
set_description("NNG, like its predecessors nanomsg (and to some extent ZeroMQ), is a lightweight, broker-less library, offering a simple API to solve common recurring messaging problems.")
add_urls("https://github.com/nanomsg/nng/archive/v$(version).zip")
add_versions("1.5.2", "652ff3a2dbaeae194942205c369e9259e2b5cb5985d679d744cbfb95d1c807a3")
add_versions("1.4.0", "43674bb15d0f3810cf3602d2662cc91b6576b914492710244125e32b29f546b8")
add_versions("1.3.2", "2616110016c89ed3cbd458022ba41f4f545ab17f807546d2fdd0789b55d64471")
-- default is false
add_configs("NNG_ELIDE_DEPRECATED", {description = "Elide deprecated functionality.", default = false, type = "boolean"})
add_configs("NNG_TRANSPORT_ZEROTIER", {description = "Enable ZeroTier transport (requires libzerotiercore).", default = false, type = "boolean"})
add_configs("NNG_ENABLE_TLS", {description = "Enable TLS support.", default = false, type = "boolean"})
-- default is true
add_configs("NNG_ENABLE_STATS", {description = "Enable statistics.", default = true, type = "boolean"})
add_configs("NNG_PROTO_BUS0", {description = "Enable BUSv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_PAIR0", {description = "Enable PAIRv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_PAIR1", {description = "Enable PAIRv1 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_PUSH0", {description = "Enable PUSHv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_PULL0", {description = "Enable PULLv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_PUB0", {description = "Enable PUBv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_SUB0", {description = "Enable SUBv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_REQ0", {description = "Enable REQv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_REP0", {description = "Enable REPv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_RESPONDENT0", {description = "Enable RESPONDENTv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_PROTO_SURVEYOR0", {description = "Enable SURVEYORv0 protocol.", default = true, type = "boolean"})
add_configs("NNG_ENABLE_HTTP", {description = "Enable HTTP API.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_INPROC", {description = "Enable inproc transport.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_IPC", {description = "Enable IPC transport.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_TCP", {description = "Enable TCP transport.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_TLS", {description = "Enable TLS transport.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_WS", {description = "Enable WebSocket transport.", default = true, type = "boolean"})
add_configs("NNG_TRANSPORT_WSS", {description = "Enable WSS transport.", default = true, type = "boolean"})
if is_plat("linux") then
add_syslinks("pthread")
end
on_load(function (package)
if not package:config("shared") then
package:add("defines", "NNG_STATIC_LIB")
end
if package:config("NNG_ENABLE_TLS") then
package:add("deps", "mbedtls")
end
end)
add_deps("cmake")
on_install("windows", "linux", "macosx", "android", "iphoneos", "cross", function(package)
local configs = {"-DNNG_TESTS=OFF", "-DNNG_ENABLE_NNGCAT=OFF"}
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
for name, enabled in pairs(package:configs()) do
if not package:extraconf("configs", name, "builtin") then
table.insert(configs, "-D" .. name .. "=" .. (enabled and "ON" or "OFF"))
end
end
import("package.tools.cmake").install(package, configs)
end)
on_test(function(package)
assert(package:check_csnippets({test = [[
#include <nng/nng.h>
#include <nng/protocol/reqrep0/req.h>
#include <nng/supplemental/util/platform.h>
static void test() {
nng_socket sock;
int rv;
nng_req0_open(&sock);
nng_close(sock);
}
]]}, {includes = "nng/nng.h"}))
end)

View File

@ -1,86 +0,0 @@
import("lib.detect.find_path")
import("lib.detect.find_library")
import("lib.detect.find_program")
import("lib.detect.find_programver")
function _find_binary(package, opt)
local result = package:find_tool("python3", opt)
if not result then
result = package:find_tool("python", opt)
end
if result then
-- check if pip, setuptools and wheel are installed
local ok = try { function ()
os.vrunv(result.program, {"-c", "import pip"})
os.vrunv(result.program, {"-c", "import setuptools"})
os.vrunv(result.program, {"-c", "import wheel"})
return true
end}
if not ok then
return false
end
end
end
function _find_library(package, opt)
-- init search options
opt = opt or {}
opt.paths = opt.paths or {}
table.insert(opt.paths, "$(env PATH)")
table.insert(opt.paths, "$(env CONDA_PREFIX)")
-- find python
local program = find_program("python3", opt)
if not program then
program = find_program("python", opt)
end
local version = nil
if program then
opt.command = function ()
local outs, errs = os.iorunv(program, {"--version"})
return ((outs or "") .. (errs or "")):trim()
end
version = find_programver(program, opt)
end
if not program or not version then
return false
end
-- find library and header
local exepath = path.directory(program)
local link = nil
local libpath = nil
local includepath = nil
if package:is_plat("windows") then
link = format("python" .. table.concat(table.slice(version:split("%."), 1, 2), ""))
libpath = find_library(link, {exepath}, {suffixes = {"libs"}})
linkdirs = {}
includepath = find_path("Python.h", {exepath}, {suffixes = {"include"}})
else
local pyver = table.concat(table.slice(version:split("%."), 1, 2), ".")
link = format("python" .. pyver)
libpath = find_library(link, {path.directory(exepath)}, {suffixes = {"lib", "lib64", "lib/x86_64-linux-gnu"}})
includepath = find_path("Python.h", {path.directory(exepath)}, {suffixes = {"include/python" .. pyver}})
end
if libpath and includepath then
local result = {
version = version,
links = libpath.link,
linkdirs = libpath.linkdir,
includedirs = includepath
}
return result
end
end
function main(package, opt)
if opt.system then
if package:is_binary() then
return _find_binary(package, opt)
else
return _find_library(package, opt)
end
end
end

View File

@ -1,262 +0,0 @@
package("python")
set_homepage("https://www.python.org/")
set_description("The python programming language.")
if is_host("windows") then
if is_arch("x86", "i386") or os.arch() == "x86" then
add_urls("https://github.com/xmake-mirror/python-windows/releases/download/$(version)/python-$(version).win32.zip")
add_versions("2.7.18", "95e21c87c9f38fa8068e014fc3683c3bc2c827f64875e620b9ecd3c75976a79c")
add_versions("3.7.9", "55c8a408a11e598964f5d581589cf7f8c622e3cad048dce331ee5a61e5a6f57f")
add_versions("3.8.10", "f520d2880578df076e3df53bf9e147b81b5328db02d8d873670a651fa076be50")
add_versions("3.9.5", "ce0bfe8ced874d8d74a6cf6a98f13f5afee27cffbaf2d1ee0f09d3a027fab299")
add_versions("3.9.6", "2918246384dfb233bd8f8c2bcf6aa3688e6834e84ab204f7c962147c468f8d12")
add_versions("3.9.10", "e2c8e6b792748289ac27ef8462478022c96e24c99c4c3eb97d3afe510d9db646")
add_versions("3.9.13", "c60ec0da0adf3a31623073d4fa085da62747085a9f23f4348fe43dfe94ea447b")
add_versions("3.10.6", "c1a07f7685b5499f58cfad2bb32b394b853ba12b8062e0f7530f2352b0942096")
else
add_urls("https://github.com/xmake-mirror/python-windows/releases/download/$(version)/python-$(version).win64.zip")
add_versions("2.7.18", "6680835ed5b818e2c041c7033bea47ace17f6f3b73b0d6efb6ded8598a266754")
add_versions("3.7.9", "d0d879c934b463d46161f933db53a676790d72f24e92143f629ee5629ae286bc")
add_versions("3.8.10", "acf35048274404dd415e190bf5b928fae3b03d8bb5dfbfa504f9a183361468bd")
add_versions("3.9.5", "3265059edac21bf4c46fac13553a5d78417e7aa209eceeffd0250aa1dd8d6fdf")
add_versions("3.9.6", "57ccd1b1b5fbc62882bd2a6f47df6e830ba39af741acf0a1d2f161eef4e87f2e")
add_versions("3.9.10", "4cee67e2a529fe363e34f0da57f8e5c3fc036913dc838b17389b2319ead0927e")
add_versions("3.9.13", "6774fdd872fc55b028becc81b7d79bdcb96c5e0eb1483cfcd38224b921c94d7d")
add_versions("3.10.6", "8cbc234939a679687da44c3bbc6d6ce375ea4b84c4fa8dbc1bf5befc43254b58")
end
else
set_urls("https://www.python.org/ftp/python/$(version)/Python-$(version).tgz",
"https://github.com/xmake-mirror/cpython/releases/download/v$(version)/Python-$(version).tgz")
add_versions("2.7.18", "da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814")
add_versions("3.7.9", "39b018bc7d8a165e59aa827d9ae45c45901739b0bbb13721e4f973f3521c166a")
add_versions("3.8.10", "b37ac74d2cbad2590e7cd0dd2b3826c29afe89a734090a87bf8c03c45066cb65")
add_versions("3.9.5", "e0fbd5b6e1ee242524430dee3c91baf4cbbaba4a72dd1674b90fda87b713c7ab")
add_versions("3.9.6", "d0a35182e19e416fc8eae25a3dcd4d02d4997333e4ad1f2eee6010aadc3fe866")
add_versions("3.9.10", "1aa9c0702edbae8f6a2c95f70a49da8420aaa76b7889d3419c186bfc8c0e571e")
add_versions("3.9.13", "829b0d26072a44689a6b0810f5b4a3933ee2a0b8a4bfc99d7c5893ffd4f97c44")
add_versions("3.10.6", "848cb06a5caa85da5c45bd7a9221bb821e33fc2bdcba088c127c58fad44e6343")
end
if not is_plat(os.host()) or not is_arch(os.arch()) then
set_kind("binary")
end
if is_host("linux", "bsd") then
add_deps("libffi", "zlib", {host = true})
add_syslinks("util", "pthread", "dl")
end
on_load("@windows", "@msys", "@cygwin", function (package)
-- set includedirs
package:add("includedirs", "include")
-- set python environments
local PYTHONPATH = package:installdir("Lib", "site-packages")
package:addenv("PYTHONPATH", PYTHONPATH)
package:addenv("PATH", "bin")
package:addenv("PATH", "Scripts")
end)
on_load("@macosx", "@linux", "@bsd", function (package)
local version = package:version()
-- set openssl dep
if version:ge("3.10") then
-- starting with Python 3.10, Python requires OpenSSL 1.1.1 or newer
-- see https://peps.python.org/pep-0644/
package:add("deps", "openssl >=1.1.1-a", "ca-certificates", {host = true})
else
package:add("deps", "openssl", "ca-certificates", {host = true})
end
-- set includedirs
local pyver = ("python%d.%d"):format(version:major(), version:minor())
if version:ge("3.0") and version:le("3.8") then
package:add("includedirs", path.join("include", pyver .. "m"))
else
package:add("includedirs", path.join("include", pyver))
end
-- set python environments
local PYTHONPATH = package:installdir("lib", pyver, "site-packages")
package:addenv("PYTHONPATH", PYTHONPATH)
package:addenv("PATH", "bin")
package:addenv("PATH", "Scripts")
end)
on_fetch("fetch")
on_install("@windows|x86", "@windows|x64", "@msys", "@cygwin", function (package)
if package:version():ge("3.0") then
os.cp("python.exe", path.join(package:installdir("bin"), "python3.exe"))
else
os.cp("python.exe", path.join(package:installdir("bin"), "python2.exe"))
end
os.cp("*.exe", package:installdir("bin"))
os.cp("*.dll", package:installdir("bin"))
os.cp("Lib", package:installdir())
os.cp("libs/*", package:installdir("lib"))
os.cp("*", package:installdir())
local python = path.join(package:installdir("bin"), "python.exe")
if package:version():eq("3.9.10") then
-- https://github.com/xmake-io/xmake-repo/issues/1013
os.vrunv(python, {"-m", "pip", "install", "--upgrade", "--force-reinstall", "pip==21.3.1"})
else
os.vrunv(python, {"-m", "pip", "install", "--upgrade", "--force-reinstall", "pip"})
end
os.vrunv(python, {"-m", "pip", "install", "wheel"})
end)
on_install("@macosx", "@bsd", "@linux", function (package)
-- init configs
local configs = {"--enable-ipv6", "--with-ensurepip", "--enable-optimizations"}
table.insert(configs, "--datadir=" .. package:installdir("share"))
table.insert(configs, "--datarootdir=" .. package:installdir("share"))
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
-- add openssl libs path for detecting
local openssl_dir
local openssl = package:dep("openssl"):fetch()
if openssl then
for _, linkdir in ipairs(openssl.linkdirs) do
if path.filename(linkdir) == "lib" then
openssl_dir = path.directory(linkdir)
if openssl_dir then
break
end
end
end
end
if openssl_dir then
if package:version():ge("3.0") then
table.insert(configs, "--with-openssl=" .. openssl_dir)
else
io.gsub("setup.py", "/usr/local/ssl", openssl_dir)
end
end
-- allow python modules to use ctypes.find_library to find xmake's stuff
if package:is_plat("macosx") then
io.gsub("Lib/ctypes/macholib/dyld.py", "DEFAULT_LIBRARY_FALLBACK = %[", format("DEFAULT_LIBRARY_FALLBACK = [ '%s/lib',", package:installdir()))
end
-- add flags for macOS
local cppflags = {}
local ldflags = {}
if package:is_plat("macosx") then
-- get xcode information
import("core.tool.toolchain")
local xcode_dir
local xcode_sdkver
local target_minver
local xcode = toolchain.load("xcode", {plat = package:plat(), arch = package:arch()})
if xcode and xcode.config and xcode:check() then
xcode_dir = xcode:config("xcode")
xcode_sdkver = xcode:config("xcode_sdkver")
target_minver = xcode:config("target_minver")
end
xcode_dir = xcode_dir or get_config("xcode")
xcode_sdkver = xcode_sdkver or get_config("xcode_sdkver")
target_minver = target_minver or get_config("target_minver")
-- TODO will be deprecated after xmake v2.5.1
xcode_sdkver = xcode_sdkver or get_config("xcode_sdkver_macosx")
if not xcode_dir or not xcode_sdkver then
-- maybe on cross platform, we need find xcode envs manually
local xcode = import("detect.sdks.find_xcode")(nil, {force = true, plat = package:plat(), arch = package:arch()})
if xcode then
xcode_dir = xcode.sdkdir
xcode_sdkver = xcode.sdkver
end
end
-- TODO will be deprecated after xmake v2.5.1
target_minver = target_minver or get_config("target_minver_macosx")
if not target_minver then
local macos_ver = macos.version()
if macos_ver then
target_minver = macos_ver:major() .. "." .. macos_ver:minor()
end
end
if xcode_dir and xcode_sdkver then
-- help Python's build system (setuptools/pip) to build things on SDK-based systems
-- the setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
table.insert(cppflags, "-isysroot " .. xcode_sdkdir)
table.insert(cppflags, "-I" .. path.join(xcode_sdkdir, "/usr/include"))
table.insert(ldflags, "-isysroot " .. xcode_sdkdir)
-- for the Xlib.h, Python needs this header dir with the system Tk
-- yep, this needs the absolute path where zlib needed a path relative to the SDK.
table.insert(cppflags, "-I" .. path.join(xcode_sdkdir, "/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"))
end
-- avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
if target_minver then
table.insert(configs, "MACOSX_DEPLOYMENT_TARGET=" .. target_minver)
end
end
-- add pic
if package:is_plat("linux") and package:config("pic") ~= false then
table.insert(cppflags, "-fPIC")
end
-- add external path for zlib and libffi
for _, libname in ipairs({"zlib", "libffi"}) do
local lib = package:dep(libname)
if lib and not lib:is_system() then
local fetchinfo = lib:fetch({external = false})
if fetchinfo then
for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
table.insert(cppflags, "-I" .. includedir)
end
for _, linkdir in ipairs(fetchinfo.linkdirs) do
table.insert(ldflags, "-L" .. linkdir)
end
end
end
end
if #cppflags > 0 then
table.insert(configs, "CPPFLAGS=" .. table.concat(cppflags, " "))
end
if #ldflags > 0 then
table.insert(configs, "LDFLAGS=" .. table.concat(ldflags, " "))
end
-- unset these so that installing pip and setuptools puts them where we want
-- and not into some other Python the user has installed.
import("package.tools.autoconf").configure(package, configs, {envs = {PYTHONHOME = "", PYTHONPATH = ""}})
os.vrunv("make", {"install", "-j4", "PYTHONAPPSDIR=" .. package:installdir()})
if package:version():ge("3.0") then
os.cp(path.join(package:installdir("bin"), "python3"), path.join(package:installdir("bin"), "python"))
os.cp(path.join(package:installdir("bin"), "python3-config"), path.join(package:installdir("bin"), "python-config"))
end
-- install wheel
local python = path.join(package:installdir("bin"), "python")
local version = package:version()
local pyver = ("python%d.%d"):format(version:major(), version:minor())
local envs = {
PATH = package:installdir("bin"),
PYTHONPATH = package:installdir("lib", pyver, "site-packages"),
LD_LIBRARY_PATH = package:installdir("lib")
}
os.vrunv(python, {"-m", "pip", "install", "--upgrade", "--force-reinstall", "pip"}, {envs = envs})
os.vrunv(python, {"-m", "pip", "install", "wheel"}, {envs = envs})
end)
on_test(function (package)
os.vrun("python --version")
os.vrun("python -c \"import pip\"")
os.vrun("python -c \"import setuptools\"")
os.vrun("python -c \"import wheel\"")
if package:kind() ~= "binary" then
assert(package:has_cfuncs("PyModule_New", {includes = "Python.h"}))
end
end)

View File

@ -56,6 +56,10 @@ target("core")
pydir = path.directory(pydir)
target:add("includedirs", pydir .. "/include")
target:add("linkdirs", pydir .. "/libs")
local out, err = os.iorun("python --version")
local ver = (out .. err):trim():match("%d+.%d+"):gsub("%p+", "")
target:add("links", "libboost_python"..ver.."-mt")
return
end
@ -107,11 +111,11 @@ target("core")
os.trycp(target:targetdir() .. '/*.so.*', dst_dir)
end
os.cp("$(env BOOST_LIB)/boost_date_time*.dll", dst_dir)
os.cp("$(env BOOST_LIB)/boost_filesystem*.dll", dst_dir)
os.cp("$(env BOOST_LIB)/boost_python3*.dll", dst_dir)
os.cp("$(env BOOST_LIB)/boost_serialization*.dll", dst_dir)
os.cp("$(env BOOST_LIB)/boost_system*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/boost_date_time*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/boost_filesystem*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/boost_python3*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/boost_serialization*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/boost_system*.dll", dst_dir)
-- os.cp("$(env BOOST_LIB)/libboost_date_time*.so.*", dst_dir)
-- os.cp("$(env BOOST_LIB)/libboost_filesystem*.so.*", dst_dir)
-- os.cp("$(env BOOST_LIB)/libboost_python3*.so.*", dst_dir)

101
setup.py
View File

@ -20,31 +20,6 @@ def check_xmake():
return False if xmake != 0 else True
def get_boost_envrionment():
"""
BOOST
@return (current_boost_root, current_boost_lib)
"""
current_dir = os.getcwd()
current_boost_root = ''
current_boost_lib = ''
if 'BOOST_ROOT' in os.environ:
current_boost_root = os.environ['BOOST_ROOT']
if 'BOOST_LIB' in os.environ:
current_boost_lib = os.environ['BOOST_LIB']
else:
current_boost_lib = current_boost_root + '/stage/lib'
os.environ['BOOST_LIB'] = current_boost_lib
else:
for dir in os.listdir():
if len(dir) >= 5 and dir[:5] == 'boost' and os.path.isdir(dir):
current_boost_root = current_dir + '/' + dir
current_boost_lib = current_dir + '/' + dir + '/stage/lib'
os.environ['BOOST_ROOT'] = current_boost_root
os.environ['BOOST_LIB'] = current_boost_lib
return (current_boost_root, current_boost_lib)
def get_python_version():
"""获取当前 python版本"""
py_version = platform.python_version_tuple()
@ -64,14 +39,11 @@ def get_current_compile_info():
current_arch = 'x86_64' if current_bits == 64 else 'i386'
py_version = get_python_version()
current_boost_root, current_boost_lib = get_boost_envrionment()
current_compile_info = {
'plat': sys.platform,
'arch': current_arch,
'mode': '',
'py_version': py_version,
'boost_root': current_boost_root,
'boost_lib': current_boost_lib
}
return current_compile_info
@ -87,8 +59,6 @@ def get_history_compile_info():
'arch': '',
'mode': '',
'py_version': 0,
'boost_root': '',
'boost_lib': ''
}
return result
@ -99,43 +69,6 @@ def save_current_compile_info(compile_info):
json.dump(compile_info, f)
def build_boost(mode):
""" 编译依赖的 boost 库 """
new_mode = 'release' if mode == 'release' else 'debug'
current_boost_root, current_boost_lib = get_boost_envrionment()
if current_boost_root == '' or current_boost_lib == '':
print("Can't get boost environment!")
return
current_dir = os.getcwd()
if sys.platform == 'win32':
os.chdir(current_boost_root)
if not os.path.exists('b2.exe'):
os.system('bootstrap.bat')
os.system(
'b2 {} link=static runtime-link=shared address-model=64 -j 4 --with-date_time'
' --with-filesystem --with-system --with-test'.format(mode))
os.system(
'b2 {} link=shared runtime-link=shared address-model=64 -j 4 --with-python'
' --with-serialization'.format(mode))
#os.system(
# 'b2 {} link=shared runtime-link=shared address-model=64 -j 4 --with-python'
# ' --with-date_time --with-filesystem --with-system --with-test'
# ' --with-serialization'.format(mode))
os.chdir(current_dir)
else:
# 新版的 boost 配置 project-cofig.jam 中的 python 版本无效,必须在当前 python 下重新编译 b2
cmd = 'cd {boost} ; ./bootstrap.sh; '\
'./b2 {mode} link=shared address-model=64 -j 4 --with-python --with-serialization; '\
'./b2 {mode} link=static address-model=64 cxxflags=-fPIC -j 4 --with-date_time '\
'--with-filesystem --with-system --with-test --with-atomic; '\
'cd {current}'.format(boost=current_boost_root, mode=mode, current=current_dir)
# cmd = 'cd {boost} ; if [ ! -f "b2" ]; then ./bootstrap.sh ; fi; '\
# './b2 {mode} link=shared address-model=64 -j 4 --with-python --with-serialization '\
# '--with-date_time --with-filesystem --with-system --with-test; '\
# 'cd {current}'.format(boost=current_boost_root, mode=mode, current=current_dir)
os.system(cmd)
def clear_with_python_changed(mode):
"""
python版本发生变化时python编译结果
@ -166,9 +99,6 @@ def clear_with_python_changed(mode):
exit(0)
if os.path.lexists(build_pywrap_dir):
shutil.rmtree(build_pywrap_dir)
current_boost_root, _ = get_boost_envrionment()
if os.path.lexists('{}/bin.v2/libs/python'.format(current_boost_root)):
shutil.rmtree('{}/bin.v2/libs/python'.format(current_boost_root))
#------------------------------------------------------------------------------
@ -190,21 +120,11 @@ def start_build(verbose=False, mode='release', worker_num=2):
print("Python version must >= 3.1 !")
return
current_boost_root = current_compile_info['boost_root']
current_boost_lib = current_compile_info['boost_lib']
if current_boost_root == '' or current_boost_lib == '':
print("Please configure BOOST")
exit(0)
print('BOOST_ROOT:', current_boost_root)
print('BOOST_LIB:', current_boost_lib)
#如果 python版本或者编译模式发生变化则编译依赖的 boost 库boost.python)
history_compile_info = get_history_compile_info()
if py_version != history_compile_info[
'py_version'] or history_compile_info['mode'] != mode:
clear_with_python_changed(mode)
print('\ncompile boost ...')
build_boost(mode)
os.system("xmake f {} -c -y -m {}".format("-v -D" if verbose else "",
mode))
@ -277,7 +197,7 @@ def test(all, compile, verbose, mode, case, j):
'' if case == '' else '--test-case={}'.format(case)))
def clear_build(with_boost):
def clear_build():
""" 清除当前编译设置及结果 """
if os.path.lexists('.xmake'):
print('delete .xmake')
@ -291,26 +211,13 @@ def clear_build(with_boost):
if os.path.exists('compile_info'):
print('delete compile_info')
os.remove('compile_info')
for r, _, f_list in os.walk('hikyuu'):
for name in f_list:
if (name != 'UnRAR.exe' and len(name) > 4 and name[-4:] in ('.dll','.exe','.pyd')) \
or (len(name) > 3 and name[-3:] == '.so') \
or (len(name) > 8 and name[:9] == 'libboost_') \
or (len(name) > 6 and name[-6:] == '.dylib'):
print('delete', r + '/' + name)
os.remove(os.path.join(r, name))
if with_boost:
_, boost_lib_dir = get_boost_envrionment()
if os.path.lexists(boost_lib_dir):
shutil.rmtree(boost_lib_dir)
print('clear finished!')
os.system("xmake clean")
@click.command()
@click.option("-with_boost", "--with_boost", is_flag=True, help='BOOST库')
def clear(with_boost):
clear_build(with_boost)
def clear():
clear_build()
@click.command()
@ -356,7 +263,7 @@ def install():
def wheel(j):
""" 生成 python 的 wheel 安装包 """
# 清理之前遗留的打包产物
clear_build(with_boost=True)
clear_build()
# 尝试编译
start_build(False, 'release', j)

View File

@ -60,7 +60,15 @@ elseif is_plat("linux", "cross") then
elseif is_plat("macosx") then
add_requires("brew::hdf5")
end
add_requires("boost", {system=false, configs = {data_time=true, filesystem=true, serialization=true, system=true, python=true, pyver=39}})
add_requires("boost", {system=false,
configs = {
vs_runtime="MD",
data_time=true,
filesystem=true,
serialization=true,
system=true,
python=true,
pyver=39}})
-- add_requires("fmt 8.1.1", {system=false, configs = {header_only = true}})
add_requires("spdlog", {system=false, configs = {header_only = true, fmt_external=true, vs_runtime = "MD"}})
@ -83,6 +91,7 @@ set_targetdir("$(buildir)/$(mode)/$(plat)/$(arch)/lib")
-- modifed to use boost static library, except boost.python, serialization
--add_defines("BOOST_ALL_DYN_LINK")
-- add_defines("BOOST_SERIALIZATION_DYN_LINK")
add_defines("BOOST_PYTHON_STATIC_LIB")
-- is release now
if is_mode("release") then