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 -- configuration 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_workspace_settings() language "C++" configurations {"Debug", "DebugOpt", "Release"} location "build" architecture "x86_64" filter "configurations:Debug" defines {"DEBUG"} symbols "On" warnings "Extra" filter "configurations:DebugOpt" defines {"DEBUG"} symbols "On" optimize "Debug" warnings "Extra" filter "configurations:Release" defines {"NDEBUG"} optimize "On" warnings "Extra" filter {} 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 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) -- TODO: handle dependencies project(self.name) kind(use_kind) defines(self.defines) files(self.files) includedirs(self.public_includes) includedirs(self.private_includes) links(self.links) 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) filter {} end return mod end return { _VERSION = "0.0.1", base_workspace_settings = base_workspace_settings, library_module = library_module, link_against_modules = link_against_modules }