| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- local library_base_folders = "extern/"
- local function extern_path(local_path)
- if local_path:sub(1,1) == '/' then
- -- TODO : Windows absolute path check
- print(([[[WARN] "%s" is not a local path.]]):format(local_path))
- local_path = local_path:sub(2)
- end
- return library_base_folders .. local_path
- end
- --- Common function I use to structure projects according to the three-stage
- -- project pattern I usually see : Debug, optimized Debug and Release.
- -- Sometimes I see also a Final version, but it almost is a copy of the Release
- -- stage.
- local function base_project_settings()
- -- I commonly use modern C++ nowadays.
- language "C++"
- configuration "Debug"
- defines {"DEBUG"}
- symbols "On"
- warnings "Extra"
- configuration "DebugOpt"
- defines {"DEBUG"}
- symbols "On"
- optimize "Debug"
- warnings "Extra"
- configuration "Release"
- defines {"NDEBUG"}
- optimize "On"
- warnings "Extra"
- end
- local function link_against_modules(modules)
- for _, mod in pairs(modules) do
- links(mod.name)
- end
- for _, mod in pairs(modules) do
- includedirs(mod.public_includes)
- end
- -- TODO system filters
- end
- --- An attempt at making a common ground for multiple libraries I'd use
- -- in various projects.
- local function library_module(lib_name, folder)
- local mod = {
- name = lib_name,
- folder = folder or lib_name,
- links = {},
- win_links = {},
- linux_links = {},
- files = {},
- win_files = {},
- linux_files = {},
- defines = {},
- win_defines = {},
- linux_defines = {},
-
- -- Separating private/public includes helps
- -- to reuse the public when needed.
- private_includes = {},
- win_private_includes = {},
- linux_private_includes = {},
- public_includes = {},
- module_dependencies = {}
- }
- function mod:_convert_and_store_path(destination, paths)
- local path_prefix = library_base_folders .. self.folder .. "/"
- for k, path in pairs(paths) do
- table.insert(destination, path_prefix .. path)
- end
- end
- function mod:use_private_includes(local_private_paths)
- self:_convert_and_store_path(self.private_includes, local_private_paths)
- return self
- end
- function mod:use_win_private_includes(local_win_private_paths)
- self:_convert_and_store_path(self.win_private_includes, local_win_private_paths)
- return self
- end
- function mod:use_linux_private_includes(local_linux_private_paths)
- self:_convert_and_store_path(self.linux_private_includes, local_linux_private_paths)
- return self
- end
- function mod:use_public_includes(local_public_paths)
- self:_convert_and_store_path(self.public_includes, local_public_paths)
- return self
- end
- function mod:use_files(local_file_paths)
- self:_convert_and_store_path(self.files, local_file_paths)
- return self
- end
- function mod:use_win_files(local_file_paths)
- self:_convert_and_store_path(self.win_files, local_file_paths)
- return self
- end
- function mod:use_linux_files(local_file_paths)
- self:_convert_and_store_path(self.linux_files, local_file_paths)
- return self
- end
- function mod:use_defines(defines)
- self.defines = defines
- return self
- end
- function mod:use_win_defines(defines)
- self.win_defines = defines
- return self
- end
- function mod:use_linux_defines(defines)
- self.linux_defines = defines
- return self
- end
- function mod:require_module(module)
- self.module_dependencies:insert(module)
- end
- function mod:use_links(links)
- self.links = links
- return self
- end
- function mod:use_win_links(links)
- self.win_links = links
- return self
- end
- function mod:use_linux_links(links)
- self.linux_links = links
- return self
- end
- --- Calls premake's code to add the module's project to the current
- -- workspace.
- function mod:use(use_kind)
- project(self.name)
- kind(use_kind)
- -- TODO : kind
- defines(self.defines)
- files(self.files)
- includedirs(self.public_includes)
- includedirs(self.private_includes)
- links(self.links)
- base_project_settings()
- filter "system:windows"
- defines(self.win_defines)
- files(self.win_files)
- includedirs(self.win_private_includes)
- links(self.win_links)
-
- filter "system:linux"
- defines(self.linux_defines)
- files(self.linux_files)
- includedirs(self.linux_private_includes)
- links(self.linux_links)
- end
- return mod
- end
- return {
- _VERSION = "0.0.1",
- base_project_settings = base_project_settings,
- library_module = library_module,
- link_against_modules = link_against_modules
- }
|