1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Bug 174176 - initial contrib of CMake support.

Change-Id: I7f0417bd92415aa9abb24ebabe849d9e4f75cea5
This commit is contained in:
Doug Schaefer 2015-12-04 13:38:37 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent 6ba479a6f2
commit 6f36a51b5b
41 changed files with 1293 additions and 1 deletions

View file

@ -27,6 +27,8 @@ public interface IToolChain {
String getName();
String getCommand();
boolean supports(ILaunchTarget target);
IExtendedScannerInfo getScannerInfo(String command, List<String> args, List<String> includePaths,

View file

@ -46,8 +46,9 @@ import org.osgi.service.prefs.Preferences;
*/
public class GCCToolChain implements IToolChain {
private IToolChainType type;
private final IToolChainType type;
private final String name;
private String command;
private String version;
private String target;
@ -55,11 +56,13 @@ public class GCCToolChain implements IToolChain {
this.type = type;
getVersion(path.resolve(command).toString());
this.name = command + '-' + version;
this.command = command;
}
protected GCCToolChain(IToolChainType type, String name) {
this.type = type;
this.name = name;
// TODO need to pull the other info out of preferences
}
@Override
@ -72,6 +75,11 @@ public class GCCToolChain implements IToolChain {
return name;
}
@Override
public String getCommand() {
return command;
}
private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.cmake-feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1 @@
bin.includes = feature.xml

View file

@ -0,0 +1,29 @@
###############################################################################
# Copyright (c) 2015 QNX Software Systems and others
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
###############################################################################
# features.properties
# contains externalized strings for feature.xml
# "%foo" in feature.xml corresponds to the key "foo" in this file
# java.io.Properties file (ISO 8859-1 with "\" escapes)
# This file should be translated.
# "featureName" property - name of the feature
featureName=C/C++ CMake Support
# "providerName" property - name of the company that provides the feature
providerName=Eclipse CDT
# "description" property - description of the feature
description=Support for projects built using CMake
# copyright
copyright=\
Copyright (c) 2015 QNX Software Systems and others.\n\
All rights reserved. This program and the accompanying materials\n\
are made available under the terms of the Eclipse Public License v1.0\n\
which accompanies this distribution, and is available at\n\
http://www.eclipse.org/legal/epl-v10.html

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.eclipse.cdt.cmake"
label="%featureName"
version="1.0.0.qualifier"
provider-name="%providerName">
<description>
%description
</description>
<copyright>
%copyright
</copyright>
<license url="%licenseURL">
%license
</license>
<plugin
id="org.eclipse.cdt.cmake.core"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.cmake.ui"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.8.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<groupId>org.eclipse.cdt.features</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.cmake</artifactId>
<packaging>eclipse-feature</packaging>
</project>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.cmake.core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CDT CMake Core
Bundle-SymbolicName: org.eclipse.cdt.cmake.core;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.cmake.core.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.11.0",
org.freemarker;bundle-version="2.3.22",
org.eclipse.debug.core;bundle-version="3.10.0",
org.eclipse.launchbar.core;bundle-version="2.0.0",
org.eclipse.cdt.core;bundle-version="5.12.0",
org.eclipse.cdt.build.core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.cmake.core

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
plugin.xml

View file

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="cmakeNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="org.eclipse.cdt.cmake.core.CMakeNature">
</run>
</runtime>
<builder
id="org.eclipse.cdt.cmake.core.cmakeBuilder">
</builder>
</extension>
<extension
id="cmakeBuilder"
name="CMake Builder"
point="org.eclipse.core.resources.builders">
<builder
callOnEmptyDelta="true"
hasNature="true"
isConfigurable="true"
supportsConfigurations="true">
<run
class="org.eclipse.cdt.cmake.core.internal.CMakeBuilder">
</run>
</builder>
</extension>
<extension
point="org.eclipse.launchbar.core.launchBarContributions">
<descriptorType
class="org.eclipse.cdt.cmake.core.internal.CMakeLaunchDescriptorType"
id="org.eclipse.cdt.cmake.core.descriptorType"
priority="org.eclipse.cdt.cmake.core.descriptorType">
<enablement>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
forcePluginActivation="true"
property="org.eclipse.core.resources.projectNature"
value="org.eclipse.cdt.cmake.core.cmakeNature">
</test>
</enablement>
<enablement>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
property="org.eclipse.core.resources.projectNature">
</test>
</enablement>
</descriptorType>
<configProvider
class="org.eclipse.cdt.cmake.core.internal.CMakeLocalLaunchConfigurationProvider"
descriptorType="org.eclipse.cdt.cmake.core.descriptorType"
priority="10">
</configProvider>
</extension>
<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
delegate="org.eclipse.cdt.cmake.core.internal.CMakeLocalRunLaunchConfigDelegate"
id="org.eclipse.cdt.cmake.core.localLunchConfigurationType"
modes="run"
name="CMake Local Application"
public="true">
</launchConfigurationType>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.core.resources.IBuildConfiguration"
class="org.eclipse.cdt.cmake.core.internal.CMakeBuildConfigurationFactory">
<adapter
type="org.eclipse.cdt.cmake.core.internal.CMakeBuildConfiguration">
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.cdt.core.ScannerInfoProvider2">
<provider
builder="org.eclipse.cdt.cmake.core.cmakeBuilder"
class="org.eclipse.cdt.cmake.core.internal.CMakeScannerInfoProvider">
</provider>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.8.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.cmake.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core;
import org.eclipse.cdt.cmake.core.internal.Activator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
public class CMakeNature implements IProjectNature {
public static final String ID = Activator.getId() + ".cmakeNature"; //$NON-NLS-1$
private IProject project;
public static boolean hasNature(IProject project) {
try {
return project.hasNature(ID);
} catch (CoreException e) {
Activator.log(e);
return false;
}
}
@Override
public void configure() throws CoreException {
}
@Override
public void deconfigure() throws CoreException {
}
@Override
public IProject getProject() {
return project;
}
@Override
public void setProject(IProject project) {
this.project = project;
}
}

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.cmake.core.internal.CMakeBuilder;
import org.eclipse.cdt.cmake.core.internal.CMakeTemplateGenerator;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public class CMakeProjectGenerator {
private final IProject project;
public CMakeProjectGenerator(IProject project) {
this.project = project;
}
public void generate(IProgressMonitor monitor) throws CoreException {
// Generate the files
IFolder sourceFolder = project.getFolder("src"); //$NON-NLS-1$
if (!sourceFolder.exists()) {
sourceFolder.create(true, true, monitor);
}
CMakeTemplateGenerator templateGen = new CMakeTemplateGenerator();
Map<String, Object> fmModel = new HashMap<>();
fmModel.put("projectName", project.getName()); //$NON-NLS-1$
IFile sourceFile = sourceFolder.getFile("main.cpp"); //$NON-NLS-1$
templateGen.generateFile(fmModel, "simple/main.cpp", sourceFile, monitor); //$NON-NLS-1$
sourceFile = project.getFile("CMakeLists.txt"); //$NON-NLS-1$
templateGen.generateFile(fmModel, "simple/CMakeLists.txt", sourceFile, monitor); //$NON-NLS-1$
// Set up the project
IProjectDescription projDesc = project.getDescription();
String[] oldIds = projDesc.getNatureIds();
String[] newIds = new String[oldIds.length + 3];
System.arraycopy(oldIds, 0, newIds, 0, oldIds.length);
newIds[newIds.length - 3] = CProjectNature.C_NATURE_ID;
newIds[newIds.length - 2] = CCProjectNature.CC_NATURE_ID;
newIds[newIds.length - 1] = CMakeNature.ID;
projDesc.setNatureIds(newIds);
ICommand command = projDesc.newCommand();
command.setBuilderName(CMakeBuilder.ID);
command.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
projDesc.setBuildSpec(new ICommand[] { command });
project.setDescription(projDesc, monitor);
IPathEntry[] entries = new IPathEntry[] { CoreModel.newOutputEntry(sourceFolder.getFullPath()) };
CoreModel.getDefault().create(project).setRawPathEntries(entries, monitor);
}
}

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class Activator extends Plugin {
private static Activator plugin;
public void start(BundleContext bundleContext) throws Exception {
super.start(bundleContext);
Activator.plugin = this;
}
public void stop(BundleContext bundleContext) throws Exception {
super.stop(bundleContext);
Activator.plugin = null;
}
public static Activator getPlugin() {
return plugin;
}
public static String getId() {
return plugin.getBundle().getSymbolicName();
}
public static void log(Throwable e) {
if (e instanceof CoreException) {
plugin.getLog().log(((CoreException) e).getStatus());
} else {
plugin.getLog().log(errorStatus(e.getLocalizedMessage(), e));
}
}
public static void error(String message, Throwable cause) {
plugin.getLog().log(errorStatus(message, cause));
}
public static IStatus errorStatus(String message, Throwable cause) {
return new Status(IStatus.ERROR, getId(), message, cause);
}
public static <T> T getService(Class<T> service) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}

View file

@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import org.eclipse.cdt.build.core.CBuildConfiguration;
import org.eclipse.cdt.build.core.IToolChain;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
public class CMakeBuildConfiguration extends CBuildConfiguration {
public CMakeBuildConfiguration(IBuildConfiguration config) {
super(config);
}
public CMakeBuildConfiguration(IBuildConfiguration config, IToolChain toolChain) {
super(config, toolChain);
}
private IFolder getBuildFolder() {
String configName = getBuildConfiguration().getName();
if (configName.isEmpty()) {
configName = "default"; //$NON-NLS-1$
}
try {
// TODO should really be passing a monitor in here or create this in
// a better spot. should also throw the core exception
IFolder buildRootFolder = getProject().getFolder("build"); //$NON-NLS-1$
if (!buildRootFolder.exists()) {
buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, new NullProgressMonitor());
}
IFolder buildFolder = buildRootFolder.getFolder(configName);
if (!buildFolder.exists()) {
buildFolder.create(true, true, new NullProgressMonitor());
}
return buildFolder;
} catch (CoreException e) {
Activator.log(e);
}
return null;
}
public Path getBuildDirectory() {
return getBuildFolder().getLocation().toFile().toPath();
}
@Override
public IScannerInfo getScannerInfo(IResource resource) throws IOException {
IScannerInfo info = super.getScannerInfo(resource);
if (info == null) {
ILanguage language = LanguageManager.getInstance()
.getLanguage(CCorePlugin.getContentType(getProject(), resource.getName()), getProject()); // $NON-NLS-1$
Path dir = Paths.get(getProject().getLocationURI());
// TODO this is where we need to pass the compile options for this
// file.
IExtendedScannerInfo extendedInfo = getToolChain().getScannerInfo(getToolChain().getCommand(),
Arrays.asList("-c", new File(resource.getLocationURI()).getAbsolutePath()), //$NON-NLS-1$
Collections.emptyList(), resource, dir);
putScannerInfo(language, extendedInfo);
info = extendedInfo;
}
return info;
}
}

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.build.core.IToolChain;
import org.eclipse.cdt.build.core.IToolChainManager;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
public class CMakeBuildConfigurationFactory implements IAdapterFactory {
private static IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
private static Map<IBuildConfiguration, CMakeBuildConfiguration> cache = new HashMap<>();
@Override
public Class<?>[] getAdapterList() {
return new Class<?>[] { CMakeBuildConfiguration.class };
}
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType.equals(CMakeBuildConfiguration.class) && adaptableObject instanceof IBuildConfiguration) {
IBuildConfiguration config = (IBuildConfiguration) adaptableObject;
synchronized (cache) {
CMakeBuildConfiguration cmakeConfig = cache.get(config);
if (cmakeConfig == null) {
if (!config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) {
cmakeConfig = new CMakeBuildConfiguration(config);
cache.put(config, cmakeConfig);
return (T) cmakeConfig;
} else {
// Default to local
ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class);
ILaunchTarget localTarget = targetManager
.getLaunchTargetsOfType(ILaunchTargetManager.localLaunchTargetTypeId)[0];
Collection<IToolChain> toolChains = toolChainManager.getToolChainsSupporting(localTarget);
if (!toolChains.isEmpty()) {
// TODO propery handle when we have more than one
cmakeConfig = new CMakeBuildConfiguration(config, toolChains.iterator().next());
cache.put(config, cmakeConfig);
return (T) cmakeConfig;
}
// Just find a combination that works
for (ILaunchTarget target : targetManager.getLaunchTargets()) {
if (!target.equals(localTarget)) {
toolChains = toolChainManager.getToolChainsSupporting(target);
if (!toolChains.isEmpty()) {
// TODO propery handle when we have more
// than one
cmakeConfig = new CMakeBuildConfiguration(config, toolChains.iterator().next());
cache.put(config, cmakeConfig);
return (T) cmakeConfig;
}
}
}
// TODO if we don't have a target, need another way to
// match whatever qtInstalls we have with matching
// toolchains
}
} else {
return (T) cmakeConfig;
}
}
}
return null;
}
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.build.core.IConsoleService;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public class CMakeBuilder extends IncrementalProjectBuilder {
public static final String ID = Activator.getId() + ".cmakeBuilder"; //$NON-NLS-1$
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
IProject project = getProject();
try {
IConsoleService console = Activator.getService(IConsoleService.class);
CMakeBuildConfiguration cmakeConfig = project.getActiveBuildConfig()
.getAdapter(CMakeBuildConfiguration.class);
Path buildDir = cmakeConfig.getBuildDirectory();
if (!Files.exists(buildDir.resolve("Makefile"))) { //$NON-NLS-1$
// TODO assuming cmake is in the path here, probably need a
// preference in case it isn't.
List<String> command = Arrays.asList("cmake", //$NON-NLS-1$
new File(project.getLocationURI()).getAbsolutePath());
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
cmakeConfig.getToolChain().setEnvironment(processBuilder.environment());
Process process = processBuilder.start();
console.writeOutput(String.join(" ", command) + '\n'); //$NON-NLS-1$
console.monitor(process, null, buildDir);
}
// TODO need to figure out which builder to call. Hardcoding to make
// for now.
List<String> command = Arrays.asList("make");
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); // $NON-NLS-1$
cmakeConfig.getToolChain().setEnvironment(processBuilder.environment());
Process process = processBuilder.start();
console.writeOutput(String.join(" ", command) + '\n'); //$NON-NLS-1$
console.monitor(process, null, buildDir);
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
return new IProject[] { project };
} catch (IOException e) {
throw new CoreException(Activator.errorStatus("Building " + project.getName(), e));
}
}
}

View file

@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.ILaunchDescriptorType;
public class CMakeLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
private final CMakeLaunchDescriptorType type;
private final IProject project;
public CMakeLaunchDescriptor(CMakeLaunchDescriptorType type, IProject project) {
this.type = type;
this.project = project;
}
@Override
public String getName() {
return project.getName();
}
@Override
public ILaunchDescriptorType getType() {
return type;
}
public IProject getProject() {
return project;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter.equals(IProject.class)) {
return (T) project;
} else {
return super.getAdapter(adapter);
}
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.cmake.core.CMakeNature;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.ILaunchDescriptorType;
public class CMakeLaunchDescriptorType implements ILaunchDescriptorType {
private Map<IProject, CMakeLaunchDescriptor> descriptors = new HashMap<>();
@Override
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
if (launchObject instanceof IProject) {
IProject project = (IProject) launchObject;
if (CMakeNature.hasNature(project)) {
CMakeLaunchDescriptor desc = descriptors.get(project);
if (desc == null) {
desc = new CMakeLaunchDescriptor(this, project);
descriptors.put(project, desc);
}
return desc;
}
}
return null;
}
}

View file

@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.launchbar.core.AbstractLaunchConfigProvider;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
public class CMakeLocalLaunchConfigurationProvider extends AbstractLaunchConfigProvider {
private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
@Override
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
return ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId());
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target)
throws CoreException {
return DebugPlugin.getDefault().getLaunchManager()
.getLaunchConfigurationType(CMakeLocalRunLaunchConfigDelegate.TYPE_ID);
}
// TODO the rest here is the same as the Qt provider. Opportunity to create
// a common super class
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
throws CoreException {
ILaunchConfiguration config = null;
IProject project = descriptor.getAdapter(IProject.class);
if (project != null) {
config = configs.get(project);
if (config == null) {
config = createLaunchConfiguration(descriptor, target);
// launch config added will get called below to add it to the
// configs map
}
}
return config;
}
@Override
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target,
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
super.populateLaunchConfiguration(descriptor, target, workingCopy);
// Set the project and the connection
CMakeLaunchDescriptor qtDesc = (CMakeLaunchDescriptor) descriptor;
workingCopy.setMappedResources(new IResource[] { qtDesc.getProject() });
}
@Override
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (ownsLaunchConfiguration(configuration)) {
IProject project = configuration.getMappedResources()[0].getProject();
configs.put(project, configuration);
return true;
}
return false;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
for (Entry<IProject, ILaunchConfiguration> entry : configs.entrySet()) {
if (configuration.equals(entry.getValue())) {
configs.remove(entry.getKey());
return true;
}
}
return false;
}
@Override
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
// TODO not sure I care
return false;
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
IProject project = descriptor.getAdapter(IProject.class);
if (project != null) {
configs.remove(project);
}
}
@Override
public void launchTargetRemoved(ILaunchTarget target) throws CoreException {
// nothing to do since the Local connection can't be removed
}
}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
public class CMakeLocalRunLaunchConfigDelegate extends LaunchConfigurationTargetedDelegate
implements ILaunchConfigurationDelegate {
public static final String TYPE_ID = "org.eclipse.cdt.cmake.core.localLunchConfigurationType"; //$NON-NLS-1$
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
// TODO need to find the binary and launch it.
}
@Override
protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
// 1. Extract project from configuration
// TODO dependencies too.
IProject project = configuration.getMappedResources()[0].getProject();
return new IProject[] { project };
}
}

View file

@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.io.IOException;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
public class CMakeScannerInfoProvider implements IScannerInfoProvider {
@Override
public IScannerInfo getScannerInformation(IResource resource) {
try {
IProject project = resource.getProject();
IBuildConfiguration config = project.getActiveBuildConfig();
CMakeBuildConfiguration cmakeConfig = config.getAdapter(CMakeBuildConfiguration.class);
if (cmakeConfig != null) {
return cmakeConfig.getScannerInfo(resource);
}
} catch (CoreException | IOException e) {
Activator.log(e);
}
return null;
}
@Override
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
}
@Override
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
}
}

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class CMakeTemplateGenerator {
private final Configuration config;
public CMakeTemplateGenerator() throws CoreException {
config = new Configuration(Configuration.VERSION_2_3_22);
URL templateDirURL = FileLocator.find(Activator.getPlugin().getBundle(), new Path("/templates"), null); //$NON-NLS-1$
try {
config.setDirectoryForTemplateLoading(new File(FileLocator.toFileURL(templateDirURL).toURI()));
} catch (IOException | URISyntaxException e) {
throw new CoreException(Activator.errorStatus("Template configuration", e));
}
}
public void generateFile(final Object model, String templateFile, final IFile outputFile, IProgressMonitor monitor)
throws CoreException {
try {
final Template template = config.getTemplate(templateFile);
try (StringWriter writer = new StringWriter()) {
template.process(model, writer);
try (ByteArrayInputStream in = new ByteArrayInputStream(
writer.getBuffer().toString().getBytes(StandardCharsets.UTF_8))) {
if (outputFile.exists()) {
outputFile.setContents(in, true, true, monitor);
} else {
outputFile.create(in, true, monitor);
}
}
}
} catch (IOException | TemplateException e) {
throw new CoreException(Activator.errorStatus("Processing template " + templateFile, e));
}
}
}

View file

@ -0,0 +1,3 @@
cmake_minimum_required (VERSION 2.6)
project (${projectName})
add_executable(${projectName} src/main.cpp)

View file

@ -0,0 +1,4 @@
int main(int argc, char **argv) {
return 0;
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.cmake.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CDT CMake UI
Bundle-SymbolicName: org.eclipse.cdt.cmake.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.cmake.ui.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.11.0",
org.eclipse.ui,
org.eclipse.ui.ide,
org.eclipse.cdt.build.ui;bundle-version="1.0.0",
org.eclipse.cdt.cmake.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
plugin.xml

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.newWizards">
<wizard
category="org.eclipse.cdt.ui.newCWizards"
class="org.eclipse.cdt.cmake.ui.internal.NewCMakeProjectWizard"
finalPerspective="org.eclipse.cdt.ui.CPerspective"
icon="icons/newcc_app.gif"
id="org.eclipse.cdt.cmake.ui.newProjectWizard"
name="CMake Project"
project="true">
</wizard>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.8.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.cmake.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.cmake.ui.internal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin {
private static Activator plugin;
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
public static Activator getPlugin() {
return plugin;
}
public static String getId() {
return plugin.getBundle().getSymbolicName();
}
public static IStatus errorStatus(String message, Throwable cause) {
return new Status(IStatus.ERROR, getId(), message, cause);
}
public static void log(Exception e) {
if (e instanceof CoreException) {
plugin.getLog().log(((CoreException) e).getStatus());
} else {
plugin.getLog().log(errorStatus(e.getLocalizedMessage(), e));
}
}
}

View file

@ -0,0 +1,45 @@
/**
* The activator class controls the plug-in life cycle
*/
package org.eclipse.cdt.cmake.ui.internal;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.cmake.core.CMakeProjectGenerator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
public class NewCMakeProjectWizard extends BasicNewProjectResourceWizard {
@Override
public boolean performFinish() {
if (!super.performFinish()) {
return false;
}
IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask("Generating project", 1);
CMakeProjectGenerator generator = new CMakeProjectGenerator(getNewProject());
generator.generate(monitor);
monitor.done();
} catch (CoreException e) {
Activator.log(e);
}
}
});
try {
getContainer().run(false, true, op);
} catch (InvocationTargetException | InterruptedException e) {
return false;
}
return true;
}
}

View file

@ -218,6 +218,10 @@
<!--module>qt/org.eclipse.cdt.qt.core.tests</module-->
<module>qt/org.eclipse.cdt.qt.ui.tests</module>
<module>qt/org.eclipse.cdt.qt-feature</module>
<module>build/org.eclipse.cdt.cmake.core</module>
<module>build/org.eclipse.cdt.cmake.ui</module>
<module>build/org.eclipse.cdt.cmake-feature</module>
<module>xlc/org.eclipse.cdt.errorparsers.xlc.tests</module>