summaryrefslogtreecommitdiff
path: root/cmake/FindDirectX.cmake
blob: 53d86e1f0e389e0d78c7543db1387f4adf52096a (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# - try to find DirectX include directories and libraries
#
# Once done this will define:
#
#  DirectX_XYZ_FOUND         - system has the XYZ API
#  DirectX_XYZ_INCLUDE_FOUND - system has the include for the XYZ API
#  DirectX_XYZ_INCLUDE_DIR   - include directory for the XYZ API
#  DirectX_XYZ_LIBRARY       - path/name for the XYZ library
#
# Where XYZ can be any of:
#
#  DDRAW
#  D3D
#  D3DX
#  D3D8
#  D3DX8
#  D3D9
#  D3DX9
#  D3D10
#  D3D10_1
#  D3DX10
#  D3D11
#  D3D11_1
#  D3D11_2
#  D3DX11
#  D2D1
#


include (CheckIncludeFileCXX)
include (FindPackageMessage)


if (WIN32)

    if (CMAKE_SIZEOF_VOID_P EQUAL 8)
        set (DirectX_ARCHITECTURE x64)
    else ()
        set (DirectX_ARCHITECTURE x86)
    endif ()

    # Can't use "$ENV{ProgramFiles(x86)}" to avoid violating CMP0053.  See
    # http://public.kitware.com/pipermail/cmake-developers/2014-October/023190.html
    set (ProgramFiles_x86 "ProgramFiles(x86)")
    if ("$ENV{${ProgramFiles_x86}}")
        set (ProgramFiles "$ENV{${ProgramFiles_x86}}")
    else ()
        set (ProgramFiles "$ENV{ProgramFiles}")
    endif ()

    find_path (DirectX_ROOT_DIR
        Include/d3d9.h
        PATHS
            "$ENV{DXSDK_DIR}"
            "${ProgramFiles}/Microsoft DirectX SDK (June 2010)"
            "${ProgramFiles}/Microsoft DirectX SDK (February 2010)"
            "${ProgramFiles}/Microsoft DirectX SDK (March 2009)"
            "${ProgramFiles}/Microsoft DirectX SDK (August 2008)"
            "${ProgramFiles}/Microsoft DirectX SDK (June 2008)"
            "${ProgramFiles}/Microsoft DirectX SDK (March 2008)"
            "${ProgramFiles}/Microsoft DirectX SDK (November 2007)"
            "${ProgramFiles}/Microsoft DirectX SDK (August 2007)"
            "${ProgramFiles}/Microsoft DirectX SDK"
        DOC "DirectX SDK root directory"
    )
    if (DirectX_ROOT_DIR)
        set (DirectX_INC_SEARCH_PATH "${DirectX_ROOT_DIR}/Include")
        set (DirectX_LIB_SEARCH_PATH "${DirectX_ROOT_DIR}/Lib/${DirectX_ARCHITECTURE}")
        set (DirectX_BIN_SEARCH_PATH "${DirectX_ROOT_DIR}/Utilities/bin/x86")
    endif ()

    # With VS 2011 and Windows 8 SDK, the DirectX SDK is included as part of
    # the Windows SDK.
    #
    # See also:
    # - http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx
    if (DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
        set (USE_WINSDK_HEADERS TRUE)
    endif ()

    # Find a header in the DirectX SDK
    macro (find_dxsdk_header var_name header)
        set (include_dir_var "DirectX_${var_name}_INCLUDE_DIR")
        set (include_found_var "DirectX_${var_name}_INCLUDE_FOUND")
        find_path (${include_dir_var} ${header}
            HINTS ${DirectX_INC_SEARCH_PATH}
            DOC "The directory where ${header} resides"
            CMAKE_FIND_ROOT_PATH_BOTH
        )
        if (${include_dir_var})
            set (${include_found_var} TRUE)
            find_package_message (${var_name}_INC "Found ${header} header: ${${include_dir_var}}/${header}" "[${${include_dir_var}}]")
        endif ()
        mark_as_advanced (${include_found_var})
    endmacro ()

    # Find a library in the DirectX SDK
    macro (find_dxsdk_library var_name library)
        # DirectX SDK
        set (library_var "DirectX_${var_name}_LIBRARY")
        find_library (${library_var} ${library}
            HINTS ${DirectX_LIB_SEARCH_PATH}
            DOC "The directory where ${library} resides"
            CMAKE_FIND_ROOT_PATH_BOTH
        )
        if (${library_var})
            find_package_message (${var_name}_LIB "Found ${library} library: ${${library_var}}" "[${${library_var}}]")
        endif ()
        mark_as_advanced (${library_var})
    endmacro ()

    # Find a header in the Windows SDK
    macro (find_winsdk_header var_name header)
        if (USE_WINSDK_HEADERS)
            # Windows SDK
            set (include_dir_var "DirectX_${var_name}_INCLUDE_DIR")
            set (include_found_var "DirectX_${var_name}_INCLUDE_FOUND")
            check_include_file_cxx (${header} ${include_found_var})
            set (${include_dir_var})
            mark_as_advanced (${include_found_var})
        else ()
            find_dxsdk_header (${var_name} ${header})
        endif ()
    endmacro ()

    # Find a library in the Windows SDK
    macro (find_winsdk_library var_name library)
        if (USE_WINSDK_HEADERS)
            # XXX: We currently just assume the library exists
            set (library_var "DirectX_${var_name}_LIBRARY")
            set (${library_var} ${library})
            mark_as_advanced (${library_var})
        else ()
            find_dxsdk_library (${var_name} ${library})
        endif ()
    endmacro ()

    # Combine header and library variables into an API found variable
    macro (find_combined var_name inc_var_name lib_var_name)
        if (DirectX_${inc_var_name}_INCLUDE_FOUND AND DirectX_${lib_var_name}_LIBRARY)
            set (DirectX_${var_name}_FOUND 1)
            find_package_message (${var_name} "Found ${var_name} API" "[${DirectX_${lib_var_name}_LIBRARY}][${DirectX_${inc_var_name}_INCLUDE_DIR}]")
        endif ()
    endmacro ()

    find_winsdk_header  (DDRAW   ddraw.h)
    find_winsdk_library (DDRAW   ddraw)
    find_combined       (DDRAW   DDRAW DDRAW)

    if (CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
        set (WINDOWS_XP TRUE)
    endif ()

    if (WINDOWS_XP)
        # Windows 7 SDKs, used by XP toolset, do not include d3d.h
        find_dxsdk_header   (D3D     d3d.h)
    else ()
        find_winsdk_header  (D3D     d3d.h)
    endif ()
    find_combined       (D3D     D3D DDRAW)

    find_dxsdk_header   (D3DX    d3dx.h)
    find_combined       (D3DX    D3DX D3DX)

    find_dxsdk_header   (D3D8    d3d8.h)
    find_dxsdk_library  (D3D8    d3d8)
    find_combined       (D3D8    D3D8 D3D8)

    find_dxsdk_header   (D3DX8   d3dx8.h)
    find_dxsdk_library  (D3DX8   d3dx8)
    find_combined       (D3DX8   D3DX8 D3DX8)

    find_winsdk_header  (D3D9    d3d9.h)
    find_winsdk_library (D3D9    d3d9)
    find_combined       (D3D9    D3D9 D3D9)

    find_dxsdk_header   (D3DX9   d3dx9.h)
    find_dxsdk_library  (D3DX9   d3dx9)
    find_combined       (D3DX9   D3DX9 D3DX9)

    if (NOT WINDOWS_XP)
        find_winsdk_header  (DXGI    dxgi.h)
        find_winsdk_header  (DXGI1_2 dxgi1_2.h)
        find_winsdk_header  (DXGI1_3 dxgi1_3.h)
        find_winsdk_library (DXGI    dxgi)

        find_winsdk_header  (D3D10   d3d10.h)
        find_winsdk_library (D3D10   d3d10)
        find_combined       (D3D10   D3D10 D3D10)

        find_winsdk_header  (D3D10_1 d3d10_1.h)
        find_winsdk_library (D3D10_1 d3d10_1)
        find_combined       (D3D10_1 D3D10_1 D3D10_1)

        find_dxsdk_header   (D3DX10  d3dx10.h)
        find_dxsdk_library  (D3DX10  d3dx10)
        find_combined       (D3DX10  D3DX10 D3DX10)

        find_winsdk_header  (D3D11   d3d11.h)
        find_winsdk_library (D3D11   d3d11)
        find_combined       (D3D11   D3D11 D3D11)
        find_winsdk_header  (D3D11_1 d3d11_1.h)
        find_combined       (D3D11_1 D3D11_1 D3D11)
        find_winsdk_header  (D3D11_2 d3d11_2.h)
        find_combined       (D3D11_2 D3D11_2 D3D11)

        find_dxsdk_header   (D3DX11  d3dx11.h)
        find_dxsdk_library  (D3DX11  d3dx11)
        find_combined       (D3DX11  D3DX11 D3DX11)

        find_winsdk_header  (D2D1    d2d1.h)
        find_winsdk_library (D2D1    d2d1)
        find_combined       (D2D1    D2D1 D2D1)
    endif ()

    find_program (DirectX_FXC_EXECUTABLE fxc
        HINTS ${DirectX_BIN_SEARCH_PATH}
        DOC "Path to fxc.exe executable."
    )

endif ()