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

sdl_mixer: add v2.8.0 as a new subdir #21782

Merged
merged 21 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6.3":
url:
- "https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.6.3/SDL2_mixer-2.6.3.tar.gz"
- "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.6.3.tar.gz"
sha256: "7a6ba86a478648ce617e3a5e9277181bc67f7ce9876605eea6affd4a0d6eea8f"
212 changes: 212 additions & 0 deletions recipes/sdl_mixer/cmake/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import os
valgur marked this conversation as resolved.
Show resolved Hide resolved

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.scm import Version

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],
"mpg123": [True, False],
"drmp3": [True, False],
"opus": [True, False],
"modplug": [True, False],
"fluidsynth": [True, False],
"nativemidi": [True, False],
"tinymidi": [True, False],
"vorbis": [False, "vorbisfile", "tremor", "stb"],
}
default_options = {
"shared": False,
"fPIC": True,
"cmd": False,
"wav": True,
"flac": True,
"mpg123": True,
"drmp3": True,
"opus": True,
"modplug": True,
"fluidsynth": False,
"nativemidi": True,
"tinymidi": True,
"vorbis": "stb",
}

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")
if self.options.mpg123:
self.requires("mpg123/1.31.2")
if self.options.drmp3:
self.requires("drmp3/0.6.34")
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.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")

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)
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.cache_variables["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
valgur marked this conversation as resolved.
Show resolved Hide resolved
if Version(self.version) <= "2.6.3":
tc.cache_variables["SDL2MIXER_DEBUG_POSTFIX"] = ""
valgur marked this conversation as resolved.
Show resolved Hide resolved
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
# MOD
tc.variables["SDL2MIXER_MOD"] = self.options.modplug
# MP3
tc.variables["SDL2MIXER_MP3"] = self.options.mpg123 or self.options.drmp3
tc.variables["SDL2MIXER_MP3_MPG123"] = self.options.mpg123
tc.variables["SDL2MIXER_MP3_DRMP3"] = self.options.drmp3
# 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

# TODO: add support for dynamic loading of dependencies
valgur marked this conversation as resolved.
Show resolved Hide resolved
tc.variables["SDL2MIXER_DEPS_SHARED"] = False
tc.variables["SDL2MIXER_FLAC_LIBFLAC_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.generate()

deps = CMakeDeps(self)
deps.set_property("flac", "cmake_file_name", "FLAC")
deps.set_property("flac", "cmake_target_name", "FLAC")
deps.set_property("fluidsynth", "cmake_file_name", "FluidSynth")
deps.set_property("fluidsynth", "cmake_target_name", "FluidSynth::FluidSynth")
deps.set_property("libxmp", "cmake_file_name", "libxmp")
deps.set_property("libxmp", "cmake_target_name", "libxmp::libxmp")
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::mpg123")
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", "vorbisfile")
deps.set_property("vorbis::vorbisfile", "cmake_target_name", "vorbisfile::vorbisfile")

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"))
valgur marked this conversation as resolved.
Show resolved Hide resolved
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "SDL2_mixer")
valgur marked this conversation as resolved.
Show resolved Hide resolved
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")

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"])

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_v1_package are no longer necessary, it is better to not add them, specially for new recipes (this under cmake is a new recipe)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change it now, but just FYI. Less is more, specially when the backlog in ConanCenter is so big.

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.6.3":
folder: "cmake"
"2.0.4":
folder: "all"