diff options
| author | RichardYCJ <[email protected]> | 2023-03-11 01:37:26 +0800 |
|---|---|---|
| committer | RichardYCJ <[email protected]> | 2023-03-11 01:37:26 +0800 |
| commit | 782550ef08e2f9dc107c46e5fda6040793d7d2ce (patch) | |
| tree | 243a27231edcaf4bea7ffecb05cff55b9ac8f5bd /xmake/modules/package/manager/cmake/find_package.lua | |
| parent | 1c254ee6ab33a0701c57b5e9dafa2b1641b3c929 (diff) | |
improve cmake::find_package use include_dirs instead of find_name
use `include_dirs` and `link_libraries` to customize cmake detection.
Diffstat (limited to 'xmake/modules/package/manager/cmake/find_package.lua')
| -rw-r--r-- | xmake/modules/package/manager/cmake/find_package.lua | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua index a16c8ceeb..c73a2ef4c 100644 --- a/xmake/modules/package/manager/cmake/find_package.lua +++ b/xmake/modules/package/manager/cmake/find_package.lua @@ -78,24 +78,30 @@ 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, findname, findname) - cmakefile:print(" target_include_directories(%s PRIVATE ${%s_INCLUDE_DIR} ${%s_INCLUDE_DIRS})", - testname, findname:upper(), findname:upper()) + -- setup include directories + local includedirs = "" + if configs.include_dirs then + includedirs = table.concat(table.wrap(configs.include_dirs), " ") + else + includedirs = string.gsub("${X_INCLUDE_DIR} ${X_INCLUDE_DIRS}", "X", name) + includedirs = includedirs .. string.gsub(" ${X_INCLUDE_DIR} ${X_INCLUDE_DIRS}", "X", name:upper()) + end + cmakefile:print(" target_include_directories(%s PRIVATE %s)", testname, includedirs) + -- reserved for backword compatibility cmakefile:print(" target_include_directories(%s PRIVATE ${%s_CXX_INCLUDE_DIRS})", - testname, findname) - cmakefile:print(" target_link_libraries(%s ${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS})", - testname, findname, findname, findname) - cmakefile:print(" target_link_libraries(%s ${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS})", - testname, findname:upper(), findname:upper(), findname:upper()) + testname, name) + -- setup link library/target + local linklibs = "" if configs.link_libraries then - cmakefile:print(" target_link_libraries(%s %s)", - testname, table.concat(table.wrap(configs.link_libraries), " ")) + linklibs = table.concat(table.wrap(configs.link_libraries), " ") + else + linklibs = string.gsub("${X_LIBRARY} ${X_LIBRARIES} ${X_LIBS}", "X", name) + linklibs = linklibs .. string.gsub(" ${X_LIBRARY} ${X_LIBRARIES} ${X_LIBS}", "X", name:upper()) end + cmakefile:print(" target_link_libraries(%s PRIVATE %s)", testname, linklibs) cmakefile:print("endif(%s_FOUND)", name) cmakefile:close() |
