Skip to content

Commit

Permalink
sdl_mixer: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 22, 2023
1 parent 9eabe04 commit 60c8ca2
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 147 deletions.
99 changes: 47 additions & 52 deletions recipes/sdl_mixer/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 2.8.12)
project(sdl2_mixer)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

include(CheckTypeSize)

macro(add_music_option type)
Expand Down Expand Up @@ -33,70 +30,70 @@ add_music_option(MID_TINYMIDI)
if(${MID_NATIVE})

set(NATIVE_MIDI_SOURCES
source_subfolder/native_midi/native_midi_common.c
source_subfolder/native_midi/native_midi_common.h
source_subfolder/native_midi/native_midi_haiku.cpp
source_subfolder/native_midi/native_midi_mac.c
source_subfolder/native_midi/native_midi_macosx.c
source_subfolder/native_midi/native_midi_win32.c
src/native_midi/native_midi_common.c
src/native_midi/native_midi_common.h
src/native_midi/native_midi_haiku.cpp
src/native_midi/native_midi_mac.c
src/native_midi/native_midi_macosx.c
src/native_midi/native_midi_win32.c
)

set(NATIVE_MIDI_HEADERS
source_subfolder/native_midi/native_midi.h
src/native_midi/native_midi.h
)

endif()

set(SOURCES
source_subfolder/effect_position.c
source_subfolder/effect_stereoreverse.c
source_subfolder/effects_internal.c
source_subfolder/load_aiff.c
source_subfolder/load_voc.c
source_subfolder/mixer.c
source_subfolder/music.c
source_subfolder/music_cmd.c
source_subfolder/music_flac.c
source_subfolder/music_fluidsynth.c
source_subfolder/music_mad.c
source_subfolder/music_mikmod.c
source_subfolder/music_modplug.c
source_subfolder/music_mpg123.c
source_subfolder/music_nativemidi.c
source_subfolder/music_ogg.c
source_subfolder/music_opus.c
source_subfolder/music_timidity.c
source_subfolder/music_wav.c
src/effect_position.c
src/effect_stereoreverse.c
src/effects_internal.c
src/load_aiff.c
src/load_voc.c
src/mixer.c
src/music.c
src/music_cmd.c
src/music_flac.c
src/music_fluidsynth.c
src/music_mad.c
src/music_mikmod.c
src/music_modplug.c
src/music_mpg123.c
src/music_nativemidi.c
src/music_ogg.c
src/music_opus.c
src/music_timidity.c
src/music_wav.c
${NATIVE_MIDI_SOURCES}
)

set(HEADERS
source_subfolder/effects_internal.h
source_subfolder/load_aiff.h
source_subfolder/load_voc.h
source_subfolder/mixer.h
source_subfolder/music.h
source_subfolder/music_cmd.h
source_subfolder/music_flac.h
source_subfolder/music_fluidsynth.h
source_subfolder/music_mad.h
source_subfolder/music_mikmod.h
source_subfolder/music_modplug.h
source_subfolder/music_mpg123.h
source_subfolder/music_nativemidi.h
source_subfolder/music_ogg.h
source_subfolder/music_opus.h
source_subfolder/music_timidity.h
source_subfolder/music_wav.h
src/effects_internal.h
src/load_aiff.h
src/load_voc.h
src/mixer.h
src/music.h
src/music_cmd.h
src/music_flac.h
src/music_fluidsynth.h
src/music_mad.h
src/music_mikmod.h
src/music_modplug.h
src/music_mpg123.h
src/music_nativemidi.h
src/music_ogg.h
src/music_opus.h
src/music_timidity.h
src/music_wav.h
${NATIVE_MIDI_HEADERS}
)

add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})

target_include_directories(${PROJECT_NAME} PRIVATE "source_subfolder")
target_include_directories(${PROJECT_NAME} PRIVATE "src")

if(${MID_NATIVE})
target_include_directories(${PROJECT_NAME} PRIVATE "source_subfolder/native_midi")
target_include_directories(${PROJECT_NAME} PRIVATE "src/native_midi")
endif()

find_package(SDL2 CONFIG REQUIRED)
Expand Down Expand Up @@ -146,7 +143,7 @@ if(MID_TINYMIDI)
target_link_libraries(${PROJECT_NAME} PRIVATE tinymidi::tinymidi)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER source_subfolder/SDL_mixer.h)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/SDL_mixer.h)

if(${BUILD_SHARED_LIBS})
target_compile_definitions(${PROJECT_NAME} PRIVATE DLL_EXPORT)
Expand All @@ -159,9 +156,7 @@ if(SSIZE_T STREQUAL "")
target_compile_definitions(${PROJECT_NAME} PRIVATE ssize_t=signed) # non-standard type
endif()

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
PUBLIC_HEADER DESTINATION "include/SDL2"
)
178 changes: 95 additions & 83 deletions recipes/sdl_mixer/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,144 +1,156 @@
from conans import CMake, tools
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy
from conan.tools.files import get, rmdir
import os
import functools

required_conan_version = ">=1.53.0"


class SDLMixerConan(ConanFile):
name = "sdl_mixer"
description = "SDL_mixer is a sample multi-channel audio mixer library"
topics = ("sdl_mixer", "sdl2", "sdl", "mixer", "audio", "multimedia", "sound", "music")
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libsdl.org/projects/SDL_mixer/"
license = "Zlib"
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "cmake_find_package_multi"
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],
"mad": [True, False],
"ogg": [True, False],
"opus": [True, False],
"mikmod": [True, False],
"modplug": [True, False],
"fluidsynth": [True, False],
"nativemidi": [True, False],
"tinymidi": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"cmd": False, # needs sys/wait.h
"wav": True,
"flac": True,
"mpg123": True,
"mad": True,
"ogg": True,
"opus": True,
"mikmod": True,
"modplug": True,
"fluidsynth": False, # TODO: add fluidsynth to Conan Center
"nativemidi": True,
"tinymidi": True}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
options = {
"shared": [True, False],
"fPIC": [True, False],
"cmd": [True, False],
"wav": [True, False],
"flac": [True, False],
"mpg123": [True, False],
"mad": [True, False],
"ogg": [True, False],
"opus": [True, False],
"mikmod": [True, False],
"modplug": [True, False],
"fluidsynth": [True, False],
"nativemidi": [True, False],
"tinymidi": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"cmd": False,
"wav": True,
"flac": True,
"mpg123": True,
"mad": True,
"ogg": True,
"opus": True,
"mikmod": True,
"modplug": True,
"fluidsynth": False,
"nativemidi": True,
"tinymidi": True,
}

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os != "Linux":
del self.options.tinymidi
self.options.rm_safe("tinymidi")
else:
del self.options.nativemidi
self.options.rm_safe("nativemidi")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
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.0.20")
self.requires("sdl/2.26.5", transitive_headers=True)
if self.options.flac:
self.requires("flac/1.3.3")
self.requires("flac/1.4.2")
if self.options.mpg123:
self.requires("mpg123/1.29.3")
self.requires("mpg123/1.31.2")
if self.options.mad:
self.requires("libmad/0.15.1b")
if self.options.ogg:
self.requires("ogg/1.3.5")
self.requires("vorbis/1.3.7")
if self.options.opus:
self.requires("openssl/1.1.1q")
self.requires("openssl/[>=1.1 <4]")
self.requires("opus/1.3.1")
self.requires("opusfile/0.12")
if self.options.mikmod:
self.requires("libmikmod/3.3.11.1")
if self.options.modplug:
self.requires("libmodplug/0.8.9.0")
if self.options.fluidsynth:
self.requires("fluidsynth/2.2") # TODO: this package is missing on the conan-center-index
self.requires("fluidsynth/2.2") # TODO: this package is missing on the conan-center-index
if self.settings.os == "Linux":
if self.options.tinymidi:
self.requires("tinymidi/cci.20130325")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["CMD"] = self.options.cmd
cmake.definitions["WAV"] = self.options.wav
cmake.definitions["FLAC"] = self.options.flac
cmake.definitions["MP3_MPG123"] = self.options.mpg123
cmake.definitions["MP3_MAD"] = self.options.mad
cmake.definitions["OGG"] = self.options.ogg
cmake.definitions["OPUS"] = self.options.opus
cmake.definitions["MOD_MIKMOD"] = self.options.mikmod
cmake.definitions["MOD_MODPLUG"] = self.options.modplug
cmake.definitions["MID_FLUIDSYNTH"] = self.options.fluidsynth
def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMD"] = self.options.cmd
tc.variables["WAV"] = self.options.wav
tc.variables["FLAC"] = self.options.flac
tc.variables["MP3_MPG123"] = self.options.mpg123
tc.variables["MP3_MAD"] = self.options.mad
tc.variables["OGG"] = self.options.ogg
tc.variables["OPUS"] = self.options.opus
tc.variables["MOD_MIKMOD"] = self.options.mikmod
tc.variables["MOD_MODPLUG"] = self.options.modplug
tc.variables["MID_FLUIDSYNTH"] = self.options.fluidsynth
if self.settings.os == "Linux":
cmake.definitions["MID_TINYMIDI"] = self.options.tinymidi
cmake.definitions["MID_NATIVE"] = False
tc.variables["MID_TINYMIDI"] = self.options.tinymidi
tc.variables["MID_NATIVE"] = False
else:
cmake.definitions["MID_TINYMIDI"] = False
cmake.definitions["MID_NATIVE"] = self.options.nativemidi

cmake.definitions["FLAC_DYNAMIC"] = self.options["flac"].shared if self.options.flac else False
cmake.definitions["MP3_MPG123_DYNAMIC"] = self.options["mpg123"].shared if self.options.mpg123 else False
cmake.definitions["OGG_DYNAMIC"] = self.options["ogg"].shared if self.options.ogg else False
cmake.definitions["OPUS_DYNAMIC"] = self.options["opus"].shared if self.options.opus else False
cmake.definitions["MOD_MIKMOD_DYNAMIC"] = self.options["libmikmod"].shared if self.options.mikmod else False
cmake.definitions["MOD_MODPLUG_DYNAMIC"] = self.options["libmodplug"].shared if self.options.modplug else False

cmake.configure(build_folder=self._build_subfolder)

return cmake
tc.variables["MID_TINYMIDI"] = False
tc.variables["MID_NATIVE"] = self.options.nativemidi
tc.variables["FLAC_DYNAMIC"] = self.dependencies["flac"].options.shared if self.options.flac else False
tc.variables["MP3_MPG123_DYNAMIC"] = self.dependencies["mpg123"].options.shared if self.options.mpg123 else False
tc.variables["OGG_DYNAMIC"] = self.dependencies["ogg"].options.shared if self.options.ogg else False
tc.variables["OPUS_DYNAMIC"] = self.dependencies["opus"].options.shared if self.options.opus else False
tc.variables["MOD_MIKMOD_DYNAMIC"] = self.dependencies["libmikmod"].options.shared if self.options.mikmod else False
tc.variables["MOD_MODPLUG_DYNAMIC"] = self.dependencies["libmodplug"].options.shared if self.options.modplug else False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure(build_script_folder=self.source_path.parent)
cmake.build()

def package(self):
self.copy(pattern="COPYING.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "COPYING.txt",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "SDL2_mixer")
self.cpp_info.set_property("cmake_file_name", "SDL2_mixer")
self.cpp_info.set_property("cmake_target_name", "SDL2_mixer::SDL2_mixer")
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"]

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


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

find_package(SDL2_mixer CONFIG REQUIRED)
find_package(SDL2_mixer REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_mixer::SDL2_mixer)
Loading

0 comments on commit 60c8ca2

Please sign in to comment.