forked from xfangfang/wiliwili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
279 lines (248 loc) · 10.4 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
cmake_minimum_required(VERSION 3.15)
# build options
set(PLATFORM_DESKTOP OFF CACHE BOOL "build for desktop, ON for desktop; OFF for switch")
set(BUILTIN_NSP OFF CACHE BOOL "Built in NSP forwarder")
set(WIN32_TERMINAL ON CACHE BOOL "Show terminal when run on Windows")
set(VERIFY_SSL ON CACHE BOOL "Whether to verify ssl")
set(USE_SYSTEM_CURL OFF CACHE BOOL "Whether to use the curl in your system libs")
# analytics
set(ANALYTICS OFF CACHE BOOL "Using Google Analytics")
set(ANALYTICS_ID "" CACHE STRING "Google Analytics ID")
set(ANALYTICS_KEY "" CACHE STRING "Google Analytics key")
# Strongly depends on the environment, these options may lead to build errors
set(MAC_10_15 OFF CACHE BOOL "Set the Minimum OS X deployment version to 10.15")
set(MAC_UNIVERSAL OFF CACHE BOOL "Support x86_64;arm64 at the same time")
option(USE_GLFW "using glfw for input and create window" ON)
option(USE_SDL2 "using sdl2 for input and create window" OFF)
option(USE_GL2 "using OpenGL 2.1" OFF)
option(INSTALL "Install to system. only use this option with Linux." OFF)
if (USE_SDL2)
message("SDL2")
set(USE_GLFW OFF)
else ()
# default glfw3.3
message("GLFW")
set(USE_GLFW ON)
set(USE_SDL2 OFF)
endif ()
if (USE_GL2)
set(USE_GL2 ON)
add_definitions(-DUSE_GL2)
endif ()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/extra.cmake)
# toolchain
if (PLATFORM_DESKTOP)
message("building for Desktop")
set(TARGET_PLATFORM desktop CACHE STRING "")
message("Build Type: ${CMAKE_BUILD_TYPE}")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
else ()
message("building for SWITCH")
message("Build Type: ${CMAKE_BUILD_TYPE}")
message("DEVKITPRO: $ENV{DEVKITPRO}")
set(CMAKE_USE_SYSTEM_ENVIRONMENT_PATH OFF)
file(TO_CMAKE_PATH "$ENV{DEVKITPRO}" DEVKITPRO)
if (NOT IS_DIRECTORY ${DEVKITPRO})
message(FATAL_ERROR "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif ()
set(DEVKITPRO $ENV{DEVKITPRO} CACHE BOOL "DEVKITPRO")
include(${DEVKITPRO}/cmake/Switch.cmake REQUIRED)
set(__SWITCH__ ON)
set(CMAKE_C_FLAGS "-I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include")
set(CMAKE_CXX_FLAGS "-I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include")
message(STATUS "PKG_CONFIG_EXECUTABLE = ${PKG_CONFIG_EXECUTABLE}")
message(STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
message(STATUS "NX_NACP" = ${NX_NACPTOOL_EXE})
message(STATUS "NX_ELF2NRO" = ${NX_ELF2NRO_EXE})
endif ()
# project info
project(wiliwili)
set(VERSION_MAJOR "0")
set(VERSION_MINOR "6")
set(VERSION_REVISION "0")
set(PROJECT_TITLEID "0x010FF000FFFF0001")
set(PROJECT_AUTHOR "xfangfang")
set(PROJECT_ICON ${CMAKE_CURRENT_SOURCE_DIR}/resources/icon/icon.jpg)
set(PROJECT_ICON_PNG ${CMAKE_CURRENT_SOURCE_DIR}/resources/icon/icon.png)
set(PROJECT_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources)
set(PACKAGE_NAME cn.xfangfang.wiliwili)
set(PROJECT_DESKTOP ${CMAKE_CURRENT_SOURCE_DIR}/scripts/linux/${PACKAGE_NAME}.desktop)
set(PROJECT_ICON_SVG ${CMAKE_CURRENT_SOURCE_DIR}/resources/svg/${PACKAGE_NAME}.svg)
set(RESOURCES_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/wiliwili) # Only used in Linux
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
add_definitions(
-DBUILD_VERSION_MAJOR=${VERSION_MAJOR}
-DBUILD_VERSION_MINOR=${VERSION_MINOR}
-DBUILD_VERSION_REVISION=${VERSION_REVISION})
if (USE_SDL2)
add_definitions(-D__SDL2__)
else ()
add_definitions(-D__GLFW__)
endif ()
# disable in-source build
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed")
endif ()
# set resources dir
if (INSTALL)
set(BRLS_RESOURCES_DIR ${RESOURCES_INSTALL_DIR})
else ()
set(BRLS_RESOURCES_DIR ".")
endif ()
if (USE_SYSTEM_CURL)
set(CPR_USE_SYSTEM_CURL ON)
else ()
set(CPR_USE_SYSTEM_CURL OFF)
endif ()
# build borealis qrcode and other third party libraries
add_subdirectory(library)
# setting src and include
file(GLOB_RECURSE MAIN_SRC wiliwili/source/*.cpp)
set(PLATFORM_OPTION)
if (PLATFORM_DESKTOP)
find_package(MPV REQUIRED)
if (MPV_FOUND)
message(STATUS "Found libmpv: ${MPV_VERSION} ${MPV_INCLUDE_DIR} ${MPV_LIBRARY}")
endif ()
set(PLATFORM_LIBS ${MPV_LIBRARY})
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(PLATFORM_OPTION -pthread -I${MPV_INCLUDE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
else ()
if (USE_SDL2)
set(PLATFORM_LIBS SDL2)
else ()
set(PLATFORM_LIBS glfw3)
endif ()
list(APPEND PLATFORM_LIBS
# needed by borealis
EGL glapi drm_nouveau
# needed by mpv
mpv swscale swresample avformat avfilter avcodec avutil ass freetype fribidi png bz2 z SDL2
mbedx509 mbedtls mbedcrypto mbedx509 mbedtls
# needed by cpr
curl z
# base lib
nx m
)
if (BUILTIN_NSP)
list(APPEND PLATFORM_LIBS nsp)
set(PLATFORM_OPTION -DBUILTIN_NSP)
endif ()
list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/library/borealis/library/lib/platforms/switch/switch_wrapper.c)
endif ()
# building target
if (WIN32)
if (WIN32_TERMINAL)
add_executable(${PROJECT_NAME} ${MAIN_SRC} app_win32.rc)
else ()
add_executable(${PROJECT_NAME} WIN32 ${MAIN_SRC} app_win32.rc)
endif ()
else ()
add_executable(${PROJECT_NAME} ${MAIN_SRC})
endif ()
# set google analytics
if (ANALYTICS)
if (NOT ANALYTICS_ID OR NOT ANALYTICS_KEY)
message(FATAL_ERROR "ANALYTICS set to ON, You need set ANALYTICS_ID and ANALYTICS_KEY too")
endif ()
target_compile_options(${PROJECT_NAME} PRIVATE
-DANALYTICS=${ANALYTICS}
-DANALYTICS_ID=${ANALYTICS_ID}
-DANALYTICS_KEY=${ANALYTICS_KEY})
endif ()
if (VERIFY_SSL)
target_compile_options(${PROJECT_NAME} PRIVATE -DVERIFY_SSL)
endif ()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_include_directories(${PROJECT_NAME} PRIVATE
wiliwili/include
wiliwili/include/api)
target_compile_options(${PROJECT_NAME} PRIVATE
-D__VERSION_MAJOR__=${VERSION_MAJOR}
-D__VERSION_MINOR__=${VERSION_MINOR}
-D__VERSION_REVISION__=${VERSION_REVISION}
-ffunction-sections
-fdata-sections
-Wunused-variable
${PLATFORM_OPTION}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
cpr::cpr
qrcode
borealis
lunasvg
pystring
${PLATFORM_LIBS}
)
# building release file
if (PLATFORM_DESKTOP)
add_custom_target(${PROJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${CMAKE_SOURCE_DIR}/resources ${CMAKE_CURRENT_BINARY_DIR}/resources
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.data)
if (APPLE)
if (MAC_10_15)
message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: 10.15")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version" FORCE)
endif ()
if (MAC_UNIVERSAL)
message(STATUS "CMAKE_OSX_ARCHITECTURES: x86_64;arm64")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Architectures" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64] "11.0" CACHE STRING "arm 64 minimum deployment target" FORCE)
endif ()
add_custom_target(${PROJECT_NAME}.app
COMMAND "bash" "${CMAKE_BINARY_DIR}/../scripts/build_mac.sh"
)
add_dependencies(${PROJECT_NAME}.app ${PROJECT_NAME})
elseif (UNIX)
if (INSTALL)
message("install prefix: ${CMAKE_INSTALL_PREFIX}")
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(DIRECTORY ${PROJECT_RESOURCES}
DESTINATION ${RESOURCES_INSTALL_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
install(FILES ${PROJECT_ICON_SVG}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
set(icon_dirs 16x16 22x22 24x24 32x32 48x48 64x64 128x128 256x256)
foreach (icon_dir ${icon_dirs})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/icon/${PACKAGE_NAME}.png
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/${icon_dir}/apps
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endforeach ()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/linux/${PACKAGE_NAME}.appdata.xml
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/metainfo
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
install(FILES ${PROJECT_DESKTOP}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
)
add_custom_target(${PROJECT_NAME}.install
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/resources/icon/icon.png
${CMAKE_CURRENT_BINARY_DIR}/resources/icon/${PACKAGE_NAME}.png
)
add_dependencies(${PROJECT_NAME}.install ${PROJECT_NAME}.data)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.install)
endif ()
endif ()
else ()
add_custom_target(${PROJECT_NAME}.nro
DEPENDS ${PROJECT_NAME}
COMMAND ${NX_NACPTOOL_EXE} --create "${PROJECT_NAME}"
"${PROJECT_AUTHOR}" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}"
${PROJECT_NAME}.nacp --titleid=${PROJECT_TITLEID}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_BINARY_DIR}/resources
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/resources/icon/wiliwili.ico
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/resources/font
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/resources/gamepad
COMMAND ${NX_ELF2NRO_EXE} ${PROJECT_NAME}.elf ${PROJECT_NAME}.nro --icon=${PROJECT_ICON}
--nacp=${PROJECT_NAME}.nacp --romfsdir=${CMAKE_BINARY_DIR}/resources
)
endif ()