diff options
| author | ruki <[email protected]> | 2026-01-12 23:37:57 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-12 23:37:57 +0800 |
| commit | 0569f75900e97a721cc7acbff3e9738095743d8c (patch) | |
| tree | fdeea00210ca68a7cb943d28675d2386a1b4f740 | |
| parent | 0bb0eca7e93dbdc1390fee4a7bcf30c7cf834a66 (diff) | |
| parent | 6c20d1006e21b8fe6ac33f65f8600152b81830b1 (diff) | |
Merge pull request #7213 from xmake-io/importfiles
fix installdir of imporfiles
| -rw-r--r-- | xmake/modules/target/action/install/cmake_importfiles.lua | 39 | ||||
| -rw-r--r-- | xmake/modules/target/action/install/pkgconfig_importfiles.lua | 6 |
2 files changed, 31 insertions, 14 deletions
diff --git a/xmake/modules/target/action/install/cmake_importfiles.lua b/xmake/modules/target/action/install/cmake_importfiles.lua index 6b8769225..c9c454554 100644 --- a/xmake/modules/target/action/install/cmake_importfiles.lua +++ b/xmake/modules/target/action/install/cmake_importfiles.lua @@ -21,13 +21,19 @@ -- imports import("core.project.project") +-- get install libdir +function _get_install_libdir(target, installdir, opt) + opt = opt or {} + return path.normalize(opt.libdir and path.join(installdir, opt.libdir) or target:libdir()) +end + -- get the lib file of the target -function _get_libfile(target, installdir) +function _get_libfilename(target, libdir) local libfile = path.filename(target:targetfile()) if target:is_plat("windows") then libfile = libfile:gsub("%.dll$", ".lib") elseif target:is_plat("mingw") then - if os.isfile(path.join(installdir, "lib", libfile:gsub("%.dll$", ".dll.a"))) then + if os.isfile(path.join(libdir, libfile:gsub("%.dll$", ".dll.a"))) then libfile = libfile:gsub("%.dll$", ".dll.a") else libfile = libfile:gsub("%.dll$", ".lib") @@ -44,10 +50,16 @@ function _get_builtinvars(target, installdir, libdir) else target_ptrbytes = target:is_arch64() and "8" or "4" end - return {LIBDIR = libdir, + local libsubdir + if libdir:startswith(installdir) then + libsubdir = path.relative(libdir, installdir) + else + raise("target(%s): libdir(%s) is not in installdir(%s)", target:name(), libdir, installdir) + end + return {LIBDIR = libsubdir, TARGETNAME = target:name(), PROJECTNAME = project.name() or target:name(), - TARGETFILENAME = target:targetfile() and _get_libfile(target, installdir), + TARGETFILENAME = target:targetfile() and _get_libfilename(target, libdir), TARGETKIND = target:is_headeronly() and "INTERFACE" or (target:is_shared() and "SHARED" or "STATIC"), PACKAGE_VERSION = target:get("version") or "1.0.0", TARGET_PTRBYTES = target_ptrbytes} @@ -57,10 +69,10 @@ end function _install_cmake_configfile(target, installdir, filename, opt) -- get import file path - local libdir = opt and opt.libdir or "lib" + local libdir = _get_install_libdir(target, installdir, opt) local projectname = project.name() or target:name() local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename) - local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", projectname))) + local importfile_dst = path.join(libdir, "cmake", projectname, (filename:gsub("xxx", projectname))) -- trace vprint("generating %s ..", importfile_dst) @@ -85,10 +97,10 @@ end function _append_cmake_configfile(target, installdir, filename, opt) -- get import file path - local libdir = opt and opt.libdir or "lib" + local libdir = _get_install_libdir(target, installdir, opt) local projectname = project.name() or target:name() local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename) - local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", projectname))) + local importfile_dst = path.join(libdir, "cmake", projectname, (filename:gsub("xxx", projectname))) -- get the builtin variables local builtinvars = _get_builtinvars(target, installdir, libdir) @@ -121,10 +133,10 @@ end function _install_cmake_targetfile(target, installdir, filename, opt) -- get import file path - local libdir = opt and opt.libdir or "lib" + local libdir = _get_install_libdir(target, installdir, opt) local projectname = project.name() or target:name() local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename) - local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", target:name()))) + local importfile_dst = path.join(libdir, "cmake", projectname, (filename:gsub("xxx", target:name()))) -- trace vprint("generating %s ..", importfile_dst) @@ -140,14 +152,14 @@ function _install_cmake_targetfile(target, installdir, filename, opt) local value = builtinvars[variable] return type(value) == "function" and value() or value end) - local libfile = path.filename(target:targetfile()) + local libfilename = path.filename(target:targetfile()) local postfix = is_mode("debug") and "DEBUG" or "RELEASE" - if target:is_shared() and (_get_libfile(target, installdir) ~= libfile) then + if target:is_shared() and (_get_libfilename(target, libdir) ~= libfilename) then -- On DLL platforms, the import library is named differently from the target file content = content:gsub("# IMPORTED_IMPLIB_" .. postfix, "IMPORTED_IMPLIB_" .. postfix) content = content:gsub( "IMPORTED_LOCATION_" .. postfix .. " \"%${_IMPORT_PREFIX}/lib/.-\"", - "IMPORTED_LOCATION_" .. postfix .. " \"${_IMPORT_PREFIX}/bin/" .. libfile .. "\"" + "IMPORTED_LOCATION_" .. postfix .. " \"${_IMPORT_PREFIX}/bin/" .. libfilename .. "\"" ) end io.writefile(importfile_dst, content) @@ -168,6 +180,7 @@ function main(target, opt) end -- do install + installdir = path.normalize(installdir) _append_cmake_configfile(target, installdir, "xxxConfig.cmake", opt) _install_cmake_configfile(target, installdir, "xxxConfigVersion.cmake", opt) _install_cmake_targetfile(target, installdir, "xxxTargets.cmake", opt) diff --git a/xmake/modules/target/action/install/pkgconfig_importfiles.lua b/xmake/modules/target/action/install/pkgconfig_importfiles.lua index b96833071..9a9b8ee81 100644 --- a/xmake/modules/target/action/install/pkgconfig_importfiles.lua +++ b/xmake/modules/target/action/install/pkgconfig_importfiles.lua @@ -30,7 +30,11 @@ function main(target, opt) end -- get pkgconfig/.pc file - local pcfile = path.join(installdir, opt and opt.libdir or "lib", "pkgconfig", opt.filename or (target:basename() .. ".pc")) + local libdir = path.unix(path.normalize(opt.libdir and path.join(installdir, opt.libdir) or target:libdir())) + local pcfile = path.join(libdir, "pkgconfig", opt.filename or (target:basename() .. ".pc")) + if not libdir:startswith(installdir) then + raise("target(%s): libdir(%s) is not in installdir(%s)", target:name(), libdir, installdir) + end -- get includedirs local includedirs = opt.includedirs |
