[oe-commits] Valentin Longchamp : cmake.bbclass: add toolchain file for cmake compilations

git version control git at git.openembedded.org
Sat Mar 27 20:50:40 UTC 2010


Module: openembedded.git
Branch: org.openembedded.dev
Commit: 69c661e671a2cff1b09d8598cf3792e8a0159005
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=69c661e671a2cff1b09d8598cf3792e8a0159005

Author: Valentin Longchamp <valentin.longchamp at epfl.ch>
Date:   Thu Oct 22 03:08:31 2009 +0000

cmake.bbclass: add toolchain file for cmake compilations

Based on work done by Matthew Dombroski.
We want to generate a toolchain file for cmake compilations. This
adds a task that is performed before the configure task.

Additional defines can be made in the toolchain file directly in
the recipe file by using a do_generate_toolchain_file_append().
This is especially interesting for recipes that need to define
values for additionnal libraries.

Signed-off-by: Valentin Longchamp <valentin.longchamp at epfl.ch>

---

 classes/cmake.bbclass |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
index 706bdda..5f1f737 100644
--- a/classes/cmake.bbclass
+++ b/classes/cmake.bbclass
@@ -1,5 +1,8 @@
 DEPENDS += " cmake-native "
 
+# We need to unset CCACHE otherwise cmake gets too confused
+CCACHE = ""
+
 # We want the staging and installing functions from autotools
 inherit autotools_stage
 
@@ -11,6 +14,39 @@ OECMAKE_SOURCEPATH ?= "."
 # "-C ${OECMAKE_BUILDPATH}". So it will run the right makefiles.
 OECMAKE_BUILDPATH ?= ""
 
+# C/C++ Compiler (without cpu arch/tune arguments)
+OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`"
+OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`"
+
+# Compiler flags
+OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${BUILD_CPPFLAGS}"
+OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${BUILD_CPPFLAGS} -fpermissive"
+OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
+OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
+
+cmake_do_generate_toolchain_file() {
+# CMake system name must be something like "Linux".
+# This is important for cross-compiling.
+  echo "set( CMAKE_SYSTEM_NAME" `echo ${SDK_OS} | sed 's/^./\u&/'` ")" > ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_C_FLAGS \"${OECMAKE_C_FLAGS}\" CACHE STRING \"OpenEmbedded CFLAGS\" )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_CXX_FLAGS \"${OECMAKE_CXX_FLAGS}\" CACHE STRING \"OpenEmbedded CXXFLAGS\" )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_C_FLAGS_RELEASE \"${OECMAKE_C_FLAGS_RELEASE}\" CACHE STRING \"CFLAGS for release\" )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_CXX_FLAGS_RELEASE \"${OECMAKE_CXX_FLAGS_RELEASE}\" CACHE STRING \"CXXFLAGS for release\" )" >> ${WORKDIR}/toolchain.cmake
+
+# only search in the paths provided (from openembedded) so cmake doesnt pick
+# up libraries and tools from the native build machine
+  echo "set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )" >> ${WORKDIR}/toolchain.cmake
+  echo "set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )" >> ${WORKDIR}/toolchain.cmake
+# Use native cmake modules
+  echo "set( CMAKE_MODULE_PATH ${STAGING_DIR_NATIVE}/usr/share/cmake-2.6/Modules/ )" >> ${WORKDIR}/toolchain.cmake
+}
+
+addtask generate_toolchain_file after do_patch before do_configure
+
 cmake_do_configure() {
   if [ ${OECMAKE_BUILDPATH} ]
   then
@@ -20,8 +56,9 @@ cmake_do_configure() {
 
   cmake ${OECMAKE_SOURCEPATH} \
     -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \
-    -DCMAKE_FIND_ROOT_PATH:PATH=${STAGING_DIR_HOST} \
     -DCMAKE_INSTALL_SO_NO_EXE=0 \
+	-DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \
+	-DCMAKE_VERBOSE_MAKEFILE=1 \
     ${EXTRA_OECMAKE} \
     -Wno-dev
 }
@@ -44,4 +81,4 @@ cmake_do_install() {
   autotools_do_install
 }
 
-EXPORT_FUNCTIONS do_configure do_compile do_install
+EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file





More information about the Openembedded-commits mailing list