summaryrefslogtreecommitdiff
path: root/classes/cmake.bbclass
diff options
context:
space:
mode:
authorValentin Longchamp <valentin.longchamp@epfl.ch>2009-10-22 03:08:31 +0000
committerKoen Kooi <koen@openembedded.org>2010-03-27 21:50:18 +0100
commit69c661e671a2cff1b09d8598cf3792e8a0159005 (patch)
tree77ea148025178481a30cac973c2493241c9754ce /classes/cmake.bbclass
parent90869a3727a820b60064c30f05832c7ad3436a27 (diff)
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@epfl.ch>
Diffstat (limited to 'classes/cmake.bbclass')
-rw-r--r--classes/cmake.bbclass41
1 files changed, 39 insertions, 2 deletions
diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
index 706bddae5a..5f1f737397 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