diff options
| author | ruki <[email protected]> | 2017-05-12 11:03:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-12 11:03:34 +0800 |
| commit | 2cfd41ae2fe1c008e9572538ebf90e5f898513f9 (patch) | |
| tree | ab1186b3705253ce7f1130b12ce3008fa34a524a | |
| parent | 149d26d8fefd4d3dbba882131b926f4a852e336c (diff) | |
add includes and links from target deps automatically
| -rw-r--r-- | xmake/core/project/option.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 24 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 12 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 58 |
4 files changed, 97 insertions, 3 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index e4e408d90..72cc0d750 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -484,6 +484,12 @@ function option:get(infoname) return self._INFO[infoname] end +-- get option deps +function option:deps() + -- TODO in the future + return {} +end + -- save the option info to the cache function option:save() diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index d0434a3b1..8952cbdc3 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -348,6 +348,23 @@ function project._interpreter() return interp end +-- load target deps +function project._load_target_deps(target, targets) + + -- get dep targets + local deptargets = {} + for _, dep in ipairs(table.wrap(target:get("deps"))) do + local deptarget = targets[dep] + if deptarget then + table.join2(deptargets, project._load_target_deps(deptarget)) + table.insert(deptargets, deptarget) + end + end + + -- ok? + return table.unique(deptargets) +end + -- get the project directory function project.directory() @@ -444,6 +461,11 @@ function project.load() targets[targetname] = target.new(targetname, targetinfo) end + -- load and attach target deps + for _, target in pairs(targets) do + target._DEPS = project._load_target_deps(target, targets) + end + -- save targets project._TARGETS = targets @@ -455,7 +477,7 @@ end function project.target(targetname) -- check - assert(targetname and targetname ~= "all") + assert(targetname) -- the targets local targets = project.targets() diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 76f2f7548..f58e2eb88 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -124,6 +124,11 @@ function target:linkflags() return self:linker():linkflags(self) end +-- get target deps +function target:deps() + return self._DEPS +end + -- get the options function target:options() @@ -219,6 +224,11 @@ function target:scriptdir() return self:get("__scriptdir") end +-- get header directory +function target:headerdir() + return self:get("headerdir") or config.get("buildir") +end + -- get the config header files function target:configheader(outputdir) @@ -401,7 +411,7 @@ function target:headerfiles(outputdir) if not headers then return end -- get the headerdir - local headerdir = outputdir or self:get("headerdir") or config.get("buildir") + local headerdir = outputdir or self:headerdir() assert(headerdir) -- get the source pathes and destinate pathes diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index aa212ead6..a79b7c902 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -152,6 +152,50 @@ function builder:_addflags_from_target(flags, target) end end +-- add flags from target deps +function builder:_addflags_from_targetdeps(results, target, flagname) + + -- for all target deps + for _, dep in ipairs(target:deps()) do + + -- is static or shared target library? link it + local targetkind = dep:targetkind() + if targetkind == "static" or targetkind == "shared" then + if flagname == "links" then + + -- add dependent link + local link, ok = path.filename(dep:targetfile()):gsub(target.filename("([%w_]+)", targetkind):gsub("%.", "%%.") .. "$", "%1") + if link and ok > 0 then + table.insert(results, link) + end + + elseif flagname == "linkdirs" then + + -- add dependent linkdirs + table.insert(results, path.directory(dep:targetfile())) + + elseif flagname == "rpathdirs" then + + -- add dependent rpathdirs (need absolute path) + table.insert(results, path.directory(path.absolute(dep:targetfile(), xmake._PROJECT_DIR))) + + elseif flagname == "includedirs" then + + -- add dependent headerdir + if dep:get("headers") and os.isdir(dep:headerdir()) then + table.insert(results, dep:headerdir()) + end + + -- add dependent configheader directory + local configheader = dep:configheader() + if configheader and os.isfile(configheader) then + table.insert(results, path.directory(configheader)) + end + end + end + end +end + -- add flags (named) from the language function builder:_addflags_from_language(flags, target) @@ -160,7 +204,19 @@ function builder:_addflags_from_language(flags, target) { config = config.get , platform = platform.get - , target = function (name) return target:get(name) end + , target = function (name) + + -- get flagvalues of target with given flagname + local results = table.wrap(target:get(name)) + + -- link? add includes and links of all dependent targets + if name == "links" or name == "linkdirs" or name == "rpathdirs" or name == "includedirs" then + self:_addflags_from_targetdeps(results, target, name) + end + + -- ok? + return results + end , option = function (name) -- only for target (exclude option) |
