11# include some defines automatically made by qpm
22include (qpm_defines.cmake)
3- include (${EXTERN_DIR} /includes/kaleb/shared/cmake/assets.cmake)
43
5- add_definitions (-DCP_SDK_BMBF)
6- add_definitions (-DDEBUG_SCENES)
4+ cmake_minimum_required (VERSION 3.22)
5+ project (${COMPILE_ID} )
6+ include (${EXTERN_DIR} /includes/kaleb/shared/cmake/assets.cmake)
77
8- # override mod id
9- set (MOD_ID "ChatPlexSDK-BS" )
8+ # c++ standard
9+ set (CMAKE_CXX_STANDARD 20)
10+ set (CMAKE_CXX_STANDARD_REQUIRED 20)
1011
1112# Enable link time optimization
1213# In my experience, this can be highly unstable but it nets a huge size optimization and likely performance
1314# However, the instability was seen using Android.mk/ndk-build builds. With Ninja + CMake, this problem seems to have been solved.
1415# As always, test thoroughly
1516# - Fern
1617# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
17-
18- cmake_minimum_required (VERSION 3.21)
19- project (${COMPILE_ID} )
20-
2118# export compile commands for significantly better intellisense
2219set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
2320
24- # c++ standard
25- set (CMAKE_CXX_STANDARD 20)
26- set (CMAKE_CXX_STANDARD_REQUIRED 20)
27-
2821# define that stores the actual source directory
2922set (SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src)
3023set (INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /include )
3124set (SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR} /shared)
3225
3326# compile options used
34- add_compile_options (-frtti -fexceptions)
35- add_compile_options (-O3)
27+ add_compile_options (-frtti -fPIE -fPIC -fexceptions -fdeclspec -fvisibility=hidden -Wno-extra-qualification -O3)
3628
3729# get git info
3830execute_process (COMMAND git config user.name OUTPUT_VARIABLE GIT_USER)
@@ -50,103 +42,107 @@ message(STATUS "GIT_BRANCH: ${GIT_BRANCH}")
5042message (STATUS "GIT_COMMIT: 0x${GIT_COMMIT} " )
5143message (STATUS "GIT_MODIFIED: ${GIT_MODIFIED} " )
5244
53- # set git defines
54- add_compile_definitions (GIT_USER=\"${GIT_USER} \")
55- add_compile_definitions (GIT_BRANCH=\"${GIT_BRANCH} \")
56- add_compile_definitions (GIT_COMMIT=0x${GIT_COMMIT} )
57- add_compile_definitions (GIT_MODIFIED=${GIT_MODIFIED} )
45+
46+ # Check for file presence and read current contents
47+ set (GIT_INFO_H_PATH "${CMAKE_CURRENT_SOURCE_DIR} /include/git_info.h" )
48+ if (EXISTS "${GIT_INFO_H_PATH} " )
49+ file (READ "${GIT_INFO_H_PATH} " GIT_INFO_H_CURRENT)
50+ else ()
51+ set (GIT_INFO_H_CURRENT "" )
52+ endif ()
53+
54+ # Define new git info content
55+ set (GIT_INFO_H "#pragma once
56+ #define GIT_USER \" ${GIT_USER} \"
57+ #define GIT_BRANCH \" ${GIT_BRANCH} \"
58+ #define GIT_COMMIT 0x${GIT_COMMIT}
59+ #define GIT_MODIFIED ${GIT_MODIFIED}
60+ " )
61+
62+ # Write git info to file if the contents have changed
63+ if (NOT "${GIT_INFO_H} " STREQUAL "${GIT_INFO_H_CURRENT} " )
64+ file (WRITE "${GIT_INFO_H_PATH} " "${GIT_INFO_H} " )
65+ endif ()
66+
5867
5968# compile definitions used
6069add_compile_definitions (VERSION =\"${MOD_VERSION} \")
6170add_compile_definitions (MOD_ID=\"${MOD_ID} \")
71+ add_compile_definitions (UNITY_2021)
72+ add_compile_definitions (CORDL_RUNTIME_FIELD_NULL_CHECKS)
6273add_compile_definitions (__USE_LARGEFILE64)
63- add_compile_definitions (BEATSABER_1_29_4_OR_NEWER)
74+
75+ # compile options used
76+ add_compile_definitions (CP_SDK_BMBF)
77+ add_compile_definitions (DEBUG_SCENES)
78+
79+ string (LENGTH "${CMAKE_CURRENT_LIST_DIR} /" FOLDER_LENGTH)
80+ add_compile_definitions ("PAPER_ROOT_FOLDER_LENGTH=${FOLDER_LENGTH} " )
6481
6582# recursively get all src files
66- RECURSE_FILES(h_file_lista ${INCLUDE_DIR} /*.hpp)
67- RECURSE_FILES(h_file_listb ${SHARED_DIR} /*.hpp)
68- RECURSE_FILES(hpp_file_lista ${INCLUDE_DIR} /*.hpp)
69- RECURSE_FILES(hpp_file_listb ${SHARED_DIR} /*.hpp)
70- RECURSE_FILES(cpp_file_list ${SOURCE_DIR} /*.cpp)
71- RECURSE_FILES(c_file_list ${SOURCE_DIR} /*.c)
83+ recurse_files(cpp_file_list ${SOURCE_DIR} /*.cpp)
84+ recurse_files(c_file_list ${SOURCE_DIR} /*.c)
7285list (APPEND c_file_list ${INCLUDE_DIR} /zip/src/zip.c)
7386
87+ recurse_files(inline_hook_c ${EXTERN_DIR} /includes/beatsaber-hook/shared/inline-hook/*.c)
88+ recurse_files(inline_hook_cpp ${EXTERN_DIR} /includes/beatsaber-hook/shared/inline-hook/*.cpp)
89+
7490# add all src files to compile
7591add_library (
76- ${COMPILE_ID}
77- SHARED
78- ${h_file_lista}
79- ${h_file_listb}
80- ${hpp_file_lista}
81- ${hpp_file_listb}
82- ${cpp_file_list}
83- ${c_file_list}
92+ ${COMPILE_ID} SHARED ${cpp_file_list} ${c_file_list} ${inline_hook_c} ${inline_hook_cpp}
8493)
8594
86- # Add any assets
87- add_assets(assets_${COMPILE_ID} STATIC ${CMAKE_CURRENT_LIST_DIR} /assets ${INCLUDE_DIR} /assets.hpp)
88-
89- # get the vcpkg dir from env variables
90- if (EXISTS $ENV{VCPKG_ROOT} )
91- set (VCPKG_ROOT $ENV{VCPKG_ROOT} )
92- else ()
93- MESSAGE (ERROR "Please define the environment variable VCPKG_ROOT with the root to your vcpkg install!" )
94- endif ()
95-
96- target_include_directories (${COMPILE_ID} PRIVATE .)
97-
9895# add src dir as include dir
9996target_include_directories (${COMPILE_ID} PRIVATE ${SOURCE_DIR} )
10097# add include dir as include dir
10198target_include_directories (${COMPILE_ID} PRIVATE ${INCLUDE_DIR} )
10299# add shared dir as include dir
103100target_include_directories (${COMPILE_ID} PUBLIC ${SHARED_DIR} )
104- # codegen includes
105- target_include_directories (${COMPILE_ID} PRIVATE ${EXTERN_DIR} /includes/${CODEGEN_ID} /include )
106101
107- target_link_libraries (${COMPILE_ID} PRIVATE -llog)
108- target_link_libraries (${COMPILE_ID} PRIVATE assets_${COMPILE_ID} )
102+ # Add any assets
103+ add_assets(${COMPILE_ID} -assets STATIC ${CMAKE_CURRENT_LIST_DIR} /assets ${INCLUDE_DIR} /assets.hpp)
104+ target_link_libraries (${COMPILE_ID} PRIVATE -llog -lz ${COMPILE_ID} -assets)
109105
110106# add extern stuff like libs and other includes
111107include (extern.cmake)
112108
113109add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
114- COMMAND ${CMAKE_STRIP} -d --strip-all
115- "lib${COMPILE_ID} .so" -o "stripped_lib${COMPILE_ID} .so"
116- COMMENT "Strip debug symbols done on final binary." )
110+ COMMAND ${CMAKE_STRIP} -g -S -d --strip-all
111+ "lib${COMPILE_ID} .so" -o "stripped_lib${COMPILE_ID} .so"
112+ COMMENT "Strip debug symbols done on final binary." )
117113
118114add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
119115 COMMAND ${CMAKE_COMMAND} -E make_directory debug
120116 COMMENT "Make directory for debug symbols"
121117 )
122118
123119add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
124- COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID} .so debug/lib${COMPILE_ID} .so
125- COMMENT "Rename the lib to debug_ since it has debug symbols"
126- )
120+ COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID} .so debug/lib${COMPILE_ID} .so
121+ COMMENT "Rename the lib to debug_ since it has debug symbols"
122+ )
127123
128- # strip debug symbols from the .so and all dependencies
129124add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
130- COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID} .so lib${COMPILE_ID} .so
131- COMMENT "Rename the stripped lib to regular"
132- )
133- foreach (so_file ${so_list} )
134- cmake_path(GET so_file FILENAME file)
125+ COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID} .so lib${COMPILE_ID} .so
126+ COMMENT "Rename the stripped lib to regular"
127+ )
135128
136- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
137- COMMAND ${CMAKE_COMMAND} -E copy ${so_file} debug/${file}
138- COMMENT "Copy so files for ndk stack"
139- )
129+ foreach (so_file ${so_list} )
130+ cmake_path(GET so_file FILENAME file)
140131
141- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
142- COMMAND ${CMAKE_STRIP } -g -S -d --strip- all ${so_file} -o ${file}
143- COMMENT "Strip debug symbols from the dependencies" )
144- endforeach ( )
132+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
133+ COMMAND ${CMAKE_COMMAND } -E copy ${so_file} debug/ ${file}
134+ COMMENT "Copy so files for ndk stack"
135+ )
145136
146- foreach (a_file ${a_list} )
147- cmake_path(GET a_file FILENAME file)
137+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
138+ COMMAND ${CMAKE_STRIP} -g -S -d --strip-all ${so_file} -o ${file}
139+ COMMENT "Strip debug symbols from the dependencies" )
140+ endforeach ()
148141
149- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
150- COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file}
151- COMMENT "Copy a files for ndk stack" )
152- endforeach ()
142+ foreach (a_file ${a_list} )
143+ cmake_path(GET a_file FILENAME file)
144+
145+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
146+ COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file}
147+ COMMENT "Copy a files for ndk stack" )
148+ endforeach ()
0 commit comments