Cmake cross-compile file
Hello,
I had already posted this patch earlier bit I got no comment. It allows cmake to work with cross-compile files where the needed paths, options and programs are given, which is the recommended way of doing cross-compilation with cmake according to their documentation.
Furthermore, you can add additionnal path in individual recipes by writing into the cross-compile file in the do_generate_toolchain_file_append() task as done below for qt4 for instance.
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
}I have been using it in my overlay for quite some time with various cmake based recipes we have here and I definitely think it would deserve OE inlcusion.
Comment welcome
Val
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 | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-)
classes/cmake.bbclass +37 -2
@@ -11,6 +11,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,9 +53,11 @@ 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
Quoted 6 lines
I had already posted this patch earlier bit I got no comment. It allows cmake to work with cross-compile files where the needed paths, options and programs are given, which is the recommended way of doing cross-compilation with cmake according to their documentation.
Quoted 10 lines
Furthermore, you can add additionnal path in individual recipes by writing into the cross-compile file in the
do_generate_toolchain_file_append()task as done below for qt4 for instance.I have been using it in my overlay for quite some time with various cmake based recipes we have here and I definitely think it would deserve OE inlcusion.
I have been using the same system for cmake too, with one small change - I have made the toolchain path configurable. OECMAKE_TOOLCHAIN_FILE ?= "${WORKDIR}/toolchain.cmake"
~Matthew