mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
Add support for the clang --target option for cross compilation.
(Backport from cmake4eclipse) Change-Id: I8239aec001a5e9c919f85177798dabeec1f18285 Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
parent
8b80033025
commit
80de3ba94f
3 changed files with 94 additions and 2 deletions
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Ghaith Hachem.
|
||||
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
|
||||
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.jsoncdb.core.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.eclipse.cdt.jsoncdb.core.participant.Arglets;
|
||||
import org.eclipse.cdt.jsoncdb.core.participant.Arglets.Target_Clang;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BuiltinsDetectTarget_Clang_Test {
|
||||
|
||||
private Target_Clang testee;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testee = new Target_Clang();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Arglets.Sysroot_GCC#processArgument}.
|
||||
*/
|
||||
@Test
|
||||
public final void testProcessArgument_target() {
|
||||
final String more = " -g -MMD -MT CMakeFiles/execut1.dir/util1.c.o -MF \"CMakeFiles/execut1.dir/util1.c.o.d\""
|
||||
+ " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c";
|
||||
ParseContext context;
|
||||
String parsed;
|
||||
|
||||
final IPath cwd = new Path("");
|
||||
// --target=some-triplet-string
|
||||
String arg = "--target=test-triplet-entry";
|
||||
|
||||
context = new ParseContext();
|
||||
testee.processArgument(context, cwd, arg + more);
|
||||
assertEquals("#entries", 1, context.getBuiltinDetectionArgs().size());
|
||||
parsed = context.getBuiltinDetectionArgs().get(0);
|
||||
assertEquals("name", arg, parsed);
|
||||
// --sysroot="/a/Path"
|
||||
context = new ParseContext();
|
||||
arg = "--target=test-triplet-entry";
|
||||
testee.processArgument(context, cwd, arg + " " + arg + more);
|
||||
assertEquals("#entries", 1, context.getBuiltinDetectionArgs().size());
|
||||
parsed = context.getBuiltinDetectionArgs().get(0);
|
||||
assertEquals("name", arg, parsed);
|
||||
}
|
||||
|
||||
}
|
|
@ -87,7 +87,6 @@ public final class ParserDetection {
|
|||
final IToolCommandlineParser gcc = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
|
||||
btbGcc, gcc_args);
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("gcc", true, "exe", gcc));
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("clang", true, "exe", gcc));
|
||||
// cross compilers, e.g. arm-none-eabi-gcc ====
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-gcc", true, "exe", gcc));
|
||||
}
|
||||
|
@ -96,10 +95,27 @@ public final class ParserDetection {
|
|||
final IToolCommandlineParser gxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
|
||||
btbGcc, gcc_args);
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("g\\+\\+", true, "exe", gxx));
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("clang\\+\\+", true, "exe", gxx));
|
||||
// cross compilers, e.g. arm-none-eabi-g++ ====
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-g\\+\\+", true, "exe", gxx));
|
||||
}
|
||||
// Clang C & C++ Compiler ====
|
||||
{
|
||||
/** Names of known tools along with their command line argument parsers for clang */
|
||||
final IArglet[] clang_args = { new Arglets.IncludePath_C_POSIX(), new Arglets.MacroDefine_C_POSIX(),
|
||||
new Arglets.MacroUndefine_C_POSIX(),
|
||||
// not defined by POSIX, but does not harm..
|
||||
new Arglets.SystemIncludePath_C(), new Arglets.LangStd_GCC(), new Arglets.Sysroot_GCC(),
|
||||
new Arglets.IncludeFile_GCC(), new Arglets.MacrosFile_GCC(),
|
||||
// Clang only
|
||||
new Arglets.Target_Clang() };
|
||||
|
||||
final IToolCommandlineParser clang = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
|
||||
btbGcc, clang_args);
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("clang", true, "exe", clang));
|
||||
final IToolCommandlineParser clangxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
|
||||
btbGcc, clang_args);
|
||||
parserDetectors.add(new DefaultToolDetectionParticipant("clang\\+\\+", true, "exe", clangxx));
|
||||
}
|
||||
{
|
||||
// cross compilers, e.g. arm-none-eabi-c++ ====
|
||||
final IToolCommandlineParser cxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
|
||||
|
|
|
@ -483,6 +483,24 @@ public final class Arglets {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* A tool argument parser capable to parse a Clang option to specify the compilation target {@code --target}.
|
||||
*/
|
||||
public static class Target_Clang extends BuiltinDetctionArgsGeneric implements IArglet {
|
||||
private static final Matcher[] optionMatchers = {
|
||||
/* "--target=" triple */
|
||||
Pattern.compile("--target=\\w+(-\\w+)*").matcher("") }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
/*-
|
||||
* @see de.marw.cmake.cdt.lsp.IArglet#processArgs(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
|
||||
return processArgument(resultCollector, argsLine, optionMatchers);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* A tool argument parser capable to parse a GCC option to specify the language
|
||||
|
|
Loading…
Add table
Reference in a new issue