diff options
| author | ruki <[email protected]> | 2025-07-14 22:27:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-07-14 22:27:01 +0800 |
| commit | de2b17c8dd59b886c067068a864f3c44f45320f7 (patch) | |
| tree | 4850eda4bb8f55a3902e5cf7fdf269ec7341a1ef /tests/projects | |
| parent | 6c19713835849ac96f7eb8a2c67b19d0381749ed (diff) | |
fix sfml tests
Diffstat (limited to 'tests/projects')
| -rw-r--r-- | tests/projects/package/components/xmake.lua | 242 |
1 files changed, 163 insertions, 79 deletions
diff --git a/tests/projects/package/components/xmake.lua b/tests/projects/package/components/xmake.lua index 14dbe472d..08ea6d7ca 100644 --- a/tests/projects/package/components/xmake.lua +++ b/tests/projects/package/components/xmake.lua @@ -18,60 +18,52 @@ target("test") add_deps("graphics", "network") package("sfml") - set_homepage("https://www.sfml-dev.org") set_description("Simple and Fast Multimedia Library") + set_license("zlib") - if is_plat("windows", "linux") then - set_urls("https://www.sfml-dev.org/files/SFML-$(version)-sources.zip") - add_urls("https://github.com/SFML/SFML/releases/download/$(version)/SFML-$(version)-sources.zip") - add_versions("2.5.1", "bf1e0643acb92369b24572b703473af60bac82caf5af61e77c063b779471bb7f") - elseif is_plat("macosx") then - if is_arch("x64", "x86_64") then - set_urls("https://www.sfml-dev.org/files/SFML-$(version)-macOS-clang.tar.gz") - add_versions("2.5.1", "6af0f14fbd41dc038a00d7709f26fb66bb7ccdfe6187657ef0ef8cba578dcf14") + add_urls("https://github.com/SFML/SFML/archive/refs/tags/$(version).tar.gz", + "https://github.com/SFML/SFML.git") - add_configs("debug", {builtin = true, description = "Enable debug symbols.", default = false, type = "boolean", readonly = true}) - add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true}) - end - elseif is_plat("mingw") then - if is_arch("x64", "x86_64") then - set_urls("https://www.sfml-dev.org/files/SFML-$(version)-windows-gcc-7.3.0-mingw-64-bit.zip") - add_versions("2.5.1", "671e786f1af934c488cb22c634251c8c8bd441c709b4ef7bc6bbe227b2a28560") - elseif is_arch("x86", "i386") then - set_urls("https://www.sfml-dev.org/files/SFML-$(version)-windows-gcc-7.3.0-mingw-32-bit.zip") - add_versions("2.5.1", "92d864c9c9094dc9d91e0006d66784f25ac900a8ee23c3f79db626de46a1d9d8") - end + -- Before 2.6.0 only x86 is supported for Mac + if not is_plat("macosx") or not is_arch("arm.*") then + add_versions("2.5.1", "438c91a917cc8aa19e82c6f59f8714da353c488584a007d401efac8368e1c785") end - if is_plat("linux") then - add_syslinks("pthread") - end + add_versions("3.0.1", "f99f71bb2f2608835b1a37e078512b75dd39d52b89e13e12246603a950da3c1f") + add_versions("3.0.0", "37506fafbd618b1f8e153bbca8811e62203a70b32a1183279fb9612fd0501d2b") + add_versions("2.6.1", "82535db9e57105d4f3a8aedabd138631defaedc593cab589c924b7d7a11ffb9d") + add_versions("2.6.0", "0c3f84898ea1db07dc46fa92e85038d8c449e3c8653fe09997383173de96bc06") add_configs("graphics", {description = "Use the graphics module", default = true, type = "boolean"}) add_configs("window", {description = "Use the window module", default = true, type = "boolean"}) add_configs("audio", {description = "Use the audio module", default = true, type = "boolean"}) add_configs("network", {description = "Use the network module", default = true, type = "boolean"}) if is_plat("windows", "mingw") then - add_configs("main", {description = "Link to the sfml-main library", default = true, type = "boolean"}) + add_configs("main", {description = "Link to the sfml-main library", default = true, type = "boolean"}) end - if is_plat("macosx") then + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::sfml") + elseif is_plat("linux") then + add_extsources("pacman::sfml", "apt::libsfml-dev") + elseif is_plat("macosx") then add_extsources("brew::sfml/sfml-all") end + if not is_host("windows") then + add_extsources("pkgconfig::sfml-all") + end + on_component("graphics", function (package, component) local e = package:config("shared") and "" or "-s" if package:debug() then e = e .. "-d" end component:add("links", "sfml-graphics" .. e) - if package:is_plat("windows", "mingw") and not package:config("shared") then - component:add("links", "freetype") - component:add("syslinks", "opengl32", "gdi32", "user32", "advapi32") - end component:add("deps", "window", "system") component:add("extsources", "brew::sfml/sfml-graphics") + component:add("extsources", "pkgconfig::sfml-graphics") end) on_component("window", function (package, component) @@ -80,11 +72,22 @@ package("sfml") e = e .. "-d" end component:add("links", "sfml-window" .. e) - if package:is_plat("windows", "mingw") and not package:config("shared") then - component:add("syslinks", "opengl32", "gdi32", "user32", "advapi32") - end component:add("deps", "system") component:add("extsources", "brew::sfml/sfml-window") + component:add("extsources", "pkgconfig::sfml-window") + if not package:config("shared") then + if package:is_plat("windows", "mingw") then + component:add("syslinks", "opengl32", "gdi32", "advapi32", "user32") + elseif package:is_plat("linux") then + component:add("syslinks", "dl") + elseif package:is_plat("bsd") then + component:add("syslinks", "usbhid") + elseif package:is_plat("macosx") then + component:add("frameworks", "Foundation", "AppKit", "IOKit", "Carbon") + elseif package:is_plat("iphoneos") then + component:add("frameworks", "Foundation", "UIKit", "CoreGraphics", "QuartzCore", "CoreMotion") + end + end end) on_component("audio", function (package, component) @@ -93,11 +96,15 @@ package("sfml") e = e .. "-d" end component:add("links", "sfml-audio" .. e) - if package:is_plat("windows", "mingw") and not package:config("shared") then - component:add("links", "openal32", "flac", "vorbisenc", "vorbisfile", "vorbis", "ogg") - end component:add("deps", "system") component:add("extsources", "brew::sfml/sfml-audio") + component:add("extsources", "pkgconfig::sfml-audio") + if not package:config("shared") and package:is_plat("windows", "mingw") then + component:add("links", "flac", "vorbisenc", "vorbisfile", "vorbis", "ogg") + if not (package:gitref() or package:version():ge("3.0.0")) then + component:add("links", "openal32") + end + end end) on_component("network", function (package, component) @@ -106,12 +113,13 @@ package("sfml") e = e .. "-d" end component:add("links", "sfml-network" .. e) - if package:is_plat("windows", "mingw") and not package:config("shared") then - component:add("syslinks", "ws2_32") - end component:add("deps", "system") component:add("extsources", "brew::sfml/sfml-network") + component:add("extsources", "pkgconfig::sfml-network") component:add("extsources", "apt::sfml-network") + if not package:config("shared") and package:is_plat("windows", "mingw") then + component:add("syslinks", "ws2_32") + end end) on_component("system", function (package, component) @@ -127,6 +135,16 @@ package("sfml") component:add("deps", "main") end component:add("extsources", "brew::sfml/sfml-system") + component:add("extsources", "pkgconfig::sfml-system") + if not package:config("shared") then + if package:is_plat("windows", "mingw") then + component:add("syslinks", "winmm") + elseif package:is_plat("linux") then + component:add("syslinks", "rt", "pthread") + elseif package:is_plat("bsd", "macosx") then + component:add("syslinks", "pthread") + end + end end) on_component("main", function (package, component) @@ -140,7 +158,7 @@ package("sfml") end) on_load("windows", "linux", "macosx", "mingw", function (package) - if package:is_plat("windows", "linux") then + if package:is_plat("windows", "linux", "macosx") then package:add("deps", "cmake") end @@ -148,105 +166,171 @@ package("sfml") package:add("defines", "SFML_STATIC") end + if package:config("graphics") then + package:add("deps", "freetype") + end + if package:is_plat("linux") then if package:config("window") or package:config("graphics") then - package:add("deps", "libx11", "libxext", "libxrandr", "libxrender", "freetype", "eudev") + package:add("deps", "libx11", "libxcursor", "libxrandr", "libxrender", "libxfixes", "libxext", "eudev", "libxi") package:add("deps", "opengl", "glx", {optional = true}) end - if package:config("audio") then - package:add("deps", "libogg", "libflac", "libvorbis", "openal-soft") + end + + if package:config("audio") then + package:add("deps", "libogg", "libflac", "libvorbis") + if not (package:gitref() or package:version():ge("3.0.0")) then + package:add("deps", "openal-soft") end end + package:add("components", "system") for _, component in ipairs({"graphics", "window", "audio", "network"}) do if package:config(component) then package:add("components", component) end end + if package:is_plat("windows", "mingw") and package:config("main") then package:add("components", "main") end end) - on_install("windows", "linux", function (package) + on_install("windows", "linux", "macosx", "mingw", function (package) local configs = {"-DSFML_BUILD_DOC=OFF", "-DSFML_BUILD_EXAMPLES=OFF"} table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) if package:config("shared") then table.insert(configs, "-DBUILD_SHARED_LIBS=ON") + -- Fix missing system libs + if package:config("audio") and not (package:gitref() or package:version():ge("3.0.0")) then + if package:is_plat("windows", "mingw") then + local file = io.open("src/SFML/Audio/CMakeLists.txt", "a") + file:print("target_link_libraries(OpenAL INTERFACE winmm)") + file:close() + end + end + if package:config("graphics") then + local freetype = package:dep("freetype") + if freetype then + local fetchinfo = freetype:fetch() + if fetchinfo then + if not freetype:config("shared") then + local libfiles = {} + for _, dep in ipairs(freetype:librarydeps()) do + local depinfo = dep:fetch() + if depinfo then + table.join2(libfiles, depinfo.libfiles) + end + end + if #libfiles > 0 then + local libraries = {} + for _, libfile in ipairs(libfiles) do + table.insert(libraries, (libfile:gsub("\\", "/"))) + end + local lib_name = (package:gitref() or package:version():ge("3.0.0")) and "freetype" or "Freetype" + local file = io.open("src/SFML/Graphics/CMakeLists.txt", "a") + file:print("target_link_libraries(%s INTERFACE %s)", lib_name, table.concat(libraries, " ")) + file:close() + end + end + end + end + end + if package:config("window") and package:is_plat("linux") then + local libfiles = {} + for _, name in ipairs({"libx11", "libxcursor", "libxrandr", "libxrender", "libxfixes", "libxext"}) do + local dep = package:dep(name) + if dep then + local fetchinfo = dep:fetch() + if fetchinfo then + table.join2(libfiles, fetchinfo.libfiles) + end + end + end + if #libfiles > 0 then + libfiles = table.reverse_unique(libfiles) + local libraries = {} + for _, libfile in ipairs(libfiles) do + table.insert(libraries, (libfile:gsub("\\", "/"))) + end + local file = io.open("src/SFML/Window/CMakeLists.txt", "a") + file:print("target_link_libraries(sfml-window PRIVATE " .. table.concat(libraries, " ") .. ")") + file:close() + end + end else table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") - if package:is_plat("windows") and package:runtimes():startswith("MT") then - table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=ON") - end - end - local packagedeps - if package:is_plat("linux") and package:config("shared") then - io.replace("src/SFML/Graphics/CMakeLists.txt", "target_link_libraries(sfml-graphics PRIVATE X11)", - "target_link_libraries(sfml-graphics PRIVATE X11 Xext Xrender)", {plain = true}) - packagedeps = {"libxext", "libxrender"} + -- SFML overrides MSVC runtimes if set to ON, xmake already takes cares of setting it + table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=OFF") end table.insert(configs, "-DSFML_BUILD_AUDIO=" .. (package:config("audio") and "ON" or "OFF")) table.insert(configs, "-DSFML_BUILD_GRAPHICS=" .. (package:config("graphics") and "ON" or "OFF")) table.insert(configs, "-DSFML_BUILD_WINDOW=" .. (package:config("window") and "ON" or "OFF")) table.insert(configs, "-DSFML_BUILD_NETWORK=" .. (package:config("network") and "ON" or "OFF")) - import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps}) - end) + table.insert(configs, "-DWARNINGS_AS_ERRORS=OFF") + if not is_plat("mingw") then + table.insert(configs, "-DSFML_USE_SYSTEM_DEPS=TRUE") + end + if package:gitref() or package:version():ge("3.0.0") then + table.insert(configs, "-DCMAKE_CXX_STANDARD=17") + end - on_install("macosx", "mingw", function (package) - os.cp("lib", package:installdir()) - os.cp("include", package:installdir()) - if package:is_plat("mingw") then - os.cp("bin/*", package:installdir("lib"), {rootdir = "bin"}) + local packagedeps + if package:config("audio") and not (package:gitref() or package:version():ge("3.0.0")) then + packagedeps = packagedeps or {} + table.insert(packagedeps, "openal-soft") + end + if package:config("graphics") then + packagedeps = packagedeps or {} + table.insert(packagedeps, "freetype") + table.insert(packagedeps, "zlib") end + + import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps}) end) on_test(function (package) + local configs = (package:gitref() or package:version():ge("3.0.0")) and {languages = "c++17"} or {} assert(package:check_cxxsnippets({test = [[ void test(int args, char** argv) { sf::Clock c; c.restart(); } - ]]}, {includes = "SFML/System.hpp"})) + ]]}, {configs = configs, includes = "SFML/System.hpp"})) if package:config("graphics") then assert(package:check_cxxsnippets({test = [[ - void test(int args, char** argv) { - sf::Text text; - text.setString("Hello world"); + void test(const sf::Texture& texture, const sf::Color& color) { + sf::Sprite sprite(texture); + sprite.setColor(color); } - ]]}, {includes = "SFML/Graphics.hpp"})) + ]]}, {configs = configs, includes = "SFML/Graphics.hpp"})) end if package:config("window") or package:config("graphics") then assert(package:check_cxxsnippets({test = [[ void test(int args, char** argv) { - sf::Window window(sf::VideoMode(1280, 720), "Title"); + sf::Window window(sf::VideoMode(), "Title"); - sf::Event event; - window.pollEvent(event); + window.close(); } - ]]}, {includes = "SFML/Window.hpp"})) + ]]}, {configs = configs, includes = "SFML/Window.hpp"})) end if package:config("audio") then assert(package:check_cxxsnippets({test = [[ void test(int args, char** argv) { sf::Music music; - music.openFromFile("music.ogg"); + auto res = music.openFromFile("music.ogg"); music.play(); } - ]]}, {includes = "SFML/Audio.hpp"})) + ]]}, {configs = configs, includes = "SFML/Audio.hpp"})) end if package:config("network") then assert(package:check_cxxsnippets({test = [[ - void test(int args, char** argv) { - sf::UdpSocket socket; - socket.bind(54000); - + void test(sf::UdpSocket& socket, const sf::IpAddress& remoteAddress) { char data[100]; - std::size_t received; - sf::IpAddress sender; - unsigned short port; - socket.receive(data, 100, received, sender, port); + unsigned short remotePort = 54000; + auto status = socket.send(data, 100, remoteAddress, remotePort); } - ]]}, {includes = "SFML/Network.hpp"})) + ]]}, {configs = configs, includes = "SFML/Network.hpp"})) end end) package_end() |
