summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-02-18 22:06:45 +0800
committerGitHub <[email protected]>2023-02-18 22:06:45 +0800
commit882cb4e03cff1fb20cc561780477d649334b59e1 (patch)
tree075835d3461f31bef6b98c02041ee8a810f881cc
parent7c41b302ce315dde4ed031fa8ba5e406ea368b1a (diff)
parent85fc36e139b0bb3695cf5853a5e9aab58e52f61d (diff)
Merge pull request #3387 from star-hengxing/find_cmake_package
improve find cmake package
-rw-r--r--xmake/modules/package/manager/cmake/configurations.lua10
-rw-r--r--xmake/modules/package/manager/cmake/find_package.lua15
2 files changed, 17 insertions, 8 deletions
diff --git a/xmake/modules/package/manager/cmake/configurations.lua b/xmake/modules/package/manager/cmake/configurations.lua
index e65525f6d..ae69199ba 100644
--- a/xmake/modules/package/manager/cmake/configurations.lua
+++ b/xmake/modules/package/manager/cmake/configurations.lua
@@ -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
diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua
index 6066a66b0..b42acabc2 100644
--- a/xmake/modules/package/manager/cmake/find_package.lua
+++ b/xmake/modules/package/manager/cmake/find_package.lua
@@ -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
@@ -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})",
@@ -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