summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java
blob: b3d0f2c776c0065ac17271fbcd5eaf89188babd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2013 BMW Car IT GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * BMW Car IT - initial API and implementation
 *******************************************************************************/
package org.yocto.sdk.ide.natures;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.envvar.IContributedEnvironment;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.yocto.sdk.ide.YoctoSDKPlugin;
import org.yocto.sdk.ide.utils.YoctoSDKUtils;

public class YoctoSDKCMakeProjectNature extends YoctoSDKProjectNature {
	public static final  String YoctoSDK_CMAKE_NATURE_ID = YoctoSDKPlugin.getUniqueIdentifier() + ".YoctoSDKCMakeNature";

	// Considered poky's cmake.bbclass for this method
	public static void extendProjectEnvironmentForCMake(IProject project) {
		ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true);
		ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration();
		IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager();
		IContributedEnvironment env = manager.getContributedEnvironment();
		String delimiter = manager.getDefaultDelimiter();

		env.addVariable("CCACHE", "", IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		env.addVariable("OECMAKE_SOURCEPATH", "..",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		String oecmakeBuildPathString = "";
		env.addVariable("OECMAKE_BUILDPATH", oecmakeBuildPathString,
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		env.addVariable("EXTRA_OEMAKE", "-C " + oecmakeBuildPathString,
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		String ccString = YoctoSDKUtils.getEnvValue(project, "CC");

		if (!ccString.equals("") && !ccString.equals(" ")) {
			ccString.trim();
			ccString = ccString.split(" ")[0];
		}

		env.addVariable("OECMAKE_C_COMPILER", ccString,
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		String cxxString = YoctoSDKUtils.getEnvValue(project, "CXX");

		if (!cxxString.equals("") && !cxxString.equals(" ")) {
			cxxString.trim();
			cxxString = cxxString.split(" ")[0];
		}

		env.addVariable("OECMAKE_CXX_COMPILER", cxxString,
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		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 selectedOptimizationString = YoctoSDKUtils.getEnvValue(project, "SELECTED_OPTIMIZATION");
		env.addVariable("OECMAKE_C_FLAGS", hostCCArchString + " " + toolchainOptionsString + " " + cppFlagsString,
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		env.addVariable("OECMAKE_CXX_FLAGS", hostCCArchString + " " + toolchainOptionsString + " " + cxxFlagsString
				+ " -fpermissive",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		env.addVariable("OECMAKE_C_FLAGS_RELEASE", selectedOptimizationString + " " + cppFlagsString + " -DNDEBUG",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		env.addVariable("OECMAKE_CXX_FLAGS_RELEASE", selectedOptimizationString + " " + cxxFlagsString + " -DNDEBUG",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		env.addVariable("OECMAKE_RPATH", "",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);
		env.addVariable("OECMAKE_PERLNATIVE_DIR", "",
				IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc);

		try {
			CoreModel.getDefault().setProjectDescription(project, cpdesc);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}