mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Set CC and CXX variables to toolchain compileCommands in std build.
Also set BUILD_MODE to the launch mode so the makefile can do different things based on the mode. Change template to add -g option for debug. Also fix a deadlock I detected due to side affect build folder creation. Change-Id: Ic7b13ba3238e6ef201cccb1b2bfc8dcc6956ea3a
This commit is contained in:
parent
dc4be72b1a
commit
a90655bc04
5 changed files with 75 additions and 18 deletions
|
@ -2,13 +2,17 @@ PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
OBJS = ${projectName}.o
|
OBJS = ${projectName}.o
|
||||||
|
|
||||||
|
ifeq ($(BUILD_MODE),debug)
|
||||||
|
CFLAGS += -g
|
||||||
|
endif
|
||||||
|
|
||||||
all: ${projectName}
|
all: ${projectName}
|
||||||
|
|
||||||
${projectName}: $(OBJS)
|
${projectName}: $(OBJS)
|
||||||
$(CXX) -o $@ $^
|
$(CXX) -o $@ $^
|
||||||
|
|
||||||
%.o: $(PROJECT_ROOT)%.cpp
|
%.o: $(PROJECT_ROOT)%.cpp
|
||||||
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
|
||||||
|
|
||||||
%.o: $(PROJECT_ROOT)%.c
|
%.o: $(PROJECT_ROOT)%.c
|
||||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
||||||
|
|
|
@ -68,12 +68,11 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.eclipse.osgi.util.NLS;
|
|
||||||
import org.osgi.service.prefs.BackingStoreException;
|
import org.osgi.service.prefs.BackingStoreException;
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
|
@ -127,9 +126,9 @@ public abstract class CBuildConfiguration extends PlatformObject
|
||||||
null));
|
null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toolChain = tc;
|
this.toolChain = tc;
|
||||||
|
|
||||||
launchMode = settings.get(LAUNCH_MODE, "run"); //$NON-NLS-1$
|
this.launchMode = settings.get(LAUNCH_MODE, "run"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
|
protected CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
|
||||||
|
@ -204,18 +203,28 @@ public abstract class CBuildConfiguration extends PlatformObject
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContainer getBuildContainer() throws CoreException {
|
public IContainer getBuildContainer() throws CoreException {
|
||||||
// TODO should really be passing a monitor in here or create this in
|
|
||||||
// a better spot. should also throw the core exception
|
|
||||||
// TODO make the name of this folder a project property
|
// TODO make the name of this folder a project property
|
||||||
IProgressMonitor monitor = new NullProgressMonitor();
|
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
IFolder buildRootFolder = project.getFolder("build"); //$NON-NLS-1$
|
IFolder buildRootFolder = project.getFolder("build"); //$NON-NLS-1$
|
||||||
if (!buildRootFolder.exists()) {
|
|
||||||
buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
|
|
||||||
}
|
|
||||||
IFolder buildFolder = buildRootFolder.getFolder(name);
|
IFolder buildFolder = buildRootFolder.getFolder(name);
|
||||||
if (!buildFolder.exists()) {
|
|
||||||
buildFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
|
if (!buildRootFolder.exists() || !buildFolder.exists()) {
|
||||||
|
new Job(Messages.CBuildConfiguration_CreateJob) {
|
||||||
|
@Override
|
||||||
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
try {
|
||||||
|
if (!buildRootFolder.exists()) {
|
||||||
|
buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
|
||||||
|
}
|
||||||
|
if (!buildFolder.exists()) {
|
||||||
|
buildFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
|
||||||
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return e.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildFolder;
|
return buildFolder;
|
||||||
|
@ -308,7 +317,14 @@ public abstract class CBuildConfiguration extends PlatformObject
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnvironmentVariable getVariable(String name) {
|
public IEnvironmentVariable getVariable(String name) {
|
||||||
// By default, none
|
IEnvironmentVariable[] vars = getVariables();
|
||||||
|
if (vars != null) {
|
||||||
|
for (IEnvironmentVariable var : vars) {
|
||||||
|
if (var.getName().equals(name)) {
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,8 +393,7 @@ public abstract class CBuildConfiguration extends PlatformObject
|
||||||
URI uri = URIUtil.toURI(externalLocation);
|
URI uri = URIUtil.toURI(externalLocation);
|
||||||
if (uri.getScheme() != null) {
|
if (uri.getScheme() != null) {
|
||||||
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, externalLocation);
|
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, externalLocation);
|
||||||
String locationText = NLS.bind(
|
String locationText = String.format(Messages.CBuildConfiguration_Location,
|
||||||
CCorePlugin.getResourceString("ACBuilder.ProblemsView.Location"), //$NON-NLS-1$
|
|
||||||
problemMarkerInfo.lineNumber, externalLocation);
|
problemMarkerInfo.lineNumber, externalLocation);
|
||||||
marker.setAttribute(IMarker.LOCATION, locationText);
|
marker.setAttribute(IMarker.LOCATION, locationText);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
import org.eclipse.cdt.core.IConsoleParser;
|
import org.eclipse.cdt.core.IConsoleParser;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
|
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
|
||||||
|
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||||
import org.eclipse.cdt.core.resources.IConsole;
|
import org.eclipse.cdt.core.resources.IConsole;
|
||||||
import org.eclipse.cdt.internal.core.build.Messages;
|
import org.eclipse.cdt.internal.core.build.Messages;
|
||||||
|
@ -59,15 +63,18 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
|
||||||
private String[] buildCommand;
|
private String[] buildCommand;
|
||||||
private String[] cleanCommand;
|
private String[] cleanCommand;
|
||||||
private IContainer buildContainer;
|
private IContainer buildContainer;
|
||||||
|
private IEnvironmentVariable[] envVars;
|
||||||
|
|
||||||
public StandardBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
|
public StandardBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
|
||||||
super(config, name);
|
super(config, name);
|
||||||
applyProperties();
|
applyProperties();
|
||||||
|
setupEnvVars();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
|
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
|
||||||
String launchMode) {
|
String launchMode) throws CoreException {
|
||||||
super(config, name, toolChain);
|
super(config, name, toolChain, launchMode);
|
||||||
|
setupEnvVars();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyProperties() {
|
private void applyProperties() {
|
||||||
|
@ -92,6 +99,33 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupEnvVars() throws CoreException {
|
||||||
|
IToolChain toolchain = getToolChain();
|
||||||
|
List<IEnvironmentVariable> vars = new ArrayList<>();
|
||||||
|
|
||||||
|
String[] cc = toolchain.getCompileCommands(GCCLanguage.getDefault());
|
||||||
|
if (cc != null && cc.length > 0) {
|
||||||
|
vars.add(new EnvironmentVariable("CC", cc[0])); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] cxx = toolchain.getCompileCommands(GPPLanguage.getDefault());
|
||||||
|
if (cxx != null && cxx.length > 0) {
|
||||||
|
vars.add(new EnvironmentVariable("CXX", cxx[0])); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
String mode = getLaunchMode();
|
||||||
|
if (mode != null && !mode.isEmpty()) {
|
||||||
|
vars.add(new EnvironmentVariable("BUILD_MODE", mode)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
envVars = vars.toArray(new IEnvironmentVariable[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEnvironmentVariable[] getVariables() {
|
||||||
|
return envVars;
|
||||||
|
}
|
||||||
|
|
||||||
public void setBuildContainer(IContainer buildContainer) {
|
public void setBuildContainer(IContainer buildContainer) {
|
||||||
this.buildContainer = buildContainer;
|
this.buildContainer = buildContainer;
|
||||||
setProperty(BUILD_CONTAINER, buildContainer.getFullPath().toString());
|
setProperty(BUILD_CONTAINER, buildContainer.getFullPath().toString());
|
||||||
|
|
|
@ -11,7 +11,9 @@ import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
public class Messages extends NLS {
|
public class Messages extends NLS {
|
||||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.build.Messages"; //$NON-NLS-1$
|
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.build.Messages"; //$NON-NLS-1$
|
||||||
|
public static String CBuildConfiguration_CreateJob;
|
||||||
public static String CBuildConfiguration_ToolchainMissing;
|
public static String CBuildConfiguration_ToolchainMissing;
|
||||||
|
public static String CBuildConfiguration_Location;
|
||||||
public static String CBuilder_ExceptionWhileBuilding;
|
public static String CBuilder_ExceptionWhileBuilding;
|
||||||
public static String CBuilder_ExceptionWhileBuilding2;
|
public static String CBuilder_ExceptionWhileBuilding2;
|
||||||
public static String CBuilder_NotConfiguredCorrectly;
|
public static String CBuilder_NotConfiguredCorrectly;
|
||||||
|
|
|
@ -11,4 +11,6 @@ CBuilder_NotConfiguredCorrectly=Build not configured correctly\n
|
||||||
CBuilder_NotConfiguredCorrectly2=Build not configured correctly\n
|
CBuilder_NotConfiguredCorrectly2=Build not configured correctly\n
|
||||||
StandardBuildConfiguration_0=Building in: %s\n
|
StandardBuildConfiguration_0=Building in: %s\n
|
||||||
StandardBuildConfiguration_1=Build complete: %s\n
|
StandardBuildConfiguration_1=Build complete: %s\n
|
||||||
|
CBuildConfiguration_CreateJob=Create Build Folder
|
||||||
|
CBuildConfiguration_Location=line %d, external location: %s
|
||||||
CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration
|
CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration
|
||||||
|
|
Loading…
Add table
Reference in a new issue