Skip to content

Commit 504a734

Browse files
AbrilRBSperseoGIfranramirez688ErniGH
authored
sfml: Add support for SFML3 (#25305)
* First sketch towards SFML 3 support * Get the test running * graphics * network * Missing system requirement * Add missing file * Fix android configure() * Fix android name scheme * Try to fix Android lib locations * Typo * Address main always being static * Audio * Cleanup * Use android_abi instead of changing upstream * Experimental: Android missing system_libs * Experimental: Do you even fail? * Revert "Experimental: Do you even fail?" This reverts commit 9fb2cf0. * Experimental: EGL, GLES for Android * Cleanup, usbhid support in FreeBSD * Add missing system requires for audio & network * Component name check * Remove check_components_exist * Revert unintended flac change * Cleanup comments * Gcc 7 min * Missing version * Enable examples for easier testing for now, fix macos isssues * Disable cocoa example in Macos * Gcc 9 * Remove test_v1_package from SFML 3 * Cleanup * Add C++17 to tests * Back to gcc9 * Add missing Core framework * Cleanup diff * ooops * Adapt for 3.0.0 release * Minor changes * Simplify * Comment exampples * Fix lib names * Last fixes --------- Co-authored-by: PerseoGI <[email protected]> * Unvendor dependencies as needed --------- Co-authored-by: PerseoGI <[email protected]> * Vulkan, but can't get it to me available * Try to simplify * Fix library extension logic on shared-libraries * Update recipes/sfml/3.x/conanfile.py Co-authored-by: Francisco Ramírez <[email protected]> * Update recipes/sfml/3.x/conanfile.py Co-authored-by: Francisco Ramírez <[email protected]> * Update recipes/sfml/3.x/conanfile.py Co-authored-by: Francisco Ramírez <[email protected]> * Fix package extension * Fix static checks * typo * Update recipes/sfml/3.x/conanfile.py * Update recipes/sfml/3.x/conanfile.py * Update recipes/sfml/3.x/test_package/CMakeLists.txt * Restrict version range of stb to cci.20220909 and vulkan-headers to ~1 * Update recipes/sfml/3.x/conanfile.py Co-authored-by: Francisco Ramírez <[email protected]> --------- Co-authored-by: PerseoGI <[email protected]> Co-authored-by: Francisco Ramírez <[email protected]> Co-authored-by: Ernesto de Gracia Herranz <[email protected]>
1 parent 4ba86b6 commit 504a734

File tree

7 files changed

+448
-0
lines changed

7 files changed

+448
-0
lines changed

recipes/sfml/3.x/conandata.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sources:
2+
"3.0.2":
3+
url: "https://github.com/SFML/SFML/archive/refs/tags/3.0.2.tar.gz"
4+
sha256: "0034e05f95509e5d3fb81b1625713e06da7b068f210288ce3fd67106f8f46995"
5+
patches:
6+
"3.0.2":
7+
- patch_file: "patches/3.0.2-001-unvendor-deps.patch"

recipes/sfml/3.x/conanfile.py

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.android import android_abi
4+
from conan.tools.build import check_min_cppstd
5+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
6+
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, rmdir, copy
7+
import os
8+
9+
required_conan_version = ">=2.1"
10+
11+
12+
class SfmlConan(ConanFile):
13+
name = "sfml"
14+
description = "Simple and Fast Multimedia Library."
15+
license = "Zlib"
16+
url = "https://github.com/conan-io/conan-center-index"
17+
homepage = "https://www.sfml-dev.org"
18+
topics = ("multimedia", "games", "graphics", "audio")
19+
package_type = "library"
20+
settings = "os", "arch", "compiler", "build_type"
21+
options = {
22+
"shared": [True, False],
23+
"fPIC": [True, False],
24+
# modules
25+
"window": [True, False],
26+
"graphics": [True, False],
27+
"network": [True, False],
28+
"audio": [True, False],
29+
# window module options
30+
"opengl": ["es", "desktop"],
31+
# "use_drm": [True, False], # Linux only, no support for now, PR welcome
32+
# "use_mesa3d": [True, False], # Windows only, not available in CCI
33+
34+
}
35+
default_options = {
36+
"shared": False,
37+
"fPIC": True,
38+
"window": True,
39+
"graphics": True,
40+
"network": True,
41+
"audio": True,
42+
"opengl": "desktop",
43+
}
44+
implements = ["auto_shared_fpic"]
45+
46+
def export_sources(self):
47+
export_conandata_patches(self)
48+
49+
def configure(self):
50+
if self.options.get_safe("shared"):
51+
self.options.rm_safe("fPIC")
52+
53+
if not self.options.window:
54+
del self.options.opengl
55+
56+
# As per CMakeLists.txt#L44, Android is always shared
57+
if self.settings.os == "Android":
58+
del self.options.shared
59+
del self.options.fPIC
60+
self.package_type = "shared-library"
61+
62+
def layout(self):
63+
cmake_layout(self, src_folder="src")
64+
65+
def requirements(self):
66+
if self.options.window:
67+
if self.settings.os in ["Linux", "FreeBSD"]:
68+
self.requires("xorg/system")
69+
if self.settings.os == "Linux":
70+
self.requires("libudev/system")
71+
72+
if self.settings.os not in ("iOS", "Android"): # Handled as a framework
73+
self.requires("opengl/system")
74+
self.requires("vulkan-headers/[~1]")
75+
76+
if self.options.graphics:
77+
if self.settings.os == "Android" or self.settings.os == "iOS":
78+
self.requires("zlib/[>=1.2.11 <2]")
79+
if self.settings.os == "iOS":
80+
self.requires("bzip2/1.0.8")
81+
self.requires("freetype/2.13.2")
82+
self.requires("stb/[>=cci.20240531]")
83+
84+
if self.options.audio:
85+
self.requires("vorbis/1.3.7")
86+
self.requires("flac/1.4.3")
87+
self.requires("minimp3/cci.20211201")
88+
self.requires("miniaudio/0.11.22", transitive_headers=True)
89+
90+
def build_requirements(self):
91+
self.tool_requires("cmake/[>=3.24]")
92+
93+
def validate(self):
94+
check_min_cppstd(self, 17)
95+
96+
if self.options.graphics and not self.options.window:
97+
raise ConanInvalidConfiguration(f"-o={self.ref}:graphics=True requires -o={self.ref}:window=True")
98+
99+
if self.settings.os == "Windows" and self.options.get_safe("shared") and self.settings.get_safe("compiler.runtime") == "static":
100+
raise ConanInvalidConfiguration(f"{self.ref} does not support shared libraries with static runtime")
101+
102+
def validate_build(self):
103+
if self.settings.os == "Macos" and self.settings.compiler != "apple-clang":
104+
raise ConanInvalidConfiguration(f"{self.ref} is not supported on {self.settings.os} with {self.settings.compiler}")
105+
106+
def source(self):
107+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
108+
apply_conandata_patches(self)
109+
110+
def generate(self):
111+
tc = CMakeToolchain(self)
112+
113+
tc.cache_variables["SFML_BUILD_WINDOW"] = self.options.window
114+
tc.cache_variables["SFML_BUILD_GRAPHICS"] = self.options.graphics
115+
tc.cache_variables["SFML_BUILD_NETWORK"] = self.options.network
116+
tc.cache_variables["SFML_BUILD_AUDIO"] = self.options.audio
117+
118+
if self.options.window:
119+
tc.cache_variables["SFML_OPENGL_ES"] = self.options.opengl == "es"
120+
121+
tc.cache_variables["SFML_GENERATE_PDB"] = False # PDBs not allowed in CCI
122+
123+
if self.settings.os == "Windows":
124+
tc.cache_variables["SFML_USE_STATIC_STD_LIBS"] = self.settings.get_safe("compiler.runtime") == "static"
125+
tc.cache_variables["SFML_USE_MESA3D"] = False # self.options.use_mesa3d
126+
127+
tc.cache_variables["SFML_USE_SYSTEM_DEPS"] = True
128+
129+
tc.cache_variables["SFML_INSTALL_PKGCONFIG_FILES"] = False
130+
tc.cache_variables["SFML_WARNINGS_AS_ERRORS"] = False
131+
tc.cache_variables["SFML_CONFIGURE_EXTRAS"] = False
132+
133+
# Tip: You can use this locally to test the extras when adding a new version,
134+
# uncomment both to build examples, or run them manually
135+
# tc.cache_variables["SFML_CONFIGURE_EXTRAS"] = True
136+
# tc.cache_variables["SFML_BUILD_EXAMPLES"] = True
137+
138+
tc.generate()
139+
deps = CMakeDeps(self)
140+
if self.options.audio:
141+
deps.set_property("flac", "cmake_file_name", "FLAC")
142+
143+
if self.options.graphics:
144+
deps.set_property("freetype", "cmake_file_name", "Freetype")
145+
deps.set_property("freetype", "cmake_target_name", "Freetype::Freetype")
146+
deps.generate()
147+
148+
def build(self):
149+
cmake = CMake(self)
150+
cmake.configure()
151+
cmake.build()
152+
153+
def package(self):
154+
copy(self, "license.md", self.source_folder, os.path.join(self.package_folder, "licenses"))
155+
cmake = CMake(self)
156+
cmake.install()
157+
158+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
159+
rmdir(self, os.path.join(self.package_folder, "share"))
160+
161+
def _basic_module_definition(self, name):
162+
self.cpp_info.components[name].set_property("cmake_target_name", f"SFML::{name.capitalize()}")
163+
164+
libname = f"sfml-{name}"
165+
166+
if self.package_type == "static-library" and name != "main":
167+
libname += "-s"
168+
self.cpp_info.components[name].defines = ["SFML_STATIC"]
169+
if self.settings.build_type == "Debug":
170+
libname += "-d"
171+
self.cpp_info.components[name].libs = [libname]
172+
173+
# CMakeLists.txt#L87 - Android libs are in lib/<CMAKE_ANDROID_ARCH_ABI>
174+
if self.settings.os == "Android":
175+
self.cpp_info.components[name].libdirs = [os.path.join("lib", android_abi(self))]
176+
177+
def package_info(self):
178+
self.cpp_info.set_property("cmake_file_name", "SFML")
179+
self.cpp_info.set_property("pkg_config_name", "sfml-all")
180+
181+
modules = ["system"]
182+
if self.settings.os in ["Windows", "iOS", "Android"]:
183+
modules.append("main")
184+
185+
modules.extend(module for module in ["window", "graphics", "network", "audio"] if self.options.get_safe(module))
186+
187+
for module in modules:
188+
self._basic_module_definition(module)
189+
190+
# System module is always required
191+
if self.settings.os in ["Linux", "FreeBSD"]:
192+
self.cpp_info.components["system"].system_libs = ["pthread", "rt"]
193+
elif self.settings.os == "Windows":
194+
self.cpp_info.components["system"].system_libs = ["winmm"]
195+
elif self.settings.os == "Android":
196+
self.cpp_info.components["system"].system_libs = ["log", "android"]
197+
198+
if self.options.window:
199+
self.cpp_info.components["window"].requires = ["system", "vulkan-headers::vulkan-headers"]
200+
if self.settings.os in ["Linux", "FreeBSD"]:
201+
self.cpp_info.components["window"].system_libs.append("dl")
202+
self.cpp_info.components["window"].requires.extend(["xorg::x11", "xorg::xrandr", "xorg::xcursor", "xorg::xi"])
203+
204+
if self.settings.os == "iOS":
205+
self.cpp_info.components["window"].frameworks = ["OpenGLES"]
206+
elif self.settings.os == "Android":
207+
self.cpp_info.components["window"].system_libs.extend(["egl", "GLESv2"])
208+
else:
209+
self.cpp_info.components["window"].requires.append("opengl::opengl")
210+
211+
if self.settings.os == "Linux":
212+
self.cpp_info.components["window"].requires.append("libudev::libudev")
213+
elif self.settings.os == "Windows":
214+
self.cpp_info.components["window"].system_libs.extend(["gdi32", "winmm"])
215+
elif self.settings.os == "FreeBSD":
216+
self.cpp_info.components["window"].system_libs.append("usbhid")
217+
elif self.settings.os == "Macos":
218+
# CoreServices is pulled from Carbon, even if it does not show up in the upstream CMakeLists.txt
219+
self.cpp_info.components["window"].frameworks = ["Foundation", "AppKit", "IOKit", "Carbon", "CoreServices"]
220+
elif self.settings.os == "iOS":
221+
self.cpp_info.components["window"].frameworks = ["Foundation", "UIKit", "CoreGraphics", "QuartzCore", "CoreMotion"]
222+
elif self.settings.os == "Android":
223+
self.cpp_info.components["window"].system_libs = ["android"]
224+
225+
if self.options.graphics:
226+
self.cpp_info.components["graphics"].requires = ["window", "stb::stb"]
227+
if self.settings.os == "Android" or self.settings.os == "iOS":
228+
self.cpp_info.components["graphics"].requires.append("zlib::zlib")
229+
if self.settings.os == "iOS":
230+
self.cpp_info.components["graphics"].requires.append("bzip2::bzip2")
231+
self.cpp_info.components["graphics"].requires.append("freetype::freetype")
232+
233+
if self.options.network:
234+
self.cpp_info.components["network"].requires = ["system"]
235+
236+
if self.settings.os == "Windows":
237+
self.cpp_info.components["network"].system_libs = ["ws2_32"]
238+
239+
if self.options.audio:
240+
self.cpp_info.components["audio"].requires = ["vorbis::vorbis", "flac::flac", "system", "minimp3::minimp3", "miniaudio::miniaudio"]
241+
if self.settings.os == "iOS":
242+
self.cpp_info.components["audio"].frameworks = ["Foundation", "CoreFoundation", "CoreAudio", "AudioToolbox", "AVFoundation"]
243+
else:
244+
self.cpp_info.components["audio"].requires.extend(["vorbis::vorbisfile", "vorbis::vorbisenc"])
245+
246+
if self.settings.os == "Android":
247+
self.cpp_info.components["audio"].system_libs = ["android", "OpenSLES"]
248+
249+
if self.settings.os == "Linux":
250+
self.cpp_info.components["audio"].system_libs = ["pthread", "dl"]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt
2+
index 7567205..907c98c 100644
3+
--- a/src/SFML/Audio/CMakeLists.txt
4+
+++ b/src/SFML/Audio/CMakeLists.txt
5+
@@ -187,10 +187,12 @@ if(SFML_OS_IOS)
6+
endif()
7+
8+
# miniaudio sources
9+
-target_include_directories(sfml-audio SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/miniaudio")
10+
+find_package(miniaudio CONFIG REQUIRED)
11+
+target_link_libraries(sfml-audio PRIVATE miniaudio::miniaudio)
12+
13+
# minimp3 sources
14+
-target_include_directories(sfml-audio SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/minimp3")
15+
+find_package(minimp3 CONFIG REQUIRED)
16+
+target_link_libraries(sfml-audio PRIVATE minimp3::minimp3)
17+
18+
if(SFML_OS_ANDROID)
19+
target_link_libraries(sfml-audio PRIVATE android OpenSLES)
20+
diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt
21+
index 4886ac7..fe260fd 100644
22+
--- a/src/SFML/Graphics/CMakeLists.txt
23+
+++ b/src/SFML/Graphics/CMakeLists.txt
24+
@@ -93,7 +93,8 @@ sfml_add_library(Graphics
25+
target_link_libraries(sfml-graphics PUBLIC SFML::Window)
26+
27+
# stb_image sources
28+
-target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image")
29+
+find_package(stb CONFIG REQUIRED)
30+
+target_link_libraries(sfml-graphics PRIVATE stb::stb)
31+
32+
# glad sources
33+
target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/glad/include")
34+
diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt
35+
index ae9d90e..4af88b0 100644
36+
--- a/src/SFML/Window/CMakeLists.txt
37+
+++ b/src/SFML/Window/CMakeLists.txt
38+
@@ -292,7 +292,8 @@ if((NOT BUILD_SHARED_LIBS) AND SFML_OS_MACOS)
39+
endif()
40+
41+
# Vulkan headers
42+
-target_include_directories(sfml-window SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/vulkan")
43+
+find_package(VulkanHeaders REQUIRED CONFIG)
44+
+target_link_libraries(sfml-window PRIVATE Vulkan::Headers)
45+
46+
# CMake 3.11 and later prefer to choose GLVND, but we choose legacy OpenGL for backward compatibility
47+
# (unless the OpenGL_GL_PREFERENCE was explicitly set)
48+
diff --git a/src/SFML/Window/Unix/VulkanImplX11.cpp b/src/SFML/Window/Unix/VulkanImplX11.cpp
49+
index a991c6a..51e86dc 100644
50+
--- a/src/SFML/Window/Unix/VulkanImplX11.cpp
51+
+++ b/src/SFML/Window/Unix/VulkanImplX11.cpp
52+
@@ -36,7 +36,7 @@
53+
54+
#define VK_USE_PLATFORM_XLIB_KHR
55+
#define VK_NO_PROTOTYPES
56+
-#include <vulkan.h>
57+
+#include <vulkan/vulkan.h>
58+
59+
60+
namespace
61+
diff --git a/src/SFML/Window/Win32/VulkanImplWin32.cpp b/src/SFML/Window/Win32/VulkanImplWin32.cpp
62+
index 6e83b2d..5cde97d 100644
63+
--- a/src/SFML/Window/Win32/VulkanImplWin32.cpp
64+
+++ b/src/SFML/Window/Win32/VulkanImplWin32.cpp
65+
@@ -35,7 +35,7 @@
66+
67+
#define VK_USE_PLATFORM_WIN32_KHR
68+
#define VK_NO_PROTOTYPES
69+
-#include <vulkan.h>
70+
+#include <vulkan/vulkan.h>
71+
72+
73+
namespace
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
add_executable(${PROJECT_NAME} test_package.cpp)
5+
6+
set(SFML_COMPONENTS SFML::System)
7+
set(SFML_TARGETS SFML::System)
8+
if(SFML_WITH_WINDOW)
9+
target_compile_definitions(${PROJECT_NAME} PRIVATE SFML_WITH_WINDOW)
10+
list(APPEND SFML_COMPONENTS SFML::Window)
11+
list(APPEND SFML_TARGETS SFML::Window)
12+
endif()
13+
if(SFML_WITH_GRAPHICS)
14+
target_compile_definitions(${PROJECT_NAME} PRIVATE SFML_WITH_GRAPHICS)
15+
list(APPEND SFML_COMPONENTS SFML::Graphics)
16+
list(APPEND SFML_TARGETS SFML::Graphics)
17+
endif()
18+
if(SFML_WITH_NETWORK)
19+
target_compile_definitions(${PROJECT_NAME} PRIVATE SFML_WITH_NETWORK)
20+
list(APPEND SFML_COMPONENTS SFML::Network)
21+
list(APPEND SFML_TARGETS SFML::Network)
22+
endif()
23+
if(SFML_WITH_AUDIO)
24+
target_compile_definitions(${PROJECT_NAME} PRIVATE SFML_WITH_AUDIO)
25+
list(APPEND SFML_COMPONENTS SFML::Audio)
26+
list(APPEND SFML_TARGETS SFML::Audio)
27+
endif()
28+
29+
find_package(SFML REQUIRED ${SFML_COMPONENTS} CONFIG)
30+
target_link_libraries(${PROJECT_NAME} PRIVATE ${SFML_TARGETS})

0 commit comments

Comments
 (0)