Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9600 from Bonta0/mgba-pr
Full GBA Controllers Integration with mGBA
  • Loading branch information
JMC47 committed Jul 21, 2021
2 parents b515786 + b8f0e97 commit a1e806e
Show file tree
Hide file tree
Showing 99 changed files with 4,323 additions and 408 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ Thumbs.db
# Ignore Finder view option files created by OS X
.DS_Store
# Ignore autogenerated source files
Externals/mGBA/version.c
Source/Core/Common/scmrev.h
# Ignore files output by build
/[Bb]uild*/
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Expand Up @@ -3,3 +3,8 @@
url = https://github.com/dolphin-emu/ext-win-qt.git
branch = master
shallow = true
[submodule "Externals/mGBA/mgba"]
path = Externals/mGBA/mgba
url = https://github.com/mgba-emu/mgba.git
branch = master
shallow = true
9 changes: 9 additions & 0 deletions CMakeLists.txt
Expand Up @@ -45,6 +45,7 @@ option(ENABLE_LLVM "Enables LLVM support, for disassembly" ON)
option(ENABLE_TESTS "Enables building the unit tests" ON)
option(ENABLE_VULKAN "Enables vulkan video backend" ON)
option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence, show the current game on Discord" ON)
option(USE_MGBA "Enables GBA controllers emulation using libmgba" ON)

# Maintainers: if you consider blanket disabling this for your users, please
# consider the following points:
Expand Down Expand Up @@ -826,6 +827,14 @@ if(USE_DISCORD_PRESENCE)
include_directories(Externals/discord-rpc/include)
endif()

if(NOT ENABLE_QT)
set(USE_MGBA 0)
endif()
if(USE_MGBA)
message(STATUS "Using static libmgba from Externals")
add_subdirectory(Externals/mGBA)
endif()

find_package(SYSTEMD)
if(SYSTEMD_FOUND)
message(STATUS "libsystemd found, enabling traversal server watchdog support")
Expand Down
3 changes: 3 additions & 0 deletions Externals/ExternalsReferenceAll.props
Expand Up @@ -58,6 +58,9 @@
<ProjectReference Include="$(ExternalsDir)mbedtls\mbedTLS.vcxproj">
<Project>{bdb6578b-0691-4e80-a46c-df21639fd3b8}</Project>
</ProjectReference>
<ProjectReference Include="$(ExternalsDir)mGBA\mgba.vcxproj">
<Project>{864C4C8E-296D-3DBC-AD83-F1D5CB6E8EC6}</Project>
</ProjectReference>
<ProjectReference Include="$(ExternalsDir)miniupnpc\miniupnpc.vcxproj">
<Project>{31643fdb-1bb8-4965-9de7-000fc88d35ae}</Project>
</ProjectReference>
Expand Down
2 changes: 2 additions & 0 deletions Externals/licenses.md
Expand Up @@ -38,6 +38,8 @@ Dolphin includes or links code of the following third-party software projects:
[University of Illinois/NCSA Open Source license](http://llvm.org/docs/DeveloperPolicy.html#license)
- [LZO](http://www.oberhumer.com/opensource/lzo/):
[GPLv2+](http://www.oberhumer.com/opensource/gpl.html)
- [mGBA](http://mgba.io)
[MPL 2.0](https://github.com/mgba-emu/mgba/blob/master/LICENSE)
- [MiniUPnPc](http://miniupnp.free.fr/):
[3-clause BSD](https://github.com/miniupnp/miniupnp/blob/master/miniupnpc/LICENSE)
- [Microsoft Visual C++ Runtime Library](http://www.microsoft.com/en-us/download/details.aspx?id=40784):
Expand Down
13 changes: 13 additions & 0 deletions Externals/mGBA/CMakeLists.txt
@@ -0,0 +1,13 @@
set(LIBMGBA_ONLY ON)
set(USE_LZMA ON)
add_subdirectory(mgba EXCLUDE_FROM_ALL)

if(NOT MSVC)
target_compile_options(mgba PRIVATE -Wno-unused-parameter -Wno-unused-result -Wno-unused-variable)
endif()

if(ANDROID)
target_compile_definitions(mgba PRIVATE -Dfutimes=futimens)
endif()

add_library(mGBA::mgba ALIAS mgba)
140 changes: 140 additions & 0 deletions Externals/mGBA/make_version.c.js
@@ -0,0 +1,140 @@
var wshShell = new ActiveXObject("WScript.Shell")
var oFS = new ActiveXObject("Scripting.FileSystemObject");

wshShell.CurrentDirectory += "\\mgba";
var outfile = "../version.c";
var cmd_commit = " describe --always --abbrev=40 --dirty";
var cmd_commit_short = " describe --always --dirty";
var cmd_branch = " symbolic-ref --short HEAD";
var cmd_rev = " rev-list HEAD --count";
var cmd_tag = " describe --tag --exact-match";

function GetGitExe()
{
try
{
gitexe = wshShell.RegRead("HKCU\\Software\\GitExtensions\\gitcommand");
wshShell.Exec(gitexe);
return gitexe;
}
catch (e)
{}

for (var gitexe in {"git.cmd":1, "git":1, "git.bat":1})
{
try
{
wshShell.Exec(gitexe);
return gitexe;
}
catch (e)
{}
}

// last try - msysgit not in path (vs2015 default)
msyspath = "\\Git\\cmd\\git.exe";
gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") + msyspath;
if (oFS.FileExists(gitexe)) {
return gitexe;
}
gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") + msyspath;
if (oFS.FileExists(gitexe)) {
return gitexe;
}

WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" +
wshShell.ExpandEnvironmentStrings("%PATH%"));
WScript.Quit(1);
}

function GetFirstStdOutLine(cmd)
{
try
{
return wshShell.Exec(cmd).StdOut.ReadLine();
}
catch (e)
{
// catch "the system cannot find the file specified" error
WScript.Echo("Failed to exec " + cmd + " this should never happen");
WScript.Quit(1);
}
}

function GetFileContents(f)
{
try
{
return oFS.OpenTextFile(f).ReadAll();
}
catch (e)
{
// file doesn't exist
return "";
}
}

// get version from version.cmake
var version_cmake = GetFileContents("version.cmake");
var version_major = version_cmake.match(/set\(LIB_VERSION_MAJOR (.*)\)/)[1];
var version_minor = version_cmake.match(/set\(LIB_VERSION_MINOR (.*)\)/)[1];
var version_patch = version_cmake.match(/set\(LIB_VERSION_PATCH (.*)\)/)[1];
var version_abi = version_cmake.match(/set\(LIB_VERSION_ABI (.*)\)/)[1];
var version_string = version_major + "." + version_minor + "." + version_patch;

// get info from git
var gitexe = GetGitExe();
var commit = GetFirstStdOutLine(gitexe + cmd_commit);
var commit_short = GetFirstStdOutLine(gitexe + cmd_commit_short);
var branch = GetFirstStdOutLine(gitexe + cmd_branch);
var rev = GetFirstStdOutLine(gitexe + cmd_rev);
var tag = GetFirstStdOutLine(gitexe + cmd_tag);
var binary_name = "mgba";
var project_name = "mGBA";

if (!rev)
rev = -1;

if (tag)
{
version_string = tag;
}
else if (branch)
{
if (branch == "master")
version_string = rev + "-" + commit_short;
else
version_string = branch + "-" + rev + "-" + commit_short;

if (branch != version_abi)
version_string = version_abi + "-" + version_string;
}

if (!commit)
commit = "(unknown)";
if (!commit_short)
commit_short = "(unknown)";
if (!branch)
branch = "(unknown)";

var out_contents =
"#include <mgba/core/version.h>\n" +
"MGBA_EXPORT const char* const gitCommit = \"" + commit + "\";\n" +
"MGBA_EXPORT const char* const gitCommitShort = \"" + commit_short + "\";\n" +
"MGBA_EXPORT const char* const gitBranch = \"" + branch + "\";\n" +
"MGBA_EXPORT const int gitRevision = " + rev + ";\n" +
"MGBA_EXPORT const char* const binaryName = \"" + binary_name + "\";\n" +
"MGBA_EXPORT const char* const projectName = \"" + project_name + "\";\n" +
"MGBA_EXPORT const char* const projectVersion = \"" + version_string + "\";\n";

// check if file needs updating
if (out_contents == GetFileContents(outfile))
{
WScript.Echo(project_name + ": " + outfile + " current at " + version_string);
}
else
{
// needs updating - writeout current info
oFS.CreateTextFile(outfile, true).Write(out_contents);
WScript.Echo(project_name + ": " + outfile + " updated to " + version_string);
}
1 change: 1 addition & 0 deletions Externals/mGBA/mgba
Submodule mgba added at 9cccc5

2 comments on commit a1e806e

@Athkore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this commit I get the below error message unless I disable the mgba when running cmake

CMake Error at Externals/mGBA/CMakeLists.txt:3 (add_subdirectory):
The source directory

~/git/dolphin/Externals/mGBA/mgba                                                                                                                                                                                                                              

does not contain a CMakeLists.txt file.

CMake Error at Externals/mGBA/CMakeLists.txt:6 (target_compile_options):
Cannot specify compile options for target "mgba" which is not built by this
project.

CMake Error at Externals/mGBA/CMakeLists.txt:13 (add_library):
add_library cannot create ALIAS target "mGBA::mgba" because target "mgba"
does not already exist.

@AdmiralCurtiss
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update your submodules. git submodule update --init --recursive

Please sign in to comment.