forked from natinusala/borealis
-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
178 lines (162 loc) · 7.46 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
cmake_minimum_required(VERSION 3.10)
set(BOREALIS_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/library)
# build options
include(${BOREALIS_LIBRARY}/cmake/commonOption.cmake)
# Dependencies
option(USE_SHARED_LIB "Whether to use shared libs provided by system" OFF)
cmake_dependent_option(USE_SYSTEM_FMT "" OFF "NOT USE_SHARED_LIB" ON)
cmake_dependent_option(USE_SYSTEM_TINYXML2 "" OFF "NOT USE_SHARED_LIB" ON)
cmake_dependent_option(USE_SYSTEM_TWEENY "" OFF "NOT USE_SHARED_LIB" ON)
if (APPLE AND PLATFORM_DESKTOP)
option(BUNDLE_MACOS_APP "Bundle a app for macOS" OFF)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64] "11.0" CACHE STRING "" FORCE)
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif ()
# toolchain
include(${BOREALIS_LIBRARY}/cmake/toolchain.cmake)
# project info
project(borealis_demo)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_ALTER "0")
set(VERSION_BUILD "0")
set(PACKAGE_NAME "com.borealis.demo")
set(PSN_TITLE_ID "BRLS00000")
set(PSN_VERSION "01.00")
set(PROJECT_AUTHOR "borealis")
set(PROJECT_ICON ${CMAKE_CURRENT_SOURCE_DIR}/resources/img/demo_icon.jpg)
set(PROJECT_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources)
if (USE_LIBROMFS)
add_libromfs(${PROJECT_NAME} ${PROJECT_RESOURCES})
endif ()
add_subdirectory(library)
find_package(Threads REQUIRED)
list(APPEND APP_PLATFORM_LIB ${CMAKE_THREAD_LIBS_INIT})
# setting src and include
list(APPEND APP_PLATFORM_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/demo/include)
file(GLOB_RECURSE MAIN_SRC demo/*.cpp)
set(PLATFORM_OPTION)
if (PLATFORM_DESKTOP)
if (WIN32)
configure_file("${CMAKE_SOURCE_DIR}/demo/resource.rc.in" "${CMAKE_BINARY_DIR}/resource.rc")
list(APPEND MAIN_SRC ${CMAKE_BINARY_DIR}/resource.rc)
if (MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static" CACHE STRING "" FORCE)
endif ()
elseif (BUNDLE_MACOS_APP)
list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/demo/borealis.icns)
endif ()
elseif (PLATFORM_SWITCH)
set(APP_PLATFORM_LIB
# needed by borealis
glfw3 EGL glapi drm_nouveau
# base lib
nx m
)
list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/library/lib/platforms/switch/switch_wrapper.c)
elseif (PLATFORM_PS4)
# Show backtrace when app crash
list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/library/lib/platforms/ps4/crashlog.c)
elseif (PLATFORM_PSV)
add_definitions(-D__psp2__ -D__PSV__)
endif ()
# building target
program_target(${PROJECT_NAME} "${MAIN_SRC}")
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
# building release file
if (PLATFORM_DESKTOP)
if (BUNDLE_MACOS_APP)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}"
MACOSX_BUNDLE_ICON_FILE "borealis.icns"
MACOSX_BUNDLE_COPYRIGHT "Copyright 2023 ${PROJECT_AUTHOR}"
RESOURCE "${CMAKE_SOURCE_DIR}/demo/borealis.icns"
)
add_custom_target(${PROJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${PROJECT_RESOURCES} ${PROJECT_NAME}.app/Contents/Resources/resources
)
else ()
add_custom_target(${PROJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_CURRENT_BINARY_DIR}/resources
)
endif ()
if (NOT USE_LIBROMFS)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.data)
endif ()
elseif (PLATFORM_PSV)
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d ATTRIBUTE2=12") # max heap size mode
vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME} UNSAFE)
if (USE_LIBROMFS)
vita_create_vpk(${PROJECT_NAME}.vpk ${PSN_TITLE_ID} ${PROJECT_NAME}.self
VERSION ${PSN_VERSION}
NAME ${PROJECT_NAME}
FILE ${CMAKE_SOURCE_DIR}/psv/sce_sys sce_sys
FILE ${CMAKE_SOURCE_DIR}/psv/module/ module
)
else()
vita_create_vpk(${PROJECT_NAME}.vpk ${PSN_TITLE_ID} ${PROJECT_NAME}.self
VERSION ${PSN_VERSION}
NAME ${PROJECT_NAME}
FILE ${CMAKE_SOURCE_DIR}/resources resources
FILE ${CMAKE_SOURCE_DIR}/psv/sce_sys sce_sys
FILE ${CMAKE_SOURCE_DIR}/psv/module/ module
)
endif()
elseif (PLATFORM_PS4)
# There is no `add_self` and `add_pkg` functions without pacbrew toolchain.
# We can install the OpenOrbits SDK so that the IDE can provide some basic code prompts,
# but compilation is done through the pacbrew Docker container as pacbrew only supports Linux.
if (PS4)
# Defined by pacbrew toolchain
add_self(${PROJECT_NAME})
add_pkg(${PROJECT_NAME}
# Put all the resources inside `<build dir>/ps4` directory, and access through `/app0/...`
# eg: `cmake-build/ps4/resources/icon.png` -> `/app0/resources/icon.png`
${CMAKE_BINARY_DIR}/ps4
${PSN_TITLE_ID}
"Borealis DEMO"
${PSN_VERSION}
# https://psdevwiki.com/ps4/param.sfo#ATTRIBUTE
# Support ps4 pro
8388608
)
endif()
add_custom_target(${PROJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${CMAKE_SOURCE_DIR}/ps4 ${CMAKE_BINARY_DIR}/ps4
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_BINARY_DIR}/ps4/resources
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.data)
elseif (PLATFORM_SWITCH)
if (USE_DEKO3D)
gen_dksh("${PROJECT_RESOURCES}/shaders")
endif ()
add_custom_target(${PROJECT_NAME}.nro DEPENDS ${PROJECT_NAME}
COMMAND ${NX_NACPTOOL_EXE} --create "${PROJECT_NAME}" "${PROJECT_AUTHOR}" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}" ${PROJECT_NAME}.nacp --titleid=${PROJECT_TITLEID}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_BINARY_DIR}/resources
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/resources/font
COMMAND ${NX_ELF2NRO_EXE} ${PROJECT_NAME}.elf ${PROJECT_NAME}.nro --icon=${PROJECT_ICON} --nacp=${PROJECT_NAME}.nacp --romfsdir=${CMAKE_BINARY_DIR}/resources
)
elseif (PLATFORM_IOS)
ios_bundle(
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/iphoneos/Splash.storyboard"
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/Images.xcassets"
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/iOSBundleInfo.plist.in"
"borealis"
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}")
elseif (PLATFORM_TVOS)
ios_bundle(
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/tvos/Splash.storyboard"
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/Images.xcassets"
"${CMAKE_CURRENT_SOURCE_DIR}/demo/ios/iOSBundleInfo.plist.in"
"borealis"
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}")
endif ()
target_include_directories(${PROJECT_NAME} PRIVATE demo ${APP_PLATFORM_INCLUDE})
target_compile_options(${PROJECT_NAME} PRIVATE -ffunction-sections -fdata-sections ${APP_PLATFORM_OPTION})
target_link_libraries(${PROJECT_NAME} PRIVATE borealis ${APP_PLATFORM_LIB})