Permalink
Browse files

Support for cross-compiling for Windows on Linux

  • Loading branch information...
1 parent bde4619 commit dd8d1e7bd86acb1971b56490a37e908019abd32d @thp committed Sep 27, 2012
Showing with 133 additions and 8 deletions.
  1. +14 −2 CMakeLists.txt
  2. +75 −0 contrib/cross-compile-mingw64
  3. +36 −0 contrib/toolchain-mingw64.cmake
  4. +2 −2 src/daemon/moved_client.h
  5. +4 −2 src/psmove.c
  6. +2 −2 src/utils/moved.h
View
@@ -107,8 +107,20 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
list(APPEND PSMOVEAPI_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32 winmm)
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/mingw-w64-headers)
- link_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/mingw-w64-headers)
+ option(PSMOVE_USE_LOCAL_OPENCV "OpenCV (contrib/cross-compile-mingw64)" OFF)
+ if (PSMOVE_USE_LOCAL_OPENCV)
+ # Force tracker build with a locally-built opencv library installation
+ set(OPENCV_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opencv-win32/opencv/build-win32/install)
+ link_directories(${OPENCV_INSTALL_DIR}/lib)
+ include_directories(${OPENCV_INSTALL_DIR}/include)
+ list(APPEND PSMOVEAPI_TRACKER_REQUIRED_LIBS
+ opencv_core249.dll opencv_highgui249 opencv_imgproc249)
+ set(PSMOVE_BUILD_TRACKER ON)
+ set(INFO_BUILD_TRACKER "Yes (mingw64-cross-compile)")
+ else()
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/mingw-w64-headers)
+ link_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/mingw-w64-headers)
+ endif()
IF(PSMOVE_USE_CL_EYE_SDK)
find_path(CL_EYE_SDK_PATH Bin/CLEyeMulticam.dll
@@ -0,0 +1,75 @@
+#!/bin/bash -x -e
+#
+# Script to cross compile PS Move API for Windows on a Linux host
+# Thomas Perl <m@thp.io>; 2012-09-27
+#
+# Dependencies (Ubuntu/Debian):
+#
+# sudo apt-get install mingw-w64 mingw-w64-dev
+#
+
+export PSMOVEAPI_CHECKOUT=$(pwd)
+export TOOLCHAIN=$PSMOVEAPI_CHECKOUT/contrib/toolchain-mingw64.cmake
+export OPENCV_CHECKOUT_DIR=$PSMOVEAPI_CHECKOUT/opencv-win32/opencv
+export OPENCV_INSTALL_DIR=$OPENCV_CHECKOUT_DIR/build-win32/install
+
+if [ ! -f $PSMOVEAPI_CHECKOUT/CMakeLists.txt ]; then
+ echo "ERROR: You have to run this script in the PS Move API source root."
+ exit 1
+fi
+
+# Build OpenCV
+if [ ! -d $OPENCV_INSTALL_DIR ]; then
+ mkdir -p opencv-win32
+ cd opencv-win32
+ if [ ! -d opencv ]; then
+ git clone git://code.opencv.org/opencv.git
+ fi
+ cd opencv
+ rm -rf build-win32
+ mkdir -p build-win32
+ cd build-win32
+ cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN ..
+ make
+ make install
+fi
+
+cd $PSMOVEAPI_CHECKOUT
+
+# Build PS Move API
+rm -rf build-win32
+mkdir build-win32
+cd build-win32
+cmake -DPSMOVE_USE_LOCAL_OPENCV=ON \
+ -DPSMOVE_BUILD_TRACKER=OFF \
+ -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN ..
+make
+
+cd $PSMOVEAPI_CHECKOUT
+
+# Packaging
+rm -rf dist
+mkdir -p dist/bin
+cp build-win32/*.exe dist/bin/
+cp build-win32/libpsmoveapi.dll dist/bin/
+cp build-win32/libpsmoveapi_tracker.dll dist/bin/
+cp $OPENCV_INSTALL_DIR/bin/libopencv_core249.dll dist/bin/
+cp $OPENCV_INSTALL_DIR/bin/libopencv_highgui249.dll dist/bin/
+cp $OPENCV_INSTALL_DIR/bin/libopencv_imgproc249.dll dist/bin/
+mkdir -p dist/lib
+cp build-win32/libpsmoveapi.dll.a dist/lib/
+cp build-win32/libpsmoveapi_tracker.dll.a dist/lib/
+cp $OPENCV_INSTALL_DIR/lib/libopencv_core249.dll.a dist/lib/
+cp $OPENCV_INSTALL_DIR/lib/libopencv_highgui249.dll.a dist/lib/
+cp $OPENCV_INSTALL_DIR/lib/libopencv_imgproc249.dll.a dist/lib/
+mkdir -p dist/include
+cp include/*.h dist/include/
+
+cd $PSMOVEAPI_CHECKOUT
+
+# Zip it up
+PACKAGE_NAME=psmoveapi-$(date +%F)_win32
+rm -rf $PACKAGE_NAME
+mv dist $PACKAGE_NAME
+zip -r $PACKAGE_NAME.zip $PACKAGE_NAME
+
@@ -0,0 +1,36 @@
+# based on http://www.cmake.org/Wiki/CmakeMingw
+
+# the name of the target operating system
+SET(CMAKE_SYSTEM_NAME Windows)
+
+# Choose an appropriate compiler prefix
+
+# for classical mingw32
+# see http://www.mingw.org/
+#set(COMPILER_PREFIX "i586-mingw32msvc")
+
+# for 32 or 64 bits mingw-w64
+# see http://mingw-w64.sourceforge.net/
+set(COMPILER_PREFIX "i686-w64-mingw32")
+#set(COMPILER_PREFIX "x86_64-w64-mingw32"
+
+# which compilers to use for C and C++
+find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres)
+#SET(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres)
+find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc)
+#SET(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
+find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++)
+#SET(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
+
+
+# here is the target environment located
+SET(USER_ROOT_PATH /home/erk/erk-win32-dev)
+SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} ${USER_ROOT_PATH})
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
@@ -33,8 +33,8 @@
#ifdef _WIN32
-# include <Winsock2.h>
-# include <Ws2tcpip.h>
+# include <winsock2.h>
+# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <netinet/in.h>
View
@@ -65,9 +65,11 @@
#ifdef _WIN32
# include <windows.h>
-# include <Bthsdpdef.h>
-# include <BluetoothAPIs.h>
+# include <bthsdpdef.h>
+# include <bluetoothapis.h>
+#ifndef PATH_MAX
# define PATH_MAX MAX_PATH
+#endif
# define ENV_USER_HOME "APPDATA"
# define PATH_SEP "\\"
#else
View
@@ -39,8 +39,8 @@
#include <wchar.h>
#ifdef _WIN32
-# include <Winsock2.h>
-# include <Ws2tcpip.h>
+# include <winsock2.h>
+# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <netinet/in.h>

0 comments on commit dd8d1e7

Please sign in to comment.