[yocto] [eclipse-poky][PATCH] org.yocto.sdk.ide: Use CFLAGS from CC variable in cmake toolchain file

Thomas Elste thomas.elste at imms.de
Thu Apr 7 07:52:32 PDT 2016


The CC and CXX variables imported from the Yocto build environment
may contain additional compiler flags after the compiler name. Extract
those and add them to cmake toolchain file variables, too.

Signed-off-by: Thomas Elste <thomas.elste at imms.de>
---

Hi,

using the Yocto plugin for Eclipse to generate CMake based C projects
I've encountered a problem. I'm using a standalone armhf toolchain
(ADT) for building the project. Compiling works fine but linkings fails
due to a mismatch in the FP ABI of object files and target sysroot
libraries.

This happens as the compiler is not called with all the flags
necessary. The flags which appear in the environment file of the ADT in
the CC/CXX variable are not present. For example CC for my toolchain
looks like this:

export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfloat-abi=hard
-mfpu=neon -mtune=cortex-a7 --sysroot=$SDKTARGETSYSROOT"

Everything after the compiler name does not get integrated into the
CMake toolchain file generated by the Eclipse plugin (which in case of
the float-abi flag leads to the previous mentioned build error).

So I propose the attached patch, which adds everything found (except
sysroot entries) after the compiler name in the C/CXX build environment
variable to the CMake toolchain file (OECMAKE_C_FLAGS, etc.).


Best regards
Thomas

 .../ide/natures/YoctoSDKCMakeProjectNature.java    | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java
index b3d0f2c..44ccfe6 100644
--- a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java
@@ -45,19 +45,33 @@ public class YoctoSDKCMakeProjectNature extends YoctoSDKProjectNature {
 				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
 
 		String ccString = YoctoSDKUtils.getEnvValue(project, "CC");
+		String ccFlagsString = "";
 
 		if (!ccString.equals("") && !ccString.equals(" ")) {
 			ccString.trim();
-			ccString = ccString.split(" ")[0];
+			String[] ccSplitString = ccString.split(" ");
+			ccString = ccSplitString[0];
+
+			for(int i=1; i<ccSplitString.length; i++) {
+				if(ccSplitString[i].indexOf("sysroot")<0)
+					ccFlagsString+=ccSplitString[i] + " ";
+			}
 		}
 
 		env.addVariable("OECMAKE_C_COMPILER", ccString,
 				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
 		String cxxString = YoctoSDKUtils.getEnvValue(project, "CXX");
+		String cxxFlagsString = "";
 
 		if (!cxxString.equals("") && !cxxString.equals(" ")) {
 			cxxString.trim();
-			cxxString = cxxString.split(" ")[0];
+			String[] cxxSplitString = cxxString.split(" ");
+			cxxString = cxxSplitString[0];
+
+			for(int i=1; i<cxxSplitString.length; i++) {
+				if(cxxSplitString[i].indexOf("sysroot")<0)
+					cxxFlagsString+=cxxSplitString[i] +  " ";
+			}
 		}
 
 		env.addVariable("OECMAKE_CXX_COMPILER", cxxString,
@@ -65,8 +79,8 @@ public class YoctoSDKCMakeProjectNature extends YoctoSDKProjectNature {
 
 		String hostCCArchString = YoctoSDKUtils.getEnvValue(project, "HOST_CC_ARCH");
 		String toolchainOptionsString = YoctoSDKUtils.getEnvValue(project, "TOOLCHAIN_OPTIONS");
-		String cppFlagsString = YoctoSDKUtils.getEnvValue(project, "CPPFLAGS");
-		String cxxFlagsString = YoctoSDKUtils.getEnvValue(project, "CXXFLAGS");
+		String cppFlagsString = YoctoSDKUtils.getEnvValue(project, "CPPFLAGS") + " " + ccFlagsString;
+		cxxFlagsString = YoctoSDKUtils.getEnvValue(project, "CXXFLAGS") + " " + cxxFlagsString;
 		String selectedOptimizationString = YoctoSDKUtils.getEnvValue(project, "SELECTED_OPTIMIZATION");
 		env.addVariable("OECMAKE_C_FLAGS", hostCCArchString + " " + toolchainOptionsString + " " + cppFlagsString,
 				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
-- 
2.4.10




More information about the yocto mailing list