Code Monkey home page Code Monkey logo

Comments (11)

waruqi avatar waruqi commented on August 17, 2024

你这边定义的dirs是个 dictionary 类型,需要 用 pairs 来遍历,ipairs 是用来遍历数组的。。这个你可以百度下 lua 中 pairs 和 ipairs的使用区别

你改成:

for k, v pairs(dirs) do
end

试试,如果调试的话,你可以使用下面的调用,打印变量的所有数据,包括数组和字典:

table.dump(dirs)

from xmake.

waruqi avatar waruqi commented on August 17, 2024

还有这里判断各种option去设置不同的on_build,不建议这种写法,太混乱

on_build这种自定义脚本本身就是为了解决一些复杂需求的,你可以吧外层的option判断什么都放置到 on_build 内部中去,外层描述尽可能保持简单可读,也不需要for循环遍历,在on_build里面,可以使用更多的模块接口,访问配置,例如:

target(name)

    -- set kind
    set_kind("shared")
    add_includedirs(prefixInclude)
    add_options("LightInk3D2D")

    on_build(function()

          -- 导入配置模块
          import("core.project.config")

          -- 加载配置
          config.load()

          -- 判断选项是否被设置,也就是,是否设置了:xmake f --LightInk3D2D=y 后,进行的build
          if config.get("LightInk3D2D") then
          end
    end)

还有像这种 写死的 :

local prefixInclude = "../../include/ThirdParty/"
local prefixSrc = "../../src/ThirdParty/"

也可以定义成 option ,然后通过 "$(prefixSrc)" 或者 config.get("prefixSrc") 来访问,例如:

option("prefixSrc")
    set_default("../../src/ThirdParty/")
    set_showmenu(true)
    set_description("sssss")  -- 可以在这适当加些菜单描述,这样xmake f --help的时候,可以看到选项的说明

option("prefixInclude")
    set_default("../../include/ThirdParty/")
    set_showmenu(true)

这样路径就是可配置的:

xmake f --prefixSrc="../../src/ThirdParty/" --prefixInclude="../../include/ThirdParty/" 

from xmake.

waruqi avatar waruqi commented on August 17, 2024

add_subdirs(k) 还有这个属于全局作用域,on_build属于 target 内部作用域,像

target("")

      add_subdirs("")
      on_build(function() end)

这种 add_subdirs放置在 target中间,虽然xmake兼容支持的,但是对用户来讲,容易产生误导,这个我文档中可能没详细说明,不好意思,建议改成:

-- 一个完整的子工程目标设置
target("")
      on_build(function() end)

-- 包含其他子工程目录
add_subdirs("")

from xmake.

baisai avatar baisai commented on August 17, 2024

好吧,我好像一直没有注意作用域的问题..
我现在是想通过option来add_subdirs不同的模块编译....貌似不管放在全局作用域还是放on_build里都不行...
不知道有没办法可以实现

from xmake.

waruqi avatar waruqi commented on August 17, 2024

add_subdirs 仅仅是用来包含子工程文件的,一般不是用来区分编译不同模块的。。

因为子工程xmake.lua 也可以定义option,这样通过option来区分调用add_subdirs的话,就会出现鸡生蛋的问题了。。。

一般做法是,add_subdirs照样包含全部子工程模块的xmake.lua ,不用做区分,你可以在子工程的xmake.lua里面定义个 option ,然后通过 区分target 来处理,例如:

子模块的xmake.lua

-- 定义个选项开关
option("enable_module")
      ....

-- 当前编译是否启用了此模块target?
if is_option("enable_module") then

     -- 只有选项启用后,才会去定义这个子模块目标工程,如果没定义的话,也就不会编译进去了
     target("xxxx")
         ...
end

from xmake.

waruqi avatar waruqi commented on August 17, 2024

还有中更加方便的方式是,option什么都不需要定义,全部子工程模块target定义好后,不敲xmake来编译,这个默认会全部编译,直接指定需要编译的子模块就行了,例如:

-- 重建指定子工程模块 (注:由于第一个参数被action占用了,不能直接执行 xmake targetname)
xmake -r targetname

clean, package 等也是可以指定target运行的

-- 清理指定子工程模块
xmake c targetname
xmake clean targetname

-- 打包指定模块
xmake p targetname
xmake package targetname

from xmake.

waruqi avatar waruqi commented on August 17, 2024

然后target之间可以通过 add_deps("") 添加依赖关系,级联编译。。

from xmake.

baisai avatar baisai commented on August 17, 2024

好的,谢谢....
不过貌似add_subdirs接口文档那....是这么用,可能是文档太老了....最好改一下
https://github.com/waruqi/xmake/wiki/add_subdirs

from xmake.

waruqi avatar waruqi commented on August 17, 2024

文档这样用也是可以的 不过option的定义必须放根xmake.lua中去 里面api我更新下 应该是is_option

from xmake.

waruqi avatar waruqi commented on August 17, 2024

可以参考https://github.com/waruqi/tbox/blob/master/xmake.lua

from xmake.

baisai avatar baisai commented on August 17, 2024

好的,谢谢

from xmake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.