dev.nokee.platform.cpp.internal.plugins.CppLibraryPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platformNative Show documentation
Show all versions of platformNative Show documentation
Painless native development in Gradle
The newest version!
package dev.nokee.platform.cpp.internal.plugins;
import dev.nokee.internal.Cast;
import dev.nokee.platform.base.internal.Component;
import dev.nokee.platform.base.internal.ComponentCollection;
import dev.nokee.platform.base.internal.NamingScheme;
import dev.nokee.platform.cpp.CppLibraryExtension;
import dev.nokee.platform.cpp.internal.DefaultCppLibraryExtension;
import dev.nokee.platform.nativebase.internal.DefaultNativeApplicationComponent;
import dev.nokee.platform.nativebase.internal.DefaultNativeLibraryComponent;
import dev.nokee.platform.nativebase.internal.TargetMachineRule;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
import org.gradle.nativeplatform.toolchain.internal.plugins.StandardToolChainsPlugin;
import javax.inject.Inject;
public abstract class CppLibraryPlugin implements Plugin {
private static final String EXTENSION_NAME = "library";
@Inject
protected abstract ObjectFactory getObjects();
@Override
public void apply(Project project) {
project.getPluginManager().apply(StandardToolChainsPlugin.class);
NamingScheme names = NamingScheme.asMainComponent(project.getName()).withComponentDisplayName("main native component");
ComponentCollection components = Cast.uncheckedCast("of type erasure", project.getExtensions().create("components", ComponentCollection.class));
DefaultNativeLibraryComponent component = components.register(DefaultNativeLibraryComponent.class, names).get();
DefaultCppLibraryExtension extension = getObjects().newInstance(DefaultCppLibraryExtension.class, component);
project.afterEvaluate(getObjects().newInstance(TargetMachineRule.class, extension.getTargetMachines(), EXTENSION_NAME));
project.afterEvaluate(extension::finalizeExtension);
project.getExtensions().add(CppLibraryExtension.class, EXTENSION_NAME, extension);
}
}