Created
April 20, 2019 05:43
-
-
Save leidegre/c3a888882eda043915d307b5241fa983 to your computer and use it in GitHub Desktop.
Implicit build units with Tundra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local msvc_common = { | |
{"/MDd", Config = "*-msvc-debug-*"}, | |
--Unicode | |
"/DUNICODE", | |
"/D_UNICODE", | |
"/D_CRT_SECURE_NO_WARNINGS", | |
"/D_WINSOCK_DEPRECATED_NO_WARNINGS", | |
"/W4", | |
--treat as error | |
"/we4701", --Potentially uninitialized local variable 'name' used | |
"/we4715", --'function' : not all control paths return a value | |
"/we4244", --conversion' conversion from 'type1' to 'type2', possible loss of data | |
--disable | |
"/wd4100", --unreferenced formal parameter | |
"/wd4706", --assignment within conditional expression | |
--windows.h requires Microsoft language extensions? | |
--"/Za" -- emits an error for language constructs that are not compatible with ANSI C89 or ISO C++11 | |
{"/Ox", Config = "*-msvc-release-*"} --optimize! | |
} | |
Build { | |
Configs = { | |
{ | |
Name = "win64-msvc", | |
DefaultOnHost = "windows", | |
Tools = {{"msvc-vs2017", TargetArch = "x64", SdkVersion = "10.0.15063.0"}}, | |
Env = { | |
CCOPTS = { | |
msvc_common | |
}, | |
CXXOPTS = { | |
msvc_common, | |
"/EHsc" -- catch C++ exceptions only and tells the compiler to assume that functions declared as extern "C" never throw a C++ exception | |
}, | |
GENERATE_PDB = {"1", Config = "*-msvc-debug-*"} | |
} | |
} | |
}, | |
Units = { | |
"vendor/zlib.lua", | |
"vendor/libpng.lua", | |
"vendor/simplex_noise.lua", | |
"vendor/lua.lua", | |
"units.lua" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local path = require "tundra.path" | |
local native = require "tundra.native" | |
require "tundra.syntax.glob" | |
--StaticLibrary { | |
-- Name = "glew", | |
-- Sources = { | |
-- "lib/glew/src/glew.c" | |
-- }, | |
-- Defines = { | |
-- "GLEW_STATIC" | |
-- }, | |
-- Includes = { | |
-- "lib/glew/include" | |
-- }, | |
-- Propagate = { | |
-- Defines = { | |
-- "GLEW_STATIC" | |
-- }, | |
-- Includes = { | |
-- "lib/glew/include" | |
-- }, | |
-- Libs = { | |
-- "opengl32.lib", | |
-- "gdi32.lib" | |
-- } | |
-- } | |
--} | |
ExternalLibrary { | |
Name = "win32", | |
Propagate = { | |
Defines = {}, | |
Includes = {}, | |
Libs = { | |
"opengl32.lib", | |
"gdi32.lib" | |
} | |
} | |
} | |
local implicit_depends = {"win32", "luacore", "lualib"} | |
local implicit_depends2 = {} | |
local implicit_units = {} | |
local dirs, _ = native.list_directory("src/game") | |
for _, dir in ipairs(dirs) do | |
local source = | |
FGlob { | |
Dir = "src/game/" .. dir, | |
Extensions = {".c", ".cc"}, | |
Filters = { | |
{Pattern = "_test.cc?$", Config = "ignore"}, | |
{Pattern = "_ignore.cc?$", Config = "ignore"}, | |
{Pattern = "_windows.cc$", Config = "win64-*"} | |
} | |
} | |
if dir:match("^cmd_") then | |
local name = dir:sub(5) | |
implicit_units[name] = { | |
Name = name, | |
Depends = {implicit_depends, implicit_depends2}, | |
Sources = { | |
source | |
}, | |
Libs = { | |
"user32.lib", | |
"ws2_32.lib" | |
}, | |
Env = { | |
PROGOPTS = { | |
{"/SUBSYSTEM:WINDOWS,6.01", Config = "msvc-*"} --Windows 7 | |
} | |
} | |
} | |
else | |
local name = dir | |
--source must have at least 1 source file | |
local has_source = false | |
for _, fn in ipairs(source) do | |
if has_source then | |
break | |
end | |
if type(fn) == "table" then | |
for _, fn2 in ipairs(fn) do | |
if fn2:match(".cc?$") ~= nil then | |
has_source = true | |
break --inner loop | |
end | |
end | |
else | |
if fn:match(".cc?$") ~= nil then | |
has_source = true | |
end | |
end | |
end | |
--if there's no source then we don't need to compile it | |
if has_source then | |
StaticLibrary { | |
Name = name, | |
Depends = {implicit_depends}, | |
Sources = { | |
source | |
} | |
} | |
implicit_depends2[#implicit_depends2 + 1] = name | |
end | |
end | |
end | |
--!!! | |
local blueprints = { | |
["game"] = { | |
Libs = { | |
"user32.lib", | |
"ws2_32.lib" | |
} | |
}, | |
["fbx"] = { | |
Depends = {"fbxsdk"}, | |
Libs = { | |
"user32.lib", | |
"ws2_32.lib" | |
} | |
} | |
} | |
for name, unit in pairs(implicit_units) do | |
local blueprint = blueprints[name] | |
if blueprint then | |
for k, v in pairs(blueprint) do | |
if k == "Depends" then --append Depends | |
local deps = unit[k] | |
if deps == nil then | |
deps = {} | |
end | |
for _, dep in ipairs(v) do | |
deps[#deps + 1] = dep | |
end | |
unit[k] = deps | |
else | |
unit[k] = v | |
end | |
end | |
end | |
Program(unit) | |
end | |
Default "game_dll" | |
--test programs | |
local tests = | |
Glob { | |
Dir = "src/game", | |
Extensions = {".c", ".cc"} | |
} | |
for k, v in ipairs(tests) do | |
if v:find("_test.cc?$") then | |
local mod = path.get_filename(path.get_filename_dir(v)) | |
Program { | |
Name = mod .. "_" .. path.get_filename_base(v), | |
Depends = {"test", "mem", "common", "simplex_noise"}, | |
Sources = { | |
v, | |
FGlob { | |
Dir = path.get_filename_dir(v), | |
Extensions = {".c", ".cc"}, | |
Filters = { | |
{Pattern = "_test.cc?$", Config = "ignore"} | |
} | |
}, | |
Recursive = false | |
}, | |
Libs = { | |
"user32.lib", | |
"ws2_32.lib" | |
} | |
} | |
end | |
end | |
--fbx | |
ExternalLibrary { | |
Name = "fbxsdk", | |
Propagate = { | |
Defines = { | |
"FBXSDK_SHARED" | |
}, | |
Includes = { | |
"C:/Program Files/Autodesk/FBX/FBX SDK/2017.1/include" | |
}, | |
Libs = { | |
"C:/Program Files/Autodesk/FBX/FBX SDK/2017.1/lib/vs2015/x64/release/libfbxsdk.lib" | |
} | |
} | |
} | |
-- Node.js C++ Addon | |
-- (node-gyp can generate MSBuild files, | |
-- we simply reverse engineer this from that) | |
SharedLibrary { | |
Name = "game_dll", | |
Depends = {implicit_depends, implicit_depends2}, | |
Target = "$(OBJECTDIR)/game_dll.node", --note: custom extension | |
Defines = { | |
"NODE_GYP_MODULE_NAME=game_dll", --note: must be same as everything else | |
--"USING_UV_SHARED=1", | |
--"USING_V8_SHARED=1", | |
"V8_DEPRECATION_WARNINGS=1", | |
"_CRT_SECURE_NO_DEPRECATE", | |
"_CRT_NONSTDC_NO_DEPRECATE", | |
"_HAS_EXCEPTIONS=0", | |
"BUILDING_NODE_EXTENSION" | |
-- todo: V8_ENABLE_CHECKS (debug) | |
}, | |
Includes = { | |
"lib/node/v10.7.0/include/node" | |
}, | |
Libs = { | |
{"lib/node/v10.7.0/win-x64/node.lib", Config = "win64-msvc-*"}, | |
"user32.lib", | |
"ws2_32.lib" | |
}, | |
Sources = { | |
FGlob { | |
Dir = "src/game_dll", | |
Extensions = {".c", ".cc"}, | |
Filters = { | |
{Pattern = "_test.cc?$", Config = "ignore"} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment