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

improve find cmake package #3387

Merged
merged 2 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions xmake/modules/package/manager/cmake/configurations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
function main()
return
{
components = {description = "Set the cmake package components, e.g. {\"regex\", \"system\"}"},
moduledirs = {description = "Set the cmake modules directories."},
presets = {description = "Set the preset values, e.g. {Boost_USE_STATIC_LIB = true}"},
envs = {description = "Set the run environments of cmake, e.g. {CMAKE_PREFIX_PATH = \"xxx\"}"},
link_libraries = {description = "Set the cmake package dependencies, e.g. {\"abc::lib1\", \"abc::lib2\"}"},
search_mode = {description = "Set the cmake package search mode, e.g. {\"config\", \"module\"}"},
components = {description = "Set the cmake package components, e.g. {\"regex\", \"system\"}"},
moduledirs = {description = "Set the cmake modules directories."},
presets = {description = "Set the preset values, e.g. {Boost_USE_STATIC_LIB = true}"},
envs = {description = "Set the run environments of cmake, e.g. {CMAKE_PREFIX_PATH = \"xxx\"}"},
}
end

15 changes: 11 additions & 4 deletions xmake/modules/package/manager/cmake/find_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ function _find_package(cmake, name, opt)
requirestr = requirestr .. " " .. configs.search_mode:upper()
end
-- use opt.components is for backward compatibility
local componentstr = ""
local components = configs.components or opt.components
if components then
requirestr = requirestr .. " COMPONENTS"
if components and #components > 0 then
componentstr = "COMPONENTS"
for _, component in ipairs(components) do
requirestr = requirestr .. " " .. component
componentstr = componentstr .. " " .. component
end
end
local moduledirs = configs.moduledirs or opt.moduledirs
Expand All @@ -77,7 +78,7 @@ function _find_package(cmake, name, opt)
end
end
local testname = "test_" .. name
cmakefile:print("find_package(%s REQUIRED)", requirestr)
cmakefile:print("find_package(%s REQUIRED %s)", requirestr, componentstr)
cmakefile:print("if(%s_FOUND)", name)
cmakefile:print(" add_executable(%s test.cpp)", testname)
cmakefile:print(" target_include_directories(%s PRIVATE ${%s_INCLUDE_DIR} ${%s_INCLUDE_DIRS})",
Expand Down Expand Up @@ -238,6 +239,12 @@ function _find_package(cmake, name, opt)
end
end
end

values = line:match("<PreprocessorDefinitions>%%%(PreprocessorDefinitions%);(.+)</PreprocessorDefinitions>")
if values then
defines = defines or {}
table.join2(defines, path.splitenv(values))
end
end
end
end
Expand Down