Commit Graph

252 Commits

Author SHA1 Message Date
Rafael Kitover b69fced749
cmake: refactor, better clang support
Do some reformatting towards the more modern cmake style.

Clean up some code.

Support linking to gcc compiled wxWidgets by setting
`-D__GXX_ABI_VERSION=` appropriately for clang.

Use the new method of calling `FindwxWidgets.cmake`, the old method
causes some problems now.

Set all necessary policies in both cmake files.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-03-27 03:25:43 +00:00
Rafael Kitover 7fb27c4df9
cmake: check for broken LTO
When using LTO with gcc or clang, try to compile and link something to
make sure it works, and disable it if it doesn't.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-03-26 14:49:48 +00:00
Rafael Kitover f2e9dc5530
cmake: check for policy CMP0077 existence
Check `if(POLICY CMP0077)` before trying to set it, because setting a
policy a version of cmake does not know about is an error.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-03-26 13:40:35 +00:00
Rafael Kitover ae38a70d1e
cmake: gcc/clang colors with ninja, fix warnings
Ninja requires `-fdiagnostics-color=always` instead of
`-fdiagnostics-color=auto` with gcc because it pipes output from the
compiler unlike regular makes.

Use `-fcolor-diagnostics` for clang, which also works correctly with
ninja to show colors.

Information for this taken from here:

https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949

Set all cmake policies in both the root `CMakeLists.txt` and
`src/wx/CMakeLists.txt` to silence warnings about unset policies from
cmake.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-03-26 00:35:23 +00:00
Rafael Kitover f1ecd7c322
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<wxString>` 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 <rkitover@gmail.com>
2019-03-21 16:01:46 -07:00
Rafael Kitover 3da07f4083
detect llvm toolchain utilities #392
Use `clang -print-prog-path=<tool>` to find the locations of llvm
toolchain utilities such as `llvm-ranlib` and set the appropriate cmake
variables to the resultant paths.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-03-19 18:41:25 -07:00
Rafael Kitover 7dda58097a cmake: do not use -fPIC on 32 bit x86, breaks asm
Do not add the -fPIC (position independent code) compiler flag on 32 bit
x86 architectures because that breaks inline assembly, and some included
libraries like fex require inline assembly to work.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-02-22 14:53:51 +00:00
Rafael Kitover 5a77d8f4ba
cmake: don't use ccache on msys2+ninja
When using msys ccache with a mingw ninja, the compiler fails to
execute.

Don't try to detect ccache when using the Ninja generator on msys2, it
can still be specified through cmake variables.

Do not check for the mingw ccache because it is broken and I will assume
not being used.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-02-14 14:58:13 -08:00
Rafael Kitover c6fa7246de cmake: use color gcc/clang output when possible
Test for the -fdiagnostics-color=auto compiler option supported by gcc
and probably clang, and turn it on if it's available.

This option colorizes compiler warnings/errors/etc. when output to a
terminal.

Also fix a typo above when adding the -fopenmp flag.
2019-01-30 14:29:06 -08:00
Rafael Kitover de0e8d6ba3 cmake: support libasan/-fsanitize
Add the ENABLE_ASAN cmake option, defaulting to `-fsanitize=address` if
ON, or the value specified for the option.
2019-01-02 08:23:26 -08:00
Rafael Kitover 6f1df2ddea rename mingw include dir mingw-include in deps 2018-10-23 20:07:04 -07:00
Rafael Kitover 26b15b2c1e add mingw dependencies/include to include path
Older versions of mingw64 do not have the versionhelpers.h header, add
it to the dependencies submodule include/ directory and add it to
include_directories() for mingw in cmake.
2018-10-23 16:32:34 -07:00
Rafael Kitover 0092dc16ac msys2: don't try to link msys librt and libpthread
In cmake on Win32, don't try to find librt or libpthread using
find_library(), and on mingw just include -lpthread.

For some reason the msys versions of librt and libpthread were being
picked up when find_library() was being used.
2018-08-10 16:47:17 -07:00
Rafael Kitover 65e1ab041d disable gcc stack protector, segfault on 8.2.0
Make gcc -fstack-protector-strong and associated options controlled by
the cmake option ENABLE_SSP which defaults to OFF.

This option causes a segfault on startup with gcc 8.2.0.
2018-08-10 16:35:49 -07:00
Rafael Kitover bfe21aee3e remove -fpermissive compiler flag
Remove -fpermissive from the list of flags passed to gcc and clang.

Remove -fpermissive from the cxxflags from wxWidgets config as well.

When checking wxWidgets ABI compatibility version, temporarily add
-fpermissive to compiler flags on Win32 because minhook requires it.
2018-08-10 06:46:51 -07:00
Rafael Kitover 498019a39b support older 32 bit macs running 10.7, fix build
Make mac builder use -m32 in CFLAGS etc. to produce a 32 bit binary
targetting 10.7 (Lion.) This provides the greatest backward
compatibility for older macs, and also allows for asm filters.

Fix an issue with m4 on 10.13 using a patch from macports.

Support `-pX` patch level args in DIST_PATCHES in builder.

Fix an issue with bison on 10.13 by bumping the version to 3.0.5.

Build libxslt `--without-crypto` so that it doesn't try to link the brew
libgcrypt.

Invoke cmake for dists with -DCMAKE_C_COMPILER_LAUNCHER=ccache and
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache to use ccache, and set
CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to the actual compilers not
prefixed by ccache.

When checking for ccache in vbam cmake code, check that
CMAKE_CXX_COMPILER_LAUNCHER and CMAKE_C_COMPILER_LAUNCHER were not
already defined (generally on the command line.)

Remove align attributes from sections in 2xSaImmx.asm, macho format on
mac does not support this and the filter works fine without them.

In the Quartz2D renderer, pass the NSRect view.bounds through
NSRectToCGRect when calling CGContextDrawImage(), this is necessary for
the 32 bit API.

Bump openssl to 1.0.2o.

Bump libxml2 to 2.9.8.

Update URL for urw fonts, and improve the dist downloading/unpacking
code to handle URLs that do not contain the filename (for .tar.gz and
.zip as identified by `file`.)

Change post-build for harfbuzz from `rebuild_dist freetype;` to
`rebuild_dist freetype --with-harfbuzz=yes;` as it was supposed to have
been.

Build cmake itself with --parallel and --enable-ccache.

Silence errors from killed jobs due to tmp directory being gone.

Write a couple of string functions, rtrim() and gsub().

Make path_exists() handle globs with spaces in them, by escaping the
space.

Use --host and --build args to autoconf configure to "cross-compile" for
32 bits, this is necessary for some dists, and does not work for others,
remove it for dists where it does not work.

Add COMMAND_MODE=unix2003 to the build environment, this is necessary to
fix some build errors, why I have no clue, found it on stackoverflow.

Pass -Wl,-no_compact_unwind in LDFLAGS to openssl, this is necessary for
32 bits.

Force sfml to compile as 32 bit, it normally does not allow this.

Remove shared-mime-info from this build, it's not necessary for anything
and there are issues XML::Parser linked to our expat and brew perl that
need to be resolved.
2018-06-30 03:40:47 -07:00
Rafael Kitover 8778837c83 add Travis CI support
Use a matrix of 4 jobs, linux (ubuntu trusty), mingw i686, mingw x86-64
and mac.

Automatically detect ccache in the cmake config and cache the
`~/.ccache` directory for faster rebuilds.

Instructions for ccache in cmake are here:
https://stackoverflow.com/a/24305849

Change build status badge in README.md to Travis.
2018-06-26 19:15:22 -07:00
Rafael Kitover 66980934b2 add multi-platform build system
under `tools/` add some scripts to invoke the build system to build all
deps for vbam and vbam itself:

- `tools/linux/builder`

This builds a mostly static linux binary with a few dynamic deps for
xorg and wayland. Using gtk3. This will run on just about any dist.

- `tools/osx/builder`

Builds a static mac app targetting 10.7.

- `tools/win/linux-cross-builder`

Builds a static windows binary using the mingw-w64 toolchain.

- `tools/win/msys2-builder`

Builds a static windows binary in the MSYS2 environment, this may be
suffering from a few regressions.

Change some cmake code to support the build system, refactor a few
things in it.
2018-02-24 14:39:29 -05:00
Rafael Kitover df0bd439fb fix deps submodule init on windows
`git submodule update --remote --recursive` must be called with `--init`
if the submodules have never been initialized, add the flag to the cmake
code that does this. If they are already initialized, it will not cause
any harm.
2017-10-25 06:25:29 -07:00
Rafael Kitover 420450255c mac build/builder improvements
Improve, refactor and clean up `tools/osx/builder` to build a relatively
full-featured ffmpeg as well. This requires lots of other dists. It's
kind of like a mini port system now. Will generalize it shortly to a
sourced library for using with both the mac and the mingw builds. Will
hopefully become a separate repo on github at some point.

Add perl dist support to the builder.

Add an `--env` flag to the builder to print the build environment
variables so that they can be read in with `eval` for debugging
purposes.

Also add the `FFMPEG_STATIC` cmake option to link static ffmpeg
libraries correctly.

Move the codesigning and zipping of the `.app` bundle to the builder
script and out of cmake, as this is something most users don't need.
2017-10-22 15:35:56 -07:00
Rafael Kitover 21926d6230 add -mfpmath=sse -msse2 compiler flags: x86/amd64
This may speed things up a little in some places, or maybe not, but
should be safe as few if any users are likely to be using a CPU without
SSE2.
2017-10-17 10:26:37 -07:00
Rafael Kitover d7ff2afb80 add mac release builder script
Add `tools/osx/builder`, a POSIX sh script to build all dependant
libraries as static, targetted to OS X 10.7, and build the project with
them (also targetted to OS X 10.7.)

ffmpeg currently does not link, as recording functionality is currently
non-functional anyway, this will be fixed later.

MISC:

- set WORKING_DIRECTORY and ERROR_QUIET for all git commands, for the
  cases when the build directory is not under the git checkout

- #include <cerrno> in ConfigManager.cpp as it uses errno

- change `build*` in `.gitignore` to `build/*` so that files starting
  with "build" are not affected
2017-10-12 01:32:18 -07:00
Rafael Kitover 46486381f0 read version info from CHANGELOG.md if no git
If git tags are not available, set the version and revision by finding
the first version tag in `CHANGELOG.md` of the form

```
```

Where N.N.N is the number version (number of components can vary) and
the revision (as speicified by -REV) is optional.

TODO: support named revision without a version number of the form
`[REV]`.
2017-10-11 19:17:25 -07:00
Rafael Kitover 52439cee0e fix error and version info in shallow git clones
Fix `cmake/GitTagVersion.cmake` to not throw errors when in a shallow
git clone, or any git clone that has no tags.

And when either git or git tag version info is not available, set the
version variables to the defaults, which are:

```
VERSION         = '2.0.0'
REVISION        = 'unknown'
VERSION_RELEASE = 0
```
2017-10-07 18:17:52 -07:00
Rafael Kitover f5379ab806 read version and subversion info from Git
To get the version, find the last tag in git tag of the form "v2.0.0" or
"2.0.0". If this is the last tag and the current commit matches the ref
of this tag, the revision will be empty.

In the case that the current commit is not tagged with a version, to get
the revision, use the short sha unless the current commit is tagged with
something that is not a version string, e.g.  "feature-foo", in which
case the revision will be "feature-foo".

If the current commit is tagged as e.g. "v2.0.1-foo" or "2.0.1-foo" then
the version will be "2.0.1" and the revision will be "foo". Tags of this
form are also checked when finding the current version.

This is all done in cmake. If there is no git detected, the version will
be "2.0.0" and the revision will be "unknown".
2017-10-07 14:00:47 -07:00
Rafael Kitover f069f0c02d default LTO to OFF on 64 bit MinGW
64 bit MinGW (e.g. msys2 64 bit) produces a binary that immediately
segfaults when built with LTO.

Make ENABLE_LTO default to OFF on 64 bit MinGW (32 bit will still
default to ON.)
2017-09-22 00:42:49 -07:00
ZachBacon 75ef0aa26d Added executable extension
* Allows the SDL binary to be installed if it's cross compiled from
within linux or macOS for windows for packaging purposes.
2017-09-22 02:46:20 -04:00
Rafael Kitover de89bd0561 use num cpu cores to parallelize LTO link with gcc
Use the `cmake` `ProcessorCount` module to determine the number of CPU
threads, and set the `-flto` flag for gcc to `-flto=${num_cpus}` if the
number of CPU threads is detected and is greater than `1`.

clang does not support this.
2017-09-19 06:58:48 -07:00
Rafael Kitover 268c638456 improve win32 dependencies git submodule handling
Use `git submodule update --remote --recursive` instead of `git
submodule update --init --recursive` so that the latest version of the
repo is always installed.

Run the command from cmake instead of throwing an error if the submodule
is not checked out. Only throw an error if the checkout failed or the
source tree is not a git checkout.

Don't add the `mingw-xaudio` include directory if using MSVC.

Remove the submodule check from src/wx/CMakeLists.txt, having it in the
main CMakeLists.txt is enough.
2017-09-19 06:11:41 -07:00
Rafael Kitover 7f1fec88af work around gcc lto wrappers bug with gcc 7.x
gcc lto wrapper commands such as `gcc-ar` will segfault with some
versions of gcc 7.x when called via an absolute path, see:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80717

Generalize the mechanism for compiling a small C program on the host
(currently used for bin2c for Wx resources) and use it to wrap the gcc
wrappers in a little executable that prepends their dirname to PATH and
runs them with `execvp()`.

Make LTO default to ON again, except on win32 with gcc < 7, because
those toolchains produce broken binaries with LTO enabled.

Also add `-ffat-lto-objects` to compiler flags for gcc when LTO is
enabled, this will increase the chances that the LTO build will succeed
even if there are issues with the binutils wrappers. Clang does not
support this.
2017-09-16 19:47:39 -07:00
Rafael Kitover b82cab14e2 rename CMakeScripts/ to cmake/
Most projects nowadays call the project specific cmake scripts directory
just `cmake/` and we will do so as well.
2017-09-13 20:30:33 -07:00
Rafael Kitover 2ad204619b compile/run test to detect Wx ABI version #142
In 4e665ae I hardcoded -fabi-version=2 for g++ flags, and @ArtiiP
pointed out that this is wrong, because Wx may be compiled with other
ABI versions.

Add cmake check_cxx_source_runs() tests to determine the correct ABI
version flag to use with Wx.
2017-09-01 21:51:24 -07:00
Rafael Kitover 4e665ae088 use -fabi-version=2 for GCC, turn off LTO #142
Use the g++ `-fabi-version=2` compiler option, as suggested by @ArtiiP
to fix problems similar to:

```
Fatal Error: Mismatch between the program and library build versions
detected.
The library used 3.0 (wchar_t,compiler with C++ ABI 1002,wx
containers,compatible with 2.8),
and your program used 3.0 (wchar_t,compiler with C++ ABI 1009,wx
containers,compatible with 2.8).
Aborted
```

Turn LTO off by default until I fix it for newer gcc/binutils, currently
with gcc7 ar segfaults linking vbamcore.
2017-09-01 05:06:26 -07:00
Rafael Kitover 8b2e8f87d4 only use -mtune=generic on x86/amd64 #146
This flags breaks the build on e.g. ARM, so only use it when a PC
architecture (x86 or amd64) has been detected. Thanks to ZachBacon for
spotting this.
2017-08-30 14:42:08 -07:00
Rafael Kitover e0f79f32a5 remove version.h in ConfigManager and AutoBuild.h
ConfigManager does not use any version info, but is part of libvbamcore,
so removing the `#include` makes rebuilds after git changes much much
faster.

Remove the AutoBuild.h includes from ConfigManager.cpp and SDL.cpp (the
SDL port) because the information in that file does not seem to be used
and it also includes version.h, forcing those files to rebuild
unnecessarily.
2017-08-27 13:32:13 -07:00
Rafael Kitover 2179215a8b fix rebuilds on git changes
Use cmake to generate the version.h from version.h.in which is a cleaned
up version of the old version.h with the git short sha into the build
directory, and include the version.h from there.

Continue to use the GetGitRevisionDescription plugin to make the cmake
configuration state depend on the current sha of HEAD, but throw away
the results (for the time being.)

This makes rebuilds after git changes such as a commit only recompile a
couple of files instead of the whole tree.
2017-08-27 13:20:17 -07:00
Rafael Kitover 1d0eece046 let cmake escape -D preproc. definitions
As cmake now warns when policies are set to OLD, change the CMP0005
policy to NEW.

What this does is have cmake escape -D preprocessor definitions passed
to e.g. add_definitions() starting in cmake 2.6 . This is fine since the
minimum cmake version we support is 2.8.12 . It also makes the code
cleaner since we don't have to escape quotes anymore ourselves. This
will also work better on different platforms, where different escapes
may be needed.

Remove all quote escapes from string params to add_definitions() for
this policy change to work.
2017-08-09 02:34:40 -07:00
Rafael Kitover 783475bf39 switch to cmake module GNUInstallDirs #116
See:

https://cmake.org/cmake/help/v2.8.12/cmake.html#module:GNUInstallDirs

Use these variables to set all installation paths.

Add link and note about module to README.md .
2017-05-24 04:25:45 -07:00
orbea 7ea1616afc Add BIN_INSTALL_DIR and MAN_INSTALL_DIR 2017-05-11 06:39:37 -07:00
Rafael Kitover 6af5525ac1 cmake: default to ENABLE_ASM_CORE=OFF #98 #54
The inline assembly in src/gba/GBA-thumb.cpp which is turned on with the
cmake ENABLE_ASM_CORES option, sometimes causes weird behavior on
windows (see: #54) and a crash on startup in linux (see: #98, confirmed
on both Fedora and Arch Linux.)

Previously the default for this option was ON for 32 bit builds, set the
default to OFF always for the time being, until it is either fixed or
replaced.
2017-03-18 19:04:39 -07:00
Rafael Kitover 2e8bee117d cmake: use add_compile_options for ssp-buffer-size
In 82c8a1e3 I made "--param ssp-buffer-size=4" one argument instead of
two because when added to CMAKE_REQUIRED_LIBRARIES the ssp-buffer-size=4
part was being recognized as a library, breaking the compile tests.

This broke the build on mac, which I fixed in 915e2d1e by using ssp
flags for gcc only and not clang.

Now apparently it is breaking mxe, so instead of adding this particular
parameter to the MY_C_FLAGS variable which is then added to
CMAKE_REQUIRED_* variables for compile tests, add it directly via
ADD_COMPILE_OPTIONS().

This should hopefully resolve any remaining issues with this compiler
flag.
2017-03-14 10:33:24 -07:00
Rafael Kitover 915e2d1ec2 activate libssp compiler flags for gcc only
In 82c8a1e3 I made "--param ssp-buffer-size=4" one argument instead of
two to fix another problem when passing compiler flags to
CMAKE_REQUIRED_LIBRARIES, clang cannot deal with this and this breaks
the build on mac.

Enable libssp related flags for gcc only, because clang does not support
them anyway. This fixes the build issue on mac.
2017-03-11 19:19:47 -08:00
Rafael Kitover 82c8a1e3fa fix linux build broken in 687c08a
Stop saving and restoring the CMAKE_REQUIRED_* variables for the compile
test, because the subsequent Wx header symbol tests need them set up for
Wx support as well.

Also --param foo=bar needs to be a single string in the list of compiler
flags, or cmake can misinterpret the second part as a library when it is
passed to libraries/link-options.
2017-03-10 06:38:50 -08:00
Rafael Kitover 7b0baadbaa fix 32bit intel detection for 32bit mxe target
mxe leaves CMAKE_SYSTEM_PROCESSOR empty, so detect if mxe is being used
and set the variable based on CMAKE_TOOLCHAIN_FILE, this allows the
32bit asm to compile under mxe.

Also if no toolchain file is being used and CMAKE_SYSTEM_PROCESSOR is
empty, fall back to CMAKE_HOST_SYSTEM_PROCESSOR.
2017-03-08 15:49:00 -08:00
Rafael Kitover 687c08a051 pass all compiler/linker flags for compile test
When determining gcc/clang flags, save resulting C flags as MY_C_FLAGS,
C++ flags as MY_CXX_FLAGS, and linker flags as MY_C_LINKER_FLAGS, then
use them in the Wx OpenGL compile test.

This fixes the test erroneously failing on git mxe on mac.

Also, don't use -fPIC on Win32, set Wx defines separately from the test,
and save all CMAKE_REQUIRED_* variables before the test and restore them
afterwards.
2017-03-07 16:15:02 -08:00
Rafael Kitover fef71439fc add ENABLE_ASM cmake option
Add the ENABLE_ASM flag for cmake which turns ON or OFF the
ENABLE_ASM_CORE, ENABLE_ASM_SCALERS and the ENABLE_MMX options at once.
2017-03-06 01:40:55 -08:00
Zach Bacon eb7dab6272 ws2_32 is needed for the SDL binary on windows 2017-03-05 20:06:22 -05:00
Rafael Kitover cf5f425b3a default to -DENABLE_FFMPEG=ON on Mac again
No particular reason to exclude ffmpeg support in Mac builds.
2017-02-24 06:44:26 -08:00
Rafael Kitover 99c6c4f938 Merge pull request #74 from Mystro256/gccwarnings
- fix C++ only flags being used for C

- check if cheats/patches files load correctly
2017-02-13 01:26:22 -08:00
Mystro256 611bbd6707 Re-add missing installed icons (for linux) 2017-02-12 06:50:54 -08:00
Rafael Kitover 289abcd7a2 use -fpermissive and -fexceptions with C++ only
Add -fpermissive and -fexceptions to CMAKE_CXX_COMPILE_OBJECT so that
they only affect C++. -std=gnu++11 was already there from b4ba9d9d, but
this is a cleaner method (which is also used for NASM) where we use
STRING(REGEX REPLACE ...) to append options after the <FLAGS>
placeholder in CMAKE_CXX_COMPILE_OBJECT.
2017-02-12 04:41:57 -08:00
Mystro256 28624ac01b fpermissive is only a C++ flag 2017-02-12 04:26:21 -08:00
Rafael Kitover 65dae0d0a1 support Ninja cmake generator on msys2
Add a hack to the root CMakeLists.txt to SET(MSYS ON) for the Ninja
generator when running under msys2, otherwise it cannot find libs.

The quoting fixes from #70 allow all of this to work.
2017-02-11 14:18:38 -08:00
Rafael Kitover c02c448f47 clean up dependencies/msvc inclusion cmake code
Move the check for dependencies/msvc into the previous IF(WIN32) block
adding an IF(MSVC) level.

Remove duplicate call to INCLUDE_DIRECTORIES(dependencies/msvc) from
later on in the main CMakeLists.txt.
2017-02-11 06:33:08 -08:00
Rafael Kitover d6c1b53653 add one missed cmake windows quoting fix
Also quote LOCALEDIR with as \\\""${LOCALEDIR}"\\\", just like the other
defs are quoted.

This fixes the build on msys2.
2017-02-11 05:52:42 -08:00
Rafael Kitover b4ba9d9d65 set -std=gnu++11 globally for C++ only
Add -std=gnu+11 to CMAKE_CXX_COMPILE_OBJECT in the main CMakeLists.txt
to force the option for all C++ sources.

The right way to do this is to use a generator expression with
ADD_COMPILE_OPTIONS, but this is only available in cmake 3.3 and we must
maintain 2.8.12 compatibility to support Ubuntu 14.

This fixes the mac build (clang.)
2017-02-11 05:33:10 -08:00
edorax f7186a6493 Move 'dependencies/msvc' inclusion to the CMakeLists.txt in top level. 2017-02-11 13:39:50 +08:00
Su Yong 4e096c127c Some fixes for MSVC. 2017-02-11 10:57:35 +08:00
Rafael Kitover fcc34394c1 fix build failure on OS X Lion with XCode 4.2
XCode 4.2 generates a broken binary if -fomit-frame-pointer and/or -flto
is used for compile and link flags.

Check for Clang version less than 4.3 on APPLE and remove these flags in
the compile options setting cmake code.
2017-02-03 12:39:10 -08:00
Rafael Kitover cb0bcfae6b fix msys2 build failure in 34e408cc
cmake automatically passes -std=gnu++11 in some cases, while we were
passing -std=c++11, and this was causing incompatibilites in name
mangling between different objects.

Fix this by using -std=gnu++11 for gcc.
2017-01-30 19:12:04 -08:00
Rafael Kitover f21178f6f7 fix nasm support broken in 34e408cc
The last commit removed generator expressions from ADD_COMPILE_OPTIONS()
which made C/C++ flags apply to nasm as well.

Fix this by removing <FLAGS> from CMAKE_ASM_NASM_COMPILE_OBJECT and
replacing it with the flags we want.
2017-01-30 18:14:33 -08:00
Rafael Kitover 34e408ccb7 fix Debian 8 Jessie and Ubuntu 14 Trusty compat
Fix some porting issues to make everything work on Debian 8 "Jessie"
and Ubuntu 14 "Trusty":

- set cmake minimum version to 2.8.12, this is the Ubuntu 14 version

- combine C and C++ flags and add all of them using
  ADD_COMPILE_OPTIONS() without using generator expressions, which is a
  cmake 3.2 or so feature

- add -fpermissive to force some non-const type casts to compile on
  older versions of gcc

- add -std=c++11 for gcc to enable support on older versions of gcc

- check that the compiler supports -fstack-protector-strong before
  adding it, older versions of gcc do not

- fix the debian section of ./installdeps to include libpng-dev instead
  of libpng16-dev and add gettext for msginit etc.

- fix compat checks in src/common/ffmpeg.cpp and src/wx/cmdevents.cpp to
  check for libavcodec >= 56 instead of > 56, the Debian Jessie version
  is exactly version 56 . With the one exception of
  AV_CODEC_FLAG_GLOBAL_HEADER which is defined in later versions.
2017-01-29 10:14:34 -08:00
Rafael Kitover fdc389c280 fix wx 2.8 compat, debug logging works everywhere
Fix backcompat with wx 2.8. This involved writing
wxPositiveDoubleValidator and rewiring the DrawingPanel inheritance tree
and event handling mechanisms (because 2.8 does not have ->Bind, only
->Connect which is less flexible.) As a result all the event handling
has been gathered into GameArea and the affected code is somewhat
cleaner. 2.8 support is untested on Mac because it requires 32 bit libs
and Carbon.

Add support for cross-compiling for windows using the Fedora MinGW
packages in ./installdeps.

Check for OpenGL support in the wx library being linked, this was
necessary because the Fedora MinGW wx library does not have OpenGL
support.

Remove vbamDebug() in favor of wxLogDebug(), and add an override for it
so that it works in non-debug builds of wx as well as on Windows. Turn
off buffering on stdout and stderr on startup so that debug logging
works in msys2/cygwin mintty as well.

On Windows, build a console binary for debug builds.

Update README.md to reflect Fedora MinGW support and debug logging
support.

Add -Wextra to cflags for debug builds.
2017-01-25 10:53:05 -08:00
Rafael Kitover 82d694df3a disable LTO on Win32 for now
Due to reports of segfaults etc. disabling LTO on Win32 for now.
2016-12-31 04:48:51 -08:00
DoctorWho11 57adfaf24e Add missing libiconv for enabling nls 2016-12-30 22:48:23 -05:00
Rafael Kitover d06e7afceb full support for cross-compiling to win32 with mxe
Fix all cmake issues related to building for win32 with mxe.

Add support for ./installdeps win32 on Debian/Ubuntu using the mxe apt
repository.

Details:

* default to ENABLE_LTO=OFF on mxe

* set SFML_STATIC_LIBRARIES=TRUE on mxe

* fix the libintl/gettext checking logic

* fix the git dependencies submodule checking logic, and check that it
  triggers for mxe

* revert FindSFML.cmake to upstream version, works fine with mxe

* make 'win32' an alias for the 'MinGW-w64-i686' target for
  ./installdeps, add support for mxe apt repository for Debian/Ubuntu

* change bin2c related cmake code to compile the tool on the host always
  even when cross-compiling

* copy src/win32/res/VBA.ico to src/wx/icons since src/win32 has been
  removed

TODO: generic mxe installer for other unix-likes
2016-12-21 13:02:55 -08:00
DoctorWho11 978d5b7991 Missed one other cmake instance of gvbam 2016-12-20 21:26:11 -05:00
DoctorWho11 a1bf0f3f82 Drop gtk and mfc interfaces. Things are changing and for the better. 2016-12-20 17:34:34 -05:00
Rafael Kitover 7b1b1ea236 only use gcc binutils wrappers when LTO is enabled
Use gcc wrappers like gcc-ar/gcc-nm/gcc-ranlib only when LTO is enabled.
2016-12-14 05:48:37 -08:00
Rafael Kitover c216528793 generalize ./installdeps + mac pkg mgrs support
Add a more general purpose ./installdeps script to replace
./installdeps-msys2 that handles: Debian Linux, Arch Linux, MSYS2+MinGW,
Mac Homebrew, MacPorts and Fink for Mac. More OSes and distributions
will be added in the future, and the script may be generalized for use
in other projects.

Move Mac package manager setup code into MacPackageManagers.cmake and
greatly improve it. Handles Homebrew, MacPorts and Fink correctly.

Minor tweaks for FindSDL2.cmake: better include dir searching that works
on cygwin, fix flags for MinGW, and quiet pkg-config program errors.

Add MinGW cross-compilation toolchain files, they can be specified on
the cmake command line with:

-DCMAKE_TOOLCHAIN_FILE=../CMakeScripts/Toolchain-cross-MinGW-w64-i686.cmake

or

-DCMAKE_TOOLCHAIN_FILE=../CMakeScripts/Toolchain-cross-MinGW-w64-x86_64.cmake

these work for Cygwin and should work for MinGW on Linux as well.
2016-12-10 23:41:32 -08:00
Mystro256 8baa415848 Add linux appdata and fixes
Desktop files aren't installed for linux by default
2016-12-10 19:05:30 -05:00
Mystro256 d6228254cf cmake fixes
-Whitespace fixes
-Binaries installation fixes
2016-12-10 18:27:18 -05:00
Mystro256 24d2521914 Manpage fixes 2016-12-10 17:56:04 -05:00
Jeremy Newton c7386503c4 Fix DSYSCONF_INSTALL_DIR
I'm not sure if this was changed in cmake recently, but "SYSCONFDIR" is incorrect. It should be SYSCONF_INSTALL_DIR.

As well CMAKE_INSTALL_PREFIX refers to /usr or /usr/local in linux, so installing it into ${CMAKE_INSTALL_PREFIX}/${SYSCONFDIR} would be incorrect. I've wrapped it in the existing IF( WIN32 ) to preserve the installation for windows, a window dev should fix that if it's incorrect.
2016-12-09 12:44:11 -05:00
Rafael Kitover 37518fc88b add LTO option, disable on GCC+AMD64+Win32
Add ENABLE_LTO cmake option that defaults to ON except on GCC building
for AMD64 on Win32.

Also set the cmake variables AMD64 or X86_32 when one of these
architectures is detected.
2016-11-27 15:37:24 -08:00
Rafael Kitover b468eddfa5 only use -flto=10 with gcc
gcc allows flto=<jobs> to parallelize linking, clang does not understand
this, use just -flto for clang and -flto=10 for gcc.
2016-11-23 03:13:33 -08:00
Rafael Kitover cdae078e42 pass all compile flags to link step
This makes -static-libgcc -static-libstdc++ actually work, and is
probably better for LTO as well.
2016-11-21 13:53:16 -08:00
Rafael Kitover 349bbd13bc add LTO support, fix libssp link, add -ggdb3 -Og
Add support for Link Time Optimization (LTO) on gcc and Clang.

Link libssp only when it is on the system, some toolchains like Ubuntu's
do not require explicitly linking to libssp. On Win32 try to link it
statically.

In debug builds with GCC, use -ggdb3 -Og, otherwise use -g .

Two new cmake modules were written for this:

* FindSSP.cmake -- this is for finding libssp on the system.

* UseGCCBinUtilsWrappers.cmake -- this is for using gcc binutils
wrappers such as gcc-ar, which is required for gcc LTO to work.

These will be distributed separately as well.
2016-11-21 12:37:21 -08:00
Rafael Kitover 55f6e17f0d compile/link flags improvements
* Bump minimum cmake required to 3.3.2, to make sure generator
  expressions work.

* Force CMAKE_BUILD_TYPE to "Release" if unset, not sure if this
  actually works.

* Merge the older compile flags block with the new one and use generator
  expressions to make sure the relevant flags apply only to C, C++ or
  nasm.

* Add -lssp to the end of the link commands for the -fstack-protector*
  options, this is only needed/done for gcc.

* Add -lversion and -limm32 to SDL2_LIBRARY (Zach asked for this.)

* Builds on msys2 again!
2016-11-20 11:11:52 -08:00
Rafael Kitover 1dd7ecfe0f set Zach's CXXFLAGS only on gcc/clang
Set the flags Zach gave me only when cmake detects gcc or clang, this
way other generators like Visual Studio will still work fine.
2016-11-20 06:15:27 -08:00
Rafael Kitover bbdc6ca577 make ENABLE_SDL default to OFF
Default building options now just build the Wx port.

Also set +x on ./installdeps-msys2 .
2016-11-20 05:46:24 -08:00
Rafael Kitover 180ee60c7a clean up APPLE block in main CMakeLists.txt
Remove some redundant nasm-related code and an outdated comment.

Objective-C++ code is now separated into an .mm file and nothing is done
to change the compiler invocation for it.
2016-11-19 17:13:49 -08:00
Rafael Kitover 40dcb2df7a add some compiler flags
These are the flags Zach wanted.

They work fine with gcc and clang, will test what happens with msvc as
well.
2016-11-19 17:07:30 -08:00
Rafael Kitover 902a7a7e0d fix 32bit build support
Make ASM_CORE, ASM_SCALERS and ENABLE_MMX the defaults for 32bit builds
on intel hosts (the host can be AMD64, as long as the target is 32bits.)

Move mac nasm search into the mac section of the cmake code and stop
defaulting to /usr/bin/nasm, this was screwing up the build on msys2.

Fix src/filters/2xSaImmx.asm to compile and link correctly.

Add nasm to list of mingw deps for ./installdeps-msys2 .

Tested that msys2-built Wx binary runs, including with 2xSaI.

Keyboard doesn't work yet on msys2 builds, but that's a completely
different issue.
2016-11-18 09:04:55 -08:00
Rafael Kitover 3c30d59aba msys2 build improvements
* Enable ffmpeg by default only on linux and msys2, it will be disabled
for normal windows builds and on mac.

* Set SFML_STATIC_LIBRARIES only for normal non-msys2 windows builds,
because msys2 does not currently have static versions of the SFML
sub-libraries, e.g. system, network, etc.. Dynamic linking works fine
for now.

* Fix quoting for -DLOCALEDIR, on windows spaces were causing errors in
make on msys2.

* Update to upstream FindSFML.cmake .

* Add an ./installdeps-msys2 script to install all necessary tools and
libraries on msys2 for building both 64 and 32 bit windows Wx binaries.

* Add the dependencies/mingw-xaudio/include directory to
INCLUDE_DIRECTORIES so that XAudio compiles on msys2, as mingw-w64 does
not currently have XAudio headers. Also check that the user pulled the
git submodule in the process (the ./installdeps-msys2 script does this
for you.)

TODO:

* Generalize ./installdeps to work on more platforms.

* Make console Wx app in debug mode so that debug prints will work.

* Fix game keyboard input for msys2 builds.

* Add HiDPI support for Windows.

* Fix the -D*DIR defines to have the correct paths on windows.
2016-11-14 10:56:50 -08:00
Adam Sampson 4bf4248985 SFML is required for link support. 2016-11-10 11:39:45 +00:00
Rafael Kitover 30f80ab22b fix wx GL viewport + build improvements
Add GetRealPixelClientSize() method to HiDPIAware and implement using
wx GetClientSize() in panel.cpp for the generic version, and using
convertSizeToBacking: in macsupport.mm .

Add an AdjustViewport() method to GLDrawingPanel that sets glViewport()
using GetRealPixelClientSize(), and call it for the SIZE event. Debug
print the viewport size here instead of in DrawingPanelInit().

Build improvements:

* default to Cairo off for all platforms, currently libcairo2-dev does
  not install on Ubuntu

* default to ON for ENABLE_LINK and ENABLE_FFMPEG (for game recording),
  this will allow for more fully-featured default builds

* do not set SFML_STATIC_LIBRARIES on Mac because this is currently
  broken

* fix the Mac bundling/linking script to deal with links in dependent
  libs that already use @rpath (very minor change.)
2016-11-08 04:51:26 -08:00
Rafael Kitover 981026dc80 fix Xcode project generation via cmake
Move Objective-C++ Mac code for Wx into macsupport.mm with stub methods
in panel.cpp, and stop compiling all C++ as Objective-C++.

cmake -G Xcode # now works fine
2016-11-06 14:09:50 -08:00
Rafael Kitover 2d9ec99c11 Mac build improvements
Move closer to allowing an "out of the box" distributable build for Mac:

* fix the icon for the .app

* link SDL2 statically, a PR has been sent to the original repo here:
  https://github.com/tcbrindle/sdl2-cmake-scripts/pull/9

* link SFML statically

TODO:

For a releasable build on OS X, system libs must be linked
dynamically while third party libs are linked statically or bundled. The
goal is to link them statically.

The two remaining libs that need static linking are PNG and wX.

For PNG a similar approach to the one used for SDL2 using pkg-config
should work fine and be simple to implement.

For wX things are more complicated. The default build of wX does not
include static libs, I will need to submit a PR for Homebrew to change
the default build to include both dynamic and static versions.
2016-10-26 16:58:21 -07:00
Rafael Kitover 2b45cc7662 fix typo in CMakeLists.txt from 7a7a72f
Fix typo in the default cpp flag when CMAKE_BUILD_TYPE is "Release"
from `-NDEBUG` to `-DNDEBUG`.
2016-10-24 13:12:40 -07:00
Rafael Kitover 7a7a72f2bd Mac OS X HiDPI fixes + other misc
Use a high-res surface on HiDPI (e.g. retina) Macs for the OpenGL
renderer, and scale window accordingly. Also fix fullscreen toggle not
working in HiDPI mode. And some other stuff.

Aside from the .app not being linked statically, the app is now fully
functional on Mac and ready to ship.

Full change details:

* add -DDEBUG or -DNDEBUG based on CMAKE_BUILD_TYPE (-DNDEBUG for
  Release and -DDEBUG for Debug)

* properly search for homebrew/macports/fink directories, and only add
  them if they exist

* fix building with wx debug support, when available

* use explicit OpenGL context on Mac too for new versions of wx

* add main_frame pointer in GameArea back to MainFrame, and a
  SetMainFrame(MainFrame* parent) public method to set it in guinit

* add full support for reading and writing double value config options
  (the GUI still needs to be updated for options that can take doubles,
  such as video_scale)

* change video_scale option (Display/Scale) to a double, putting a
  double value such as 3.6 in the config file works correctly

* add a HiDPIAware mixin class for GameArea and DrawingPanel, with the
  method HiDPIScaleFactor which returns the current window's
  backingScaleFactor

* change the GameArea sizing methods (DelBorder(), AdjustMinSize() and
  AdjustSize()) to divide the window size by the
  HiDPIAware::HiDPIScaleFactor so that the window is scaled properly

* change GameArea::ShowFullScreen to ignore fullscreen events for a
  maximized window on Mac, because maximized windows on OS X are
  actually native fullscreen windows

* change scale variables to double from int, and use std::ceil() to
  round scaled pixel or memory size values

* make a default base class DrawingPane::DrawingPanelInit() virtual
  method, call by all concrete class constructors based on the did_init
  flag

* call setWantsBestResolutionOpenGLSurface:YES on the view backing the
  wxGLCanvas for the OpenGL renderer (GLDrawingPanel) to get a high res
  OpenGL surface in HiDPI mode

* remove GLDrawingPanel::OnSize event, the OpenGL viewport resizes
  automatically without the need to call glViewport()

* do not hide the mouse pointer if the main frame has menus or dialogs
  open

* add variadic vbamDebug(const char* format, ...) function, active only
  #ifdef DEBUG, which sets the wx log target to STDERR and logs a
  message to it

* use full name of app "visualboyadvance-m" instead of "vbam" when
  getting configuration paths, this way the config is saved to
  ~/Library/Application Support/visualboyadvance-m rather than
  ~/Library/Application Support/vbam

* listen to the MENU_HIGHLIGHT_ALL event as well, as an extra way to
  check when the menus are open

* add public MainFrame::SetMenusOpened(bool state) method to force the
  main frame to change the internal menus_opened state, this is
  necessary because in HiDPI mode on Mac the keyboard accelerator for
  toggle fullscreen sends a menu open event, but not a menu close event,
  so on switch to fullscreen the state is changed to menus closed and
  the emu is unpaused

TODO:

* GUI option to change toggle fullscreen behavior between native and
  non-native fullscreen on Mac

* GUI support for double config values like Display/Scale

* add HiDPI support to simple renderer

* fix SDL sound, or disable the option

* fix Cairo suport on Mac, or disable the option

* use dynamic_cast<> to implement GetWindow() for DrawingPanel instead
  of pure virtual method, likewise for Delete()

* link .app statically by default so it can be shipped

* add Homebrew formula
2016-10-22 05:47:27 -07:00
EoD a513d3191e Add C++11 in cmake as default
Currently, the build is broken on Linux as fixed width integers (for
example uint32) are used via <cstdint> without a namespace. This is only
allowed in C++11 and later.

See http://en.cppreference.com/w/cpp/types/integer for details.
2016-07-31 01:03:40 +02:00
Dorian Wouters 31391e090c
Kill common/Types.h, replace its old typedefs w/ standard types
Fix includes in files using standard int types
Fix wxWidgets UI includes
Silence some unused variable warnings in GBA-arm.cpp macros
2016-07-29 11:07:11 +02:00
Markus Kitsinger (SwooshyCueb) 57c619ca13 Add some header and resource files to CMakeLists.txts (Core+WX)
This makes these files show up in generated CodeBlocks projects, which
makes life easier for folks who import into QtCreator.
2016-06-07 15:26:53 -05:00
Zach Bacon c8343267fc <wip> Migration to SDL2 made possible by galtgendo, gtk changes to follow. 2015-11-18 21:34:38 -05:00
Rafael Kitover 3d679c1469 more minor improvements for OS X build
Add Homebrew and MacPorts paths for findings headers and libraries.

Add -x objective-c++ to the C++ compile command so that conditionally
compiled ObjectiveC code for OS X can be supported.

Throw a fatal error if the user tries to enable ENABLE_ASM_CORE,
ENABLE_ASM_SCALERS or ENABLE_MMX on AMD64, as this is not supported yet.

If ENABLE_ASM_SCALERS is enabled, try to find a Homebrew or MacPorts
nasm before using the outdated XCode nasm.

For the future, if the user has only the old XCode nasm which does not
support 64 bit objects and the build is 64 bit, throw a fatal error.

For 32 bit builds with the old XCode nasm, use -f macho instead of -f
macho32, which is used if the version of nasm is > 2.0 .

Pass -DMACHO instead of -DELF and, on AMD64 (for the future) -D__AMD64__
for nasm on OS X.

Pass -D__AMD64__ to C++ compilation as well on AMD64, this will help
when we support AMD64 inline assembly.

Add support for automatically linking Homebrew keg-only gettext from
/usr/local/opt/gettext for ENABLE_NLS.

Fix copying Info.plist and vbam.icns to the .app bundle.

Add a key to the Info.plist to support sharp text on retina displays, as
per:
https://wiki.wxwidgets.org/WxMac-specific_topics#Retina_display_support

Set wxWidgets_USE_DEBUG to ON if CMAKE_BUILD_TYPE is "Debug". I'm not
sure this does anything or if I'm doing this correctly though.

Also set wxWidgets_USE_UNICODE to ON. Again, I'm not sure this does
anything or is in the right place.

Fix a bug in the config dir finding code in
wxvbamApp::GetConfigurationPath() updated in 8b8f2f7 to only use the
more top level dirs if there is a vbam.ini in them, not if they are
writable as well, and use the reverse order (starting with user local
dirs) to check for writable dirs and their writable parents. This fixes
a problem with the vbam.ini being written to the Plugins directory of
the .app bundle if it's writable instead of ~/Library/Application
Support/vbam as was intended.
2015-11-16 21:56:23 -05:00
DoctorWho11 1e1b1cc35c This should fix the issue of when users on linux run the install command and make not finding the proper binary. 2015-09-29 23:49:15 -04:00
skidau 023d28a9cc OSX build fix by Juha Laukkanen. This one works with wxWidgets 3.0 and Cairo 1.14.2. 2015-07-11 10:34:27 +10:00
DoctorWho11 3389ba5cd6 make cpack ignore the dep folder 2015-06-15 09:20:20 -04:00
DoctorWho11 65f7546798 rename exe and added more cpack stuff. 2015-06-15 09:00:47 -04:00