From 369eeea1a59c3dd1bd67229ee2b5bdd753301f8a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 25 Jan 2018 18:46:10 -0800 Subject: [PATCH] Windows: Package script --- CMakeLists.txt | 14 +++++++++++++- README.md | 6 +++--- src/platform/qt/CMakeLists.txt | 15 +++++++++++---- src/platform/sdl/CMakeLists.txt | 4 +++- tools/deploy-win.sh | 27 +++++++++++++++++++++++++++ tools/dlls.gdb | 3 +++ 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tools/deploy-win.sh create mode 100644 tools/dlls.gdb diff --git a/CMakeLists.txt b/CMakeLists.txt index 413c18c08..7f1e9769e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,10 @@ set(BUILD_GL ON CACHE STRING "Build with OpenGL") set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2") set(USE_EPOXY ON CACHE STRING "Build with libepoxy") set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies") +if(WIN32) + set(WIN32_UNIX_PATHS OFF CACHE BOOL "Use Unix-like paths") + mark_as_advanced(WIN32_UNIX_PATHS) +endif() file(GLOB ARM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/*.c) file(GLOB ARM_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/test/*.c) file(GLOB LR35902_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/*.c) @@ -78,7 +82,15 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE) endif() -include(GNUInstallDirs) +if(NOT WIN32 OR WIN32_UNIX_PATHS) + include(GNUInstallDirs) +else() + set(CMAKE_INSTALL_LIBDIR ".") + set(CMAKE_INSTALL_BINDIR ".") + set(CMAKE_INSTALL_DATADIR ".") + set(CMAKE_INSTALL_DOCDIR ".") + set(CMAKE_INSTALL_INCLUDEDIR "include") +endif() set(LIBDIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installed library directory") mark_as_advanced(LIBDIR) diff --git a/README.md b/README.md index 3b52e1573..6f6f8394a 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,11 @@ To build on Windows for development, using MSYS2 is recommended. Follow the inst For x86 (32 bit) builds: - pacman -Sy mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libzip,pkg-config,qt5,SDL2} + pacman -Sy mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libzip,pkg-config,qt5,SDL2,ntdll-git} For x86_64 (64 bit) builds: - pacman -Sy mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libzip,pkg-config,qt5,SDL2} + pacman -Sy mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libzip,pkg-config,qt5,SDL2,ntdll-git} Check out the source code by running this command: @@ -128,7 +128,7 @@ Then finally build it by running these commands: cmake .. -G "MSYS Makefiles" make -Please note that this build of mGBA for Windows is not suitable for distribution, due to the scattering of DLLs it needs to run, but is perfect for development. However, if distributing such a build is desired (e.g. for testing on machines that don't have the MSYS2 environment installed), a tool called "[Dependency Walker](http://dependencywalker.com)" can be used to see which additional DLL files need to be shipped with the mGBA executable. +Please note that this build of mGBA for Windows is not suitable for distribution, due to the scattering of DLLs it needs to run, but is perfect for development. However, if distributing such a build is desired (e.g. for testing on machines that don't have the MSYS2 environment installed), running `cpack -G ZIP` will prepare a zip file with all of the necessary DLLs. ### Dependencies diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index d1bfe234b..8afd4f320 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -212,6 +212,8 @@ endif() if(NOT DEFINED DATADIR) if(APPLE) set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources) + elseif(WIN32 AND NOT WIN32_UNIX_PATHS) + set(DATADIR ".") else() set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) endif() @@ -307,8 +309,13 @@ if(APPLE) endif() install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")") endif() -endif() -if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7) - # Work around CMake issue #16907 - set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON) +elseif(WIN32) + if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8) + # Work around CMake issue #16907 + set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON) + endif() + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + find_program(BASH bash) + install(CODE "execute_process(COMMAND \"${BASH}\" \"${CMAKE_SOURCE_DIR}/tools/deploy-win.sh\" \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.exe\" \"\${CMAKE_INSTALL_PREFIX}\" \"\$ENV{PWD}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")" COMPONENT ${BINARY_NAME}-qt) + endif() endif() diff --git a/src/platform/sdl/CMakeLists.txt b/src/platform/sdl/CMakeLists.txt index 5a6e28ec6..a72ba221f 100644 --- a/src/platform/sdl/CMakeLists.txt +++ b/src/platform/sdl/CMakeLists.txt @@ -89,7 +89,9 @@ endif() add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC}) set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}") target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY}) -set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME}) +if(NOT WIN32) + set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME}) +endif() install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl) if(UNIX) install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl) diff --git a/tools/deploy-win.sh b/tools/deploy-win.sh new file mode 100644 index 000000000..d5a3d3296 --- /dev/null +++ b/tools/deploy-win.sh @@ -0,0 +1,27 @@ +#!/bin/bash +BINARY=$1 +INSTALLPATH="$2" +WORKDIR="$3" + + +if [ -z "$DESTDIR" ]; then + OUTDIR="$INSTALLPATH" +else + if [ -n $(echo ${INSTALLPATH} | grep "^[A-Z]:") ]; then + INSTALLPATH="${INSTALLPATH:3}" + fi + OUTDIR="$WORKDIR/$DESTDIR/$INSTALLPATH" +fi + +IFS=$'\n' +if [ -n $(which ntldd 2>&1 | grep /ntldd) ]; then + DLLS=$(ntldd -R "$BINARY" | grep -i mingw | cut -d">" -f2 | sed -e 's/(0x[0-9a-f]\+)//' -e 's/^ \+//' -e 's/ \+$//' -e 's,\\,/,g') +elif [ -n $(which gdb 2>&1 | grep /gdb) ]; then + DLLS=$(gdb "$BINARY" --command=$(dirname $0)/dlls.gdb | grep -i mingw | cut -d" " -f7- | sed -e 's/^ \+//' -e 's/ \+$//' -e 's,\\,/,g') +else + echo "Please install gdb or ntldd for deploying DLLs" +fi +cp -vu $DLLS "$OUTDIR" +if [ -n $(which windeployqt 2>&1 | grep /windeployqt) ]; then + windeployqt --no-opengl-sw --no-svg --release --dir "$OUTDIR" "$BINARY" +fi diff --git a/tools/dlls.gdb b/tools/dlls.gdb new file mode 100644 index 000000000..017b39ac5 --- /dev/null +++ b/tools/dlls.gdb @@ -0,0 +1,3 @@ +start +info sharedlibrary +q