From cee1edf30a6ce58e2c9812adfe89b03f26f4116a Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 22 Jan 2013 22:35:08 +0100 Subject: [PATCH 3/3] Fixed crosscompiling on linux opensuse. --- README.cmake | 15 +++++++++++++++ cmake/CMakeLists.txt | 2 +- cmake/cross-compile.sh | 24 ++++++++++++++---------- cmake/doc/CMakeLists.txt | 16 +++++++--------- cmake/modules/FindLibExpat.cmake | 26 +++++++++++++++++--------- cmake/modules/Macros.cmake | 6 +++--- 6 Dateien geändert, 57 Zeilen hinzugefügt(+), 32 Zeilen entfernt(-) diff --git a/README.cmake b/README.cmake index 5feaf55..a319b68 100644 --- a/README.cmake +++ b/README.cmake @@ -73,6 +73,21 @@ Linux make make install +Crosscompile on Linux +1. install required tools + opensuse 12.2 + zypper ar http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_12.2/windows:mingw:win32.repo + zypper install mingw32-cross-gcc mingw32-cross-gcc-c++ mingw32-libexpat-devel + zypper install binutils git +2. get dbus sources +3. unpack dbus sources into a sub directory (referred as later) +4. mkdir dbus-build +5. cd dbus-build +6. run + /cmake/cross-compile.sh + make + make install + For other compilers see cmake --help in the Generators section Configuration flags diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 0459695..abef49e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -433,7 +433,7 @@ endif (WIN32) set (DBUS_USER ) -if (WIN32) +if (WIN32 OR CMAKE_CROSSCOMPILING) set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "nonce-tcp:" CACHE STRING "system bus default address") set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "nonce-tcp:" CACHE STRING "session bus default address") diff --git a/cmake/cross-compile.sh b/cmake/cross-compile.sh index 49e66e5..142d604 100755 --- a/cmake/cross-compile.sh +++ b/cmake/cross-compile.sh @@ -1,17 +1,23 @@ #!/bin/sh # # cross compile script for cmake -# +# # initial written by Fridrich Strba # refactored to debian/lenny by Ralf Habacker +# refactored to opensuse by Ralf Habacker # -# reported to work at least on debian/lenny +# reported to work at least on debian/lenny # - +cc_postfix= if test -f /usr/bin/i686-pc-mingw32-gcc; then cross_cc=i686-pc-mingw32 elif test -f /usr/bin/i586-mingw32msvc-gcc; then cross_cc=i586-mingw32msvc +elif test -f /usr/bin/i686-w64-mingw32-gcc-4.7.2; then + cross_cc=i686-w64-mingw32 + cc_postfix=-4.7.2 +elif test -f /usr/bin/i686-w64-mingw32-gcc; then + cross_cc=i686-w64-mingw32 else echo "could not determine mingw cross compiler" exit 1 @@ -47,7 +53,7 @@ if test -d "$MINGW32_CLASSPATH" || test -f "$cross_root/share/java/libgcj.jar"; fi _PREFIX="/usr/bin/$cross_cc-"; -for i in `ls -1 ${_PREFIX}* | grep -v 'gcc-'`; do +for i in `ls -1 ${_PREFIX}* | grep -v 'gcc-' | grep -v 'ld.bfd'`; do x=`echo $i|sed "s,${_PREFIX},,"|sed "s,\.awk*,,"|tr "a-z+-" "A-ZX_"`; declare -x $x="$i" ; export $x; done; @@ -79,7 +85,7 @@ if ! test -f "$cross_root/lib/libexpat.dll.a"; then fi if test -f "$cross_root/lib/libexpat.dll.a"; then - xml_library=-DDBUS_USE_EXPAT=On -DLIBEXPAT_INCLUDE_DIR:PATH=$cross_root/include -DLIBEXPAT_LIBRARIES:PATH=$cross_root/lib/libexpat.dll.a + xml_library="-DDBUS_USE_EXPAT=On -DLIBEXPAT_INCLUDE_DIR:PATH=$cross_root/include -DLIBEXPAT_LIBRARIES:PATH=$cross_root/lib/libexpat.dll.a" else echo "could not find a cross compile xml libraray" exit 1 @@ -95,16 +101,14 @@ cmake \ -DSYSCONF_INSTALL_DIR:PATH=$cross_root/etc \ -DSHARE_INSTALL_PREFIX:PATH=$cross_root/share \ -DBUILD_SHARED_LIBS:BOOL=ON \ - -DCMAKE_C_COMPILER="/usr/bin/$cross_cc-gcc" \ - -DCMAKE_CXX_COMPILER="/usr/bin/$cross_cc-g++" \ - -DCMAKE_FIND_ROOT_PATH="$cross_root" \ - -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ - -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ + -DCMAKE_C_COMPILER="/usr/bin/$cross_cc-gcc$cc_postfix" \ -DCMAKE_CXX_COMPILER="/usr/bin/$cross_cc-g++" \ + -DCMAKE_RC_COMPILER="/usr/bin/$cross_cc-windres" \ -DCMAKE_FIND_ROOT_PATH="$cross_root" \ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ $xml_library \ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ + -DDBUS_SESSION_BUS_DEFAULT_ADDRESS="autolaunch:" \ $* diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt index df6b587..e107918 100644 --- a/cmake/doc/CMakeLists.txt +++ b/cmake/doc/CMakeLists.txt @@ -23,7 +23,12 @@ if (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE) OPTION(DBUS_ENABLE_XML_DOCS "build XML documentation (requires xmlto or meinproc4)" ON) endif (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE) -if (MEINPROC4_EXECUTABLE) +if (XMLTO_EXECUTABLE) + set (DOCBOOK_GENERATOR_NAME "xmlto" PARENT_SCOPE) + set(DBUS_XML_DOCS_ENABLED 1) + set(MEINPROC4_EXECUTABLE 0) + MESSAGE(STATUS "xmlto docbook generator found") +elseif (MEINPROC4_EXECUTABLE) set(DOCBOOK_GENERATOR_NAME "meinproc4" PARENT_SCOPE) set(DBUS_XML_DOCS_ENABLED 1) if(WIN32) @@ -33,14 +38,7 @@ if (MEINPROC4_EXECUTABLE) set(_meinproc_install_path ${CMAKE_INSTALL_PREFIX}) endif(WIN32) set(STYLESHEET "${_meinproc_install_path}/share/apps/ksgmltools2/docbook/xsl/html/docbook.xsl") -endif (MEINPROC4_EXECUTABLE) - - -if (XMLTO_EXECUTABLE) - set (DOCBOOK_GENERATOR_NAME "xmlto" PARENT_SCOPE) - set(DBUS_XML_DOCS_ENABLED 1) - MESSAGE(STATUS "xmlto docbook generator found") -endif (XMLTO_EXECUTABLE) +endif () if (DBUS_ENABLE_XML_DOCS) diff --git a/cmake/modules/FindLibExpat.cmake b/cmake/modules/FindLibExpat.cmake index a07c8de..1c74cf9 100644 --- a/cmake/modules/FindLibExpat.cmake +++ b/cmake/modules/FindLibExpat.cmake @@ -12,24 +12,32 @@ if (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES) SET(LIBEXPAT_FOUND TRUE) else (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES) - - IF (WIN32) - file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _progFiles) - find_FILE(LIBEXPAT_DIR expat Source/lib/expat.h - PATHS - "${_progFiles}" - ) + IF (CMAKE_CROSSCOMPILING) + find_FILE(LIBEXPAT_DIR include/expat.h + PATHS + ${CMAKE_FIND_ROOT_PATH} + ) + if (LIBEXPAT_DIR) + set (_LIBEXPATIncDir ${LIBEXPAT_DIR}/include) + set (_LIBEXPATLinkDir ${LIBEXPAT_DIR}/lib) + endif (LIBEXPAT_DIR) + ELSEIF (WIN32) + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _progFiles) + find_FILE(LIBEXPAT_DIR expat Source/lib/expat.h + PATHS + "${_progFiles}" + ) if (LIBEXPAT_DIR) set (_LIBEXPATIncDir ${LIBEXPAT_DIR}/Source/lib) set (_LIBEXPATLinkDir ${LIBEXPAT_DIR}/libs) endif (LIBEXPAT_DIR) - ELSE (WIN32) + ELSE () # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls INCLUDE(UsePkgConfig) PKGCONFIG(LIBEXPAT-2.0 _LIBEXPATIncDir _LIBEXPATLinkDir _LIBEXPATLinkFlags _LiIconvCflags) SET(LIBEXPAT_DEFINITIONS ${_LIBEXPATCflags}) - ENDIF (WIN32) + ENDIF () FIND_PATH(LIBEXPAT_INCLUDE_DIR expat.h PATHS diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index b637156..86b1c48 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -1,12 +1,12 @@ - +message(STATUS "++" ${CMAKE_CROSSCOMPILING}) MACRO(TIMESTAMP RESULT) - IF(WIN32) + IF(WIN32 AND NOT CMAKE_CROSSCOMPILING) EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE DATE) string(REGEX REPLACE "(..)[/.](..)[/.](....).*" "\\3\\2\\1" DATE ${DATE}) EXECUTE_PROCESS(COMMAND "cmd" " /C time /T" OUTPUT_VARIABLE TIME) string(REGEX REPLACE "(..):(..)" "\\1\\2" TIME ${TIME}) set (${RESULT} "${DATE}${TIME}") - ELSEIF(UNIX) + ELSEIF(UNIX OR CMAKE_CROSSCOMPILING) EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT}) ELSE() MESSAGE(SEND_ERROR "date not implemented") -- 1.7.10.4