diff --git a/recipes/sfml/all/CMakeLists.txt b/recipes/sfml/all/CMakeLists.txt new file mode 100644 index 0000000000000..a69305eb3971f --- /dev/null +++ b/recipes/sfml/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.12) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/sfml/all/conandata.yml b/recipes/sfml/all/conandata.yml new file mode 100644 index 0000000000000..3771535ae6082 --- /dev/null +++ b/recipes/sfml/all/conandata.yml @@ -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" diff --git a/recipes/sfml/all/conanfile.py b/recipes/sfml/all/conanfile.py new file mode 100644 index 0000000000000..7db3b074e3b1d --- /dev/null +++ b/recipes/sfml/all/conanfile.py @@ -0,0 +1,186 @@ +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.20.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) + + 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")) + + 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"].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"].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"].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"].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"].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["network"].system_libs = ['ws2_32'] + + if self.options.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", "system"] + 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'] diff --git a/recipes/sfml/all/patches/001_disable_deps_installation.patch b/recipes/sfml/all/patches/001_disable_deps_installation.patch new file mode 100644 index 0000000000000..c8b9da8849a3f --- /dev/null +++ b/recipes/sfml/all/patches/001_disable_deps_installation.patch @@ -0,0 +1,106 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -398,68 +398,12 @@ + COMPONENT devel) + endif() + +-install(FILES license.md DESTINATION ${SFML_MISC_INSTALL_PREFIX}) +-install(FILES readme.md DESTINATION ${SFML_MISC_INSTALL_PREFIX}) +- + # 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 +423,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() diff --git a/recipes/sfml/all/patches/002_fix_shared.patch b/recipes/sfml/all/patches/002_fix_shared.patch new file mode 100644 index 0000000000000..5a43e7eda949d --- /dev/null +++ b/recipes/sfml/all/patches/002_fix_shared.patch @@ -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") diff --git a/recipes/sfml/all/test_package/CMakeLists.txt b/recipes/sfml/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..23706ad620563 --- /dev/null +++ b/recipes/sfml/all/test_package/CMakeLists.txt @@ -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() diff --git a/recipes/sfml/all/test_package/conanfile.py b/recipes/sfml/all/test_package/conanfile.py new file mode 100644 index 0000000000000..7e0a2853110a4 --- /dev/null +++ b/recipes/sfml/all/test_package/conanfile.py @@ -0,0 +1,21 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.definitions['WITH_WINDOW'] = self.options['sfml'].window + cmake.definitions['WITH_GRAPHICS'] = self.options['sfml'].graphics + cmake.definitions['WITH_AUDIO'] = self.options['sfml'].audio + cmake.definitions['WITH_NETWORK'] = self.options['sfml'].network + 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) diff --git a/recipes/sfml/all/test_package/test_package.cpp b/recipes/sfml/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..b21254f4e0c73 --- /dev/null +++ b/recipes/sfml/all/test_package/test_package.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include + +#ifdef WITH_WINDOW + #include +#endif +#ifdef WITH_GRAPHICS + #include +#endif +#ifdef WITH_AUDIO + #include +#endif +#ifdef WITH_NETWORK + #include +#endif + + +int main(int argc, char **argv) +{ + sf::Clock clock; + clock.getElapsedTime().asSeconds(); + + #ifdef WITH_WINDOW + sf::VideoMode videoMode(720, 480); + #endif + + #ifdef WITH_GRAPHICS + sf::RectangleShape shape; + shape.setFillColor(sf::Color::Cyan); + #endif + + #ifdef WITH_AUDIO + sf::SoundBuffer buffer; + sf::Sound sound; + sound.setBuffer(buffer); + #endif + + #ifdef WITH_NETWORK + sf::TcpListener listener; + listener.isBlocking(); + #endif + + return EXIT_SUCCESS; +} diff --git a/recipes/sfml/config.yml b/recipes/sfml/config.yml new file mode 100644 index 0000000000000..eab83a303df52 --- /dev/null +++ b/recipes/sfml/config.yml @@ -0,0 +1,3 @@ +versions: + "2.5.1": + folder: all