diff options
| author | ruki <[email protected]> | 2023-05-03 00:26:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-05-03 00:26:24 +0800 |
| commit | a39ce82c6a22f890e55187a95a7d105d2558ac04 (patch) | |
| tree | cf7bbea6a2b4d7e25ba30943661d5cb8d8ed32dd | |
| parent | 4f89cfadfd187382802dbc3ef2332eadc6f548af (diff) | |
improve conan options
4 files changed, 51 insertions, 24 deletions
diff --git a/tests/projects/package/conan/xmake.lua b/tests/projects/package/conan/xmake.lua index fcd36e3a8..ecf8c6b60 100644 --- a/tests/projects/package/conan/xmake.lua +++ b/tests/projects/package/conan/xmake.lua @@ -1,6 +1,6 @@ add_requires("conan::zlib 1.2.11", {alias = "zlib", debug = true}) add_requires("conan::openssl 1.1.1t", {alias = "openssl", - configs = {options = "openssl/*:shared=True"}}) + configs = {options = "shared=True"}}) target("test") set_kind("binary") diff --git a/xmake/modules/package/manager/conan/configurations.lua b/xmake/modules/package/manager/conan/configurations.lua index 8667ab112..8e03cf9a3 100644 --- a/xmake/modules/package/manager/conan/configurations.lua +++ b/xmake/modules/package/manager/conan/configurations.lua @@ -24,7 +24,7 @@ function main() { build = {description = "Use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}}, remote = {description = "Set the conan remote server."}, - options = {description = "Set the options values, e.g. shared=True"}, -- TODO + options = {description = "Set the options values, e.g. shared=True"}, settings = {description = "Set the build settings for conan."}, imports = {description = "Set the imports for conan 1.x, it has been deprecated in conan 2.x."}, build_requires = {description = "Set the build requires for conan."} diff --git a/xmake/modules/package/manager/conan/v1/install_package.lua b/xmake/modules/package/manager/conan/v1/install_package.lua index f8c60ad72..e443e585b 100644 --- a/xmake/modules/package/manager/conan/v1/install_package.lua +++ b/xmake/modules/package/manager/conan/v1/install_package.lua @@ -75,7 +75,12 @@ function _conan_generate_conanfile(name, configs, opt) end if #options > 0 then conanfile:print("[options]") - conanfile:print("%s", table.concat(options, "\n")) + for _, item in ipairs(options) do + if not item:find(":", 1, true) then + item = name .. ":" .. item + end + conanfile:print("%s", item) + end end if #imports > 0 then conanfile:print("[imports]") diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index 694fd5ff1..f5181022d 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -59,7 +59,8 @@ function _conan_generate_conanfile(name, configs, opt) local options = table.wrap(configs.options) local build_requires = table.wrap(configs.build_requires) - -- @see https://docs.conan.io/en/latest/systems_cross_building/cross_building.html + -- @see https://docs.conan.io/1/migrating_to_2.0/recipes.html + -- https://docs.conan.io/en/latest/systems_cross_building/cross_building.html -- generate it local conanfile = io.open("conanfile.txt", "w") if conanfile then @@ -72,10 +73,15 @@ function _conan_generate_conanfile(name, configs, opt) end if #options > 0 then conanfile:print("[options]") - conanfile:print("%s", table.concat(options, "\n")) + for _, item in ipairs(options) do + if not item:find(":", 1, true) then + item = name .. "/*:" .. item + end + conanfile:print("%s", item) + end end if #build_requires > 0 then - conanfile:print("[build_requires]") + conanfile:print("[tool_requires]") conanfile:print("%s", table.concat(build_requires, "\n")) end conanfile:close() @@ -104,6 +110,36 @@ function _conan_install_xmake_generator(conan) end end +-- generate host profile +function _conan_generate_host_profile(configs, opt) + + io.writefile("profile_host.txt", [[ + [settings] +arch=x86_64 +build_type=Release +compiler=gcc +compiler.cppstd=gnu17 +compiler.libcxx=libstdc++11 +compiler.version=11 +os=Linux]]) + +end + +-- generate build profile +function _conan_generate_build_profile(configs, opt) + + io.writefile("profile_build.txt", [[ + [settings] +arch=x86_64 +build_type=Release +compiler=gcc +compiler.cppstd=gnu17 +compiler.libcxx=libstdc++11 +compiler.version=11 +os=Linux]]) + +end + -- install package function main(conan, name, opt) @@ -129,25 +165,11 @@ function main(conan, name, opt) -- generate conanfile.txt _conan_generate_conanfile(name, configs, opt) - io.writefile("profile_build.txt", [[ - [settings] -arch=x86_64 -build_type=Release -compiler=gcc -compiler.cppstd=gnu17 -compiler.libcxx=libstdc++11 -compiler.version=11 -os=Linux]]) + -- generate host profile + _conan_generate_host_profile(configs, opt) - io.writefile("profile_host.txt", [[ - [settings] -arch=x86_64 -build_type=Release -compiler=gcc -compiler.cppstd=gnu17 -compiler.libcxx=libstdc++11 -compiler.version=11 -os=Linux]]) + -- generate build profile + _conan_generate_build_profile(configs, opt) -- install package local argv = {"install", ".", "-g", "XmakeGenerator", "--profile:build=profile_build.txt", "--profile:host=profile_host.txt"} |
