|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | +cmake_minimum_required(VERSION 3.10.2) |
| 4 | +project(DirectX-Headers |
| 5 | + LANGUAGES CXX |
| 6 | + VERSION 1.614.1 |
| 7 | +) |
| 8 | +include(CTest) |
| 9 | +set(CMAKE_CXX_STANDARD 14) |
| 10 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 12 | +enable_testing() |
| 13 | + |
| 14 | +# It's useful to know if you are a top level project or not, if your project is |
| 15 | +# being consumed via add_subdirectory |
| 16 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 17 | + set(IS_TOPLEVEL_PROJECT TRUE) |
| 18 | +else() |
| 19 | + set(IS_TOPLEVEL_PROJECT FALSE) |
| 20 | +endif() |
| 21 | + |
| 22 | +# Use DXHEADERS_* prefix to avoid potential name conflicts in cmake-gui, and allow |
| 23 | +# grouping by prefix if more options are added |
| 24 | +# |
| 25 | +# Testing should only be enabled by default if we are top level. Otherwise clients can set it |
| 26 | +# either via cmake or cmake-gui |
| 27 | +option(DXHEADERS_BUILD_TEST "Build the test" ${IS_TOPLEVEL_PROJECT}) |
| 28 | +option(DXHEADERS_INSTALL "Installation logic" ${IS_TOPLEVEL_PROJECT}) |
| 29 | +option(DXHEADERS_BUILD_GOOGLE_TEST "Build the google test suite" ${IS_TOPLEVEL_PROJECT}) |
| 30 | + |
| 31 | +include(GNUInstallDirs) |
| 32 | + |
| 33 | +# Enables consumers to add this library as a link target to automatically add |
| 34 | +# these include directories, regardless of whether this is referenced via subdirectory |
| 35 | +# or from an installed location |
| 36 | +add_library(DirectX-Headers STATIC src/d3dx12_property_format_table.cpp) |
| 37 | +target_include_directories(DirectX-Headers SYSTEM PUBLIC |
| 38 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 39 | + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" |
| 40 | +) |
| 41 | +target_include_directories(DirectX-Headers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/directx) |
| 42 | + |
| 43 | +add_library(Microsoft::DirectX-Headers ALIAS DirectX-Headers) |
| 44 | + |
| 45 | +add_library(DirectX-Guids STATIC src/dxguids.cpp) |
| 46 | +target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers) |
| 47 | + |
| 48 | +add_library(Microsoft::DirectX-Guids ALIAS DirectX-Guids) |
| 49 | + |
| 50 | +# For non-Windows targets, also add the WSL stubs to the include path |
| 51 | +if (NOT WIN32) |
| 52 | + target_include_directories(DirectX-Headers SYSTEM PUBLIC |
| 53 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/wsl/stubs>" |
| 54 | + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/wsl/stubs>" |
| 55 | + ) |
| 56 | +elseif((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) |
| 57 | + # MinGW has RPC headers which define old versions, and complain if D3D |
| 58 | + # headers are included before the RPC headers, since D3D headers were |
| 59 | + # generated with new MIDL and "require" new RPC headers. |
| 60 | + target_compile_definitions(DirectX-Headers PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") |
| 61 | + target_compile_definitions(DirectX-Guids PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") |
| 62 | +endif() |
| 63 | + |
| 64 | +if (DXHEADERS_INSTALL) |
| 65 | + # Install the targets |
| 66 | + install(TARGETS DirectX-Headers DirectX-Guids |
| 67 | + EXPORT DirectX-Headers-Targets |
| 68 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 69 | + # Create the targets CMake file which contains the above definitions |
| 70 | + install(EXPORT DirectX-Headers-Targets FILE directx-headers-targets.cmake |
| 71 | + NAMESPACE Microsoft:: |
| 72 | + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) |
| 73 | + |
| 74 | + # Install the actual includes |
| 75 | + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" |
| 76 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 77 | + |
| 78 | + # Create the CMake config files |
| 79 | + include(CMakePackageConfigHelpers) |
| 80 | + write_basic_package_version_file("directx-headers-config-version.cmake" |
| 81 | + VERSION ${PROJECT_VERSION} |
| 82 | + COMPATIBILITY SameMajorVersion) |
| 83 | + configure_package_config_file( |
| 84 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/directx-headers-config.cmake.in" |
| 85 | + "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" |
| 86 | + INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) |
| 87 | + |
| 88 | + # Install the CMake config files |
| 89 | + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" |
| 90 | + "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config-version.cmake" |
| 91 | + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) |
| 92 | + |
| 93 | + # Create pkg-config file |
| 94 | + include(cmake/JoinPaths.cmake) |
| 95 | + # from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files |
| 96 | + join_paths(DIRECTX_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") |
| 97 | + join_paths(DIRECTX_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") |
| 98 | + configure_file( |
| 99 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/DirectX-Headers.pc.in" |
| 100 | + "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" @ONLY) |
| 101 | + |
| 102 | + # Install the pkg-config file |
| 103 | + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" |
| 104 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 105 | + |
| 106 | +endif() |
| 107 | + |
| 108 | +if (BUILD_TESTING) |
| 109 | + if (DXHEADERS_BUILD_TEST) |
| 110 | + add_subdirectory(test) |
| 111 | + endif() |
| 112 | + |
| 113 | + if (DXHEADERS_BUILD_GOOGLE_TEST) |
| 114 | + # We do not want to install GoogleTest when packaging DirectX-Headers. |
| 115 | + set(INSTALL_GTEST OFF) |
| 116 | + add_subdirectory(googletest) |
| 117 | + endif() |
| 118 | +endif() |
0 commit comments