diff --git a/examples/HelloWindow/project.cpp b/examples/HelloWindow/project.cpp new file mode 100644 index 0000000..d1a7a5d --- /dev/null +++ b/examples/HelloWindow/project.cpp @@ -0,0 +1,23 @@ +import std; +import Crafter.Build; +namespace fs = std::filesystem; +using namespace Crafter; + +extern "C" Configuration CrafterBuildProject(std::span args) { + Configuration* graphics = LocalProject({ + .projectFile = "../../project.cpp", + .args = std::vector(args.begin(), args.end()), + }); + + Configuration cfg; + cfg.path = "./"; + cfg.name = "HelloWindow"; + cfg.outputName = "HelloWindow"; + ApplyStandardArgs(cfg, args); + cfg.dependencies = { graphics }; + + std::array ifaces = {}; + std::array impls = { "main" }; + cfg.GetInterfacesAndImplementations(ifaces, impls); + return cfg; +} diff --git a/examples/HelloWindow/project.json b/examples/HelloWindow/project.json deleted file mode 100644 index 976af27..0000000 --- a/examples/HelloWindow/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "crafter-graphics", - "configurations": [ - { - "name": "executable", - "implementations": ["main"], - "dependencies": [ - { - "path":"../../project.json", - "configuration":"lib-wayland-debug" - } - ], - "debug": true - } - ] -} diff --git a/project.cpp b/project.cpp new file mode 100644 index 0000000..014d010 --- /dev/null +++ b/project.cpp @@ -0,0 +1,109 @@ +import std; +import Crafter.Build; +namespace fs = std::filesystem; +using namespace Crafter; + +extern "C" Configuration CrafterBuildProject(std::span args) { + std::vector depArgs(args.begin(), args.end()); + Configuration* event = GitProject({ + .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git" }, + .args = depArgs, + }); + Configuration* math = GitProject({ + .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git" }, + .args = depArgs, + }); + Configuration* asset = GitProject({ + .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git" }, + .args = depArgs, + }); + + Configuration cfg; + cfg.path = "./"; + cfg.name = "Crafter.Graphics"; + cfg.outputName = "Crafter.Graphics"; + cfg.type = ConfigurationType::LibraryStatic; + auto opts = ApplyStandardArgs(cfg, args); + cfg.dependencies = { event, math, asset }; + + // Window backend follows the target triple. V1 had separate lib-wayland / + // lib-win32 configurations; V2 picks the right one automatically based on + // where the build is going. Cross-compile (`--target=...`) flips the + // backend along with everything else. + bool windows = cfg.target.find("windows") != std::string::npos + || cfg.target.find("mingw") != std::string::npos; + if (windows) { + cfg.defines.push_back({"CRAFTER_GRAPHICS_WINDOW_WIN32", ""}); + cfg.linkFlags.push_back("-lkernel32"); + cfg.linkFlags.push_back("-luser32"); + cfg.linkFlags.push_back("-lgdi32"); + } else { + cfg.defines.push_back({"CRAFTER_GRAPHICS_WINDOW_WAYLAND", ""}); + cfg.linkFlags.push_back("-lwayland-client"); + cfg.linkFlags.push_back("-lxkbcommon"); + cfg.cFiles.push_back("lib/xdg-shell-protocol"); + cfg.cFiles.push_back("lib/wayland-xdg-decoration-unstable-v1-client-protocol"); + cfg.cFiles.push_back("lib/fractional-scale-v1"); + cfg.cFiles.push_back("lib/viewporter"); + } + + // Renderer: --vulkan opts in (clones Vulkan-Headers + Vulkan-Utility-Libraries + // for headers and links libvulkan); default is the software path. + if (opts.Has("--vulkan")) { + cfg.defines.push_back({"CRAFTER_GRAPHICS_RENDERER_VULKAN", ""}); + ExternalDependency& vkHeaders = cfg.externalDependencies.emplace_back(); + vkHeaders.name = "Vulkan-Headers"; + vkHeaders.source.url = "https://github.com/KhronosGroup/Vulkan-Headers.git"; + vkHeaders.builder = ExternalBuilder::None; + vkHeaders.includeDirs = { "include" }; + ExternalDependency& vkUtility = cfg.externalDependencies.emplace_back(); + vkUtility.name = "Vulkan-Utility-Libraries"; + vkUtility.source.url = "https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git"; + vkUtility.builder = ExternalBuilder::None; + vkUtility.includeDirs = { "include" }; + cfg.linkFlags.push_back(windows ? "-lvulkan-1" : "-lvulkan"); + } else { + cfg.defines.push_back({"CRAFTER_GRAPHICS_RENDERER_SOFTWARE", ""}); + } + + if (opts.Has("--timing")) cfg.defines.push_back({"CRAFTER_TIMING", ""}); + + std::array ifaces = { + "interfaces/Crafter.Graphics", + "interfaces/Crafter.Graphics-Animation", + "interfaces/Crafter.Graphics-DescriptorHeapVulkan", + "interfaces/Crafter.Graphics-Device", + "interfaces/Crafter.Graphics-Font", + "interfaces/Crafter.Graphics-ForwardDeclarations", + "interfaces/Crafter.Graphics-GridElement", + "interfaces/Crafter.Graphics-ImageVulkan", + "interfaces/Crafter.Graphics-Mesh", + "interfaces/Crafter.Graphics-MouseElement", + "interfaces/Crafter.Graphics-PipelineRTVulkan", + "interfaces/Crafter.Graphics-RenderingElement2D", + "interfaces/Crafter.Graphics-RenderingElement2DBase", + "interfaces/Crafter.Graphics-RenderingElement2DVulkan", + "interfaces/Crafter.Graphics-RenderingElement3D", + "interfaces/Crafter.Graphics-Rendertarget", + "interfaces/Crafter.Graphics-SamplerVulkan", + "interfaces/Crafter.Graphics-ShaderBindingTableVulkan", + "interfaces/Crafter.Graphics-ShaderVulkan", + "interfaces/Crafter.Graphics-Transform2D", + "interfaces/Crafter.Graphics-Types", + "interfaces/Crafter.Graphics-VulkanBuffer", + "interfaces/Crafter.Graphics-VulkanTransition", + "interfaces/Crafter.Graphics-Window", + }; + std::array impls = { + "implementations/Crafter.Graphics-Device", + "implementations/Crafter.Graphics-Font", + "implementations/Crafter.Graphics-Mesh", + "implementations/Crafter.Graphics-MouseElement", + "implementations/Crafter.Graphics-RenderingElement3D", + "implementations/Crafter.Graphics-Transform2D", + "implementations/Crafter.Graphics-Window", + }; + cfg.GetInterfacesAndImplementations(ifaces, impls); + + return cfg; +} diff --git a/project.json b/project.json deleted file mode 100644 index 752dc42..0000000 --- a/project.json +++ /dev/null @@ -1,201 +0,0 @@ -{ - "name": "crafter-graphics", - "configurations": [ - { - "name": "base", - "implementations": [ - "implementations/Crafter.Graphics-Font", - "implementations/Crafter.Graphics-Window", - "implementations/Crafter.Graphics-MouseElement", - "implementations/Crafter.Graphics-Transform2D", - "implementations/Crafter.Graphics-Device", - "implementations/Crafter.Graphics-Mesh", - "implementations/Crafter.Graphics-RenderingElement3D", - "implementations/Crafter.Graphics-Rendertarget" - ], - "interfaces": [ - "interfaces/Crafter.Graphics-Window", - "interfaces/Crafter.Graphics", - "interfaces/Crafter.Graphics-Types", - "interfaces/Crafter.Graphics-Font", - "interfaces/Crafter.Graphics-Animation", - "interfaces/Crafter.Graphics-RenderingElement2D", - "interfaces/Crafter.Graphics-RenderingElement2DBase", - "interfaces/Crafter.Graphics-MouseElement", - "interfaces/Crafter.Graphics-Transform2D", - "interfaces/Crafter.Graphics-GridElement", - "interfaces/Crafter.Graphics-Device", - "interfaces/Crafter.Graphics-VulkanTransition", - "interfaces/Crafter.Graphics-Mesh", - "interfaces/Crafter.Graphics-VulkanBuffer", - "interfaces/Crafter.Graphics-RenderingElement3D", - "interfaces/Crafter.Graphics-ShaderVulkan", - "interfaces/Crafter.Graphics-PipelineRTVulkan", - "interfaces/Crafter.Graphics-ShaderBindingTableVulkan", - "interfaces/Crafter.Graphics-ImageVulkan", - "interfaces/Crafter.Graphics-SamplerVulkan", - "interfaces/Crafter.Graphics-DescriptorHeapVulkan", - "interfaces/Crafter.Graphics-Rendertarget", - "interfaces/Crafter.Graphics-ForwardDeclarations", - "interfaces/Crafter.Graphics-RenderingElement2DVulkan" - ], - "type": "library" - }, - { - "name": "wayland", - "libs": ["wayland-client", "xkbcommon"], - "c_files": ["lib/xdg-shell-protocol", "lib/wayland-xdg-decoration-unstable-v1-client-protocol", "lib/fractional-scale-v1", "lib/viewporter"], - "extends": ["base"], - "defines": [ - { - "name": "CRAFTER_GRAPHICS_WINDOW_WAYLAND" - } - ] - }, - { - "name": "win32", - "libs": ["kernel32", "user32", "gdi32"], - "extends": ["base"], - "defines": [ - { - "name": "CRAFTER_GRAPHICS_WINDOW_WIN32" - } - ] - }, - { - "name": "vulkan", - "defines": [ - { - "name": "CRAFTER_GRAPHICS_RENDERER_VULKAN" - } - ], - "dependencies": [ - { - "path":"https://github.com/KhronosGroup/Vulkan-Headers.git", - "type":"include" - }, - { - "path":"https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git", - "type":"include" - } - ] - }, - { - "name": "software", - "defines": [ - { - "name": "CRAFTER_GRAPHICS_RENDERER_SOFTWARE" - } - ] - }, - { - "name": "deps", - "dependencies": [ - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git", - "configuration":"lib" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", - "configuration":"lib" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", - "configuration":"lib" - } - ] - }, - { - "name": "deps-timing", - "dependencies": [ - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git", - "configuration":"lib-timing" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", - "configuration":"lib" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", - "configuration":"lib" - } - ], - "defines": [{ "name": "CRAFTER_TIMING" }] - }, - { - "name": "deps-debug", - "debug": true, - "dependencies": [ - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git", - "pathh":"/home/jorijn/repos/Crafter/Crafter.Event/project.json", - "configuration":"lib-debug" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", - "pathh":"/home/jorijn/repos/Crafter/Crafter.Math/project.json", - "configuration":"lib-debug" - }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", - "configuration":"lib-debug" - } - ] - }, - { - "name": "lib-wayland", - "extends": ["wayland", "software", "deps"] - }, - { - "name": "lib-wayland-timing", - "extends": ["wayland", "software", "deps-timing"] - }, - { - "name": "lib-wayland-debug", - "extends": ["wayland", "software", "deps-debug"] - }, - { - "name": "lib-wayland-vulkan", - "extends": ["wayland", "vulkan", "deps"], - "libs": ["vulkan"] - }, - { - "name": "lib-wayland-vulkan-timing", - "extends": ["wayland", "vulkan", "deps-timing"], - "libs": ["vulkan"] - }, - { - "name": "lib-wayland-vulkan-debug", - "extends": ["wayland", "vulkan", "deps-debug"], - "libs": ["vulkan"] - }, - { - "name": "lib-win32", - "extends": ["win32", "software", "deps"] - }, - { - "name": "lib-win32-timing", - "extends": ["win32", "software", "deps-timing"] - }, - { - "name": "lib-win32-debug", - "extends": ["win32", "software", "deps-debug"] - }, - { - "name": "lib-win32-vulkan", - "extends": ["win32", "vulkan", "deps"], - "libs": ["vulkan-1"] - }, - { - "name": "lib-win32-vulkan-timing", - "extends": ["win32", "vulkan", "deps-timing"], - "libs": ["vulkan-1"] - }, - { - "name": "lib-win32-vulkan-debug", - "extends": ["win32", "vulkan", "deps-debug"], - "libs": ["vulkan-1"] - } - ] -}