/
CMakeLists.txt
288 lines (258 loc) · 10.7 KB
1
CMAKE_MINIMUM_REQUIRED(VERSION 3.12.0)
2
PROJECT(MojoShader)
3
4
5
# !!! FIXME: can we lowercase this file, if nothing else?
6
7
8
9
INCLUDE(CheckIncludeFile)
CHECK_INCLUDE_FILE(d3d11.h HAS_D3D11_H)
CHECK_INCLUDE_FILE(vulkan/vulkan.h HAS_VULKAN_H)
10
OPTION(BUILD_SHARED_LIBS "Build MojoShader as a shared library" OFF)
11
12
OPTION(PROFILE_D3D "Build MojoShader with support for the D3D profile" ON)
OPTION(PROFILE_BYTECODE "Build MojoShader with support for the BYTECODE profile" ON)
13
OPTION(PROFILE_HLSL "Build MojoShader with support for the HLSL profile" HAS_D3D11_H)
14
OPTION(PROFILE_GLSL120 "Build MojoShader with support for the GLSL120 profile" ON)
15
OPTION(PROFILE_GLSLES "Build MojoShader with support for the GLSLES profile" ON)
16
17
18
OPTION(PROFILE_GLSL "Build MojoShader with support for the GLSL profile" ON)
OPTION(PROFILE_ARB1 "Build MojoShader with support for the ARB1 profile" ON)
OPTION(PROFILE_ARB1_NV "Build MojoShader with support for the ARB1_NV profile" ON)
19
OPTION(PROFILE_METAL "Build MojoShader with support for the Metal profile" APPLE)
20
21
OPTION(PROFILE_SPIRV "Build MojoShader with support for the SPIR-V profile" HAS_VULKAN_H)
OPTION(PROFILE_GLSPIRV "Build MojoShader with support for the ARB_gl_spirv profile" HAS_VULKAN_H)
22
OPTION(EFFECT_SUPPORT "Build MojoShader with support for Effect framework files" ON)
23
OPTION(COMPILER_SUPPORT "Build MojoShader with support for HLSL source files" !WIN32) # TODO: Fix lemon on Windows
24
25
26
27
OPTION(FLIP_VIEWPORT "Build MojoShader with the ability to flip the GL viewport" OFF)
OPTION(DEPTH_CLIPPING "Build MojoShader with the ability to simulate [0, 1] depth clipping" OFF)
OPTION(XNA4_VERTEXTEXTURE "Build MojoShader with XNA4 vertex texturing behavior" OFF)
28
29
INCLUDE_DIRECTORIES(.)
30
31
32
# This was a Mercurial thing. In Git, it's always -1.
SET(MOJOSHADER_VERSION -1)
33
# If Git is installed and we are in a git repository, include the changeset as version information.
34
35
36
FIND_PROGRAM(GIT git DOC "Path to git command line app: https://git-scm.com/")
IF(NOT GIT)
MESSAGE(STATUS "Git not found. You can go on, but version info will be wrong.")
37
SET(MOJOSHADER_CHANGESET "???")
38
39
40
41
ELSE(NOT GIT)
MARK_AS_ADVANCED(GIT)
# !!! FIXME: this didn't actually use the GIT variable...
42
43
# See if we are in a git repository.
44
EXECUTE_PROCESS(
45
COMMAND git rev-parse --show-toplevel
46
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
47
48
OUTPUT_VARIABLE MOJOSHADER_GIT_TOPLEVEL_DIR
RESULT_VARIABLE GITVERSION_RC
49
ERROR_QUIET
50
OUTPUT_STRIP_TRAILING_WHITESPACE
51
)
52
53
IF(NOT GITVERSION_RC EQUAL 0)
MESSAGE(STATUS "Git repository not found. You can go on, but version info will be wrong.")
54
SET(MOJOSHADER_CHANGESET "???")
55
56
ELSE(NOT GITVERSION_RC EQUAL 0)
# Query the changeset.
57
EXECUTE_PROCESS(
58
COMMAND git rev-list HEAD~..
59
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
60
61
RESULT_VARIABLE GITVERSION_RC
OUTPUT_VARIABLE MOJOSHADER_GIT_CHANGESET
62
63
64
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
65
66
67
68
69
70
71
IF(NOT GITVERSION_RC EQUAL 0)
SET(MOJOSHADER_CHANGESET "???")
ELSE(NOT GITVERSION_RC EQUAL 0)
SET(MOJOSHADER_CHANGESET "git-${MOJOSHADER_GIT_CHANGESET}")
ENDIF(NOT GITVERSION_RC EQUAL 0)
ENDIF(NOT GITVERSION_RC EQUAL 0)
ENDIF(NOT GIT)
72
73
74
75
76
77
78
79
80
81
82
WRITE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_version.h"
"/* This file was autogenerated. Do not edit! */\n"
"#ifndef _INCL_MOJOSHADER_VERSION_H_\n"
"#define _INCL_MOJOSHADER_VERSION_H_\n"
"#define MOJOSHADER_VERSION ${MOJOSHADER_VERSION}\n"
"#define MOJOSHADER_CHANGESET \"${MOJOSHADER_CHANGESET}\"\n"
"#endif\n"
)
83
84
85
86
IF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-Wall -ggdb3)
ENDIF(CMAKE_COMPILER_IS_GNUCC)
87
88
# testparse uses this when I'm looking at memory usage patterns.
#ADD_DEFINITIONS(-DMOJOSHADER_DEBUG_MALLOC=1)
89
90
91
92
93
94
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS=1)
ADD_DEFINITIONS(-TP) # force .c files to compile as C++.
ENDIF(MSVC)
95
# We build lemon, then use it to generate parser C code.
96
97
98
99
100
101
IF(COMPILER_SUPPORT)
ADD_EXECUTABLE(lemon "misc/lemon.c")
ADD_CUSTOM_COMMAND(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.h"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.lemon"
DEPENDS lemon "${CMAKE_CURRENT_SOURCE_DIR}/misc/lempar.c"
102
COMMAND lemon
103
104
105
ARGS -q "-T${CMAKE_CURRENT_SOURCE_DIR}/misc/lempar.c" "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.lemon"
)
ENDIF(COMPILER_SUPPORT)
106
107
IF(APPLE)
108
109
110
IF(NOT IOS)
find_library(CARBON_FRAMEWORK Carbon) # Stupid Gestalt.
ENDIF(NOT IOS)
111
112
113
114
115
116
117
118
ENDIF(APPLE)
IF(NOT PROFILE_D3D)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_D3D=0)
ENDIF(NOT PROFILE_D3D)
IF(NOT PROFILE_BYTECODE)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_BYTECODE=0)
ENDIF(NOT PROFILE_BYTECODE)
119
120
121
IF(NOT PROFILE_HLSL)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_HLSL=0)
ENDIF(NOT PROFILE_HLSL)
122
123
124
IF(NOT PROFILE_GLSL120)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_GLSL120=0)
ENDIF(NOT PROFILE_GLSL120)
125
126
127
IF(NOT PROFILE_GLSLES)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_GLSLES=0)
ENDIF(NOT PROFILE_GLSLES)
128
129
130
IF(NOT PROFILE_GLSLES3)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_GLSLES3=0)
ENDIF(NOT PROFILE_GLSLES3)
131
132
133
134
135
136
137
138
139
IF(NOT PROFILE_GLSL)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_GLSL=0)
ENDIF(NOT PROFILE_GLSL)
IF(NOT PROFILE_ARB1)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_ARB1=0)
ENDIF(NOT PROFILE_ARB1)
IF(NOT PROFILE_ARB1_NV)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_ARB1_NV=0)
ENDIF(NOT PROFILE_ARB1_NV)
140
141
IF(NOT PROFILE_METAL)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_METAL=0)
142
143
ELSE(NOT PROFILE_METAL)
SET(LOBJC -lobjc)
144
ENDIF(NOT PROFILE_METAL)
145
146
147
IF(NOT PROFILE_SPIRV)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_SPIRV=0)
ENDIF(NOT PROFILE_SPIRV)
148
149
150
IF(NOT PROFILE_GLSPIRV)
ADD_DEFINITIONS(-DSUPPORT_PROFILE_GLSPIRV=0)
ENDIF(NOT PROFILE_GLSPIRV)
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
IF(EFFECT_SUPPORT)
IF(UNIX)
SET(LIBM -lm)
ENDIF(UNIX)
ADD_DEFINITIONS(-DMOJOSHADER_EFFECT_SUPPORT)
ENDIF(EFFECT_SUPPORT)
IF(FLIP_VIEWPORT)
ADD_DEFINITIONS(-DMOJOSHADER_FLIP_RENDERTARGET)
ENDIF(FLIP_VIEWPORT)
IF(DEPTH_CLIPPING)
ADD_DEFINITIONS(-DMOJOSHADER_DEPTH_CLIPPING)
ENDIF(DEPTH_CLIPPING)
IF(XNA4_VERTEXTEXTURE)
ADD_DEFINITIONS(-DMOJOSHADER_XNA4_VERTEX_TEXTURES)
ENDIF(XNA4_VERTEXTEXTURE)
171
ADD_LIBRARY(mojoshader
172
mojoshader.c
173
mojoshader_common.c
174
mojoshader_opengl.c
175
mojoshader_metal.c
176
mojoshader_d3d11.c
177
mojoshader_vulkan.c
178
179
180
profiles/mojoshader_profile_arb1.c
profiles/mojoshader_profile_bytecode.c
profiles/mojoshader_profile_d3d.c
181
profiles/mojoshader_profile_hlsl.c
182
183
profiles/mojoshader_profile_glsl.c
profiles/mojoshader_profile_metal.c
184
profiles/mojoshader_profile_spirv.c
185
profiles/mojoshader_profile_common.c
186
)
187
188
189
190
191
192
193
194
195
196
197
198
199
IF(EFFECT_SUPPORT)
TARGET_SOURCES(mojoshader PRIVATE
mojoshader_effects.c
)
ENDIF(EFFECT_SUPPORT)
IF(COMPILER_SUPPORT)
TARGET_SOURCES(mojoshader PRIVATE
mojoshader_compiler.c
mojoshader_preprocessor.c
mojoshader_lexer.c
mojoshader_assembler.c
)
ENDIF(COMPILER_SUPPORT)
200
IF(BUILD_SHARED_LIBS)
201
TARGET_LINK_LIBRARIES(mojoshader ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
202
ENDIF(BUILD_SHARED_LIBS)
203
204
# These are fallback paths for Vulkan/D3D11, try to have this on the system instead!
205
TARGET_INCLUDE_DIRECTORIES(mojoshader PUBLIC
206
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../Vulkan-Headers/include>
207
208
209
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../dxvk-native/include/native/directx>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../dxvk-native/include/native/windows>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../dxvk-native/include/native/wsi>
210
211
)
212
213
SET_SOURCE_FILES_PROPERTIES(
mojoshader_compiler.c
214
PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.h"
215
216
)
217
218
219
220
221
222
FIND_PROGRAM(RE2C re2c DOC "Path to re2c command line app: http://re2c.org/")
IF(NOT RE2C)
MESSAGE(STATUS "re2c missing. You can go on, but can't rebuild the lexer.")
ELSE(NOT RE2C)
MARK_AS_ADVANCED(RE2C)
ADD_CUSTOM_COMMAND(
223
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_lexer.c"
224
DEPENDS mojoshader_lexer.re
225
226
COMMAND "${RE2C}"
ARGS -is --no-generation-date -o "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_lexer.c" "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_lexer.re"
227
228
)
ENDIF(NOT RE2C)
229
230
231
232
find_package(SDL2)
IF(SDL2_FOUND)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS})
233
ADD_EXECUTABLE(glcaps utils/glcaps.c)
234
TARGET_LINK_LIBRARIES(glcaps ${SDL2_LIBRARIES} ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
235
ADD_EXECUTABLE(bestprofile utils/bestprofile.c)
236
TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL2_LIBRARIES} ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
237
ADD_EXECUTABLE(availableprofiles utils/availableprofiles.c)
238
TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL2_LIBRARIES} ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
239
ADD_EXECUTABLE(testglcompile utils/testglcompile.c)
240
241
TARGET_LINK_LIBRARIES(testglcompile mojoshader ${SDL2_LIBRARIES} ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
ENDIF(SDL2_FOUND)
242
243
244
IF(COMPILER_SUPPORT)
ADD_EXECUTABLE(finderrors utils/finderrors.c)
245
246
IF(SDL2_FOUND)
TARGET_LINK_LIBRARIES(finderrors mojoshader ${SDL2_LIBRARIES} ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
247
248
249
250
SET_SOURCE_FILES_PROPERTIES(
utils/finderrors.c
PROPERTIES COMPILE_FLAGS "-DFINDERRORS_COMPILE_SHADERS=1"
)
251
ELSE(SDL2_FOUND)
252
TARGET_LINK_LIBRARIES(finderrors mojoshader ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
253
ENDIF(SDL2_FOUND)
254
ENDIF(COMPILER_SUPPORT)
255
256
257
258
259
260
261
262
FIND_PATH(SPIRV_TOOLS_INCLUDE_DIR "spirv-tools/libspirv.h" PATH_SUFFIXES "include")
FIND_LIBRARY(SPIRV_TOOLS_LIBRARY NAMES SPIRV-Tools-shared)
IF(SPIRV_TOOLS_INCLUDE_DIR AND SPIRV_TOOLS_LIBRARY)
INCLUDE_DIRECTORIES(${SPIRV_TOOLS_INCLUDE_DIR})
ADD_DEFINITIONS(-DMOJOSHADER_HAS_SPIRV_TOOLS)
ENDIF(SPIRV_TOOLS_INCLUDE_DIR AND SPIRV_TOOLS_LIBRARY)
263
ADD_EXECUTABLE(testparse utils/testparse.c)
264
TARGET_LINK_LIBRARIES(testparse mojoshader ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
265
266
267
IF(SPIRV_TOOLS_INCLUDE_DIR AND SPIRV_TOOLS_LIBRARY)
TARGET_LINK_LIBRARIES(testparse ${SPIRV_TOOLS_LIBRARY})
ENDIF(SPIRV_TOOLS_INCLUDE_DIR AND SPIRV_TOOLS_LIBRARY)
268
ADD_EXECUTABLE(testoutput utils/testoutput.c)
269
TARGET_LINK_LIBRARIES(testoutput mojoshader ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
270
271
IF(COMPILER_SUPPORT)
ADD_EXECUTABLE(mojoshader-compiler utils/mojoshader-compiler.c)
272
TARGET_LINK_LIBRARIES(mojoshader-compiler mojoshader ${LIBM} ${LOBJC} ${CARBON_FRAMEWORK})
273
ENDIF(COMPILER_SUPPORT)
274
275
# Unit tests...
276
277
278
279
280
281
282
283
284
285
IF(COMPILER_SUPPORT)
ADD_CUSTOM_TARGET(
test
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/run_tests.pl"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS mojoshader-compiler
COMMENT "Running unit tests..."
VERBATIM
)
ENDIF(COMPILER_SUPPORT)
286
287
# End of CMakeLists.txt ...