forked from RedBrumbler/SongDetails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
133 lines (105 loc) · 4.5 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
cmake_minimum_required(VERSION 3.22)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/quest.cmake)
# get the vcpkg dir from env variables
if(EXISTS $ENV{VCPKG_ROOT})
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
else()
MESSAGE(ERROR "Please define the environment variable VCPKG_ROOT with the root to your vcpkg install!")
endif()
# vcpkg config. Must be before project
message("VCPKG $ENV{VCPKG_ROOT}")
set(VCPKG_TARGET_TRIPLET arm64-android)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake)
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR})
set(VCPKG_INSTALLED_DIR ${CMAKE_SOURCE_DIR}/vcpkg_installed)
string(REPLACE "\\" "/" VCPKG_ROOT_WINDOWS_FIX $ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT_WINDOWS_FIX}/scripts/buildsystems/vcpkg.cmake)
project(${PACKAGE_ID} VERSION ${PACKAGE_VERSION})
# c++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# define that stores the actual source directory
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(COMPILE_ID songdetails)
# compile options used
add_compile_options(-frtti -fPIE -fPIC -fexceptions -fvisibility=hidden)
if(${CMAKE_BUILD_TYPE} STREQUAL "RELEASE" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" OR ${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel")
# Better optimizations
add_compile_options(-O3)
# LTO
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
add_compile_options(-flto)
endif()
# compile definitions used
add_compile_definitions(VERSION=\"${PACKAGE_VERSION}\")
add_compile_definitions(MOD_ID=\"${PACKAGE_ID}\")
add_compile_definitions(FMT_HEADER_ONLY)
# DEFINE UNITY_2021
add_compile_definitions(UNITY_2021)
# recursively get all src files
file(GLOB_RECURSE cpp_file_list ${SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE c_file_list ${SOURCE_DIR}/*.c)
# add all src files to compile
add_library(
${COMPILE_ID}
SHARED
${cpp_file_list}
${c_file_list}
${CMAKE_SOURCE_DIR}/src/SongProto.pb.cc # it ends in .cc so add it manually
)
target_include_directories(${COMPILE_ID} PRIVATE "${VCPKG_ROOT}/installed/arm64-android/include")
find_package(unofficial-brotli CONFIG REQUIRED)
find_package(protobuf CONFIG REQUIRED)
# add src dir as include dir
target_include_directories(${COMPILE_ID} PRIVATE ${SOURCE_DIR})
# add include dir as include dir
target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR})
# add shared dir as include dir
target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR})
target_include_directories(${COMPILE_ID} PRIVATE ${EXTERN_DIR}/includes)
target_include_directories(${COMPILE_ID} SYSTEM PRIVATE ${EXTERN_DIR}/includes/libil2cpp/il2cpp/libil2cpp)
target_include_directories(${COMPILE_ID} SYSTEM PRIVATE ${EXTERN_DIR}/includes/fmt/fmt/include/)
target_link_libraries(
${COMPILE_ID}
PRIVATE
-llog
-lz
unofficial::brotli::brotlidec
protobuf::libprotobuf
${EXTERN_DIR}/libs/libcurl.a
${EXTERN_DIR}/libs/libpaper2_scotland2.so
)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_STRIP} -g -S -d --strip-all
"lib${COMPILE_ID}.so" -o "stripped_lib${COMPILE_ID}.so"
COMMENT "Strip debug symbols done on final binary.")
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory debug
COMMENT "Make directory for debug symbols"
)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID}.so debug/lib${COMPILE_ID}.so
COMMENT "Rename the lib to debug_ since it has debug symbols"
)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID}.so lib${COMPILE_ID}.so
COMMENT "Rename the stripped lib to regular"
)
foreach(so_file ${so_list})
cmake_path(GET so_file FILENAME file)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${so_file} debug/${file}
COMMENT "Copy so files for ndk stack"
)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_STRIP} -g -S -d --strip-all ${so_file} -o ${file}
COMMENT "Strip debug symbols from the dependencies")
endforeach()
foreach(a_file ${a_list})
cmake_path(GET a_file FILENAME file)
add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file}
COMMENT "Copy a files for ndk stack")
endforeach()