diff options
| author | ruki <[email protected]> | 2021-03-23 22:44:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-03-23 22:44:31 +0800 |
| commit | ec9c9cd7c9544eb259c306d9930ab43bad63d1b2 (patch) | |
| tree | a981b4ab72038065bcccf372150e24abd347ce9c /xmake/modules/target/action | |
| parent | d93735db9696932fdff5a8f0db268eba9ac50a5b (diff) | |
generate cmake importfiles
Diffstat (limited to 'xmake/modules/target/action')
| -rw-r--r-- | xmake/modules/target/action/install/cmake_importfiles.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/xmake/modules/target/action/install/cmake_importfiles.lua b/xmake/modules/target/action/install/cmake_importfiles.lua index 56e995373..c325caece 100644 --- a/xmake/modules/target/action/install/cmake_importfiles.lua +++ b/xmake/modules/target/action/install/cmake_importfiles.lua @@ -18,6 +18,41 @@ -- @file cmake_importfiles.lua -- +-- get the builtin variables +function _get_builtinvars(target, installdir) + return {TARGETNAME = target:name(), + TARGETBASENAME = target:basename(), + TARGETFILE = path.absolute(target:targetfile()), + TARGETKIND = target:is_shared() and "SHARED" or "STATIC", + PACKAGE_VERSION = target:get("version") or "1.0.0", + IMPORT_PREFIX = path.absolute(installdir)} +end + +-- install cmake import file +function _install_cmake_importfile(target, installdir, filename, opt) + + -- get import file path + local importfile_src = path.join(os.programdir(), "scripts", "cmake_importfiles", filename) + local importfile_dst = path.join(installdir, opt and opt.libdir or "lib", "cmake", target:name(), (filename:gsub("xxx", target:name()))) + + -- trace + vprint("generating %s ..", importfile_dst) + + -- get the builtin variables + local builtinvars = _get_builtinvars(target, installdir) + + -- copy and replace builtin variables + local content = io.readfile(importfile_src) + if content then + content = content:gsub("(@(.-)@)", function(_, variable) + variable = variable:trim() + local value = builtinvars[variable] + return type(value) == "function" and value() or value + end) + io.writefile(importfile_dst, content) + end +end + -- install .cmake import files function main(target, opt) @@ -25,5 +60,20 @@ function main(target, opt) opt = opt or {} assert(target:is_library(), 'cmake_importfiles: only support for library target(%s)!', target:name()) + -- get install directory + local installdir = target:installdir() + if not installdir then + return + end + + -- do install + _install_cmake_importfile(target, installdir, "xxxConfig.cmake", opt) + _install_cmake_importfile(target, installdir, "xxxConfigVersion.cmake", opt) + _install_cmake_importfile(target, installdir, "xxxTargets.cmake", opt) + if is_mode("debug") then + _install_cmake_importfile(target, installdir, "xxxTargets-debug.cmake", opt) + else + _install_cmake_importfile(target, installdir, "xxxTargets-release.cmake", opt) + end end |
