Premake: Split up dependencies, make them easily configurable and provide easy-to-use imports.

All dependency projects are now separated into their own Premake scripts and are designed to provide easy "import", "includes" and "setup" functions.

First, you use project.setup { ... } to provide the library with its respective configuration, this MAY include defines and MUST include the source path of that specific library. Then you can use project.includes() or project.import() in your target application or library project to let the script configure your project. This will configure all necessary include directories and links.
This commit is contained in:
/dev/urandom 2016-08-13 19:24:02 +02:00
parent 6dfd22c07a
commit 7ff05580c9
No known key found for this signature in database
GPG Key ID: 41322B973E0F295E
11 changed files with 541 additions and 213 deletions

44
premake/fmt.lua Normal file
View File

@ -0,0 +1,44 @@
fmt = {
settings = nil
}
function fmt.setup(settings)
if not settings.source then error("Missing source.") end
fmt.settings = settings
end
function fmt.import()
if not fmt.settings then error("Run fmt.setup first") end
links { "fmt" }
fmt.includes()
end
function fmt.includes()
if not fmt.settings then error("Run fmt.setup first") end
includedirs { fmt.settings.source }
end
function fmt.project()
if not fmt.settings then error("Run fmt.setup first") end
project "fmt"
language "C++"
fmt.includes()
files
{
path.join(fmt.settings.source, "fmt/*.cc"),
path.join(fmt.settings.source, "fmt/*.h"),
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
defines { "_LIB" }
removedefines { "_USRDLL", "_DLL" }
kind "StaticLib"
end

51
premake/json11.lua Normal file
View File

@ -0,0 +1,51 @@
json11 = {
settings = nil,
}
function json11.setup(settings)
if not settings.source then error("Missing source.") end
json11.settings = settings
end
function json11.import()
if not json11.settings then error("Run json11.setup first") end
links { "json11" }
json11.includes()
end
function json11.includes()
if not json11.settings then error("Run json11.setup first") end
includedirs { json11.settings.source }
end
function json11.project()
if not json11.settings then error("Run json11.setup first") end
project "json11"
language "C++"
includedirs
{
json11.settings.source,
}
files
{
path.join(json11.settings.source, "*.cpp"),
path.join(json11.settings.source, "*.hpp"),
}
removefiles
{
path.join(json11.settings.source, "test*"),
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
defines { "_LIB" }
removedefines { "_USRDLL", "_DLL" }
kind "StaticLib"
end

61
premake/libtomcrypt.lua Normal file
View File

@ -0,0 +1,61 @@
libtomcrypt = {
settings = nil
}
function libtomcrypt.setup(settings)
if not settings.source then error("Missing source") end
libtomcrypt.settings = settings
if not libtomcrypt.settings.defines then libtomcrypt.settings.defines = {} end
end
function libtomcrypt.import()
if not libtomcrypt.settings then error("Run libtomcrypt.setup first") end
links { "libtomcrypt" }
libtomcrypt.includes()
end
function libtomcrypt.includes()
if not libtomcrypt.settings then error("Run libtomcrypt.setup first") end
defines(libtomcrypt.settings.defines)
includedirs { path.join(libtomcrypt.settings.source, "src/headers") }
end
function libtomcrypt.project()
if not libtomcrypt.settings then error("Run libtomcrypt.setup first") end
project "libtomcrypt"
language "C"
libtomcrypt.includes()
files
{
path.join(libtomcrypt.settings.source, "src/**.c"),
}
removefiles
{
path.join(libtomcrypt.settings.source, "src/**/*tab.c"), -- included by files as necessary already afaik
path.join(libtomcrypt.settings.source, "src/encauth/ocb3/**.c"), -- fails in Visual Studio with invalid syntax
}
defines
{
"_CRT_SECURE_NO_WARNINGS",
"LTC_SOURCE", -- we are compiling from source code
}
-- dependencies
if libtommath and libtommath.settings then
defines { "USE_LTM" }
libtommath.import()
end
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
defines { "_LIB" }
removedefines { "_DLL", "_USRDLL" }
kind "StaticLib"
end

48
premake/libtommath.lua Normal file
View File

@ -0,0 +1,48 @@
libtommath = {
settings = nil
}
function libtommath.setup(settings)
if not settings.source then error("Missing source") end
libtommath.settings = settings
if not libtommath.settings.defines then libtommath.settings.defines = {} end
end
function libtommath.import()
if not libtommath.settings then error("Run libtommath.setup first") end
links { "libtommath" }
libtommath.includes()
end
function libtommath.includes()
if not libtommath.settings then error("Run libtommath.setup first") end
defines(libtommath.settings.defines)
includedirs { libtommath.settings.source }
end
function libtommath.project()
if not libtommath.settings then error("Run libtommath.setup first") end
project "libtommath"
language "C"
libtommath.includes()
files
{
path.join(libtommath.settings.source, "*.c"),
}
-- dependencies
libtommath.import()
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
defines { "_LIB" }
removedefines { "_DLL", "_USRDLL" }
kind "StaticLib"
end

42
premake/mongoose.lua Normal file
View File

@ -0,0 +1,42 @@
mongoose = {
settings = nil,
}
function mongoose.setup(settings)
if not settings.source then error("Missing source.") end
mongoose.settings = settings
end
function mongoose.import()
if not mongoose.settings then error("Run mongoose.setup first") end
links { "mongoose" }
mongoose.includes()
end
function mongoose.includes()
if not mongoose.settings then error("Run mongoose.setup first") end
includedirs { mongoose.settings.source }
end
function mongoose.project()
if not mongoose.settings then error("Run mongoose.setup first") end
project "mongoose"
language "C"
mongoose.includes()
files
{
path.join(mongoose.settings.source, "*.c"),
path.join(mongoose.settings.source, "*.h"),
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as mongoose doesn't export anything
kind "StaticLib"
end

48
premake/pdcurses.lua Normal file
View File

@ -0,0 +1,48 @@
pdcurses = {
settings = nil,
}
function pdcurses.setup(settings)
if not settings.source then error("Missing source.") end
pdcurses.settings = settings
end
function pdcurses.import()
if not pdcurses.settings then error("Run pdcurses.setup first") end
links { "pdcurses" }
pdcurses.includes()
end
function pdcurses.includes()
if not pdcurses.settings then error("Run pdcurses.setup first") end
includedirs { pdcurses.settings.source }
end
function pdcurses.project()
if not pdcurses.settings then error("Run pdcurses.setup first") end
project "pdcurses"
language "C"
includedirs
{
pdcurses.settings.source,
}
files
{
path.join(pdcurses.settings.source, "pdcurses/*.c"),
path.join(pdcurses.settings.source, "pdcurses/*.h"),
path.join(pdcurses.settings.source, "win32/*.c"),
path.join(pdcurses.settings.source, "win32/*.h"),
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as pdcurses doesn't export anything
kind "StaticLib"
end

63
premake/protobuf.lua Normal file
View File

@ -0,0 +1,63 @@
protobuf = {
settings = nil,
}
function protobuf.setup(settings)
if not settings.source then error("Missing source.") end
protobuf.settings = settings
end
function protobuf.import()
if not protobuf.settings then error("Run protobuf.setup first") end
links { "protobuf" }
protobuf.includes()
end
function protobuf.includes()
if not protobuf.settings then error("Run protobuf.setup first") end
includedirs
{
path.join(protobuf.settings.source, "src"),
}
end
function protobuf.project()
if not protobuf.settings then error("Run protobuf.setup first") end
project "protobuf"
language "C++"
includedirs
{
path.join(protobuf.settings.source, "src"),
}
files
{
path.join(protobuf.settings.source, "src/**.cc"),
}
removefiles
{
path.join(protobuf.settings.source, "src/**/*test.cc"),
path.join(protobuf.settings.source, "src/google/protobuf/*test*.cc"),
path.join(protobuf.settings.source, "src/google/protobuf/testing/**.cc"),
path.join(protobuf.settings.source, "src/google/protobuf/compiler/**.cc"),
path.join(protobuf.settings.source, "src/google/protobuf/arena_nc.cc"),
path.join(protobuf.settings.source, "src/google/protobuf/util/internal/error_listener.cc"),
path.join(protobuf.settings.source, "**/*_gcc.cc"),
}
-- dependencies
zlib.import()
-- not our code, ignore POSIX usage warnings for now
defines { "_SCL_SECURE_NO_WARNINGS" }
warnings "Off"
-- always build as static lib, as we include our custom classes and therefore can't perform shared linking
kind "StaticLib"
end

27
premake/winksignals.lua Normal file
View File

@ -0,0 +1,27 @@
winksignals = {
settings = nil,
}
function winksignals.setup(settings)
if not settings.source then error("Missing source.") end
winksignals.settings = settings
end
function winksignals.import()
if not winksignals.settings then error("Run winksignals.setup first") end
winksignals.includes()
end
function winksignals.includes()
if not winksignals.settings then error("Run winksignals.setup first") end
includedirs { winksignals.settings.source }
end
function winksignals.project()
if not winksignals.settings then error("Run winksignals.setup first") end
-- Wink-Signals is header-only, so no project files needed for this
end

53
premake/zlib.lua Normal file
View File

@ -0,0 +1,53 @@
zlib = {
settings = nil
}
function zlib.setup(settings)
if not settings.source then error("Missing source.") end
zlib.settings = settings
if not zlib.settings.defines then zlib.settings.defines = {} end
end
function zlib.import()
if not zlib.settings then error("You need to call zlib.setup first") end
links { "zlib" }
zlib.includes()
end
function zlib.includes()
if not zlib.settings then error("You need to call zlib.setup first") end
includedirs { zlib.settings.source }
defines(zlib.settings.defines)
end
function zlib.project()
if not zlib.settings then error("You need to call zlib.setup first") end
project "zlib"
language "C"
zlib.includes()
files
{
path.join(zlib.settings.source, "*.h"),
path.join(zlib.settings.source, "*.c"),
}
defines
{
"ZLIB_DLL",
"_CRT_SECURE_NO_DEPRECATE",
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
kind "SharedLib"
configuration "*Static"
defines { "_LIB" }
removedefines { "_USRDLL", "_DLL", "ZLIB_DLL" }
kind "StaticLib"
end

View File

@ -105,6 +105,66 @@ newaction {
end
}
depsBasePath = "./deps"
require "premake/fmt"
require "premake/json11"
require "premake/libtomcrypt"
require "premake/libtommath"
require "premake/mongoose"
require "premake/pdcurses"
require "premake/protobuf"
require "premake/winksignals"
require "premake/zlib"
fmt.setup
{
source = path.join(depsBasePath, "fmt"),
}
json11.setup
{
source = path.join(depsBasePath, "json11"),
}
libtomcrypt.setup
{
defines = {
"LTC_NO_FAST",
"LTC_NO_PROTOTYPES",
"LTC_NO_RSA_BLINDING",
},
source = path.join(depsBasePath, "libtomcrypt"),
}
libtommath.setup
{
defines = {
"LTM_DESC",
},
source = path.join(depsBasePath, "libtommath"),
}
mongoose.setup
{
source = path.join(depsBasePath, "mongoose"),
}
pdcurses.setup
{
source = path.join(depsBasePath, "pdcurses"),
}
protobuf.setup
{
source = path.join(depsBasePath, "protobuf"),
}
winksignals.setup
{
source = path.join(depsBasePath, "Wink-Signals"),
}
zlib.setup
{
defines = {
"ZLIB_CONST",
},
source = path.join(depsBasePath, "zlib"),
}
workspace "iw4x"
location "./build"
objdir "%{wks.location}/obj"
@ -164,38 +224,20 @@ workspace "iw4x"
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
pchsource "src/STDInclude.cpp" -- real path
buildoptions { "/Zm200" }
filter "files:**.pb.*"
flags {
"NoPCH",
}
buildoptions {
"/wd4100", -- "Unused formal parameter"
"/wd4389", -- "Signed/Unsigned mismatch"
"/wd6011", -- "Dereferencing NULL pointer"
"/wd4125", -- "Decimal digit terminates octal escape sequence"
}
defines {
"_SCL_SECURE_NO_WARNINGS",
}
filter {}
-- Dependency libraries
links { "zlib", "fmt", "json11", "pdcurses", "libtomcrypt", "libtommath", "protobuf", "mongoose" }
includedirs
{
"./deps/fmt",
"./deps/zlib",
"./deps/json11",
"./deps/pdcurses",
"./deps/mongoose",
"./deps/libtomcrypt/src/headers",
"./deps/libtommath",
"./deps/protobuf/src",
"./deps/Wink-Signals",
}
fmt.import()
json11.import()
libtomcrypt.import()
libtommath.import()
mongoose.import()
pdcurses.import()
protobuf.import()
winksignals.import()
zlib.import()
-- fix vpaths for protobuf sources
vpaths
vpaths
{
["*"] = { "./src/**" },
["Proto/Generated"] = { "**.pb.*" }, -- meh.
@ -203,7 +245,7 @@ workspace "iw4x"
-- Virtual paths
if not _OPTIONS["no-new-structure"] then
vpaths
vpaths
{
["Headers/*"] = { "./src/**.hpp" },
["Sources/*"] = { "./src/**.cpp" },
@ -213,15 +255,16 @@ workspace "iw4x"
}
end
vpaths {
vpaths
{
["Docs/*"] = { "**.txt","**.md" },
}
-- Pre-build
prebuildcommands
prebuildcommands
{
"cd %{_MAIN_SCRIPT_DIR}",
"tools\\premake5 generate-buildinfo"
"tools\\premake5 generate-buildinfo",
}
-- Post-build
@ -247,191 +290,47 @@ workspace "iw4x"
configuration {}
-- Generate source code from protobuf definitions
filter "files:**.pb.*"
flags {
"NoPCH",
}
buildoptions {
"/wd4100", -- "Unused formal parameter"
"/wd4389", -- "Signed/Unsigned mismatch"
"/wd6011", -- "Dereferencing NULL pointer"
"/wd4125", -- "Decimal digit terminates octal escape sequence"
}
defines {
"_SCL_SECURE_NO_WARNINGS",
}
filter {}
rules { "ProtobufCompiler" }
-- Workaround: Consume protobuf generated source files
matches = os.matchfiles(path.join("src/Proto/**.proto"))
for i, srcPath in ipairs(matches) do
basename = path.getbasename(srcPath)
files
files
{
string.format("%%{prj.location}/src/proto/%s.pb.h", basename),
string.format("%%{prj.location}/src/proto/%s.pb.cc", basename),
}
end
includedirs {
"%{prj.location}/src/proto"
includedirs
{
"%{prj.location}/src/proto",
}
group "External dependencies"
-- zlib
project "zlib"
language "C"
defines { "ZLIB_DLL", "_CRT_SECURE_NO_DEPRECATE" }
files
{
"./deps/zlib/*.h",
"./deps/zlib/*.c"
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
kind "SharedLib"
configuration "*Static"
kind "StaticLib"
removedefines { "ZLIB_DLL" }
-- json11
project "json11"
language "C++"
files
{
"./deps/json11/*.cpp",
"./deps/json11/*.hpp"
}
-- remove dropbox's testing code
removefiles { "./deps/json11/test.cpp" }
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as json11 doesn't export anything
kind "StaticLib"
-- fmt
project "fmt"
language "C++"
includedirs { "./deps/fmt" }
files
{
"./deps/fmt/fmt/*.cc",
"./deps/fmt/fmt/*.h"
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as fmt doesn't export anything
kind "StaticLib"
-- mongoose
project "mongoose"
language "C"
files
{
"./deps/mongoose/*.c",
"./deps/mongoose/*.h"
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as mongoose doesn't export anything
kind "StaticLib"
-- pdcurses
project "pdcurses"
language "C"
includedirs { "./deps/pdcurses/" }
files
{
"./deps/pdcurses/pdcurses/*.c",
"./deps/pdcurses/win32/*.c"
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as pdcurses doesn't export anything
kind "StaticLib"
-- libtomcrypt
project "libtomcrypt"
language "C"
defines { "_LIB", "LTC_SOURCE", "LTC_NO_FAST", "LTC_NO_RSA_BLINDING", "LTM_DESC", "USE_LTM", "WIN32" }
links { "libtommath" }
includedirs { "./deps/libtomcrypt/src/headers" }
includedirs { "./deps/libtommath" }
files { "./deps/libtomcrypt/src/**.c" }
-- seems like tab stuff can be omitted
removefiles { "./deps/libtomcrypt/src/**/*tab.c" }
-- remove incorrect files
-- for some reason, they lack the necessary header files
-- i might have to open a pull request which includes them
removefiles
{
"./deps/libtomcrypt/src/pk/dh/dh_sys.c",
"./deps/libtomcrypt/src/hashes/sha2/sha224.c",
"./deps/libtomcrypt/src/hashes/sha2/sha384.c",
"./deps/libtomcrypt/src/encauth/ocb3/**.c",
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as libtomcrypt doesn't export anything
kind "StaticLib"
-- libtommath
project "libtommath"
language "C"
defines { "_LIB" }
includedirs { "./deps/libtommath" }
files { "./deps/libtommath/*.c" }
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as libtommath doesn't export anything
kind "StaticLib"
-- protobuf
project "protobuf"
language "C++"
links { "zlib" }
defines { "_SCL_SECURE_NO_WARNINGS" }
includedirs
{
"./deps/zlib",
"./deps/protobuf/src",
}
-- default protobuf sources
files { "./deps/protobuf/src/**.cc" }
-- remove unnecessary sources
removefiles
{
"./deps/protobuf/src/**/*test.cc",
"./deps/protobuf/src/google/protobuf/*test*.cc",
"./deps/protobuf/src/google/protobuf/testing/**.cc",
"./deps/protobuf/src/google/protobuf/compiler/**.cc",
"./deps/protobuf/src/google/protobuf/arena_nc.cc",
"./deps/protobuf/src/google/protobuf/util/internal/error_listener.cc",
"./deps/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"
-- always build as static lib, as we include our custom classes and therefore can't perform shared linking
kind "StaticLib"
fmt.project()
json11.project()
libtomcrypt.project()
libtommath.project()
mongoose.project()
pdcurses.project()
winksignals.project()
zlib.project()
protobuf.project()
rule "ProtobufCompiler"
display "Protobuf compiler"

View File

@ -56,14 +56,6 @@
#pragma warning(disable: 6386)
#pragma warning(disable: 6387)
#define ZLIB_CONST
#define USE_LTM
#define LTM_DESC
#define LTC_NO_FAST
#define LTC_NO_PROTOTYPES
#define LTC_NO_RSA_BLINDING
#include <zlib.h>
#include <curses.h>
#include <mongoose.h>