summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-05-30 08:38:08 +0800
committerGitHub <[email protected]>2023-05-30 08:38:08 +0800
commit853d25d9192c4e2c936b2dbd267342ad5a6766ae (patch)
tree135310022b521544a25c6ca5dc73ad0d08f9884d
parenteeb6658c829a0e2d72d47790b98a6669a74c444e (diff)
parenta4afa8cd97a5d20e208f277f75f9fd9e2df5733c (diff)
Merge pull request #3790 from xmake-io/conan2
improve to install package for conan 2.x
-rw-r--r--xmake/modules/package/manager/conan/find_package.lua80
-rw-r--r--xmake/scripts/conan/extensions/generators/xmake_generator.py65
2 files changed, 112 insertions, 33 deletions
diff --git a/xmake/modules/package/manager/conan/find_package.lua b/xmake/modules/package/manager/conan/find_package.lua
index 2ac494043..6abee754b 100644
--- a/xmake/modules/package/manager/conan/find_package.lua
+++ b/xmake/modules/package/manager/conan/find_package.lua
@@ -23,8 +23,12 @@ import("core.base.option")
import("core.project.config")
-- get build info file
-function _conan_get_buildinfo_file(name)
- return path.absolute(path.join(config.buildir() or os.tmpdir(), ".conan", name, "conanbuildinfo.xmake.lua"))
+function _conan_get_buildinfo_file(name, dep_name)
+ local filename = "conanbuildinfo.xmake.lua"
+ if dep_name then
+ filename = "conanbuildinfo_" .. dep_name .. ".xmake.lua"
+ end
+ return path.absolute(path.join(config.buildir() or os.tmpdir(), ".conan", name, filename))
end
-- get conan platform
@@ -56,35 +60,39 @@ function _conan_get_mode(opt)
return opt.mode == "debug" and "Debug" or "Release"
end
--- find package using the conan package manager
---
--- @param name the package name
--- @param opt the options, e.g. {verbose = true)
---
-function main(name, opt)
+-- get info key
+function _conan_get_infokey(opt)
+ local plat = _conan_get_plat(opt)
+ local arch = _conan_get_arch(opt)
+ local mode = _conan_get_mode(opt)
+ if plat and arch and mode then
+ return plat .. "_" .. arch .. "_" .. mode
+ end
+end
- -- get the build info
+-- get build info
+function _conan_get_buildinfo(name, opt)
opt = opt or {}
- local buildinfo_file = _conan_get_buildinfo_file(name)
+ local buildinfo_file = _conan_get_buildinfo_file(name, opt.dep_name)
if not os.isfile(buildinfo_file) then
return
end
-- load build info
- local buildinfo = io.load(buildinfo_file)
-
- -- get platform, architecture and mode
- local plat = _conan_get_plat(opt)
- local arch = _conan_get_arch(opt)
- local mode = _conan_get_mode(opt)
- if not plat or not arch or not mode then
+ local infokey = _conan_get_infokey(opt)
+ if not infokey then
return
end
+ local buildinfo = io.load(buildinfo_file)
+ if buildinfo then
+ buildinfo = buildinfo[infokey]
+ end
-- get the package info of the given platform, architecture and mode
local found = false
local result = {}
- for k, v in pairs(buildinfo[plat .. "_" .. arch .. "_" .. mode]) do
+ local dep_names
+ for k, v in pairs(buildinfo) do
if not k:startswith("__") then
if #table.wrap(v) > 0 then
result[k] = v
@@ -94,6 +102,15 @@ function main(name, opt)
end
if found then
+ return buildinfo, result
+ end
+end
+
+-- find conan library
+function _conan_find_library(name, opt)
+ opt = opt or {}
+ local buildinfo, result = _conan_get_buildinfo(name, opt)
+ if result then
local libfiles = {}
for _, linkdir in ipairs(result.linkdirs) do
if not os.isdir(linkdir) then
@@ -127,6 +144,31 @@ function main(name, opt)
result.version = opt.require_version
end
result.libfiles = table.unique(libfiles)
- return result
+ return result, buildinfo.__dep_names
+ end
+end
+
+-- find package using the conan package manager
+--
+-- @param name the package name
+-- @param opt the options, e.g. {verbose = true)
+--
+function main(name, opt)
+ local result, dep_names = _conan_find_library(name, opt)
+ if result and dep_names then
+ for _, dep_name in ipairs(dep_names) do
+ local depinfo = _conan_find_library(name, table.join(opt, {dep_name = dep_name}))
+ for k, v in pairs(depinfo) do
+ result[k] = table.join(result[k] or {}, v)
+ end
+ end
+ for k, v in pairs(result) do
+ if k == "links" or k == "syslinks" or k == "frameworks" then
+ result[k] = table.unwrap(table.reverse_unique(v))
+ else
+ result[k] = table.unwrap(table.unique(v))
+ end
+ end
end
+ return result
end
diff --git a/xmake/scripts/conan/extensions/generators/xmake_generator.py b/xmake/scripts/conan/extensions/generators/xmake_generator.py
index 2c796df26..2bb0e4415 100644
--- a/xmake/scripts/conan/extensions/generators/xmake_generator.py
+++ b/xmake/scripts/conan/extensions/generators/xmake_generator.py
@@ -12,8 +12,11 @@ class XmakeGenerator:
def __init__(self, conanfile):
self._conanfile = conanfile
- def filename(self):
- return "conanbuildinfo.xmake.lua"
+ def filename(self, pkgname = None):
+ if pkgname:
+ return "conanbuildinfo_%s.xmake.lua" %pkgname
+ else:
+ return "conanbuildinfo.xmake.lua"
def generate(self):
print("XmakeGenerator: generating build info ..")
@@ -27,19 +30,26 @@ class XmakeGenerator:
+ list(test_req.items()) \
+ list(build_req.items())
+ dep_names = []
+ pkginfo = None
+ plat = self._conanfile.settings.os
+ arch = self._conanfile.settings.arch
+ mode = self._conanfile.settings.build_type
for require, dep in full_req:
- #dep_name = require.ref.name
-
# get aggregate dependency's cppinfo
dep_aggregate = dep.cpp_info.aggregated_components()
# format deps
deps = XmakeDepsFormatter(dep_aggregate)
- # make template
- plat = self._conanfile.settings.os
- arch = self._conanfile.settings.arch
- mode = self._conanfile.settings.build_type
+ # get package and deps
+ dep_name = require.ref.name
+ if not pkginfo:
+ pkginfo = deps
+ else:
+ dep_names.append(dep_name)
+
+ # make content
template = (' {plat}_{arch}_{mode} = \n'
' {{\n'
' includedirs = {{{deps.include_paths}}},\n'
@@ -58,18 +68,45 @@ class XmakeGenerator:
' __srcdirs = {{{deps.src_paths}}}\n'
' }}')
- # make sections
sections = []
sections.append(template.format(plat = plat, arch = arch, mode = mode, deps = deps))
-
- # make content
content = "{\n" + ",\n".join(sections) + "\n}"
- print(content)
+ print(dep_name, content)
- # save content to file
- with open(self.filename(), 'w') as file:
+ # save package content to file
+ with open(self.filename(dep_name), 'w') as file:
file.write(content)
+ # save root content to file
+ template = (' {plat}_{arch}_{mode} = \n'
+ ' {{\n'
+ ' includedirs = {{{pkginfo.include_paths}}},\n'
+ ' linkdirs = {{{pkginfo.lib_paths}}},\n'
+ ' links = {{{pkginfo.libs}}},\n'
+ ' frameworkdirs = {{{pkginfo.framework_paths}}},\n'
+ ' frameworks = {{{pkginfo.frameworks}}},\n'
+ ' syslinks = {{{pkginfo.system_libs}}},\n'
+ ' defines = {{{pkginfo.defines}}},\n'
+ ' cxxflags = {{{pkginfo.cppflags}}},\n'
+ ' cflags = {{{pkginfo.cflags}}},\n'
+ ' shflags = {{{pkginfo.sharedlinkflags}}},\n'
+ ' ldflags = {{{pkginfo.exelinkflags}}},\n'
+ ' __bindirs = {{{pkginfo.bin_paths}}},\n'
+ ' __resdirs = {{{pkginfo.res_paths}}},\n'
+ ' __srcdirs = {{{pkginfo.src_paths}}},\n'
+ ' __dep_names = {{{dep_names}}}\n'
+ ' }}')
+
+ sections = []
+ dep_names_str = ", ".join('"%s"' % p for p in dep_names)
+ sections.append(template.format(plat = plat, arch = arch, mode = mode, pkginfo = pkginfo, dep_names = dep_names_str))
+ content = "{\n" + ",\n".join(sections) + "\n}"
+ print(content)
+
+ # save package content to file
+ with open(self.filename(), 'w') as file:
+ file.write(content)
+
class XmakeDepsFormatter(object):
def __prepare_process_escape_character(self, raw_string):
if raw_string.find('\"') != -1: