diff --git a/premake5.lua b/premake5.lua index 5b07a78c..06454952 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,68 +1,8 @@ --- Functions for locating commonly used folders -local _BuildFolder = path.getabsolute("build") -function BuildFolder() - return path.getrelative(os.getcwd(), _BuildFolder) -end - -local _ThirdPartyFolder = path.getabsolute("thirdparty") -function ThirdPartyFolder() - return path.getrelative(os.getcwd(), _ThirdPartyFolder) -end - -local _ProjectFolder = path.getabsolute("src") -function ProjectFolder() - return path.getrelative(os.getcwd(), _ProjectFolder) -end - -local _TestFolder = path.getabsolute("test") -function TestFolder() - return path.getrelative(os.getcwd(), _TestFolder) -end - --- Functions for including projects -References = { - includeList = {}, - linkList = {} -} - -function References:include(name) - result = self.includeList[name] == nil - - if result then - self.includeList[name] = true - end - - return result -end - -function References:link(name) - result = self.linkList[name] == nil - - if result then - self.linkList[name] = true - end - - return result -end - -function References:reset() - self.includeList = {} - self.linkList = {} -end - --- Target Directories -TargetDirectoryBin = "%{wks.location}/bin/%{cfg.buildcfg}_%{cfg.platform}" -TargetDirectoryLib = "%{wks.location}/lib/%{cfg.buildcfg}_%{cfg.platform}" -TargetDirectoryTest = "%{wks.location}/lib/%{cfg.buildcfg}_%{cfg.platform}/tests" - --- Platform functions -function ExecutableByOs(name) - if os.host() == "windows" then - return name .. ".exe" - else - return name - end -end +include "tools/scripts/folders.lua" +include "tools/scripts/including.lua" +include "tools/scripts/linking.lua" +include "tools/scripts/options.lua" +include "tools/scripts/platform.lua" -- ================== -- Workspace diff --git a/src/Crypto.lua b/src/Crypto.lua index 7718b09d..96cd1670 100644 --- a/src/Crypto.lua +++ b/src/Crypto.lua @@ -1,31 +1,33 @@ Crypto = {} -function Crypto:include() - if References:include("Crypto") then +function Crypto:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "Crypto") } end end -function Crypto:link() - if References:link("Crypto") then - libtomcrypt:link() - libtommath:link() - salsa20:link() - links "Crypto" - end +function Crypto:link(links) + links:add(self:name()) + links:linkto(libtomcrypt) + links:linkto(libtommath) + links:linkto(salsa20) end function Crypto:use() end -function Crypto:project() - References:reset() - local folder = ProjectFolder(); +function Crypto:name() + return "Crypto" +end - project "Crypto" +function Crypto:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -36,8 +38,8 @@ function Crypto:project() path.join(folder, "Crypto/**.cpp") } - self:include() - libtomcrypt:include() - libtommath:include() - salsa20:include() + self:include(includes) + libtomcrypt:include(includes) + libtommath:include(includes) + salsa20:include(includes) end diff --git a/src/Linker.lua b/src/Linker.lua index ab8999c6..9fad9a3e 100644 --- a/src/Linker.lua +++ b/src/Linker.lua @@ -1,26 +1,31 @@ Linker = {} -function Linker:include() - if References:include("Linker") then +function Linker:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "Linker") } end end -function Linker:link() +function Linker:link(links) end function Linker:use() - dependson "Linker" + dependson(self:name()) +end + +function Linker:name() + return "Linker" end function Linker:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() + local links = Links:create() - project "Linker" + project(self:name()) targetdir(TargetDirectoryBin) location "%{wks.location}/src/%{prj.name}" kind "ConsoleApp" @@ -31,10 +36,12 @@ function Linker:project() path.join(folder, "Linker/**.cpp") } - self:include() - Utils:include() - ZoneWriting:include() + self:include(includes) + Utils:include(includes) + ZoneWriting:include(includes) - Utils:link() - --ZoneWriting:link() + links:linkto(Utils) + links:linkto(ZoneWriting) + --ZoneWriting:link(links) + links:linkall() end diff --git a/src/ObjCommon.lua b/src/ObjCommon.lua index 57ba9d0b..a7ccb245 100644 --- a/src/ObjCommon.lua +++ b/src/ObjCommon.lua @@ -1,35 +1,35 @@ ObjCommon = {} -function ObjCommon:include() - if References:include("ObjCommon") then - ZoneCommon:include() - minizip:include() +function ObjCommon:include(includes) + if includes:handle(self:name()) then + ZoneCommon:include(includes) + minizip:include(includes) includedirs { path.join(ProjectFolder(), "ObjCommon") } end end -function ObjCommon:link() - if References:link("ObjCommon") then - Utils:link() - ZoneCommon:link() - minizip:link() - links { - "ObjCommon" - } - end +function ObjCommon:link(links) + links:add(self:name()) + links:linkto(Utils) + links:linkto(ZoneCommon) + links:linkto(minizip) end function ObjCommon:use() end -function ObjCommon:project() - References:reset() - local folder = ProjectFolder(); +function ObjCommon:name() + return "ObjCommon" +end - project "ObjCommon" +function ObjCommon:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -46,6 +46,6 @@ function ObjCommon:project() } } - self:include() - Utils:include() + self:include(includes) + Utils:include(includes) end diff --git a/src/ObjLoading.lua b/src/ObjLoading.lua index 32301f37..c9109ae5 100644 --- a/src/ObjLoading.lua +++ b/src/ObjLoading.lua @@ -1,38 +1,38 @@ ObjLoading = {} -function ObjLoading:include() - if References:include("ObjLoading") then - ObjCommon:include() - ZoneCommon:include() +function ObjLoading:include(includes) + if includes:handle(self:name()) then + ObjCommon:include(includes) + ZoneCommon:include(includes) includedirs { path.join(ProjectFolder(), "ObjLoading") } end end -function ObjLoading:link() - if References:link("ObjLoading") then - Utils:link() - ObjCommon:link() - ZoneCommon:link() - minilzo:link() - minizip:link() - zlib:link() - links { - "ObjLoading" - } - end +function ObjLoading:link(links) + links:add(self:name()) + links:linkto(Utils) + links:linkto(ObjCommon) + links:linkto(ZoneCommon) + links:linkto(minilzo) + links:linkto(minizip) + links:linkto(zlib) end function ObjLoading:use() end -function ObjLoading:project() - References:reset() - local folder = ProjectFolder(); +function ObjLoading:name() + return "ObjLoading" +end - project "ObjLoading" +function ObjLoading:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -49,10 +49,10 @@ function ObjLoading:project() } } - self:include() - Crypto:include() - Utils:include() - minilzo:include() - minizip:include() - zlib:include() + self:include(includes) + Crypto:include(includes) + Utils:include(includes) + minilzo:include(includes) + minizip:include(includes) + zlib:include(includes) end diff --git a/src/ObjWriting.lua b/src/ObjWriting.lua index 4dfe0e99..22303aed 100644 --- a/src/ObjWriting.lua +++ b/src/ObjWriting.lua @@ -1,37 +1,37 @@ ObjWriting = {} -function ObjWriting:include() - if References:include("ObjWriting") then - ObjCommon:include() - ZoneCommon:include() +function ObjWriting:include(includes) + if includes:handle(self:name()) then + ObjCommon:include(includes) + ZoneCommon:include(includes) includedirs { path.join(ProjectFolder(), "ObjWriting") } end end -function ObjWriting:link() - if References:link("ObjWriting") then - Utils:link() - ObjCommon:link() - ZoneCommon:link() - minilzo:link() - minizip:link() - links { - "ObjWriting" - } - end +function ObjWriting:link(links) + links:add(self:name()) + links:linkto(Utils) + links:linkto(ObjCommon) + links:linkto(ZoneCommon) + links:linkto(minilzo) + links:linkto(minizip) end function ObjWriting:use() end -function ObjWriting:project() - References:reset() - local folder = ProjectFolder(); +function ObjWriting:name() + return "ObjWriting" +end - project "ObjWriting" +function ObjWriting:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -48,8 +48,8 @@ function ObjWriting:project() } } - self:include() - Utils:include() - minilzo:include() - minizip:include() + self:include(includes) + Utils:include(includes) + minilzo:include(includes) + minizip:include(includes) end diff --git a/src/Unlinker.lua b/src/Unlinker.lua index bb97a46a..15c55adc 100644 --- a/src/Unlinker.lua +++ b/src/Unlinker.lua @@ -1,26 +1,31 @@ Unlinker = {} -function Unlinker:include() - if References:include("Unlinker") then +function Unlinker:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "Unlinker") } end end -function Unlinker:link() +function Unlinker:link(links) end function Unlinker:use() - dependson "Unlinker" + dependson(self:name()) +end + +function Unlinker:name() + return "Unlinker" end function Unlinker:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() + local links = Links:create() - project "Unlinker" + project(self:name()) targetdir(TargetDirectoryBin) location "%{wks.location}/src/%{prj.name}" kind "ConsoleApp" @@ -31,14 +36,15 @@ function Unlinker:project() path.join(folder, "Unlinker/**.cpp") } - self:include() - Utils:include() - ZoneLoading:include() - ObjLoading:include() - ObjWriting:include() + self:include(includes) + Utils:include(includes) + ZoneLoading:include(includes) + ObjLoading:include(includes) + ObjWriting:include(includes) - Utils:link() - ZoneLoading:link() - ObjLoading:link() - ObjWriting:link() + links:linkto(Utils) + links:linkto(ZoneLoading) + links:linkto(ObjLoading) + links:linkto(ObjWriting) + links:linkall() end diff --git a/src/Utils.lua b/src/Utils.lua index 91ad56bc..0b96dbb6 100644 --- a/src/Utils.lua +++ b/src/Utils.lua @@ -1,17 +1,15 @@ Utils = {} -function Utils:include() - if References:include(self:name()) then +function Utils:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "Utils") } end end -function Utils:link() - if References:link(self:name()) then - links(self:name()) - end +function Utils:link(links) + links:add(self:name()) end function Utils:use() @@ -23,8 +21,8 @@ function Utils:name() end function Utils:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() project(self:name()) targetdir(TargetDirectoryLib) @@ -43,5 +41,5 @@ function Utils:project() } } - self:include() + self:include(includes) end diff --git a/src/ZoneCode.lua b/src/ZoneCode.lua index 2698bb5c..6b2d6a84 100644 --- a/src/ZoneCode.lua +++ b/src/ZoneCode.lua @@ -145,8 +145,8 @@ function ZoneCode:allWriteFiles() return result end -function ZoneCode:include() - if References:include("ZoneCode") then +function ZoneCode:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "ZoneCode"), "%{wks.location}/src/ZoneCode" @@ -154,19 +154,22 @@ function ZoneCode:include() end end -function ZoneCode:link() +function ZoneCode:link(links) end function ZoneCode:use() - dependson "ZoneCode" + dependson(self:name()) +end + +function ZoneCode:name() + return "ZoneCode" end function ZoneCode:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() - project "ZoneCode" + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "Utility" diff --git a/src/ZoneCodeGenerator.lua b/src/ZoneCodeGenerator.lua index 32f76458..036ef45b 100644 --- a/src/ZoneCodeGenerator.lua +++ b/src/ZoneCodeGenerator.lua @@ -1,18 +1,16 @@ ZoneCodeGenerator = {} -function ZoneCodeGenerator:include() - if References:include(self:name()) then +function ZoneCodeGenerator:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "ZoneCodeGenerator") } + Utils:include(includes) end - Utils:include() end -function ZoneCodeGenerator:link() - if References:link(self:name()) then - links(self:name()) - end +function ZoneCodeGenerator:link(links) + end function ZoneCodeGenerator:use() @@ -24,8 +22,9 @@ function ZoneCodeGenerator:name() end function ZoneCodeGenerator:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() + local links = Links:create() project(self:name()) targetdir(TargetDirectoryBin) @@ -43,9 +42,10 @@ function ZoneCodeGenerator:project() } } - self:include() - ZoneCodeGeneratorLib:include() + self:include(includes) + ZoneCodeGeneratorLib:include(includes) - ZoneCodeGeneratorLib:link() - Utils:link() + links:linkto(Utils) + links:linkto(ZoneCodeGeneratorLib) + links:linkall() end diff --git a/src/ZoneCodeGeneratorLib.lua b/src/ZoneCodeGeneratorLib.lua index 4a1b4eb0..c5b53173 100644 --- a/src/ZoneCodeGeneratorLib.lua +++ b/src/ZoneCodeGeneratorLib.lua @@ -1,19 +1,17 @@ ZoneCodeGeneratorLib = {} -function ZoneCodeGeneratorLib:include() - if References:include(self:name()) then +function ZoneCodeGeneratorLib:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ProjectFolder(), "ZoneCodeGeneratorLib") } + Utils:include(includes) end - Utils:include() end -function ZoneCodeGeneratorLib:link() - if References:link(self:name()) then - links(self:name()) - Utils:link() - end +function ZoneCodeGeneratorLib:link(links) + links:add(self:name()) + links:linkto(Utils) end function ZoneCodeGeneratorLib:use() @@ -25,8 +23,8 @@ function ZoneCodeGeneratorLib:name() end function ZoneCodeGeneratorLib:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() project(self:name()) targetdir(TargetDirectoryLib) @@ -39,7 +37,5 @@ function ZoneCodeGeneratorLib:project() path.join(folder, "ZoneCodeGeneratorLib/**.cpp") } - self:include() - - Utils:link() + self:include(includes) end diff --git a/src/ZoneCommon.lua b/src/ZoneCommon.lua index d8d82ddb..a0da0eea 100644 --- a/src/ZoneCommon.lua +++ b/src/ZoneCommon.lua @@ -1,21 +1,19 @@ ZoneCommon = {} -function ZoneCommon:include() - if References:include(self:name()) then - Utils:include() - ObjCommon:include() +function ZoneCommon:include(includes) + if includes:handle(self:name()) then + Utils:include(includes) + ObjCommon:include(includes) includedirs { path.join(ProjectFolder(), "ZoneCommon") } end end -function ZoneCommon:link() - if References:link(self:name()) then - links(self:name()) - Utils:link() - ObjCommon:link() - end +function ZoneCommon:link(links) + links:add(self:name()) + links:linkto(Utils) + links:linkto(ObjCommon) end function ZoneCommon:use() @@ -27,8 +25,8 @@ function ZoneCommon:name() end function ZoneCommon:project() - References:reset() - local folder = ProjectFolder(); + local folder = ProjectFolder() + local includes = Includes:create() project(self:name()) targetdir(TargetDirectoryLib) @@ -41,7 +39,5 @@ function ZoneCommon:project() path.join(folder, "ZoneCommon/**.cpp") } - self:include() - - Utils:link() + self:include(includes) end diff --git a/src/ZoneLoading.lua b/src/ZoneLoading.lua index dd4aa0ac..f564e064 100644 --- a/src/ZoneLoading.lua +++ b/src/ZoneLoading.lua @@ -1,35 +1,35 @@ ZoneLoading = {} -function ZoneLoading:include() - if References:include("ZoneLoading") then - ZoneCommon:include() +function ZoneLoading:include(includes) + if includes:handle(self:name()) then + ZoneCommon:include(includes) includedirs { path.join(ProjectFolder(), "ZoneLoading") } end end -function ZoneLoading:link() - if References:link("ZoneLoading") then - Crypto:link() - Utils:link() - ZoneCommon:link() - zlib:link() - links { - "ZoneLoading" - } - end +function ZoneLoading:link(links) + links:add(self:name()) + links:linkto(Crypto) + links:linkto(Utils) + links:linkto(ZoneCommon) + links:linkto(zlib) end function ZoneLoading:use() end -function ZoneLoading:project() - References:reset() - local folder = ProjectFolder(); +function ZoneLoading:name() + return "ZoneLoading" +end - project "ZoneLoading" +function ZoneLoading:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -48,11 +48,11 @@ function ZoneLoading:project() } } - self:include() - Crypto:include() - Utils:include() - zlib:include() - ZoneCode:include() + self:include(includes) + Crypto:include(includes) + Utils:include(includes) + zlib:include(includes) + ZoneCode:include(includes) ZoneCode:use() end diff --git a/src/ZoneWriting.lua b/src/ZoneWriting.lua index 77c6e464..d51d5d3b 100644 --- a/src/ZoneWriting.lua +++ b/src/ZoneWriting.lua @@ -1,35 +1,35 @@ ZoneWriting = {} -function ZoneWriting:include() - if References:include("ZoneWriting") then - ZoneCommon:include() +function ZoneWriting:include(includes) + if includes:handle(self:name()) then + ZoneCommon:include(includes) includedirs { path.join(ProjectFolder(), "ZoneWriting") } end end -function ZoneWriting:link() - if References:link("ZoneWriting") then - Crypto:link() - Utils:link() - ZoneCommon:link() - zlib:link() - links { - "ZoneWriting" - } - end +function ZoneWriting:link(links) + links:add(self:name()) + links:linkto(Crypto) + links:linkto(Utils) + links:linkto(ZoneCommon) + links:linkto(zlib) end function ZoneWriting:use() end -function ZoneWriting:project() - References:reset() - local folder = ProjectFolder(); +function ZoneWriting:name() + return "ZoneWriting" +end - project "ZoneWriting" +function ZoneWriting:project() + local folder = ProjectFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/src/%{prj.name}" kind "StaticLib" @@ -46,10 +46,10 @@ function ZoneWriting:project() } } - self:include() - Crypto:include() - Utils:include() - zlib:include() + self:include(includes) + Crypto:include(includes) + Utils:include(includes) + zlib:include(includes) ZoneCode:use() end diff --git a/test/ObjCommonTests.lua b/test/ObjCommonTests.lua index 7106f9aa..d30f2ae2 100644 --- a/test/ObjCommonTests.lua +++ b/test/ObjCommonTests.lua @@ -1,17 +1,15 @@ ObjCommonTests = {} -function ObjCommonTests:include() - if References:include(self:name()) then +function ObjCommonTests:include(includes) + if includes:handle(self:name()) then includedirs { path.join(TestFolder(), "ObjCommonTests") } end end -function ObjCommonTests:link() - if References:link(self:name()) then - links(self:name()) - end +function ObjCommonTests:link(links) + end function ObjCommonTests:use() @@ -23,8 +21,9 @@ function ObjCommonTests:name() end function ObjCommonTests:project() - References:reset() - local folder = TestFolder(); + local folder = TestFolder() + local includes = Includes:create() + local links = Links:create() project(self:name()) targetdir(TargetDirectoryTest) @@ -44,9 +43,10 @@ function ObjCommonTests:project() } } - self:include() - ObjCommon:include() - catch2:include() + self:include(includes) + ObjCommon:include(includes) + catch2:include(includes) - ObjCommon:link() + links:linkto(ObjCommon) + links:linkall() end diff --git a/test/ZoneCodeGeneratorLibTests.lua b/test/ZoneCodeGeneratorLibTests.lua index 9c84d1bc..f9a3a548 100644 --- a/test/ZoneCodeGeneratorLibTests.lua +++ b/test/ZoneCodeGeneratorLibTests.lua @@ -1,17 +1,15 @@ ZoneCodeGeneratorLibTests = {} -function ZoneCodeGeneratorLibTests:include() - if References:include(self:name()) then +function ZoneCodeGeneratorLibTests:include(includes) + if includes:handle(self:name()) then includedirs { path.join(TestFolder(), "ZoneCodeGeneratorLibTests") } end end -function ZoneCodeGeneratorLibTests:link() - if References:link(self:name()) then - links(self:name()) - end +function ZoneCodeGeneratorLibTests:link(links) + end function ZoneCodeGeneratorLibTests:use() @@ -23,8 +21,9 @@ function ZoneCodeGeneratorLibTests:name() end function ZoneCodeGeneratorLibTests:project() - References:reset() - local folder = TestFolder(); + local folder = TestFolder() + local includes = Includes:create() + local links = Links:create() project(self:name()) targetdir(TargetDirectoryTest) @@ -43,9 +42,10 @@ function ZoneCodeGeneratorLibTests:project() } } - self:include() - ZoneCodeGeneratorLib:include() - catch2:include() + self:include(includes) + ZoneCodeGeneratorLib:include(includes) + catch2:include(includes) - ZoneCodeGeneratorLib:link() + links:linkto(ZoneCodeGeneratorLib) + links:linkall() end diff --git a/test/ZoneCommonTests.lua b/test/ZoneCommonTests.lua index 146d8ccf..f256dcc5 100644 --- a/test/ZoneCommonTests.lua +++ b/test/ZoneCommonTests.lua @@ -1,17 +1,15 @@ ZoneCommonTests = {} -function ZoneCommonTests:include() - if References:include(self:name()) then +function ZoneCommonTests:include(includes) + if includes:handle(self:name()) then includedirs { path.join(TestFolder(), "ZoneCommonTests") } end end -function ZoneCommonTests:link() - if References:link(self:name()) then - links(self:name()) - end +function ZoneCommonTests:link(links) + end function ZoneCommonTests:use() @@ -23,8 +21,9 @@ function ZoneCommonTests:name() end function ZoneCommonTests:project() - References:reset() - local folder = TestFolder(); + local folder = TestFolder() + local includes = Includes:create() + local links = Links:create() project(self:name()) targetdir(TargetDirectoryTest) @@ -45,11 +44,12 @@ function ZoneCommonTests:project() } } - self:include() - ZoneCommon:include() - catch2:include() + self:include(includes) + ZoneCommon:include(includes) + catch2:include(includes) - ZoneCommon:link() + links:linkto(ZoneCommon) + links:linkall() ZoneCode:use() end diff --git a/thirdparty/catch2.lua b/thirdparty/catch2.lua index 61a90ea2..254a024d 100644 --- a/thirdparty/catch2.lua +++ b/thirdparty/catch2.lua @@ -1,7 +1,7 @@ catch2 = {} -function catch2:include() - if References:include(self:name()) then +function catch2:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ThirdPartyFolder(), "catch2", "single_include") } @@ -20,5 +20,4 @@ function catch2:name() end function catch2:project() - References:reset() end diff --git a/thirdparty/libtomcrypt.lua b/thirdparty/libtomcrypt.lua index 749878ec..9b6d8306 100644 --- a/thirdparty/libtomcrypt.lua +++ b/thirdparty/libtomcrypt.lua @@ -1,7 +1,7 @@ libtomcrypt = {} -function libtomcrypt:include() - if References:include("libtomcrypt") then +function libtomcrypt:include(includes) + if includes:handle(self:name()) then defines{ "LTM_DESC" } @@ -12,21 +12,24 @@ function libtomcrypt:include() end end -function libtomcrypt:link() - if References:link("libtomcrypt") then - links "libtomcrypt" - end +function libtomcrypt:link(links) + links:add(self:name()) + links:linkto(libtommath) end function libtomcrypt:use() end -function libtomcrypt:project() - References:reset() - local folder = ThirdPartyFolder(); +function libtomcrypt:name() + return "libtomcrypt" +end - project "libtomcrypt" +function libtomcrypt:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -45,8 +48,8 @@ function libtomcrypt:project() "LTC_NO_PROTOTYPES" } - self:include() - libtommath:include() + self:include(includes) + libtommath:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/thirdparty/libtommath.lua b/thirdparty/libtommath.lua index 1d50d07c..dc3189c5 100644 --- a/thirdparty/libtommath.lua +++ b/thirdparty/libtommath.lua @@ -1,28 +1,30 @@ libtommath = {} -function libtommath:include() - if References:include("libtommath") then +function libtommath:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ThirdPartyFolder(), "libtommath") } end end -function libtommath:link() - if References:link("libtommath") then - links "libtommath" - end +function libtommath:link(links) + links:add(self:name()) end function libtommath:use() end -function libtommath:project() - References:reset() - local folder = ThirdPartyFolder(); +function libtommath:name() + return "libtommath" +end - project "libtommath" +function libtommath:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -33,7 +35,7 @@ function libtommath:project() path.join(folder, "libtommath/*.c") } - self:include() + self:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/thirdparty/minilzo.lua b/thirdparty/minilzo.lua index 2b5f434b..958166aa 100644 --- a/thirdparty/minilzo.lua +++ b/thirdparty/minilzo.lua @@ -1,28 +1,30 @@ minilzo = {} -function minilzo:include() - if References:include("minilzo") then +function minilzo:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ThirdPartyFolder(), "minilzo") } end end -function minilzo:link() - if References:link("minilzo") then - links "minilzo" - end +function minilzo:link(links) + links:add(self:name()) end function minilzo:use() end -function minilzo:project() - References:reset() - local folder = ThirdPartyFolder(); +function minilzo:name() + return "minilzo" +end - project "minilzo" +function minilzo:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -33,7 +35,7 @@ function minilzo:project() path.join(folder, "minilzo/*.c") } - self:include() + self:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/thirdparty/minizip.lua b/thirdparty/minizip.lua index a84f9f3c..f6e451c0 100644 --- a/thirdparty/minizip.lua +++ b/thirdparty/minizip.lua @@ -1,30 +1,32 @@ minizip = {} -function minizip:include() - if References:include("minizip") then - zlib:include() +function minizip:include(includes) + if includes:handle(self:name()) then + zlib:include(includes) includedirs { path.join(ThirdPartyFolder(), "zlib/contrib/minizip") } end end -function minizip:link() - if References:link("minizip") then - zlib:link() - links "minizip" - end +function minizip:link(links) + links:add(self:name()) + links:linkto(zlib) end function minizip:use() end -function minizip:project() - References:reset() - local folder = ThirdPartyFolder(); +function minizip:name() + return "minizip" +end - project "minizip" +function minizip:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -40,7 +42,7 @@ function minizip:project() path.join(folder, "zlib/contrib/minizip/crypt.h"), } - self:include() + self:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/thirdparty/salsa20.lua b/thirdparty/salsa20.lua index 0db3d7c2..795c2e0e 100644 --- a/thirdparty/salsa20.lua +++ b/thirdparty/salsa20.lua @@ -1,28 +1,30 @@ salsa20 = {} -function salsa20:include() - if References:include("salsa20") then +function salsa20:include(includes) + if includes:handle(self:name()) then includedirs { path.join(ThirdPartyFolder(), "salsa20") } end end -function salsa20:link() - if References:link("salsa20") then - links "salsa20" - end +function salsa20:link(links) + links:add(self:name()) end function salsa20:use() end -function salsa20:project() - References:reset() - local folder = ThirdPartyFolder(); +function salsa20:name() + return "salsa20" +end - project "salsa20" +function salsa20:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -33,7 +35,7 @@ function salsa20:project() path.join(folder, "salsa20/*.c") } - self:include() + self:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/thirdparty/zlib.lua b/thirdparty/zlib.lua index acd4fd6e..80687169 100644 --- a/thirdparty/zlib.lua +++ b/thirdparty/zlib.lua @@ -1,7 +1,7 @@ zlib = {} -function zlib:include() - if References:include("zlib") then +function zlib:include(includes) + if includes:handle(self:name()) then defines { "ZLIB_CONST" } @@ -12,21 +12,23 @@ function zlib:include() end end -function zlib:link() - if References:link("zlib") then - links "zlib" - end +function zlib:link(links) + links:add(self:name()) end function zlib:use() end -function zlib:project() - References:reset() - local folder = ThirdPartyFolder(); +function zlib:name() + return "zlib" +end - project "zlib" +function zlib:project() + local folder = ThirdPartyFolder() + local includes = Includes:create() + + project(self:name()) targetdir(TargetDirectoryLib) location "%{wks.location}/thirdparty/%{prj.name}" kind "StaticLib" @@ -42,7 +44,7 @@ function zlib:project() "_CRT_NONSTDC_NO_DEPRECATE" } - self:include() + self:include(includes) -- Disable warnings. They do not have any value to us since it is not our code. warnings "off" diff --git a/tools/scripts/folders.lua b/tools/scripts/folders.lua new file mode 100644 index 00000000..e6bad73a --- /dev/null +++ b/tools/scripts/folders.lua @@ -0,0 +1,25 @@ +-- Functions for locating commonly used folders +local _BuildFolder = path.getabsolute("../../build") +function BuildFolder() + return path.getrelative(os.getcwd(), _BuildFolder) +end + +local _ThirdPartyFolder = path.getabsolute("../../thirdparty") +function ThirdPartyFolder() + return path.getrelative(os.getcwd(), _ThirdPartyFolder) +end + +local _ProjectFolder = path.getabsolute("../../src") +function ProjectFolder() + return path.getrelative(os.getcwd(), _ProjectFolder) +end + +local _TestFolder = path.getabsolute("../../test") +function TestFolder() + return path.getrelative(os.getcwd(), _TestFolder) +end + +-- Target Directories +TargetDirectoryBin = "%{wks.location}/bin/%{cfg.buildcfg}_%{cfg.platform}" +TargetDirectoryLib = "%{wks.location}/lib/%{cfg.buildcfg}_%{cfg.platform}" +TargetDirectoryTest = "%{wks.location}/lib/%{cfg.buildcfg}_%{cfg.platform}/tests" \ No newline at end of file diff --git a/tools/scripts/including.lua b/tools/scripts/including.lua new file mode 100644 index 00000000..e26e0883 --- /dev/null +++ b/tools/scripts/including.lua @@ -0,0 +1,20 @@ +-- Functions for including projects +Includes = {} + +function Includes:create() + + list = { + handles = {} + } + + function list:handle(name) + if self.handles[name] == nil then + self.handles[name] = true + return true + end + + return false + end + + return list +end \ No newline at end of file diff --git a/tools/scripts/linking.lua b/tools/scripts/linking.lua new file mode 100644 index 00000000..4d59b585 --- /dev/null +++ b/tools/scripts/linking.lua @@ -0,0 +1,48 @@ +-- Functions for linking projects +Links = {} + +function Links:create() + + list = { + stack = {}, + dependencies = {} + } + + function list:linkto(project) + local projectName = project:name() + for i, dependency in ipairs(self.stack) do + if dependency == projectName then + print "Circular dependency detected:" + local dependencyList = projectName + for j = i + 1, #self.stack do + dependencyList = dependencyList .. " -> " .. self.stack[j] + end + dependencyList = dependencyList .. " -> " .. projectName + print(dependencyList) + os.exit(1) + end + end + + table.insert(self.stack, projectName) + project:link(self) + table.remove(self.stack) + end + + function list:add(name) + for i = 1, #self.dependencies do + if self.dependencies[i] == name then + table.remove(self.dependencies, i) + i = i - 1 + end + end + table.insert(self.dependencies, name) + end + + function list:linkall() + for i, dependency in ipairs(self.dependencies) do + links(dependency) + end + end + + return list +end \ No newline at end of file diff --git a/tools/scripts/options.lua b/tools/scripts/options.lua new file mode 100644 index 00000000..e69de29b diff --git a/tools/scripts/platform.lua b/tools/scripts/platform.lua new file mode 100644 index 00000000..f792109c --- /dev/null +++ b/tools/scripts/platform.lua @@ -0,0 +1,8 @@ +-- Platform functions +function ExecutableByOs(name) + if os.host() == "windows" then + return name .. ".exe" + else + return name + end +end \ No newline at end of file