### Project Setup and Version Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Sets the minimum CMake version and defines the project name, languages, and version. ```cmake cmake_minimum_required(VERSION 3.10.2) project(DirectX-Headers LANGUAGES CXX VERSION 1.619.1 ) ``` -------------------------------- ### Install DirectX Targets and Export CMake Targets Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt When DXHEADERS_INSTALL is enabled, this section installs the DirectX-Headers and DirectX-Guids targets. It also creates a CMake export file (directx-headers-targets.cmake) for use by other projects. ```cmake if (DXHEADERS_INSTALL) # Install the targets install(TARGETS DirectX-Headers DirectX-Guids EXPORT DirectX-Headers-Targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Create the targets CMake file which contains the above definitions install(EXPORT DirectX-Headers-Targets FILE directx-headers-targets.cmake NAMESPACE Microsoft:: DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) # Install the actual includes install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # Create the CMake config files include(CMakePackageConfigHelpers) write_basic_package_version_file("directx-headers-config-version.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/directx-headers-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) # Install the CMake config files install(FILES "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config-version.cmake" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) # Create pkg-config file include(cmake/JoinPaths.cmake) # from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files join_paths(DIRECTX_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") join_paths(DIRECTX_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/DirectX-Headers.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" @ONLY) # Install the pkg-config file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() ``` -------------------------------- ### Build Options Configuration Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Configures build options such as testing, installation, and Google Test suite, defaulting based on whether it's a top-level project. ```cmake set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) enable_testing() if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(IS_TOPLEVEL_PROJECT TRUE) else() set(IS_TOPLEVEL_PROJECT FALSE) endif() option(DXHEADERS_BUILD_TEST "Build the test" ${IS_TOPLEVEL_PROJECT}) option(DXHEADERS_INSTALL "Installation logic" ${IS_TOPLEVEL_PROJECT}) option(DXHEADERS_BUILD_GOOGLE_TEST "Build the google test suite" ${IS_TOPLEVEL_PROJECT}) ``` -------------------------------- ### Add Subdirectories for Testing Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt This section conditionally adds subdirectories for testing based on build flags. It includes the 'test' subdirectory if DXHEADERS_BUILD_TEST is enabled and the 'googletest' subdirectory if DXHEADERS_BUILD_GOOGLE_TEST is enabled, with a specific setting to prevent installing GoogleTest. ```cmake if (BUILD_TESTING) if (DXHEADERS_BUILD_TEST) add_subdirectory(test) endif() if (DXHEADERS_BUILD_GOOGLE_TEST) # We do not want to install GoogleTest when packaging DirectX-Headers. set(INSTALL_GTEST OFF) add_subdirectory(googletest) endif() endif() ``` -------------------------------- ### Project and C++ Standard Configuration Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Configures the main project with a description and sets the C++ standard to C++17, disabling extensions. ```cmake project(DirectX-Headers-Test DESCRIPTION "DirectX-Header test" HOMEPAGE_URL "https://github.com/microsoft/DirectX-Headers/" LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) ``` -------------------------------- ### Fetch GoogleTest using FetchContent Source: https://github.com/microsoft/directx-headers/blob/main/googletest/CMakeLists.txt Declares and makes available the GoogleTest library from its GitHub repository. This ensures the testing framework is present for the build. ```cmake include(FetchContent) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG main # Live at head ) FetchContent_MakeAvailable(googletest) ``` -------------------------------- ### Define Static Library for DirectX-Headers Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Creates a static library for DirectX-Headers and sets system and private include directories. ```cmake add_library(DirectX-Headers STATIC src/d3dx12_property_format_table.cpp) target_include_directories(DirectX-Headers SYSTEM PUBLIC "$" "$" ) target_include_directories(DirectX-Headers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/directx) ``` -------------------------------- ### Define COM/ATL Build Option Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Sets up an option to control whether the build uses COM with ATL CComPtr. ```cmake option(DXHEADERS_BUILD_COM_ATL "Build using ATL CComPtr" OFF) ``` -------------------------------- ### Define Static Library for DirectX-Guids Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Creates a static library for DirectX-Guids and links it with DirectX-Headers. ```cmake add_library(DirectX-Guids STATIC src/dxguids.cpp) target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers) ``` -------------------------------- ### Define and Link Test Executable Source: https://github.com/microsoft/directx-headers/blob/main/googletest/CMakeLists.txt Defines the main test executable 'Feature-Support-Test' and links it against DirectX-Headers, DirectX-Guids, and the GoogleTest main library. This prepares the test suite for compilation and execution. ```cmake project(DirectX-Headers-GoogleTest-Suite DESCRIPTION "DirectX-Header tests using GooleTest" HOMEPAGE_URL "https://github.com/microsoft/DirectX-Headers/" LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_executable(Feature-Support-Test feature_support_test.cpp) target_link_libraries(Feature-Support-Test DirectX-Headers DirectX-Guids ${dxlibs} gtest_main) add_test(Feature-Support-Test Feature-Support-Test) ``` -------------------------------- ### Define Test Executables Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Lists the names of the test executables to be built. ```cmake set(TEST_EXES DirectX-Headers-Test DirectX-Headers-Check-Feature-Support-Test) ``` -------------------------------- ### Add Test Executables and Tests Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Adds two executable targets for testing and registers them as CMake tests. ```cmake add_executable(DirectX-Headers-Test test.cpp) add_test(NAME DirectX-Headers-Test COMMAND DirectX-Headers-Test) add_executable(DirectX-Headers-Check-Feature-Support-Test feature_check_test.cpp) add_test(NAME DirectX-Headers-Check-Feature-Support-Test COMMAND DirectX-Headers-Check-Feature-Support-Test) ``` -------------------------------- ### Create Alias Target for DirectX-Headers Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Creates an alias target for DirectX-Headers for easier referencing. ```cmake add_library(Microsoft::DirectX-Headers ALIAS DirectX-Headers) ``` -------------------------------- ### Windows Specific Compile Definitions Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Sets common Windows-specific compile definitions for Unicode and target Windows version. ```cmake if(WIN32) foreach(t IN LISTS TEST_EXES) target_compile_definitions(${t} PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0A00) endforeach() if(WINDOWS_STORE) foreach(t IN LISTS TEST_EXES) target_compile_definitions(${t} PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_APP) endforeach() endif() endif() ``` -------------------------------- ### Create Alias Target for DirectX-Guids Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt Creates an alias target for DirectX-Guids for easier referencing. ```cmake add_library(Microsoft::DirectX-Guids ALIAS DirectX-Guids) ``` -------------------------------- ### Windows-Specific Compile Definitions Source: https://github.com/microsoft/directx-headers/blob/main/googletest/CMakeLists.txt Sets Windows-specific preprocessor definitions (_UNICODE, UNICODE, _WIN32_WINNT=0x0A00) for the test executable when building on a Windows platform. This ensures compatibility with Windows APIs. ```cmake if(WIN32) target_compile_definitions(Feature-Support-Test PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0A00) if(WINDOWS_STORE) target_compile_definitions(Feature-Support-Test PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_APP) endif() endif() ``` -------------------------------- ### Link Libraries to Test Executables Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Links the necessary DirectX libraries to all defined test executables. ```cmake foreach(t IN LISTS TEST_EXES) target_link_libraries(${t} DirectX-Headers DirectX-Guids ${dxlibs}) endforeach() ``` -------------------------------- ### Find DirectX Libraries in WSL Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Locates DirectX libraries (d3d12, dxcore) in a WSL environment. Falls back to default CMake search if not found in the specified path. ```cmake list(APPEND dxlibs "") # Check if in WSL and if has DirectX driver and runtime if(EXISTS "/usr/lib/wsl/lib/") find_library(libd3d12 d3d12 HINTS /usr/lib/wsl/lib) find_library(libdxcore dxcore HINTS /usr/lib/wsl/lib) list(APPEND dxlibs ${libd3d12} ${libdxcore}) else() # Fallback to default: let CMake look for libs list(APPEND dxlibs d3d12) if (MSVC) # MINGW doesn't have dxcore yet list(APPEND dxlibs dxcore) endif() endif() ``` -------------------------------- ### Add WSL Stubs Include Path for Non-Windows Targets Source: https://github.com/microsoft/directx-headers/blob/main/CMakeLists.txt For non-Windows targets, this snippet adds the WSL stubs to the include path for the DirectX-Headers target. This ensures that necessary stub headers are available when building on systems like Windows Subsystem for Linux. ```cmake if (NOT WIN32) target_include_directories(DirectX-Headers SYSTEM PUBLIC "$" "$" ) elseif((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) # MinGW has RPC headers which define old versions, and complain if D3D # headers are included before the RPC headers, since D3D headers were # generated with new MIDL and "require" new RPC headers. target_compile_definitions(DirectX-Headers PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") target_compile_definitions(DirectX-Guids PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") endif() ``` -------------------------------- ### Conditional Compile Definition for ATL Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Adds a compile definition for ATL support if the DXHEADERS_BUILD_COM_ATL option is enabled. ```cmake if(DXHEADERS_BUILD_COM_ATL) foreach(t IN LISTS TEST_EXES) target_compile_definitions(${t} PRIVATE D3DX12_USE_ATL) endforeach() endif() ``` -------------------------------- ### Compile Option for Clang/IntelLLVM Source: https://github.com/microsoft/directx-headers/blob/main/test/CMakeLists.txt Adds a specific compile option to suppress unused variable warnings for the feature check test when using Clang or IntelLLVM compilers. ```cmake if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM" ) target_compile_options(DirectX-Headers-Check-Feature-Support-Test PRIVATE -Wno-unused-variable) endif() ``` -------------------------------- ### Conditional Library Finding for WSL Source: https://github.com/microsoft/directx-headers/blob/main/googletest/CMakeLists.txt Attempts to find the d3d12 library in a specific WSL path, falling back to CMake's default search if the path does not exist. This ensures the DirectX 12 library is correctly linked. ```cmake list(APPEND dxlibs "") if(EXISTS "/usr/lib/wsl/lib/") find_library(libd3d12 d3d12 HINTS /usr/lib/wsl/lib) list(APPEND dxlibs ${libd3d12}) else() # Fallback to default: let CMake look for libs list(APPEND dxlibs d3d12) endif() ``` -------------------------------- ### Compiler-Specific Options for Clang Source: https://github.com/microsoft/directx-headers/blob/main/googletest/CMakeLists.txt Applies a specific compile option (-Wno-unused-variable) to the test executable when using the Clang compiler. This helps suppress warnings for unused variables during the build. ```cmake if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) target_compile_options(Feature-Support-Test PRIVATE -Wno-unused-variable) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.