From e22cfe2d6205983623a227be5ca563157beced80 Mon Sep 17 00:00:00 2001 From: RichardYCJ Date: Fri, 10 Mar 2023 20:02:56 +0800 Subject: improve cmake::find_package add extra `find_name` to configurations. --- xmake/modules/package/manager/cmake/configurations.lua | 1 + xmake/modules/package/manager/cmake/find_package.lua | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/xmake/modules/package/manager/cmake/configurations.lua b/xmake/modules/package/manager/cmake/configurations.lua index ae69199ba..fdb34907b 100644 --- a/xmake/modules/package/manager/cmake/configurations.lua +++ b/xmake/modules/package/manager/cmake/configurations.lua @@ -28,6 +28,7 @@ function main() 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\"}"}, + find_name = {description = "Set the name used for ${find_name}_LIBS/_INCLUDE_DIRS in cmake"}, } end diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua index b42acabc2..686739e28 100644 --- a/xmake/modules/package/manager/cmake/find_package.lua +++ b/xmake/modules/package/manager/cmake/find_package.lua @@ -78,19 +78,20 @@ function _find_package(cmake, name, opt) end end local testname = "test_" .. name + local findname = configs.find_name or name 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})", - testname, name, name) + testname, findname, findname) cmakefile:print(" target_include_directories(%s PRIVATE ${%s_INCLUDE_DIR} ${%s_INCLUDE_DIRS})", - testname, name:upper(), name:upper()) + testname, findname:upper(), findname:upper()) cmakefile:print(" target_include_directories(%s PRIVATE ${%s_CXX_INCLUDE_DIRS})", - testname, name) + testname, findname) cmakefile:print(" target_link_libraries(%s ${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS})", - testname, name, name, name) + testname, findname, findname, findname) cmakefile:print(" target_link_libraries(%s ${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS})", - testname, name:upper(), name:upper(), name:upper()) + testname, findname:upper(), findname:upper(), findname:upper()) if configs.link_libraries then cmakefile:print(" target_link_libraries(%s %s)", testname, table.concat(table.wrap(configs.link_libraries), " ")) -- cgit v1.3.1