diff options
| author | star-hengxing <[email protected]> | 2023-02-18 17:23:28 +0800 |
|---|---|---|
| committer | star-hengxing <[email protected]> | 2023-02-18 17:23:28 +0800 |
| commit | 960abbeb4e89a7f72927b5d7a72a93c51de06dd0 (patch) | |
| tree | 126a0072afaf2795c96dcfed2d80eb5c75e65d5c | |
| parent | ab4a4b4872a6bdc70e4fa27a286d93123ec98a68 (diff) | |
improve find cmake package
| -rw-r--r-- | xmake/modules/package/manager/cmake/find_package.lua | 15 |
1 files changed, 11 insertions, 4 deletions
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 |
