forked from FNA-XNA/FNA3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
240 lines (224 loc) · 7.02 KB
/
CMakeLists.txt
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# CMake Project for FNA3D
# Written by @NeroBurner
cmake_minimum_required(VERSION 2.8.12)
project(FNA3D C)
# Options
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(TRACING_SUPPORT "Build with tracing enabled" OFF)
option(BUILD_SDL3 "Build against SDL 3.0" OFF)
option(MOJOSHADER_STATIC_SPIRVCROSS "Build against statically linked spirvcross" OFF)
# Version
SET(LIB_MAJOR_VERSION "0")
SET(LIB_MINOR_VERSION "24")
SET(LIB_REVISION "11")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
# Build Type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# By default, we use Release
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE
STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug" "Release" "RelWithDebInfo"
)
endif()
# Platform Flags
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
set(LOBJC "objc")
elseif(WIN32)
# "FNA3D.dll", not "libFNA3D.dll"
set(CMAKE_SHARED_LIBRARY_PREFIX "")
else()
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_search_module(DXVK_NATIVE dxvk-dxgi)
if(DXVK_NATIVE_FOUND)
set(BUILD_DXVK_NATIVE ON)
endif()
endif()
endif()
# Defines
add_definitions(
-DFNA3D_DRIVER_VULKAN
-DFNA3D_DRIVER_OPENGL
)
if(BUILD_SDL3)
add_definitions(-DFNA3D_DRIVER_SDL)
endif()
add_definitions(
-DMOJOSHADER_NO_VERSION_INCLUDE
-DMOJOSHADER_USE_SDL_STDLIB
-DMOJOSHADER_EFFECT_SUPPORT
-DMOJOSHADER_DEPTH_CLIPPING
-DMOJOSHADER_FLIP_RENDERTARGET
-DMOJOSHADER_XNA4_VERTEX_TEXTURES
-DSUPPORT_PROFILE_ARB1=0
-DSUPPORT_PROFILE_ARB1_NV=0
-DSUPPORT_PROFILE_BYTECODE=0
-DSUPPORT_PROFILE_D3D=0
)
if(TRACING_SUPPORT)
add_definitions(-DFNA3D_TRACING)
endif()
if(BUILD_SDL3)
add_definitions(-DUSE_SDL3)
endif()
if (MOJOSHADER_STATIC_SPIRVCROSS)
add_definitions(-DSDL_GPU_SHADERCROSS_STATIC)
endif()
if(WIN32 OR BUILD_DXVK_NATIVE)
add_definitions(
-DFNA3D_DRIVER_D3D11
)
else()
add_definitions(
-DSUPPORT_PROFILE_HLSL=0
)
endif()
if(EMSCRIPTEN)
remove_definitions(
-DFNA3D_DRIVER_VULKAN
)
add_definitions(
-DSUPPORT_PROFILE_GLSPIRV=0
-DSUPPORT_PROFILE_SPIRV=0
)
endif()
if(NOT APPLE)
add_definitions(
-DSUPPORT_PROFILE_METAL=0
)
endif()
# Source lists
add_library(FNA3D
# Public Headers
include/FNA3D.h
include/FNA3D_Image.h
# Internal Headers
src/FNA3D_Driver.h
src/FNA3D_Driver_OpenGL.h
src/FNA3D_Driver_OpenGL_glfuncs.h
src/FNA3D_Driver_Vulkan_vkfuncs.h
src/FNA3D_CommandBuffer.h
src/FNA3D_Memory.h
src/FNA3D_PipelineCache.h
# Source Files
src/FNA3D.c
src/FNA3D_Driver_D3D11.c
src/FNA3D_Driver_OpenGL.c
src/FNA3D_Driver_SDL.c
src/FNA3D_Driver_Vulkan.c
src/FNA3D_Image.c
src/FNA3D_CommandBuffer.c
src/FNA3D_Memory.c
src/FNA3D_PipelineCache.c
src/FNA3D_Tracing.c
)
add_library(mojoshader STATIC
MojoShader/mojoshader.c
MojoShader/mojoshader_effects.c
MojoShader/mojoshader_common.c
MojoShader/mojoshader_d3d11.c
MojoShader/mojoshader_opengl.c
MojoShader/mojoshader_vulkan.c
MojoShader/mojoshader_sdlgpu.c
MojoShader/profiles/mojoshader_profile_common.c
MojoShader/profiles/mojoshader_profile_glsl.c
MojoShader/profiles/mojoshader_profile_hlsl.c
MojoShader/profiles/mojoshader_profile_spirv.c
MojoShader/profiles/mojoshader_profile_metal.c
)
if(TRACING_SUPPORT)
add_executable(fna3d_replay replay/replay.c)
target_link_libraries(fna3d_replay FNA3D)
target_include_directories(fna3d_replay PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/MojoShader>
)
endif()
# Build flags
if(NOT MSVC)
set_property(TARGET FNA3D PROPERTY COMPILE_FLAGS "-std=gnu99 -Wall -Wno-strict-aliasing -pedantic")
endif()
if(BUILD_SHARED_LIBS)
set_property(TARGET mojoshader PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
# FNA3D folders as includes, for other targets to consume
target_include_directories(FNA3D PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include>
)
if(BUILD_DXVK_NATIVE)
add_definitions(-DFNA3D_DXVK_NATIVE)
target_include_directories(FNA3D PUBLIC ${DXVK_NATIVE_INCLUDE_DIRS})
target_include_directories(mojoshader PUBLIC ${DXVK_NATIVE_INCLUDE_DIRS})
endif()
target_include_directories(mojoshader PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/MojoShader>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include>
)
# MinGW builds should statically link libgcc
if(MINGW)
target_link_libraries(FNA3D PRIVATE -static-libgcc)
endif()
# Soname
set_target_properties(FNA3D PROPERTIES OUTPUT_NAME "FNA3D"
VERSION ${LIB_VERSION}
SOVERSION ${LIB_MAJOR_VERSION}
)
# Internal Dependencies
target_link_libraries(FNA3D PRIVATE mojoshader ${LOBJC})
# SDL Dependency
if (BUILD_SDL3)
if (DEFINED SDL3_INCLUDE_DIRS AND DEFINED SDL3_LIBRARIES)
message(STATUS "using pre-defined SDL3 variables SDL3_INCLUDE_DIRS and SDL3_LIBRARIES")
target_include_directories(FNA3D PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_include_directories(mojoshader PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(FNA3D PUBLIC ${SDL3_LIBRARIES})
else()
# Only try to autodetect if both SDL3 variables aren't explicitly set
find_package(SDL3 CONFIG)
if (TARGET SDL3::SDL3)
message(STATUS "using TARGET SDL3::SDL3")
target_link_libraries(FNA3D PUBLIC SDL3::SDL3)
target_link_libraries(mojoshader PUBLIC SDL3::SDL3)
elseif (TARGET SDL3)
message(STATUS "using TARGET SDL3")
target_link_libraries(FNA3D PUBLIC SDL3)
target_link_libraries(mojoshader PUBLIC SDL3)
else()
message(STATUS "no TARGET SDL3::SDL3, or SDL3, using variables")
target_include_directories(FNA3D PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_include_directories(mojoshader PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(FNA3D PUBLIC ${SDL3_LIBRARIES})
endif()
endif()
else()
if (DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES)
message(STATUS "using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES")
target_include_directories(FNA3D PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_include_directories(mojoshader PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(FNA3D PUBLIC ${SDL2_LIBRARIES})
else()
# Only try to autodetect if both SDL2 variables aren't explicitly set
find_package(SDL2 CONFIG)
if (TARGET SDL2::SDL2)
message(STATUS "using TARGET SDL2::SDL2")
target_link_libraries(FNA3D PUBLIC SDL2::SDL2)
target_link_libraries(mojoshader PUBLIC SDL2::SDL2)
elseif (TARGET SDL2)
message(STATUS "using TARGET SDL2")
target_link_libraries(FNA3D PUBLIC SDL2)
target_link_libraries(mojoshader PUBLIC SDL2)
else()
message(STATUS "no TARGET SDL2::SDL2, or SDL2, using variables")
target_include_directories(FNA3D PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_include_directories(mojoshader PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(FNA3D PUBLIC ${SDL2_LIBRARIES})
endif()
endif()
endif()