From: Atanas Gegov <[email protected]>
The generation of the toolchain.cmake file happens
just before the exectuion of the configure job.
The current environment of the project is used to
set the values in the toolchain.cmake file.
---
.../YoctoCMakeMakefileGenerator.java | 107 ++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git
a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
index d80f603..b77ae9e 100644
---
a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
+++
b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
@@ -149,6 +149,8 @@ public class YoctoCMakeMakefileGenerator implements
IManagedBuilderMakefileGener
}
monitor.setTaskName(taskName);
+ createToolchainCMakeFile(workingDir);
+
// Create the Makefiles by executing cmake
ExecuteConfigureJob job =
new ExecuteConfigureJob(
@@ -171,4 +173,109 @@ public class YoctoCMakeMakefileGenerator implements
IManagedBuilderMakefileGener
YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.error.makeFileGenerationFailed")),
null); //$NON-NLS-1$
}
}
+
+ private String createCMakeSetStatement(String variable, String value,
String cacheOption) {
+ String setStatement = "set("; //$NON-NLS-1$
+ setStatement += variable + " " + value; //$NON-NLS-1$
+ if(cacheOption != null && !cacheOption.equals("")) {
//$NON-NLS-1$
+ setStatement += " " + cacheOption; //$NON-NLS-1$
+ }
+ setStatement += ")\n"; //$NON-NLS-1$
+ return setStatement;
+ }
+
+ // Considered poky's cmake.bbclass for this method
+ private void createToolchainCMakeFile(IPath workingDir) {
+ String toolchainCMakeFileContentAsString = "# CMake system name
must be something like \"Linux\".\n" + //$NON-NLS-1$
+ "# This is important for cross-compiling.\n";
//$NON-NLS-1$
+
+ String targetArchValue = YoctoSDKUtils.getEnvValue(project,
"TARGET_ARCH"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_SYSTEM_PROCESSOR", targetArchValue, null);
//$NON-NLS-1$
+
+ String oeCMakeCCompilerValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_COMPILER"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_C_COMPILER", oeCMakeCCompilerValue, null);
//$NON-NLS-1$
+
+ String oeCMakeCXXCompilerValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_COMPILER"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_CXX_COMPILER", oeCMakeCXXCompilerValue, null);
//$NON-NLS-1$
+
+ String oeCMakeCFlagsValue = YoctoSDKUtils.getEnvValue(project,
"OECMAKE_C_FLAGS"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_C_FLAGS", //$NON-NLS-1$
+ "\"" + oeCMakeCFlagsValue + "\"", "CACHE STRING
\"CFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ String oeCMakeCXXFlagsValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_CXX_FLAGS", //$NON-NLS-1$
+ "\"" + oeCMakeCXXFlagsValue + "\"", "CACHE
STRING \"CXXFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ String oeCMakeCFlagsReleaseValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_FLAGS_RELEASE"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_C_FLAGS_RELEASE", //$NON-NLS-1$
+ "\"" + oeCMakeCFlagsReleaseValue + "\"", "CACHE
STRING \"CFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ String oeCMakeCXXFlagsReleaseValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS_RELEASE"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_CXX_FLAGS_RELEASE", //$NON-NLS-1$
+ "\"" + oeCMakeCXXFlagsReleaseValue + "\"",
"CACHE STRING \"CXXFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+
+ String oeCMakeCLinkFlagsValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_LINK_FLAGS"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_C_LINK_FLAGS", //$NON-NLS-1$
+ "\"" + oeCMakeCLinkFlagsValue + "\"", "CACHE
STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ String oeCMakeCXXLinkFlagsValue =
YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_LINK_FLAGS"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_CXX_LINK_FLAGS", //$NON-NLS-1$
+ "\"" + oeCMakeCXXLinkFlagsValue + "\"", "CACHE
STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString += "# only search in the
paths provided so cmake doesnt pick\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString += "# up libraries and tools
from the native build machine\n"; //$NON-NLS-1$
+
+ String findRootPathValue = YoctoSDKUtils.getEnvValue(project,
"STAGING_DIR_HOST"); //$NON-NLS-1$
+ findRootPathValue += " "; //$NON-NLS-1$
+ findRootPathValue += YoctoSDKUtils.getEnvValue(project,
"STAGING_DIR_NATIVE"); //$NON-NLS-1$
+ findRootPathValue += " "; //$NON-NLS-1$
+ findRootPathValue += YoctoSDKUtils.getEnvValue(project,
"CROSS_DIR"); //$NON-NLS-1$
+ findRootPathValue += " "; //$NON-NLS-1$
+ findRootPathValue += YoctoSDKUtils.getEnvValue(project,
"OECMAKE_PERLNATIVE_DIR"); //$NON-NLS-1$
+ findRootPathValue += " "; //$NON-NLS-1$
+ findRootPathValue += YoctoSDKUtils.getEnvValue(project,
"OECMAKE_EXTRA_ROOT_PATH"); //$NON-NLS-1$
+ findRootPathValue += " "; //$NON-NLS-1$
+ findRootPathValue += YoctoSDKUtils.getEnvValue(project,
"EXTERNAL_TOOLCHAIN"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_FIND_ROOT_PATH", findRootPathValue, null);
//$NON-NLS-1$
+
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", "ONLY", null);
//$NON-NLS-1$ //$NON-NLS-2$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", "ONLY", null);
//$NON-NLS-1$ //$NON-NLS-2$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "ONLY", null);
//$NON-NLS-1$ //$NON-NLS-2$
+ toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
+
+ toolchainCMakeFileContentAsString += "# Use qt.conf
settings\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("ENV{QT_CONF_PATH}", "qt.conf", null); //$NON-NLS-1$
//$NON-NLS-2$
+ toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
+
+ toolchainCMakeFileContentAsString += "# We need to set the
rpath to the correct directory as cmake does not provide any\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString += "# directory as rpath by
default\n"; //$NON-NLS-1$
+
+ String oeCMakeRPathValue = YoctoSDKUtils.getEnvValue(project,
"OECMAKE_RPATH"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_INSTALL_RPATH", oeCMakeRPathValue, null);
//$NON-NLS-1$
+
+ toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString += "# Use native cmake
modules\n"; //$NON-NLS-1$
+
+ String stagingDatadirValue = YoctoSDKUtils.getEnvValue(project,
"STAGING_DATADIR"); //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_MODULE_PATH", //$NON-NLS-1$
+ stagingDatadirValue + "/cmake/Modules/", null);
//$NON-NLS-1$
+
+ toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString += "# add for non /usr/lib
libdir, e.g. /usr/lib64\n"; //$NON-NLS-1$
+ toolchainCMakeFileContentAsString +=
createCMakeSetStatement("CMAKE_LIBRARY_PATH", //$NON-NLS-1$
+ "${libdir} ${base_libdir}", null); //$NON-NLS-1$
+
+ InputStream toolchainCMakeFileContent = new
ByteArrayInputStream(toolchainCMakeFileContentAsString.getBytes());
+
+ IFile toolchainCMakeFile =
project.getFile(TOOLCHAINCMAKE_FILE_NAME);
+ try {
+ if (toolchainCMakeFile.exists()) {
+ toolchainCMakeFile.delete(true, monitor);
+ }
+ toolchainCMakeFile.create(toolchainCMakeFileContent,
true, monitor);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
}
--
1.7.9.5
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto