auto deps for visual studio, take 1

Use vcpkg to build deps when Visual Studio on Windows is detected, this
only happens on first build, but does take a while because things like
wxWidgets need to be built. Building from the developer command line is
also supported.

I considered making a pre-built tarball available, but the resulting
files are just too big for this to be practical.

Make the necessary cmake code changes for this to work and to use the
vcpkg packages, which work just like on linux or have other cmake glue
code available.

To do this, we make vcpkg a submodule, use git to checkout all
submodules, then just build and use the `vcpkg.exe`. Then we set the
CMAKE_TOOLCHAIN_FILE to the vcpkg toolchain and also include it
directly, why this is necessary I don't know, without it it doesn't work
in the IDE but does on the command line.

All of this requires no vcpkg integration with either the user or the
project. A user-wide `ENV{VCPKG_ROOT}` is also supported.

Fix the dynamic arrays in the GBA core, MSVC follows the C++ standard on
this and gcc does not.

TODO: add the necessary gcc flags to make this an error in cmake.

Use `wxArrayString` instead of `std::vector<wxString>` in
`src/wx/strutils.cpp` which is used in options parsing. This was
necessary because of a bizarre linker error with wxWidgets when using
Visual Studio:

https://trac.wxwidgets.org/ticket/10884#comment:46

In `src/wx/panel.cpp` make sure the unimplemented D3D renderer code does
not get compiled if it's actually `OFF`.

Also fix the new spacer code for the drawing panel to not combine
`wxEXPAND` with `wxALIGN_CENTER`, which is an error on wxWidgets 3.1.2,
which is what vcpkg uses. The drawing panel seems to be automatically
stretched to the max size automatically anyway.

TODO: if all of this works, we'll need an Appveyor set up for visual
studio.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-03-21 16:01:46 -07:00
parent 3da07f4083
commit f1ecd7c322
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
13 changed files with 525 additions and 320 deletions

2
.gitignore vendored
View File

@ -6,7 +6,9 @@ src/wx/cmdtab.cpp
src/wx/wxvbam.xrs
build/*
build32/*
vsbuild/*
dependencies/*
vcpkg/*
.vs/*
*.o
*.so

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "dependencies"]
path = dependencies
url = https://github.com/visualboyadvance-m/dependencies.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/Microsoft/vcpkg.git

View File

@ -1,3 +1,17 @@
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # link to full path of libs
cmake_policy(SET CMP0005 NEW) # escapes in add_definitions
endif()
option(ENABLE_VCPKG "Use dependencies for Visual Studio from vcpkg" ON)
set(NLS_DEFAULT ON)
# get win32 deps before project declaration, because toolchain is set for vcpkg
set(VCPKG_DEPS zlib libpng SDL2 SFML gettext wxWidgets)
include(${CMAKE_SOURCE_DIR}/cmake/Win32Deps.cmake)
project(VBA-M C CXX)
cmake_minimum_required(VERSION 2.8.12)
@ -12,19 +26,13 @@ endif()
set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # link to full path of libs
cmake_policy(SET CMP0005 NEW) # escapes in add_definitions
endif()
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
#Output all binaries at top level
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
option(ENABLE_SDL "Build the SDL port" OFF)
option(ENABLE_WX "Build the wxWidgets port" ON)
option(ENABLE_DEBUGGER "Enable the debugger" ON)
option(ENABLE_NLS "Enable translations" ON)
option(ENABLE_ASAN "Enable -fsanitize=<option>, address by default, requires debug build" OFF)
option(VBAM_STATIC "Try to link all libraries statically" OFF)
@ -37,7 +45,15 @@ if(VBAM_STATIC)
set(OPENAL_STATIC ON)
endif()
set(ASM_DEFAULT OFF)
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
@ -51,32 +67,14 @@ if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "") AND CMAKE_GENERATOR STREQUAL N
endif()
endif()
if(NOT CMAKE_SYSTEM_PROCESSOR)
if(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
elseif(CMAKE_TOOLCHAIN_FILE MATCHES mxe)
if(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86")
set(CMAKE_SYSTEM_PROCESSOR i686)
else()
set(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()
endif()
endif()
# turn asm on by default on 32bit x86
if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64")
if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 4) # 32 bit
set(ASM_DEFAULT ON)
set(X86_32 ON)
else()
set(AMD64 ON)
endif()
endif()
set(SSP_DEFAULT OFF)
option(ENABLE_SSP "Enable gcc stack protector support" ${SSP_DEFAULT})
set(ASM_DEFAULT OFF)
include(Architecture)
option(ENABLE_ASM "Enable x86 ASM related options" ${ASM_DEFAULT})
# The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being
@ -134,6 +132,13 @@ if(NOT ENABLE_DEBUGGER AND ENABLE_SDL)
message(SEND_ERROR "The SDL port can't be built without debugging support")
endif()
# this has to run after the toolchain is initialized so it can't be in
# Win32deps.cmake
if(MINGW)
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
endif()
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
include(GitTagVersion)
@ -204,7 +209,7 @@ add_definitions(${SDL2_DEFINITIONS})
if(ENABLE_LINK)
# msys2 does not have static sfml libs atm
# while on mxe we use static libs
if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe))
if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2 COMPONENTS network system REQUIRED)
@ -297,6 +302,8 @@ if(NOT ENABLE_ASM_CORE)
add_definitions(-DC_CORE)
endif()
option(ENABLE_NLS "Enable translations" ${NLS_DEFAULT})
# Enable internationalization
if(ENABLE_NLS)
set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
@ -332,30 +339,6 @@ if(ENABLE_NLS)
endif()
endif()
# Win32 deps submodule
if(WIN32)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
set(git_checkout FALSE)
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(git_checkout TRUE)
execute_process(COMMAND "${GIT_EXECUTABLE}" submodule update --init --remote --recursive RESULT_VARIABLE git_status WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif()
if(NOT (git_checkout AND git_status EQUAL 0))
message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive")
endif()
endif()
if(MINGW)
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
elseif(MSVC)
set(DEPS_MSVC "${CMAKE_SOURCE_DIR}/dependencies/msvc")
include_directories("${DEPS_MSVC}") # for GL/glext.h and getopt.h
endif()
endif()
include(ProcessorCount)
ProcessorCount(num_cpus)

53
CMakeSettings.json Normal file
View File

@ -0,0 +1,53 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}

View File

@ -63,7 +63,20 @@ make -j`nproc`
`./installdeps` is supported on MSys2, Linux (Debian/Ubuntu, Fedora, Arch or
Solus) and Mac OS X (homebrew, macports or fink.)
The Ninja cmake generator is also now supported, including on msys2.
The Ninja cmake generator is also now supported, including on msys2 and Visual Studio.
### Visual Studio Support
For visual studio, dependency management is handled automatically with vcpkg,
just clone the repository with git and build with cmake. You can do this from
the developer command line as well. 2019 will not work yet for building
dependencies, but you can build the dependencies in 2017 and then use the
project from 2019.
Using your own user-wide installation of vcpkg is supported, just make sure the
environment variable `VCPKG_ROOT` is set.
### Dependencies
If your OS is not supported, you will need the following:

24
cmake/Architecture.cmake Normal file
View File

@ -0,0 +1,24 @@
if(NOT CMAKE_SYSTEM_PROCESSOR)
if(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
elseif(CMAKE_TOOLCHAIN_FILE MATCHES mxe)
if(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86")
set(CMAKE_SYSTEM_PROCESSOR i686)
else()
set(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()
endif()
endif()
# turn asm on by default on 32bit x86
# and set WINARCH for windows stuff
if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64")
if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 4) # 32 bit
if(NOT (MSVC AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg))
set(ASM_DEFAULT ON)
endif()
set(X86_32 ON)
else()
set(AMD64 ON)
endif()
endif()

62
cmake/Win32Deps.cmake Normal file
View File

@ -0,0 +1,62 @@
if(WIN32)
# compiler has not been detected yet maybe
if(CMAKE_C_COMPILER MATCHES "cl\\.exe" OR CMAKE_CXX_COMPILER MATCHES "cl\\.exe" OR MSVC OR DEFINED ENV{VisualStudioVersion})
set(VS TRUE)
endif()
set(WINARCH x86)
if(CMAKE_C_COMPILER MATCHES x64 OR CMAKE_CXX_COMPILER MATCHES x64 OR $ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
set(WINARCH x64)
endif()
# Win32 deps submodules (dependencies and vcpkg)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include" OR NOT EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(git_checkout FALSE)
# find_package(Git)
#if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(git_checkout TRUE)
execute_process(COMMAND git submodule update --init --remote --recursive RESULT_VARIABLE git_status WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif()
if(NOT (git_checkout AND git_status EQUAL 0))
message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive")
endif()
endif()
if(VS)
set(DEPS_MSVC "${CMAKE_SOURCE_DIR}/dependencies/msvc")
include_directories("${DEPS_MSVC}") # for GL/glext.h and getopt.h
endif()
if(VS AND ENABLE_VCPKG)
if(NOT DEFINED ENV{VCPKG_ROOT})
set(ENV{VCPKG_ROOT} "${CMAKE_SOURCE_DIR}/vcpkg")
endif()
# build vcpkg if not built
if(NOT EXISTS $ENV{VCPKG_ROOT}/vcpkg.exe)
execute_process(
COMMAND bootstrap-vcpkg.bat
WORKING_DIRECTORY $ENV{VCPKG_ROOT}
)
endif()
foreach(pkg ${VCPKG_DEPS})
#list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${WINARCH}-windows-static)
list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${WINARCH}-windows)
endforeach()
# build our deps
execute_process(
COMMAND vcpkg install ${VCPKG_DEPS_QUALIFIED}
WORKING_DIRECTORY $ENV{VCPKG_ROOT}
)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH '' FORCE)
include("$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(NLS_DEFAULT OFF)
set(ENABLE_NLS OFF) # not sure why this is necessary
endif()
endif()

View File

@ -3528,7 +3528,7 @@ void remotePutPacket(const char* packet)
const char* hex = "0123456789abcdef";
size_t count = strlen(packet);
char buffer[count + 5];
char* buffer = new char[count + 5];
unsigned char csum = 0;
@ -3548,10 +3548,15 @@ void remotePutPacket(const char* packet)
char c = 0;
while (c != '+') {
remoteSendFnc(buffer, (int)count + 4);
if (remoteRecvFnc(&c, 1) < 0)
if (remoteRecvFnc(&c, 1) < 0) {
delete buffer;
return;
}
// fprintf(stderr,"sent:%s recieved:%c\n",buffer,c);
}
delete buffer;
}
void remoteOutput(const char* s, uint32_t addr)
@ -3684,7 +3689,7 @@ void remoteMemoryRead(char* p)
sscanf(p, "%x,%x:", &address, &count);
// monprintf("Memory read for %08x %d\n", address, count);
char buffer[(count*2)+1];
char* buffer = new char[(count*2)+1];
char* s = buffer;
for (int i = 0; i < count; i++) {
@ -3695,6 +3700,8 @@ void remoteMemoryRead(char* p)
}
*s = 0;
remotePutPacket(buffer);
delete buffer;
}
void remoteQuery(char* p)

View File

@ -7,11 +7,16 @@ ENDIF()
include(VbamFunctions)
if( WIN32 )
# not yet implemented
option( ENABLE_DIRECT3D "Enable Direct3D rendering for the wxWidgets port" ON )
option( ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" ON )
endif( WIN32 )
if(WIN32)
# not yet implemented
option(ENABLE_DIRECT3D "Enable Direct3D rendering for the wxWidgets port" OFF)
if(NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
option(ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" ON)
else()
option(ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" OFF)
endif()
endif()
option(ENABLE_FAUDIO "Enable FAudio sound output for the wxWidgets port" OFF)
@ -50,115 +55,169 @@ if(ENABLE_FAUDIO)
set(FAUDIO_LIBS FAudio)
endif()
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm
ENDIF()
# on VS with vcpkg we can't use FindwxWidgets, we have to set everything up
# manually because the package is broken
if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64))
# set up wxwidgets stuff
add_definitions(-D_UNICODE -DUNICODE -DWXUSINGDLL -DwxUSE_GUI=1 -D__WXMSW__)
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
add_definitions(-D_DEBUG)
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/debug/lib/mswud)
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/include)
set(wxWidgets_LIB_DIR ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/debug/lib)
set(wxWidgets_LIBRARIES
${wxWidgets_LIB_DIR}/wxbase31ud_net.lib
${wxWidgets_LIB_DIR}/wxbase31ud_xml.lib
${wxWidgets_LIB_DIR}/wxmsw31ud_core.lib
${wxWidgets_LIB_DIR}/wxmsw31ud_gl.lib
${wxWidgets_LIB_DIR}/wxmsw31ud_xrc.lib
${wxWidgets_LIB_DIR}/wxbase31ud.lib
winmm comctl32 oleacc rpcrt4 shlwapi version wsock32 opengl32
)
# on e.g. msys2 add a couple of libraries wx needs
#if(WIN32 AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang))
# set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -luuid -lwinspool")
#endif()
file(COPY ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows-dbg/lib/wxrc.exe DESTINATION ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/debug/bin)
set(WXRC ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/debug/bin/wxrc.exe)
elseif("${CMAKE_BUILD_TYPE}" MATCHES "Release")
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/lib/mswu)
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/include)
set(wxWidgets_LIB_DIR ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/lib)
set(wxWidgets_LIBRARIES
${wxWidgets_LIB_DIR}/wxbase31u_net.lib
${wxWidgets_LIB_DIR}/wxbase31u_xml.lib
${wxWidgets_LIB_DIR}/wxmsw31u_core.lib
${wxWidgets_LIB_DIR}/wxmsw31u_gl.lib
${wxWidgets_LIB_DIR}/wxmsw31ud_xrc.lib
${wxWidgets_LIB_DIR}/wxbase31u.lib
winmm comctl32 oleacc rpcrt4 shlwapi version wsock32 opengl32
)
# convert msys paths like /c/foo to windows paths like c:/foo
# for variables set by FindWxWidgets
function(normalize_wx_paths)
if(MSYS)
unset(new_paths)
foreach(p ${wxWidgets_LIBRARY_DIRS})
execute_process(COMMAND cygpath -m "${p}" OUTPUT_VARIABLE p_win OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND new_paths "${p_win}")
endforeach()
set(wxWidgets_LIBRARY_DIRS ${new_paths} PARENT_SCOPE)
string(REGEX REPLACE "((^| )[^/]*)/([a-zA-Z])/" "\\1\\3:/" new_libs "${wxWidgets_LIBRARIES}")
set(wxWidgets_LIBRARIES ${new_libs} PARENT_SCOPE)
file(COPY ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows-rel/lib/wxrc.exe DESTINATION ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/bin)
set(WXRC ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/bin/wxrc.exe)
endif()
endfunction()
macro(cleanup_wx_vars)
if(wxWidgets_CXX_FLAGS)
list(REMOVE_ITEM wxWidgets_CXX_FLAGS -fpermissive)
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe)
# get zip binary for wxrc
file(DOWNLOAD "https://www.willus.com/archive/zip64/infozip_binaries_win32.zip" ${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip)
# unzip it
execute_process(
COMMAND powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip', '${CMAKE_CURRENT_BINARY_DIR}'); }"
)
endif()
endmacro()
if(CMAKE_PREFIX_PATH)
set(wxWidgets_CONFIG_OPTIONS "--prefix=${CMAKE_PREFIX_PATH}")
endif()
SET(wxWidgets_USE_UNICODE ON)
# adv is for wxAboutBox
# xml, html is for xrc
# do not include gl at first
set(wxWidgets_USE_LIBS xrc xml html adv net core base)
#list(APPEND wxWidgets_CONFIG_OPTIONS --version=2.8)
# Check for gtk4 then gtk3 packages first, some dists like arch rename the
# wx-config utility for these packages to e.g. wx-config-gtk3
#
# Do not do the check if the WX_CONFIG env var is set.
if(NOT WIN32 AND NOT APPLE AND "$ENV{WX_CONFIG}" STREQUAL "")
find_program(wxWidgets_CONFIG_EXECUTABLE NAMES wx-config-gtk4 wx-config-gtk3 wx-config)
endif()
# the gl lib may not be available, and if it looks like it is we still have to
# do a compile test later
list(APPEND wxWidgets_USE_LIBS gl)
find_package(wxWidgets QUIET)
cleanup_wx_vars()
normalize_wx_paths()
SET(CHECK_WX_OPENGL FALSE)
IF(wxWidgets_FOUND)
SET(CHECK_WX_OPENGL TRUE)
ELSE()
SET(WX_HAS_OPENGL FALSE)
# the requirement check is later after the opengl compile test
ENDIF()
INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIRS})
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
# tell wx to enable debug mode if possible, if the cmake module did not do it for us
EXECUTE_PROCESS(COMMAND "${wxWidgets_CONFIG_EXECUTABLE} --debug=yes" RESULT_VARIABLE WX_CONFIG_DEBUG OUTPUT_QUIET ERROR_QUIET)
IF(WX_CONFIG_DEBUG EQUAL 0)
ADD_DEFINITIONS(-DwxDEBUG_LEVEL=1)
# SDL2.dll does not get copied to build dir
if(NOT EXISTS ${CMAKE_BINARY_DIR}/SDL2.dll)
file(COPY ${_VCPKG_ROOT_DIR}/installed/${WINARCH}-windows/bin/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR})
endif()
else()
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm
ENDIF()
# this one should be safe in non-debug builds too
ADD_DEFINITIONS(-DWXDEBUG)
ENDIF()
# on e.g. msys2 add a couple of libraries wx needs
#if(WIN32 AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang))
# set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -luuid -lwinspool")
#endif()
FOREACH(DEF ${wxWidgets_DEFINITIONS})
ADD_DEFINITIONS("-D${DEF}")
ENDFOREACH()
# convert msys paths like /c/foo to windows paths like c:/foo
# for variables set by FindWxWidgets
function(normalize_wx_paths)
if(MSYS)
unset(new_paths)
foreach(p ${wxWidgets_LIBRARY_DIRS})
execute_process(COMMAND cygpath -m "${p}" OUTPUT_VARIABLE p_win OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND new_paths "${p_win}")
endforeach()
# check if this build of wx actually has OpenGL support
set(wxWidgets_LIBRARY_DIRS ${new_paths} PARENT_SCOPE)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MY_CXX_FLAGS} ${MY_C_FLAGS} ${MY_CXX_LINKER_FLAGS} ${MY_C_LINKER_FLAGS} ${wxWidgets_LIBRARIES})
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${wxWidgets_CXX_FLAGS} ${MY_CXX_FLAGS} ${MY_C_FLAGS})
string(REGEX REPLACE "((^| )[^/]*)/([a-zA-Z])/" "\\1\\3:/" new_libs "${wxWidgets_LIBRARIES}")
IF(WIN32)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-Wl,--subsystem,console")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--subsystem,console")
ENDIF()
set(wxWidgets_LIBRARIES ${new_libs} PARENT_SCOPE)
endif()
endfunction()
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${wxWidgets_INCLUDE_DIRS})
macro(cleanup_wx_vars)
if(wxWidgets_CXX_FLAGS)
list(REMOVE_ITEM wxWidgets_CXX_FLAGS -fpermissive)
endif()
endmacro()
FOREACH(DEF ${wxWidgets_DEFINITIONS})
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-D${DEF}")
ENDFOREACH()
if(CMAKE_PREFIX_PATH)
set(wxWidgets_CONFIG_OPTIONS "--prefix=${CMAKE_PREFIX_PATH}")
endif()
# CheckCXXSourceCompiles ignores compiler flags, so we have to stuff them into the definitions
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_FLAGS} ${CMAKE_REQUIRED_DEFINITIONS})
SET(wxWidgets_USE_UNICODE ON)
# adv is for wxAboutBox
# xml, html is for xrc
# do not include gl at first
set(wxWidgets_USE_LIBS xrc xml html adv net core base)
#list(APPEND wxWidgets_CONFIG_OPTIONS --version=2.8)
INCLUDE(CheckCXXSourceCompiles)
# Check for gtk4 then gtk3 packages first, some dists like arch rename the
# wx-config utility for these packages to e.g. wx-config-gtk3
#
# Do not do the check if the WX_CONFIG env var is set.
if(NOT WIN32 AND NOT APPLE AND "$ENV{WX_CONFIG}" STREQUAL "")
find_program(wxWidgets_CONFIG_EXECUTABLE NAMES wx-config-gtk4 wx-config-gtk3 wx-config)
endif()
IF(CHECK_WX_OPENGL)
CHECK_CXX_SOURCE_COMPILES("
# the gl lib may not be available, and if it looks like it is we still have to
# do a compile test later
list(APPEND wxWidgets_USE_LIBS gl)
find_package(wxWidgets QUIET)
cleanup_wx_vars()
normalize_wx_paths()
SET(CHECK_WX_OPENGL FALSE)
IF(wxWidgets_FOUND)
SET(CHECK_WX_OPENGL TRUE)
ELSE()
SET(WX_HAS_OPENGL FALSE)
# the requirement check is later after the opengl compile test
ENDIF()
INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIRS})
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
# tell wx to enable debug mode if possible, if the cmake module did not do it for us
EXECUTE_PROCESS(COMMAND "${wxWidgets_CONFIG_EXECUTABLE} --debug=yes" RESULT_VARIABLE WX_CONFIG_DEBUG OUTPUT_QUIET ERROR_QUIET)
IF(WX_CONFIG_DEBUG EQUAL 0)
ADD_DEFINITIONS(-DwxDEBUG_LEVEL=1)
ENDIF()
# this one should be safe in non-debug builds too
ADD_DEFINITIONS(-DWXDEBUG)
ENDIF()
FOREACH(DEF ${wxWidgets_DEFINITIONS})
ADD_DEFINITIONS("-D${DEF}")
ENDFOREACH()
# check if this build of wx actually has OpenGL support
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MY_CXX_FLAGS} ${MY_C_FLAGS} ${MY_CXX_LINKER_FLAGS} ${MY_C_LINKER_FLAGS} ${wxWidgets_LIBRARIES})
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${wxWidgets_CXX_FLAGS} ${MY_CXX_FLAGS} ${MY_C_FLAGS})
IF(WIN32)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-Wl,--subsystem,console")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--subsystem,console")
ENDIF()
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${wxWidgets_INCLUDE_DIRS})
FOREACH(DEF ${wxWidgets_DEFINITIONS})
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-D${DEF}")
ENDFOREACH()
# CheckCXXSourceCompiles ignores compiler flags, so we have to stuff them into the definitions
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_FLAGS} ${CMAKE_REQUIRED_DEFINITIONS})
INCLUDE(CheckCXXSourceCompiles)
IF(CHECK_WX_OPENGL)
CHECK_CXX_SOURCE_COMPILES("
#include <wx/wxprec.h>
#include <wx/config.h>
#include <wx/glcanvas.h>
@ -167,22 +226,22 @@ int main(int argc, char** argv) {
wxGLCanvas canvas(NULL, wxID_ANY, NULL, wxPoint(0, 0), wxSize(300, 300), 0);
return 0;
}" WX_HAS_OPENGL)
ENDIF()
ENDIF()
IF(NOT WX_HAS_OPENGL)
ADD_DEFINITIONS(-DNO_OGL)
LIST(REMOVE_ITEM wxWidgets_USE_LIBS gl)
find_package(wxWidgets REQUIRED)
normalize_wx_paths()
cleanup_wx_vars()
ENDIF()
IF(NOT WX_HAS_OPENGL)
ADD_DEFINITIONS(-DNO_OGL)
LIST(REMOVE_ITEM wxWidgets_USE_LIBS gl)
find_package(wxWidgets REQUIRED)
normalize_wx_paths()
cleanup_wx_vars()
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CROSSCOMPILING)
SET(WX_ABI_FOUND_MATCH FALSE)
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CROSSCOMPILING)
SET(WX_ABI_FOUND_MATCH FALSE)
INCLUDE(CheckCXXSourceRuns)
INCLUDE(CheckCXXSourceRuns)
SET(WX_TEST_CONSOLE_APP "
SET(WX_TEST_CONSOLE_APP "
#include <cstdlib>
#include <iostream>
#include <wx/wxprec.h>
@ -251,140 +310,150 @@ int main(int argc, char** argv)
}
")
# on windows we need the trampoline library from dependencies
IF(WIN32)
# minhook requires -fpermissive unfortunately
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -fpermissive)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -fpermissive -w "-I${CMAKE_SOURCE_DIR}/dependencies/minhook/include")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -Wl,--subsystem,console)
# on windows we need the trampoline library from dependencies
IF(WIN32)
# minhook requires -fpermissive unfortunately
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -fpermissive)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -fpermissive -w "-I${CMAKE_SOURCE_DIR}/dependencies/minhook/include")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -Wl,--subsystem,console)
IF(AMD64)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "${CMAKE_SOURCE_DIR}/dependencies/minhook/libMinHook_64.a")
ELSE() # assume 32 bit windows
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "${CMAKE_SOURCE_DIR}/dependencies/minhook/libMinHook.a")
ENDIF()
ENDIF()
CHECK_CXX_SOURCE_RUNS("${WX_TEST_CONSOLE_APP}" WX_DEFAULT_ABI_VERSION_COMPATIBLE)
# remove -fpermissive set for minhook
list(REMOVE_ITEM CMAKE_REQUIRED_FLAGS -fpermissive)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -fpermissive)
IF(NOT WX_DEFAULT_ABI_VERSION_COMPATIBLE)
# currently goes up to 11 with gcc7, but we give it some room
SET(WX_ABI_VERSION 15)
SET(CURRENT_DEFS ${CMAKE_REQUIRED_DEFINITIONS})
SET(CURRENT_LIBS ${CMAKE_REQUIRED_LIBRARIES})
WHILE(NOT WX_ABI_VERSION EQUAL -1)
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS} "-fabi-version=${WX_ABI_VERSION}")
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS} "-fabi-version=${WX_ABI_VERSION}")
SET(WX_ABI_VAR "WX_ABI_VERSION_${WX_ABI_VERSION}")
CHECK_CXX_SOURCE_RUNS("${WX_TEST_CONSOLE_APP}" ${WX_ABI_VAR})
IF(${${WX_ABI_VAR}})
SET(WX_ABI_FOUND_MATCH TRUE)
BREAK()
IF(AMD64)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "${CMAKE_SOURCE_DIR}/dependencies/minhook/libMinHook_64.a")
ELSE() # assume 32 bit windows
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "${CMAKE_SOURCE_DIR}/dependencies/minhook/libMinHook.a")
ENDIF()
MATH(EXPR WX_ABI_VERSION "${WX_ABI_VERSION} - 1")
ENDWHILE()
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS})
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS})
ENDIF()
IF(WX_ABI_FOUND_MATCH)
# add C++ flags
STRING(REGEX REPLACE "<FLAGS>" "<FLAGS> -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT})
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -fabi-version=${WX_ABI_VERSION}")
ENDIF()
ENDIF()
# end of wx compile checks
FOREACH(CXX_COMPILE_FLAG ${wxWidgets_CXX_FLAGS})
ADD_COMPILE_OPTIONS(${CXX_COMPILE_FLAG})
ENDFOREACH()
#EXECUTE_PROCESS(COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --cxxflags)
INCLUDE( ${wxWidgets_USE_FILE} )
FIND_PACKAGE ( Gettext REQUIRED )
FIND_PROGRAM(XGETTEXT xgettext)
FIND_PROGRAM(MSGINIT msginit)
if(ENABLE_NLS AND (NOT XGETTEXT OR NOT MSGINIT))
message(SEND_ERROR "Cannot find gettext ${XGETTEXT} ${MSGINIT}")
endif(ENABLE_NLS AND (NOT XGETTEXT OR NOT MSGINIT))
IF(WIN32 AND ENABLE_DIRECTX)
FIND_PACKGE ( DirectX REQUIRED )
ENDIF(WIN32 AND ENABLE_DIRECTX)
# we make some direct gtk/gdk calls on linux and such
# so need to link the gtk that wx was built with
IF(NOT WIN32 AND NOT APPLE)
FIND_PACKAGE(PkgConfig REQUIRED)
FIND_PATH(WX_CONFIG_H NAMES wx/config.h PATHS ${wxWidgets_INCLUDE_DIRS})
IF(NOT WX_CONFIG_H)
MESSAGE(FATAL_ERROR "Could not find wx/config.h in ${wxWidgets_INCLUDE_DIRS}")
ENDIF()
SET(WX_CONFIG_H "${WX_CONFIG_H}/wx/config.h")
INCLUDE(CheckCXXSymbolExists)
CHECK_CXX_SYMBOL_EXISTS(__WXGTK4__ ${WX_CONFIG_H} WX_USING_GTK4)
CHECK_CXX_SYMBOL_EXISTS(__WXGTK3__ ${WX_CONFIG_H} WX_USING_GTK3)
IF(WX_USING_GTK4)
PKG_CHECK_MODULES(GTK4 REQUIRED gtk+-4.0)
IF(NOT GTK4_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk4")
ENDIF()
INCLUDE_DIRECTORIES(${GTK4_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK4_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK4_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK4_LIBRARIES})
ELSEIF(WX_USING_GTK3)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
IF(NOT GTK3_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk3")
ENDIF()
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK3_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK3_LIBRARIES})
ELSE()
CHECK_CXX_SYMBOL_EXISTS(__WXGTK20__ ${WX_CONFIG_H} WX_USING_GTK2)
IF(WX_USING_GTK2)
# try to use pkg-config to find gtk2 first
PKG_CHECK_MODULES(GTK2 REQUIRED gtk+-2.0)
IF(GTK2_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK2_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK2_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK2_LIBRARIES})
ELSE()
# and if that fails, use the cmake module
FIND_PACKAGE(GTK2 REQUIRED gtk)
IF(NOT GTK2_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk2")
CHECK_CXX_SOURCE_RUNS("${WX_TEST_CONSOLE_APP}" WX_DEFAULT_ABI_VERSION_COMPATIBLE)
# remove -fpermissive set for minhook
list(REMOVE_ITEM CMAKE_REQUIRED_FLAGS -fpermissive)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -fpermissive)
IF(NOT WX_DEFAULT_ABI_VERSION_COMPATIBLE)
# currently goes up to 11 with gcc7, but we give it some room
SET(WX_ABI_VERSION 15)
SET(CURRENT_DEFS ${CMAKE_REQUIRED_DEFINITIONS})
SET(CURRENT_LIBS ${CMAKE_REQUIRED_LIBRARIES})
WHILE(NOT WX_ABI_VERSION EQUAL -1)
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS} "-fabi-version=${WX_ABI_VERSION}")
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS} "-fabi-version=${WX_ABI_VERSION}")
SET(WX_ABI_VAR "WX_ABI_VERSION_${WX_ABI_VERSION}")
CHECK_CXX_SOURCE_RUNS("${WX_TEST_CONSOLE_APP}" ${WX_ABI_VAR})
IF(${${WX_ABI_VAR}})
SET(WX_ABI_FOUND_MATCH TRUE)
BREAK()
ENDIF()
INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
ADD_COMPILE_OPTIONS(${GTK2_DEFINITIONS})
SET(GTK_LIBRARIES ${GTK2_LIBRARIES})
ENDIF()
ELSE()
FIND_PACKAGE(GTK REQUIRED gtk)
IF(NOT GTK_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk")
ENDIF()
INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS})
ADD_COMPILE_OPTIONS(${GTK_DEFINITIONS})
MATH(EXPR WX_ABI_VERSION "${WX_ABI_VERSION} - 1")
ENDWHILE()
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS})
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS})
ENDIF()
IF(WX_ABI_FOUND_MATCH)
# add C++ flags
STRING(REGEX REPLACE "<FLAGS>" "<FLAGS> -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT})
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -fabi-version=${WX_ABI_VERSION}")
ENDIF()
ENDIF()
ENDIF()
# end of wx compile checks
FOREACH(CXX_COMPILE_FLAG ${wxWidgets_CXX_FLAGS})
ADD_COMPILE_OPTIONS(${CXX_COMPILE_FLAG})
ENDFOREACH()
# we make some direct gtk/gdk calls on linux and such
# so need to link the gtk that wx was built with
IF(NOT WIN32 AND NOT APPLE)
FIND_PACKAGE(PkgConfig REQUIRED)
FIND_PATH(WX_CONFIG_H NAMES wx/config.h PATHS ${wxWidgets_INCLUDE_DIRS})
IF(NOT WX_CONFIG_H)
MESSAGE(FATAL_ERROR "Could not find wx/config.h in ${wxWidgets_INCLUDE_DIRS}")
ENDIF()
SET(WX_CONFIG_H "${WX_CONFIG_H}/wx/config.h")
INCLUDE(CheckCXXSymbolExists)
CHECK_CXX_SYMBOL_EXISTS(__WXGTK4__ ${WX_CONFIG_H} WX_USING_GTK4)
CHECK_CXX_SYMBOL_EXISTS(__WXGTK3__ ${WX_CONFIG_H} WX_USING_GTK3)
IF(WX_USING_GTK4)
PKG_CHECK_MODULES(GTK4 REQUIRED gtk+-4.0)
IF(NOT GTK4_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk4")
ENDIF()
INCLUDE_DIRECTORIES(${GTK4_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK4_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK4_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK4_LIBRARIES})
ELSEIF(WX_USING_GTK3)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
IF(NOT GTK3_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk3")
ENDIF()
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK3_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK3_LIBRARIES})
ELSE()
CHECK_CXX_SYMBOL_EXISTS(__WXGTK20__ ${WX_CONFIG_H} WX_USING_GTK2)
IF(WX_USING_GTK2)
# try to use pkg-config to find gtk2 first
PKG_CHECK_MODULES(GTK2 REQUIRED gtk+-2.0)
IF(GTK2_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK2_LIBRARY_DIRS})
ADD_COMPILE_OPTIONS(${GTK2_CFLAGS_OTHER})
SET(GTK_LIBRARIES ${GTK2_LIBRARIES})
ELSE()
# and if that fails, use the cmake module
FIND_PACKAGE(GTK2 REQUIRED gtk)
IF(NOT GTK2_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk2")
ENDIF()
INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
ADD_COMPILE_OPTIONS(${GTK2_DEFINITIONS})
SET(GTK_LIBRARIES ${GTK2_LIBRARIES})
ENDIF()
ELSE()
FIND_PACKAGE(GTK REQUIRED gtk)
IF(NOT GTK_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Could not find gtk")
ENDIF()
INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS})
ADD_COMPILE_OPTIONS(${GTK_DEFINITIONS})
ENDIF()
ENDIF()
ENDIF()
if (wxWidgets_USE_FILE)
INCLUDE(${wxWidgets_USE_FILE})
endif()
endif() # wxWidgets checks
if(CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
find_package(unofficial-gettext REQUIRED)
else()
find_package(Gettext REQUIRED)
find_program(XGETTEXT xgettext)
find_program(MSGINIT msginit)
if(ENABLE_NLS AND (NOT XGETTEXT OR NOT MSGINIT))
message(SEND_ERROR "Cannot find gettext ${XGETTEXT} ${MSGINIT}")
endif()
endif()
if(WIN32 AND ENABLE_DIRECTX)
find_packge(DirectX REQUIRED)
endif()
# contrib widgets
include_directories(widgets)

View File

@ -999,7 +999,7 @@ void GameArea::OnIdle(wxIdleEvent& event)
panel = new GLDrawingPanel(this, basic_width, basic_height);
break;
#endif
#ifdef __WXMSW__
#if defined(__WXMSW__) && !defined(NO_D3D)
case RND_DIRECT3D:
panel = new DXDrawingPanel(this, basic_width, basic_height);
break;
@ -1034,7 +1034,7 @@ void GameArea::OnIdle(wxIdleEvent& event)
// add spacers on top and bottom to center panel vertically
GetSizer()->Add(0, 0, 1, wxEXPAND);
GetSizer()->Add(w, 0, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER | wxEXPAND) : wxEXPAND);
GetSizer()->Add(w, 0, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER) : wxEXPAND);
GetSizer()->Add(0, 0, 1, wxEXPAND);
Layout();

View File

@ -1,36 +1,26 @@
#include <algorithm>
#include <wx/string.h>
#include <string>
#include <vector>
#include "strutils.h"
// From: https://stackoverflow.com/a/7408245/262458
//
// modified to ignore empty tokens
std::vector<wxString> str_split(const wxString& text, const wxString& sep) {
std::vector<wxString> tokens;
std::size_t start = 0, end = 0;
wxArrayString str_split(const wxString& text, const wxString& sep) {
wxArrayString tokens;
size_t start = 0, end = 0;
while ((end = text.find(sep, start)) != std::string::npos) {
wxString token = text.substr(start, end - start);
if (token.length())
tokens.push_back(token);
tokens.Add(token);
start = end + 1;
}
tokens.push_back(text.substr(start));
tokens.Add(text.substr(start));
return tokens;
}
// From: https://stackoverflow.com/a/15099743/262458
std::size_t vec_find(std::vector<wxString>& opts, const wxString& val) {
auto it = std::find(opts.begin(), opts.end(), val);
if (it == opts.end())
return wxNOT_FOUND;
return std::distance(opts.begin(), it);
size_t vec_find(wxArrayString& opts, const wxString& val) {
return opts.Index(val);
}

View File

@ -1,15 +1,13 @@
#ifndef STRUTILS_H
#define STRUTILS_H
#include <algorithm>
#include <wx/string.h>
#include <string>
#include <vector>
#include <wx/arrstr.h>
// From: https://stackoverflow.com/a/7408245/262458
std::vector<wxString> str_split(const wxString& text, const wxString& sep);
wxArrayString str_split(const wxString& text, const wxString& sep);
// From: https://stackoverflow.com/a/15099743/262458
std::size_t vec_find(std::vector<wxString>& opts, const wxString& val);
size_t vec_find(wxArrayString& opts, const wxString& val);
#endif

1
vcpkg Submodule

@ -0,0 +1 @@
Subproject commit b5ae25cf3d1e8c28095f5379f18f1a47390b33a0