From 66edf8a647cce4a21b98a43b4180039760c8800a Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 12 Feb 2016 14:21:38 +0100 Subject: [PATCH] Fix cross-compilation with mingw-w64 --- cmake/i686-w64-mingw32.toolchain | 4 + cmake/toolchain-mingw64.cmake | 36 ------ cmake/x86_64-w64-mingw32.toolchain | 4 + contrib/cross-compile-mingw64 | 145 +++++++++++----------- contrib/opencv.patch | 13 -- docs/README.cross | 23 ++++ docs/README.win32_mingw64 | 192 ----------------------------- src/CMakeLists.txt | 2 +- src/daemon/moved_client.c | 6 +- src/tracker/CMakeLists.txt | 3 - 10 files changed, 106 insertions(+), 322 deletions(-) create mode 100644 cmake/i686-w64-mingw32.toolchain delete mode 100644 cmake/toolchain-mingw64.cmake create mode 100644 cmake/x86_64-w64-mingw32.toolchain delete mode 100644 contrib/opencv.patch create mode 100644 docs/README.cross delete mode 100644 docs/README.win32_mingw64 diff --git a/cmake/i686-w64-mingw32.toolchain b/cmake/i686-w64-mingw32.toolchain new file mode 100644 index 00000000..d6cb8ce3 --- /dev/null +++ b/cmake/i686-w64-mingw32.toolchain @@ -0,0 +1,4 @@ +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) +SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) diff --git a/cmake/toolchain-mingw64.cmake b/cmake/toolchain-mingw64.cmake deleted file mode 100644 index 1ed9c9f9..00000000 --- a/cmake/toolchain-mingw64.cmake +++ /dev/null @@ -1,36 +0,0 @@ -# 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) - diff --git a/cmake/x86_64-w64-mingw32.toolchain b/cmake/x86_64-w64-mingw32.toolchain new file mode 100644 index 00000000..1d9cce48 --- /dev/null +++ b/cmake/x86_64-w64-mingw32.toolchain @@ -0,0 +1,4 @@ +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) diff --git a/contrib/cross-compile-mingw64 b/contrib/cross-compile-mingw64 index 67c4f727..26707b45 100644 --- a/contrib/cross-compile-mingw64 +++ b/contrib/cross-compile-mingw64 @@ -9,92 +9,87 @@ # export PSMOVEAPI_CHECKOUT=$(pwd) -export TOOLCHAIN=$PSMOVEAPI_CHECKOUT/contrib/toolchain-mingw64.cmake -export OPENCV_CHECKOUT_DIR=$PSMOVEAPI_CHECKOUT/opencv -export OPENCV_INSTALL_DIR=$OPENCV_CHECKOUT_DIR/build/install - -# For parallel builds -MAKE_ARGS=-j4 - -# Take version from Debian package info -PSMOVEAPI_VERSION=$(dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2-) - -# Git revision identifier -PSMOVEAPI_REVISION=$(git describe --long --tags) - -# By default, we build a snapshot. If "release" is the first argument, we -# build a release (do not add date and Git revision information to version) -if [ "$1" != "release" ]; then - PSMOVEAPI_VERSION=${PSMOVEAPI_VERSION}~$(date +%F)+${PSMOVEAPI_REVISION} -fi - 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 - if [ ! -d opencv ]; then - git clone git://github.com/Itseez/opencv.git +OPENCV_VERSION=3.1.0 +PSMOVEAPI_VERSION=$(git describe --tags) + +MAKE_ARGS="$@" + +for PSMOVEAPI_PLATFORM in i686-w64-mingw32 x86_64-w64-mingw32; do + export TOOLCHAIN=$PSMOVEAPI_CHECKOUT/cmake/${PSMOVEAPI_PLATFORM}.toolchain + export OPENCV_CHECKOUT_DIR=$PSMOVEAPI_CHECKOUT/external/opencv + export OPENCV_BUILD_DIR=$OPENCV_CHECKOUT_DIR/build-${PSMOVEAPI_PLATFORM} + + # Build OpenCV + if [ ! -d $OPENCV_BUILD_DIR ]; then + if [ ! -d external/opencv ]; then + if [ ! -f ${OPENCV_VERSION}.zip ]; then + curl -O https://github.com/Itseez/opencv/archive/${OPENCV_VERSION}.zip + fi + unzip ${OPENCV_VERSION}.zip + mv opencv-${OPENCV_VERSION} external/opencv + fi + cd external/opencv + rm -rf ${OPENCV_BUILD_DIR} + mkdir -p ${OPENCV_BUILD_DIR} + cd ${OPENCV_BUILD_DIR} + cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_PERF_TESTS=OFF \ + -DBUILD_TESTS=OFF \ + -DBUILD_DOCS=OFF \ + -DBUILD_opencv_flann=OFF \ + -DBUILD_opencv_features2d=OFF \ + -DBUILD_opencv_objdetect=OFF \ + -DBUILD_opencv_photo=OFF \ + -DBUILD_opencv_ts=OFF \ + -DBUILD_opencv_ml=OFF \ + -DBUILD_opencv_video=OFF \ + -DWITH_OPENEXR=OFF \ + -DWITH_FFMPEG=OFF \ + -DWITH_JASPER=OFF \ + -DWITH_TIFF=OFF \ + ${OPENCV_CHECKOUT_DIR} + make ${MAKE_ARGS} fi - cd opencv + + cd $PSMOVEAPI_CHECKOUT + + # Build PS Move API rm -rf build - mkdir -p build + mkdir build cd build - cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_PERF_TESTS=OFF \ - -DBUILD_TESTS=OFF \ - -DBUILD_DOCS=OFF \ - -DBUILD_opencv_flann=OFF \ - -DBUILD_opencv_features2d=OFF \ - -DBUILD_opencv_objdetect=OFF \ - -DBUILD_opencv_photo=OFF \ - -DBUILD_opencv_ts=OFF \ - -DBUILD_opencv_ml=OFF \ - -DBUILD_opencv_video=OFF \ - -DWITH_OPENEXR=OFF \ - -DWITH_FFMPEG=OFF \ - -DWITH_JASPER=OFF \ - -DWITH_TIFF=OFF \ - .. + cmake -DPSMOVE_BUILD_TRACKER=ON \ + -DOpenCV_DIR=${OPENCV_BUILD_DIR} \ + -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \ + ${PSMOVEAPI_CHECKOUT} make ${MAKE_ARGS} - make install -fi - -cd $PSMOVEAPI_CHECKOUT - -# Build PS Move API -rm -rf build -mkdir build -cd build -cmake -DPSMOVE_USE_LOCAL_OPENCV=ON \ - -DPSMOVE_BUILD_TRACKER=OFF \ - -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN .. -make ${MAKE_ARGS} - -cd $PSMOVEAPI_CHECKOUT -# Packaging -rm -rf dist -mkdir -p dist/bin -echo $PSMOVEAPI_REVISION >dist/revision.txt -cp README COPYING README.win32 README.moved dist/ -cp build/*.exe dist/bin/ -cp build/libpsmoveapi.dll dist/bin/ -cp build/libpsmoveapi_tracker.dll dist/bin/ -mkdir -p dist/include -cp include/*.h dist/include/ + cd $PSMOVEAPI_CHECKOUT -cd $PSMOVEAPI_CHECKOUT + # Packaging + rm -rf dist + mkdir -p dist/bin + cp README COPYING dist/ + cp -r docs dist/ + cp build/*.exe dist/bin/ + cp build/libpsmoveapi.dll dist/bin/ + cp build/libpsmoveapi_tracker.dll dist/bin/ + mkdir -p dist/include + cp include/*.h dist/include/ -# Zip it up -PACKAGE_NAME=psmoveapi_${PSMOVEAPI_VERSION}_win32 -rm -rf $PACKAGE_NAME -mv dist $PACKAGE_NAME -mkdir -p upload -zip -r upload/${PACKAGE_NAME}.zip $PACKAGE_NAME -rm -rf $PACKAGE_NAME + cd $PSMOVEAPI_CHECKOUT + # Zip it up + PACKAGE_NAME=psmoveapi-${PSMOVEAPI_VERSION}-${PSMOVEAPI_PLATFORM} + rm -rf $PACKAGE_NAME + mv dist $PACKAGE_NAME + mkdir -p upload + zip -r upload/${PACKAGE_NAME}.zip $PACKAGE_NAME + rm -rf $PACKAGE_NAME +done diff --git a/contrib/opencv.patch b/contrib/opencv.patch deleted file mode 100644 index 200443dd..00000000 --- a/contrib/opencv.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake -index fe3de3f..4f77cb7 100644 ---- a/cmake/OpenCVCompilerOptions.cmake -+++ b/cmake/OpenCVCompilerOptions.cmake -@@ -76,7 +76,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) - add_extra_compiler_option(-W) - add_extra_compiler_option(-Wall) - add_extra_compiler_option(-Werror=return-type) -- add_extra_compiler_option(-Werror=non-virtual-dtor) -+ #add_extra_compiler_option(-Werror=non-virtual-dtor) - add_extra_compiler_option(-Werror=address) - add_extra_compiler_option(-Werror=sequence-point) - add_extra_compiler_option(-Wformat) diff --git a/docs/README.cross b/docs/README.cross new file mode 100644 index 00000000..277477c5 --- /dev/null +++ b/docs/README.cross @@ -0,0 +1,23 @@ +To cross-compile for Windows on Ubuntu: + + sudo apt-get install nsis mingw-w64-i686-dev mingw-w64-x86-64-dev + +To build manually without the tracker: + + mkdir build-win32 + cd build-win32 + cmake \ + -DCMAKE_TOOLCHAIN_FILE=../cmake/i686-w64-mingw32.toolchain \ + -DPSMOVE_BUILD_TRACKER=OFF \ + .. + + mkdir build-win64 + cd build-win64 + cmake \ + -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-w64-mingw32.toolchain \ + -DPSMOVE_BUILD_TRACKER=OFF \ + .. + +Or use: + + sh -x contrib/cross-compile-mingw64 diff --git a/docs/README.win32_mingw64 b/docs/README.win32_mingw64 deleted file mode 100644 index 34893d1f..00000000 --- a/docs/README.win32_mingw64 +++ /dev/null @@ -1,192 +0,0 @@ - - Building and running the PS Move API on a legacy operating system - ================================================================= - -We usually build PS Move API for Windows on Linux via cross-compliation, as -we don't run Windows for day-to-day work. For cross-compiling the PS Move API -for Windows on Linux, you can use the following script: - - contrib/cross-compile-mingw64 - - -Please take into account that Bluetooth pairing on Windows still does not work -as smoothly as on both Mac OS X and Linux. If you plan to do serious -development, it's time to switch to Mac OS X or Linux. As an alternative, you -can use a Linux host for Bluetooth communcation, and export the controller via -"moved" to the Windows host. This setup has reliable pairing, and you can still -develop and build your applications in Windows if you have to. - - -Requirements ------------- - -- MinGW - http://mingw-w64.sourceforge.net/ -- CMake - http://www.cmake.org/cmake/resources/software.html -- OpenCV - http://sourceforge.net/projects/opencvlibrary/files/opencv-win/ -- Git - http://code.google.com/p/msysgit/ -- CL Eye Driver (if you plan to use the PS Eye camera) - http://codelaboratories.com/get/cl-eye-driver/ - -Optional dependency: - -- CLEyeSDK - http://codelaboratories.com/get/cl-eye-sdk/ - - - -IMPORTANT: Get the right MinGW version! - - -> "Regular" MinGW might not be able to build the PS Move API, as we are - using some features that are only included in MinGW-w64. - - -> Get "MinGW-w64" instead. Despite its name, it also works for 32-bit - systems (and you probably have to/want to build PS Move API as 32-bit - library on Windows, anyway. This is also what we use, both for cross- - compiling it on Linux, and for building it directly on Windows. - - -> The build has been successfully tested on Windows XP, Windows 7, - and Windows 8 using MinGW-w64 version 4.9.1. To get it, you can either - A) use the online installer or B) download the archive directly for - manual setup: - - A) Get the online installer at http://sourceforge.net/projects/mingw-w64/ - - Run the installer using these setup settings: - - Version: 4.9.1 - Architecture: i686 or x86_64 - Threads: posix - Exception: sjlj or seh - Build revision: 1 - - B) For 64-bit Windows, get the archive at - http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.1/threads-posix/sjlj/ - - For 32-bit Windows, get the archive at - http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.1/threads-posix/sjlj/ - - Extract the archive (using 7-Zip) and add the path to its "bin" subdirectory to the - PATH environment variable like so, for instance: - - set PATH=C:\mingw32\bin;%PATH% - - - NOTE: If you want to use the CL Eye Driver (for PS Eye camera) you *must* - build everything as 32-bit binaries. The driver is, as of writing, - only available in a 32-bit version that will not work together with - 64-bit builds of OpenCV and the PS Move API. The easiest way to - achieve this is to install the i686 version of MinGW-w64 (see above) - for the following build steps. - - -1. Clone the PS Move API repository - - git clone --recursive git://github.com/thp/psmoveapi.git - cd psmoveapi - -2. Clone the OpenCV repository - - Since OpenCV binary distributions typically do not come with - MinGW builds, we build our own. First, get version 2.4.10 from - the OpenCV repository. - - cd external - git clone git://github.com/Itseez/opencv.git - cd opencv - -2b. Patch around a mingw-specific bug in OpenCV3 (see http://code.opencv.org/issues/4107) - git apply ../../contrib/opencv.patch - -3. Configure the OpenCV build to produce static libs - - mkdir build - cd build - cmake .. -G "MinGW Makefiles" -DBUILD_DOCS=0 -DBUILD_FAT_JAVA_LIB=0 -DBUILD_PACKAGE=0 -DBUILD_PERF_TESTS=0 -DBUILD_SHARED_LIBS=0 -DBUILD_TESTS=0 -DBUILD_opencv_apps=0 -DBUILD_opencv_calib3d=0 -DBUILD_opencv_features2d=0 -DBUILD_opencv_flann=0 -DBUILD_opencv_objdetect=0 -DBUILD_opencv_photo=0 -DBUILD_opencv_shape=0 -DBUILD_opencv_stitching=0 -DBUILD_opencv_superres=0 -DBUILD_opencv_ts=0 -DBUILD_opencv_video=0 -DBUILD_opencv_videostab=0 -DBUILD_opencv_world=0 -DWITH_FFMPEG=0 -DWITH_IPP=OFF -DWITH_JASPER=0 -DWITH_OPENEXR=0 -DWITH_TIFF=0 - -4. Build and install OpenCV - - It will install to psmoveapi's opencv/build/install subdirectory. - - mingw32-make - mingw32-make install - -5. (Optional) Get libusb-1.0 static libraries - - If you wish to use the optical tracker without the CL Eye driver then you need the - PS3EYEDriver and its libusb-1.0 dependency. You can either use precompiled binaries - or build from source. - - To use the precompiled binaries, go to http://libusb.info/ and click on Downloads - and "Latest Windows Binaries". Extract the archive into psmoveapi/external/libusb-1.0 - - Building from source requires MSys. Specific instructions for installing and using - MSys are not provided here. In brief, from the libusb-1.0 directory you will have - to run autogen.sh and then configure and make. - -6. Configure the PS Move API build - - Switch back to the psmoveapi root directory. - - cd ..\..\.. - - mkdir build - cd build - cmake .. -G "MinGW Makefiles" - - Alternatively, if you want to use the CL Eye SDK: - - cmake .. -G "MinGW Makefiles" -DPSMOVE_USE_CL_EYE_SDK=1 - - Also alternatively, if you want to use the PS3EYEDriver: - cmake .. -G "MinGW Makefiles" -DPSMOVE_USE_PS3EYE_DRIVER=1 - -7. Finally build the PS Move API - - mingw32-make - -8. Pair the controller to the host - - Using the controllers' Bluetooth capabilities requires you to pair the - controller to the host computer first. That is what the psmovepair utility - is for. It is automatically built as part of the PS Move API. - - Make sure that Bluetooth is enabled on your computer, then connect a Move - controller via USB and run - - psmovepair.exe - - to store the host's Bluetooth device address in the Move and register the - controller. Follow the instructions on the screen until the Move's red - status LED eventually remains lit to indicate a working Bluetooth - connection. Since this step involves modifications of the registry on - Windows 8 and later, you will probably have to run psmovepair.exe as - Administrator. - - Note that the pairing step is necessary only once per controller. From that - point on you can enable the Bluetooth connection simply by pressing the - PS button. Only if you switched to a different Bluetooth adapter or deleted - the controller from the list of Bluetooth devices you need to run - psmovepair again for that controller. - -9. Start one of the desired test applications - - If you previously chose to build the example applications (which is the - default), you can then run - - example.exe - - for a basic example. - - - -For questions, please read the archives of the PS Move Mailing List. If you -cannot find an answer to your question in the archives, send an e-mail: - - https://groups.google.com/forum/#!aboutgroup/psmove - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83291ab6..61fbe91b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,7 +84,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CMAKE_STATIC_LIBRARY_FLAGS "${CMAKE_STATIC_LIBRARY_FLAGS} -stdlib=libc++") ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - list(APPEND PSMOVEAPI_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32 winmm version Imm32 ${MSVC_LIBS}) + list(APPEND PSMOVEAPI_REQUIRED_LIBS setupapi bthprops kernel32 ws2_32 winmm version imm32 ${MSVC_LIBS}) include_directories(${MSVC_INCLUDES}) list(APPEND PSMOVEAPI_PLATFORM_SRC ${MSVC_SRCS}) diff --git a/src/daemon/moved_client.c b/src/daemon/moved_client.c index 9bde6b0f..8ac5748a 100644 --- a/src/daemon/moved_client.c +++ b/src/daemon/moved_client.c @@ -132,8 +132,10 @@ moved_client_create(const char *hostname) client->moved_addr.sin_family = AF_INET; client->moved_addr.sin_port = htons(MOVED_UDP_PORT); - result = inet_pton(AF_INET, hostname, &(client->moved_addr.sin_addr)); - assert(result != 0); + + + client->moved_addr.sin_addr.s_addr = inet_addr(hostname); + assert(client->moved_addr.sin_addr.s_addr != INADDR_NONE); return client; } diff --git a/src/tracker/CMakeLists.txt b/src/tracker/CMakeLists.txt index 353c8d2e..9e15d42d 100644 --- a/src/tracker/CMakeLists.txt +++ b/src/tracker/CMakeLists.txt @@ -8,9 +8,6 @@ set(PSMOVEAPI_TRACKER_PLATFORM_SRC) # Build the OpenCV-based camera tracking module? (see psmove_tracker.h) option(PSMOVE_BUILD_TRACKER "Build the Tracker module (needs OpenCV)" ON) -# Use a custom location for OpenCV src dir -set(OpenCV_DIR ${ROOT_DIR}/external/opencv/build CACHE PATH "Path to local OpenCV source tree" FORCE) - # Enable tweaks (e.g. registry settings on Windows, ...) for PS Eye option(PSMOVE_USE_PSEYE "Enable tweaks for the PS Eye camera" ON)