Skip to content

Commit

Permalink
cmake build support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Clark committed May 4, 2016
1 parent 9262366 commit 5ee7efc
Show file tree
Hide file tree
Showing 42 changed files with 1,828 additions and 44 deletions.
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
131 changes: 131 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
cmake_minimum_required(VERSION 2.9 FATAL_ERROR)

set(FE_VERSION "v2.0.0")

project(attract)

# Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "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)

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_NET "Disable network scraper support" OFF)
option(NO_SWF "Disable SWF support (gameswf)" OFF)
option(USE_FONTCONFIG "FontConfig support" ON)
option(USE_LIBARCHIVE "Archive library support" ON)
option(USE_XINERAMA "Xinerama support" ON)
option(USE_GLES "GLES instead of GL" OFF)
option(FE_DEBUG "Debug" OFF)
option(FE_RPI "Build for Raspberry PI" OFF)

if(FE_RPI)
set(USE_GLES ON)
endif()

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

if(USE_XINERAMA AND NOT WIN32 AND NOT APPLE)
find_package(Xinerama)
endif()
set(USE_XINERAMA ${XINERAMA_FOUND})

if(USE_LIBARCHIVE)
find_package(LibArchive)
endif()
set(USE_LIBARCHIVE ${LibArchive_Found})

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

#### 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_POINT)
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(USE_FONTCONFIG)
find_package(EXPAT REQUIRED)
endif()

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

#### END: Dependencies ####

#### BEGIN: Misc ####

# If ARM, assume GLES
if(NOT FE_RPI AND "${CMAKE_TARGET_ARCHITECTURES}" MATCHES "arm")
set(USE_GLES ON)
set(FE_RPI ON)
message(STATUS "ARM detected: FE_RPI and USE_GLES set")
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})
82 changes: 55 additions & 27 deletions Compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@ distributions. Other distributions should have similar packages available.

1. Install the following libraries and related headers on your system:
* Required:
- SFML SDK version 2.x (<http://sfml-dev.org>)
- OpenAL
- zlib
- FreeType 2
- The following FFmpeg libraries (required for videos): avformat,
- [cmake] 2.9+
- [SFML] SDK version 2.x
- [OpenAL]
- [zlib]
- [FreeType] 2
- The following [FFmpeg] libraries (required for videos): avformat,
avcodec, swscale, avutil and either swresample or avresample.
* Optional:
- Fontconfig (to assist with finding fonts).
- Xinerama (for multiple monitor support).
- libarchive (for .7z, .rar, .tar.gz and .tar.bz2 archive support).
- [Fontconfig] (to assist with finding fonts).
- [Xinerama] (for multiple monitor support).
- [libarchive] (for .7z, .rar, .tar.gz and .tar.bz2 archive support).

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

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

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 -j 3 USE_GLES=1
cmake -DUSE_GLES=ON ..

This step will create the "attract" executable file.

Expand All @@ -52,19 +56,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: The 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 @@ -78,6 +85,9 @@ These instructions assume that you have X Code installed.

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

mkdir build
cd build
cmake ..
make -j 3

This step will create the "attract" executable file.
Expand All @@ -100,11 +110,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 and libarchive packages:

Expand All @@ -113,17 +121,21 @@ OS X.
the above command will make 32-bit versions of ffmpeg and sfml (and anything
else that they depend on). To make the 64-bit version use the following:

make MXE_TARGETS='x86_64-w64-mingw32.static' ffmpeg sfml
make MXE_TARGETS='x86_64-w64-mingw32.static' ffmpeg sfml libarchive

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

4. From the directory you extracted the source into, run the following:

make -j 3 CROSS=1 TOOLCHAIN=i686-w64-mingw32.static WINDOWS_STATIC=1
mkdir build
cd build
i686-w64-mingw32.static-cmake ..
make -j 3

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

make -j 3 CROSS=1 TOOLCHAIN=x86_64-w64-mingw32.static WINDOWS_STATIC=1
x86_64-w64-mingw32.static-cmake .. && make -j3
make -j 3

This step will create the "attract.exe" executable file.

Expand All @@ -134,8 +146,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 @@ -148,15 +159,32 @@ Windows (native compile):
4. Install required packaged. (optionally use the mingw-w64-i686-toolchain
instead for 32-bit windows architectures):

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
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/
[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
Loading

0 comments on commit 5ee7efc

Please sign in to comment.