diff --git a/.travis.yml b/.travis.yml index 9ade01c6..83ee698b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ script: - mkdir -p -- "$DIR" - cd -- "$DIR" - if [ "$BUILD_ENV" != libretro ]; then $CMAKE $CMAKE_ARGS ..; fi - - make - - if [ "$BUILD_ENV" != libretro ]; then make install DESTDIR=/tmp/VBAM; fi + - if [ "$BUILD_ENV" != libretro ]; then ninja; else make; fi + - if [ "$BUILD_ENV" != libretro ]; then DESTDIR=/tmp/VBAM ninja install; fi - | if [ "$BUILD_ENV" = mac ]; then ./$PRGNAM.app/Contents/MacOS/$PRGNAM --help @@ -68,7 +68,7 @@ script: env: global: - - CMAKE_ARGS="" + - CMAKE_ARGS="-G Ninja" - ENABLE_SDL=1 - MAKEFLAGS="-j2" - PRGNAM=visualboyadvance-m diff --git a/CMakeLists.txt b/CMakeLists.txt index a0d9686f..010c0403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) # link to full path of libs cmake_policy(SET CMP0005 NEW) # escapes in add_definitions + if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) # use Package_ROOT if set + endif() + if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) # use vars for options endif() @@ -30,7 +34,7 @@ include(Set-Toolchain-vcpkg) set(VBAM_STATIC_DEFAULT OFF) -if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) +if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static") set(VBAM_STATIC_DEFAULT ON) endif() @@ -66,18 +70,14 @@ if(VBAM_STATIC) set(FFMPEG_STATIC ON) set(SSP_STATIC ON) set(OPENAL_STATIC ON) + set_property(GLOBAL PROPERTY LINK_SEARCH_START_STATIC ON) + set_property(GLOBAL PROPERTY LINK_SEARCH_END_STATIC ON) + + if(NOT MSVC) + list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .a) + endif() endif() -set(ENABLE_BUNDLED_LIBS_DEFAULT OFF) - -# on visual studio use all bundled stuff -if(MSVC) - set(ENABLE_BUNDLED_LIBS_DEFAULT ON) -endif() - -# XXX: do some stuff with this -#option(ENABLE_BUNDLED_LIBS "Use bundled libraries instead of system libraries" ${ENABLE_BUNDLED_LIBS_DEFAULT}) - # use ccache if available, and not already enabled on the command line # but not with ninja and msys ccache on msys2 if(NOT (WIN32 AND NOT "$ENV{MSYSTEM_PREFIX}" STREQUAL "" AND CMAKE_GENERATOR STREQUAL Ninja)) @@ -186,7 +186,7 @@ set(LTO_DEFAULT ON) # gcc lto produces buggy binaries for 64 bit mingw # and we generally don't want it when debugging because it makes linking slow -if(CMAKE_BUILD_TYPE MATCHES Debug OR (WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64)) +if(CMAKE_BUILD_TYPE MATCHES Debug OR (WIN32 AND CMAKE_COMPILER_IS_GNUCXX)) set(LTO_DEFAULT OFF) endif() diff --git a/cmake/Architecture.cmake b/cmake/Architecture.cmake index 99a0d0c7..d9d5731f 100644 --- a/cmake/Architecture.cmake +++ b/cmake/Architecture.cmake @@ -7,6 +7,10 @@ if(NOT CMAKE_SYSTEM_PROCESSOR) else() set(CMAKE_SYSTEM_PROCESSOR x86_64) endif() + elseif(CROSS_ARCH STREQUAL x86_64) + set(CMAKE_SYSTEM_PROCESSOR x86_64) + elseif(CROSS_ARCH STREQUAL i686) + set(CMAKE_SYSTEM_PROCESSOR i686) endif() endif() diff --git a/cmake/Toolchain-cross-MinGW-w64-common.cmake b/cmake/Toolchain-cross-MinGW-w64-common.cmake new file mode 100644 index 00000000..233306ec --- /dev/null +++ b/cmake/Toolchain-cross-MinGW-w64-common.cmake @@ -0,0 +1,76 @@ +SET(CMAKE_SYSTEM_NAME Windows) + +set(COMPILER_PREFIX "${CROSS_ARCH}-w64-mingw32") + +unset(CMAKE_RC_COMPILER CACHE) +unset(CMAKE_C_COMPILER CACHE) +unset(CMAKE_CXX_COMPILER CACHE) +unset(PKG_CONFIG_EXECUTABLE CACHE) + +# which compilers to use for C and C++ +find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) +find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) +find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) + +SET(CMAKE_FIND_ROOT_PATH + /usr/${COMPILER_PREFIX} + /usr/${COMPILER_PREFIX}/usr + /usr/${COMPILER_PREFIX}/sys-root/mingw + /usr/local/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} + /home/linuxbrew/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} + $ENV{HOME}/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} +) + +# find wx-config +foreach(p ${CMAKE_FIND_ROOT_PATH}) + file(GLOB paths ${p}/lib/wx/config/${COMPILER_PREFIX}-msw-*) + + list(APPEND wx_confs ${paths}) +endforeach() + +foreach(p ${wx_confs}) + if(CMAKE_TOOLCHAIN_FILE MATCHES -static) + string(REGEX MATCH "(static-)?([0-9]+\\.?)+$" wx_conf_ver ${p}) + else() + string(REGEX MATCH "([0-9]+\\.?)+$" wx_conf_ver ${p}) + endif() + + list(APPEND wx_conf_vers ${wx_conf_ver}) +endforeach() + +list(SORT wx_conf_vers) +list(REVERSE wx_conf_vers) +list(GET wx_conf_vers 0 wx_conf_ver) + +foreach(p ${wx_confs}) + if(p MATCHES "${wx_conf_ver}$") + set(wx_conf ${p}) + break() + endif() +endforeach() + +set(wxWidgets_CONFIG_EXECUTABLE ${wx_conf} CACHE FILEPATH "path to wx-config script for the desired wxWidgets configuration" FORCE) + +# find the right static zlib +if(CMAKE_TOOLCHAIN_FILE MATCHES -static) + foreach(p ${CMAKE_FIND_ROOT_PATH}) + if(EXISTS ${p}/lib/libz.a) + set(ZLIB_ROOT ${p} CACHE FILEPATH "where to find zlib" FORCE) + break() + endif() + endforeach() +endif() + +if(CMAKE_PREFIX_PATH) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) +endif() + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment too +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# pkg-config may be under the prefix +find_program(PKG_CONFIG_EXECUTABLE NAMES ${COMPILER_PREFIX}-pkg-config) diff --git a/cmake/Toolchain-cross-MinGW-w64-i686-static.cmake b/cmake/Toolchain-cross-MinGW-w64-i686-static.cmake new file mode 100644 index 00000000..4c696d6e --- /dev/null +++ b/cmake/Toolchain-cross-MinGW-w64-i686-static.cmake @@ -0,0 +1 @@ +include(Toolchain-cross-MinGW-w64-i686) diff --git a/cmake/Toolchain-cross-MinGW-w64-i686.cmake b/cmake/Toolchain-cross-MinGW-w64-i686.cmake index 1225f5ae..35838894 100644 --- a/cmake/Toolchain-cross-MinGW-w64-i686.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-i686.cmake @@ -1,30 +1,2 @@ -SET(CMAKE_SYSTEM_NAME Windows) - set(CROSS_ARCH i686) -set(COMPILER_PREFIX "${CROSS_ARCH}-w64-mingw32") - -unset(CMAKE_RC_COMPILER CACHE) -unset(CMAKE_C_COMPILER CACHE) -unset(CMAKE_CXX_COMPILER CACHE) -unset(PKG_CONFIG_EXECUTABLE CACHE) - -# which compilers to use for C and C++ -find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) -find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) -find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) - -SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/usr /usr/${COMPILER_PREFIX}/sys-root/mingw /usr/local/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} /home/linuxbrew/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} $ENV{HOME}/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX}) - -if(CMAKE_PREFIX_PATH) - set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) -endif() - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment too -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# pkg-config may be under the prefix -find_program(PKG_CONFIG_EXECUTABLE NAMES ${COMPILER_PREFIX}-pkg-config) +include(Toolchain-cross-MinGW-w64-common) diff --git a/cmake/Toolchain-cross-MinGW-w64-x86_64-static.cmake b/cmake/Toolchain-cross-MinGW-w64-x86_64-static.cmake new file mode 100644 index 00000000..9577702b --- /dev/null +++ b/cmake/Toolchain-cross-MinGW-w64-x86_64-static.cmake @@ -0,0 +1 @@ +include(Toolchain-cross-MinGW-w64-x86_64) diff --git a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake index cfdab986..4f71cb44 100644 --- a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake @@ -1,30 +1,2 @@ -SET(CMAKE_SYSTEM_NAME Windows) - set(CROSS_ARCH x86_64) -set(COMPILER_PREFIX "${CROSS_ARCH}-w64-mingw32") - -unset(CMAKE_RC_COMPILER CACHE) -unset(CMAKE_C_COMPILER CACHE) -unset(CMAKE_CXX_COMPILER CACHE) -unset(PKG_CONFIG_EXECUTABLE CACHE) - -# which compilers to use for C and C++ -find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) -find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) -find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) - -SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/usr /usr/${COMPILER_PREFIX}/sys-root/mingw /usr/local/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} /home/linuxbrew/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX} $ENV{HOME}/.linuxbrew/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX}) - -if(CMAKE_PREFIX_PATH) - set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) -endif() - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment too -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# pkg-config may be under the prefix -find_program(PKG_CONFIG_EXECUTABLE NAMES ${COMPILER_PREFIX}-pkg-config) +include(Toolchain-cross-MinGW-w64-common) diff --git a/installdeps b/installdeps index 78a1de5b..e7060a34 100755 --- a/installdeps +++ b/installdeps @@ -108,7 +108,8 @@ Examples: ./installdeps m32 # make a 32 bit binary for the host OS ./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) + ./installdeps win64 # cross-compile for 64 bit windows (Debian/Ubuntu, Arch Linux or MSYS2) + ./installdeps MinGW-w64-x86_64 # likewise EOF } @@ -260,7 +261,7 @@ check_cross() { fi case "$target" in - win32|mingw*) + win32|win64|mingw*) if [ -z "$arch_linux" -a -z "$msys2" -a -z "$debian" -a -z "$fedora" ]; then error 'win32 cross compiling targets are only supported on Debian/Ubuntu, Fedora, Arch and MSYS2 at the moment' fi @@ -269,12 +270,15 @@ check_cross() { win32) target='mingw-w64-i686' ;; + win64) + target='mingw-w64-x86_64' + ;; mingw-w64-i686) ;; mingw-w64-x86_64) ;; *) - error "target must be one of 'm32', 'win32', 'MinGW-w64-i686' or 'MinGW-w64-x86_64'" + error "target must be one of 'm32', 'win32', 'MinGW-w64-i686', 'win64' or 'MinGW-w64-x86_64'" ;; esac @@ -331,7 +335,7 @@ debian_installdeps() { wx_lib_dev=libwxgtk3.0-dev fi - pkgs="build-essential g++ nasm cmake ccache gettext zlib1g-dev libgl1-mesa-dev libgettextpo-dev libpng-dev libsdl2-dev libsdl2-2.0 libglu1-mesa-dev libglu1-mesa libgles2-mesa-dev libsfml-dev $sfml_libs $glew_lib $wx_lib $wx_lib_dev libgtk2.0-dev libgtk-3-dev ccache zip" + pkgs="build-essential g++ nasm cmake ccache gettext zlib1g-dev libgl1-mesa-dev libgettextpo-dev libpng-dev libsdl2-dev libsdl2-2.0 libglu1-mesa-dev libglu1-mesa libgles2-mesa-dev libsfml-dev $sfml_libs $glew_lib $wx_lib $wx_lib_dev libgtk2.0-dev libgtk-3-dev ccache zip ninja-build" [ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs libopenal-dev" [ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs libavcodec-dev libavformat-dev libswscale-dev libavutil-dev $libswresample_dev" @@ -391,7 +395,7 @@ debian_installdeps() { done check sudo apt-get --allow-unauthenticated -qq -y update # native wx-common needed for wxrc executable - check sudo apt-get --allow-unauthenticated -qy install build-essential cmake ccache wx-common "$@" + check sudo apt-get --allow-unauthenticated -qy install build-essential cmake ninja-build ccache wx-common "$@" fi build_instructions @@ -544,18 +548,18 @@ fedora_installdeps() { case "$target" in mingw-w64-i686) target=mingw32 - cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake" + cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686-static.cmake" ;; mingw-w64-x86_64) target=mingw64 - cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake" + cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64-static.cmake" ;; *) error 'unknown cross target (this should not happen)' ;; esac # install static deps - for pkg in zlib gettext libpng SDL2 wxWidgets; do + for pkg in zlib gettext libpng SDL2 wxWidgets3; do set -- "$@" "${target}-${pkg}-static" done # install deps that are not available as static @@ -770,7 +774,7 @@ suse_installdeps() { check_cross installing - tools="make cmake ccache nasm gettext-tools pkg-config ccache zip sfml2-devel" + tools="make cmake ccache nasm gettext-tools pkg-config ccache zip sfml2-devel ninja" libs="gcc gcc-c++ libpng16-devel libSDL2-devel wxWidgets-3_0-devel" # ffmpeg-devel @@ -824,7 +828,7 @@ archlinux_installdeps() { # common needed dev packages # not using the base-devel group because it can break gcc-multilib - check $pacman --noconfirm --needed -S binutils file grep gawk gzip libtool make patch sed util-linux nasm cmake ccache pkg-config git ccache zip + check $pacman --noconfirm --needed -S binutils file grep gawk gzip libtool make patch sed util-linux nasm cmake ccache pkg-config git ccache zip ninja gtk=gtk3 @@ -950,7 +954,7 @@ solus_installdeps() { check sudo eopkg -y update-repo check sudo eopkg -y install -c system.devel - check sudo eopkg -y install git ccache + check sudo eopkg -y install git ccache ninja set -- sdl2-devel wxwidgets-devel libgtk-2-devel libgtk-3-devel @@ -1019,7 +1023,7 @@ gentoo_installdeps() { check sudo emerge-webrsync - ebuilds="gcc make cmake ccache binutils libsdl2 libsfml wxGTK zlib dev-util/pkgconfig nasm" + ebuilds="gcc make cmake ccache binutils libsdl2 libsfml wxGTK zlib dev-util/pkgconfig nasm dev-util/ninja" [ -n "$ENABLE_OPENAL" ] && ebuilds="$ebuilds media-libs/openal" @@ -1039,7 +1043,7 @@ windows_installdeps() { # update catalogs check pacman -Sy - pkgs="SDL2 sfml wxWidgets zlib binutils cmake crt-git extra-cmake-modules gcc gcc-libs gcc-libgfortran gdb headers-git make pkg-config tools-git windows-default-manifest libmangle-git nasm" + pkgs="SDL2 sfml wxWidgets zlib binutils cmake crt-git extra-cmake-modules gcc gcc-libs gcc-libgfortran gdb headers-git make pkg-config tools-git windows-default-manifest libmangle-git nasm ninja" [ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs openal" [ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg" @@ -1098,7 +1102,7 @@ brew_installdeps() { check brew -v update - brews="nasm cmake ccache gettext libpng pkg-config sdl2 wxmac ccache" + brews="nasm cmake ccache gettext libpng pkg-config sdl2 wxmac ccache ninja" [ -n "$ENABLE_FFMPEG" ] && brews="$brews ffmpeg" @@ -1128,7 +1132,7 @@ macports_installdeps() { check sudo port -v selfupdate - ports="cmake ccache nasm gettext libpng pkgconfig libsdl2 sfml wxWidgets-3.0 libiconv" + ports="cmake ccache nasm gettext libpng pkgconfig libsdl2 sfml wxWidgets-3.0 libiconv ninja" [ -n "$ENABLE_FFMPEG" ] && ports="$ports ffmpeg" @@ -1144,7 +1148,7 @@ fink_installdeps() { check sudo fink -vy selfupdate - pkgs="cmake ccache nasm libgettext8-dev gettext-tools libpng16 pkgconfig sdl2 wxwidgets300-osxcocoa libiconv-dev sfml24-dev ccache" + pkgs="cmake ccache nasm libgettext8-dev gettext-tools libpng16 pkgconfig sdl2 wxwidgets300-osxcocoa libiconv-dev sfml24-dev ccache ninja" [ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg" @@ -1160,8 +1164,8 @@ build_instructions() { $pre_build mkdir -p build && cd build -$CMAKE .. $cmake_flags -make $(jobs_flag) +$CMAKE .. $cmake_flags -G Ninja +ninja $post_build EOF diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 82c79424..18c51068 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -4,11 +4,16 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) # link to full path of libs cmake_policy(SET CMP0005 NEW) # escapes in add_definitions + + if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) # use Package_ROOT if set + endif() + if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) # use vars for options endif() - if(NOT CMAKE_VERSION VERSION_LESS 3.0) + if(POLICY CMP0043) cmake_policy(SET CMP0043 NEW) # for wxWidgets, use generator expressions endif() endif()