Add toolchain file generation to cmake bbclass
PATCH 1/1 Add toolchain file generation to cmake bbclass
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(-)
classes/cmake.bbclass +66 -1
@@ -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
Quoted 7 lines · Matthew Dombroski
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 had no problem with boost and with Qt4, I have been able to achieve similar results without the toolchain file, only by using a qt.conf file as Zecke had suggested to me.
Although the toolchain file is the preferred value according to the cmake documentation, it has not been necessary to me.
I attach the recipe I use below (and have added a small comment in your patch inline):
Quoted 180 lines
DESCRIPTION = "aseba is an event-based architecture for distributed robots control" HOMEPAGE = "http://mobots.epfl.ch/aseba.html"
LICENCE = "GPL"
PR = "r1"PV = "svn${SRCDATE}"
DEPENDS = "dashel qt4-embedded"LEAD_SONAME= "libasebacore.so"
SRC_URI= "svn://svn.gna.org/svn/aseba;module=trunk"S = "${WORKDIR}/trunk"
inherit qt4e cmake
EXTRA_OECMAKE += "-DSHARED_LIBS:BOOL=ON -DCMD_LINE:BOOL=ON \ -DQT_LIBRARY_DIR=${OE_QMAKE_LIBDIR_QT} \ -DQT_INSTALL_LIBS=${OE_QMAKE_LIBDIR_QT} \ -DQT_INCLUDE_DIR=${OE_QMAKE_INCDIR_QT} \ -DQT_MOC_EXECUTABLE=${OE_QMAKE_MOC} \ -DQT_UIC_EXECUTABLE=${OE_QMAKE_UIC} \ -DQT_UIC3_EXECUTABLE=${OE_QMAKE_UIC3} \ -DQT_RCC_EXECUTABLE=${OE_QMAKE_RCC} \ -DQT_QMAKE_EXECUTABLE=${OE_QMAKE_QMAKE} \ -DQT_QTCORE_INCLUDE_DIR=${OE_QMAKE_INCDIR_QT}/QtCore \ -DQT_DBUSXML2CPP_EXECUTABLE=/usr/bin/qdbusxml2cpp \ -DQT_DBUSCPP2XML_EXECUTABLE=/usr/bin/qdbuscpp2xml \ "export QT_CONF_PATH="${WORKDIR}/trunk/qt.conf"
do_configure_prepend() { echo "[Paths]" > $QT_CONF_PATH echo "Prefix=${STAGING_DIR}/${HOST_SYS}/usr" >> $QT_CONF_PATH echo "Documentation=${docdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Headers=${STAGING_INCDIR}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Libraries=${STAGING_LIBDIR}" >> $QT_CONF_PATH echo "Binaries=${STAGING_BINDIR_NATIVE}" >> $QT_CONF_PATH echo "Plugins=${libdir}/${QT_DIR_NAME}/plugins" >> $QT_CONF_PATH echo "Data=${datadir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Translations=${datadir}/${QT_DIR_NAME}/translations" >> $QT_CONF_PATH echo "Settings=${sysconfdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Examples=${bindir}/${QT_DIR_NAME}/examples" >> $QT_CONF_PATH echo "Demos=${bindir}/${QT_DIR_NAME}/demos" >> $QT_CONF_PATH }do_stage() { oe_libinstall -so libasebacore ${STAGING_LIBDIR} oe_libinstall -so libasebacompiler ${STAGING_LIBDIR} oe_libinstall -so libasebavm ${STAGING_LIBDIR} install -d ${STAGING_INCDIR}/aseba install -d ${STAGING_INCDIR}/aseba/common install -m 0644 common/consts.h ${STAGING_INCDIR}/aseba/common install -m 0644 common/types.h ${STAGING_INCDIR}/aseba/common install -d ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/descriptions-manager.h ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/msg.h ${STAGING_INCDIR}/aseba/msg install -d ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/FormatableString.h ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/utils.h ${STAGING_INCDIR}/aseba/utils }FILES_${PN} += "${libdir}/libasebacore.so"
FILES_${PN} += "${libdir}/libasebacompiler.so"
FILES_${PN} += "${libdir}/libasebavm.so"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(-)classes/cmake.bbclass +6
-0@@ -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"classes/cmake.bbclass +15
-0+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.cmakeclasses/cmake.bbclass +2
-0+ +# only search in the paths provided (from openembedded) so cmake doesntpick
classes/cmake.bbclass +2
-0+# 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.cmakeclasses/cmake.bbclass +2
-0+# Use native cmake modules + echo "set( CMAKE_MODULE_PATH${STAGING_DIR_NATIVE}/usr/share/cmake-2.6/Modules/ )" >> ${WORKDIR}/toolchain.cmake
classes/cmake.bbclass +3
-0+ +# Boost libraries have an unusual naming convention thanks to bjam + echo "set( Boost_COMPILER \"-gcc\" CACHE STRING \"Boost gcc string\")" >> ${WORKDIR}/toolchain.cmake
classes/cmake.bbclass +2
-0+ +# Qt4 support is complex because FindQt4.cmake requires a lot ofinformation
classes/cmake.bbclass +6
-0+# 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 \"Qt4include 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.cmakeclasses/cmake.bbclass +4
-0+ fi +} + + cmake_do_configure() { if [ ${OECMAKE_BUILDPATH} ] then@@ -18,9 +79,13 @@ cmake_do_configure() { cd ${OECMAKE_BUILDPATH} fi
classes/cmake.bbclass cmake_do_configure() { · line 90
Quoted 10 lines
classes/cmake.bbclass +5
-1+ 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
With my above config file, here is what I have to the cmake command:
Quoted 8 lines
classes/cmake.bbclass +0
-0cmake ${OECMAKE_SOURCEPATH} \-DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ -DCMAKE_FIND_ROOT_PATH="${STAGING_DIR_HOST};${STAGING_DIR_NATIVE}" \ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ ${EXTRA_OECMAKE} \ -Wno-dev
which is similar to what you had in your toolchain.cmake file.
Quoted 3 lines
}
Signature · 1 line
1.6.3.3
Quoted 5 lines · On Tuesday 25 August 2009 11:07:47 Valentin Longchamp wrote:
Quoted 4 lines · Matthew Dombroski
It is possible to make cmake use a toolchain file that defines flags, search
paths and any other cmake options.
Quoted 8 lines
Quoted 4 lines
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 had no problem with boost and with Qt4, I have been able to achieve similar results without the toolchain file, only by using a qt.conf file as Zecke had suggested to me.
Hey,
could you come up with a patch or help me to work on a patch?
z.
Quoted 10 lines · Holger Hans Peter Freyther
Quoted 9 lines · On Tuesday 25 August 2009 11:07:47 Valentin Longchamp wrote:
Quoted 8 lines · Matthew Dombroski
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.
Quoted 7 lines
Quoted 3 lines
I have had no problem with boost and with Qt4, I have been able to achieve similar results without the toolchain file, only by using a qt.conf file as Zecke had suggested to me.
Hey,
could you come up with a patch or help me to work on a patch?
With great pleasure.
I have already posted the recipe I use for qt4/cmake build, the FindQt4.cmake module patch is the same Matthew posted earlier today, and here is my cmake patch.
Don't hesitate to ask if you need more info (I'll try to be on IRC, Longfield)
Val
From 290226efcab3375808924efb03d264534ab97984 Mon Sep 17 00:00:00 2001
From: Valentin Longchamp <[email protected]>
Date: Thu, 18 Jun 2009 18:49:04 +0200
Subject: [PATCH 1/1] render cmake search path stricter
The search is only done in the STAGING directy: all the needed tools should be there (already built) and all the libs and header are there too. With this, we are sure that we do not mix with the host libs, headers or tools.
--- classes/cmake.bbclass | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
classes/cmake.bbclass +4 -1
@@ -20,7 +20,10 @@ cmake_do_configure() { cmake ${OECMAKE_SOURCEPATH} \ -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ - -DCMAKE_FIND_ROOT_PATH=${STAGING_DIR_HOST} \ + -DCMAKE_FIND_ROOT_PATH="${STAGING_DIR_HOST};${STAGING_DIR_NATIVE}" \ + -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \ + -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ + -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ ${EXTRA_OECMAKE} \ -Wno-dev }
Signature · 1 line
1.6.0.4
Quoted 3 lines
I have had no problem with boost and with Qt4, I have been able to achieve similar results without the toolchain file, only by using a qt.conf file as Zecke had suggested to me.
I'm using boost-1.39 and found i needed to set Boost_COMPILER or it wouldn't find libraries. (Oh how I hate bjam, but thats another story...)
Setting Qt environment data in cmake.bbclass may seem a bit out of place. When you consider that cmake is distributed with scripts for configuring/detecting Qt it doesn't seem too bad. It is definitly tidier than generating a qt.conf in every recipe. Adding all the Qt info in EXTRA_OECMAKE is doing the same work twice.
Quoted 2 lines
Although the toolchain file is the preferred value according to the cmake documentation, it has not been necessary to me.
The effect of a toolchain file is the same as that of defining lots of options in EXTRA_OECMAKE. personally, I think it is cleaner. The ability to use it outside of openembedded is really useful to me also.
~Matt
begin:vcard
fn:Matthew Dombroski
n:Dombroski;Matthew
org:4D Electronics Limited
adr:Sydenham;;54 Wordsworth St;Christchurch;;8013;New Zealand email;internet:[email protected] tel;work:(643) 982 1113
tel;cell:0211321773
x-mozilla-html:FALSE
url:www.4d-electronics.co.nz
version:2.1
end:vcard
Quoted 4 lines · Matthew Dombroski
Quoted 3 lines
I have had no problem with boost and with Qt4, I have been able to achieve similar results without the toolchain file, only by using a qt.conf file as Zecke had suggested to me.
I'm using boost-1.39 and found i needed to set
Boost_COMPILERor it wouldn't find libraries. (Oh how I hate bjam, but thats another story...)
Ok, I think I had 1.36.
Quoted 3 lines
Setting Qt environment data in cmake.bbclass may seem a bit out of place. When you consider that cmake is distributed with scripts for configuring/detecting Qt it doesn't seem too bad. It is definitly tidier than generating a qt.conf in every recipe. Adding all the Qt info in
EXTRA_OECMAKEis doing the same work twice.
Well that's a point of view. From my point of view, not all cmake based programs need that qt info, that's why I find it's cleaner to enable it in the recipes that need these libraries.
About adding the EXTRA_OECMAKE, I have to check, but I think I needed to define some so that the right qmake is found. I will try without or by adding only the needed definitions.
Quoted 6 lines
Quoted 3 lines
Although the toolchain file is the preferred value according to the cmake documentation, it has not been necessary to me.
The effect of a toolchain file is the same as that of defining lots of options in
EXTRA_OECMAKE. personally, I think it is cleaner. The ability to use it outside of openembedded is really useful to me also.
I agree that it is the same. It's just that it was done until now like that in OE, so I chose that way. However one advantage that I see of defining things directly in the recipes and not in a toolchain file, is that you can easily add definitions using EXTRA_OECMAKE in every recipe. Is cmake able to take two toolchain files (one from cmake.bbclass and one from the recipes with the needed libraries) without having to rewrite the do_configure in the recipe ?
This comes back to the point above: do we need to define all the libraries that could come with cmake-based programs in cmake.bbclass ? From my point of view, this is definitely something related to the recipes.
Val
Quoted 9 lines · Valentin Longchamp
Quoted 3 lines · Matthew Dombroski
Setting Qt environment data in cmake.bbclass may seem a bit out of place. When you consider that cmake is distributed with scripts for configuring/detecting Qt it doesn't seem too bad. It is definitly tidier than generating a qt.conf in every recipe. Adding all the Qt info in
EXTRA_OECMAKEis doing the same work twice.Well that's a point of view. From my point of view, not all cmake based programs need that qt info, that's why I find it's cleaner to enable it in the recipes that need these libraries.
About adding the
EXTRA_OECMAKE, I have to check, but I think I needed to define some so that the right qmake is found. I will try without or by adding only the needed definitions.
I have tried it, and the only thing I now have in the EXTRA_OECMAKE is QT_QMAKE_EXECUTABLE to be sure that it takes the one from staging and not the one from my system.
Quoted 56 lines
DESCRIPTION = "aseba is an event-based architecture for distributed robots control" HOMEPAGE = "http://mobots.epfl.ch/aseba.html"
LICENCE = "GPL"
PR = "r1"PV = "svn${SRCDATE}"
DEPENDS = "dashel qt4-embedded"LEAD_SONAME= "libasebacore.so"
SRC_URI= "svn://svn.gna.org/svn/aseba;module=trunk"S = "${WORKDIR}/trunk"
inherit qt4e cmake
EXTRA_OECMAKE += "-DSHARED_LIBS:BOOL=ON -DCMD_LINE:BOOL=ON \ -DQT_QMAKE_EXECUTABLE=${OE_QMAKE_QMAKE} \ "export QT_CONF_PATH="${WORKDIR}/trunk/qt.conf"
do_configure_prepend() { echo "[Paths]" > $QT_CONF_PATH echo "Prefix=${STAGING_DIR}/${HOST_SYS}/usr" >> $QT_CONF_PATH echo "Documentation=${docdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Headers=${STAGING_INCDIR}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Libraries=${STAGING_LIBDIR}" >> $QT_CONF_PATH echo "Binaries=${STAGING_BINDIR_NATIVE}" >> $QT_CONF_PATH echo "Plugins=${libdir}/${QT_DIR_NAME}/plugins" >> $QT_CONF_PATH echo "Data=${datadir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Translations=${datadir}/${QT_DIR_NAME}/translations" >> $QT_CONF_PATH echo "Settings=${sysconfdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Examples=${bindir}/${QT_DIR_NAME}/examples" >> $QT_CONF_PATH echo "Demos=${bindir}/${QT_DIR_NAME}/demos" >> $QT_CONF_PATH }do_stage() { oe_libinstall -so libasebacore ${STAGING_LIBDIR} oe_libinstall -so libasebacompiler ${STAGING_LIBDIR} oe_libinstall -so libasebavm ${STAGING_LIBDIR} install -d ${STAGING_INCDIR}/aseba install -d ${STAGING_INCDIR}/aseba/common install -m 0644 common/consts.h ${STAGING_INCDIR}/aseba/common install -m 0644 common/types.h ${STAGING_INCDIR}/aseba/common install -d ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/descriptions-manager.h ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/msg.h ${STAGING_INCDIR}/aseba/msg install -d ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/FormatableString.h ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/utils.h ${STAGING_INCDIR}/aseba/utils }FILES_${PN} += "${libdir}/libasebacore.so"
FILES_${PN} += "${libdir}/libasebacompiler.so"
FILES_${PN} += "${libdir}/libasebavm.so"
Quoted 25 lines
I have tried it, and the only thing I now have in the
EXTRA_OECMAKEisQT_QMAKE_EXECUTABLEto be sure that it takes the one from staging and not the one from my system.Quoted 23 lines
inherit qt4e cmake
EXTRA_OECMAKE += "-DSHARED_LIBS:BOOL=ON -DCMD_LINE:BOOL=ON \ -DQT_QMAKE_EXECUTABLE=${OE_QMAKE_QMAKE} \ "export QT_CONF_PATH="${WORKDIR}/trunk/qt.conf"
do_configure_prepend() { echo "[Paths]" > $QT_CONF_PATH echo "Prefix=${STAGING_DIR}/${HOST_SYS}/usr" >> $QT_CONF_PATH echo "Documentation=${docdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Headers=${STAGING_INCDIR}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Libraries=${STAGING_LIBDIR}" >> $QT_CONF_PATH echo "Binaries=${STAGING_BINDIR_NATIVE}" >> $QT_CONF_PATH echo "Plugins=${libdir}/${QT_DIR_NAME}/plugins" >> $QT_CONF_PATH echo "Data=${datadir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Translations=${datadir}/${QT_DIR_NAME}/translations" >> $QT_CONF_PATH echo "Settings=${sysconfdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Examples=${bindir}/${QT_DIR_NAME}/examples" >> $QT_CONF_PATH echo "Demos=${bindir}/${QT_DIR_NAME}/demos" >> $QT_CONF_PATH }
That looks quite good now, maybe it's a good idea to add a generate_qt_conf() to qmake2.bbclass. That way it's independent of what build system we're using.
~Matt
Quoted 26 lines
Quoted 26 lines
I have tried it, and the only thing I now have in the
EXTRA_OECMAKEisQT_QMAKE_EXECUTABLEto be sure that it takes the one from staging and not the one from my system.Quoted 23 lines
inherit qt4e cmake
EXTRA_OECMAKE += "-DSHARED_LIBS:BOOL=ON -DCMD_LINE:BOOL=ON \ -DQT_QMAKE_EXECUTABLE=${OE_QMAKE_QMAKE} \ "export QT_CONF_PATH="${WORKDIR}/trunk/qt.conf"
do_configure_prepend() { echo "[Paths]" > $QT_CONF_PATH echo "Prefix=${STAGING_DIR}/${HOST_SYS}/usr" >> $QT_CONF_PATH echo "Documentation=${docdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Headers=${STAGING_INCDIR}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Libraries=${STAGING_LIBDIR}" >> $QT_CONF_PATH echo "Binaries=${STAGING_BINDIR_NATIVE}" >> $QT_CONF_PATH echo "Plugins=${libdir}/${QT_DIR_NAME}/plugins" >> $QT_CONF_PATH echo "Data=${datadir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Translations=${datadir}/${QT_DIR_NAME}/translations" >> $QT_CONF_PATH echo "Settings=${sysconfdir}/${QT_DIR_NAME}" >> $QT_CONF_PATH echo "Examples=${bindir}/${QT_DIR_NAME}/examples" >> $QT_CONF_PATH echo "Demos=${bindir}/${QT_DIR_NAME}/demos" >> $QT_CONF_PATH }
Quoted 2 lines
That looks quite good now, maybe it's a good idea to add a
generate_qt_conf()to qmake2.bbclass. That way it's independent of what build system we're using.
Have tried it, didn't work.
cmake is able to find libs, headers and some executables but a lot of stuff is unfound.
~Matt
BTW, while you're on cmake, please consider acking this one:
http://lists.linuxtogo.org/pipermail/openembedded-devel/2009-April/009958.html
Quoted 5 lines · Valentin Longchamp
Quoted 4 lines · Matthew Dombroski
Quoted 3 lines
Although the toolchain file is the preferred value according to the cmake documentation, it has not been necessary to me.
Quoted 9 lines
Quoted 2 lines
The effect of a toolchain file is the same as that of defining lots of options in
EXTRA_OECMAKE. personally, I think it is cleaner. The ability to use it outside of openembedded is really useful to me also.I agree that it is the same. It's just that it was done until now like that in OE, so I chose that way. However one advantage that I see of defining things directly in the recipes and not in a toolchain file, is that you can easily add definitions using
EXTRA_OECMAKEin every recipe. Is cmake able to take two toolchain files (one from cmake.bbclass and one from the recipes with the needed libraries) without having to rewrite thedo_configurein the recipe ?This comes back to the point above: do we need to define all the libraries that could come with cmake-based programs in cmake.bbclass ?
From my point of view, this is definitely something related to the
recipes.
I have been thinking about this today I here is a proposition that takes the better of both our approaches. I agree that having the toolchain file is much cleaner, however it should be possible to add things to this toolchain file in the recipes according to what libraries are needed.
So I have added a task that generates a generic toolchain file, and the idea is to add all the needed defines for additionnal libraries in the recipe, in a do_generate_toolchain_file_append() function.
Here is my example recipe, sending the patch with git.
Val
Quoted 51 lines
DESCRIPTION = "aseba is an event-based architecture for distributed robots control" HOMEPAGE = "http://mobots.epfl.ch/aseba.html"
LICENCE = "GPL"
PR = "r1"PV = "svn${SRCDATE}"
DEPENDS = "dashel qt4-embedded"LEAD_SONAME= "libasebacore.so"
SRC_URI= "svn://svn.gna.org/svn/aseba;module=trunk"S = "${WORKDIR}/trunk"
inherit qt4e cmake
EXTRA_OECMAKE+= "-DSHARED_LIBS:BOOL=ON -DCMD_LINE:BOOL=ON"do_generate_toolchain_file_append() { 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 }do_stage() { oe_libinstall -so libasebacore ${STAGING_LIBDIR} oe_libinstall -so libasebacompiler ${STAGING_LIBDIR} oe_libinstall -so libasebavm ${STAGING_LIBDIR} install -d ${STAGING_INCDIR}/aseba install -d ${STAGING_INCDIR}/aseba/common install -m 0644 common/consts.h ${STAGING_INCDIR}/aseba/common install -m 0644 common/types.h ${STAGING_INCDIR}/aseba/common install -d ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/descriptions-manager.h ${STAGING_INCDIR}/aseba/msg install -m 0644 msg/msg.h ${STAGING_INCDIR}/aseba/msg install -d ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/FormatableString.h ${STAGING_INCDIR}/aseba/utils install -m 0644 utils/utils.h ${STAGING_INCDIR}/aseba/utils }FILES_${PN} += "${libdir}/libasebacore.so"
FILES_${PN} += "${libdir}/libasebacompiler.so"
FILES_${PN} += "${libdir}/libasebavm.so"
PATCH 1/1 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.
--- classes/cmake.bbclass | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-)
classes/cmake.bbclass +26 -2
@@ -11,6 +11,29 @@ OECMAKE_SOURCEPATH ?= "." # "-C ${OECMAKE_BUILDPATH}". So it will run the right makefiles. OECMAKE_BUILDPATH ?= "" +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,9 +43,10 @@ cmake_do_configure() { cmake ${OECMAKE_SOURCEPATH} \ -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ - -DCMAKE_FIND_ROOT_PATH=${STAGING_DIR_HOST} \ + -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \ + -DCMAKE_VERBOSE_MAKEFILE=1 \ ${EXTRA_OECMAKE} \ -Wno-dev } -EXPORT_FUNCTIONS do_configure +EXPORT_FUNCTIONS do_configure do_generate_toolchain_file
Signature · 1 line
1.6.0.4