Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible package fetching from cmake #2576

Closed
xq114 opened this issue Jul 17, 2022 · 7 comments
Closed

More flexible package fetching from cmake #2576

xq114 opened this issue Jul 17, 2022 · 7 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Jul 17, 2022

你在什么场景下需要该功能?

https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#guide:Using%20Dependencies%20Guide

希望xmake支持:

  • Module/Config模式设置 find_package(ABC CONFIG REQUIRED) (仅从ABCConfig.cmake查找)
  • Components设置 find_package(Boost 1.79 COMPONENTS date_time)
  • 特定target设置 target_link_libraries(test PRIVATE ABC::lib1 ABC::lib3)

这里第3点很重要,因为package提供的cflags、cxxflags、defines、syslinks都是通过这种方式链接才有,只链接ABC_LIBRARIES不仅无法控制链接的库和顺序(可能导致冲突),还会丢失信息(可能导致编译不过)。

描述可能的解决方案

改进cmake/find_package模块

描述你认为的候选方案

No response

其他信息

No response

@waruqi waruqi added this to the v2.7.1 milestone Jul 17, 2022
@waruqi
Copy link
Member

waruqi commented Jul 25, 2022

Components设置 find_package(Boost 1.79 COMPONENTS date_time)

这个不是原本就支持么

-- e.g. OpenCV 4.1.1, Boost COMPONENTS regex system
local requirestr = name
local configs = opt.configs or {}
if opt.require_version and opt.require_version ~= "latest" then
requirestr = requirestr .. " " .. opt.require_version
end
-- use opt.components is for backward compatibility
local components = configs.components or opt.components
if components then
requirestr = requirestr .. " COMPONENTS"
for _, component in ipairs(components) do
requirestr = requirestr .. " " .. component
end
end

@waruqi
Copy link
Member

waruqi commented Jul 26, 2022

特定target设置 target_link_libraries(test PRIVATE ABC::lib1 ABC::lib3)

这个怎么搞?要么传自定义 targetlinks 进去,add_requires("cmake::xxx", {configs = {targetlinks = {"abc::lib1", "abc::lib2"}}})

@waruqi
Copy link
Member

waruqi commented Jul 26, 2022

Module/Config模式设置 find_package(ABC CONFIG REQUIRED) (仅从ABCConfig.cmake查找)

还有这,add_requires("cmake::xxx", {configs = {find_config = true}}) 这样?

要么你直接来个 pr 吧。https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

@xq114
Copy link
Contributor Author

xq114 commented Jul 26, 2022

特定target设置 target_link_libraries(test PRIVATE ABC::lib1 ABC::lib3)

这个怎么搞?要么传自定义 targetlinks 进去,add_requires("cmake::xxx", {configs = {targetlinks = {"abc::lib1", "abc::lib2"}}})

targetlinks这个名字不是很贴切,改成link_libraries比较好,因为cmake里面的target_link_libraries(test PRIVATE ABC::lib1 ABC::lib3)是把 test 这个 target ”link“ 到 libraries ABC::lib1 和 ABC::lib3。{find_config = true}也不如{search_mode = "config"}好,后者可以设置"both" "config" "module"。见 https://cmake.org/cmake/help/latest/command/find_package.html#id4

@waruqi
Copy link
Member

waruqi commented Jul 26, 2022

好了

add_requires("cmake::xxx", {configs = {link_libraries = {"abc::lib1", "abc::lib2"}}})
add_requires("cmake::xxx", {configs = {search_mode = "config"}}) -- module, both

@xq114
Copy link
Contributor Author

xq114 commented Jul 26, 2022

不好意思我没讲清楚,both就是啥也不加,默认就两个都找,不需要额外声明,需要声明的只有config和module

@waruqi
Copy link
Member

waruqi commented Jul 26, 2022

好了

add_requires("cmake::xxx", {configs = {link_libraries = {"abc::lib1", "abc::lib2"}}})
add_requires("cmake::xxx", {configs = {search_mode = "config"}}) -- module, both

那就不设置就行了

add_requires("cmake::xxx", {configs = {search_mode = "config"}})
add_requires("cmake::xxx", {configs = {search_mode = "module"}})
add_requires("cmake::xxx") -- both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants