Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
(conan-io#21782) sdl_mixer: add v2.8.0 as a new subdir
Browse files Browse the repository at this point in the history
* sdl_mixer: add v2.6.3 as a new subdir

* sdl_mixer: fix license install

* sdl_mixer: remove unnecessary install dirs

* sdl-mixer: add GitHub URL

* sdl-mixer: set SDL2MIXER_DEBUG_POSTFIX

* sdl_mixer: fix typo

Co-authored-by: Johnny Jazeix <be__good@hotmail.com>

* sdl_mixer: fix typo in .set_property()

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* sdl_mixer: use a more specific include

* sdl_mixer: add a -static CMake target alias

* sdl_mixer: rmdir cmake

* sdl_mixer: fix MSVC static lib name

* sdl_mixer: bump to v2.8.0

* sdl_mixer: drmp3 has been replaced with minimp3

* sdl_mixer: update options

* sdl_mixer: disable debug postfix

* sdl_mixer: add missing frameworks

* sdl_mixer: review changes

* sdl_mixer: revert flac version bump

---------

Co-authored-by: Johnny Jazeix <be__good@hotmail.com>
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
  • Loading branch information
3 people authored and ericLemanissier committed Apr 16, 2024
1 parent 06273f0 commit 305a0ff
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 0 deletions.
6 changes: 6 additions & 0 deletions recipes/sdl_mixer/cmake/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sources:
"2.8.0":
url:
- "https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.8.0/SDL2_mixer-2.8.0.tar.gz"
- "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.8.0.tar.gz"
sha256: "1cfb34c87b26dbdbc7afd68c4f545c0116ab5f90bbfecc5aebe2a9cb4bb31549"
250 changes: 250 additions & 0 deletions recipes/sdl_mixer/cmake/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.57.0"


class SDLMixerConan(ConanFile):
name = "sdl_mixer"
description = "SDL_mixer is a sample multi-channel audio mixer library"
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libsdl.org/projects/SDL_mixer/"
topics = ("sdl2", "sdl", "mixer", "audio", "multimedia", "sound", "music")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"cmd": [True, False],
"wav": [True, False],
"flac": [True, False],
"gme": [True, False],
"minimp3": [True, False],
"mpg123": [True, False],
"opus": [True, False],
"modplug": [True, False],
"fluidsynth": [True, False],
"nativemidi": [True, False],
"tinymidi": [True, False],
"vorbis": [False, "vorbisfile", "tremor", "stb"],
"wavpack": [True, False],
"xmp": [False, "libxmp", "libxmp-lite"],
}
default_options = {
"shared": False,
"fPIC": True,
"cmd": False,
"wav": True,
"flac": True,
"gme": False,
"minimp3": False,
"mpg123": True,
"opus": True,
"modplug": True,
"fluidsynth": False,
"nativemidi": True,
"tinymidi": True,
"vorbis": "stb",
"wavpack": False,
"xmp": False
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os not in ["Linux", "FreeBSD"]:
del self.options.tinymidi
if not (self.settings.os == "Windows" or is_apple_os(self)):
del self.options.nativemidi

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("sdl/2.28.5", transitive_headers=True, transitive_libs=True)
if self.options.flac:
self.requires("flac/1.4.2")
elif self.options.gme:
# TODO: not available on CCI
self.requires("gme/x.y.z")
if self.options.mpg123:
self.requires("mpg123/1.31.2")
if self.options.minimp3:
self.requires("minimp3/cci.20211201")
if self.options.vorbis == "stb":
self.requires("stb/cci.20230920")
elif self.options.vorbis == "vorbisfile":
self.requires("vorbis/1.3.7")
elif self.options.vorbis == "tremor":
# TODO: not available on CCI
self.requires("tremor/1.2.1")
if self.options.opus:
self.requires("opusfile/0.12")
if self.options.modplug:
self.requires("libmodplug/0.8.9.0")
if self.options.xmp == "libxmp":
# TODO: not available on CCI
self.requires("libxmp/x.y.z")
elif self.options.xmp == "libxmp-lite":
# TODO: not available on CCI
self.requires("libxmp-lite/x.y.z")
if self.options.fluidsynth:
# TODO: not available on CCI
self.requires("fluidsynth/2.2")
if self.options.get_safe("tinymidi"):
self.requires("tinymidi/cci.20130325")
# https://github.com/libsdl-org/SDL_mixer/blob/release-2.6.3/CMakeLists.txt#L148-L162
if self.options.vorbis or self.options.flac or self.options.opus:
self.requires("ogg/1.3.5")
if self.options.wavpack:
# TODO: not available on CCI
self.requires("wavpack/x.y.z")

def build_requirements(self):
self.tool_requires("cmake/[>=3.16 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
rmdir(self, os.path.join(self.source_folder, "external"))

def generate(self):
tc = CMakeToolchain(self)
# Disable debug postfix as it's not relevant to single-configuration Conan builds
# and will be removed in v3.0 anyway.
tc.variables["SDL2MIXER_DEBUG_POSTFIX"] = ""
tc.variables["SDL2MIXER_VENDORED"] = False
tc.variables["SDL2MIXER_SAMPLES"] = False
tc.variables["SDL2MIXER_CMD"] = self.options.cmd
# WAVE
tc.variables["SDL2MIXER_WAVE"] = self.options.wav
# FLAC
tc.variables["SDL2MIXER_FLAC"] = self.options.flac
# GME
tc.variables["SDL2MIXER_GME"] = self.options.gme
# MOD
tc.variables["SDL2MIXER_MOD"] = self.options.modplug or bool(self.options.xmp)
tc.variables["SDL2MIXER_MOD_MODPLUG"] = self.options.modplug
tc.variables["SDL2MIXER_MOD_XMP"] = self.options.xmp == "libxmp"
tc.variables["SDL2MIXER_MOD_XMP_LITE"] = self.options.xmp == "libxmp-lite"
# MP3
tc.variables["SDL2MIXER_MP3"] = self.options.mpg123 or self.options.minimp3
tc.variables["SDL2MIXER_MP3_MPG123"] = self.options.mpg123
tc.variables["SDL2MIXER_MP3_MINIMP3"] = self.options.minimp3
# MIDI
tc.variables["SDL2MIXER_MIDI"] = self.options.get_safe("nativemidi", False) or self.options.get_safe("tinymidi", False) or self.options.fluidsynth
tc.variables["SDL2MIXER_MIDI_FLUIDSYNTH"] = self.options.fluidsynth
tc.variables["SDL2MIXER_MIDI_TIMIDITY"] = self.options.get_safe("tinymidi", False)
tc.variables["SDL2MIXER_MIDI_NATIVE"] = self.options.get_safe("nativemidi", False)
# OPUS
tc.variables["SDL2MIXER_OPUS"] = self.options.opus
# VORBIS
if self.options.vorbis == "stb":
tc.variables["SDL2MIXER_VORBIS"] = "STB"
elif self.options.vorbis == "vorbisfile":
tc.variables["SDL2MIXER_VORBIS"] = "VORBISFILE"
elif self.options.vorbis == "tremor":
tc.variables["SDL2MIXER_VORBIS"] = "TREMOR"
else:
tc.variables["SDL2MIXER_VORBIS"] = False
# WavPack
tc.variables["SDL2MIXER_WAVPACK"] = self.options.wavpack

# TODO: add support for dynamic loading of dependencies
tc.variables["SDL2MIXER_DEPS_SHARED"] = False
tc.variables["SDL2MIXER_FLAC_LIBFLAC_SHARED"] = False
tc.variables["SDL2MIXER_GME_SHARED"] = False
tc.variables["SDL2MIXER_MIDI_FLUIDSYNTH_SHARED"] = False
tc.variables["SDL2MIXER_MIDI_TIMIDITY_SHARED"] = False
tc.variables["SDL2MIXER_MOD_MODPLUG_SHARED"] = False
tc.variables["SDL2MIXER_MOD_XMP_SHARED"] = False
tc.variables["SDL2MIXER_MP3_MPG123_SHARED"] = False
tc.variables["SDL2MIXER_OGG_SHARED"] = False
tc.variables["SDL2MIXER_OPUS_SHARED"] = False
tc.variables["SDL2MIXER_SNDFILE_SHARED"] = False
tc.variables["SDL2MIXER_VORBIS_TREMOR_SHARED"] = False
tc.variables["SDL2MIXER_VORBIS_VORBISFILE_SHARED"] = False
tc.variables["SDL2MIXER_WAVPACK_SHARED"] = False
tc.generate()

deps = CMakeDeps(self)
deps.set_property("flac", "cmake_file_name", "FLAC")
deps.set_property("flac", "cmake_target_name", "FLAC::FLAC")
deps.set_property("fluidsynth", "cmake_file_name", "FluidSynth")
deps.set_property("fluidsynth", "cmake_target_name", "FluidSynth::libfluidsynth")
deps.set_property("gme", "cmake_file_name", "gme")
deps.set_property("gme", "cmake_target_name", "gme::gme")
deps.set_property("libxmp", "cmake_file_name", "libxmp")
deps.set_property("libxmp", "cmake_target_name", "libxmp::libxmp")
deps.set_property("libxmp-lite", "cmake_file_name", "libxmp-lite")
deps.set_property("libxmp-lite", "cmake_target_name", "libxmp-lite::libxmp-lite")
deps.set_property("libmodplug", "cmake_file_name", "modplug")
deps.set_property("libmodplug", "cmake_target_name", "modplug::modplug")
deps.set_property("mpg123", "cmake_file_name", "mpg123")
deps.set_property("mpg123", "cmake_target_name", "MPG123::libmpg123")
deps.set_property("opusfile", "cmake_file_name", "OpusFile")
deps.set_property("opusfile", "cmake_target_name", "OpusFile::opusfile")
deps.set_property("tremor", "cmake_file_name", "tremor")
deps.set_property("tremor", "cmake_target_name", "tremor::tremor")
deps.set_property("vorbis", "cmake_file_name", "Vorbis")
deps.set_property("vorbis::vorbisfile", "cmake_target_name", "Vorbis::vorbisfile")
deps.set_property("wavpack", "cmake_file_name", "wavpack")
deps.set_property("wavpack", "cmake_target_name", "WavPack::WavPack")

deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "SDL2_mixer")
self.cpp_info.set_property("cmake_target_name", "SDL2_mixer::SDL2_mixer")
# https://github.com/libsdl-org/SDL_mixer/blob/release-2.6.3/CMakeLists.txt#L164-L172
if not self.options.shared:
self.cpp_info.set_property("cmake_target_aliases", ["SDL2_mixer::SDL2_mixer-static"])
# The project only creates a pkg-config file for a shared lib, but add it for static as well, unofficially
# https://github.com/libsdl-org/SDL_mixer/blob/release-2.6.3/CMakeLists.txt#L828
self.cpp_info.set_property("pkg_config_name", "SDL2_mixer")

if is_msvc(self) and not self.options.shared:
self.cpp_info.libs = ["SDL2_mixer-static"]
else:
self.cpp_info.libs = ["SDL2_mixer"]
self.cpp_info.includedirs.append(os.path.join("include", "SDL2"))
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
if self.settings.os == "Windows":
if self.options.nativemidi:
self.cpp_info.system_libs.append("winmm")
elif is_apple_os(self):
self.cpp_info.frameworks.extend(["AudioToolbox", "AudioUnit", "CoreServices", "CoreGraphics", "CoreFoundation"])
if self.settings.os == "Macos":
self.cpp_info.frameworks.append("AppKit")

self.cpp_info.names["cmake_find_package"] = "SDL2_mixer"
self.cpp_info.names["cmake_find_package_multi"] = "SDL2_mixer"
7 changes: 7 additions & 0 deletions recipes/sdl_mixer/cmake/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(SDL2_mixer REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_mixer::SDL2_mixer)
26 changes: 26 additions & 0 deletions recipes/sdl_mixer/cmake/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
43 changes: 43 additions & 0 deletions recipes/sdl_mixer/cmake/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int audio_rate = MIX_DEFAULT_FREQUENCY;
int audio_format = MIX_DEFAULT_FORMAT;
int audio_channels = 2;
const SDL_version * version = Mix_Linked_Version();
printf("%s", "SDL2_mixer version: ");
printf("%d.", (int)(version->major));
printf("%d.", (int)(version->minor));
printf("%d\n", (int)(version->patch));

if (SDL_Init(SDL_INIT_AUDIO) == 0) {
int initted = Mix_Init(MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG | MIX_INIT_MID | MIX_INIT_OPUS);
printf("%s %s\n", "Supported MIX_INIT_MOD: " , (initted & MIX_INIT_MOD ? "Yes" : "No"));
printf("%s %s\n", "Supported MIX_INIT_MP3: " , (initted & MIX_INIT_MP3 ? "Yes" : "No"));
printf("%s %s\n", "Supported MIX_INIT_OGG: " , (initted & MIX_INIT_OGG ? "Yes" : "No"));
printf("%s %s\n", "Supported MIX_INIT_FLAC: ", (initted & MIX_INIT_FLAC ? "Yes" : "No"));
printf("%s %s\n", "Supported MIX_INIT_MID: " , (initted & MIX_INIT_MID ? "Yes" : "No"));
printf("%s %s\n", "Supported MIX_INIT_OPUS: ", (initted & MIX_INIT_OPUS ? "Yes" : "No"));

if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) == 0) {
int num_chunk_decoders = Mix_GetNumChunkDecoders();
int num_music_decoders = Mix_GetNumMusicDecoders();
int i = 0;
printf("%s\n", "chunk decoders:");
for (i = 0; i < num_chunk_decoders; ++i)
printf("\t%s\n", Mix_GetChunkDecoder(i));
printf("%s\n", "music decoders:");
for (i = 0; i < num_music_decoders; ++i)
printf("\t%s\n", Mix_GetMusicDecoder(i));
Mix_CloseAudio();
Mix_Quit();
}
}

return 0;
}
8 changes: 8 additions & 0 deletions recipes/sdl_mixer/cmake/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/sdl_mixer/cmake/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/sdl_mixer/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"2.8.0":
folder: "cmake"
"2.0.4":
folder: "all"

0 comments on commit 305a0ff

Please sign in to comment.