hikyuu2/hikyuu_pywrap/xmake_on_load.lua

49 lines
1.9 KiB
Lua
Raw Normal View History

import("lib.detect.find_tool")
2018-09-15 02:52:35 +08:00
function main(target)
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 must > 3.0, please use python3.0 or later!")
-- find python include and libs directory
2018-09-15 02:52:35 +08:00
local pydir = os.iorun("python -c \"import sys; print(sys.executable)\"")
pydir = path.directory(pydir)
target:add("includedirs", pydir .. "/include")
target:add("linkdirs", pydir .. "/libs")
2018-09-19 02:45:50 +08:00
return
end
2018-09-21 01:08:43 +08:00
target:add("rpathdirs", "$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib")
2018-09-19 02:45:50 +08:00
if is_plat("macosx") then
2018-09-20 23:12:30 +08:00
local libdir = os.iorun("python3-config --prefix"):trim() .. "/lib"
2018-09-20 02:43:03 +08:00
target:add("linkdirs", libdir)
2018-09-22 15:37:17 +08:00
local out, err = os.iorun("python3 --version")
local ver = (out .. err):trim()
2018-09-20 23:12:30 +08:00
local python_lib = format("python%s.%sm", string.sub(ver,8,8), string.sub(ver,10,10))
target:add("links", python_lib)
2018-09-19 02:45:50 +08:00
end
2018-09-20 02:43:03 +08:00
2018-09-19 02:45:50 +08:00
-- get python include directory.
local pydir = try { function () return os.iorun("python3-config --includes"):trim() end }
assert(pydir, "python3-config not found!")
2018-09-19 02:45:50 +08:00
target:add("cxflags", pydir)
2018-09-15 02:52:35 +08:00
2018-09-19 02:45:50 +08:00
-- get suffix configure for link libboost_pythonX.so
2018-09-20 02:43:03 +08:00
local suffix = get_config("boost-python-suffix")
2018-09-19 02:45:50 +08:00
if suffix == nil then
2018-09-20 02:43:03 +08:00
raise("You need to config --boost-python-suffix specify libboost_python suffix")
2018-09-19 02:45:50 +08:00
end
2018-09-15 02:52:35 +08:00
2018-09-19 02:45:50 +08:00
suffix = string.upper(suffix)
if suffix == "3X" then
2018-09-22 15:37:17 +08:00
local out, err = os.iorun("python3 --version")
local ver = (out .. err):trim()
2018-09-20 23:12:30 +08:00
local boost_python_lib = "boost_python"..string.sub(ver,8,8)..string.sub(ver,10,10)
2018-09-19 02:45:50 +08:00
target:add("links", boost_python_lib)
else
target:add("links", "boost_python"..suffix)
2018-09-15 02:52:35 +08:00
end
end