update Visual Studio support

Replace the vcpkg code with a newer and better version. In this version
the `vcpkg` directory is on the same level as the source directory, so
that IntelliSense does not get confused scanning for files.

The cmake variable `VCPKG_TARGET_TRIPLET` is required to activate vcpkg
support, it must be set to e.g. `x64-windows` or `x86-windows`.

Update `CMakeSettings.json` for the new code for the GUI.

Fix a problem copying the `SDL2.dll` file to the binary directory.

Update `README.md` with commandline instructions.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-07-03 23:28:48 +00:00
parent 91501becf6
commit e2f06210e0
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
9 changed files with 106 additions and 89 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[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

@ -11,14 +11,11 @@ if(COMMAND cmake_policy)
endif()
endif()
option(ENABLE_VCPKG "Use dependencies for Visual Studio from vcpkg" ON)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
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)
include(Set-Toolchain-vcpkg)
project(VBA-M C CXX)
@ -34,7 +31,6 @@ endif()
set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
#Output all binaries at top level
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
@ -124,7 +120,28 @@ endif()
option(ENABLE_LTO "Compile with Link Time Optimization (gcc and clang only)" ${LTO_DEFAULT})
if(WIN32 OR CMAKE_TOOLCHAIN_FILE MATCHES "[Mm][Ii][Nn][Gg][Ww]")
# Win32 deps submodule
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
set(git_checkout FALSE)
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()
endif()
if(MSVC)
include_directories("${CMAKE_SOURCE_DIR}/dependencies/msvc")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
@ -938,5 +955,4 @@ set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0-Git-" ${COMMITHASH})
list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/dependencies")
list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg")
include(CPack)

View File

@ -2,51 +2,47 @@
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows",
"ctestCommandArgs": ""
}, {
"name": "x64-Release",
"generator": "Ninja",
"generator": "Visual Studio 15 2017",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows",
"ctestCommandArgs": ""
}, {
"name": "x86-Debug",
"generator": "Ninja",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows",
"ctestCommandArgs": ""
}, {
"name": "x86-Release",
"generator": "Ninja",
"generator": "Visual Studio 15 2017",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows",
"ctestCommandArgs": ""
}
]

View File

@ -76,6 +76,15 @@ project from 2019.
Using your own user-wide installation of vcpkg is supported, just make sure the
environment variable `VCPKG_ROOT` is set.
To build in the visual studio command prompt, use something like this:
```
mkdir vsbuild
cd vsbuild
cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows
msbuild /m .\ALL_BUILD.vcxproj
```
### Dependencies
If your OS is not supported, you will need the following:

View File

@ -18,7 +18,9 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64")
set(ASM_DEFAULT ON)
endif()
set(X86_32 ON)
set(WINARCH x86)
else()
set(AMD64 ON)
set(WINARCH x64)
endif()
endif()

View File

@ -0,0 +1,63 @@
if(VCPKG_TARGET_TRIPLET)
if(NOT DEFINED ENV{VCPKG_ROOT})
get_filename_component(VCPKG_ROOT ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE)
set(ENV{VCPKG_ROOT} ${VCPKG_ROOT})
else()
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
endif()
if(NOT EXISTS ${VCPKG_ROOT})
get_filename_component(vcpkg_root_parent ${VCPKG_ROOT}/.. ABSOLUTE)
execute_process(
COMMAND git clone https://github.com/microsoft/vcpkg.git
RESULT_VARIABLE git_status
WORKING_DIRECTORY ${vcpkg_root_parent}
)
if(NOT git_status EQUAL 0)
message(FATAL_ERROR "Error cloning vcpkg, please make sure git for windows is installed correctly, it can be installed from Visual Studio components")
endif()
endif()
# build vcpkg if not built
if(WIN32)
if(NOT EXISTS ${VCPKG_ROOT}/vcpkg.exe)
execute_process(
COMMAND bootstrap-vcpkg.bat
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
else()
if(NOT EXISTS ${VCPKG_ROOT}/vcpkg)
execute_process(
COMMAND ./bootstrap-vcpkg.sh
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
endif()
foreach(pkg ${VCPKG_DEPS})
list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${VCPKG_TARGET_TRIPLET})
endforeach()
# build our deps
if(WIN32)
execute_process(
COMMAND vcpkg install ${VCPKG_DEPS_QUALIFIED}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
else()
execute_process(
COMMAND ./vcpkg install ${VCPKG_DEPS_QUALIFIED}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
if(WIN32 AND VCPKG_TARGET_TRIPLET MATCHES x64)
set(CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE)
endif()
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE FILEPATH "vcpkg toolchain" FORCE)
include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
endif()

View File

@ -1,65 +0,0 @@
if(WIN32 OR CMAKE_TOOLCHAIN_FILE MATCHES "[Mm][Ii][Nn][Gg][Ww]")
# 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)
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

@ -119,7 +119,7 @@ if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64))
# 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${suffix}/${path_prefix}/bin/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${_VCPKG_ROOT_DIR}/installed/${WINARCH}-windows/${path_prefix}/bin/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR})
endif()
else()
if(CMAKE_BUILD_TYPE MATCHES Debug)

1
vcpkg

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