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

add sdl2_image/2.0.5 and sdl2_mixer/2.0.4 #1317

Merged
merged 22 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 19 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
100 changes: 100 additions & 0 deletions recipes/sdl2_image/2.0.5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
cmake_minimum_required(VERSION 2.8)

project(SDL2_image)

include(conanbuildinfo.cmake)
conan_basic_setup()

find_package(SDL2 REQUIRED CONFIG)

macro(add_image_option type)
option(${type} "${type} images support" ON)
if(${type})
add_definitions("-DLOAD_${type}")
if(${type}_DYNAMIC)
add_definitions("-DLOAD_${type}_DYNAMIC")
endif()
endif()
endmacro()

if(APPLE)
option(IMAGEIO "use native Mac OS X frameworks for loading images" ON)
if(IMAGEIO)
set(IMAGEIO_SOURCE "source_subfolder/IMG_ImageIO.m")
else()
add_definitions("-DSDL_IMAGE_USE_COMMON_BACKEND")
endif()
endif()

add_image_option(BMP)
add_image_option(GIF)
add_image_option(JPG)
add_image_option(LBM)
add_image_option(PCX)
add_image_option(PNG)
add_image_option(PNM)
add_image_option(SVG)
add_image_option(TGA)
add_image_option(TIF)
add_image_option(WEBP)
add_image_option(XCF)
add_image_option(XPM)
add_image_option(XV)

set(SOURCES
source_subfolder/IMG.c
source_subfolder/IMG_bmp.c
source_subfolder/IMG_gif.c
source_subfolder/IMG_jpg.c
source_subfolder/IMG_lbm.c
source_subfolder/IMG_pcx.c
source_subfolder/IMG_png.c
source_subfolder/IMG_pnm.c
source_subfolder/IMG_svg.c
source_subfolder/IMG_tga.c
source_subfolder/IMG_tif.c
source_subfolder/IMG_xcf.c
source_subfolder/IMG_xpm.c
source_subfolder/IMG_xv.c
source_subfolder/IMG_webp.c
${IMAGEIO_SOURCE}
)

add_library(${PROJECT_NAME} ${SOURCES})

target_include_directories(${PROJECT_NAME} PRIVATE "source_subfolder")

if(${SDL_DYNAMIC})
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2-static)
endif()

if(${TIF})
find_package(TIFF REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE TIFF::TIFF)
endif()

if(${JPG})
find_package(JPEG REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE JPEG::JPEG)
endif()

if(${PNG})
find_package(PNG REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE PNG::PNG)
endif()

if(${WEBP})
find_package(WebP REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE WebP::webp)
endif()

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

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
PUBLIC_HEADER DESTINATION "include/SDL2"
)
4 changes: 4 additions & 0 deletions recipes/sdl2_image/2.0.5/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.0.5":
url: "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz"
sha256: "bdd5f6e026682f7d7e1be0b6051b209da2f402a2dd8bd1c4bd9c25ad263108d0"
126 changes: 126 additions & 0 deletions recipes/sdl2_image/2.0.5/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from conans import ConanFile, tools, CMake
import os


class SDL2ImageConan(ConanFile):
name = "sdl2_image"
description = "SDL_image is an image file loading library"
topics = ("sdl2_image", "sdl_image", "sdl2", "sdl", "images", "opengl")
url = "https://github.com/bincrafters/community"
homepage = "https://www.libsdl.org/projects/SDL_image/"
license = "MIT"
exports_sources = ["CMakeLists.txt"]
generators = ["cmake", "cmake_find_package_multi"]
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"bmp": [True, False],
"gif": [True, False],
"lbm": [True, False],
"pcx": [True, False],
"pnm": [True, False],
"svg": [True, False],
"tga": [True, False],
"xcf": [True, False],
"xpm": [True, False],
"xv": [True, False],
"jpg": [True, False],
"tif": [True, False],
"png": [True, False],
"webp": [True, False],
"imageio": [True, False]}
default_options = {
"shared": False,
"fPIC": True,
"bmp": True,
"gif": True,
"lbm": True,
"pcx": True,
"pnm": True,
"svg": True,
"tga": True,
"xcf": True,
"xpm": True,
"xv": True,
"jpg": True,
"tif": True,
"png": True,
"webp": True,
"imageio": False
}

_cmake = None
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"

def config_options(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os != "Macos":
del self.options.imageio

def requirements(self):
self.requires("sdl2/2.0.14@bincrafters/stable")
if self.options.tif:
self.requires("libtiff/4.0.9")
if self.options.jpg:
self.requires("libjpeg/9d")
if self.options.png:
self.requires("libpng/1.6.37")
if self.options.webp:
self.requires("libwebp/1.0.3")
self.requires("zlib/1.2.11")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "SDL2_image-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self)
self._cmake.definitions["BMP"] = self.options.bmp
self._cmake.definitions["GIF"] = self.options.gif
self._cmake.definitions["IMAGEIO"] = self.options.get_safe("imageio")
self._cmake.definitions["JPG"] = self.options.jpg
self._cmake.definitions["LBM"] = self.options.lbm
self._cmake.definitions["PCX"] = self.options.pcx
self._cmake.definitions["PNG"] = self.options.png
self._cmake.definitions["PNM"] = self.options.pnm
self._cmake.definitions["SVG"] = self.options.svg
self._cmake.definitions["TGA"] = self.options.tga
self._cmake.definitions["TIF"] = self.options.tif
self._cmake.definitions["WEBP"] = self.options.webp
self._cmake.definitions["XCF"] = self.options.xcf
self._cmake.definitions["XPM"] = self.options.xpm
self._cmake.definitions["XV"] = self.options.xv
self._cmake.definitions["TIF_DYNAMIC"] = self.options["libtiff"].shared if self.options.tif else False
self._cmake.definitions["JPG_DYNAMIC"] = self.options["libjpeg"].shared if self.options.jpg else False
self._cmake.definitions["PNG_DYNAMIC"] = self.options["libpng"].shared if self.options.png else False
self._cmake.definitions["WEBP_DYNAMIC"] = self.options["libwebp"].shared if self.options.webp else False
self._cmake.definitions["SDL2_DYNAMIC"] = self.options["sdl2"].shared
Copy link
Contributor

@SpaceIm SpaceIm Feb 6, 2021

Choose a reason for hiding this comment

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

It's not because libtiff is shared that consumer wants dynamic load. In upstream configure.in, there is a specific option (true by default) for each dependency for which sdl2_image supports dynamic load (libtiff, libjpeg, libpng and libwebp).
So, you can link to static, to shared, or dynamically load shared.

Moreover, there is no dynamic load of sdl2 in sdl2_image, it's always linked.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the catch. We are currently using a custom CMake file for sdl2_image, only the next version will have official CMake support.

I will rename the SDL2_DYNAMIC option name as it only seems to make a switch between static and shared linking. Not entirely sure how to proceed with the rest.

Is dynamic loading just working, despite our custom CMake file?
If yes, we don't necessarily need special handling I guess.
If not, it doesn't work right now

Copy link
Contributor

@SpaceIm SpaceIm Jul 21, 2021

Choose a reason for hiding this comment

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

From what I see in this custom CMake file, nothing is done with these definitions (except SDL2_DYNAMIC, but it's a different purpose and this CMake option could be avoided), so well let's say that the "dynamic" options in upstream configure.in is not supported for the moment in this recipe.

Is dynamic loading just working, despite our custom CMake file?

It can't work with this custom CMakeLists, there is an explicit branching with macros for dynamic load handling at runtime:
https://github.com/SDL-mirror/SDL_image/blob/b4f28c1fc9ab2f91ae594fc3e86622c5c13ffbbb/configure.in#L358-L364
https://github.com/SDL-mirror/SDL_image/blob/f4f5caf21d6f18de85baee945348f56697d1813a/IMG_jpg.c#L70-L77


self._cmake.configure(build_dir="build")
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="COPYING.txt", dst="license", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.libs = ["SDL2_image"]
self.cpp_info.includedirs.append(os.path.join("include", "SDL2"))
# TODO: Add components in a sane way. SDL2_image might be incorrect, as the current dev version uses SDL2::image
# The current dev version is the first version with official CMake support
self.cpp_info.names["cmake_find_package"] = "SDL2_image"
self.cpp_info.names["cmake_find_package_multi"] = "SDL2_image"
11 changes: 11 additions & 0 deletions recipes/sdl2_image/2.0.5/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)


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

find_package(SDL2_image REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} SDL2_image::SDL2_image)
17 changes: 17 additions & 0 deletions recipes/sdl2_image/2.0.5/test_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.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
19 changes: 19 additions & 0 deletions recipes/sdl2_image/2.0.5/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <cstdlib>
#include <iostream>
#include "SDL_image.h"

int main(int argc, char *argv[])
{
SDL_version compile_version;
const SDL_version * link_version=IMG_Linked_Version();
SDL_IMAGE_VERSION(&compile_version);
std::cout << "SDL2_image compile version: " <<
int(compile_version.major) << "." <<
int(compile_version.minor) << "." <<
int(compile_version.patch) << std::endl;
std::cout << "SDL2_image link version: " <<
int(link_version->major) << "." <<
int(link_version->minor) << "." <<
int(link_version->patch) << std::endl;
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/sdl2_image/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.0.5":
folder: "2.0.5"
108 changes: 108 additions & 0 deletions recipes/sdl2_mixer/2.0.4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
cmake_minimum_required(VERSION 2.8.12)
project(sdl2_mixer)

include(conanbuildinfo.cmake)
conan_basic_setup()

macro(add_music_option type)
option(${type} "${type} music support" OFF)
message(STATUS "${type} ${${type}}")
if(${${type}})
add_definitions("-DMUSIC_${type}")
if(${${type}_DYNAMIC})
add_definitions("-D${type}_DYNAMIC")
endif()
endif()
endmacro()

add_music_option(CMD)
add_music_option(WAV)
add_music_option(FLAC)
add_music_option(OGG)
add_music_option(OPUS)
add_music_option(MP3_MPG123)
add_music_option(MP3_MAD)
add_music_option(MOD_MIKMOD)
add_music_option(MOD_MODPLUG)
add_music_option(MID_NATIVE)
add_music_option(MID_FLUIDSYNTH)
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
)

set(NATIVE_MIDI_HEADERS
source_subfolder/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
${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
${NATIVE_MIDI_HEADERS}
)

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

target_include_directories(${PROJECT_NAME} PRIVATE "source_subfolder")

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

target_link_libraries(${PROJECT_NAME} PRIVATE ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER source_subfolder/SDL_mixer.h)

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
PUBLIC_HEADER DESTINATION "include/SDL2"
)
Loading