forked from symphony-of-empires/symphony-of-empires
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
198 lines (177 loc) · 5.77 KB
/
CMakeLists.txt
File metadata and controls
198 lines (177 loc) · 5.77 KB
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
cmake_minimum_required(VERSION 3.22)
IF(CMAKE_GENERATOR_PLATFORM STREQUAL "Switch")
set(DEVKITPRO $ENV{DEVKITPRO})
IF(DEVKITPRO)
message(STATUS "Using DevKitPro")
list(APPEND CMAKE_MODULE_PATH "$ENV{DEVKITPRO}/cmake")
include(Switch)
include(Platform/NintendoSwitch)
ENDIF()
ENDIF()
#set(CMAKE_CXX_CLANG_TIDY clang-tidy;-checks=cppcoreguidelines-*;)
set(FETCHCONTENT_QUIET FALSE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
project(SymphonyOfEmpires CXX C)
include(FetchContent)
option(BUILD_ENGINE "Enable building Eng3D" ON)
option(BUILD_GAME "Enable building SymphonyOfEmpires" ON)
option(SOE_UBSAN "Enable UBSAN instrumentation" OFF)
IF(SOE_UBSAN)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
ENDIF()
IF(WIN32)
add_definitions(-DNOMINMAX=1)
add_definitions(-DWIN32_LEAN_AND_MEAN=1)
ELSEIF(ANDROID)
set(NDK_PROJECT_PATH $ENV{PWD}) # Set project path to current directory
set(ANDROID_STL c++_static) # Static libc++
#IF(NOT DEFINED ANDROID_HOME)
# message(FATAL_ERROR "Please define ANDROID_NDK_HOME")
#ENDIF()
#IF(NOT DEFINED ANDROID_NDK_HOME)
# message(FATAL_ERROR "Please define ANDROID_NDK_HOME")
#ENDIF()
add_compile_options(-fPIE -fPIC)
add_link_options(-fPIE -pie)
ENDIF()
IF(NO_COPY_MODS)
add_compile_definitions(NO_COPY_MODS)
ENDIF()
IF(SANITIZE_ON)
add_compile_options(-fsanitize=undefined -fsanitize=thread)
ENDIF()
# Backend selection
IF(E3D_BACKEND_GLES)
add_compile_definitions(E3D_BACKEND_GLES)
ELSEIF(E3D_BACKEND_D3D9)
IF(NOT WIN32)
message(FATAL_ERROR "DirectX 9 is not supported in ${CMAKE_SYSTEM_NAME} platform")
ENDIF()
message("Using DirectX 9 SDK")
add_compile_definitions(E3D_BACKEND_D3D9)
ELSE()
IF(NOT E3D_BACKEND_OPENGL)
message(WARNING "No backend specified - using OpenGL as default")
set(E3D_BACKEND_OPENGL ON)
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" OR ANDROID)
message(FATAL_ERROR "OpenGL is not supported in ${CMAKE_SYSTEM_NAME} platform, try GLES instead")
ENDIF()
message("Using OpenGL backend")
IF(ANDROID)
message(FATAL_ERROR "Use E3D_BACKEND_GLES instead on Android")
ENDIF()
add_compile_definitions(E3D_BACKEND_OPENGL)
ENDIF()
#
# Dependencies
#
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(dependencies)
#
# Compilation flags
#
IF (CMAKE_BUILD_TYPE STREQUAL "Release")
IF(NOT MSVC)
add_compile_options("-O3")
ELSE()
add_compile_options("/O2")
ENDIF()
ENDIF()
IF(NOT MSVC)
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow)
ENDIF()
IF(UNIT_TEST)
add_compile_definitions(UNIT_TEST)
ENDIF()
IF(WIN32)
add_compile_definitions(E3D_TARGET_WINDOWS)
ELSEIF(UNIX)
add_compile_definitions(E3D_TARGET_UNIX)
ELSEIF(ANDROID)
add_compile_definitions(E3D_TARGET_UNIX E3D_TARGET_ANDROID)
add_compile_definitions(E3D_HANDHELD)
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
add_compile_definitions(E3D_TARGET_UNIX)
add_compile_definitions(E3D_TARGET_NETBSD)
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
include_directories("${DEVKITPRO}/portlibs/switch/include/")
add_compile_definitions(E3D_TARGET_UNIX E3D_TARGET_SWITCH)
add_compile_definitions(E3D_HANDHELD)
# Compiler is for 32bits and doesn't support long long
add_compile_definitions(LUA_32BITS)
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "NintendoWii")
link_directories("${DEVKITPRO}/libogc/lib")
include_directories("${DEVKITPRO}/libogc/include")
add_compile_definitions(E3D_TARGET_RVL)
ENDIF()
include_directories("${PROJECT_SOURCE_DIR}/game/src" "${CMAKE_SOURCE_DIR}/eng3d")
#
# Source code files
#
# C++ source files
file(GLOB_RECURSE MAIN_SOURCES
"${PROJECT_SOURCE_DIR}/game/src/*.cpp"
)
IF(ANDROID)
list(APPEND MAIN_SOURCES "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
ENDIF()
IF(ANDROID)
add_executable(SymphonyOfEmpires "${MAIN_SOURCES}" "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
ELSEIF(WIN32)
if(MSVC)
endif()
# Build as a windows application
add_executable(SymphonyOfEmpires "${MAIN_SOURCES}")
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_include_directories(SymphonyOfEmpires PRIVATE "/opt/devkitpro/portlibs/switch/include/")
ELSE()
# The rest is a normal application
add_executable(SymphonyOfEmpires "${MAIN_SOURCES}")
ENDIF()
#
# Linking
#
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Pthread
find_package(Threads)
IF(Threads_FOUND)
set(THREADS_PREFER_PTHREAD_FLAG ON)
target_link_libraries(SymphonyOfEmpires PRIVATE Threads::Threads)
ENDIF()
target_link_libraries(SymphonyOfEmpires PRIVATE
dependency_tbb
dependency_lua
)
# Build stuff
IF(BUILD_ENGINE)
add_subdirectory(${CMAKE_SOURCE_DIR}/eng3d ${CMAKE_BINARY_DIR}/eng3d)
add_dependencies(SymphonyOfEmpires eng3d)
ENDIF()
IF(WIN32)
target_link_directories(SymphonyOfEmpires PRIVATE "${CMAKE_BINARY_DIR}")
target_link_libraries(SymphonyOfEmpires PRIVATE eng3d)
target_link_libraries(SymphonyOfEmpires PRIVATE wsock32 ws2_32 iphlpapi)
ELSE()
target_link_libraries(SymphonyOfEmpires PRIVATE eng3d)
ENDIF()
IF(ANDROID)
set(APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libtbb.so)
list(APPEND APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libSDL2.so)
list(APPEND APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/liblua.so)
list(APPEND APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libeng3d.so)
list(APPEND APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libassimp.so)
android_create_apk(SymphonyOfEmpires "${CMAKE_BINARY_DIR}/apk" "${APP_SHARED_LIBRARIES}" "" "mods")
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
message(STATUS "Creating NRO file")
set(NROFLAGS "")
string(APPEND NROFLAGS " --romfsdir=${CMAKE_SOURCE_DIR}/mods")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SymphonyOfEmpires.nro
COMMAND ${NX_ELF2NRO_EXE} $<TARGET_FILE:SymphonyOfEmpires> ${CMAKE_CURRENT_BINARY_DIR}/SymphonyOfEmpires.nro ${NROFLAGS}
DEPENDS SymphonyOfEmpires
VERBATIM
)
ENDIF()