Skip to content

Commit

Permalink
auto deps for visual studio, take 1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rkitover committed Mar 21, 2019
1 parent 3da07f4 commit f1ecd7c
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 296 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,7 +6,9 @@ src/wx/cmdtab.cpp
src/wx/wxvbam.xrs src/wx/wxvbam.xrs
build/* build/*
build32/* build32/*
vsbuild/*
dependencies/* dependencies/*
vcpkg/*
.vs/* .vs/*
*.o *.o
*.so *.so
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
@@ -1,3 +1,6 @@
[submodule "dependencies"] [submodule "dependencies"]
path = dependencies path = dependencies
url = https://github.com/visualboyadvance-m/dependencies.git url = https://github.com/visualboyadvance-m/dependencies.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/Microsoft/vcpkg.git
93 changes: 38 additions & 55 deletions CMakeLists.txt
@@ -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) project(VBA-M C CXX)


cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
Expand All @@ -12,19 +26,13 @@ endif()


set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam) set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam)


if(COMMAND cmake_policy) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
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)
#Output all binaries at top level #Output all binaries at top level
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})


option(ENABLE_SDL "Build the SDL port" OFF) option(ENABLE_SDL "Build the SDL port" OFF)
option(ENABLE_WX "Build the wxWidgets port" ON) option(ENABLE_WX "Build the wxWidgets port" ON)
option(ENABLE_DEBUGGER "Enable the debugger" 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(ENABLE_ASAN "Enable -fsanitize=<option>, address by default, requires debug build" OFF)


option(VBAM_STATIC "Try to link all libraries statically" OFF) option(VBAM_STATIC "Try to link all libraries statically" OFF)
Expand All @@ -37,7 +45,15 @@ if(VBAM_STATIC)
set(OPENAL_STATIC ON) set(OPENAL_STATIC ON)
endif() 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 # use ccache if available, and not already enabled on the command line
# but not with ninja and msys ccache on msys2 # but not with ninja and msys ccache on msys2
Expand All @@ -51,32 +67,14 @@ if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "") AND CMAKE_GENERATOR STREQUAL N
endif() endif()
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) set(SSP_DEFAULT OFF)


option(ENABLE_SSP "Enable gcc stack protector support" ${SSP_DEFAULT}) 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}) 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 # The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being
Expand Down Expand Up @@ -134,6 +132,13 @@ if(NOT ENABLE_DEBUGGER AND ENABLE_SDL)
message(SEND_ERROR "The SDL port can't be built without debugging support") message(SEND_ERROR "The SDL port can't be built without debugging support")
endif() 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) find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
include(GitTagVersion) include(GitTagVersion)
Expand Down Expand Up @@ -204,7 +209,7 @@ add_definitions(${SDL2_DEFINITIONS})
if(ENABLE_LINK) if(ENABLE_LINK)
# msys2 does not have static sfml libs atm # msys2 does not have static sfml libs atm
# while on mxe we use static libs # 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) set(SFML_STATIC_LIBRARIES TRUE)
endif() endif()
find_package(SFML 2 COMPONENTS network system REQUIRED) find_package(SFML 2 COMPONENTS network system REQUIRED)
Expand Down Expand Up @@ -297,6 +302,8 @@ if(NOT ENABLE_ASM_CORE)
add_definitions(-DC_CORE) add_definitions(-DC_CORE)
endif() endif()


option(ENABLE_NLS "Enable translations" ${NLS_DEFAULT})

# Enable internationalization # Enable internationalization
if(ENABLE_NLS) if(ENABLE_NLS)
set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale) set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
Expand Down Expand Up @@ -332,30 +339,6 @@ if(ENABLE_NLS)
endif() endif()
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) include(ProcessorCount)
ProcessorCount(num_cpus) ProcessorCount(num_cpus)


Expand Down
53 changes: 53 additions & 0 deletions CMakeSettings.json
@@ -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": ""
}
]
}
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -63,7 +63,20 @@ make -j`nproc`
`./installdeps` is supported on MSys2, Linux (Debian/Ubuntu, Fedora, Arch or `./installdeps` is supported on MSys2, Linux (Debian/Ubuntu, Fedora, Arch or
Solus) and Mac OS X (homebrew, macports or fink.) 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: If your OS is not supported, you will need the following:


Expand Down
24 changes: 24 additions & 0 deletions cmake/Architecture.cmake
@@ -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 changes: 62 additions & 0 deletions cmake/Win32Deps.cmake
@@ -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()
13 changes: 10 additions & 3 deletions src/gba/remote.cpp
Expand Up @@ -3528,7 +3528,7 @@ void remotePutPacket(const char* packet)
const char* hex = "0123456789abcdef"; const char* hex = "0123456789abcdef";


size_t count = strlen(packet); size_t count = strlen(packet);
char buffer[count + 5]; char* buffer = new char[count + 5];


unsigned char csum = 0; unsigned char csum = 0;


Expand All @@ -3548,10 +3548,15 @@ void remotePutPacket(const char* packet)
char c = 0; char c = 0;
while (c != '+') { while (c != '+') {
remoteSendFnc(buffer, (int)count + 4); remoteSendFnc(buffer, (int)count + 4);
if (remoteRecvFnc(&c, 1) < 0)
if (remoteRecvFnc(&c, 1) < 0) {
delete buffer;
return; return;
}
// fprintf(stderr,"sent:%s recieved:%c\n",buffer,c); // fprintf(stderr,"sent:%s recieved:%c\n",buffer,c);
} }

delete buffer;
} }


void remoteOutput(const char* s, uint32_t addr) void remoteOutput(const char* s, uint32_t addr)
Expand Down Expand Up @@ -3684,7 +3689,7 @@ void remoteMemoryRead(char* p)
sscanf(p, "%x,%x:", &address, &count); sscanf(p, "%x,%x:", &address, &count);
// monprintf("Memory read for %08x %d\n", 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; char* s = buffer;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Expand All @@ -3695,6 +3700,8 @@ void remoteMemoryRead(char* p)
} }
*s = 0; *s = 0;
remotePutPacket(buffer); remotePutPacket(buffer);

delete buffer;
} }


void remoteQuery(char* p) void remoteQuery(char* p)
Expand Down

0 comments on commit f1ecd7c

Please sign in to comment.