Search in sources :

Example 1 with PreCompiledHeader

use of org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader in project gradle by gradle.

the class PCHCompileTaskConfig method configureCompileTask.

@Override
protected void configureCompileTask(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal languageSourceSet) {
    // Note that the sourceSet is the sourceSet this pre-compiled header will be used with - it's not an
    // input sourceSet to the compile task.
    final DependentSourceSetInternal sourceSet = (DependentSourceSetInternal) languageSourceSet;
    task.setDescription("Compiles a pre-compiled header for the " + sourceSet + " of " + binary);
    // Add the source of the source set to the include paths to resolve any headers that may be in source directories
    task.includes(sourceSet.getSource().getSourceDirectories());
    final Project project = task.getProject();
    task.source(sourceSet.getPrefixHeaderFile());
    task.getObjectFileDir().set(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), languageSourceSet.getProjectScopedName() + "PCH"));
    task.dependsOn(project.getTasks().withType(PrefixHeaderFileGenerateTask.class).matching(new Spec<PrefixHeaderFileGenerateTask>() {

        @Override
        public boolean isSatisfiedBy(PrefixHeaderFileGenerateTask prefixHeaderFileGenerateTask) {
            return prefixHeaderFileGenerateTask.getPrefixHeaderFile().equals(sourceSet.getPrefixHeaderFile());
        }
    }));
    // This is so that VisualCpp has the object file of the generated source file available at link time
    binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
    PreCompiledHeader pch = binary.getPrefixFileToPCH().get(sourceSet.getPrefixHeaderFile());
    pch.setPchObjects(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.pch", "**/*.gch")));
    pch.builtBy(task);
}
Also used : Project(org.gradle.api.Project) PrefixHeaderFileGenerateTask(org.gradle.nativeplatform.tasks.PrefixHeaderFileGenerateTask) PreCompiledHeader(org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader) Spec(org.gradle.api.specs.Spec) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 2 with PreCompiledHeader

use of org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader in project gradle by gradle.

the class SourceCompileTaskConfig method configureCompileTask.

@Override
protected void configureCompileTask(AbstractNativeCompileTask abstractTask, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    AbstractNativeSourceCompileTask task = (AbstractNativeSourceCompileTask) abstractTask;
    task.setDescription("Compiles the " + sourceSet + " of " + binary);
    task.source(sourceSet.getSource());
    final Project project = task.getProject();
    task.getObjectFileDir().set(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), sourceSet.getProjectScopedName()));
    // If this task uses a pre-compiled header
    if (sourceSet instanceof DependentSourceSetInternal && ((DependentSourceSetInternal) sourceSet).getPreCompiledHeader() != null) {
        final DependentSourceSetInternal dependentSourceSet = (DependentSourceSetInternal) sourceSet;
        PreCompiledHeader pch = binary.getPrefixFileToPCH().get(dependentSourceSet.getPrefixHeaderFile());
        pch.setPrefixHeaderFile(dependentSourceSet.getPrefixHeaderFile());
        pch.setIncludeString(dependentSourceSet.getPreCompiledHeader());
        task.setPreCompiledHeader(pch);
    }
    binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}
Also used : Project(org.gradle.api.Project) PreCompiledHeader(org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader) AbstractNativeSourceCompileTask(org.gradle.language.nativeplatform.tasks.AbstractNativeSourceCompileTask) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Aggregations

File (java.io.File)2 Project (org.gradle.api.Project)2 PatternSet (org.gradle.api.tasks.util.PatternSet)2 PreCompiledHeader (org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader)2 Spec (org.gradle.api.specs.Spec)1 AbstractNativeSourceCompileTask (org.gradle.language.nativeplatform.tasks.AbstractNativeSourceCompileTask)1 PrefixHeaderFileGenerateTask (org.gradle.nativeplatform.tasks.PrefixHeaderFileGenerateTask)1