cmake: Visual Studio support improvements.

Add support for vcpkg ffmpeg, this requires using someone's
FindFFmpeg.cmake instead of relying on pkg-config, since vcpkg does not
have pkg-config.

Do not use the ffmpeg from vcpkg on appveyor however, because that
pushes the build cache generation over the time limit for jobs.

Add secur32 and bcrypt to the list of ffmpeg libs on windows, these are
standard windows libraries.

Change some code in ffmpeg.cpp to remove C-style casts of struct
initializers, which are illegal in MSVC.

Add the INT64_C and UINT64_C macros missing in MSVC's stdint.h (if not
defined) to ffmpeg.h before the ffmpeg headers are included, because
they rely on them.

Rewrite the wxWidgets finding code for the vcpkg wxWidgets to be nicer
and work correctly for debug and static builds.

Remove all /W* and /w* warnings options from cmake compiler flags, and
replace them with /W4 for debug builds, and /w (no warnings) for release
modes.

When building a static binary, remove all /MD* flags from cmake compiler
flags, and use /MT for static release builds and /MTd for static debug
builds.

Improve the vcpkg toolchain wrapper to only rebuild the vcpkg binary if
there were git updates.

Redo the handling of SDL2 and SDL_main. Only link SDL2Main to the SDL
binary and don't use the definitions.

Update CMakeSettings.json to use Ninja and include static
configurations.

Use CMAKE_PROJECT_DIR instead of CMAKE_SOURCE_DIR to determine the vcpkg
root, as CMAKE_SOURCE_DIR is sometimes set incorrectly in the 2017 GUI.

Add /nodefaultlib:libcmt to the debug build link flags, as in debug
builds libcmtd is used and libcmt should not be.

Add /subsystem:console to debug build link flags to produce a windows
console app for debug builds, like we do for mingw builds. To do this,
define a WIN32_CONSOLE_APP macro and if set, define a main() that calls
WinMain().

Call wxMesdsageOutput::Set() in OnInit with an instance of
wxMessageOutputStderr for windows debug builds to make sure the --help
text etc. goes to the console instead of a popup box.

Update the Visual Studio related text in README.md.

Fix dynamic debug builds by linking to the debug version of SDL2 and
copying the debug version of the dll to the build dir.

Fix issue in MainFrame::BindAppIcon with the function we are using not
being found in a Windows DLL in debug builds by using
wxDynamicLibrary::GetSymboolAorW() instead of GetSymbol().

Enable LTO for MSVC in Release modes, if the option is set.

Change appveyor config to use an 8 item build matrix of
x64/x86 / Release/Debug / Static/Dynamic. And test the binary in debug
modes by running --help.

When copying the wxrc.exe out of the build tree, copy both the release
and debug versions, this is so that appveyor caching of vcpkg works,
since the build trees are not cached.

Add some necessary win32 libraries to the SDL binary. And enable
building it on appveyor.

Fix #465.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-12-10 11:13:58 +00:00
parent d183245bdd
commit cf9a88dfc3
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
12 changed files with 563 additions and 189 deletions

View File

@ -7,14 +7,17 @@ build:
verbosity: detailed verbosity: detailed
configuration: configuration:
- Debug
- Release - Release
platform: platform:
- x64 - x64
- x86
environment: environment:
matrix: matrix:
- arch: Win64 - STATIC: " "
- STATIC: "-static"
matrix: matrix:
fast_finish: true fast_finish: true
@ -27,13 +30,23 @@ install:
- ninja --version - ninja --version
before_build: before_build:
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
build_script: build_script:
- mkdir build - mkdir build
- cd build - cd build
- cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Release -G Ninja - cmake .. -DVCPKG_TARGET_TRIPLET=%PLATFORM%-windows%STATIC% -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DENABLE_SDL=TRUE -G Ninja
- ninja - ninja
# only debug builds are console mode apps, in them test --help
for:
-
matrix:
except:
- configuration: Release
test_script:
- .\visualboyadvance-m.exe --help
cache: cache:
- c:\projects\vcpkg\installed - c:\vcpkg\installed

View File

@ -15,8 +15,19 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(VCPKG_DEPS zlib libpng SDL2 SFML gettext wxWidgets) set(VCPKG_DEPS zlib libpng SDL2 SFML gettext wxWidgets)
if(NOT DEFINED ENV{APPVEYOR})
# job goes over time limit if building ffmpeg
list(APPEND VCPKG_DEPS ffmpeg)
endif()
include(Set-Toolchain-vcpkg) include(Set-Toolchain-vcpkg)
set(VBAM_STATIC_DEFAULT OFF)
if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)
set(VBAM_STATIC_DEFAULT ON)
endif()
project(VBA-M C CXX) project(VBA-M C CXX)
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
@ -41,7 +52,7 @@ option(ENABLE_WX "Build the wxWidgets port" ON)
option(ENABLE_DEBUGGER "Enable the debugger" ON) option(ENABLE_DEBUGGER "Enable the debugger" 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" ${VBAM_STATIC_DEFAULT})
if(VBAM_STATIC) if(VBAM_STATIC)
set(SDL2_STATIC ON) set(SDL2_STATIC ON)
@ -100,6 +111,8 @@ if(ENABLE_ASM_SCALERS)
option(ENABLE_MMX "Enable MMX" ${MMX_DEFAULT}) option(ENABLE_MMX "Enable MMX" ${MMX_DEFAULT})
endif() endif()
find_package(PkgConfig)
set(ENABLE_LINK_DEFAULT OFF) set(ENABLE_LINK_DEFAULT OFF)
# msys2 does not have static sfml libs atm # msys2 does not have static sfml libs atm
@ -120,23 +133,31 @@ option(ENABLE_LIRC "Enable LIRC support" OFF)
set(FFMPEG_DEFAULT OFF) set(FFMPEG_DEFAULT OFF)
find_package(PkgConfig) set(FFMPEG_COMPONENTS AVCODEC AVFORMAT SWSCALE AVUTIL SWRESAMPLE)
set(FFMPEG_COMPONENT_VERSIONS AVCODEC>=58.18.100 AVFORMAT>=58.12.100 SWSCALE>=5.1.100 AVUTIL>=56.14.100 SWRESAMPLE>=3.1.100)
set(FFMPEG_LIBS_LIST libavcodec>=58.18.100 libavformat>=58.12.100 libswscale>=5.1.100 libavutil>=56.14.100 libswresample>=3.1.100) macro(check_ffmpeg_component_versions)
# check versions, but only if pkgconfig is available
if(FFMPEG_FOUND AND PKG_CONFIG_FOUND AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
foreach(component ${FFMPEG_COMPONENT_VERSIONS})
string(REPLACE ">=" ";" parts ${component})
list(GET parts 0 name)
list(GET parts 1 version)
if(PKGCONFIG_FOUND) if((NOT DEFINED ${name}_VERSION) OR ${name}_VERSION VERSION_LESS ${version})
set(FFMPEG_DEFAULT ON) set(FFMPEG_FOUND OFF)
endif()
endforeach()
endif()
endmacro()
foreach(ffmpeg_lib ${FFMPEG_LIBS_LIST}) set(FFMPEG_DEFAULT ON)
string(REGEX REPLACE ">=.*" "" ffmpeg_lib_name ${ffmpeg_lib})
pkg_check_modules(FFMPEG_LIB_${ffmpeg_lib_name} ${ffmpeg_lib} QUIET) find_package(FFmpeg COMPONENTS ${FFMPEG_COMPONENTS})
check_ffmpeg_component_versions()
if(NOT FFMPEG_LIB_${ffmpeg_lib_name}_FOUND) if(NOT FFMPEG_FOUND)
set(FFMPEG_DEFAULT OFF) set(FFMPEG_DEFAULT OFF)
break()
endif()
endforeach()
endif() endif()
option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT}) option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})
@ -155,7 +176,7 @@ option(ENABLE_ONLINEUPDATES "Enable online update checks" ${ONLINEUPDATES_DEFAUL
set(LTO_DEFAULT ON) set(LTO_DEFAULT ON)
# lto produces buggy binaries for 64 bit win32 # gcc lto produces buggy binaries for 64 bit mingw
# and we generally don't want it when debugging because it makes linking slow # and we generally don't want it when debugging because it makes linking slow
if(CMAKE_BUILD_TYPE MATCHES Debug OR (WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64)) if(CMAKE_BUILD_TYPE MATCHES Debug OR (WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64))
set(LTO_DEFAULT OFF) set(LTO_DEFAULT OFF)
@ -266,23 +287,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
endif() endif()
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(PNG REQUIRED)
find_package(PNG REQUIRED) find_package(SDL2 REQUIRED)
if(EXISTS /etc/redhat-release)
set(FEDORA_HOST ON)
endif()
if((APPLE AND NOT MACPORTS) OR (WIN32 AND FEDORA_HOST))
set(SDL2_STATIC ON)
endif()
if(WIN32 AND SDL2_STATIC)
set(SDL2_BUILDING_LIBRARY TRUE) # try not to link SDL2main
endif()
find_package(SDL2 REQUIRED)
add_definitions(${SDL2_DEFINITIONS})
if(WIN32) if(WIN32)
set(SDL2_LIBRARY ${SDL2_LIBRARY} setupapi) set(SDL2_LIBRARY ${SDL2_LIBRARY} setupapi)
@ -301,31 +307,21 @@ set(
) )
if(ENABLE_FFMPEG) if(ENABLE_FFMPEG)
find_package(PkgConfig REQUIRED) if(NOT FFMPEG_LIBRARIES)
message(FATAL_ERROR "ENABLE_FFMPEG was specified, but required versions of ffmpeg libraries cannot be found!")
pkg_check_modules(FFMPEG REQUIRED ${FFMPEG_LIBS_LIST})
if(FFMPEG_STATIC)
set(FFMPEG_LIBRARIES ${FFMPEG_STATIC_LIBRARIES})
set(FFMPEG_LDFLAGS ${FFMPEG_STATIC_LDFLAGS} ${FFMPEG_STATIC_OTHER_LDFLAGS})
if(APPLE)
set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} -framework CoreText -framework ApplicationServices)
endif()
else()
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES})
set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} ${FFMPEG_OTHER_LDFLAGS})
endif() endif()
if(APPLE)
set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} -framework CoreText -framework ApplicationServices)
endif()
else()
add_definitions(-DNO_FFMPEG)
endif() endif()
if(NOT ENABLE_ONLINEUPDATES) if(NOT ENABLE_ONLINEUPDATES)
add_definitions(-DNO_ONLINEUPDATES) add_definitions(-DNO_ONLINEUPDATES)
endif() endif()
if(NOT ENABLE_FFMPEG)
add_definitions(-DNO_FFMPEG)
endif()
if(ENABLE_LIRC) if(ENABLE_LIRC)
set(WITHLIRC 1) set(WITHLIRC 1)
else() else()
@ -634,10 +630,43 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}")
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}")
elseif(MSVC) elseif(MSVC)
# first remove all warnings flags, otherwise there is a warning about overriding them
string(REGEX REPLACE "/[Ww][^ ]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/[Ww][^ ]+" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if(CMAKE_BUILD_TYPE STREQUAL Debug) if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(/W4) add_compile_options(/W4)
else() else()
add_compile_options(/W0) add_compile_options(/w)
if(ENABLE_LTO)
add_compile_options(/GL)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG")
endif()
endif()
if(VBAM_STATIC)
string(REGEX REPLACE "/MDd?" "" CMAKE_C_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "/MDd?" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS})
if(CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo")
add_compile_options(/MTd)
else()
add_compile_options(/MT)
endif()
endif() endif()
endif() endif()
@ -959,7 +988,7 @@ if(ENABLE_SDL)
set_property(TARGET vbam PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET vbam PROPERTY CXX_STANDARD_REQUIRED ON)
if(WIN32) if(WIN32)
set(WIN32_LIBRARIES wsock32 ws2_32) set(WIN32_LIBRARIES wsock32 ws2_32 winmm version imm32)
endif() endif()
if(ENABLE_LIRC) if(ENABLE_LIRC)
@ -972,6 +1001,11 @@ if(ENABLE_SDL)
${WIN32_LIBRARIES} ${WIN32_LIBRARIES}
${LIRC_CLIENT_LIBRARY} ${LIRC_CLIENT_LIBRARY}
) )
if(WIN32)
target_link_libraries(vbam ${SDL2MAIN_LIBRARY})
endif()
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
if(WIN32) if(WIN32)

View File

@ -1,49 +1,85 @@
{ {
"configurations": [ "configurations": [
{ {
"name": "x64-Debug", "name": "x64-Debug",
"generator": "Visual Studio 15 2017", "generator": "Ninja",
"configurationType": "Debug", "configurationType": "Debug",
"inheritEnvironments": [ "inheritEnvironments": [
"msvc_x64" "msvc_x64"
], ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows", "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows -DENABLE_SDL=TRUE"
"ctestCommandArgs": "" }, {
}, { "name": "x64-Release",
"name": "x64-Release", "generator": "Ninja",
"generator": "Visual Studio 15 2017", "configurationType": "Release",
"configurationType": "Release", "inheritEnvironments": [
"inheritEnvironments": [ "msvc_x64"
"msvc_x64" ],
], "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows -DENABLE_SDL=TRUE"
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows", }, {
"ctestCommandArgs": "" "name": "x86-Debug",
}, { "generator": "Ninja",
"name": "x86-Debug", "configurationType": "Debug",
"generator": "Visual Studio 15 2017", "inheritEnvironments": [
"configurationType": "Debug", "msvc_x86"
"inheritEnvironments": [ ],
"msvc_x86" "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
], "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows -DENABLE_SDL=TRUE"
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", }, {
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows", "name": "x86-Release",
"ctestCommandArgs": "" "generator": "Ninja",
}, { "configurationType": "Release",
"name": "x86-Release", "inheritEnvironments": [
"generator": "Visual Studio 15 2017", "msvc_x86"
"configurationType": "Release", ],
"inheritEnvironments": [ "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"msvc_x86" "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
], "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows -DENABLE_SDL=TRUE"
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", }, {
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "name": "x64-static-Debug",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows", "generator": "Ninja",
"ctestCommandArgs": "" "configurationType": "Debug",
} "inheritEnvironments": [
] "msvc_x64"
} ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows-static -DENABLE_SDL=TRUE"
}, {
"name": "x64-static-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows-static -DENABLE_SDL=TRUE"
}, {
"name": "x86-static-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows-static -DENABLE_SDL=TRUE"
}, {
"name": "x86-static-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows-static -DENABLE_SDL=TRUE"
}
]
}

View File

@ -75,10 +75,17 @@ Copy vbam_libretro.so to your RetroArch cores directory.
## Visual Studio Support ## Visual Studio Support
For visual studio, dependency management is handled automatically with vcpkg, 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 From the Visual Studio GUI, just clone the repository with git and build with
the developer command line as well. 2019 will not work yet for building the cmake configurations provided.
dependencies, but you can build the dependencies in 2017 and then use the
project from 2019. If the GUI does not detect cmake, go to `File -> Open -> CMake` and open the
`CMakeLists.txt`.
If you are using 2017, make sure you have all the latest updates, some issues
with cmake projects in the GUI have been fixed.
You can also build from the developer command prompt or powershell with the
environment loaded.
Using your own user-wide installation of vcpkg is supported, just make sure the Using your own user-wide installation of vcpkg is supported, just make sure the
environment variable `VCPKG_ROOT` is set. environment variable `VCPKG_ROOT` is set.
@ -88,12 +95,11 @@ To build in the visual studio command prompt, use something like this:
``` ```
mkdir build mkdir build
cd build cd build
cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Release -G Ninja cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_BUILD_TYPE=Debug -G Ninja
ninja ninja
``` ```
This support is new and we are still working out some issues, including support This support is new and we are still working out some issues.
for static builds.
## Dependencies ## Dependencies

152
cmake/FindFFmpeg.cmake Normal file
View File

@ -0,0 +1,152 @@
# vim: ts=2 sw=2
# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
#
# Once done this will define
# FFMPEG_FOUND - System has the all required components.
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
#
# For each of the components it will additionally set.
# - AVCODEC
# - AVDEVICE
# - AVFORMAT
# - AVFILTER
# - AVUTIL
# - POSTPROC
# - SWSCALE
# - SWRESAMPLE
# the following variables will be defined
# <component>_FOUND - System has <component>
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
# <component>_LIBRARIES - Link these to use <component>
# <component>_DEFINITIONS - Compiler switches required for using <component>
# <component>_VERSION - The components version
#
# Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
include(FindPackageHandleStandardArgs)
# The default components were taken from a survey over other FindFFMPEG.cmake files
if (NOT FFmpeg_FIND_COMPONENTS)
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
endif ()
#
### Macro: set_component_found
#
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
#
macro(set_component_found _component )
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
# message(STATUS " - ${_component} found.")
set(${_component}_FOUND TRUE)
else ()
# message(STATUS " - ${_component} not found.")
endif ()
endmacro()
#
### Macro: find_component
#
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
# include directories.
#
macro(find_component _component _pkgconfig _library _header)
if (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_${_component} ${_pkgconfig})
endif ()
endif (NOT WIN32)
find_path(${_component}_INCLUDE_DIRS ${_header}
HINTS
${PC_LIB${_component}_INCLUDEDIR}
${PC_LIB${_component}_INCLUDE_DIRS}
PATH_SUFFIXES
ffmpeg
)
find_library(${_component}_LIBRARIES NAMES ${_library}
HINTS
${PC_LIB${_component}_LIBDIR}
${PC_LIB${_component}_LIBRARY_DIRS}
)
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
set_component_found(${_component})
mark_as_advanced(
${_component}_INCLUDE_DIRS
${_component}_LIBRARIES
${_component}_DEFINITIONS
${_component}_VERSION)
endmacro()
# Check for cached results. If there are skip the costly part.
if (NOT FFMPEG_LIBRARIES)
# Check for all possible component.
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
foreach (_component ${FFmpeg_FIND_COMPONENTS})
if (${_component}_FOUND)
# message(STATUS "Required component ${_component} present.")
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
else ()
# message(STATUS "Required component ${_component} missing.")
endif ()
endforeach ()
# Build the include path with duplicates removed.
if (FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif ()
# cache the vars.
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
mark_as_advanced(FFMPEG_INCLUDE_DIRS
FFMPEG_LIBRARIES
FFMPEG_DEFINITIONS)
endif ()
# Now set the noncached _FOUND vars for the components.
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
set_component_found(${_component})
endforeach ()
# Compile the list of required vars
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
foreach (_component ${FFmpeg_FIND_COMPONENTS})
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
endforeach ()
# Give a nice error message if some of the required vars are missing.
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})

View File

@ -101,36 +101,38 @@ FIND_PATH(SDL2_INCLUDE_DIR SDL.h
SET(CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) SET(CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
IF(SDL2_STATIC) if(SDL2_STATIC)
IF(WIN32) if(WIN32)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
ELSE(WIN32) else()
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
ENDIF(WIN32) endif()
ENDIF(SDL2_STATIC) endif()
unset(lib_suffix)
if(MSVC AND CMAKE_BUILD_TYPE MATCHES Debug)
set(lib_suffix d)
endif()
FIND_LIBRARY(SDL2_LIBRARY_TEMP FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2 NAMES SDL2${lib_suffix}
HINTS $ENV{SDL2DIR} HINTS $ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib lib/x64 lib/x86 PATH_SUFFIXES lib64 lib lib/x64 lib/x86
PATHS ${SDL2_SEARCH_PATHS} PATHS ${SDL2_SEARCH_PATHS}
) )
IF(NOT SDL2_BUILDING_LIBRARY) if(NOT (SDL2_BUILDING_LIBRARY OR ${SDL2_INCLUDE_DIR} MATCHES ".framework"))
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") # Non-OS X framework versions expect you to also dynamically link to
# Non-OS X framework versions expect you to also dynamically link to # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms # seem to provide SDL2main for compatibility even though they don't
# seem to provide SDL2main for compatibility even though they don't # necessarily need it.
# necessarily need it. find_library(SDL2MAIN_LIBRARY
FIND_LIBRARY(SDL2MAIN_LIBRARY NAMES SDL2main${lib_suffix}
NAMES SDL2main HINTS $ENV{SDL2DIR}
HINTS PATH_SUFFIXES lib64 lib lib/x64 lib/x86
$ENV{SDL2DIR} PATHS ${SDL2_SEARCH_PATHS}
PATH_SUFFIXES lib64 lib lib/x64 lib/x86 )
PATHS ${SDL2_SEARCH_PATHS} endif()
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_FIND_LIBRARY_SUFFIXES}) SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_FIND_LIBRARY_SUFFIXES})
UNSET(CURRENT_FIND_LIBRARY_SUFFIXES) UNSET(CURRENT_FIND_LIBRARY_SUFFIXES)
@ -156,11 +158,9 @@ ENDIF(MINGW)
IF(SDL2_LIBRARY_TEMP) IF(SDL2_LIBRARY_TEMP)
# For SDL2main # For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY) if(SDL2MAIN_LIBRARY AND NOT MSVC)
IF(SDL2MAIN_LIBRARY) SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) endif()
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even # CMake doesn't display the -framework Cocoa string in the UI even

View File

@ -1,6 +1,12 @@
macro(check_git_status)
if(NOT git_status EQUAL 0)
message(FATAL_ERROR "Error updating vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components")
endif()
endmacro()
if(VCPKG_TARGET_TRIPLET) if(VCPKG_TARGET_TRIPLET)
if(NOT DEFINED ENV{VCPKG_ROOT}) if(NOT DEFINED ENV{VCPKG_ROOT})
get_filename_component(VCPKG_ROOT ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE) get_filename_component(VCPKG_ROOT ${CMAKE_PROJECT_DIR}/../vcpkg ABSOLUTE)
set(ENV{VCPKG_ROOT} ${VCPKG_ROOT}) set(ENV{VCPKG_ROOT} ${VCPKG_ROOT})
else() else()
set(VCPKG_ROOT $ENV{VCPKG_ROOT}) set(VCPKG_ROOT $ENV{VCPKG_ROOT})
@ -15,9 +21,7 @@ if(VCPKG_TARGET_TRIPLET)
WORKING_DIRECTORY ${vcpkg_root_parent} WORKING_DIRECTORY ${vcpkg_root_parent}
) )
if(NOT git_status EQUAL 0) check_git_status()
message(FATAL_ERROR "Error cloning vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components")
endif()
else() else()
# this is the case when we cache vcpkg/installed with the appveyor build cache # this is the case when we cache vcpkg/installed with the appveyor build cache
if(NOT EXISTS ${VCPKG_ROOT}/.git) if(NOT EXISTS ${VCPKG_ROOT}/.git)
@ -36,35 +40,58 @@ if(VCPKG_TARGET_TRIPLET)
RESULT_VARIABLE git_status RESULT_VARIABLE git_status
WORKING_DIRECTORY ${VCPKG_ROOT} WORKING_DIRECTORY ${VCPKG_ROOT}
) )
if(NOT git_status EQUAL 0) check_git_status()
break()
endif()
endforeach() endforeach()
else() else()
execute_process( execute_process(
COMMAND git pull --rebase COMMAND git fetch origin
RESULT_VARIABLE git_status RESULT_VARIABLE git_status
WORKING_DIRECTORY ${VCPKG_ROOT} WORKING_DIRECTORY ${VCPKG_ROOT}
) )
check_git_status()
execute_process(
COMMAND git status
RESULT_VARIABLE git_status
OUTPUT_VARIABLE git_status_text
WORKING_DIRECTORY ${VCPKG_ROOT}
)
check_git_status()
set(git_up_to_date FALSE)
if(git_status_text MATCHES "Your branch is up to date with")
set(git_up_to_date TRUE)
endif()
if(NOT git_up_to_date)
execute_process(
COMMAND git pull --rebase
RESULT_VARIABLE git_status
WORKING_DIRECTORY ${VCPKG_ROOT}
)
check_git_status()
endif()
endif() endif()
if(NOT git_status EQUAL 0) check_git_status()
message(FATAL_ERROR "Error updating vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components")
endif()
endif() endif()
# build latest vcpkg # build latest vcpkg, if needed
if(WIN32) if(NOT git_up_to_date)
execute_process( if(WIN32)
COMMAND bootstrap-vcpkg.bat execute_process(
WORKING_DIRECTORY ${VCPKG_ROOT} COMMAND bootstrap-vcpkg.bat
) WORKING_DIRECTORY ${VCPKG_ROOT}
else() )
execute_process( else()
COMMAND ./bootstrap-vcpkg.sh execute_process(
WORKING_DIRECTORY ${VCPKG_ROOT} COMMAND ./bootstrap-vcpkg.sh
) WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
endif() endif()
foreach(pkg ${VCPKG_DEPS}) foreach(pkg ${VCPKG_DEPS})
@ -99,7 +126,7 @@ if(VCPKG_TARGET_TRIPLET)
set(CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE) set(CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE)
endif() endif()
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") if(WIN32 AND (NOT CMAKE_GENERATOR MATCHES "Visual Studio"))
# set toolchain to VS for e.g. Ninja or jom # set toolchain to VS for e.g. Ninja or jom
set(CMAKE_C_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE) set(CMAKE_C_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE)
set(CMAKE_CXX_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE) set(CMAKE_CXX_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE)

View File

@ -133,8 +133,8 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
} }
} }
aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout); aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout);
aenc->time_base = (AVRational){ 1, aenc->sample_rate }; aenc->time_base = { 1, aenc->sample_rate };
ast->time_base = (AVRational){ 1, STREAM_FRAME_RATE }; ast->time_base = { 1, STREAM_FRAME_RATE };
// open and use codec on stream // open and use codec on stream
int nb_samples; int nb_samples;
if (avcodec_open2(aenc, acodec, NULL) < 0) if (avcodec_open2(aenc, acodec, NULL) < 0)
@ -248,7 +248,7 @@ recording::MediaRet recording::MediaRecorder::setup_video_stream(int width, int
st = avformat_new_stream(oc, NULL); st = avformat_new_stream(oc, NULL);
if (!st) return MRET_ERR_NOMEM; if (!st) return MRET_ERR_NOMEM;
st->id = oc->nb_streams - 1; st->id = oc->nb_streams - 1;
st->time_base = (AVRational){ 1, STREAM_FRAME_RATE }; st->time_base = { 1, STREAM_FRAME_RATE };
// video codec // video codec
vcodec = avcodec_find_encoder(fmt->video_codec); vcodec = avcodec_find_encoder(fmt->video_codec);
if (!vcodec) return MRET_ERR_FMTGUESS; if (!vcodec) return MRET_ERR_FMTGUESS;
@ -593,7 +593,7 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int
return MRET_ERR_RECORDING; return MRET_ERR_RECORDING;
} }
audioframe->data[3] = audioframe->data[2] = audioframe->data[1] = audioframe->data[0]; audioframe->data[3] = audioframe->data[2] = audioframe->data[1] = audioframe->data[0];
audioframe->pts = av_rescale_q(samplesCount, (AVRational){1, c->sample_rate}, c->time_base); audioframe->pts = av_rescale_q(samplesCount, {1, c->sample_rate}, c->time_base);
samplesCount += dst_nb_samples; samplesCount += dst_nb_samples;
got_packet = avcodec_receive_packet(c, &pkt); got_packet = avcodec_receive_packet(c, &pkt);
@ -603,7 +603,7 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int
} }
if (!got_packet) if (!got_packet)
{ {
av_packet_rescale_ts(&pkt, (AVRational){ 1, c->sample_rate }, ast->time_base); av_packet_rescale_ts(&pkt, { 1, c->sample_rate }, ast->time_base);
pkt.stream_index = ast->index; pkt.stream_index = ast->index;
//log_packet(oc, &pkt); //log_packet(oc, &pkt);
if (av_interleaved_write_frame(oc, &pkt) < 0) if (av_interleaved_write_frame(oc, &pkt) < 0)

View File

@ -8,6 +8,18 @@
#define __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS
extern "C" { extern "C" {
/* From: http://redino.net/blog/2013/12/uint64_c-defined-including-libavformatavformat-h-vs-2008/ */
#include <stdint.h>
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#endif
#ifndef UINT64_C
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavutil/avassert.h> #include <libavutil/avassert.h>
#include <libavutil/channel_layout.h> #include <libavutil/channel_layout.h>

View File

@ -90,39 +90,89 @@ endif()
if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64)) if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64))
# set up wxwidgets stuff # set up wxwidgets stuff
set(libtype u) set(libtype u)
set(suffix -rel) unset(arch_suffix)
unset(path_prefix) unset(path_prefix)
set(build_suffix -rel)
if(CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Debug)
set(libtype ud) set(libtype ud)
set(suffix -dbg)
set(path_prefix debug) set(path_prefix debug)
set(build_suffix -dbg)
add_definitions(-D_DEBUG) add_definitions(-D_DEBUG)
endif() endif()
add_definitions(-D_UNICODE -DUNICODE -DWXUSINGDLL -DwxUSE_GUI=1 -D__WXMSW__) set(build_suffix_rel -rel)
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/${path_prefix}/lib/msw${libtype}) set(build_suffix_dbg -dbg)
include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/include)
set(wxWidgets_LIB_DIR ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/${path_prefix}/lib) if(VCPKG_TARGET_TRIPLET MATCHES -static)
set(arch_suffix -static)
set(build_suffix_rel -static-rel)
set(build_suffix_dbg -static-dbg)
set(build_suffix -static${build_suffix})
else()
add_definitions(-DWXUSINGDLL)
endif()
add_definitions(-D_UNICODE -DUNICODE -DwxUSE_GUI=1 -D__WXMSW__)
set(common_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix})
set(dbg_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/debug)
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix})
set(build_prefix_rel ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows${build_suffix_rel})
set(build_prefix_dbg ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows${build_suffix_dbg})
set(build_prefix ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows${build_suffix})
include_directories(${installed_prefix}/lib/msw${libtype})
include_directories(${common_prefix}/include)
set(wxWidgets_LIB_DIR ${installed_prefix}/lib)
set(wxWidgets_LIBRARIES set(wxWidgets_LIBRARIES
${wxWidgets_LIB_DIR}/wxbase31${libtype}_net.lib ${wxWidgets_LIB_DIR}/wxbase31${libtype}_net.lib
${wxWidgets_LIB_DIR}/wxbase31${libtype}_xml.lib ${wxWidgets_LIB_DIR}/wxbase31${libtype}_xml.lib
${wxWidgets_LIB_DIR}/wxmsw31${libtype}_core.lib ${wxWidgets_LIB_DIR}/wxmsw31${libtype}_core.lib
${wxWidgets_LIB_DIR}/wxmsw31${libtype}_gl.lib ${wxWidgets_LIB_DIR}/wxmsw31${libtype}_gl.lib
${wxWidgets_LIB_DIR}/wxmsw31${libtype}_xrc.lib ${wxWidgets_LIB_DIR}/wxmsw31${libtype}_xrc.lib
${wxWidgets_LIB_DIR}/wxmsw31${libtype}_html.lib
${wxWidgets_LIB_DIR}/wxbase31${libtype}.lib ${wxWidgets_LIB_DIR}/wxbase31${libtype}.lib
winmm comctl32 oleacc rpcrt4 shlwapi version wsock32 opengl32 winmm comctl32 oleacc rpcrt4 shlwapi version wsock32 opengl32
) )
if(NOT EXISTS ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/${path_prefix}/bin/wxrc.exe) if(EXISTS ${wxWidgets_LIB_DIR}/wxregex${libtype}.lib)
file( list(APPEND wxWidgets_LIBRARIES ${wxWidgets_LIB_DIR}/wxregex${libtype}.lib)
COPY ${_VCPKG_ROOT_DIR}/buildtrees/wxwidgets/${WINARCH}-windows${suffix}/lib/wxrc.exe endif()
DESTINATION ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/${path_prefix}/bin
if(VCPKG_TARGET_TRIPLET MATCHES -static)
unset(deb_suffix)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(deb_suffix d)
endif()
list(APPEND wxWidgets_LIBRARIES
${wxWidgets_LIB_DIR}/jpeg${deb_suffix}.lib
${wxWidgets_LIB_DIR}/tiff${deb_suffix}.lib
${wxWidgets_LIB_DIR}/lzma${deb_suffix}.lib
${wxWidgets_LIB_DIR}/expat.lib
) )
endif() endif()
set(WXRC ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/${path_prefix}/bin/wxrc.exe) if(NOT EXISTS ${installed_prefix}/bin/wxrc.exe)
# Need to copy both the release and debug versions out of the build tree, because
# appveyor does not cache the build trees.
file(
COPY ${build_prefix_rel}/lib/wxrc.exe
DESTINATION ${common_prefix}/bin
)
file(
COPY ${build_prefix_dbg}/lib/wxrc.exe
DESTINATION ${dbg_prefix}/bin
)
endif()
set(WXRC ${installed_prefix}/bin/wxrc.exe)
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe) if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe)
# get zip binary for wxrc # get zip binary for wxrc
@ -134,8 +184,17 @@ if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64))
endif() endif()
# SDL2.dll does not get copied to build dir # SDL2.dll does not get copied to build dir
if(NOT EXISTS ${CMAKE_BINARY_DIR}/SDL2.dll) if(NOT VCPKG_TARGET_TRIPLET MATCHES -static)
file(COPY ${_VCPKG_ROOT_DIR}/installed/${WINARCH}-windows/${path_prefix}/bin/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR}) unset(deb_suffix)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(deb_suffix d)
endif()
set(dll_path ${installed_prefix}/bin/SDL2${deb_suffix}.dll)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/SDL2${deb_suffix}.dll AND EXISTS ${dll_path})
file(COPY ${dll_path} DESTINATION ${CMAKE_BINARY_DIR})
endif()
endif() endif()
else() else()
if(CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Debug)
@ -793,17 +852,23 @@ target_link_libraries(
) )
if(ENABLE_FFMPEG) if(ENABLE_FFMPEG)
join("${FFMPEG_LDFLAGS}" " " FFMPEG_LDFLAGS_STR) if(WIN32)
list(APPEND FFMPEG_LIBRARIES secur32 bcrypt)
endif()
target_link_libraries( target_link_libraries(
visualboyadvance-m visualboyadvance-m
${FFMPEG_LIBRARIES} ${FFMPEG_LIBRARIES}
) )
set_target_properties( if(FFMPEG_LDFLAGS)
visualboyadvance-m join("${FFMPEG_LDFLAGS}" " " FFMPEG_LDFLAGS_STR)
PROPERTIES LINK_FLAGS ${FFMPEG_LDFLAGS_STR}
) set_target_properties(
visualboyadvance-m
PROPERTIES LINK_FLAGS ${FFMPEG_LDFLAGS_STR}
)
endif()
endif() endif()
# link libgcc/libstdc++ statically on mingw # link libgcc/libstdc++ statically on mingw
@ -836,6 +901,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
) )
endif() endif()
endif() endif()
elseif(MSVC)
# the debug lib libcmtd is linked in debug mode, so don't link the normal version
# also make the app a console app in debug mode
set_target_properties(visualboyadvance-m PROPERTIES LINK_FLAGS_DEBUG "/nodefaultlib:libcmt /subsystem:console")
if(CMAKE_BUILD_TYPE MATCHES Debug)
# to get the debug console mode app to work correctly
target_compile_definitions(visualboyadvance-m PRIVATE -DWIN32_CONSOLE_APP)
endif()
endif() endif()
if(NOT WIN32 AND NOT APPLE) if(NOT WIN32 AND NOT APPLE)

View File

@ -2698,7 +2698,7 @@ void MainFrame::BindAppIcon() {
#ifdef __WXMSW__ #ifdef __WXMSW__
if (IsWindowsVistaOrGreater()) { if (IsWindowsVistaOrGreater()) {
wxDynamicLibrary comctl32("comctl32", wxDL_DEFAULT | wxDL_QUIET); wxDynamicLibrary comctl32("comctl32", wxDL_DEFAULT | wxDL_QUIET);
func_LoadIconWithScaleDown load_icon_scaled = reinterpret_cast<func_LoadIconWithScaleDown>(comctl32.GetSymbol("LoadIconWithScaleDown")); func_LoadIconWithScaleDown load_icon_scaled = reinterpret_cast<func_LoadIconWithScaleDown>(comctl32.GetSymbolAorW("LoadIconWithScaleDown"));
int icon_set_count = 0; int icon_set_count = 0;
HICON hIconLg; HICON hIconLg;

View File

@ -32,6 +32,15 @@
IMPLEMENT_APP(wxvbamApp) IMPLEMENT_APP(wxvbamApp)
IMPLEMENT_DYNAMIC_CLASS(MainFrame, wxFrame) IMPLEMENT_DYNAMIC_CLASS(MainFrame, wxFrame)
#ifdef WIN32_CONSOLE_APP
#include <windows.h>
int main(int argc, char** argv)
{
return WinMain(::GetModuleHandle(NULL), 0, 0, 0);
}
#endif
// Initializer for struct cmditem // Initializer for struct cmditem
cmditem new_cmditem(const wxString cmd, const wxString name, int cmd_id, cmditem new_cmditem(const wxString cmd, const wxString name, int cmd_id,
int mask_flags, wxMenuItem* mi) int mask_flags, wxMenuItem* mi)
@ -204,17 +213,27 @@ static void init_check_for_updates()
} }
#endif // NO_ONLINEUPDATES #endif // NO_ONLINEUPDATES
#ifdef __WXMSW__
#include <wx/msw/private.h>
#include <windows.h>
#endif
bool wxvbamApp::OnInit() bool wxvbamApp::OnInit()
{ {
// set up logging // set up logging
#ifndef NDEBUG #ifndef NDEBUG
wxLog::SetLogLevel(wxLOG_Trace); wxLog::SetLogLevel(wxLOG_Trace);
#endif #endif
// turn off output buffering on Windows to support mintty
#ifdef __WXMSW__ #ifdef __WXMSW__
// in windows console mode debug builds, redirect e.g. --help to stderr
#ifndef NDEBUG
wxMessageOutput::Set(new wxMessageOutputStderr());
#endif
// turn off output buffering to support windows consoles
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);
dup2(1, 2); // redirect stderr to stdout // redirect stderr to stdout
dup2(1, 2);
#endif #endif
using_wayland = IsItWayland(); using_wayland = IsItWayland();
@ -471,6 +490,7 @@ int wxvbamApp::OnRun()
} }
} }
// called on --help
bool wxvbamApp::OnCmdLineHelp(wxCmdLineParser& parser) bool wxvbamApp::OnCmdLineHelp(wxCmdLineParser& parser)
{ {
wxApp::OnCmdLineHelp(parser); wxApp::OnCmdLineHelp(parser);