mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix issues with CMake. Arguments not passed. Local GCC prefix wrong
I added cmake arguments in the launch configuration for CMake projects but didn't add it to the command line. Also indexing wasn't working on my Mac. llvm-cc overrode the standard local cc. Added the local compile commands if the toolchain is local. Change-Id: I914c52dd42fbf84b87cd0e8c7504f024c2449a82
This commit is contained in:
parent
b6cb657229
commit
cfdb9c2ad8
3 changed files with 52 additions and 14 deletions
|
@ -16,6 +16,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -58,6 +59,9 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
private final IEnvironmentVariable pathVar;
|
||||
private final IEnvironmentVariable[] envVars;
|
||||
private final Map<String, String> properties = new HashMap<>();
|
||||
private String[] commands;
|
||||
private String[] cCommands;
|
||||
private String[] cppCommands;
|
||||
|
||||
public GCCToolChain(IToolChainProvider provider, String id, String version) {
|
||||
this(provider, id, version, null, null);
|
||||
|
@ -73,7 +77,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
this.version = version;
|
||||
this.name = id + " - " + version; //$NON-NLS-1$
|
||||
this.path = path;
|
||||
this.prefix = prefix != null ? prefix : "";
|
||||
this.prefix = prefix != null ? prefix : ""; //$NON-NLS-1$
|
||||
|
||||
if (path != null) {
|
||||
StringBuilder pathString = new StringBuilder();
|
||||
|
@ -269,9 +273,9 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
// Source is an empty tmp file
|
||||
String extension;
|
||||
if (GPPLanguage.ID.equals(language.getId())) {
|
||||
extension = ".cpp";
|
||||
extension = ".cpp"; //$NON-NLS-1$
|
||||
} else if (GCCLanguage.ID.equals(language.getId())) {
|
||||
extension = ".c";
|
||||
extension = ".c"; //$NON-NLS-1$
|
||||
} else {
|
||||
// In theory we shouldn't get here
|
||||
return null;
|
||||
|
@ -391,17 +395,44 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
return null;
|
||||
}
|
||||
|
||||
private boolean isLocal() {
|
||||
return Platform.getOS().equals(properties.get(ATTR_OS))
|
||||
&& Platform.getOSArch().equals(properties.get(ATTR_ARCH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCompileCommands() {
|
||||
return new String[] { prefix + "gcc", prefix + "g++", prefix + "clang", prefix + "clang++", prefix + "cc", prefix + "c++" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
||||
if (commands == null) {
|
||||
boolean local = isLocal();
|
||||
|
||||
List<String> cCommandsList = new ArrayList<>(Arrays.asList(prefix + "gcc", prefix + "clang", prefix + "cc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
if (local) {
|
||||
cCommandsList.addAll(Arrays.asList("gcc", "clang", "cc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
cCommands = cCommandsList.toArray(new String[cCommandsList.size()]);
|
||||
|
||||
List<String> cppCommandsList = new ArrayList<>(Arrays.asList(prefix + "g++", prefix + "clang++", prefix + "c++")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
if (local) {
|
||||
cppCommandsList.addAll(Arrays.asList("g++", "clang++", "c++")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
cppCommands = cppCommandsList.toArray(new String[cppCommandsList.size()]);
|
||||
|
||||
List<String> commandsList = new ArrayList<>(cCommandsList);
|
||||
commandsList.addAll(cppCommandsList);
|
||||
commands = commandsList.toArray(new String[commandsList.size()]);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCompileCommands(ILanguage language) {
|
||||
if (commands == null) {
|
||||
getCompileCommands();
|
||||
}
|
||||
if (GPPLanguage.ID.equals(language.getId())) {
|
||||
return new String[] { prefix + "g++", prefix + "clang++", prefix + "c++" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return cppCommands;
|
||||
} else if (GCCLanguage.ID.equals(language.getId())) {
|
||||
return new String[] { prefix + "gcc", prefix + "clang", prefix + "cc" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return cCommands;
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
if (matcher.matches()) {
|
||||
prefix = matcher.group(1);
|
||||
String cmd = matcher.group(2);
|
||||
String altFile = prefix + (cmd.startsWith("g") ? "g++" : "clang++");
|
||||
String altFile = prefix + (cmd.startsWith("g") ? "g++" : "clang++"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
File altCmd = new File(dir, altFile);
|
||||
hasAltCmd = altCmd.exists() && altCmd.canExecute();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
if (matcher.matches()) {
|
||||
prefix = matcher.group(1);
|
||||
String cmd = matcher.group(2);
|
||||
String altFile = prefix + (cmd.startsWith("g") ? "gcc" : "clang");
|
||||
String altFile = prefix + (cmd.startsWith("g") ? "gcc" : "clang"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
File altCmd = new File(dir, altFile);
|
||||
hasAltCmd = altCmd.exists() && altCmd.canExecute();
|
||||
}
|
||||
|
@ -101,26 +101,26 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
String[] tuple = target.split("-"); //$NON-NLS-1$
|
||||
if (tuple.length > 2) {
|
||||
// Arch
|
||||
if ("x86_64".equals(tuple[0])) {
|
||||
if ("x86_64".equals(tuple[0])) { //$NON-NLS-1$
|
||||
toolChain.setProperty(IToolChain.ATTR_ARCH, tuple[0]);
|
||||
} else {
|
||||
toolChain.setProperty(IToolChain.ATTR_ARCH, "x86"); // default
|
||||
toolChain.setProperty(IToolChain.ATTR_ARCH, "x86"); // default //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// OS
|
||||
switch (tuple[1]) {
|
||||
case "w64":
|
||||
case "w64": //$NON-NLS-1$
|
||||
toolChain.setProperty(IToolChain.ATTR_OS, Platform.OS_WIN32);
|
||||
break;
|
||||
case "linux":
|
||||
case "linux": //$NON-NLS-1$
|
||||
toolChain.setProperty(IToolChain.ATTR_OS, Platform.OS_LINUX);
|
||||
break;
|
||||
case "apple":
|
||||
case "apple": //$NON-NLS-1$
|
||||
toolChain.setProperty(IToolChain.ATTR_OS, Platform.OS_MACOSX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "system");
|
||||
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "system"); //$NON-NLS-1$
|
||||
manager.addToolChain(toolChain);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -128,6 +129,12 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
|
|||
}
|
||||
|
||||
command.add("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"); //$NON-NLS-1$
|
||||
|
||||
String userArgs = properties.get(CMAKE_ARGUMENTS);
|
||||
if (userArgs != null) {
|
||||
command.addAll(Arrays.asList(userArgs.trim().split("\\s+"))); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
command.add(new File(project.getLocationURI()).getAbsolutePath());
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
|
||||
|
|
Loading…
Add table
Reference in a new issue