From a4435e72d266c889c7e6f35c7fd2945ce635fe28 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 11 May 2018 22:15:47 +0800 Subject: fix qt rule xmake.lua --- xmake/rules/qt/env/load.lua | 125 ------------------ xmake/rules/qt/env/xmake.lua | 297 ------------------------------------------- xmake/rules/qt/load.lua | 125 ++++++++++++++++++ xmake/rules/wdk/env/load.lua | 151 ---------------------- xmake/rules/wdk/load.lua | 151 ++++++++++++++++++++++ 5 files changed, 276 insertions(+), 573 deletions(-) delete mode 100644 xmake/rules/qt/env/load.lua create mode 100644 xmake/rules/qt/load.lua delete mode 100644 xmake/rules/wdk/env/load.lua create mode 100644 xmake/rules/wdk/load.lua diff --git a/xmake/rules/qt/env/load.lua b/xmake/rules/qt/env/load.lua deleted file mode 100644 index f1373b711..000000000 --- a/xmake/rules/qt/env/load.lua +++ /dev/null @@ -1,125 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2018, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- make link for framework -function _link(framework, major) - if major and framework:startswith("Qt") then - framework = "Qt" .. major .. framework:sub(3) .. (is_mode("debug") and "d" or "") - end - return framework -end - --- the main entry -function main(target, opt) - - -- init options - opt = opt or {} - - -- get qt sdk - local qt = target:data("qt") - - -- get major version - local major = nil - if qt.sdkver then - major = qt.sdkver:split('%.')[1] - end - - -- set kind - if opt.kind then - target:set("kind", opt.kind) - end - - -- add -fPIC - target:add("cxflags", "-fPIC") - target:add("mxflags", "-fPIC") - target:add("asflags", "-fPIC") - - -- need c++11 - target:set("languages", "cxx11") - - -- add defines for the compile mode - if is_mode("debug") then - target:add("defines", "QT_QML_DEBUG") - elseif is_mode("release") then - target:add("defines", "QT_NO_DEBUG") - elseif is_mode("profile") then - target:add("defines", "QT_QML_DEBUG", "QT_NO_DEBUG") - end - - -- The following define makes your compiler emit warnings if you use - -- any feature of Qt which as been marked deprecated (the exact warnings - -- depend on your compiler). Please consult the documentation of the - -- deprecated API in order to know how to port your code away from it. - target:add("defines", "QT_DEPRECATED_WARNINGS") - - -- add frameworks - if opt.frameworks then - target:add("frameworks", opt.frameworks) - end - - -- do frameworks for qt - for _, framework in ipairs(target:get("frameworks")) do - - -- translate qt frameworks - if framework:startswith("Qt") then - - -- add defines - target:add("defines", "QT_" .. framework:sub(3):upper() .. "_LIB") - - -- add includedirs - if is_plat("macosx") then - target:add("includedirs", path.join(qt.sdkdir, "lib/" .. framework .. ".framework/Headers")) - else - target:add("links", _link(framework, major)) - target:add("includedirs", path.join(qt.sdkdir, "include/" .. framework)) - end - end - end - - -- add includedirs, linkdirs - if is_plat("macosx") then - target:add("frameworks", "DiskArbitration", "IOKit") - target:add("frameworkdirs", qt.linkdirs) - target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang")) - target:add("linkdirs", qt.linkdirs) - target:add("rpathdirs", "@executable_path/Frameworks", qt.linkdirs) - elseif is_plat("linux") then - target:set("frameworks", nil) - target:add("includedirs", path.join(qt.sdkdir, "include")) - target:add("includedirs", path.join(qt.sdkdir, "mkspecs/linux-g++")) - target:add("rpathdirs", qt.linkdirs) - target:add("linkdirs", qt.linkdirs) - elseif is_plat("windows") then - target:set("frameworks", nil) - target:add("includedirs", path.join(qt.sdkdir, "include")) - target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-msvc")) - target:add("linkdirs", qt.linkdirs) - elseif is_plat("mingw") then - target:set("frameworks", nil) - target:add("includedirs", path.join(qt.sdkdir, "include")) - target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-g++")) - target:add("linkdirs", qt.linkdirs) - end -end - diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua index 5f5b43520..782aece2a 100644 --- a/xmake/rules/qt/env/xmake.lua +++ b/xmake/rules/qt/env/xmake.lua @@ -49,300 +49,3 @@ rule("qt.env") target:data_set("qt.cleanfiles", nil) end) --- define rule: *.ui -rule("qt.ui") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".ui") - - -- on load - on_load(function (target) - - -- get uic - local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") - assert(uic and os.isexec(uic), "uic not found!") - - -- save uic - target:data_set("qt.uic", uic) - end) - - -- before build file - before_build_file(function (target, sourcefile_ui, opt) - - -- imports - import("core.base.option") - import("core.project.config") - import("core.project.depend") - - -- get uic - local uic = target:data("qt.uic") - - -- get c++ header file for ui - local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h") - local headerfile_dir = path.directory(headerfile_ui) - - -- add includedirs - target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) - - -- add clean files - target:data_add("qt.cleanfiles", headerfile_ui) - - -- need build this object? - local dependfile = target:dependfile(headerfile_ui) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(headerfile_ui)}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.ui %s", opt.progress, sourcefile_ui) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.ui %s", opt.progress, sourcefile_ui) - end - - -- ensure ui header file directory - if not os.isdir(headerfile_dir) then - os.mkdir(headerfile_dir) - end - - -- compile ui - os.vrunv(uic, {sourcefile_ui, "-o", headerfile_ui}) - - -- update files and values to the dependent file - dependinfo.files = {sourcefile_ui} - depend.save(dependinfo, dependfile) - end) - --- define rule: moc -rule("qt.moc") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".h") - - -- on load - on_load(function (target) - - -- get moc - local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") - assert(moc and os.isexec(moc), "moc not found!") - - -- save moc - target:data_set("qt.moc", moc) - end) - - -- on build file - on_build_file(function (target, headerfile_moc, opt) - - -- imports - import("moc") - import("core.base.option") - import("core.project.config") - import("core.tool.compiler") - import("core.project.depend") - - -- get c++ source file for moc - local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp") - - -- get object file - local objectfile = target:objectfile(sourcefile_moc) - - -- load compiler - local compinst = compiler.load("cxx", {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) - - -- add objectfile - table.insert(target:objectfiles(), objectfile) - - -- add clean files - target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) - - -- load dependent info - local dependfile = target:dependfile(objectfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.moc %s", opt.progress, headerfile_moc) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.moc %s", opt.progress, headerfile_moc) - end - - -- generate c++ source file for moc - moc.generate(target, headerfile_moc, sourcefile_moc) - - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) - end - - -- compile c++ source file for moc - dependinfo.files = {} - compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags}) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.insert(dependinfo.files, headerfile_moc) - depend.save(dependinfo, dependfile) - end) - --- define rule: *.qrc -rule("qt.qrc") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".qrc") - - -- on load - on_load(function (target) - - -- get rcc - local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") - assert(rcc and os.isexec(rcc), "rcc not found!") - - -- save rcc - target:data_set("qt.rcc", rcc) - end) - - -- on build file - on_build_file(function (target, sourcefile_qrc, opt) - - -- imports - import("core.base.option") - import("core.project.config") - import("core.project.depend") - import("core.tool.compiler") - - -- get rcc - local rcc = target:data("qt.rcc") - - -- get c++ source file for qrc - local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp") - local sourcefile_dir = path.directory(sourcefile_cpp) - - -- get object file - local objectfile = target:objectfile(sourcefile_cpp) - - -- load compiler - local compinst = compiler.load("cxx", {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile_cpp}) - - -- add objectfile - table.insert(target:objectfiles(), objectfile) - - -- add clean files - target:data_add("qt.cleanfiles", {sourcefile_cpp, objectfile}) - - -- load dependent info - local dependfile = target:dependfile(objectfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) - end - - -- ensure the source file directory - if not os.isdir(sourcefile_dir) then - os.mkdir(sourcefile_dir) - end - - -- compile qrc - os.vrunv(rcc, {"-name", "qml", sourcefile_qrc, "-o", sourcefile_cpp}) - - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_cpp, objectfile, {compflags = compflags})) - end - - -- compile c++ source file for qrc - dependinfo.files = {} - compinst:compile(sourcefile_cpp, objectfile, {dependinfo = dependinfo, compflags = compflags}) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.insert(dependinfo.files, sourcefile_qrc) - depend.save(dependinfo, dependfile) - end) - --- define rule: qt static library -rule("qt.static") - - -- add rules - add_deps("qt.qrc", "qt.ui", "qt.moc") - - -- on load - on_load(function (target) - import("load")(target, {kind = "static", frameworks = {"QtCore"}}) - end) - --- define rule: qt shared library -rule("qt.shared") - - -- add rules - add_deps("qt.qrc", "qt.ui", "qt.moc") - - -- on load - on_load(function (target) - import("load")(target, {kind = "shared", frameworks = {"QtCore"}}) - end) - --- define rule: qt console -rule("qt.console") - - -- add rules - add_deps("qt.qrc", "qt.ui", "qt.moc") - - -- on load - on_load(function (target) - import("load")(target, {kind = "binary", frameworks = {"QtCore"}}) - end) - --- define rule: qt application -rule("qt.application") - - -- add rules - add_deps("qt.qrc", "qt.ui", "qt.moc") - - -- on load - on_load(function (target) - - -- load common flags to target - import("load")(target, {kind = "binary", frameworks = {"QtGui", "QtQml", "QtNetwork", "QtCore"}}) - - -- add -subsystem:windows for windows platform - if is_plat("windows") then - target:add("defines", "_WINDOWS") - target:add("ldflags", "-subsystem:windows", "-entry:mainCRTStartup", {force = true}) - elseif is_plat("mingw") then - target:add("defines", "_WINDOWS") - target:add("ldflags", "-Wl,-subsystem:windows", "-Wl,-entry:mainCRTStartup", {force = true}) - end - end) - diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua new file mode 100644 index 000000000..f1373b711 --- /dev/null +++ b/xmake/rules/qt/load.lua @@ -0,0 +1,125 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- make link for framework +function _link(framework, major) + if major and framework:startswith("Qt") then + framework = "Qt" .. major .. framework:sub(3) .. (is_mode("debug") and "d" or "") + end + return framework +end + +-- the main entry +function main(target, opt) + + -- init options + opt = opt or {} + + -- get qt sdk + local qt = target:data("qt") + + -- get major version + local major = nil + if qt.sdkver then + major = qt.sdkver:split('%.')[1] + end + + -- set kind + if opt.kind then + target:set("kind", opt.kind) + end + + -- add -fPIC + target:add("cxflags", "-fPIC") + target:add("mxflags", "-fPIC") + target:add("asflags", "-fPIC") + + -- need c++11 + target:set("languages", "cxx11") + + -- add defines for the compile mode + if is_mode("debug") then + target:add("defines", "QT_QML_DEBUG") + elseif is_mode("release") then + target:add("defines", "QT_NO_DEBUG") + elseif is_mode("profile") then + target:add("defines", "QT_QML_DEBUG", "QT_NO_DEBUG") + end + + -- The following define makes your compiler emit warnings if you use + -- any feature of Qt which as been marked deprecated (the exact warnings + -- depend on your compiler). Please consult the documentation of the + -- deprecated API in order to know how to port your code away from it. + target:add("defines", "QT_DEPRECATED_WARNINGS") + + -- add frameworks + if opt.frameworks then + target:add("frameworks", opt.frameworks) + end + + -- do frameworks for qt + for _, framework in ipairs(target:get("frameworks")) do + + -- translate qt frameworks + if framework:startswith("Qt") then + + -- add defines + target:add("defines", "QT_" .. framework:sub(3):upper() .. "_LIB") + + -- add includedirs + if is_plat("macosx") then + target:add("includedirs", path.join(qt.sdkdir, "lib/" .. framework .. ".framework/Headers")) + else + target:add("links", _link(framework, major)) + target:add("includedirs", path.join(qt.sdkdir, "include/" .. framework)) + end + end + end + + -- add includedirs, linkdirs + if is_plat("macosx") then + target:add("frameworks", "DiskArbitration", "IOKit") + target:add("frameworkdirs", qt.linkdirs) + target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang")) + target:add("linkdirs", qt.linkdirs) + target:add("rpathdirs", "@executable_path/Frameworks", qt.linkdirs) + elseif is_plat("linux") then + target:set("frameworks", nil) + target:add("includedirs", path.join(qt.sdkdir, "include")) + target:add("includedirs", path.join(qt.sdkdir, "mkspecs/linux-g++")) + target:add("rpathdirs", qt.linkdirs) + target:add("linkdirs", qt.linkdirs) + elseif is_plat("windows") then + target:set("frameworks", nil) + target:add("includedirs", path.join(qt.sdkdir, "include")) + target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-msvc")) + target:add("linkdirs", qt.linkdirs) + elseif is_plat("mingw") then + target:set("frameworks", nil) + target:add("includedirs", path.join(qt.sdkdir, "include")) + target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-g++")) + target:add("linkdirs", qt.linkdirs) + end +end + diff --git a/xmake/rules/wdk/env/load.lua b/xmake/rules/wdk/env/load.lua deleted file mode 100644 index 6d78ecf7a..000000000 --- a/xmake/rules/wdk/env/load.lua +++ /dev/null @@ -1,151 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2018, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load for umdf driver -function umdf_driver(target) - - -- get wdk - local wdk = target:data("wdk") - - -- set kind - target:set("kind", "shared") - - -- add defines - local arch = config.arch() - local umdfver = wdk.umdfver:split('%.') - if arch == "x64" then - target:add("defines", "_WIN64", "_AMD64_", "AMD64") - end - target:add("defines", "UMDF_VERSION_MAJOR=" .. umdfver[1], "UMDF_VERSION_MINOR=" .. umdfver[2], "UMDF_USING_NTSTATUS") - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") - - -- add include directories - target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) - target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) - - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) - target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) - - -- add links - target:add("links", "WdfDriverStubUm", "ntdll", "OneCoreUAP", "mincore", "ucrt") - target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) -end - --- load for umdf binary -function umdf_binary(target) - - -- get wdk - local wdk = target:data("wdk") - - -- set kind - target:set("kind", "binary") - - -- add defines - local arch = config.arch() - if arch == "x64" then - target:add("defines", "_WIN64", "_AMD64_", "AMD64") - end - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") - - -- add include directories - target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) - target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) - - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) - target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) - - -- add links - target:add("links", "ntdll", "OneCoreUAP", "mincore", "ucrt") - target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) -end - --- load for kmdf driver -function kmdf_driver(target) - - -- get wdk - local wdk = target:data("wdk") - - -- set kind - target:set("kind", "binary") - - -- set filename: xxx.sys - target:set("filename", target:basename() .. ".sys") - - -- add defines - local arch = config.arch() - local kmdfver = wdk.kmdfver:split('%.') - if arch == "x64" then - target:add("defines", "_WIN64", "_AMD64_", "AMD64") - end - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") - target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2], "KMDF_USING_NTSTATUS") - - -- add include directories - target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) - target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) - - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) - target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) - - -- add links - target:add("links", "BufferOverflowFastFailK", "ntoskrnl", "hal", "wmilib", "WdfLdr", "WdfDriverEntry", "ntstrsafe", "wdmsec") - target:add("ldflags", "-entry:FxDriverEntry", "-subsystem:native,10.00", "-driver", "-kernel", {force = true}) -end - --- load for kmdf binary -function kmdf_binary(target) - - -- get wdk - local wdk = target:data("wdk") - - -- set kind - target:set("kind", "binary") - - -- add defines - local arch = config.arch() - local kmdfver = wdk.kmdfver:split('%.') - if arch == "x64" then - target:add("defines", "_WIN64", "_AMD64_", "AMD64") - end - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") - target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2]) - - -- add include directories - target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) - target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) - - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) - target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) - - -- add links - target:add("links", "kernel32", "user32", "gdi32", "winspool", "comdlg32") - target:add("links", "advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32", "setupapi") -end diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/load.lua new file mode 100644 index 000000000..6d78ecf7a --- /dev/null +++ b/xmake/rules/wdk/load.lua @@ -0,0 +1,151 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- imports +import("core.project.config") + +-- load for umdf driver +function umdf_driver(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "shared") + + -- add defines + local arch = config.arch() + local umdfver = wdk.umdfver:split('%.') + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") + end + target:add("defines", "UMDF_VERSION_MAJOR=" .. umdfver[1], "UMDF_VERSION_MINOR=" .. umdfver[2], "UMDF_USING_NTSTATUS") + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) + + -- add links + target:add("links", "WdfDriverStubUm", "ntdll", "OneCoreUAP", "mincore", "ucrt") + target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) +end + +-- load for umdf binary +function umdf_binary(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "binary") + + -- add defines + local arch = config.arch() + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") + end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) + + -- add links + target:add("links", "ntdll", "OneCoreUAP", "mincore", "ucrt") + target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) +end + +-- load for kmdf driver +function kmdf_driver(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "binary") + + -- set filename: xxx.sys + target:set("filename", target:basename() .. ".sys") + + -- add defines + local arch = config.arch() + local kmdfver = wdk.kmdfver:split('%.') + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") + end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2], "KMDF_USING_NTSTATUS") + + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) + + -- add links + target:add("links", "BufferOverflowFastFailK", "ntoskrnl", "hal", "wmilib", "WdfLdr", "WdfDriverEntry", "ntstrsafe", "wdmsec") + target:add("ldflags", "-entry:FxDriverEntry", "-subsystem:native,10.00", "-driver", "-kernel", {force = true}) +end + +-- load for kmdf binary +function kmdf_binary(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "binary") + + -- add defines + local arch = config.arch() + local kmdfver = wdk.kmdfver:split('%.') + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") + end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2]) + + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) + + -- add links + target:add("links", "kernel32", "user32", "gdi32", "winspool", "comdlg32") + target:add("links", "advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32", "setupapi") +end -- cgit v1.3.1