mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +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
|
||||
|
||||
ifeq ($(BUILD_MODE),debug)
|
||||
CFLAGS += -g
|
||||
endif
|
||||
|
||||
all: ${projectName}
|
||||
|
||||
${projectName}: $(OBJS)
|
||||
$(CXX) -o $@ $^
|
||||
|
||||
%.o: $(PROJECT_ROOT)%.cpp
|
||||
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
||||
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
|
||||
|
||||
%.o: $(PROJECT_ROOT)%.c
|
||||
$(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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
|
@ -127,9 +126,9 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
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) {
|
||||
|
@ -204,19 +203,29 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
}
|
||||
|
||||
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
|
||||
IProgressMonitor monitor = new NullProgressMonitor();
|
||||
IProject project = getProject();
|
||||
IFolder buildRootFolder = project.getFolder("build"); //$NON-NLS-1$
|
||||
IFolder buildFolder = buildRootFolder.getFolder(name);
|
||||
|
||||
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);
|
||||
}
|
||||
IFolder buildFolder = buildRootFolder.getFolder(name);
|
||||
if (!buildFolder.exists()) {
|
||||
buildFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
}.schedule();
|
||||
}
|
||||
|
||||
return buildFolder;
|
||||
}
|
||||
|
@ -308,7 +317,14 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -377,8 +393,7 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
URI uri = URIUtil.toURI(externalLocation);
|
||||
if (uri.getScheme() != null) {
|
||||
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, externalLocation);
|
||||
String locationText = NLS.bind(
|
||||
CCorePlugin.getResourceString("ACBuilder.ProblemsView.Location"), //$NON-NLS-1$
|
||||
String locationText = String.format(Messages.CBuildConfiguration_Location,
|
||||
problemMarkerInfo.lineNumber, externalLocation);
|
||||
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.ErrorParserManager;
|
||||
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.resources.IConsole;
|
||||
import org.eclipse.cdt.internal.core.build.Messages;
|
||||
|
@ -59,15 +63,18 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
|
|||
private String[] buildCommand;
|
||||
private String[] cleanCommand;
|
||||
private IContainer buildContainer;
|
||||
private IEnvironmentVariable[] envVars;
|
||||
|
||||
public StandardBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
|
||||
super(config, name);
|
||||
applyProperties();
|
||||
setupEnvVars();
|
||||
}
|
||||
|
||||
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
|
||||
String launchMode) {
|
||||
super(config, name, toolChain);
|
||||
String launchMode) throws CoreException {
|
||||
super(config, name, toolChain, launchMode);
|
||||
setupEnvVars();
|
||||
}
|
||||
|
||||
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) {
|
||||
this.buildContainer = buildContainer;
|
||||
setProperty(BUILD_CONTAINER, buildContainer.getFullPath().toString());
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.eclipse.osgi.util.NLS;
|
|||
|
||||
public class Messages extends NLS {
|
||||
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_Location;
|
||||
public static String CBuilder_ExceptionWhileBuilding;
|
||||
public static String CBuilder_ExceptionWhileBuilding2;
|
||||
public static String CBuilder_NotConfiguredCorrectly;
|
||||
|
|
|
@ -11,4 +11,6 @@ CBuilder_NotConfiguredCorrectly=Build not configured correctly\n
|
|||
CBuilder_NotConfiguredCorrectly2=Build not configured correctly\n
|
||||
StandardBuildConfiguration_0=Building in: %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
|
||||
|
|
Loading…
Add table
Reference in a new issue