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 sfml/2.5.1 #2467

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions recipes/sfml/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
10 changes: 10 additions & 0 deletions recipes/sfml/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"2.5.1":
url: "https://github.com/SFML/SFML/archive/2.5.1.tar.gz"
sha256: "438c91a917cc8aa19e82c6f59f8714da353c488584a007d401efac8368e1c785"
patches:
"2.5.1":
- patch_file: "patches/001_disable_deps_installation.patch"
base_path: "source_subfolder"
- patch_file: "patches/002_fix_shared.patch"
base_path: "source_subfolder"
200 changes: 200 additions & 0 deletions recipes/sfml/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
from conans import ConanFile, CMake, tools
import os


class SFMLConan(ConanFile):
name = 'sfml'
description = 'Simple and Fast Multimedia Library'
license = "Zlib"
topics = ('conan', 'sfml', 'multimedia')
homepage = 'https://github.com/SFML/SFML'
url = 'https://github.com/conan-io/conan-center-index'
exports_sources = ['CMakeLists.txt', 'patches/*']
generators = 'cmake', 'cmake_find_package'
settings = 'os', 'compiler', 'build_type', 'arch'
options = {
'shared': [True, False],
'fPIC': [True, False],
'window': [True, False],
'graphics': [True, False],
'network': [True, False],
'audio': [True, False],
}
default_options = {
'shared': False,
'fPIC': True,
'window': True,
'graphics': True,
'network': True,
'audio': True,
}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def requirements(self):
if self.options.graphics:
self.requires('freetype/2.10.1')
self.requires('stb/20200203')
if self.options.audio:
self.requires('openal/1.19.1')
self.requires('flac/1.3.3')
self.requires('ogg/1.3.4')
self.requires('vorbis/1.3.6')
if self.options.window:
if self.settings.os in ['Linux', 'FreeBSD']:
self.requires('xorg/system')
self.requires('opengl/system')

def system_requirements(self):
if self.settings.os == 'Linux' and tools.os_info.is_linux:
if tools.os_info.with_apt:
installer = tools.SystemPackageTool()
packages = []
if self.options.window:
packages.extend(['libudev-dev'])
for package in packages:
installer.install(package)
Comment on lines +56 to +64
Copy link
Member

Choose a reason for hiding this comment

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

libudev desires a proxy package, libusb also requires libudev, but it's complete outdated.

Copy link
Contributor

@SpaceIm SpaceIm Nov 27, 2020

Choose a reason for hiding this comment

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

there is an old PR for libudev: #904

Oups, missed that there was this new one #2468


def configure(self):
if self.options.shared:
del self.options.fPIC

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = 'SFML-' + self.version
os.rename(extracted_dir, self._source_subfolder)
tools.rmdir(os.path.join(self._source_subfolder, "extlibs"))

def _configure_cmake(self):
if self._cmake:
return self.cmake
self.cmake = CMake(self)

self.cmake.definitions['SFML_BUILD_WINDOW'] = self.options.window
self.cmake.definitions['SFML_BUILD_GRAPHICS'] = self.options.graphics
self.cmake.definitions['SFML_BUILD_NETWORK'] = self.options.network
self.cmake.definitions['SFML_BUILD_AUDIO'] = self.options.audio

self.cmake.definitions['SFML_INSTALL_PKGCONFIG_FILES'] = False
self.cmake.definitions['SFML_GENERATE_PDB'] = False

self.cmake.configure(build_folder=self._build_subfolder)
return self.cmake

def build(self):
for patch in self.conan_data.get("patches",{}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("license.md", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
os.remove(os.path.join(self.package_folder, "license.md"))
os.remove(os.path.join(self.package_folder, "readme.md"))

def _get_decorated_lib(self, name):
suffix = '-s' if not self.options.shared else ''
suffix += '-d' if self.settings.build_type == 'Debug' else ''
return name + suffix

def package_info(self):

self.cpp_info.names["cmake_find_package"] = "SFML"
self.cpp_info.names["cmake_find_package_multi"] = "SFML"
self.cpp_info.names["pkg_config"] = "SFML"

self.cpp_info.components["System"].names["cmake_find_package"] = "system"
Copy link
Contributor

Choose a reason for hiding this comment

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

Components name could be lower case, it would avoid to override cmake_find_package and cmake_find_package_multi.
Personal opinion: since recipes names are always lower case in CCI, I think that always use lowercase for components is more consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, SFML module and config files cannot be properly modeled by conan generators.
Usage is:

find_package(SFML REQUIRED main window audio CONFIG)
target_link_libraries(myapp sfml-main sfml-window sfml-audio)

self.cpp_info.components["System"].names["cmake_find_package_multi"] = "system"
self.cpp_info.components["System"].libs = [self._get_decorated_lib("sfml-system")]
if not self.options.shared:
self.cpp_info.components["System"].defines = ['SFML_STATIC']
if self.settings.os == 'Windows':
self.cpp_info.components["System"].system_libs = ['winmm']
elif self.settings.os == 'Linux':
self.cpp_info.components["System"].system_libs = ['rt']
elif self.settings.os == 'Android':
self.cpp_info.components["System"].system_libs = ['android', 'log']
if self.settings.os != 'Windows':
self.cpp_info.components["System"].system_libs = ['pthread']

if self.settings.os in ['Windows', 'Android', 'iOS']:
sfml_main_suffix = '-d' if self.settings.build_type == 'Debug' else ''
self.cpp_info.components["Main"].names["cmake_find_package"] = "main"
self.cpp_info.components["Main"].names["cmake_find_package_multi"] = "main"
self.cpp_info.components["Main"].libs = ["sfml-main" + sfml_main_suffix]
if not self.options.shared:
self.cpp_info.components["Main"].defines = ['SFML_STATIC']
if self.settings.os == 'Android':
self.cpp_info.components["Main"].libs.append(self._get_decorated_lib("sfml-activity"))
self.cpp_info.components["Main"].system_libs = ['android', 'log']

if self.options.window or self.options.graphics:
self.cpp_info.components["Window"].names["cmake_find_package"] = "window"
self.cpp_info.components["Window"].names["cmake_find_package_multi"] = "window"
self.cpp_info.components["Window"].libs = [self._get_decorated_lib("sfml-window")]
self.cpp_info.components["Window"].requires = ["opengl::opengl", "System"]
if self.settings.os in ['Linux', 'FreeBSD']:
self.cpp_info.components["Window"].requires.append('xorg::xorg')
if not self.options.shared:
self.cpp_info.components["Window"].defines = ['SFML_STATIC']
if self.settings.os == 'Windows':
self.cpp_info.components["Window"].system_libs = ['winmm', 'gdi32']
if self.settings.os == 'Linux':
self.cpp_info.components["Window"].system_libs = ['udev']
if self.settings.os == 'FreeBSD':
self.cpp_info.components["Window"].system_libs = ['usbhid']
elif self.settings.os == "Macos":
self.cpp_info.components["Window"].frameworks['Foundation', 'AppKit', 'IOKit', 'Carbon']
if not self.options.shared:
self.cpp_info.components["Window"].exelinkflags.append("-ObjC")
self.cpp_info.components["Window"].sharedlinkflags = self.cpp_info.components["Window"].exelinkflags
elif self.settings.os == "iOS":
self.cpp_info.frameworks['Foundation', 'UIKit', 'CoreGraphics', 'QuartzCore', 'CoreMotion']
elif self.settings.os == "Android":
self.cpp_info.components["Window"].system_libs = ['android']

if self.options.graphics:
self.cpp_info.components["Graphics"].names["cmake_find_package"] = "graphics"
self.cpp_info.components["Graphics"].names["cmake_find_package_multi"] = "graphics"
self.cpp_info.components["Graphics"].libs = [self._get_decorated_lib("sfml-graphics")]
self.cpp_info.components["Graphics"].requires = ["freetype::freetype", "stb::stb", "Window"]
if not self.options.shared:
self.cpp_info.components["Graphics"].defines = ['SFML_STATIC']
if self.settings.os == 'Linux':
self.cpp_info.components["Graphics"].system_libs = ['udev']

if self.options.network:
self.cpp_info.components["Network"].names["cmake_find_package"] = "network"
self.cpp_info.components["Network"].names["cmake_find_package_multi"] = "network"
self.cpp_info.components["Network"].libs = [self._get_decorated_lib("sfml-network")]
self.cpp_info.components["Network"].requires = ["System"]
if not self.options.shared:
self.cpp_info.components["Network"].defines = ['SFML_STATIC']
if self.settings.os == 'Windows':
self.cpp_info.components["Window"].system_libs = ['ws2_32']

if self.options.audio:
self.cpp_info.components["Audio"].names["cmake_find_package"] = "audio"
self.cpp_info.components["Audio"].names["cmake_find_package_multi"] = "audio"
self.cpp_info.components["Audio"].libs = [self._get_decorated_lib("sfml-audio")]
self.cpp_info.components["Audio"].requires = ["openal::openal", "flac::flac", "ogg::ogg", "vorbis::vorbis"]
if not self.options.shared:
self.cpp_info.components["Audio"].defines = ['SFML_STATIC']
if self.settings.os == "Android":
self.cpp_info.components["Audio"].system_libs = ['android']
100 changes: 100 additions & 0 deletions recipes/sfml/all/patches/001_disable_deps_installation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -404,62 +404,9 @@
# install 3rd-party libraries and tools
if(SFML_OS_WINDOWS)

- if(NOT SFML_USE_SYSTEM_DEPS)
- # install the binaries of SFML dependencies
- if(ARCH_32BITS)
- install(DIRECTORY extlibs/bin/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/bin)
- if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
- install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- elseif(SFML_COMPILER_MSVC)
- install(DIRECTORY extlibs/libs-msvc-universal/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- else()
- install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- endif()
- elseif(ARCH_64BITS)
- install(DIRECTORY extlibs/bin/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/bin)
- if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
- install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- elseif(SFML_COMPILER_MSVC)
- install(DIRECTORY extlibs/libs-msvc-universal/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- else()
- install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
- endif()
- endif()
- endif()

elseif(SFML_OS_MACOSX)
# install extlibs dependencies only when used
- if(SFML_BUILD_GRAPHICS)
- if(FREETYPE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
- endif()
-
- if(SFML_BUILD_AUDIO)
- if(FLAC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
-
- if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
-
- if(VORBIS_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
-
- if(VORBISENC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
-
- if(VORBISFILE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework")
- install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
-
- if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework")
- install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
- endif()
- endif()

# install the Xcode templates if requested
if(SFML_INSTALL_XCODE_TEMPLATES)
@@ -479,34 +426,9 @@
elseif(SFML_OS_IOS)

# fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
- install(DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION lib${LIB_SUFFIX})
-
- if(NOT SFML_USE_SYSTEM_DEPS)
- # since the iOS libraries are built as static, we must install the SFML dependencies
- # too so that the end user can easily link them to its final application
- if(SFML_BUILD_GRAPHICS)
- install(FILES extlibs/libs-ios/libfreetype.a DESTINATION lib)
- endif()
-
- if(SFML_BUILD_AUDIO)
- install(FILES extlibs/libs-ios/libflac.a
- extlibs/libs-ios/libvorbis.a
- extlibs/libs-ios/libogg.a
- DESTINATION lib)
- endif()
- endif()

elseif(SFML_OS_ANDROID)

- if(NOT SFML_USE_SYSTEM_DEPS)
- # install extlibs
- install(DIRECTORY extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI} DESTINATION extlibs/lib)
- install(FILES extlibs/Android.mk DESTINATION extlibs)
- endif()
-
- # install Android.mk so the NDK knows how to set up SFML
- install(FILES src/SFML/Android.mk DESTINATION .)
-
endif()

sfml_export_targets()
32 changes: 32 additions & 0 deletions recipes/sfml/all/patches/002_fix_shared.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- cmake/Modules/FindFreetype.cmake
+++ cmake/Modules/FindFreetype.cmake
@@ -95,6 +95,7 @@ find_library(FREETYPE_LIBRARY
NAMES
freetype
libfreetype
+ freetyped
freetype219
HINTS
ENV FREETYPE_DIR
--- src/SFML/Audio/CMakeLists.txt
+++ src/SFML/Audio/CMakeLists.txt
@@ -79,7 +79,7 @@ sfml_add_library(sfml-audio
SOURCES ${SRC} ${CODECS_SRC})

# setup dependencies
-target_link_libraries(sfml-audio PRIVATE OpenAL)
+target_link_libraries(sfml-audio PRIVATE ${CONAN_LIBS} ${SFML_OSX_FRAMEWORK})

if(SFML_OS_ANDROID)
target_link_libraries(sfml-audio PRIVATE android OpenSLES)
--- src/SFML/Graphics/CMakeLists.txt
+++ src/SFML/Graphics/CMakeLists.txt
@@ -135,7 +135,7 @@ if(SFML_OS_ANDROID)
endif()

sfml_find_package(Freetype INCLUDE "FREETYPE_INCLUDE_DIRS" LINK "FREETYPE_LIBRARY")
-target_link_libraries(sfml-graphics PRIVATE Freetype)
+target_link_libraries(sfml-graphics PRIVATE ${CONAN_LIBS})

# add preprocessor symbols
target_compile_definitions(sfml-graphics PRIVATE "STBI_FAILURE_USERMSG")
38 changes: 38 additions & 0 deletions recipes/sfml/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

set(SFML_components system)
if (WITH_WINDOW)
list(APPEND SFML_components window)
endif()
if (WITH_GRAPHICS)
list(APPEND SFML_components graphics)
endif()
if (WITH_AUDIO)
list(APPEND SFML_components audio)
endif()
if (WITH_NETWORK)
list(APPEND SFML_components network)
endif()

find_package(SFML 2 COMPONENTS ${SFML_components} REQUIRED)

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${SFML_LIBRARIES})
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11)

if(WITH_WINDOW)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "WITH_WINDOW")
endif()
if(WITH_GRAPHICS)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "WITH_GRAPHICS")
endif()
if(WITH_AUDIO)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "WITH_AUDIO")
endif()
if(WITH_NETWORK)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "WITH_NETWORK")
endif()
Loading