aboutsummaryrefslogtreecommitdiff
path: root/contrib/DirectX-Headers/CMakeLists.txt
blob: 9d3c51b4d42e630381b78ba2d669a181511b4a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.10.2)
project(DirectX-Headers
    LANGUAGES CXX
    VERSION 1.4.9
)

set(CMAKE_CXX_STANDARD 14) 
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# It's useful to know if you are a top level project or not, if your project is
# being consumed via add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
    set(IS_TOPLEVEL_PROJECT TRUE)
else()
    set(IS_TOPLEVEL_PROJECT FALSE)
endif()

# Use DXHEADERS_* prefix to avoid potential name conflicts in cmake-gui, and allow
# grouping by prefix if more options are added
#
# Testing should only be enabled by default if we are top level. Otherwise clients can set it
# either via cmake or cmake-gui
option(DXHEADERS_BUILD_TEST "Build the test" ${IS_TOPLEVEL_PROJECT})
option(DXHEADERS_INSTALL "Installation logic" ${IS_TOPLEVEL_PROJECT})

include(GNUInstallDirs)

# Enables consumers to add this library as a link target to automatically add
# these include directories, regardless of whether this is referenced via subdirectory
# or from an installed location
add_library(DirectX-Headers INTERFACE)
target_include_directories(DirectX-Headers SYSTEM INTERFACE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

# For non-Windows targets, also add the WSL stubs to the include path
if (NOT WIN32)
    target_include_directories(DirectX-Headers SYSTEM INTERFACE
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/wsl/stubs>"
        "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/wsl/stubs>"
    )
endif()

add_library(Microsoft::DirectX-Headers ALIAS DirectX-Headers)

add_library(DirectX-Guids STATIC src/dxguids.cpp)
target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers)

add_library(Microsoft::DirectX-Guids ALIAS DirectX-Guids)

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)
endif()

if (DXHEADERS_BUILD_TEST)
    add_subdirectory(test) 
endif()