Bladeren bron

omath: update to 3.8.1 (#8277)

* omath:update to 3.8.1

* fixup

* check if old workaround work for cross builds

* revert

* try repair imgui at same time for cross 32 bit

* fixup

* fixup

* fixup

* fixup

* fixup
Saikari 2 maanden geleden
bovenliggende
commit
e6a03aaa04
3 gewijzigde bestanden met toevoegingen van 82 en 26 verwijderingen
  1. 6 0
      packages/i/imgui/xmake.lua
  2. 58 0
      packages/o/omath/patches/v3.8.1/fix-build.patch
  3. 18 26
      packages/o/omath/xmake.lua

+ 6 - 0
packages/i/imgui/xmake.lua

@@ -214,6 +214,12 @@ package("imgui")
 
         os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
         import("package.tools.xmake").install(package, configs)
+        local config_version_file = path.join(package:installdir("lib"), "cmake", "imgui", "imguiConfigVersion.cmake")
+        if package:is_plat("cross") and package:check_sizeof("void*") == "4" and os.exists(config_version_file) then
+            io.replace(config_version_file, [[if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")]], [[if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "4" STREQUAL "")]], {plain = true})
+            io.replace(config_version_file, [[if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")]], [[if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "4")]], {plain = true})
+            io.replace(config_version_file, [[math(EXPR installedBits "8 * 8")]], [[math(EXPR installedBits "4 * 8")]], {plain = true})
+        end
     end)
 
     on_test(function (package)

+ 58 - 0
packages/o/omath/patches/v3.8.1/fix-build.patch

@@ -0,0 +1,58 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 18c1b45..e46eb56 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -3,19 +3,29 @@ cmake_minimum_required(VERSION 3.26)
+ project(omath VERSION 3.5.0 LANGUAGES CXX)
+ 
+ include(CMakePackageConfigHelpers)
++include(CheckCXXCompilerFlag)
+ 
++if (MSVC)
++    check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
++else ()
++    check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
++endif ()
+ 
+ option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
+ option(OMATH_BUILD_BENCHMARK "Build benchmarks" ${PROJECT_IS_TOP_LEVEL})
+ option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
+ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
+-option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
++option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ${COMPILER_SUPPORTS_AVX2})
+ option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
+ option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
+ option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
+ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
+ option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
+ option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF)
++if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2)
++    message(WARNING "OMATH_USE_AVX2 requested, but compiler/target does not support AVX2. Disabling.")
++    set(OMATH_USE_AVX2 OFF CACHE BOOL "Omath will use AVX2 to boost performance" FORCE)
++endif ()
+ 
+ message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}, compiler ${CMAKE_CXX_COMPILER_ID}")
+ message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
+@@ -93,13 +103,18 @@ if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
+     )
+ endif ()
+ 
+-if (OMATH_USE_AVX2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+-    target_compile_options(${PROJECT_NAME} PUBLIC -mavx2 -mavx -mfma)
+-endif ()
++if (OMATH_USE_AVX2)
++    if (MSVC)
++        target_compile_options(${PROJECT_NAME} PUBLIC /ARCH:AVX2)
++    elseif (EMSCRIPTEN)
++        target_compile_options(${PROJECT_NAME} PUBLIC -msimd128 -mavx2)
++    elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
++        target_compile_options(${PROJECT_NAME} PUBLIC -mfma -mavx2)
++    endif()
++endif()
+ 
+ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
+ 
+-add_subdirectory(extlibs)
+ 
+ 
+ if (OMATH_BUILD_TESTS)

+ 18 - 26
packages/o/omath/xmake.lua

@@ -6,17 +6,16 @@ package("omath")
     add_urls("https://github.com/orange-cpp/omath/archive/refs/tags/$(version).tar.gz",
              "https://github.com/orange-cpp/omath.git", {submodules = false})
 
-    add_versions("v3.0.3", "f72ec671eb99d83bf6d63ec5eee7436110a9f340b416eefac51464665bbda06c")
+    add_versions("v3.8.1", "aaea99570c382478f825af759a2b0a214b429c74a9a5492ddd2866c836e85f4e")
 
-    add_configs("avx2",  {description = "Enable AVX2", default = true, type = "boolean"})
+    add_patches("v3.8.1", "patches/v3.8.1/fix-build.patch", "c1554cf0cdd027d6386544871d6248c868f8f95add343660334888da52119ae9")
+
+    if is_arch("x86_64", "x64", "x86", "i386", "i686") then
+        add_configs("avx2",  {description = "Enable AVX2", default = true, type = "boolean"})
+    end
     add_configs("imgui", {description = "Define method to convert omath types to imgui types", default = true, type = "boolean"})
 
     add_deps("cmake")
-    if is_plat("windows") then
-        add_deps("pkgconf")
-    else
-        add_deps("pkg-config")
-    end
 
     on_load(function (package)
         if package:config("imgui") then
@@ -25,24 +24,12 @@ package("omath")
     end)
 
     on_install("!macosx and !iphoneos and !android and !bsd", function (package)
-        if package:config("imgui") then
-            local imgui = package:dep("imgui")
-            if imgui and not imgui:is_system() then
-                local imgui_fetch = imgui:fetch()
-                if imgui_fetch then
-                    for _, inc in ipairs(imgui_fetch.includedirs or imgui_fetch.sysincludedirs) do
-                        os.mkdir(inc)
-                    end
-                end
-            end
-        end
-        io.replace("CMakeLists.txt", [[find_package(imgui CONFIG REQUIRED)]], [[include(FindPkgConfig)
-pkg_search_module("imgui" REQUIRED IMPORTED_TARGET "imgui")]], {plain = true})
-        io.replace("CMakeLists.txt", [[imgui::imgui]], [[PkgConfig::imgui]], {plain = true})
-        if package:is_plat("wasm") then
-            io.replace("CMakeLists.txt", [[target_compile_options(${PROJECT_NAME} PRIVATE -mavx2 -mfma)]], [[target_compile_options(${PROJECT_NAME} PRIVATE -msimd128 -mavx2)]], {plain = true})
-        end
-        local configs = {"-DOMATH_THREAT_WARNING_AS_ERROR=OFF", "-DOMATH_BUILD_TESTS=OFF"}
+        local configs = {
+            "-DOMATH_BUILD_TESTS=OFF",
+            "-DOMATH_BUILD_BENCHMARK=OFF",
+            "-DOMATH_THREAT_WARNING_AS_ERROR=OFF",
+            "-DOMATH_BUILD_EXAMPLES=OFF",
+        }
         table.insert(configs, "-DOMATH_USE_AVX2=" .. (package:config("avx2") and "ON" or "OFF"))
         table.insert(configs, "-DOMATH_IMGUI_INTEGRATION=" .. (package:config("imgui") and "ON" or "OFF"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
@@ -52,8 +39,13 @@ pkg_search_module("imgui" REQUIRED IMPORTED_TARGET "imgui")]], {plain = true})
 
     on_test(function (package)
         assert(package:check_cxxsnippets({test = [[
+            #if __has_include(<omath/omath.hpp>)
+                #include <omath/omath.hpp>
+            #else
+                #include <omath/vector2.hpp>
+            #endif
             void test() {
                 omath::Vector2 w = omath::Vector2(20.0, 30.0);
             }
-        ]]}, {configs = {languages = "c++23"}, includes = "omath/vector2.hpp"}))
+        ]]}, {configs = {languages = "c++23"}}))
     end)