CMake support added for building with MinGW (#127)
This commit is contained in:
Родитель
3356e06c6c
Коммит
d370f10c00
|
@ -3,7 +3,7 @@
|
|||
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
if(VCPKG_TOOLCHAIN)
|
||||
if(MINGW OR VCPKG_TOOLCHAIN)
|
||||
find_dependency(directx-headers CONFIG)
|
||||
find_dependency(directxmath CONFIG)
|
||||
endif()
|
||||
|
|
|
@ -12,6 +12,7 @@ project (DirectXTK12
|
|||
LANGUAGES CXX)
|
||||
|
||||
option(BUILD_XAUDIO_WIN10 "Build for XAudio 2.9" ON)
|
||||
option(BUILD_XAUDIO_REDIST "Build for XAudio2Redist" OFF)
|
||||
|
||||
option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
|
||||
|
||||
|
@ -149,7 +150,11 @@ set(SHADER_SOURCES
|
|||
Src/Shaders/ToneMap.fx
|
||||
Src/Shaders/Utilities.fxh)
|
||||
|
||||
if(WINDOWS_STORE OR BUILD_XAUDIO_WIN10)
|
||||
if(MINGW)
|
||||
set(BUILD_XAUDIO_WIN10 OFF)
|
||||
endif()
|
||||
|
||||
if(WINDOWS_STORE OR BUILD_XAUDIO_WIN10 OR BUILD_XAUDIO_REDIST)
|
||||
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
|
||||
Inc/Audio.h)
|
||||
|
||||
|
@ -202,7 +207,7 @@ add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
|
|||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${COMPILED_SHADERS})
|
||||
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16")
|
||||
if ((${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16") AND (NOT MINGW))
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE Src/pch.h)
|
||||
endif()
|
||||
|
||||
|
@ -214,7 +219,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Inc>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
|
||||
|
||||
if(WINDOWS_STORE OR BUILD_XAUDIO_WIN10)
|
||||
if(WINDOWS_STORE OR BUILD_XAUDIO_WIN10 OR BUILD_XAUDIO_REDIST)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE Src Audio)
|
||||
endif()
|
||||
|
||||
|
@ -229,7 +234,7 @@ if(MSVC)
|
|||
# Library needs /EHsc (Enable C++ exceptions)
|
||||
endif()
|
||||
|
||||
if (VCPKG_TOOLCHAIN)
|
||||
if (MINGW OR VCPKG_TOOLCHAIN)
|
||||
message("INFO: Using VCPKG for DirectX-Headers and DirectXMath.")
|
||||
find_package(directx-headers CONFIG REQUIRED)
|
||||
find_package(directxmath CONFIG REQUIRED)
|
||||
|
@ -237,6 +242,14 @@ if (VCPKG_TOOLCHAIN)
|
|||
target_compile_definitions(${PROJECT_NAME} PRIVATE USING_DIRECTX_HEADERS)
|
||||
endif()
|
||||
|
||||
if (BUILD_XAUDIO_REDIST AND (NOT BUILD_XAUDIO_WIN10) AND (NOT WINDOWS_STORE))
|
||||
message("INFO: Using XAudio2Redist for DirectX Tool Kit for Audio.")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE USING_XAUDIO2_REDIST)
|
||||
|
||||
find_package(xaudio2redist CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::XAudio2Redist)
|
||||
endif()
|
||||
|
||||
#--- Package
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
|
@ -275,19 +288,31 @@ if(MSVC)
|
|||
target_link_options(${PROJECT_NAME} PRIVATE /DYNAMICBASE /NXCOMPAT)
|
||||
|
||||
if((${CMAKE_SIZEOF_VOID_P} EQUAL 4) AND (NOT ${DIRECTX_ARCH} MATCHES "^arm"))
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /arch:SSE2)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE /SAFESEH)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ${DIRECTX_ARCH} MATCHES "^arm")
|
||||
if (${CMAKE_SIZEOF_VOID_P} EQUAL "4")
|
||||
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse2>)
|
||||
else()
|
||||
set(ARCH_SSE2 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse2>)
|
||||
endif()
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${ARCH_SSE2})
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wpedantic -Wextra)
|
||||
endif()
|
||||
if(MINGW)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-ignored-attributes)
|
||||
endif()
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /sdl /permissive- /JMC- /Zc:__cplusplus)
|
||||
|
||||
if(ENABLE_CODE_ANALYSIS)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /analyze)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /analyze)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.24)
|
||||
|
|
|
@ -81,6 +81,17 @@
|
|||
"strategy": "external"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "GNUC",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "g++.exe"
|
||||
},
|
||||
"toolset": {
|
||||
"value": "host=x64",
|
||||
"strategy": "external"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "UWP",
|
||||
|
@ -100,6 +111,14 @@
|
|||
},
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "XAudio2Redist",
|
||||
"cacheVariables": {
|
||||
"BUILD_XAUDIO_WIN10": false,
|
||||
"BUILD_XAUDIO_REDIST": true
|
||||
},
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
{ "name": "x64-Debug" , "description": "MSVC for x64 (Debug) for Windows 10", "inherits": [ "base", "x64", "Debug", "MSVC" ] },
|
||||
{ "name": "x64-Release" , "description": "MSVC for x64 (Release) for Windows 10", "inherits": [ "base", "x64", "Release", "MSVC" ] },
|
||||
|
@ -117,10 +136,10 @@
|
|||
{ "name": "arm64-Debug-UWP" , "description": "MSVC for ARM64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "MSVC", "UWP" ] },
|
||||
{ "name": "arm64-Release-UWP", "description": "MSVC for ARM64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "MSVC", "UWP" ] },
|
||||
|
||||
{ "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG" ] },
|
||||
{ "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG" ] },
|
||||
{ "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG" ] },
|
||||
{ "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG" ] },
|
||||
{ "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG", "XAudio2Redist" ] },
|
||||
{ "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG", "XAudio2Redist" ] },
|
||||
{ "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG", "XAudio2Redist" ] },
|
||||
{ "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG", "XAudio2Redist" ] },
|
||||
{ "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG" ] },
|
||||
{ "name": "arm64-Release-VCPKG", "description": "MSVC for ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "MSVC", "VCPKG" ] },
|
||||
|
||||
|
@ -136,6 +155,11 @@
|
|||
{ "name": "x86-Debug-UWP-Clang" , "description": "Clang/LLVM for x86 (Debug) for UWP", "inherits": [ "base", "x86", "Debug", "Clang", "UWP" ], "environment": { "CXXFLAGS": "-m32" } },
|
||||
{ "name": "x86-Release-UWP-Clang" , "description": "Clang/LLVM for x86 (Release) for UWP", "inherits": [ "base", "x86", "Release", "Clang", "UWP" ], "environment": { "CXXFLAGS": "-m32" } },
|
||||
{ "name": "arm64-Debug-UWP-Clang" , "description": "Clang/LLVM for AArch64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "Clang", "UWP" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } },
|
||||
{ "name": "arm64-Release-UWP-Clang", "description": "Clang/LLVM for AArch64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "Clang", "UWP" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }
|
||||
{ "name": "arm64-Release-UWP-Clang", "description": "Clang/LLVM for AArch64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "Clang", "UWP" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } },
|
||||
|
||||
{ "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "XAudio2Redist" ], "environment": { "PATH": "$penv{PATH};c:/mingw64/bin" } },
|
||||
{ "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "XAudio2Redist" ], "environment": { "PATH": "$penv{PATH};c:/mingw64/bin" } },
|
||||
{ "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "XAudio2Redist" ], "environment": { "PATH": "$penv{PATH};c:/mingw32/bin" } },
|
||||
{ "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "XAudio2Redist" ], "environment": { "PATH": "$penv{PATH};c:/mingw32/bin" } }
|
||||
]
|
||||
}
|
|
@ -164,32 +164,34 @@ namespace DirectX
|
|||
#endif
|
||||
|
||||
// Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
|
||||
#if !defined(NO_D3D12_DEBUG_NAME) && (defined(_DEBUG) || defined(PROFILE))
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const char(&name)[TNameLength]) noexcept
|
||||
{
|
||||
#if !defined(NO_D3D12_DEBUG_NAME) && (defined(_DEBUG) || defined(PROFILE))
|
||||
wchar_t wname[MAX_PATH];
|
||||
int result = MultiByteToWideChar(CP_UTF8, 0, name, TNameLength, wname, MAX_PATH);
|
||||
if (result > 0)
|
||||
{
|
||||
resource->SetName(wname);
|
||||
}
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept
|
||||
{
|
||||
#if !defined(NO_D3D12_DEBUG_NAME) && (defined(_DEBUG) || defined(PROFILE))
|
||||
resource->SetName(name);
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild*, _In_z_ const char(&)[TNameLength]) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild*, _In_z_ const wchar_t(&)[TNameLength]) noexcept
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
// Helper for resource barrier.
|
||||
inline void TransitionResource(
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#ifndef USING_GAMEINPUT
|
||||
#define USING_GAMEINPUT
|
||||
#endif
|
||||
#elif (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) && !defined(_GAMING_DESKTOP)
|
||||
#elif (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) && !defined(_GAMING_DESKTOP) && !defined(__MINGW32__)
|
||||
#ifndef USING_WINDOWS_GAMING_INPUT
|
||||
#define USING_WINDOWS_GAMING_INPUT
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#ifdef NTDDI_WIN10_FE
|
||||
#if defined(NTDDI_WIN10_FE) || defined(__MINGW32__)
|
||||
#include <ocidl.h>
|
||||
#else
|
||||
#include <OCIdl.h>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#if (defined(WIN32) || defined(WINAPI_FAMILY)) && !(defined(_XBOX_ONE) && defined(_TITLE)) && !defined(_GAMING_XBOX)
|
||||
#if (defined(_WIN32) || defined(WINAPI_FAMILY)) && !(defined(_XBOX_ONE) && defined(_TITLE)) && !defined(_GAMING_XBOX)
|
||||
#include <dxgi1_2.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
@ -39,7 +39,7 @@ namespace DirectX
|
|||
static_assert(alignment > 8, "AlignedNew is only useful for types with > 8 byte alignment. Did you forget a __declspec(align) on TDerived?");
|
||||
static_assert(((alignment - 1) & alignment) == 0, "AlignedNew only works with power of two alignment");
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
void* ptr = _aligned_malloc(size, alignment);
|
||||
#else
|
||||
// This C++17 Standard Library function is currently NOT
|
||||
|
@ -56,7 +56,7 @@ namespace DirectX
|
|||
// Free aligned memory.
|
||||
static void operator delete (void* ptr)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
|
|
|
@ -1398,7 +1398,9 @@ public:
|
|||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
static_assert(XINPUT_DEVSUBTYPE_WHEEL == Capabilities::WHEEL, "xinput.h mismatch");
|
||||
static_assert(XINPUT_DEVSUBTYPE_ARCADE_STICK == Capabilities::ARCADE_STICK, "xinput.h mismatch");
|
||||
#ifndef __MINGW32__
|
||||
static_assert(XINPUT_DEVSUBTYPE_FLIGHT_STICK == Capabilities::FLIGHT_STICK, "xinput.h mismatch");
|
||||
#endif
|
||||
static_assert(XINPUT_DEVSUBTYPE_DANCE_PAD == Capabilities::DANCE_PAD, "xinput.h mismatch");
|
||||
static_assert(XINPUT_DEVSUBTYPE_GUITAR == Capabilities::GUITAR, "xinput.h mismatch");
|
||||
static_assert(XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE == Capabilities::GUITAR_ALTERNATE, "xinput.h mismatch");
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// See https://walbourn.github.io/modern-c++-bitmask-types/
|
||||
#ifndef ENUM_FLAGS_CONSTEXPR
|
||||
#ifdef NTDDI_WIN10_RS1
|
||||
#if defined(NTDDI_WIN10_RS1) && !defined(__MINGW32__)
|
||||
#define ENUM_FLAGS_CONSTEXPR constexpr
|
||||
#else
|
||||
#define ENUM_FLAGS_CONSTEXPR const
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
using namespace DirectX;
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
#ifdef __MINGW32__
|
||||
const GUID IID_ID3D12Device = { 0x189819f1, 0x1db6, 0x4b57, { 0xbe, 0x54, 0x18, 0x21, 0x33, 0x9b, 0x85, 0xf7 } };
|
||||
#endif
|
||||
|
||||
// Include the precompiled shader code.
|
||||
namespace
|
||||
{
|
||||
|
|
14
Src/pch.h
14
Src/pch.h
|
@ -78,7 +78,7 @@
|
|||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4005)
|
||||
#define NOMINMAX
|
||||
#define NOMINMAX 1
|
||||
#define NODRAWTEXT
|
||||
#define NOGDI
|
||||
#define NOBITMAP
|
||||
|
@ -89,6 +89,10 @@
|
|||
|
||||
#include <Windows.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <unknwn.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT_WIN10
|
||||
#define _WIN32_WINNT_WIN10 0x0A00
|
||||
#endif
|
||||
|
@ -169,10 +173,12 @@
|
|||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
@ -219,11 +225,16 @@
|
|||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4467 5038 5204 5220)
|
||||
#ifdef __MINGW32__
|
||||
#include <wrl/client.h>
|
||||
#else
|
||||
#include <wrl.h>
|
||||
#endif
|
||||
#pragma warning(pop)
|
||||
|
||||
#include <wincodec.h>
|
||||
|
||||
#ifndef __MINGW32__
|
||||
// DirectX Tool Kit for Audio is in all versions of DirectXTK12
|
||||
#include <mmreg.h>
|
||||
#include <Audioclient.h>
|
||||
|
@ -247,3 +258,4 @@
|
|||
#include <shapexmacontext.h>
|
||||
#include <xma2defs.h>
|
||||
#endif
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче