diff options
| author | MeanSquaredError <[email protected]> | 2025-11-22 13:18:34 +0200 |
|---|---|---|
| committer | MeanSquaredError <[email protected]> | 2025-11-23 18:36:20 +0200 |
| commit | 21ee4d4d8b2c745fe8a3c436f9b839fdd5dd7887 (patch) | |
| tree | 8cc0240dbc127b228ac2fbf2c92070c5b6ea57f8 | |
| parent | 8b165b81f1ab59188bfbbb14ca94a4ebbf42f998 (diff) | |
cmake find_package: Simplify the generated CMakeLists.txt used to checking if a package is installed locally.
| -rw-r--r-- | xmake/modules/package/manager/cmake/find_package.lua | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua index 2683d5e1a..7192843a9 100644 --- a/xmake/modules/package/manager/cmake/find_package.lua +++ b/xmake/modules/package/manager/cmake/find_package.lua @@ -104,8 +104,7 @@ function _find_package(cmake, name, opt) end local testname = "test_" .. 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("add_executable(%s test.cpp)", testname) -- setup include directories local includedirs = "" if configs.include_directories then @@ -114,9 +113,9 @@ function _find_package(cmake, name, opt) includedirs = ("${%s_INCLUDE_DIR} ${%s_INCLUDE_DIRS}"):format(name, name) includedirs = includedirs .. (" ${%s_INCLUDE_DIR} ${%s_INCLUDE_DIRS}"):format(name:upper(), name:upper()) end - cmakefile:print(" target_include_directories(%s PRIVATE %s)", testname, includedirs) + 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})", + cmakefile:print("target_include_directories(%s PRIVATE ${%s_CXX_INCLUDE_DIRS})", testname, name) -- setup link library/target local linklibs = "" @@ -126,8 +125,7 @@ function _find_package(cmake, name, opt) linklibs = ("${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS}"):format(name, name, name) linklibs = linklibs .. (" ${%s_LIBRARY} ${%s_LIBRARIES} ${%s_LIBS}"):format(name:upper(), name:upper(), name:upper()) end - cmakefile:print(" target_link_libraries(%s PRIVATE %s)", testname, linklibs) - cmakefile:print("endif(%s_FOUND)", name) + cmakefile:print("target_link_libraries(%s PRIVATE %s)", testname, linklibs) cmakefile:close() if option.get("diagnosis") then local cmakedata = io.readfile(filepath) |
