From 17b23eeb3bde7166937e274fe142e7471c1495aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Tassoux?= Date: Tue, 13 Oct 2020 22:40:52 +0200 Subject: [PATCH] [directxtex] Use CMake build system, add OpenEXR support and dx12 feature (#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 --- ports/directxtex/CONTROL | 10 +- ports/directxtex/enable_openexr_support.patch | 107 ++++++++++++++++++ ports/directxtex/portfile.cmake | 98 ++++++++-------- 3 files changed, 167 insertions(+), 48 deletions(-) create mode 100644 ports/directxtex/enable_openexr_support.patch diff --git a/ports/directxtex/CONTROL b/ports/directxtex/CONTROL index 48964252915748..b41101dd793099 100644 --- a/ports/directxtex/CONTROL +++ b/ports/directxtex/CONTROL @@ -1,4 +1,12 @@ Source: directxtex Version: sept2020 +Port-Version: 1 Homepage: https://walbourn.github.io/directxtex -Description: DirectXTex texture processing library \ No newline at end of file +Description: DirectXTex texture processing library + +Feature: dx12 +Description: Build with DirectX12 support for Windows 10 + +Feature: openexr +Description: Enable OpenEXR support +Build-Depends: openexr diff --git a/ports/directxtex/enable_openexr_support.patch b/ports/directxtex/enable_openexr_support.patch new file mode 100644 index 00000000000000..def2700d1f4189 --- /dev/null +++ b/ports/directxtex/enable_openexr_support.patch @@ -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 + { diff --git a/ports/directxtex/portfile.cmake b/ports/directxtex/portfile.cmake index 6967b227340860..4cf2668be9ad73 100644 --- a/ports/directxtex/portfile.cmake +++ b/ports/directxtex/portfile.cmake @@ -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)