Search in sources :

Example 6 with CppPlatform

use of org.gradle.language.cpp.CppPlatform in project gradle by gradle.

the class CppApplicationPlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(CppBasePlugin.class);
    final ObjectFactory objectFactory = project.getObjects();
    final ProviderFactory providers = project.getProviders();
    // Add the application and extension
    final DefaultCppApplication application = componentFactory.newInstance(CppApplication.class, DefaultCppApplication.class, "main");
    project.getExtensions().add(CppApplication.class, "application", application);
    project.getComponents().add(application);
    // Configure the component
    application.getBaseName().convention(project.getName());
    application.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
    application.getDevelopmentBinary().convention(project.provider(() -> {
        // Prefer the host architecture, if present, else use the first architecture specified
        return application.getBinaries().get().stream().filter(CppExecutable.class::isInstance).map(CppExecutable.class::cast).filter(binary -> !binary.isOptimized() && Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture())).findFirst().orElse(application.getBinaries().get().stream().filter(CppExecutable.class::isInstance).map(CppExecutable.class::cast).filter(binary -> !binary.isOptimized()).findFirst().orElse(null));
    }));
    application.getBinaries().whenElementKnown(binary -> {
        application.getMainPublication().addVariant(binary);
    });
    project.afterEvaluate(p -> {
        // TODO: make build type configurable for components
        Dimensions.applicationVariants(application.getBaseName(), application.getTargetMachines(), objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
            if (tryToBuildOnHost(variantIdentity)) {
                ToolChainSelector.Result<CppPlatform> result = toolChainSelector.select(CppPlatform.class, new DefaultCppPlatform(variantIdentity.getTargetMachine()));
                application.addExecutable(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
            } else {
                // Known, but not buildable
                application.getMainPublication().addVariant(variantIdentity);
            }
        });
        // Configure the binaries
        application.getBinaries().realizeNow();
    });
}
Also used : CppApplication(org.gradle.language.cpp.CppApplication) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Project(org.gradle.api.Project) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) CppExecutable(org.gradle.language.cpp.CppExecutable) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) CppPlatform(org.gradle.language.cpp.CppPlatform) Inject(javax.inject.Inject) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) ObjectFactory(org.gradle.api.model.ObjectFactory) Architectures(org.gradle.nativeplatform.platform.internal.Architectures) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) DefaultCppApplication(org.gradle.language.cpp.internal.DefaultCppApplication) Plugin(org.gradle.api.Plugin) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) CppPlatform(org.gradle.language.cpp.CppPlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) ObjectFactory(org.gradle.api.model.ObjectFactory) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) CppExecutable(org.gradle.language.cpp.CppExecutable) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) DefaultCppApplication(org.gradle.language.cpp.internal.DefaultCppApplication)

Example 7 with CppPlatform

use of org.gradle.language.cpp.CppPlatform in project gradle by gradle.

the class DefaultToolChainSelector method select.

public Result<CppPlatform> select(CppPlatform requestPlatform) {
    DefaultNativePlatform targetNativePlatform = newNativePlatform(requestPlatform.getTargetMachine());
    // TODO - push all this stuff down to the tool chain and let it create the specific platform and provider
    NativeLanguage sourceLanguage = NativeLanguage.CPP;
    NativeToolChainInternal toolChain = getToolChain(sourceLanguage, targetNativePlatform);
    // TODO - don't select again here, as the selection is already performed to select the toolchain
    PlatformToolProvider toolProvider = toolChain.select(sourceLanguage, targetNativePlatform);
    CppPlatform targetPlatform = new DefaultCppPlatform(requestPlatform.getTargetMachine(), targetNativePlatform);
    return new DefaultResult<CppPlatform>(toolChain, toolProvider, targetPlatform);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) CppPlatform(org.gradle.language.cpp.CppPlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) NativeLanguage(org.gradle.nativeplatform.toolchain.internal.NativeLanguage) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform)

Aggregations

CppPlatform (org.gradle.language.cpp.CppPlatform)7 Callable (java.util.concurrent.Callable)5 Project (org.gradle.api.Project)4 ObjectFactory (org.gradle.api.model.ObjectFactory)4 ProviderFactory (org.gradle.api.provider.ProviderFactory)4 TaskContainer (org.gradle.api.tasks.TaskContainer)4 DefaultCppPlatform (org.gradle.language.cpp.internal.DefaultCppPlatform)4 Set (java.util.Set)3 AttributeContainer (org.gradle.api.attributes.AttributeContainer)3 Usage (org.gradle.api.attributes.Usage)3 Provider (org.gradle.api.provider.Provider)3 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)3 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)3 ToolChainSelector (org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector)3 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)3 DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)3 File (java.io.File)2 Action (org.gradle.api.Action)2 Configuration (org.gradle.api.artifacts.Configuration)2 Zip (org.gradle.api.tasks.bundling.Zip)2