浏览代码

add directxmath and directx-headers (#2350)

* add directx-headers

* add directxmath

* fix directx-headers on mingw

* fix cmake
Hoildkv 2 年之前
父节点
当前提交
346dfc7908

+ 33 - 0
packages/d/directx-headers/patches/1.610.0/mingw.patch

@@ -0,0 +1,33 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 9f90c8d..5ce5651 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -39,19 +39,25 @@ target_include_directories(DirectX-Headers SYSTEM PUBLIC
+ )
+ target_include_directories(DirectX-Headers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/directx)
+ 
++add_library(DirectX-Guids STATIC src/dxguids.cpp)
++target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers)
++
+ # For non-Windows targets, also add the WSL stubs to the include path
+ if (NOT WIN32)
+     target_include_directories(DirectX-Headers SYSTEM PUBLIC
+         "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/wsl/stubs>"
+         "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/wsl/stubs>"
+     )
++elseif((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
++    # MinGW has RPC headers which define old versions, and complain if D3D
++    # headers are included before the RPC headers, since D3D headers were
++    # generated with new MIDL and "require" new RPC headers.
++   target_compile_options(DirectX-Headers PRIVATE "-D__REQUIRED_RPCNDR_H_VERSION__=475")
++   target_compile_options(DirectX-Guids PRIVATE "-D__REQUIRED_RPCNDR_H_VERSION__=475")
+ endif()
+ 
+ add_library(Microsoft::DirectX-Headers ALIAS DirectX-Headers)
+ 
+-add_library(DirectX-Guids STATIC src/dxguids.cpp)
+-target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers)
+-
+ add_library(Microsoft::DirectX-Guids ALIAS DirectX-Guids)
+ 
+ if (DXHEADERS_INSTALL)

+ 28 - 0
packages/d/directx-headers/xmake.lua

@@ -0,0 +1,28 @@
+package("directx-headers")
+
+    set_homepage("https://github.com/microsoft/DirectX-Headers")
+    set_description("Official DirectX headers")
+    set_license("MIT")
+
+    add_urls("https://github.com/microsoft/DirectX-Headers/archive/refs/tags/$(version).zip",
+             "https://github.com/microsoft/DirectX-Headers.git")
+    add_versions("v1.610.0", "ce8036d57e4b3b87167bf82a0236fc09cba4ffa7088322912b8ce82f284555db")
+
+    add_patches("1.610.0", path.join(os.scriptdir(), "patches", "1.610.0", "mingw.patch"), "7409d90adb1513e8683cc6d16aba1a3e73643c3e04b9af70474a5b13323be0fb")
+
+    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+
+    add_deps("cmake")
+    if is_plat("mingw") then
+        add_defines("__REQUIRED_RPCNDR_H_VERSION__=475")
+    end
+
+    on_install("windows", "mingw", function (package)
+        local configs = {"-DDXHEADERS_BUILD_TEST=OFF", "-DDXHEADERS_BUILD_GOOGLE_TEST=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:has_cxxtypes("CD3DX12FeatureSupport", {configs = {languages = "cxx14"}, includes = "directx/d3dx12.h"}))
+    end)

+ 29 - 0
packages/d/directxmath/xmake.lua

@@ -0,0 +1,29 @@
+package("directxmath")
+
+    set_kind("library", {headeronly = true})
+    set_homepage("https://github.com/microsoft/DirectXMath")
+    set_description("DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps.")
+    set_license("MIT")
+
+    local tag = {
+        ["2022.12"] = "dec2022",
+    }
+    add_urls("https://github.com/microsoft/DirectXMath/archive/refs/tags/$(version).zip", {version = function (version) return tag[tostring(version)] end})
+    add_urls("https://github.com/microsoft/DirectXMath.git")
+    add_versions("2022.12", "2ed0ae7d7fe5d11ad11f6d3d9b31ce686024a551cf82ade723de86aa7b4b57e1")
+
+    add_deps("cmake")
+    add_includedirs("include/directxmath")
+    on_install("windows", "mingw", function (package)
+        import("package.tools.cmake").install(package, {"-DBUILD_TESTING=OFF"})
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            void test() {
+                DirectX::XMVECTOR v = DirectX::XMVectorSet(1.0f, 2.0f, 3.0f, 4.0f);
+                DirectX::XMMATRIX m = DirectX::XMMatrixIdentity();
+                DirectX::XMVECTOR vResult = DirectX::XMVector4Transform(v, m);
+            }
+        ]]}, {configs = {languages = "cxx17"}, includes = "DirectXMath.h"}))
+    end)