-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
284 lines (240 loc) · 11.1 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
cmake_minimum_required(VERSION 3.1)
project(Pineapple)
option(GENERATE_DOCS "GENERATE_DOCS" OFF)
option(GENERATE_TESTS "GENERATE_TESTS" ON)
option(GENERATE_DEMOS "GENERATE_DEMOS" ON)
option(GENERATE_PLUGINS "GENERATE_PLUGINS" ON)
set(ANDROID_SWAPPY_SDK "${ANDROID_SWAPPY_SDK}" CACHE PATH "The absolute path to the Android Swappy SDK")
set(FMOD_SDK "${FMOD_SDK}" CACHE PATH "The absolute path to the FMOD SDK")
if (GENERATE_DEMOS AND NOT GENERATE_PLUGINS)
message(STATUS "GENERATE_DEMOS is ON (forcing GENERATE_PLUGINS to be ON too)")
set(GENERATE_PLUGINS ON)
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
if(MSVC)
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
add_compile_options("/MP")
endif()
if (GENERATE_TESTS)
include(CTest)
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
include(Build/CMake/DownloadProject/DownloadProject.cmake)
download_project(PROJ googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
get_filename_component(PA_ROOT "." ABSOLUTE)
get_directory_property(hasParent PARENT_DIRECTORY)
if (hasParent)
set(PA_ROOT ${PA_ROOT} PARENT_SCOPE)
else()
set(PA_ROOT ${PA_ROOT})
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Build/CMake")
if (GENERATE_PLUGINS)
if((UNIX OR WIN32) AND NOT ANDROID)
find_package(FMOD REQUIRED)
endif()
if(UNIX AND NOT ANDROID AND NOT IOS)
find_package(X11 REQUIRED)
endif()
if(ANDROID)
find_library(LOG_LIB log)
find_library(ANDROID_LIB android)
find_library(EGL_LIB egl)
find_library(GLESV1_CM_LIB GLESv1_CM)
# FMOD SDK
if(NOT EXISTS ${FMOD_SDK})
message(FATAL_ERROR "FMOD_SDK is not set or doesn't exist. FMOD is required for Android builds")
endif()
include_directories("${FMOD_SDK}/api/core/inc")
# Android Game SDK
if(NOT EXISTS ${ANDROID_SWAPPY_SDK})
message(STATUS "ANDROID_SWAPPY_SDK is not set or doesn't exist. Please define it to be able to use Swappy.")
else()
set(ANDROID_SWAPPY_LIB swappy_static)
set(ANDROID_SWAPPY_LIB_DIRS "${ANDROID_SWAPPY_SDK}/libs/${ANDROID_ABI}_cpp_static_Release")
set(ANDROID_SWAPPY_INCLUDE_DIRS "${ANDROID_SWAPPY_SDK}/include")
set(ANDROID_SWAPPY_LIB ${ANDROID_SWAPPY_LIB} PARENT_SCOPE)
set(ANDROID_SWAPPY_LIB_DIRS ${ANDROID_SWAPPY_LIB_DIRS} PARENT_SCOPE)
set(ANDROID_SWAPPY_INCLUDE_DIRS ${ANDROID_SWAPPY_INCLUDE_DIRS} PARENT_SCOPE)
endif()
endif()
endif()
function(glob_source_files _SOURCES)
get_filename_component(_src_root_path "." ABSOLUTE)
file(
GLOB_RECURSE _glob_sources
LIST_DIRECTORIES false
"${_src_root_path}/*.c*"
"${_src_root_path}/*.h*"
"${_src_root_path}/*.inl"
"${_src_root_path}/*.mm"
)
set(${_SOURCES} ${_glob_sources} PARENT_SCOPE)
endfunction()
function(create_source_groups _SOURCES)
set( _SOURCES_LIST ${_SOURCES} ${ARGN} )
get_filename_component(_src_root_path "." ABSOLUTE)
foreach(_source IN ITEMS ${_SOURCES_LIST})
get_filename_component(_source_path "${_source}" PATH)
file(RELATIVE_PATH _source_path_rel "${_src_root_path}" "${_source_path}")
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
endfunction()
function(add_pineapple_app _TARGET _SOURCES)
set( _SOURCES_LIST ${_SOURCES} ${ARGN} )
include_directories(${PA_ROOT}/Source ${PA_ROOT}/Ext)
if(WIN32)
add_executable(${_TARGET} WIN32 ${_SOURCES_LIST})
# Need to link Opengl32.lib for wgl (not sure if this is correct usage of glad)
target_link_libraries(${_TARGET} paEngine paWindows paFMOD paOpenGL Opengl32.lib ${FMOD_LIBRARIES})
endif()
if(UNIX AND NOT ANDROID AND NOT IOS)
add_executable(${_TARGET} ${_SOURCES_LIST})
target_link_libraries(${_TARGET} paX11 paFMOD paOpenGL paEngine ${X11_LIBRARIES} pthread dl ${FMOD_LIBRARIES})
set_property(TARGET ${_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES ${X11_INCLUDE_DIRS})
endif()
if(ANDROID)
add_library(fmod SHARED IMPORTED)
set_target_properties(fmod PROPERTIES IMPORTED_LOCATION "${FMOD_SDK}/api/core/lib/${ANDROID_ABI}/libfmod.so")
include_directories("${FMOD_SDK}/api/core/inc")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
add_library(${_TARGET} SHARED ${_SOURCES_LIST})
target_link_libraries(${_TARGET} -Wl,--whole-archive paAndroid -Wl,--no-whole-archive paOpenGLES1 paFMOD paEngine fmod ${ANDROID_LIB} ${LOG_LIB} ${EGL_LIB} ${GLESV1_CM_LIB})
if(DEFINED ANDROID_SWAPPY_LIB)
set_property(TARGET ${_TARGET} APPEND PROPERTY LINK_LIBRARIES ${ANDROID_SWAPPY_LIB})
set_property(TARGET ${_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES ${ANDROID_SWAPPY_INCLUDE_DIRS})
set_property(TARGET ${_TARGET} APPEND PROPERTY LINK_DIRECTORIES ${ANDROID_SWAPPY_LIB_DIRS})
set_property(TARGET ${_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS PA_ANDROID_SWAPPY)
endif()
endif()
if(IOS)
add_executable(${_TARGET} ${_SOURCES_LIST})
target_link_libraries(${_TARGET} paIOS paFMOD paOpenGLES1 paEngine pthread dl ${FMOD_LIBRARIES} "-framework OpenGLES" "-framework GLKit" "-framework UIKit" "-framework QuartzCore" "-framework Foundation" "-framework AVFoundation" "-framework AudioToolbox")
endif()
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/pineapple.json)
set(PA_SETTINGS_USER_ASSETS_PATH ${CMAKE_CURRENT_LIST_DIR}/Assets)
set(PA_SETTINGS_ENGINE_ASSETS_PATH ${PA_ROOT}/Assets)
# Configure the settings file
configure_file(${CMAKE_CURRENT_LIST_DIR}/pineapple.json ${CMAKE_CURRENT_BINARY_DIR}/pineapple.json)
endif()
if(WIN32)
foreach(_library IN ITEMS ${FMOD_LIBRARIES})
string(REPLACE "_vc.lib" ".dll" _dll ${_library})
add_custom_command(
TARGET ${_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${_dll}
${CMAKE_CURRENT_BINARY_DIR})
endforeach()
endif()
endfunction()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
$<$<CONFIG:Debug>:PA_DEBUG>
)
include_directories(Source Ext)
if (GENERATE_DOCS)
get_property(DOC_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
file(
GLOB_RECURSE DOC_HEADER_FILES
LIST_DIRECTORIES false
"${PA_ROOT}/Source/Pineapple/Engine/*.h*"
)
# Below functionality is for updating only a single file, but it doesn't quite work well yet because standardese can't link to other files in this mode
#foreach(headerFile ${DOC_HEADER_FILES})
# get_filename_component(headerFileName ${headerFile} NAME_WE)
# set (docFile "${CMAKE_BINARY_DIR}/standardese_docs_engine/doc_${headerFileName}.md")
# if(NOT(${headerFile} IS_NEWER_THAN ${docFile}))
# list(REMOVE_ITEM DOC_HEADER_FILES ${headerFile})
# endif()
#endforeach()
#
#list(LENGTH DOC_HEADER_FILES inputCount)
#if(${inputCount} GREATER 0)
include(C:/standardese/standardese-config.cmake)
standardese_generate(docs_engine
--compilation.standard=c++14
INCLUDE_DIRECTORY ${DOC_INCLUDE_DIRS}
INPUT ${DOC_HEADER_FILES})
#else()
# # Add empty target as there is nothing to do
# add_custom_target(standardese_docs_engine)
# message(STATUS "All documentation files are up-to-date")
#endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # To be able to sort projects into folders
add_subdirectory(Source/Pineapple/Engine)
set_target_properties (paEngine PROPERTIES FOLDER Engine)
if (GENERATE_PLUGINS)
if (WIN32)
add_subdirectory(Source/Pineapple/Platform/Windows)
add_subdirectory(Source/Pineapple/Graphics/OpenGL)
add_subdirectory(Source/Pineapple/Sound/FMOD)
set_target_properties (paWindows PROPERTIES FOLDER Plugins)
set_target_properties (paOpenGL PROPERTIES FOLDER Plugins)
set_target_properties (paFMOD PROPERTIES FOLDER Plugins)
endif()
if (UNIX AND NOT ANDROID AND NOT IOS)
add_subdirectory(Source/Pineapple/Platform/X11)
add_subdirectory(Source/Pineapple/Graphics/OpenGL)
add_subdirectory(Source/Pineapple/Sound/FMOD)
set_target_properties (paX11 PROPERTIES FOLDER Plugins)
set_target_properties (paOpenGL PROPERTIES FOLDER Plugins)
set_target_properties (paFMOD PROPERTIES FOLDER Plugins)
endif()
if (ANDROID)
add_subdirectory(Source/Pineapple/Platform/Android)
add_subdirectory(Source/Pineapple/Graphics/OpenGL)
add_subdirectory(Source/Pineapple/Sound/FMOD)
set_target_properties (paAndroid PROPERTIES FOLDER Plugins)
set_target_properties (paOpenGLES1 PROPERTIES FOLDER Plugins)
set_target_properties (paFMOD PROPERTIES FOLDER Plugins)
endif()
if (IOS)
add_subdirectory(Source/Pineapple/Platform/IOS)
add_subdirectory(Source/Pineapple/Graphics/OpenGL)
add_subdirectory(Source/Pineapple/Sound/FMOD)
set_target_properties (paIOS PROPERTIES FOLDER Plugins)
set_target_properties (paOpenGL PROPERTIES FOLDER Plugins)
set_target_properties (paFMOD PROPERTIES FOLDER Plugins)
endif()
endif()
# Tests
if (GENERATE_TESTS)
set_target_properties (gtest PROPERTIES FOLDER Test/gtest)
set_target_properties (gtest_main PROPERTIES FOLDER Test/gtest)
set_target_properties (gmock PROPERTIES FOLDER Test/gtest)
set_target_properties (gmock_main PROPERTIES FOLDER Test/gtest)
add_subdirectory(Test/Engine)
set_target_properties (paEngineTest PROPERTIES FOLDER Test)
endif()
# Demos
if (GENERATE_DEMOS)
add_subdirectory(Demo/AnimatedSprite)
add_subdirectory(Demo/SpaceRocks)
add_subdirectory(Demo/HelloWorld)
add_subdirectory(Demo/CatchTheClown)
add_subdirectory(Demo/Simple)
add_subdirectory(Demo/Text)
set_target_properties (AnimatedSprite PROPERTIES FOLDER Demo)
set_target_properties (SpaceRocks PROPERTIES FOLDER Demo)
set_target_properties (HelloWorld PROPERTIES FOLDER Demo)
set_target_properties (CatchTheClown PROPERTIES FOLDER Demo)
set_target_properties (Simple PROPERTIES FOLDER Demo)
set_target_properties (Text PROPERTIES FOLDER Demo)
endif()