full support for cross-compiling to win32 with mxe

Fix all cmake issues related to building for win32 with mxe.

Add support for ./installdeps win32 on Debian/Ubuntu using the mxe apt
repository.

Details:

* default to ENABLE_LTO=OFF on mxe

* set SFML_STATIC_LIBRARIES=TRUE on mxe

* fix the libintl/gettext checking logic

* fix the git dependencies submodule checking logic, and check that it
  triggers for mxe

* revert FindSFML.cmake to upstream version, works fine with mxe

* make 'win32' an alias for the 'MinGW-w64-i686' target for
  ./installdeps, add support for mxe apt repository for Debian/Ubuntu

* change bin2c related cmake code to compile the tool on the host always
  even when cross-compiling

* copy src/win32/res/VBA.ico to src/wx/icons since src/win32 has been
  removed

TODO: generic mxe installer for other unix-likes
This commit is contained in:
Rafael Kitover 2016-12-21 13:02:55 -08:00
parent 3279ce2ab8
commit d06e7afceb
6 changed files with 79 additions and 30 deletions

View File

@ -58,7 +58,7 @@ option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})
SET(LTO_DEFAULT ON)
IF(AMD64 AND WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
IF((AMD64 AND WIN32 AND CMAKE_COMPILER_IS_GNUCXX) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)
SET(LTO_DEFAULT OFF)
ENDIF()
@ -136,7 +136,8 @@ ADD_DEFINITIONS(${SDL2_DEFINITIONS})
if( ENABLE_LINK )
# msys2 does not have static sfml libs atm
if(WIN32 AND NOT (MINGW AND MSYS))
# while on mxe we use static libs
if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe))
set(SFML_STATIC_LIBRARIES TRUE)
endif()
FIND_PACKAGE ( SFML 2 COMPONENTS network system REQUIRED )
@ -235,28 +236,28 @@ if( ENABLE_NLS )
ENDIF()
ENDIF()
IF(ENABLE_LINK)
FIND_PATH(LIBINTL_INC libintl.h )
FIND_LIBRARY(LIBINTL_LIB intl )
IF(LIBINTL_LIB)
FIND_PATH(LIBINTL_INC libintl.h)
FIND_LIBRARY(LIBINTL_LIB intl)
IF(LIBINTL_LIB)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBINTL_LIB})
SET(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBINTL_LIB})
ENDIF(LIBINTL_LIB)
ENDIF(LIBINTL_LIB)
INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(gettext GETTEXT_FN)
IF(NOT LIBINTL_INC OR NOT GETTEXT_FN)
IF(NOT (LIBINTL_INC OR GETTEXT_FN))
MESSAGE(FATAL_ERROR "NLS requires libintl/gettext")
ENDIF(NOT LIBINTL_INC OR NOT GETTEXT_FN)
ENDIF()
INCLUDE_DIRECTORIES(${LIBINTL_INC})
ENDIF(ENABLE_LINK)
endif( ENABLE_NLS )
# Win32 deps submodule
IF(WIN32)
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies" AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
MESSAGE(FATAL_ERROR "Please pull in git submodules, e.g. run: git submodule update --init --recursive")
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include" AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
MESSAGE(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --recursive")
ENDIF()
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/dependencies/include")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
ENDIF()
# Compiler flags

View File

@ -75,6 +75,7 @@ set(FIND_SFML_PATHS
# find the SFML include directory
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
PATH_SUFFIXES include
PATHS ${FIND_SFML_PATHS})
# check the version number

View File

@ -1,5 +1,7 @@
#!/bin/sh
cmake=cmake
main() {
cd "$(dirname $0)"
@ -63,10 +65,11 @@ host OS.
This program may require sudo.
A cross-compile target may be specified as the only parameter, of either
MinGW-w64-i686 or MinGW-w64-x86_64.
This is only supported on Arch Linux and MSYS2.
win32, MinGW-w64-i686 or MinGW-w64-x86_64.
win32 is an alias for MinGW-w64-i686.
This is only supported on Debian/Ubuntu, Arch Linux and MSYS2.
OPn MSYS2 dependencies are installed for both 32 and 64 bit native Windows
On MSYS2 dependencies are installed for both 32 and 64 bit native Windows
targets by default, unless you specify one or the other. MSYS2 layer builds are
not supported.
@ -74,8 +77,9 @@ not supported.
Examples:
./installdeps # install dependencies for a host build
./installdeps MinGW-w64-i686 # cross-compile for 32 bit windows (Arch Linux or MSYS2)
./installdeps MinGW-w64-x86_64 # cross-compile for 64 bit windows (Arch Linux or MSYS2)
./installdeps win32 # cross-compile for 32 bit windows (Debian/Ubuntu, Arch Linux or MSYS2)
./installdeps MinGW-w64-i686 # likewise
./installdeps MinGW-w64-x86_64 # cross-compile for 64 bit windows (Debian/Ubuntu, Arch Linux or MSYS2)
EOF
}
@ -132,17 +136,20 @@ linux_installdeps() {
check_cross() {
[ -z "$target" ] && return
if [ -z "$arch_linux" -a -z "$msys2" ]; then
error 'cross compiling targets are only supported on Arch Linux and MSYS2 at the moment'
if [ -z "$arch_linux" -a -z "$msys2" -a -z "$debian" ]; then
error 'cross compiling targets are only supported on Debian/Ubuntu, Arch Linux and MSYS2 at the moment'
fi
target=$(echo "$target" | tr 'A-Z' 'a-z')
case "$target" in
mingw-w64-x86_64)
win32)
target='mingw-w64-i686'
;;
mingw-w64-i686)
;;
mingw-w64-x86_64)
;;
*)
error "target must be one of 'MinGW-w64-i686' or 'MinGW-w64-x86_64'"
;;
@ -150,11 +157,46 @@ check_cross() {
}
debian_installdeps() {
debian=1
check_cross
installing
check sudo apt-get -y update
check sudo apt-get -y install build-essential g++ zlib1g-dev libgl1-mesa-dev cmake libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libgettextpo-dev libjpeg-dev libpng16-dev libtiff5-dev libsdl2-dev libsfml-dev libopenal-dev libwxgtk3.0-dev
if [ -z "$target" ]; then
check sudo apt-get -qq update
check sudo apt-get -qy install build-essential g++ zlib1g-dev libgl1-mesa-dev cmake libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libgettextpo-dev libjpeg-dev libpng16-dev libtiff5-dev libsdl2-dev libsfml-dev libopenal-dev libwxgtk3.0-dev
else
case "$target" in
mingw-w64-i686)
target='i686-w64-mingw32.static'
;;
mingw-w64-x86_64)
target='x86-64-w64-mingw32.static'
;;
*)
error "unknown cross target (you shouldn't see this)"
;;
esac
cmake="/usr/lib/mxe/usr/bin/${target}-cmake"
mxe_apt_sources='/etc/apt/sources.list.d/mxeapt.list'
check sudo apt-get -qq update
if [ -z "$(apt-cache search '^mxe-source$')" ]; then
if [ ! -f "$mxe_apt_sources" ]; then
echo "deb http://pkg.mxe.cc/repos/apt/debian wheezy main" | sudo -- sh -c "cat > $mxe_apt_sources"
check sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D43A795B73B16ABE9643FE1AFD8FFF16DB45C6AB
else
error "$mxe_apt_sources exists but mxe packages are not found in apt, either delete it or fix it"
fi
fi
set --
for dep in gcc zlib ffmpeg gettext jpeg tiff sdl2 sfml openal wxwidgets cairo; do
set -- "$@" "mxe-${target}-$dep"
done
check sudo apt-get -qy install build-essential cmake "$@"
fi
generic_build_instructions
}
@ -371,7 +413,7 @@ generic_build_instructions() {
Done! To build do:
mkdir build && cd build
cmake .. $cmake_flags
$cmake .. $cmake_flags
make -j10
EOF
}

View File

@ -100,22 +100,27 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# wxrc does not support xrs files in -c output (> 10x compression)
# we do it using the bin2.c utility
ADD_EXECUTABLE(bin2c bin2c.c)
# don't want SDL_main here
SET_TARGET_PROPERTIES(bin2c PROPERTIES COMPILE_FLAGS "-Dmain=main")
SET(BIN2C ${CMAKE_BINARY_DIR}/bin2c)
IF(CMAKE_HOST_WIN32)
SET(BIN2C ${BIN2C}.exe)
ENDIF()
ADD_CUSTOM_COMMAND(OUTPUT ${BIN2C}
COMMAND cc ${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c -o ${BIN2C}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c)
ADD_CUSTOM_COMMAND(OUTPUT wxvbam.xrs
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND wxrc ${CMAKE_CURRENT_SOURCE_DIR}/xrc/*.xrc -o wxvbam.xrs
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/xrc/*.xrc)
ADD_CUSTOM_COMMAND(OUTPUT builtin-xrc.h
COMMAND bin2c wxvbam.xrs builtin-xrc.h builtin_xrs
DEPENDS bin2c wxvbam.xrs)
COMMAND ${BIN2C} wxvbam.xrs builtin-xrc.h builtin_xrs
DEPENDS ${BIN2C} wxvbam.xrs)
# use a built-in vba-over.ini if no config file present
ADD_CUSTOM_COMMAND(OUTPUT builtin-over.h
COMMAND bin2c ${CMAKE_CURRENT_SOURCE_DIR}/../vba-over.ini builtin-over.h builtin_over
DEPENDS bin2c ../vba-over.ini)
COMMAND ${BIN2C} ${CMAKE_CURRENT_SOURCE_DIR}/../vba-over.ini builtin-over.h builtin_over
DEPENDS ${BIN2C} ../vba-over.ini)
# I don't like duplicating/triplicating code, so I only declare
# event handlers once, and copy them in other places they are needed

BIN
src/wx/icons/VBA.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

View File

@ -1,4 +1,4 @@
IDI_MAINICON ICON "../win32/res/VBA.ico"
IDI_MAINICON ICON "icons/VBA.ico"
#include "wx/msw/wx.rc"