summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-02 23:33:20 +0800
committerGitHub <[email protected]>2025-11-02 23:33:20 +0800
commit6b06ceace57ef4ea7c0996e382d98267ce2a8216 (patch)
treeee09f431ce8d54497fa07473b6708f9aeb372102
parent0fd0f4e108e32c36416498ba6cceafcb31d45542 (diff)
parent688e6d300bda9975bea024d4c25d07b751861485 (diff)
Merge pull request #6984 from MeanSquaredError/cmake_importfiles_libdir
Fix the libdir inside the installed CMake import files
-rw-r--r--xmake/modules/target/action/install/cmake_importfiles.lua20
-rw-r--r--xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake6
-rw-r--r--xmake/scripts/cmake_importfiles/xxxTargets-release.cmake6
3 files changed, 18 insertions, 14 deletions
diff --git a/xmake/modules/target/action/install/cmake_importfiles.lua b/xmake/modules/target/action/install/cmake_importfiles.lua
index b37729547..6b8769225 100644
--- a/xmake/modules/target/action/install/cmake_importfiles.lua
+++ b/xmake/modules/target/action/install/cmake_importfiles.lua
@@ -37,14 +37,15 @@ function _get_libfile(target, installdir)
end
-- get the builtin variables
-function _get_builtinvars(target, installdir)
+function _get_builtinvars(target, installdir, libdir)
local target_ptrbytes
if target:is_plat("cross") then
target_ptrbytes = target:check_sizeof("void*")
else
target_ptrbytes = target:is_arch64() and "8" or "4"
end
- return {TARGETNAME = target:name(),
+ return {LIBDIR = libdir,
+ TARGETNAME = target:name(),
PROJECTNAME = project.name() or target:name(),
TARGETFILENAME = target:targetfile() and _get_libfile(target, installdir),
TARGETKIND = target:is_headeronly() and "INTERFACE" or (target:is_shared() and "SHARED" or "STATIC"),
@@ -56,15 +57,16 @@ end
function _install_cmake_configfile(target, installdir, filename, opt)
-- get import file path
+ local libdir = opt and opt.libdir or "lib"
local projectname = project.name() or target:name()
local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename)
- local importfile_dst = path.join(installdir, opt and opt.libdir or "lib", "cmake", projectname, (filename:gsub("xxx", projectname)))
+ local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", projectname)))
-- trace
vprint("generating %s ..", importfile_dst)
-- get the builtin variables
- local builtinvars = _get_builtinvars(target, installdir)
+ local builtinvars = _get_builtinvars(target, installdir, libdir)
-- copy and replace builtin variables
local content = io.readfile(importfile_src)
@@ -83,12 +85,13 @@ end
function _append_cmake_configfile(target, installdir, filename, opt)
-- get import file path
+ local libdir = opt and opt.libdir or "lib"
local projectname = project.name() or target:name()
local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename)
- local importfile_dst = path.join(installdir, opt and opt.libdir or "lib", "cmake", projectname, (filename:gsub("xxx", projectname)))
+ local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", projectname)))
-- get the builtin variables
- local builtinvars = _get_builtinvars(target, installdir)
+ local builtinvars = _get_builtinvars(target, installdir, libdir)
-- generate the file if not exist / file is outdated
if target:is_headeronly() or not os.isfile(importfile_dst) or os.mtime(importfile_dst) < os.mtime(target:targetfile()) then
@@ -118,15 +121,16 @@ end
function _install_cmake_targetfile(target, installdir, filename, opt)
-- get import file path
+ local libdir = opt and opt.libdir or "lib"
local projectname = project.name() or target:name()
local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename)
- local importfile_dst = path.join(installdir, opt and opt.libdir or "lib", "cmake", projectname, (filename:gsub("xxx", target:name())))
+ local importfile_dst = path.join(installdir, libdir, "cmake", projectname, (filename:gsub("xxx", target:name())))
-- trace
vprint("generating %s ..", importfile_dst)
-- get the builtin variables
- local builtinvars = _get_builtinvars(target, installdir)
+ local builtinvars = _get_builtinvars(target, installdir, libdir)
-- copy and replace builtin variables
local content = io.readfile(importfile_src)
diff --git a/xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake b/xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake
index 7b752bd8f..d0f387f63 100644
--- a/xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake
+++ b/xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake
@@ -9,12 +9,12 @@ set(CMAKE_IMPORT_FILE_VERSION 1)
set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "ASM_NASM;C"
- # IMPORTED_IMPLIB_DEBUG "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
- IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
+ # IMPORTED_IMPLIB_DEBUG "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@"
+ IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@"
)
list(APPEND _IMPORT_CHECK_TARGETS @PROJECTNAME@::@TARGETNAME@ )
-list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" )
+list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
diff --git a/xmake/scripts/cmake_importfiles/xxxTargets-release.cmake b/xmake/scripts/cmake_importfiles/xxxTargets-release.cmake
index 074050a68..c42d48316 100644
--- a/xmake/scripts/cmake_importfiles/xxxTargets-release.cmake
+++ b/xmake/scripts/cmake_importfiles/xxxTargets-release.cmake
@@ -9,12 +9,12 @@ set(CMAKE_IMPORT_FILE_VERSION 1)
set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "ASM_NASM;C"
- # IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
- IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
+ # IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@"
+ IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@"
)
list(APPEND _IMPORT_CHECK_TARGETS @PROJECTNAME@::@TARGETNAME@ )
-list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" )
+list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/@LIBDIR@/@TARGETFILENAME@" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)