From a897d9380c3c7e49412827185f2aad2bbb3138c1 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 26 Jan 2013 13:35:24 +0100 Subject: [PATCH] CMake cross compiling fixes for opensuse. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=59733 --- README.cmake | 15 ++++++++++++ cmake/cross-compile.sh | 47 ++++++++++++++++++++++++-------------- cmake/doc/CMakeLists.txt | 16 ++++++------- cmake/modules/FindLibExpat.cmake | 26 +++++++++++++-------- cmake/modules/Macros.cmake | 5 ++-- 5 Dateien geändert, 71 Zeilen hinzugefügt(+), 38 Zeilen entfernt(-) diff --git a/README.cmake b/README.cmake index 0c30ba6..6c5aab3 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/cross-compile.sh b/cmake/cross-compile.sh index 49e66e5..c15a441 100755 --- a/cmake/cross-compile.sh +++ b/cmake/cross-compile.sh @@ -1,20 +1,36 @@ #!/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 -# - -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 +# reported to work at least on debian/lenny +# +# run: +# +# /cmake/cross_compile.sh /cmake +# +# for specific cross compiler +# +# CC=/usr/bin/i686-w64-mingw32-gcc-4.7.2 /cmake/cross_compile.sh /cmake> +# +cc_postfix= +if test -n "$CC"; then + cross_cc=$(echo $CC | sed 's,^/usr/bin/,,g;s,-gcc-.*$,,g') + cc_postfix=$(echo $CC | sed 's,^.*gcc,,g') else - echo "could not determine mingw cross compiler" - exit 1 + 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; then + cross_cc=i686-w64-mingw32 + else + echo "could not determine mingw cross compiler" + exit 1 + fi fi if test -d ~/$cross_cc; then @@ -47,7 +63,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 +95,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,12 +111,9 @@ 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 \ 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..f1fd152 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_HOST_SYSTEM_NAME STREQUAL "Windows") + 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) + elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND 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) + 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..f59df0b 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -1,12 +1,11 @@ - MACRO(TIMESTAMP RESULT) - IF(WIN32) + IF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") 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(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT}) ELSE() MESSAGE(SEND_ERROR "date not implemented") -- 1.7.10.4