2021-06-03 02:18:53 +03:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2021-02-08 05:07:14 +03:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2022-11-22 23:00:00 +03:00
|
|
|
cmake_minimum_required (VERSION 3.20)
|
2021-02-08 05:07:14 +03:00
|
|
|
|
2024-08-15 01:25:02 +03:00
|
|
|
set(DXUT_VERSION 11.32)
|
2021-02-08 05:07:14 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
if(WINDOWS_STORE OR (DEFINED XBOX_CONSOLE_TARGET))
|
|
|
|
message(FATAL "DXUT does not support UWP or Xbox")
|
|
|
|
endif()
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
project (DXUT
|
|
|
|
VERSION ${DXUT_VERSION}
|
|
|
|
DESCRIPTION "DXUT for DirectX 11"
|
|
|
|
HOMEPAGE_URL "http://go.microsoft.com/fwlink/?LinkId=320437"
|
|
|
|
LANGUAGES CXX)
|
|
|
|
|
2022-12-07 10:47:04 +03:00
|
|
|
# https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
|
|
|
|
option(ENABLE_SPECTRE_MITIGATION "Build using /Qspectre for MSVC" OFF)
|
|
|
|
|
2023-01-03 01:10:54 +03:00
|
|
|
option(DISABLE_MSVC_ITERATOR_DEBUGGING "Disable iterator debugging in Debug configurations with the MSVC CRT" OFF)
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
|
|
|
|
|
2022-08-18 03:17:20 +03:00
|
|
|
option(DIRECTXTK_INTEGRATION "Support mixing with DirectX Tool Kit" OFF)
|
|
|
|
|
2022-05-24 08:24:15 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2021-02-08 05:07:14 +03:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2024-01-17 02:18:28 +03:00
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
2021-02-08 05:07:14 +03:00
|
|
|
|
2022-05-22 22:10:50 +03:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
#--- Core Library
|
|
|
|
set(CORE_LIBRARY_HEADERS
|
|
|
|
Core/dxerr.h
|
|
|
|
Core/DXUT.h
|
|
|
|
Core/DXUTDevice11.h
|
|
|
|
Core/DXUTmisc.h
|
|
|
|
)
|
|
|
|
|
|
|
|
set(CORE_LIBRARY_SOURCES
|
|
|
|
Core/dxerr.cpp
|
|
|
|
Core/DXUT.cpp
|
|
|
|
Core/DXUTDevice11.cpp
|
|
|
|
Core/DXUTmisc.cpp
|
|
|
|
)
|
|
|
|
|
2022-12-03 09:43:55 +03:00
|
|
|
if(NOT DIRECTXTK_INTEGRATION)
|
2022-08-18 03:17:20 +03:00
|
|
|
list(APPEND CORE_LIBRARY_HEADERS
|
|
|
|
Core/DDSTextureLoader.h
|
|
|
|
Core/ScreenGrab.h
|
|
|
|
Core/WICTextureLoader.h
|
|
|
|
)
|
|
|
|
list(APPEND CORE_LIBRARY_SOURCES
|
|
|
|
Core/DDSTextureLoader.cpp
|
|
|
|
Core/ScreenGrab.cpp
|
|
|
|
Core/WICTextureLoader.cpp
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
add_library(${PROJECT_NAME} STATIC ${CORE_LIBRARY_SOURCES} ${CORE_LIBRARY_HEADERS})
|
|
|
|
|
|
|
|
#--- Optional Library
|
|
|
|
set(OPT_LIBRARY_HEADERS
|
|
|
|
Optional/DXUTcamera.h
|
|
|
|
Optional/DXUTgui.h
|
|
|
|
Optional/DXUTLockFreePipe.h
|
|
|
|
Optional/DXUTres.h
|
|
|
|
Optional/DXUTsettingsdlg.h
|
|
|
|
Optional/SDKmesh.h
|
|
|
|
Optional/SDKmisc.h
|
|
|
|
)
|
|
|
|
|
|
|
|
set(OPT_LIBRARY_SOURCES
|
|
|
|
Optional/DXUTcamera.cpp
|
|
|
|
Optional/DXUTgui.cpp
|
|
|
|
Optional/DXUTres.cpp
|
|
|
|
Optional/DXUTsettingsdlg.cpp
|
|
|
|
Optional/SDKmesh.cpp
|
|
|
|
Optional/SDKmisc.cpp
|
|
|
|
)
|
|
|
|
|
2022-05-24 08:24:15 +03:00
|
|
|
if(NOT MINGW)
|
|
|
|
set(OPT_LIBRARY_HEADERS
|
|
|
|
${OPT_LIBRARY_HEADERS}
|
|
|
|
Optional/DXUTguiIME.h
|
|
|
|
Optional/ImeUi.h
|
|
|
|
)
|
|
|
|
|
|
|
|
set(OPT_LIBRARY_SOURCES
|
|
|
|
${OPT_LIBRARY_SOURCES}
|
|
|
|
Optional/DXUTguiIME.cpp
|
|
|
|
Optional/ImeUi.cpp
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
add_library(${PROJECT_NAME}Opt STATIC ${OPT_LIBRARY_SOURCES} ${OPT_CORE_LIBRARY_HEADERS})
|
|
|
|
|
2022-12-03 09:43:55 +03:00
|
|
|
if(NOT MINGW)
|
2021-02-08 05:07:14 +03:00
|
|
|
target_precompile_headers(${PROJECT_NAME} PRIVATE Core/DXUT.h)
|
|
|
|
target_precompile_headers(${PROJECT_NAME}Opt PRIVATE Core/DXUT.h)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
source_group(DXUT REGULAR_EXPRESSION Core/*.*)
|
|
|
|
source_group(DXUTOpt REGULAR_EXPRESSION Optional/*.*)
|
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Core>
|
2022-05-22 22:10:50 +03:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME}Opt PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Optional>
|
2022-05-22 22:10:50 +03:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
|
2021-02-08 05:07:14 +03:00
|
|
|
PRIVATE Core/)
|
|
|
|
|
2022-12-03 09:43:55 +03:00
|
|
|
if(DIRECTXTK_INTEGRATION)
|
2022-08-18 03:17:20 +03:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_DIRECTXTK)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}Opt PRIVATE USE_DIRECTXTK)
|
|
|
|
|
|
|
|
find_package(directxtk REQUIRED)
|
|
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXTK)
|
|
|
|
target_link_libraries(${PROJECT_NAME}Opt PRIVATE Microsoft::DirectXTK)
|
|
|
|
endif()
|
|
|
|
|
2022-08-17 22:45:58 +03:00
|
|
|
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
|
|
|
|
target_compile_features(${PROJECT_NAME}Opt PUBLIC cxx_std_11)
|
|
|
|
|
2023-02-10 04:05:29 +03:00
|
|
|
if(MINGW)
|
2022-08-17 22:45:58 +03:00
|
|
|
find_package(directxmath CONFIG REQUIRED)
|
2023-02-10 04:05:29 +03:00
|
|
|
else()
|
|
|
|
find_package(directxmath CONFIG QUIET)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(directxmath_FOUND)
|
|
|
|
message(STATUS "Using DirectXMath package")
|
|
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC Microsoft::DirectXMath)
|
|
|
|
target_link_libraries(${PROJECT_NAME}Opt PUBLIC Microsoft::DirectXMath)
|
2022-08-17 22:45:58 +03:00
|
|
|
endif()
|
|
|
|
|
2021-02-08 05:07:14 +03:00
|
|
|
#--- Package
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
string(TOLOWER ${PROJECT_NAME} PACKAGE_NAME)
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
2022-05-22 22:10:50 +03:00
|
|
|
${PACKAGE_NAME}-config-version.cmake
|
2021-02-08 05:07:14 +03:00
|
|
|
VERSION ${DXUT_VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
|
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
|
|
EXPORT ${PROJECT_NAME}-targets
|
2022-05-22 22:10:50 +03:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
install(TARGETS ${PROJECT_NAME}Opt
|
|
|
|
EXPORT ${PROJECT_NAME}Opt-targets
|
2022-05-22 22:10:50 +03:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
2022-12-07 10:47:04 +03:00
|
|
|
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/build/${PROJECT_NAME}-config.cmake.in
|
2022-05-22 22:10:50 +03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
|
2022-08-18 00:16:37 +03:00
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
|
|
|
NAMESPACE Microsoft::
|
2022-08-18 00:16:37 +03:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
install(EXPORT ${PROJECT_NAME}Opt-targets
|
|
|
|
FILE ${PROJECT_NAME}Opt-targets.cmake
|
|
|
|
NAMESPACE Microsoft::
|
2022-08-18 00:16:37 +03:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
install(FILES ${CORE_LIBRARY_HEADERS} ${OPT_LIBRARY_HEADERS}
|
2022-05-22 22:10:50 +03:00
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
install(FILES
|
2022-05-22 22:10:50 +03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
|
2022-08-18 00:16:37 +03:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
|
|
|
if(MSVC)
|
2024-07-27 01:42:41 +03:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /EHsc /GR-)
|
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE /W4 /EHsc /GR-)
|
|
|
|
endif()
|
2022-12-07 10:47:04 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
include(build/CompilerAndLinker.cmake)
|
2023-05-18 01:52:16 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE ${COMPILER_DEFINES})
|
|
|
|
target_compile_definitions(${PROJECT_NAME}Opt PRIVATE ${COMPILER_DEFINES})
|
2022-05-24 08:24:15 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILER_SWITCHES})
|
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE ${COMPILER_SWITCHES})
|
2022-05-24 08:24:15 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE ${LINKER_SWITCHES})
|
|
|
|
target_link_options(${PROJECT_NAME}Opt PRIVATE ${LINKER_SWITCHES})
|
2021-02-08 05:07:14 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
|
2022-05-23 09:52:59 +03:00
|
|
|
set(WarningsLib "-Wno-deprecated-declarations" "-Wno-unused-const-variable" "-Wno-switch" "-Wno-ignored-attributes")
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
|
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE ${WarningsLib})
|
2024-07-27 01:42:41 +03:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB")
|
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2022-03-19 10:38:48 +03:00
|
|
|
if(ENABLE_CODE_ANALYSIS)
|
2024-05-18 00:32:44 +03:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /analyze /WX)
|
2024-07-27 01:42:41 +03:00
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE /analyze /WX)
|
2022-03-19 10:38:48 +03:00
|
|
|
endif()
|
2022-11-22 23:00:00 +03:00
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
if(ENABLE_SPECTRE_MITIGATION
|
|
|
|
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.13))
|
|
|
|
message(STATUS "Building Spectre-mitigated libraries")
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE "/Qspectre")
|
|
|
|
target_compile_options(${PROJECT_NAME}Opt PRIVATE "/Qspectre")
|
2023-04-24 23:45:19 +03:00
|
|
|
endif()
|
2021-02-08 05:07:14 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(WIN32)
|
2023-05-18 01:52:16 +03:00
|
|
|
if(${DIRECTX_ARCH} MATCHES "^arm64")
|
|
|
|
message(STATUS "Building for Windows 10/Windows 11.")
|
|
|
|
set(WINVER 0x0A00)
|
|
|
|
elseif(${DIRECTX_ARCH} MATCHES "^arm")
|
|
|
|
message(STATUS "Building for Windows 8.")
|
|
|
|
set(WINVER 0x0602)
|
|
|
|
else()
|
|
|
|
message(STATUS "Building for Windows 7.")
|
|
|
|
set(WINVER 0x0601)
|
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN7_PLATFORM_UPDATE)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}Opt PRIVATE _WIN7_PLATFORM_UPDATE)
|
|
|
|
endif()
|
|
|
|
|
2024-07-27 01:42:41 +03:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=${WINVER})
|
|
|
|
target_compile_definitions(${PROJECT_NAME}Opt PRIVATE _WIN32_WINNT=${WINVER})
|
2023-01-03 01:10:54 +03:00
|
|
|
|
|
|
|
if(DISABLE_MSVC_ITERATOR_DEBUGGING)
|
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _ITERATOR_DEBUG_LEVEL=0)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}Opt PRIVATE _ITERATOR_DEBUG_LEVEL=0)
|
|
|
|
endif()
|
2021-02-08 05:07:14 +03:00
|
|
|
endif()
|
2024-07-27 01:42:41 +03:00
|
|
|
|
|
|
|
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
|