From: Matthew Dombroski <matthew@4d-electronics.co.nz>
To: openembedded dev <openembedded-devel@lists.openembedded.org>
Subject: [PATCH] Add toolchain file generation to cmake bbclass
Date: Tue, 25 Aug 2009 17:35:45 +1200 [thread overview]
Message-ID: <4A937831.2000304@4d-electronics.co.nz> (raw)
It is possible to make cmake use a toolchain file that defines flags, search
paths and any other cmake options.
The main reason for making openembedded generate a toolchain file is
to enable the building of complex packages. Without it a package
requiring Qt4 or boost (or one of many other packages) probably wont find
the right libs and won't build properly.
I have added compiler flags mainly for use outside of openembedded, so I
can copy the generated toolchain file and use it manually.
---
classes/cmake.bbclass | 67
++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 1 deletions(-)
diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
index b5b7b86..38bed63 100644
--- a/classes/cmake.bbclass
+++ b/classes/cmake.bbclass
@@ -11,6 +11,67 @@ 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"
+
+
+#
+# Generate cmake toolchain file
+#
+cmake_generate_toolchain_file() {
+ rm -f ${WORKDIR}/toolchain.cmake
+ touch ${WORKDIR}/toolchain.cmake
+
+# 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
+
+# Boost libraries have an unusual naming convention thanks to bjam
+ echo "set( Boost_COMPILER \"-gcc\" CACHE STRING \"Boost gcc string\"
)" >> ${WORKDIR}/toolchain.cmake
+
+# Qt4 support is complex because FindQt4.cmake requires a lot of
information
+# about the Qt environment.
+ if [ ${QMAKESPEC} ]
+ then
+# In the bbfile inherit one of qmake2/qt4e/qt4x11 and this section will be
+# filled out
+ echo "set( QT_HEADERS_DIR ${OE_QMAKE_INCDIR_QT} CACHE STRING \"Qt4
include dir\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_LIBRARY_DIR ${OE_QMAKE_LIBDIR_QT} CACHE STRING \"Qt4
library dir\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_QMAKE_EXECUTABLE ${OE_QMAKE_QMAKE} CACHE STRING
\"qmake2 binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_MOC_EXECUTABLE ${OE_QMAKE_MOC} CACHE STRING \"Qt4 moc
binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_UIC_EXECUTABLE ${OE_QMAKE_UIC} CACHE STRING \"Qt4 uic
binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_UIC3_EXECUTABLE ${OE_QMAKE_UIC3} CACHE STRING \"Qt4
uic3 binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_RCC_EXECUTABLE ${OE_QMAKE_RCC} CACHE STRING \"Qt4 rcc
binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_DBUSXML2CPP_EXECUTABLE ${OE_QMAKE_QDBUSXML2CPP} CACHE
STRING \"Qt4 dbus xml2cpp binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_DBUSCPP2XML_EXECUTABLE ${OE_QMAKE_QDBUSCPP2XML} CACHE
STRING \"Qt4 dbus cpp2xml binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_LRELEASE_EXECUTABLE ${OE_QMAKE_LRELEASE} CACHE STRING
\"Qt4 lrelease binary\" )" >> ${WORKDIR}/toolchain.cmake
+ echo "set( QT_LUPDATE_EXECUTABLE ${OE_QMAKE_LUPDATE} CACHE STRING
\"Qt4 lupdate binary\" )" >> ${WORKDIR}/toolchain.cmake
+ fi
+}
+
+
cmake_do_configure() {
if [ ${OECMAKE_BUILDPATH} ]
then
@@ -18,9 +79,13 @@ cmake_do_configure() {
cd ${OECMAKE_BUILDPATH}
fi
+ cmake_generate_toolchain_file
+
cmake ${OECMAKE_SOURCEPATH} \
+ -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \
-DCMAKE_INSTALL_PREFIX:PATH=${prefix} \
- -DCMAKE_FIND_ROOT_PATH=${STAGING_DIR_HOST} \
+ -DCMAKE_VERBOSE_MAKEFILE=1 \
+ -DCMAKE_BUILD_TYPE=Release \
${EXTRA_OECMAKE} \
-Wno-dev
}
--
1.6.3.3
next reply other threads:[~2009-08-25 5:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-25 5:35 Matthew Dombroski [this message]
2009-08-25 9:07 ` [PATCH] Add toolchain file generation to cmake bbclass Valentin Longchamp
2009-08-25 11:03 ` Holger Hans Peter Freyther
2009-08-25 15:48 ` Valentin Longchamp
2009-08-25 22:12 ` Matthew Dombroski
2009-08-26 6:47 ` Valentin Longchamp
2009-08-26 11:04 ` Valentin Longchamp
2009-08-26 21:36 ` Matthew Dombroski
2009-08-26 22:38 ` Matthew Dombroski
2009-08-27 4:28 ` Roman I Khimov
2009-08-26 17:21 ` Valentin Longchamp
2009-08-26 17:28 ` [PATCH 1/1] add toolchain file for cmake compilations Valentin Longchamp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A937831.2000304@4d-electronics.co.nz \
--to=matthew@4d-electronics.co.nz \
--cc=openembedded-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.