Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake WIP #148

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ core
/stats
/modules
/history.idx
/build
157 changes: 157 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
cmake_minimum_required(VERSION 2.9 FATAL_ERROR)

set(FE_VERSION "v2.6.1")

project(attract)

# Default build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE
STRING "Choose the type of build" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release")
endif()

# cmake module search path, prefer ours
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})

include(GNUInstallDirs)
include(InstallRequiredSystemLibraries)
include(GetGitRevisionDescription)
include(CheckIncludeFile)
include(TargetArch)
include(FindPkgConfig)

target_architecture(CMAKE_TARGET_ARCHITECTURES)
string(TOUPPER ${CMAKE_SYSTEM_NAME} TARGET_SYSTEM)
string(CONCAT TARGET_SYSTEM TARGET_ ${TARGET_SYSTEM})
string(TOUPPER ${CMAKE_TARGET_ARCHITECTURES} TARGET_ARCH)
string(CONCAT TARGET_ARCH TARGET_ ${TARGET_ARCH})

message(STATUS "Target: ${CMAKE_SYSTEM_NAME} ${CMAKE_TARGET_ARCHITECTURES}")

#### BEGIN: Options ####
# All options mapped to config.h definitions

option(NO_MOVIE "Disable movie support (ffmpeg)" OFF)
option(NO_SWF "Disable SWF support (gameswf)" OFF)
option(USE_LIBARCHIVE "Archive library support" ON)
option(USE_GLES "GLES instead of GL" OFF)
option(USE_LIBCURL "Libcurl support" ON)
option(FE_DEBUG "Debug" OFF)

if(WIN32)
option(WINDOWS_CONSOLE "Enable console on Windows" OFF)
else()
option(USE_DRM "Use DRM instead of X11" OFF)
option(USE_MMAL "Use MMAL video decoder" OFF)
option(FE_HWACCEL_VAAPI "Use VAAPI video decoder" OFF)
option(FE_HWACCEL_VDPAU "Use VDPAU video decoder" OFF)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(FE_DEBUG ON)
endif()

if(NOT WIN32 AND NOT APPLE)
if(USE_DRM)
pkg_search_module(LIBDRM REQUIRED libdrm)
pkg_search_module(GBM REQUIRED gbm)
else()
find_package(X11)
pkg_search_module(XRANDR REQUIRED xrandr)
find_package(Xinerama)
endif()
endif()
set(USE_XLIB ${X11_FOUND})
set(USE_XINERAMA ${XINERAMA_FOUND})

if(USE_LIBARCHIVE)
pkg_search_module(LIBARCHIVE REQUIRED libarchive)
endif()

if(USE_LIBCURL)
pkg_search_module(CURL REQUIRED libcurl)
endif()
#### END: Options ####

#### BEGIN: Version ####
# parse VER_* definitions for config.h, prefer git, fallback to FE_VERSION

git_describe(VER_TAG --tags --abbrev=0)
if("${VER_TAG}" STREQUAL "GIT-NOTFOUND")
set(VER_TAG ${FE_VERSION})
set(VER_COUNT "0")
else()
git_revlist(VER_COUNT --count ${VER_TAG}..HEAD)
endif()
string(REGEX REPLACE "^v" "" RESULT ${VER_TAG})
string(REGEX REPLACE "[-\\.]" ";" RESULT ${RESULT})
list(GET RESULT 0 VER_MAJOR)
list(GET RESULT 1 VER_MINOR)
list(GET RESULT 2 VER_PATCH)
git_describe(VER_DIRTY --dirty)
if(NOT "${VER_COUNT}" EQUAL "0")
set(VER_TAG "${VER_TAG}-${VER_COUNT}")
endif()
if("${VER_DIRTY}" MATCHES "-dirty")
set(VER_TAG "${VER_TAG}-dirty")
endif()
message(STATUS "Version Tag: ${VER_TAG}")

#### END: Version ####

#### BEGIN: Dependencies ####

if(NOT WIN32)
find_package(FontConfig)
set(USE_FONTCONFIG ${FONTCONFIG_FOUND})
if(USE_FONTCONFIG)
find_package(EXPAT REQUIRED)
endif()
endif()

# FFmpeg
if(NOT NO_MOVIE)
find_package(FFmpeg COMPONENTS avformat avcodec avutil swscale swresample)
if(NOT FFMPEG_SWRESAMPLE_FOUND)
find_package(FFmpeg COMPONENTS avformat avcodec avutil swscale avresample REQUIRED)
endif()
endif()

#### END: Dependencies ####

#### BEGIN: Misc ####

# If ARM, assume GLES
if("${CMAKE_TARGET_ARCHITECTURES}" MATCHES "arm")
set(USE_GLES ON)
set(VIDEOCORE_PATH /opt/vc)
find_file(HAVE_VIDEOCORE bcm_host.h PATHS ${VIDEOCORE_PATH}/include NO_DEFAULT_PATH)
if(HAVE_VIDEOCORE)
include_directories(${VIDEOCORE_PATH}/include)
link_directories(${VIDEOCORE_PATH}/lib)
endif()
message(STATUS "ARM detected: USE_GLES:${USE_GLES}")
endif()

if(NOT WIN32)
set(DATA_PATH "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}/")
endif()

#### END: Misc ####

configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h")

# process CMakeLists.txt in these folders
add_subdirectory(extlibs)
add_subdirectory(src)

install(DIRECTORY config/
DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME})

include(cmake/PackageDeb.cmake)
add_custom_target(deb DEPENDS attract
COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=/usr .
COMMAND ${CMAKE_CPACK_COMMAND} -G DEB
WORKING_DIRECTORY ${BUILD_DIR})
95 changes: 61 additions & 34 deletions Compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ distributions. Other distributions should have similar packages available.
1. Install the following *development* libraries on your system:

* Required:
- SFML SDK version 2.x (<http://sfml-dev.org>)
- OpenAL
- Zlib
- FreeType 2
- [cmake] 2.9+
- [SFML] SDK version 2.x
- [OpenAL]
- [zlib]
- [FreeType] 2
- The following FFmpeg libraries (required for videos):
* avformat,
* avcodec,
Expand All @@ -26,25 +27,26 @@ distributions. Other distributions should have similar packages available.
* swresample or avresample.
- OpenGL and GLU (or OpenGLES for GLES version)
- JPEG library
- Make and Package Config
- Xrandr

* Optional:
- Fontconfig (to assist with finding fonts).
- Xinerama (for multiple monitor support).
- libarchive (for .7z, .rar, .tar.gz and .tar.bz2 archive support).
- Libcurl (for network info/artwork scraping).
- [Fontconfig] (to assist with finding fonts).
- [Xinerama] (for multiple monitor support).
- [libarchive] (for .7z, .rar, .tar.gz and .tar.bz2 archive support).
- [Libcurl] (for network info/artwork scraping).

2. Extract the Attract-Mode source to your system.

3. From the directory you extracted the source into, run:

make
mkdir build
cd build
cmake ..
make -j 3

or, if you are building on a Raspberry Pi, O-Droid or another embedded
system, you can build the OpenGL ES version with the following:
system, you can build the OpenGL ES version by adding an option to cmake:

make USE_GLES=1
cmake -DUSE_GLES=ON ..

This step will create the "attract" executable file.

Expand All @@ -64,19 +66,22 @@ distributions. Other distributions should have similar packages available.
config directory. By default, this config directory is located in
`$HOME/.attract` on Linux/FreeBSD systems.

NOTE: The Attract-Mode makefile tries to follow the GNU standards for
specifying installation directories: <https://www.gnu.org/prep/standards/html_node/Directory-Variables.html>.
NOTE: Attract-Mode tries to follow the [GNU standards for installation
directories][GNUInstallDirs].
If you want to change the location where Attract-Mode looks for its default
data from `/usr/local/share/attract` you should change these values
appropriately before running the `make` and `make install` commands.
data from `/usr/local/share/attract` you may change these values by running
`cmake` with the appropriate options. For example:

cmake -DCMAKE_INSTALL_PREFIX=PATH:/usr/ \
-DCMAKE_INSTALL_DATAROOTDIR=PATH:share

OS X:
-----

These instructions assume that you have X Code installed.

1. Install Homebrew (<http://brew.sh>). This can be done by running the
following command at a terminal command prompt:
1. Install [Homebrew]. This can be done by running the following command at a
terminal command prompt:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Expand All @@ -90,7 +95,10 @@ These instructions assume that you have X Code installed.

4. From the directory you extracted the Attract-Mode source into, run:

make
mkdir build
cd build
cmake ..
make -j 3

This step will create the "attract" executable file.

Expand All @@ -112,11 +120,9 @@ Windows (cross-compile):
------------------------

The recommended way to build Windows binaries for Attract-Mode is to cross
compile on an OS that supports MXE (<http://mxe.cc>) such as Linux, FreeBSD or
OS X.
compile on an OS that supports [MXE] such as Linux, FreeBSD or OS X.

1. Follow the steps in the mxe tutorial to set up mxe on your system:
<http://mxe.cc/#tutorial>
1. Follow the steps in the [mxe tutorial] to set up mxe on your system.

2. Make mxe's sfml, ffmpeg, libarchive and curl packages:

Expand All @@ -129,15 +135,19 @@ OS X.

3. Extract the Attract-Mode source to your system.

4. From the directory you extracted the source into, run the following:
4. From the directory you extracted the source into, run the following to make
a 32-bit build:

make CROSS=1 TOOLCHAIN=i686-w64-mingw32.static WINDOWS_STATIC=1
i686-w64-mingw32.static-cmake -B build/win32
i686-w64-mingw32.static-cmake --build build/win32 -j 4

to build the 32-bit version of Attract-Mode. To build 64-bit, run:
To make a 64-bit build:

make CROSS=1 TOOLCHAIN=x86_64-w64-mingw32.static WINDOWS_STATIC=1
x86_64-w64-mingw32.static-cmake -B build/win64
x86_64-w64-mingw32.static-cmake --build build/w64 -j 4

This step will create the "attract.exe" executable file.
This step will create the "attract.exe" executable file under `src/` of
the build directory.

5. Copy the contents of the config directory from the Attract-Mode source
directory and the executable you just built into the same directory on your
Expand All @@ -146,8 +156,7 @@ OS X.
Windows (native compile):
-------------------------

1. Install MSYS2
<https://msys2.github.io/>
1. Install [MSYS2]

2. Launch the MSYS2 shell and update the system:

Expand All @@ -160,15 +169,33 @@ Windows (native compile):
4. Install required packages. (optionally use the mingw-w64-i686-toolchain
instead for 32-bit windows architectures), install "all" (by default) :

pacman -S git mingw-w64-x86_64-toolchain msys/make mingw64/mingw-w64-x86_64-sfml mingw64/mingw-w64-x86_64-ffmpeg mingw64/mingw-w64-x86_64-libarchive
pacman -S git cmake mingw-w64-x86_64-toolchain msys/make mingw64/mingw-w64-x86_64-sfml mingw64/mingw-w64-x86_64-ffmpeg mingw64/mingw-w64-x86_64-libarchive

5. Clone and make Attract-Mode

git clone https://github.com/mickelson/attract attract
cd attract
make
mkdir attract/build
cd attract/build
cmake ..
make -j 3

This builds a version of Attract-Mode with various .dll dependencies. To
run the program, you will need to add `c:\msys64\mingw64\bin` to your path
(for 64-bit systems) or copy the dependent .dlls from that directory into
the same directory you will run Attract-Mode from.

[cmake]: https://cmake.org/
[SFML]: http://sfml-dev.org/
[OpenAL]: https://www.openal.org/
[zlib]: http://zlib.net/
[FreeType]: http://freetype.org/
[FFmpeg]: https://ffmpeg.org/
[FontConfig]: http://fontconfig.org/
[Xinerama]: https://en.wikipedia.org/wiki/Xinerama
[libarchive]: http://www.libarchive.org/
[Libcurl]: https://curl.se/libcurl/
[MXE]: http://mxe.cc
[mxe tutorial]: http://mxe.cc/#tutorial
[Homebrew]: http://brew.sh
[MSYS2]: https://msys2.github.io/
[GNUInstallDirs]: https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html
21 changes: 21 additions & 0 deletions cmake/PackageDeb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(CPACK_SET_DESTDIR "on")
set(CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
set(CPACK_GENERATOR "DEB")
set(CPACK_STRIP_FILES ON)

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Attract-Mode emulator frontend")
set(CPACK_PACKAGE_VENDOR "Andrew Mickelson")
set(CPACK_PACKAGE_CONTACT "[email protected]")

set(CPACK_PACKAGE_VERSION_MAJOR "${VER_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VER_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VER_PATCH}")

set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")

set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}-${VER_COUNT}_${CMAKE_SYSTEM_PROCESSOR}")

include(CPack)

Loading