Skip to content
Permalink
Browse files

cmake: auto-detect sfml, ffmpeg and openal

In cmake detect if the dependencies for link (sfml), recording (ffmpeg)
and openal are installed and default the features to `ON` if they are,
otherwise to `OFF`.

This simplifies the cmake usage.

Update the default column in the `README.md` table to `AUTO` as well.

Remove the cmake options from `installdeps` instructions, since they are
auto-detected.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
  • Loading branch information
rkitover committed Aug 20, 2019
1 parent c64dd25 commit d9a7e0c964c58e32c9248125c6b969b356e13afe
Showing with 60 additions and 48 deletions.
  1. +30 −19 CMakeLists.txt
  2. +3 −3 README.md
  3. +6 −14 installdeps
  4. +21 −12 src/wx/CMakeLists.txt
@@ -98,14 +98,40 @@ if(ENABLE_ASM_SCALERS)
option(ENABLE_MMX "Enable MMX" ${MMX_DEFAULT})
endif()

option(ENABLE_LINK "Enable GBA linking functionality" ON)
set(ENABLE_LINK_DEFAULT OFF)

# msys2 does not have static sfml libs atm
# while on mxe we use static libs
if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
set(SFML_STATIC_LIBRARIES TRUE)
endif()

find_package(SFML 2 COMPONENTS network system)

if(SFML_FOUND)
set(ENABLE_LINK_DEFAULT ON)
endif()

option(ENABLE_LINK "Enable GBA linking functionality" ${ENABLE_LINK_DEFAULT})

option(ENABLE_LIRC "Enable LIRC support" OFF)

# currently completely broken
set(FFMPEG_DEFAULT OFF)

if(WIN32 AND NOT (MINGW AND MSYS))
set(FFMPEG_DEFAULT OFF)
find_package(PkgConfig)

if(PKGCONFIG_FOUND)
set(FFMPEG_DEFAULT ON)

foreach(ffmpeg_lib libavcodec libavformat libswscale libavutil libswresample)
unset(FFMPEG_LIB)
pkg_check_modules(FFMPEG_LIB ${ffmpeg_lib})

if(NOT FFMPEG_LIB_FOUND)
set(FFMPEG_DEFAULT OFF)
break()
endif()
endforeach()
endif()

option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})
@@ -250,21 +276,6 @@ if(WIN32)
endif()
endif()

if(ENABLE_LINK)
# msys2 does not have static sfml libs atm
# while on mxe we use static libs
if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
set(SFML_STATIC_LIBRARIES TRUE)
endif()

find_package(SFML 2 COMPONENTS network system)

if(NOT SFML_FOUND)
message(WARNING "SFML not found, LINK will be disabled")
set(ENABLE_LINK NO)
endif()
endif()

# set the standard libraries all ports use
set(
VBAMCORE_LIBS
@@ -182,15 +182,15 @@ Here is the complete list:
| ENABLE_ASM | Enable the following two ASM options | ON for 32 bit builds |
| ENABLE_ASM_SCALERS | Enable x86 ASM graphic filters | ON for 32 bit builds |
| ENABLE_MMX | Enable MMX | ON for 32 bit builds |
| ENABLE_LINK | Enable GBA linking functionality (requires SFML) | ON |
| ENABLE_LINK | Enable GBA linking functionality (requires SFML) | AUTO |
| ENABLE_LIRC | Enable LIRC support | OFF |
| ENABLE_FFMPEG | Enable ffmpeg A/V recording | OFF |
| ENABLE_FFMPEG | Enable ffmpeg A/V recording | AUTO |
| ENABLE_ONLINEUPDATES | Enable online update checks | ON |
| ENABLE_LTO | Compile with Link Time Optimization (gcc and clang only) | ON for release build |
| ENABLE_GBA_LOGGING | Enable extended GBA logging | ON |
| ENABLE_DIRECT3D | Direct3D rendering for wxWidgets (Windows, **NOT IMPLEMENTED!!!**) | ON |
| ENABLE_XAUDIO2 | Enable xaudio2 sound output for wxWidgets (Windows only) | ON |
| ENABLE_OPENAL | Enable OpenAL for the wxWidgets port | OFF |
| ENABLE_OPENAL | Enable OpenAL for the wxWidgets port | AUTO |
| ENABLE_SSP | Enable gcc stack protector support (gcc only) | OFF |
| ENABLE_ASAN | Enable libasan sanitizers (by default address, only in debug mode) | OFF |
| VBAM_STATIC | Try link all libs statically (the following are set to ON if ON) | OFF |
@@ -419,7 +419,6 @@ fedora_installdeps() {
if [ $tries -eq 0 ]; then
warning 'installing rpmfusion repos failed, continuing without ffmpeg'
no_ffmpeg=1
cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO"
fi

# non-multiarch packages first
@@ -517,11 +516,11 @@ fedora_installdeps() {
case "$target" in
mingw-w64-i686)
target=mingw32
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake"
;;
mingw-w64-x86_64)
target=mingw64
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake"
;;
*)
error 'unknown cross target (this should not happen)'
@@ -543,7 +542,6 @@ fedora_installdeps() {

if ! rpm -q $ffmpeg >/dev/null 2>&1; then
warning 'ffmpeg failed to install (probably due to conflicts)'
cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO"
fi

[ -n "$warning" ] && warning "$warning"
@@ -598,7 +596,6 @@ rhel_installdeps() {
if [ $tries -eq 0 ]; then
warning 'installing rpmfusion repos failed, continuing without ffmpeg'
no_ffmpeg=1
cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO"
fi

# non-multiarch packages first
@@ -625,7 +622,6 @@ rhel_installdeps() {
fi

warning='RHEL does not currently have SFML packages, LINK support will be disabled'
cmake_flags="$cmake_flags -DENABLE_LINK=NO"

for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel libpng-devel SDL2-devel openal-soft-devel wxGTK3-devel gtk3-devel; do
case $pkg in
@@ -701,11 +697,11 @@ rhel_installdeps() {
case "$target" in
mingw-w64-i686)
target=mingw32
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake"
;;
mingw-w64-x86_64)
target=mingw64
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake"
;;
*)
error 'unknown cross target (this should not happen)'
@@ -727,7 +723,6 @@ rhel_installdeps() {

if ! rpm -q $ffmpeg >/dev/null 2>&1; then
warning 'ffmpeg failed to install (probably due to conflicts)'
cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO"
fi

[ -n "$warning" ] && warning "$warning"
@@ -751,7 +746,6 @@ gcc gcc-c++ libpng16-devel libSDL2-devel openal-soft-devel wxWidgets-3_0-devel\

if [ "$target" = m32 ]; then
libs=$(echo "$libs" | sed -E 's/([^ ]) ([^ ])/\1-32bit \2/g; s/$/-32bit/;')
cmake_flags="$cmake_flags -DENABLE_LINK=NO"
fi

check sudo zypper in -y $tools $libs
@@ -841,10 +835,10 @@ EOF
# windows cross build
case "$target" in
*i686*)
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake"
;;
*x86_64*)
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake -DENABLE_LINK=NO"
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake"
;;
*)
# this will never be reached, it's checked in check_cross()
@@ -972,8 +966,6 @@ solus_installdeps() {
if [ -n "$amd64" -a "$target" = m32 ]; then
warning 'SFML is required for LINK support, there is no 32 bit SFML package in Solus currently, if you want LINK support you will need to install it manually'
warning 'ffmpeg is required for game recording, there is no 32 bit ffmpeg package in Solus currently, you may wish to install it manually'

cmake_flags="$cmake_flags -DENABLE_LINK=NO -DENABLE_FFMPEG=NO"
fi

build_instructions
@@ -28,7 +28,27 @@ endif()

option(ENABLE_FAUDIO "Enable FAudio sound output for the wxWidgets port" OFF)

option(ENABLE_OPENAL "Enable OpenAL for the wxWidgets port" OFF)
find_package(OpenAL)

if(OPENAL_FOUND)
set(ENABLE_OPENAL_DEFAULT ON)
else()
set(ENABLE_OPENAL_DEFAULT OFF)
endif()

option(ENABLE_OPENAL "Enable OpenAL for the wxWidgets port" ${ENABLE_OPENAL_DEFAULT})

if(ENABLE_OPENAL)
find_package(OpenAL REQUIRED)

include_directories(${OPENAL_INCLUDE_DIR})

if(OPENAL_STATIC OR (WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)))
add_definitions(-DAL_LIBTYPE_STATIC)
endif()
else()
add_definitions(-DNO_OAL)
endif()

if(APPLE)
add_definitions(-DwxMAC_USE_CORE_GRAPHICS)
@@ -46,17 +66,6 @@ if(NOT ENABLE_DIRECT3D)
add_definitions(-DNO_D3D)
endif()

if(ENABLE_OPENAL)
find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})

if(OPENAL_STATIC OR (WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)))
add_definitions(-DAL_LIBTYPE_STATIC)
endif()
else(ENABLE_OPENAL)
add_definitions(-DNO_OAL)
endif()

unset(FAUDIO_LIBS)
if(ENABLE_FAUDIO)
find_package(FAudio REQUIRED)

0 comments on commit d9a7e0c

Please sign in to comment.
You can’t perform that action at this time.