use of org.gradle.language.cpp.CppApplication in project gradle by gradle.
the class VisualStudioPlugin method applyVisualStudioCurrentModelRules.
private void applyVisualStudioCurrentModelRules(final VisualStudioExtensionInternal extension) {
project.getComponents().withType(CppApplication.class).all(cppApplication -> {
DefaultVisualStudioProject vsProject = extension.getProjectRegistry().createProject(project.getName(), cppApplication.getName());
vsProject.getSourceFiles().from(cppApplication.getCppSource());
vsProject.getHeaderFiles().from(cppApplication.getHeaderFiles());
cppApplication.getBinaries().whenElementFinalized(CppExecutable.class, executable -> {
extension.getProjectRegistry().addProjectConfiguration(new CppApplicationVisualStudioTargetBinary(project.getName(), project.getPath(), cppApplication, executable, project.getLayout()));
});
});
project.afterEvaluate(proj -> {
project.getComponents().withType(CppLibrary.class).all(cppLibrary -> {
for (Linkage linkage : cppLibrary.getLinkage().get()) {
VisualStudioTargetBinary.ProjectType projectType = VisualStudioTargetBinary.ProjectType.DLL;
if (Linkage.STATIC.equals(linkage)) {
projectType = VisualStudioTargetBinary.ProjectType.LIB;
}
DefaultVisualStudioProject vsProject = extension.getProjectRegistry().createProject(project.getName() + projectType.getSuffix(), cppLibrary.getName());
vsProject.getSourceFiles().from(cppLibrary.getCppSource());
vsProject.getHeaderFiles().from(cppLibrary.getHeaderFiles());
}
cppLibrary.getBinaries().whenElementFinalized(CppSharedLibrary.class, library -> {
extension.getProjectRegistry().addProjectConfiguration(new CppSharedLibraryVisualStudioTargetBinary(project.getName(), project.getPath(), cppLibrary, library, project.getLayout()));
});
cppLibrary.getBinaries().whenElementFinalized(CppStaticLibrary.class, library -> {
extension.getProjectRegistry().addProjectConfiguration(new CppStaticLibraryVisualStudioTargetBinary(project.getName(), project.getPath(), cppLibrary, library, project.getLayout()));
});
});
});
}
use of org.gradle.language.cpp.CppApplication in project gradle by gradle.
the class CppModelBuilder method buildAll.
@Override
public Object buildAll(String modelName, Project project) {
DefaultProjectIdentifier projectIdentifier = new DefaultProjectIdentifier(project.getRootDir(), project.getPath());
CompilerOutputFileNamingSchemeFactory namingSchemeFactory = new CompilerOutputFileNamingSchemeFactory(((ProjectInternal) project).getFileResolver());
DefaultCppComponentModel mainComponent = null;
CppApplication application = project.getComponents().withType(CppApplication.class).findByName("main");
if (application != null) {
mainComponent = new DefaultCppApplicationModel(application.getName(), application.getBaseName().get(), binariesFor(application, application.getPrivateHeaderDirs(), projectIdentifier, namingSchemeFactory));
} else {
DefaultCppLibrary library = (DefaultCppLibrary) project.getComponents().withType(CppLibrary.class).findByName("main");
if (library != null) {
mainComponent = new DefaultCppLibraryModel(library.getName(), library.getBaseName().get(), binariesFor(library, library.getAllHeaderDirs(), projectIdentifier, namingSchemeFactory));
}
}
DefaultCppComponentModel testComponent = null;
CppTestSuite testSuite = project.getComponents().withType(CppTestSuite.class).findByName("test");
if (testSuite != null) {
testComponent = new DefaultCppTestSuiteModel(testSuite.getName(), testSuite.getBaseName().get(), binariesFor(testSuite, testSuite.getPrivateHeaderDirs(), projectIdentifier, namingSchemeFactory));
}
return new DefaultCppProjectModel(projectIdentifier, mainComponent, testComponent);
}
use of org.gradle.language.cpp.CppApplication in project gradle by gradle.
the class CppUnitTestPlugin method configureTestSuiteWithTestedComponentWhenAvailable.
private void configureTestSuiteWithTestedComponentWhenAvailable(Project project, DefaultCppTestSuite testSuite, DefaultCppTestExecutable testExecutable) {
CppComponent target = testSuite.getTestedComponent().getOrNull();
if (!(target instanceof ProductionCppComponent)) {
return;
}
final ProductionCppComponent testedComponent = (ProductionCppComponent) target;
final TaskContainer tasks = project.getTasks();
testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
if (!isTestedBinary(testExecutable, testedComponent, testedBinary)) {
return;
}
// TODO - move this to a base plugin
// Setup the dependency on the main binary
// This should all be replaced by a single dependency that points at some "testable" variants of the main binary
// Inherit implementation dependencies
testExecutable.getImplementationDependencies().extendsFrom(((DefaultCppBinary) testedBinary).getImplementationDependencies());
// Configure test binary to link against tested component compiled objects
ConfigurableFileCollection testableObjects = project.files();
if (target instanceof CppApplication) {
// TODO - this should be an outgoing variant of the component under test
TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register(testExecutable.getNames().getTaskName("relocateMainFor"), UnexportMainSymbol.class, task -> {
String dirName = ((DefaultCppBinary) testedBinary).getNames().getDirName();
task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
task.getObjects().from(testedBinary.getObjects());
});
testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
} else {
testableObjects.from(testedBinary.getObjects());
}
Dependency linkDependency = project.getDependencies().create(testableObjects);
testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
});
}
Aggregations