Skip to content

Commit

Permalink
update Visual Studio support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rkitover committed Jul 3, 2019
1 parent 91501be commit e2f0621
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 89 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
@@ -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
30 changes: 23 additions & 7 deletions CMakeLists.txt
Expand Up @@ -11,14 +11,11 @@ if(COMMAND cmake_policy)
endif()
endif()

option(ENABLE_VCPKG "Use dependencies for Visual Studio from vcpkg" ON)

set(NLS_DEFAULT ON)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# 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)

Expand All @@ -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})

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
20 changes: 8 additions & 12 deletions CMakeSettings.json
Expand Up @@ -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": ""
}
]
Expand Down
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions cmake/Architecture.cmake
Expand Up @@ -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()
63 changes: 63 additions & 0 deletions cmake/Set-Toolchain-vcpkg.cmake
@@ -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()
65 changes: 0 additions & 65 deletions cmake/Win32Deps.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion src/wx/CMakeLists.txt
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion vcpkg
Submodule vcpkg deleted from b5ae25

0 comments on commit e2f0621

Please sign in to comment.