37 lines
1.4 KiB
C++
37 lines
1.4 KiB
C++
|
|
import std;
|
||
|
|
import Crafter.Build;
|
||
|
|
namespace fs = std::filesystem;
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||
|
|
// The library — built into mylib/bin/MyMath-<target>-<march>/libMyMath.a
|
||
|
|
// and exposed to consumers via cfg.dependencies. The static unique_ptr
|
||
|
|
// keeps the Configuration alive for the duration of the build (the
|
||
|
|
// consumer holds a raw pointer to it).
|
||
|
|
static auto lib = std::make_unique<Configuration>();
|
||
|
|
lib->path = "./mylib/";
|
||
|
|
lib->name = "MyMath";
|
||
|
|
lib->outputName = "MyMath";
|
||
|
|
lib->target = "x86_64-pc-linux-gnu";
|
||
|
|
lib->type = ConfigurationType::LibraryStatic;
|
||
|
|
{
|
||
|
|
std::array<fs::path, 1> ifaces = { "MyMath" };
|
||
|
|
std::array<fs::path, 0> impls = {};
|
||
|
|
lib->GetInterfacesAndImplementations(ifaces, impls);
|
||
|
|
}
|
||
|
|
|
||
|
|
// The consumer — main.cpp imports MyMath. The build resolves the import
|
||
|
|
// through cfg.dependencies and links libMyMath.a automatically.
|
||
|
|
Configuration cfg;
|
||
|
|
cfg.path = "./";
|
||
|
|
cfg.name = "math-app";
|
||
|
|
cfg.outputName = "math-app";
|
||
|
|
cfg.target = "x86_64-pc-linux-gnu";
|
||
|
|
cfg.type = ConfigurationType::Executable;
|
||
|
|
cfg.dependencies = { lib.get() };
|
||
|
|
|
||
|
|
std::array<fs::path, 0> ifaces = {};
|
||
|
|
std::array<fs::path, 1> impls = { "main" };
|
||
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||
|
|
return cfg;
|
||
|
|
}
|