From f1ecd7c3225aa583c54abcbd4bcc29f31a506a97 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 21 Mar 2019 16:01:46 -0700 Subject: [PATCH] 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` 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 --- .gitignore | 2 + .gitmodules | 3 + CMakeLists.txt | 93 +++---- CMakeSettings.json | 53 ++++ README.md | 15 +- cmake/Architecture.cmake | 24 ++ cmake/Win32Deps.cmake | 62 +++++ src/gba/remote.cpp | 13 +- src/wx/CMakeLists.txt | 543 ++++++++++++++++++++++----------------- src/wx/panel.cpp | 4 +- src/wx/strutils.cpp | 24 +- src/wx/strutils.h | 8 +- vcpkg | 1 + 13 files changed, 525 insertions(+), 320 deletions(-) create mode 100644 CMakeSettings.json create mode 100644 cmake/Architecture.cmake create mode 100644 cmake/Win32Deps.cmake create mode 160000 vcpkg diff --git a/.gitignore b/.gitignore index 76c99d48..9c6e4e48 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ src/wx/cmdtab.cpp src/wx/wxvbam.xrs build/* build32/* +vsbuild/* dependencies/* +vcpkg/* .vs/* *.o *.so diff --git a/.gitmodules b/.gitmodules index ff35d490..048fc2d6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index cd4e26b8..5275d009 100644 --- a/CMakeLists.txt +++ b/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) 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=