Skip to content

Commit

Permalink
[directxtex] Use CMake build system, add OpenEXR support and dx12 fea…
Browse files Browse the repository at this point in the history
…ture (#13969)

* [directxtex] Use CMake build system and add OpenEXR support

Use the provided CMake file instead of the VS solutions to build the library, as recommended in the vcpkg maintainer guide.

Also add the openexr feature to enable OpenEXR in the library and its tools.
https://github.com/Microsoft/DirectXTex/wiki/Adding-OpenEXR

* [directxtex] Fix build failure on ARM and UWP

* [directxtex] Use vcpkg_copy_tools

* [directxtex] Add win7 feature

DirectXTex can be build without DirectX12 to support Windows 7 Service Pack 1 or later platforms, so I added this as a feature.

* [directxtex] Replace win7 with dx12 feature

* [directxrex] Shorten patch file

* [directxtex] Fix wrong port version

* [directxtex] Use ninja
  • Loading branch information
RT2Code committed Oct 13, 2020
1 parent b1517c9 commit 17b23ee
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 48 deletions.
10 changes: 9 additions & 1 deletion ports/directxtex/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Source: directxtex
Version: sept2020
Port-Version: 1
Homepage: https://walbourn.github.io/directxtex
Description: DirectXTex texture processing library
Description: DirectXTex texture processing library

Feature: dx12
Description: Build with DirectX12 support for Windows 10

Feature: openexr
Description: Enable OpenEXR support
Build-Depends: openexr
107 changes: 107 additions & 0 deletions ports/directxtex/enable_openexr_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 53b41a3..84867f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,9 @@ option(BC_USE_OPENMP "Build with OpenMP support" ON)

option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)

+# Includes the functions for loading/saving OpenEXR files at runtime
+option(ENABLE_OPENEXR_SUPPORT "Build with OpenEXR support" OFF)
+
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -67,6 +70,12 @@ endif()
if(BUILD_DX12)
set(LIBRARY_SOURCES ${LIBRARY_SOURCES} DirectXTex/DirectXTexD3D12.cpp)
endif()
+if(ENABLE_OPENEXR_SUPPORT)
+ set(LIBRARY_SOURCES
+ ${LIBRARY_SOURCES}
+ DirectXTex/DirectXTexEXR.h
+ DirectXTex/DirectXTexEXR.cpp)
+endif()

add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc)

@@ -82,6 +91,10 @@ add_custom_command(
source_group(${PROJECT_NAME} REGULAR_EXPRESSION DirectXTex/*.*)

target_include_directories(${PROJECT_NAME} PUBLIC DirectXTex)
+if(ENABLE_OPENEXR_SUPPORT)
+ find_package(openexr REQUIRED)
+ target_include_directories(${PROJECT_NAME} PRIVATE ${OPENEXR_INCLUDE_DIRS}/OpenEXR)
+endif()

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16")
target_precompile_headers(${PROJECT_NAME} PRIVATE DirectXTex/DirectXTexP.h)
@@ -116,6 +129,13 @@ add_executable(texdiag Texdiag/texdiag.cpp)
target_link_libraries(texdiag ${PROJECT_NAME} version.lib)
source_group(texdiag REGULAR_EXPRESSION Texdiag/*.*)

+if(ENABLE_OPENEXR_SUPPORT)
+ target_link_libraries(${PROJECT_NAME} ${OPENEXR_ILMIMF_LIBRARY})
+ target_link_libraries(texassemble ${OPENEXR_ILMIMF_LIBRARY})
+ target_link_libraries(texconv ${OPENEXR_ILMIMF_LIBRARY})
+ target_link_libraries(texdiag ${OPENEXR_ILMIMF_LIBRARY})
+endif()
+
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /fp:fast)
target_compile_options(texassemble PRIVATE /fp:fast)
@@ -140,6 +160,12 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
target_compile_options(texassemble PRIVATE ${WarningsEXE})
target_compile_options(texconv PRIVATE ${WarningsEXE})
target_compile_options(texdiag PRIVATE ${WarningsEXE} "-Wno-double-promotion" )
+
+ if(ENABLE_OPENEXR_SUPPORT)
+ target_compile_options(texassemble PRIVATE -DUSE_OPENEXR)
+ target_compile_options(texconv PRIVATE -DUSE_OPENEXR)
+ target_compile_options(texdiag PRIVATE -DUSE_OPENEXR)
+ endif()
endif()
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options(${PROJECT_NAME} PRIVATE /permissive- /JMC- /Zc:__cplusplus)
@@ -167,6 +193,12 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options(texconv PRIVATE /openmp /Zc:twoPhase-)
endif()

+ if(ENABLE_OPENEXR_SUPPORT)
+ target_compile_options(texassemble PRIVATE /D "USE_OPENEXR")
+ target_compile_options(texconv PRIVATE /D "USE_OPENEXR")
+ target_compile_options(texdiag PRIVATE /D "USE_OPENEXR")
+ endif()
+
set(WarningsEXE "/wd4061" "/wd4062" "/wd4365" "/wd4668" "/wd4710" "/wd4820" "/wd5039" "/wd5045" "/wd5219")
target_compile_options(texassemble PRIVATE ${WarningsEXE})
target_compile_options(texconv PRIVATE ${WarningsEXE})
diff --git a/DirectXTex/DirectXTexEXR.cpp b/DirectXTex/DirectXTexEXR.cpp
index 0cfd4db..7a6e70c 100644
--- a/DirectXTex/DirectXTexEXR.cpp
+++ b/DirectXTex/DirectXTexEXR.cpp
@@ -8,7 +8,7 @@
//--------------------------------------------------------------------------------------

//Uncomment if you add DirectXTexEXR to your copy of the DirectXTex library
-//#include "DirectXTexP.h"
+#include "DirectXTexP.h"

#include "DirectXTexEXR.h"

@@ -38,6 +38,7 @@
using PackedVector::XMHALF4;

// Comment out this first anonymous namespace if you add the include of DirectXTexP.h above
+#if 0
namespace
{
struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } };
@@ -70,6 +76,7 @@
HANDLE m_handle;
};
}
+#endif

namespace
{
98 changes: 51 additions & 47 deletions ports/directxtex/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,67 @@ vcpkg_from_github(
HEAD_REF master
)

IF (TRIPLET_SYSTEM_ARCH MATCHES "x86")
SET(BUILD_ARCH "Win32")
ELSE()
SET(BUILD_ARCH ${TRIPLET_SYSTEM_ARCH})
ENDIF()
if("openexr" IN_LIST FEATURES)
vcpkg_download_distfile(
DIRECTXTEX_EXR_HEADER
URLS "https://raw.githubusercontent.com/wiki/Microsoft/DirectXTex/DirectXTexEXR.h"
FILENAME "DirectXTexEXR.h"
SHA512 94ec71069949c8daa616d241ade0c771c448adab3e401a935d5462e7cac382cfbef47534072fc4b9706e086f5021de78a51fd4e2a6850cd3629c932592f9a168
)

if (VCPKG_PLATFORM_TOOLSET STREQUAL "v140")
set(VS_VERSION "2015")
elseif (VCPKG_PLATFORM_TOOLSET STREQUAL "v141")
set(VS_VERSION "2017")
elseif (VCPKG_PLATFORM_TOOLSET STREQUAL "v142")
set(VS_VERSION "2019")
else()
message(FATAL_ERROR "Unsupported platform toolset.")
vcpkg_download_distfile(
DIRECTXTEX_EXR_SOURCE
URLS "https://raw.githubusercontent.com/wiki/Microsoft/DirectXTex/DirectXTexEXR.cpp"
FILENAME "DirectXTexEXR.cpp"
SHA512 8bc66e102a0a163e42d428774c857271ad457a85038fd4ddfdbf083674879f9a8406a9aecd26949296b156a5c5fd08fdfba9600b71879be9affb9dabf23a497c
)

file(COPY ${DIRECTXTEX_EXR_HEADER} DESTINATION ${SOURCE_PATH}/DirectXTex)
file(COPY ${DIRECTXTEX_EXR_SOURCE} DESTINATION ${SOURCE_PATH}/DirectXTex)
vcpkg_apply_patches(SOURCE_PATH ${SOURCE_PATH} PATCHES enable_openexr_support.patch)
endif()

if(VCPKG_TARGET_IS_UWP)
set(SLN_NAME "Windows10_${VS_VERSION}")
vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES openexr ENABLE_OPENEXR_SUPPORT
)

if("dx12" IN_LIST FEATURES OR VCPKG_TARGET_IS_UWP OR TRIPLET_SYSTEM_ARCH STREQUAL "arm64")
list(APPEND FEATURE_OPTIONS -DBUILD_DX12=ON)
else()
if(TRIPLET_SYSTEM_ARCH STREQUAL "arm64")
set(SLN_NAME "Desktop_${VS_VERSION}_Win10")
else()
set(SLN_NAME "Desktop_${VS_VERSION}")
endif()
list(APPEND FEATURE_OPTIONS -DBUILD_DX12=OFF)
endif()

vcpkg_build_msbuild(
PROJECT_PATH ${SOURCE_PATH}/DirectXTex_${SLN_NAME}.sln
PLATFORM ${TRIPLET_SYSTEM_ARCH}
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
${FEATURE_OPTIONS}
-DBC_USE_OPENMP=ON
-DBUILD_DX11=ON
)

file(INSTALL
${SOURCE_PATH}/DirectXTex/DirectXTex.h
${SOURCE_PATH}/DirectXTex/DirectXTex.inl
DESTINATION ${CURRENT_PACKAGES_DIR}/include
)
file(INSTALL
${SOURCE_PATH}/DirectXTex/Bin/${SLN_NAME}/${BUILD_ARCH}/Debug/DirectXTex.lib
${SOURCE_PATH}/DirectXTex/Bin/${SLN_NAME}/${BUILD_ARCH}/Debug/DirectXTex.pdb
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(INSTALL
${SOURCE_PATH}/DirectXTex/Bin/${SLN_NAME}/${BUILD_ARCH}/Release/DirectXTex.lib
${SOURCE_PATH}/DirectXTex/Bin/${SLN_NAME}/${BUILD_ARCH}/Release/DirectXTex.pdb
DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
if(NOT VCPKG_TARGET_IS_UWP AND NOT TRIPLET_SYSTEM_ARCH STREQUAL "arm64")
vcpkg_build_cmake()
else()
vcpkg_build_cmake(TARGET DirectXTex)
endif()

file(INSTALL ${SOURCE_PATH}/DirectXTex/DirectXTex.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)
file(INSTALL ${SOURCE_PATH}/DirectXTex/DirectXTex.inl DESTINATION ${CURRENT_PACKAGES_DIR}/include)
if("openexr" IN_LIST FEATURES)
file(INSTALL ${SOURCE_PATH}/DirectXTex/DirectXTexEXR.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)
endif()

file(GLOB_RECURSE DEBUG_LIB ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/bin/CMake/*.lib)
file(GLOB_RECURSE RELEASE_LIB ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bin/CMake/*.lib)
file(INSTALL ${DEBUG_LIB} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(INSTALL ${RELEASE_LIB} DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
if(NOT VCPKG_TARGET_IS_UWP AND NOT TRIPLET_SYSTEM_ARCH STREQUAL "arm64")
set(TOOL_PATH ${CURRENT_PACKAGES_DIR}/tools/directxtex)
file(MAKE_DIRECTORY ${TOOL_PATH})
file(INSTALL
${SOURCE_PATH}/Texdiag/Bin/${SLN_NAME}/${BUILD_ARCH}/Release/texdiag.exe
DESTINATION ${TOOL_PATH})
file(INSTALL
${SOURCE_PATH}/Texconv/Bin/${SLN_NAME}/${BUILD_ARCH}/Release/Texconv.exe
DESTINATION ${TOOL_PATH})
file(INSTALL
${SOURCE_PATH}/Texassemble/Bin/${SLN_NAME}/${BUILD_ARCH}/Release/Texassemble.exe
DESTINATION ${TOOL_PATH})
vcpkg_copy_tools(
TOOL_NAMES texassemble texconv texdiag
SEARCH_DIR ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bin/CMake
)
endif()

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

0 comments on commit 17b23ee

Please sign in to comment.