diff options
| author | ruki <[email protected]> | 2022-10-17 22:39:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-10-17 22:39:59 +0800 |
| commit | 5692805fd0bb1aa70cd6965de83068db60743b34 (patch) | |
| tree | 1eca354f261b15ee4b1b76dc8068d5f8b811c320 | |
| parent | 81b97b43fab70ef64fda83986d7b90de6721cb70 (diff) | |
add components tests
| -rwxr-xr-x | tests/projects/package/components/src/graphics.cpp | 8 | ||||
| -rw-r--r-- | tests/projects/package/components/src/main.cpp | 14 | ||||
| -rwxr-xr-x | tests/projects/package/components/src/network.cpp | 14 | ||||
| -rw-r--r-- | tests/projects/package/components/test.lua | 12 | ||||
| -rw-r--r-- | tests/projects/package/components/xmake.lua | 201 |
5 files changed, 249 insertions, 0 deletions
diff --git a/tests/projects/package/components/src/graphics.cpp b/tests/projects/package/components/src/graphics.cpp new file mode 100755 index 000000000..bc081a517 --- /dev/null +++ b/tests/projects/package/components/src/graphics.cpp @@ -0,0 +1,8 @@ +#include <SFML/Graphics.hpp> + +extern "C" { +void graphics() { + sf::Text text; + text.setString("Hello world"); +} +} diff --git a/tests/projects/package/components/src/main.cpp b/tests/projects/package/components/src/main.cpp new file mode 100644 index 000000000..bf0ad1553 --- /dev/null +++ b/tests/projects/package/components/src/main.cpp @@ -0,0 +1,14 @@ +#include <SFML/Graphics.hpp> +#include <SFML/Network.hpp> + +extern "C" { +void network(); +void graphics(); +} + +int main(int argc, char** argv) { + network(); + graphics(); + return 0; +} + diff --git a/tests/projects/package/components/src/network.cpp b/tests/projects/package/components/src/network.cpp new file mode 100755 index 000000000..503fd5e31 --- /dev/null +++ b/tests/projects/package/components/src/network.cpp @@ -0,0 +1,14 @@ +#include <SFML/Network.hpp> + +extern "C" { +void network() { + sf::UdpSocket socket; + socket.bind(54000); + + char data[100]; + std::size_t received; + sf::IpAddress sender; + unsigned short port; + socket.receive(data, 100, received, sender, port); +} +} diff --git a/tests/projects/package/components/test.lua b/tests/projects/package/components/test.lua new file mode 100644 index 000000000..4964fecaa --- /dev/null +++ b/tests/projects/package/components/test.lua @@ -0,0 +1,12 @@ +function main(t) + + -- freebsd ci is slower + if is_host("bsd") then + return + end + + -- only for x86/x64, because it will take too long time on ci with arm/mips + if os.subarch():startswith("x") or os.subarch() == "i386" then + t:build() + end +end diff --git a/tests/projects/package/components/xmake.lua b/tests/projects/package/components/xmake.lua new file mode 100644 index 000000000..17b8b4d04 --- /dev/null +++ b/tests/projects/package/components/xmake.lua @@ -0,0 +1,201 @@ +add_rules("mode.debug", "mode.release") + +add_requires("sfml") + +target("graphics") + set_kind("static") + add_files("src/graphics.cpp") + add_packages("sfml", {public = true}) + +target("network") + set_kind("static") + add_files("src/network.cpp") + add_packages("sfml", {public = true}) + +target("test") + set_kind("binary") + add_files("src/main.cpp") + add_deps("graphics", "network") + +package("sfml") + + set_homepage("https://www.sfml-dev.org") + set_description("Simple and Fast Multimedia Library") + + 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_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 + end + + if is_plat("linux") then + add_syslinks("pthread") + end + + 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"}) + end + + on_load("windows", "linux", "macosx", "mingw", function (package) + if package:is_plat("windows", "linux") then + package:add("deps", "cmake") + end + + if not package:config("shared") then + package:add("defines", "SFML_STATIC") + end + + local e = "" + local a = "sfml-" + if not package:config("shared") then + e = "-s" + end + if package:debug() then + e = e .. "-d" + end + local main_module = a .. "main" + if package:debug() then + main_module = main_module .. "-d" + end + + if package:config("graphics") then + package:add("links", a .. "graphics" .. e) + if package:is_plat("windows", "mingw") and not package:config("shared") then + package:add("links", "freetype") + end + end + if package:config("window") or package:config("graphics") then + package:add("links", a .. "window" .. e) + if package:is_plat("windows", "mingw") and not package:config("shared") then + package:add("syslinks", "opengl32", "gdi32", "user32", "advapi32") + end + if package:is_plat("linux") then + package:add("deps", "libx11", "libxext", "libxrandr", "libxrender", "freetype", "eudev") + package:add("deps", "opengl", "glx", {optional = true}) + end + end + if package:config("audio") then + package:add("links", a .. "audio" .. e) + if package:is_plat("windows", "mingw") and not package:config("shared") then + package:add("links", "openal32", "flac", "vorbisenc", "vorbisfile", "vorbis", "ogg") + elseif package:is_plat("linux") then + package:add("deps", "libogg", "libflac", "libvorbis", "openal-soft") + end + end + if package:config("network") then + package:add("links", a .. "network" .. e) + if package:is_plat("windows", "mingw") and not package:config("shared") then + package:add("syslinks", "ws2_32") + end + end + if package:is_plat("windows", "mingw") and package:config("main") then + package:add("links", main_module) + end + package:add("links", a .. "system" .. e) + if package:is_plat("windows", "mingw") then + package:add("syslinks", "winmm") + end + end) + + on_install("windows", "linux", 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") + else + table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") + if package:is_plat("windows") and package:config("vs_runtime"):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"} + 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) + + 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"}) + end + end) + + on_test(function (package) + assert(package:check_cxxsnippets({test = [[ + void test(int args, char** argv) { + sf::Clock c; + c.restart(); + } + ]]}, {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"); + } + ]]}, {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::Event event; + window.pollEvent(event); + } + ]]}, {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"); + music.play(); + } + ]]}, {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); + + char data[100]; + std::size_t received; + sf::IpAddress sender; + unsigned short port; + socket.receive(data, 100, received, sender, port); + } + ]]}, {includes = "SFML/Network.hpp"})) + end + end) +package_end() |
