2019-07-12 07:40:57 +00:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2020-03-29 22:09:59 +00:00
|
|
|
cmake_minimum_required (VERSION 3.11)
|
2019-11-15 08:39:50 +00:00
|
|
|
|
2020-12-18 23:28:28 +00:00
|
|
|
set(DIRECTXTEX_VERSION 1.9.1)
|
|
|
|
|
|
|
|
project (DirectXTex
|
|
|
|
VERSION ${DIRECTXTEX_VERSION}
|
|
|
|
DESCRIPTION "DirectX Texture Library"
|
|
|
|
HOMEPAGE_URL "https://go.microsoft.com/fwlink/?LinkId=248926"
|
|
|
|
LANGUAGES CXX)
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
option(BUILD_TOOLS "Build tex command-line tools" ON)
|
|
|
|
|
2021-01-01 21:36:40 +00:00
|
|
|
# Includes the functions for Direct3D 11 resources and DirectCompute compression
|
2019-12-14 01:30:01 +00:00
|
|
|
option(BUILD_DX11 "Build with DirectX11 Runtime support" ON)
|
|
|
|
|
|
|
|
# Includes the functions for creating Direct3D 12 resources at runtime
|
|
|
|
option(BUILD_DX12 "Build with DirectX12 Runtime support" ON)
|
|
|
|
|
2019-12-14 06:26:18 +00:00
|
|
|
# Enable the use of OpenMP for software BC6H/BC7 compression
|
|
|
|
option(BC_USE_OPENMP "Build with OpenMP support" ON)
|
|
|
|
|
2020-06-05 22:01:02 +00:00
|
|
|
option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
|
|
|
|
|
2020-12-19 02:44:47 +00:00
|
|
|
# Includes the functions for loading/saving OpenEXR files at runtime
|
|
|
|
# NOTE requires adding DirectXTexEXR.h/.cpp source files (vcpkg does this automatically)
|
|
|
|
option(ENABLE_OPENEXR_SUPPORT "Build with OpenEXR support" OFF)
|
|
|
|
|
2019-07-12 07:40:57 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2020-08-11 03:04:44 +00:00
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/CMake")
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/CMake")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/CMake")
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2020-12-18 23:28:28 +00:00
|
|
|
#--- Library
|
|
|
|
set(LIBRARY_HEADERS
|
|
|
|
DirectXTex/DirectXTex.h
|
|
|
|
DirectXTex/DirectXTex.inl)
|
|
|
|
|
2019-12-14 01:30:01 +00:00
|
|
|
set(LIBRARY_SOURCES
|
2019-07-12 07:40:57 +00:00
|
|
|
DirectXTex/BC.h
|
|
|
|
DirectXTex/DDS.h
|
|
|
|
DirectXTex/DirectXTexP.h
|
|
|
|
DirectXTex/filters.h
|
|
|
|
DirectXTex/scoped.h
|
|
|
|
DirectXTex/BC.cpp
|
|
|
|
DirectXTex/BC4BC5.cpp
|
|
|
|
DirectXTex/BC6HBC7.cpp
|
|
|
|
DirectXTex/DirectXTexCompress.cpp
|
|
|
|
DirectXTex/DirectXTexConvert.cpp
|
|
|
|
DirectXTex/DirectXTexDDS.cpp
|
|
|
|
DirectXTex/DirectXTexFlipRotate.cpp
|
|
|
|
DirectXTex/DirectXTexHDR.cpp
|
|
|
|
DirectXTex/DirectXTexImage.cpp
|
|
|
|
DirectXTex/DirectXTexMipmaps.cpp
|
|
|
|
DirectXTex/DirectXTexMisc.cpp
|
|
|
|
DirectXTex/DirectXTexNormalMaps.cpp
|
|
|
|
DirectXTex/DirectXTexPMAlpha.cpp
|
|
|
|
DirectXTex/DirectXTexResize.cpp
|
|
|
|
DirectXTex/DirectXTexTGA.cpp
|
|
|
|
DirectXTex/DirectXTexUtil.cpp
|
2019-12-14 01:30:01 +00:00
|
|
|
DirectXTex/DirectXTexWIC.cpp)
|
|
|
|
|
2019-12-17 19:18:37 +00:00
|
|
|
set(SHADER_SOURCES
|
|
|
|
DirectXTex/Shaders/BC6HEncode.hlsl
|
|
|
|
DirectXTex/Shaders/BC7Encode.hlsl)
|
|
|
|
|
2020-06-05 22:01:02 +00:00
|
|
|
if(BUILD_DX11)
|
2021-01-01 21:36:40 +00:00
|
|
|
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
|
|
|
|
DirectXTex/BCDirectCompute.h
|
|
|
|
DirectXTex/BCDirectCompute.cpp
|
|
|
|
DirectXTex/DirectXTexCompressGPU.cpp
|
|
|
|
DirectXTex/DirectXTexD3D11.cpp
|
|
|
|
DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc)
|
2019-12-14 01:30:01 +00:00
|
|
|
endif()
|
2020-06-05 22:01:02 +00:00
|
|
|
if(BUILD_DX12)
|
2021-01-01 21:36:40 +00:00
|
|
|
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
|
|
|
|
DirectXTex/d3dx12.h
|
|
|
|
DirectXTex/DirectXTexD3D12.cpp)
|
2019-12-14 01:30:01 +00:00
|
|
|
endif()
|
|
|
|
|
2020-12-19 02:44:47 +00:00
|
|
|
if(ENABLE_OPENEXR_SUPPORT)
|
|
|
|
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
|
|
|
|
DirectXTex/DirectXTexEXR.h)
|
|
|
|
|
|
|
|
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
|
|
|
|
DirectXTex/DirectXTexEXR.h
|
|
|
|
DirectXTex/DirectXTexEXR.cpp)
|
|
|
|
endif()
|
|
|
|
|
2021-01-01 21:36:40 +00:00
|
|
|
add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
|
2019-12-17 19:18:37 +00:00
|
|
|
|
2021-01-01 21:36:40 +00:00
|
|
|
if(BUILD_DX11)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc"
|
|
|
|
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/CompileShaders.cmd"
|
|
|
|
DEPENDS ${SHADER_SOURCES}
|
|
|
|
COMMENT "Generating HLSL shaders..."
|
|
|
|
COMMAND "CompileShaders.cmd"
|
|
|
|
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders"
|
|
|
|
USES_TERMINAL)
|
|
|
|
endif()
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2019-11-15 08:39:50 +00:00
|
|
|
source_group(${PROJECT_NAME} REGULAR_EXPRESSION DirectXTex/*.*)
|
2019-09-19 06:48:38 +00:00
|
|
|
|
2020-12-18 23:28:28 +00:00
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/DirectXTex>
|
|
|
|
$<INSTALL_INTERFACE:include>)
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2020-12-19 02:44:47 +00:00
|
|
|
if(ENABLE_OPENEXR_SUPPORT)
|
|
|
|
find_package(openexr REQUIRED)
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENEXR_INCLUDE_DIRS}/OpenEXR)
|
|
|
|
endif()
|
|
|
|
|
2020-03-29 22:09:59 +00:00
|
|
|
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16")
|
|
|
|
target_precompile_headers(${PROJECT_NAME} PRIVATE DirectXTex/DirectXTexP.h)
|
|
|
|
endif()
|
2020-03-29 19:49:11 +00:00
|
|
|
|
2019-12-02 18:52:27 +00:00
|
|
|
if(MSVC)
|
2020-12-18 23:28:28 +00:00
|
|
|
# Use max Warning Level
|
2019-12-02 18:52:27 +00:00
|
|
|
string(REPLACE "/W3 " "/Wall " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REPLACE "/W3 " "/Wall " CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
|
|
|
string(REPLACE "/W3 " "/Wall " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
|
|
|
|
|
|
|
# Not using typeid or dynamic_cast, so disable RTTI to save binary size
|
|
|
|
string(REPLACE "/GR " "/GR- " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REPLACE "/GR " "/GR- " CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
|
|
|
string(REPLACE "/GR " "/GR- " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
|
|
|
endif()
|
2019-11-18 02:24:19 +00:00
|
|
|
|
2020-12-18 23:28:28 +00:00
|
|
|
#--- Package
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
2020-12-29 10:49:19 +00:00
|
|
|
string(TOLOWER ${PROJECT_NAME} PACKAGE_NAME)
|
|
|
|
|
2020-12-18 23:28:28 +00:00
|
|
|
write_basic_package_version_file(
|
2020-12-29 10:49:19 +00:00
|
|
|
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config-version.cmake
|
2020-12-18 23:28:28 +00:00
|
|
|
VERSION ${DIRECTXTEX_VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
|
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
|
|
EXPORT ${PROJECT_NAME}-targets
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
RUNTIME DESTINATION bin)
|
|
|
|
|
|
|
|
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/.nuget/${PROJECT_NAME}-config.cmake.in
|
2020-12-29 10:49:19 +00:00
|
|
|
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config.cmake
|
2020-12-18 23:28:28 +00:00
|
|
|
INSTALL_DESTINATION cmake/})
|
|
|
|
|
|
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
|
|
|
NAMESPACE Microsoft::
|
|
|
|
DESTINATION cmake/)
|
|
|
|
|
|
|
|
install(FILES ${LIBRARY_HEADERS}
|
|
|
|
DESTINATION include)
|
|
|
|
|
|
|
|
install(
|
|
|
|
FILES
|
2020-12-29 10:49:19 +00:00
|
|
|
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config.cmake
|
|
|
|
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config-version.cmake
|
2020-12-18 23:28:28 +00:00
|
|
|
DESTINATION cmake/)
|
|
|
|
|
|
|
|
#--- Command-line tools
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
add_executable(texassemble
|
2020-07-01 08:37:13 +00:00
|
|
|
Texassemble/texassemble.cpp
|
|
|
|
Texassemble/AnimatedGif.cpp)
|
2020-12-19 02:05:07 +00:00
|
|
|
target_link_libraries(texassemble ${PROJECT_NAME} version.lib)
|
|
|
|
source_group(texassemble REGULAR_EXPRESSION Texassemble/*.*)
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
add_executable(texconv
|
2020-06-05 03:07:21 +00:00
|
|
|
Texconv/texconv.cpp
|
|
|
|
Texconv/ExtendedBMP.cpp
|
|
|
|
Texconv/PortablePixMap.cpp)
|
2020-12-19 02:05:07 +00:00
|
|
|
target_link_libraries(texconv ${PROJECT_NAME} version.lib)
|
|
|
|
source_group(texconv REGULAR_EXPRESSION Texconv/*.*)
|
2019-07-12 07:40:57 +00:00
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
add_executable(texdiag Texdiag/texdiag.cpp)
|
|
|
|
target_link_libraries(texdiag ${PROJECT_NAME} version.lib)
|
|
|
|
source_group(texdiag REGULAR_EXPRESSION Texdiag/*.*)
|
2020-12-19 02:44:47 +00:00
|
|
|
|
|
|
|
if(ENABLE_OPENEXR_SUPPORT)
|
|
|
|
target_link_libraries(texassemble ${OPENEXR_ILMIMF_LIBRARY})
|
|
|
|
target_link_libraries(texconv ${OPENEXR_ILMIMF_LIBRARY})
|
|
|
|
target_link_libraries(texdiag ${OPENEXR_ILMIMF_LIBRARY})
|
|
|
|
|
|
|
|
target_compile_options(texassemble PRIVATE -DUSE_OPENEXR)
|
|
|
|
target_compile_options(texconv PRIVATE -DUSE_OPENEXR)
|
|
|
|
target_compile_options(texdiag PRIVATE -DUSE_OPENEXR)
|
|
|
|
endif()
|
2020-12-19 02:05:07 +00:00
|
|
|
endif()
|
2019-11-15 08:39:50 +00:00
|
|
|
|
2019-12-02 18:52:27 +00:00
|
|
|
if(MSVC)
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /fp:fast)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texassemble PRIVATE /fp:fast)
|
|
|
|
target_compile_options(texconv PRIVATE /fp:fast)
|
|
|
|
target_compile_options(texdiag PRIVATE /fp:fast)
|
|
|
|
endif()
|
2019-12-02 18:52:27 +00:00
|
|
|
|
|
|
|
if (${CMAKE_SIZEOF_VOID_P} EQUAL "4")
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /arch:SSE2)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texassemble PRIVATE /arch:SSE2)
|
|
|
|
target_compile_options(texconv PRIVATE /arch:SSE2)
|
|
|
|
target_compile_options(texdiag PRIVATE /arch:SSE2)
|
|
|
|
endif()
|
2019-12-02 18:52:27 +00:00
|
|
|
endif()
|
2019-11-15 08:39:50 +00:00
|
|
|
endif()
|
2019-07-12 07:40:57 +00:00
|
|
|
|
|
|
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
2019-11-15 08:39:50 +00:00
|
|
|
set(WarningsLib "-Wpedantic" "-Wextra")
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
|
|
|
|
|
2019-12-14 06:26:18 +00:00
|
|
|
# OpenMP is not supported for clang for Windows by default
|
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic" "-Wno-switch" "-Wno-switch-enum" "-Wno-language-extension-token" "-Wno-missing-prototypes")
|
|
|
|
target_compile_options(texassemble PRIVATE ${WarningsEXE})
|
|
|
|
target_compile_options(texconv PRIVATE ${WarningsEXE} "-Wno-global-constructors")
|
|
|
|
target_compile_options(texdiag PRIVATE ${WarningsEXE} "-Wno-double-promotion")
|
|
|
|
endif()
|
2019-07-12 07:40:57 +00:00
|
|
|
endif()
|
|
|
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
2019-11-15 08:39:50 +00:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /permissive- /JMC- /Zc:__cplusplus)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texassemble PRIVATE /permissive- /Zc:__cplusplus)
|
|
|
|
target_compile_options(texconv PRIVATE /permissive- /Zc:__cplusplus)
|
|
|
|
target_compile_options(texdiag PRIVATE /permissive- /Zc:__cplusplus)
|
|
|
|
endif()
|
2019-11-15 08:39:50 +00:00
|
|
|
|
2020-06-05 22:01:02 +00:00
|
|
|
if(ENABLE_CODE_ANALYSIS)
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /analyze)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texassemble PRIVATE /analyze)
|
|
|
|
target_compile_options(texconv PRIVATE /analyze)
|
|
|
|
target_compile_options(texdiag PRIVATE /analyze)
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-06-05 22:01:02 +00:00
|
|
|
|
2020-05-20 03:11:23 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.26)
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:preprocessor /wd5105)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texassemble PRIVATE /Zc:preprocessor /wd5105)
|
|
|
|
target_compile_options(texconv PRIVATE /Zc:preprocessor /wd5105)
|
|
|
|
target_compile_options(texdiag PRIVATE /Zc:preprocessor /wd5105)
|
|
|
|
endif()
|
2020-05-20 03:11:23 +00:00
|
|
|
endif()
|
|
|
|
|
2020-06-05 22:01:02 +00:00
|
|
|
if(BC_USE_OPENMP)
|
2019-12-14 06:26:18 +00:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /openmp /Zc:twoPhase-)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_options(texconv PRIVATE /openmp /Zc:twoPhase-)
|
|
|
|
endif()
|
2019-12-14 06:26:18 +00:00
|
|
|
endif()
|
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
set(WarningsEXE "/wd4061" "/wd4062" "/wd4365" "/wd4668" "/wd4710" "/wd4820" "/wd5039" "/wd5045" "/wd5219")
|
|
|
|
target_compile_options(texassemble PRIVATE ${WarningsEXE})
|
|
|
|
target_compile_options(texconv PRIVATE ${WarningsEXE})
|
|
|
|
target_compile_options(texdiag PRIVATE ${WarningsEXE})
|
|
|
|
endif()
|
2019-07-12 07:40:57 +00:00
|
|
|
endif()
|
|
|
|
|
2019-12-12 00:19:23 +00:00
|
|
|
if(WIN32)
|
2019-12-14 01:30:01 +00:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE)
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
target_compile_definitions(texassemble PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0601)
|
|
|
|
target_compile_definitions(texconv PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0601)
|
|
|
|
target_compile_definitions(texdiag PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0601)
|
|
|
|
endif()
|
2019-12-14 01:30:01 +00:00
|
|
|
|
2020-12-24 20:59:19 +00:00
|
|
|
if(BUILD_DX12 OR WINDOWS_STORE)
|
2019-12-14 01:30:01 +00:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=0x0A00)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=0x0601)
|
|
|
|
endif()
|
2019-12-12 00:19:23 +00:00
|
|
|
endif()
|
2020-08-11 03:54:31 +00:00
|
|
|
|
2020-12-19 02:05:07 +00:00
|
|
|
if(BUILD_TOOLS)
|
|
|
|
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT texconv)
|
|
|
|
endif()
|