-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
237 lines (196 loc) · 8.52 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
###############################################################################
## CMake configuration
cmake_minimum_required(VERSION 3.3)
# Engine directory
if(NOT DEFINED ENGINE_DIR)
set (ENGINE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(NOT APP_NAME)
message(FATAL_ERROR "APP_NAME not set")
endif()
project(${APP_NAME})
# Configure the projects to use folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Limit the build configurations
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
# Select the build type for the application
if(APP_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${APP_BUILD_TYPE} CACHE STRING "" FORCE)
else()
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif()
# Set the custom module path
set(CMAKE_MODULE_PATH "${ENGINE_DIR}/cmake/Modules")
# Limit the build configurations
# set(CMAKE_CXX_CLANG_TIDY "clang-tidy" ${CLANG_TIDY_COMMANDS})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Include the config and macros file
include("Config")
include("Macros")
###############################################################################
## Compiler configuration
# Require C++20 support
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable Unicode in Windows
if(OS_WINDOWS)
add_definitions(-DUNICODE -D_UNICODE)
endif()
# If compiler is GNU GCC or Clang enable the warnings
if(COMPILER_GCC OR COMPILER_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
if(COMPILER_MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4 /wd4201")
endif()
###############################################################################
## Engine configuration
set(ENGINE_NAME Engine)
option(ENGINE_BUILD_STATIC "Build the Engine as an static library" OFF)
option(ENGINE_BUILD_INTEGRATION_TESTS "Build the Engine test projects" ON)
option(ENGINE_BUILD_UNITARY_TESTS "Build the Engine test projects" ON)
option(ENGINE_BUILD_DOCS "Build the Engine documentation (Requires Doxygen)" OFF)
if(ENGINE_BUILD_STATIC)
add_definitions(-DENGINE_STATIC)
set(ENGINE_LIBRARY_TYPE STATIC)
else()
set(ENGINE_LIBRARY_TYPE SHARED)
endif()
###############################################################################
## Directories configuration
# Output directories
if(NOT OS_ANDROID)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release")
endif()
set(THIRD_PARTY_DIR "${ENGINE_DIR}/third_party")
set(ENGINE_SOURCE_DIR "${ENGINE_DIR}/src/engine")
set(ENGINE_INCLUDE_DIR "${ENGINE_DIR}/src/engine")
set(ENGINE_PLUGINS_DIR "${ENGINE_DIR}/src/plugins")
set(TESTS_DIR "${ENGINE_DIR}/tests")
set(DOCS_DIR "${ENGINE_DIR}/docs")
###############################################################################
# Set the dependencies folder
if(OS_WINDOWS)
set(CMAKE_C_FLAGS_DEBUG "/MD /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_DEBUG "/MD /Zi /Ob0 /Od /RTC1")
set(SDL2MAIN_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/windows/Release/SDL2main.lib)
set(SDL2_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/windows/Release/SDL2.lib "setupapi")
set(ASSIMP_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/windows/Release/assimp.lib
${THIRD_PARTY_DIR}/prebuilt/windows/Release/zlibstatic.lib
${THIRD_PARTY_DIR}/prebuilt/windows/Release/IrrXML.lib)
elseif(OS_LINUX)
set(SDL2MAIN_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/linux/Release/libSDL2main.a)
set(SDL2_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/linux/Release/libSDL2.a)
set(ASSIMP_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/linux/Release/libassimp.a)
elseif(OS_ANDROID)
set(SDL2MAIN_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/android/${ANDROID_ABI}/Release/libSDL2main.a)
set(SDL2_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/android/${ANDROID_ABI}/Release/libSDL2.a
${THIRD_PARTY_DIR}/prebuilt/android/${ANDROID_ABI}/Release/libhidapi.so)
set(ASSIMP_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/android/${ANDROID_ABI}/Release/libassimp.a z)
elseif(OS_IOS)
set(SDL2MAIN_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/ios/Release/libSDL2main.a)
set(SDL2_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/ios/Release/libSDL2.a
"-framework CoreBluetooth"
"-framework CoreGraphics"
"-framework CoreMotion"
"-framework CoreVideo"
"-framework Foundation"
"-framework GameController"
"-framework OpenGLES"
"-framework QuartzCore"
"-framework UIKit"
iconv)
set(ASSIMP_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/ios/Release/libassimp.a
z
${THIRD_PARTY_DIR}/prebuilt/ios/Release/libIrrXML.a)
elseif(OS_MACOS)
set(SDL2MAIN_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/macos/Release/libSDL2main.a)
set(SDL2_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/macos/Release/libSDL2.a
"-framework Cocoa"
"-framework ForceFeedback"
"-framework IOKit"
"-framework CoreVideo"
"-framework Carbon"
iconv)
set(ASSIMP_LIBRARY ${THIRD_PARTY_DIR}/prebuilt/macos/Release/libassimp.a
z
${THIRD_PARTY_DIR}/prebuilt/macos/Release/libIrrXML.a)
endif()
if(OS_WINDOWS)
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/windows")
elseif(OS_LINUX)
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/linux")
elseif(OS_ANDROID)
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/android/${ANDROID_ABI}")
elseif(OS_IOS)
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/ios")
elseif(OS_MACOS)
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/macos")
endif()
list(APPEND THIRD_PARTY_INCLUDES "${THIRD_PARTY_DIR}/include/common")
###############################################################################
## Engine library
add_subdirectory("${ENGINE_SOURCE_DIR}")
###############################################################################
## Build the plugins
set(ENGINE_PLUGINS OpenGL Vulkan)
foreach(PLUGIN ${ENGINE_PLUGINS})
add_subdirectory("${ENGINE_PLUGINS_DIR}/${PLUGIN}")
endforeach()
###############################################################################
## Integration Tests
if(ENGINE_BUILD_INTEGRATION_TESTS)
add_subdirectory(${TESTS_DIR})
set(CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${APP_PACKAGE}")
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "$ENV{DEVELOPMENT_TEAM_ID}")
set_target_properties(
${APP_NAME}
PROPERTIES
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path @executable_path/Frameworks @loader_path/Frameworks"
)
endif()
###############################################################################
## Unitary Tests
if(ENGINE_BUILD_UNITARY_TESTS)
if(OS_WINDOWS OR OS_LINUX OR OS_MACOS)
add_subdirectory(${TESTS_DIR}/Unitary)
endif()
endif()
###############################################################################
## Documentation
if(ENGINE_BUILD_DOCS)
add_subdirectory(${DOCS_DIR})
endif()
###############################################################################
## Data processing
if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp 3 REQUIRED)
endif()
set(SCRIPTS_FOLDER "${CMAKE_SOURCE_DIR}/scripts")
set(DATA_SOURCE_FOLDER "${CMAKE_SOURCE_DIR}/data")
if(OS_ANDROID)
set(DATA_OUTPUT_FOLDER "${CMAKE_SOURCE_DIR}/projects/android/app/src/main/assets")
elseif(OS_IOS)
set(DATA_OUTPUT_FOLDER "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${APP_NAME}.app/data")
else()
set(DATA_OUTPUT_FOLDER "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data")
endif()
file(GLOB_RECURSE DATA_FILES "${DATA_SOURCE_FOLDER}/*.*")
add_custom_command(
OUTPUT ${DATA_OUTPUT_FOLDER}
COMMAND ${PYTHON_EXECUTABLE} "${SCRIPTS_FOLDER}/process_data.py" ${DATA_SOURCE_FOLDER} ${DATA_OUTPUT_FOLDER}
DEPENDS ${DATA_FILES}
)
add_custom_target(
BuildAssets ALL
DEPENDS ${DATA_OUTPUT_FOLDER}
)