-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
214 lines (173 loc) · 5.55 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
cmake_minimum_required (VERSION 3.14)
project(mos)
include(FetchContent)
set(CMAKE_CXX_STANDARD 20)
# Catch2
FetchContent_Declare(
Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
GIT_TAG "v2.13.6"
)
FetchContent_MakeAvailable(Catch2)
# GLFW
FetchContent_Declare(
glfw
GIT_REPOSITORY "https://github.com/glfw/glfw.git"
GIT_TAG "3.3.4"
)
FetchContent_GetProperties(glfw)
if(NOT glfw_POPULATED)
FetchContent_Populate(glfw)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif()
# OpenAL soft
FetchContent_Declare(
openal-soft
GIT_REPOSITORY "https://github.com/kcat/openal-soft.git"
GIT_TAG "1.21.1"
)
FetchContent_GetProperties(openal-soft)
if(NOT openal-soft_POPULATED)
FetchContent_Populate(openal-soft)
set(ALSOFT_DLOPEN OFF CACHE BOOL "" FORCE)
set(ALSOFT_WERROR OFF CACHE BOOL "" FORCE)
set(ALSOFT_UTILS OFF CACHE BOOL "" FORCE)
set(ALSOFT_NO_CONFIG_UTIL OFF CACHE BOOL "" FORCE)
set(ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE)
set(ALSOFT_TESTS OFF CACHE BOOL "" FORCE)
set(ALSOFT_INSTALL_CONFIG OFF CACHE BOOL "" FORCE)
set(ALSOFT_INSTALL_HRTF_DATA OFF CACHE BOOL "" FORCE)
set(ALSOFT_INSTALL_AMBDEC_PRESETS OFF CACHE BOOL "" FORCE)
set(ALSOFT_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(${openal-soft_SOURCE_DIR} ${openal-soft_BINARY_DIR})
endif()
# glm
FetchContent_Declare(
glm
GIT_REPOSITORY "https://github.com/g-truc/glm.git"
GIT_TAG "0.9.9.8"
)
FetchContent_GetProperties(glm)
if(NOT glm_POPULATED)
FetchContent_Populate(glm)
set(GLM_TEST_ENABLE OFF CACHE BOOL "" FORCE)
add_subdirectory(${glm_SOURCE_DIR} ${glm_BINARY_DIR})
endif()
# gli
FetchContent_Declare(
gli
GIT_REPOSITORY "https://github.com/g-truc/gli.git"
)
FetchContent_MakeAvailable(gli)
# spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG "v1.8.5"
)
FetchContent_MakeAvailable(spdlog)
# unicode
FetchContent_Declare(
utfcpp
GIT_REPOSITORY "https://github.com/nemtrif/utfcpp.git"
GIT_TAG "v3.2.1"
)
FetchContent_GetProperties(utfcpp)
if(NOT utfcpp_POPULATED)
FetchContent_Populate(utfcpp)
set(UTF8_TESTS OFF CACHE BOOL "" FORCE)
set(UTF8_SAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(${utfcpp_SOURCE_DIR} ${utfcpp_BINARY_DIR})
endif()
# nlohmann-json
FetchContent_Declare(
nlohmann-json
GIT_REPOSITORY "https://github.com/azadkuh/nlohmann_json_release.git"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
FetchContent_MakeAvailable(nlohmann-json)
add_library(nlohmann-json INTERFACE)
target_include_directories(nlohmann-json INTERFACE ${nlohmann-json_SOURCE_DIR})
# glad
add_subdirectory(externals/glad)
# stb
add_subdirectory(externals/stb)
# Testing
enable_testing()
add_subdirectory(tests)
# mos
file(GLOB ROOT_SOURCE src/mos/*.cpp)
file(GLOB GFX_SOURCE src/mos/gfx/*.cpp src/mos/gl/*.cpp src/mos/gpu/*.cpp)
file(GLOB AUD_SOURCE src/mos/aud/*.cpp src/mos/al/*.cpp src/mos/apu/*.cpp)
file(GLOB SIM_SOURCE src/mos/sim/*.cpp)
file(GLOB IO_SOURCE src/mos/io/*.cpp)
file(GLOB CORE_SOURCE src/mos/core/*.cpp)
file(GLOB ROOT_HEADER include/mos/*.hpp)
file(GLOB GFX_HEADER include/mos/gfx/*.hpp include/mos/gl/*.hpp include/mos/gpu/*.hpp)
file(GLOB AUD_HEADER include/mos/aud/*.hpp include/mos/al/*.hpp include/mos/apu/*.hpp)
file(GLOB SIM_HEADER include/mos/sim/*.hpp)
file(GLOB IO_HEADER include/mos/io/*.hpp)
file(GLOB CORE_HEADER include/mos/core/*.hpp)
file(GLOB VERTEX_SHADERS assets/shaders/*.vert)
file(GLOB FRAGMENT_SHADERS assets/shaders/*.frag)
file(GLOB GEOMETRY_SHADERS assets/shaders/*.geom)
file(GLOB BRDF_LUT assets/brdfLUT.png)
add_library(${PROJECT_NAME} STATIC
${ROOT_HEADER} ${GFX_HEADER} ${AUD_HEADER} ${SIM_HEADER} ${IO_HEADER} ${CORE_HEADER}
${ROOT_SOURCE} ${GFX_SOURCE} ${AUD_SOURCE} ${SIM_SOURCE} ${IO_SOURCE} ${CORE_SOURCE}
${VERTEX_SHADERS} ${FRAGMENT_SHADERS} ${GEOMETRY_SHADERS} ${BRDF_LUT})
# NMINMAX fixes windows build
target_compile_definitions(${PROJECT_NAME}
PRIVATE
AL_ALEXT_PROTOTYPES
PUBLIC
GLM_ENABLE_EXPERIMENTAL
NOMINMAX
STB_IMAGE_IMPLEMENTATION)
target_include_directories(${PROJECT_NAME}
PUBLIC
include
externals/glad/include
externals/stb
${utfcpp_SOURCE_DIR}/source
${openal-soft_SOURCE_DIR}/include
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
OpenAL
${GL_LIBRARY}
${PLATFORM_SPECIFIC_LIBRARIES}
glfw
${GLFW_LIBRARIES}
stb
glad
nlohmann-json
gli
spdlog
)
add_custom_target(copy_resources DEPENDS ${FRAGMENT_SHADERS} ${VERTEX_SHADERS} ${GEOMETRY_SHADERS} ${BRDF_LUT})
#Copy shader files to assets and brdfLUT to assets
add_custom_command(TARGET copy_resources POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/assets)
# Copy OpenAL dll on Windows
if(WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:OpenAL>" "${CMAKE_BINARY_DIR}/")
endif()
# Copy shaders on each build
add_dependencies(${PROJECT_NAME} copy_resources)
file(GLOB ASSETS assets/*)
add_custom_target(copy_assets DEPENDS ${ASSETS})
#Copy assets
add_custom_command(TARGET copy_assets POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/assets)
# Copy shaders on each build
add_dependencies(${PROJECT_NAME} copy_assets)