Skip to content

Commit

Permalink
Support Sf2 Player, Mallets, PortAudio, and Lame with MSVC (#6507)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomClark authored Sep 19, 2022
1 parent 0b27497 commit 5bfd7fb
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 249 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ jobs:
set-env: ${{ matrix.arch == 'x86' }}
- name: Install dependencies
run: |
vcpkg install --triplet ${{ matrix.arch }}-windows --recurse `
fftw3 libsamplerate libsndfile lilv lv2 sdl2
vcpkg install `
--triplet=${{ matrix.arch }}-windows `
--host-triplet=${{ matrix.arch }}-windows `
--recurse `
fftw3 fluidsynth[sndfile] libsamplerate libsndfile libstk lilv lv2 `
portaudio sdl2
- name: Set up build environment
uses: ilammy/msvc-dev-cmd@d8610e2b41c6d0f0c3b4c46dad8df0fd826c68e1
with:
Expand Down
35 changes: 17 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ ENDIF(COMMAND CMAKE_POLICY)
# Import of windows.h breaks min()/max()
ADD_DEFINITIONS(-DNOMINMAX)

# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is not set correctly for MinGW until
# CMake 3.14.1, so avoid specifying system include directories on affected
# versions. Normal include directories are safe, since GCC ignores them if they
# are already in the built-in search path.
if(MINGW AND CMAKE_VERSION VERSION_LESS "3.14.1")
set(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE)
endif()

INCLUDE(PluginList)
INCLUDE(CheckSubmodules)
INCLUDE(AddFileDependencies)
Expand Down Expand Up @@ -110,6 +118,7 @@ IF(LMMS_BUILD_WIN32)
SET(STATUS_ALSA "<not supported on this platform>")
SET(STATUS_PULSEAUDIO "<not supported on this platform>")
SET(STATUS_SOUNDIO "<disabled in this release>")
SET(STATUS_SNDIO "<not supported on this platform>")
SET(STATUS_WINMM "OK")
SET(STATUS_APPLEMIDI "<not supported on this platform>")
ELSE(LMMS_BUILD_WIN32)
Expand Down Expand Up @@ -297,17 +306,7 @@ ENDIF(WANT_CARLA)

# check for SDL2
IF(WANT_SDL)
# Don't look for SDL2main
SET(SDL2_BUILDING_LIBRARY TRUE)

# Search for SDL2 using config mode first, then fall back to module mode.
# This allows us to use SDL2's own CMake configuration files if available.
FIND_PACKAGE(SDL2 CONFIG QUIET)
IF(NOT TARGET SDL2::SDL2)
UNSET(SDL2_FOUND)
FIND_PACKAGE(SDL2 MODULE)
ENDIF()

FIND_PACKAGE(SDL2)
IF(SDL2_FOUND)
SET(LMMS_HAVE_SDL TRUE)
SET(LMMS_HAVE_SDL2 TRUE)
Expand Down Expand Up @@ -358,13 +357,13 @@ ENDIF(WANT_STK)
# check for PortAudio
IF(WANT_PORTAUDIO)
FIND_PACKAGE(Portaudio)
IF(PORTAUDIO_FOUND)
IF(Portaudio_FOUND)
SET(LMMS_HAVE_PORTAUDIO TRUE)
SET(STATUS_PORTAUDIO "OK")
ELSE(PORTAUDIO_FOUND)
ELSE()
SET(STATUS_PORTAUDIO "not found, please install portaudio19-dev (or similar, version >= 1.9) "
"if you require PortAudio support")
ENDIF(PORTAUDIO_FOUND)
ENDIF()
ENDIF(WANT_PORTAUDIO)

# check for libsoundio
Expand Down Expand Up @@ -496,14 +495,14 @@ ENDIF()

# check for Fluidsynth
IF(WANT_SF2)
PKG_CHECK_MODULES(FLUIDSYNTH fluidsynth>=1.0.7)
IF(FLUIDSYNTH_FOUND)
find_package(FluidSynth 1.0.7)
if(FluidSynth_FOUND)
SET(LMMS_HAVE_FLUIDSYNTH TRUE)
SET(STATUS_FLUIDSYNTH "OK")
ELSE(FLUIDSYNTH_FOUND)
else()
SET(STATUS_FLUIDSYNTH "not found, libfluidsynth-dev (or similar)"
"is highly recommended")
ENDIF(FLUIDSYNTH_FOUND)
endif()
ENDIF(WANT_SF2)

# check for libgig
Expand Down
73 changes: 73 additions & 0 deletions cmake/modules/FindFluidSynth.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2022 Dominic Clark
#
# Redistribution and use is allowed according to the terms of the New BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# Return if we already have FluidSynth
if(TARGET fluidsynth)
set(FluidSynth_FOUND 1)
return()
endif()

# Attempt to find FluidSynth using PkgConfig
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(FLUIDSYNTH_PKG fluidsynth)
endif()

# Find the library and headers using the results from PkgConfig as a guide
find_path(FluidSynth_INCLUDE_DIR
NAMES "fluidsynth.h"
HINTS ${FLUIDSYNTH_PKG_INCLUDE_DIRS}
)

find_library(FluidSynth_LIBRARY
NAMES "fluidsynth"
HINTS ${FLUIDSYNTH_PKG_LIBRARY_DIRS}
)

if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY)
add_library(fluidsynth UNKNOWN IMPORTED)
set_target_properties(fluidsynth PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FluidSynth_INCLUDE_DIR}"
)

if(VCPKG_INSTALLED_DIR)
include(ImportedTargetHelpers)
_get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}")
else()
set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}")
endif()

if(FluidSynth_IMPLIB_DEBUG)
set_target_properties(fluidsynth PROPERTIES
IMPORTED_LOCATION_RELEASE "${FluidSynth_IMPLIB_RELEASE}"
IMPORTED_LOCATION_DEBUG "${FluidSynth_IMPLIB_DEBUG}"
)
else()
set_target_properties(fluidsynth PROPERTIES
IMPORTED_LOCATION "${FluidSynth_IMPLIB_RELEASE}"
)
endif()

if(EXISTS "${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h")
file(STRINGS
"${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h"
_version_string
REGEX "^#[\t ]*define[\t ]+FLUIDSYNTH_VERSION[\t ]+\".*\""
)
string(REGEX REPLACE
"^.*FLUIDSYNTH_VERSION[\t ]+\"([^\"]*)\".*$"
"\\1"
FluidSynth_VERSION_STRING
"${_version_string}"
)
unset(_version_string)
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FluidSynth
REQUIRED_VARS FluidSynth_LIBRARY FluidSynth_INCLUDE_DIR
VERSION_VAR FluidSynth_VERSION_STRING
)
39 changes: 30 additions & 9 deletions cmake/modules/FindLame.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# - Try to find LAME
# Once done this will define
#
# LAME_FOUND - system has liblame
# LAME_INCLUDE_DIRS - the liblame include directory
# LAME_LIBRARIES - The liblame libraries
# Lame_FOUND - system has liblame
# Lame_INCLUDE_DIRS - the liblame include directory
# Lame_LIBRARIES - The liblame libraries
# mp3lame::mp3lame - an imported target providing lame

find_path(LAME_INCLUDE_DIRS lame/lame.h)
find_library(LAME_LIBRARIES mp3lame)
find_package(mp3lame CONFIG QUIET)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES)
if(TARGET mp3lame::mp3lame)
# Extract details for find_package_handle_standard_args
get_target_property(Lame_LIBRARIES mp3lame::mp3lame LOCATION)
get_target_property(Lame_INCLUDE_DIRS mp3lame::mp3lame INTERFACE_INCLUDE_DIRECTORIES)
else()
find_path(Lame_INCLUDE_DIRS lame/lame.h)
find_library(Lame_LIBRARIES mp3lame)

list(APPEND Lame_DEFINITIONS HAVE_LIBMP3LAME=1)

mark_as_advanced(Lame_INCLUDE_DIRS Lame_LIBRARIES Lame_DEFINITIONS)

list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1)
if(Lame_LIBRARIES AND Lame_INCLUDE_DIRS)
add_library(mp3lame::mp3lame UNKNOWN IMPORTED)

mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS)
set_target_properties(mp3lame::mp3lame PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Lame_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${Lame_DEFINITIONS}"
IMPORTED_LOCATION "${Lame_LIBRARIES}"
)
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lame
REQUIRED_VARS Lame_LIBRARIES Lame_INCLUDE_DIRS
)
64 changes: 36 additions & 28 deletions cmake/modules/FindPortaudio.cmake
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
# - Try to find Portaudio
# Once done this will define
#
# PORTAUDIO_FOUND - system has Portaudio
# PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory
# PORTAUDIO_LIBRARIES - Link these to use Portaudio
# PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio
#
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
# Copyright (c) 2022 Dominic Clark
#
# Redistribution and use is allowed according to the terms of the New BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

# Try config mode if possible
find_package(portaudio CONFIG QUIET)

if(TARGET portaudio)
# Extract details for find_package_handle_standard_args
get_target_property(Portaudio_LIBRARY portaudio LOCATION)
get_target_property(Portaudio_INCLUDE_DIR portaudio INTERFACE_INCLUDE_DIRECTORIES)
else()
# Attempt to find PortAudio using PkgConfig, if we have it
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PORTAUDIO_PKG portaudio-2.0)
endif()

if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
# in cache already
set(PORTAUDIO_FOUND TRUE)
else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
include(FindPkgConfig)
pkg_check_modules(PORTAUDIO portaudio-2.0)
if (PORTAUDIO_FOUND)
if (NOT Portaudio_FIND_QUIETLY)
message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}")
endif (NOT Portaudio_FIND_QUIETLY)
else (PORTAUDIO_FOUND)
if (Portaudio_FIND_REQUIRED)
message(FATAL_ERROR "Could not find Portaudio")
endif (Portaudio_FIND_REQUIRED)
endif (PORTAUDIO_FOUND)
# Find the library and headers using the results from PkgConfig as a guide
find_library(Portaudio_LIBRARY
NAMES "portaudio"
HINTS ${PORTAUDIO_PKG_LIBRARY_DIRS}
)

# show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view
mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES)
find_path(Portaudio_INCLUDE_DIR
NAMES "portaudio.h"
HINTS ${PORTAUDIO_PKG_INCLUDE_DIRS}
)

endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
# Create an imported target for PortAudio if we succeeded in finding it.
if(Portaudio_LIBRARY AND Portaudio_INCLUDE_DIR)
add_library(portaudio UNKNOWN IMPORTED)
set_target_properties(portaudio PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Portaudio_INCLUDE_DIR}"
IMPORTED_LOCATION "${Portaudio_LIBRARY}"
)
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Portaudio
REQUIRED_VARS Portaudio_LIBRARY Portaudio_INCLUDE_DIR
)
Loading

0 comments on commit 5bfd7fb

Please sign in to comment.