Selaa lähdekoodia

Initial commit

Eiyeron Fulmincendii 5 vuotta sitten
commit
3b7dba9787
7 muutettua tiedostoa jossa 421 lisäystä ja 0 poistoa
  1. 1 0
      .gitignore
  2. 76 0
      README.md
  3. 1 0
      extern/.gitignore
  4. 191 0
      prelude/init.lua
  5. 47 0
      prelude/libraries/physfs.lua
  6. 73 0
      prelude/libraries/portaudio.lua
  7. 32 0
      premake5.lua

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+build

+ 76 - 0
README.md

@@ -0,0 +1,76 @@
+# Proto Factory
+
+An attempt at making a project starter to stop being stuck at this step.
+
+## Rationale
+
+I'm currently being stuck at this step in many of my current projects. By trying
+to make a proper starter kit, I'm trying to unblock myself from this blank sheet
+block.
+
+- Q: *Will there be the [abc] library?* A: Only if I'm going to use it.
+- Q: *Will the libraries be supported* A: Not actively, but I'll try to bump up
+  the setups if I'm working on a downstream project.
+- Q: *Isn't it overkill?* A: Definitely so. All my projects are falling in that
+  overkill domain. This one isn't an exception.
+
+## Pre-requisites
+
+You will need [premake5][premake], your favorite toolchain and eventually
+download the libraries you'll want to use.
+
+## Project structure
+
+The base structure is composed of two projects : core and main. Most of the
+projects I have seen have a base library for common operations and algorithm.
+The name will vary on them but for personal reasons, I'm going to stick with
+"core".
+
+Ultimately, when you're not going to make plenty of libraries to split the
+codebase into reusable parts, core can act like a common ground between multiple
+libraries or executables in the same workspace. That's how I envision its usage.
+
+## Modules
+
+Somes libraries are vaguely ready-to-use by including the proper module file
+from the prelude folder and using them as dependencies in your project
+configuration.
+
+This structure is currently optimized for source-based libraries. Already built
+libraries aren't supported yet nor are system libraries.
+
+Here's a minimal example of how a library can be easily included
+once it has its own module.
+
+```lua
+-- ...
+local prelude = require "prelude"
+local portaudio = require "prelude.libraries.portaudio"
+-- ...
+
+workspace "yourproject"
+    -- ...
+    portaduio:use "SharedLib"
+    -- ...
+    
+    project "Main project"
+        -- ...
+        prelude.link_against_modules {portaudio}
+        -- ...
+```
+
+The current module format allows not only to pass to depending projects the
+public include folders but also pass along defines or platform-specific
+configuration when needed. It required a bit of repetitive boilerplate, but
+that'd be an excellent candidate for magic-based refactoring.
+
+## Current managed libraries
+
+- PortAudio : because I have plans around generating live audio
+  - Clone the git repo into `external/portaudio`
+- PhysicsFS : the ready-toè-use library to easily abstract filesystems
+  - Unzip the tarball into `external/physfs`
+
+Obviously, more are going to come
+
+[premake]:https://github.com/premake/premake-core

+ 1 - 0
extern/.gitignore

@@ -0,0 +1 @@
+build/

+ 191 - 0
prelude/init.lua

@@ -0,0 +1,191 @@
+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
+}

+ 47 - 0
prelude/libraries/physfs.lua

@@ -0,0 +1,47 @@
+local prelude = require "prelude"
+
+local physfs = prelude.library_module("PhysFS", "physfs")
+
+-- Common
+
+:use_files {
+	"src/physfs.c",
+	"src/physfs.h",
+	"src/physfs_archiver_7z.c",
+	"src/physfs_archiver_dir.c",
+	"src/physfs_archiver_grp.c",
+	"src/physfs_archiver_hog.c",
+	"src/physfs_archiver_iso9660.c",
+	"src/physfs_archiver_mvl.c",
+	"src/physfs_archiver_qpak.c",
+	"src/physfs_archiver_slb.c",
+	"src/physfs_archiver_unpacked.c",
+	"src/physfs_archiver_vdf.c",
+	"src/physfs_archiver_wad.c",
+	"src/physfs_archiver_zip.c",
+	"src/physfs_byteorder.c",
+	"src/physfs_unicode.c"
+}
+
+:use_public_includes {
+    "src",
+}
+
+-- Linux
+
+:use_linux_files {
+	"src/physfs_platform_posix.c",
+	"src/physfs_platform_unix.c"
+}
+
+-- Windows
+
+:use_win_files {
+	"src/physfs_platform_windows.c"
+}
+
+physfs._VERSION = "0.0.1"
+physfs._LIBRARY_VERSION = "3.0.2"
+physfs._NAME = "PhysicsFS"
+
+return physfs

+ 73 - 0
prelude/libraries/portaudio.lua

@@ -0,0 +1,73 @@
+local prelude = require "prelude"
+
+local portaudio = prelude.library_module("PortAudio", "portaudio")
+
+-- Common
+
+portaudio:use_files {
+    "include/**.h", 
+    "src/common/**.c",
+}
+
+:use_public_includes {
+    "include",
+}
+:use_private_includes {
+    "src/common",
+}
+
+-- Linux
+
+portaudio:use_linux_defines {
+    "PA_USE_ALSA=1"
+}
+
+:use_linux_files {
+    "src/hostapi/alsa/**.c",
+    "src/os/unix/**.c",
+}
+
+:use_linux_private_includes {
+    "src/hostapi/alsa",
+    "src/os/unix"
+}
+
+:use_linux_links {
+	"rt",
+	"asound",
+	"m",
+	"pthread",
+}
+
+-- Windows
+
+portaudio:use_win_defines {
+    -- Windows-only settings
+    "PA_USE_WMME=0",
+    "PA_USE_WASAPI=1",
+    "PA_USE_DS=1",
+    "PA_USE_WDMKS=1",
+    "PA_USE_ASIO=0"
+}
+
+:use_win_files {
+    "src/hostapi/dsound/**.c",
+    "src/hostapi/wasapi/**.c",
+    "src/hostapi/wdmks/**.c",
+    "src/os/win/**.c",
+    "build/msvc/*.def"
+}
+
+:use_win_private_includes {
+    "src/hostapi/dsound",
+    "src/hostapi/wasapi",
+    "src/hostapi/wdmks/**.c",
+    "src/os/win"
+}
+
+
+portaudio._VERSION = "0.0.1"
+portaudio._LIBRARY_VERSION = "git"
+portaudio._NAME = "PortAudio"
+
+return portaudio

+ 32 - 0
premake5.lua

@@ -0,0 +1,32 @@
+local prelude = require "prelude"
+local portaudio = require "prelude.libraries.portaudio"
+local physfs = require "prelude.libraries.physfs"
+
+
+workspace "Your Project here"
+    configurations {"Debug", "DebugOpt", "Release"}
+    location "build"
+
+    portaudio:use "SharedLib"
+    physfs:use "SharedLib"
+
+    -- I'll also try to have a common core system to factorize some programming
+    -- elements together.
+    project "Core"
+        kind "StaticLib"
+        files {"include/core/**.hpp", "src/core/**.cpp"}
+        includedirs {""}
+
+    project "Main"
+        cppdialect "C++17"
+        kind "ConsoleApp"
+        files {"include/main/**.hpp", "src/main/**.cpp"}
+        includedirs {"include"}
+        links {"Core"}
+		
+		-- TODO : issues at link on VS2015. Does it happen at home?
+		-- Need to manually check "Link Library Dependencies" every time.
+		prelude.link_against_modules {portaudio, physfs}
+
+        prelude.base_project_settings()
+