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 (-DPAPER_DISABLE_SOURCE_LOC )
6- add_definitions (-DCP_SDK_BMBF )
4+ cmake_minimum_required ( VERSION 3.22 )
5+ project ( ${COMPILE_ID} )
76
8- # override mod id
9- set (MOD_ID "QBeatSaberPlus-NoteTweaker" )
7+ # c++ standard
8+ set (CMAKE_CXX_STANDARD 20)
9+ set (CMAKE_CXX_STANDARD_REQUIRED 20)
1010
1111# Enable link time optimization
1212# In my experience, this can be highly unstable but it nets a huge size optimization and likely performance
1313# However, the instability was seen using Android.mk/ndk-build builds. With Ninja + CMake, this problem seems to have been solved.
1414# As always, test thoroughly
1515# - Fern
1616# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
17-
18- cmake_minimum_required (VERSION 3.21)
19- project (${COMPILE_ID} )
20-
2117# export compile commands for significantly better intellisense
2218set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
2319
24- # c++ standard
25- set (CMAKE_CXX_STANDARD 20)
26- set (CMAKE_CXX_STANDARD_REQUIRED 20)
27-
2820# define that stores the actual source directory
2921set (SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src)
3022set (INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /include )
3123set (SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR} /shared)
3224
25+ # stop symbol leaking
26+ #add_link_options(-Wl,--exclude-libs,ALL)
3327# compile options used
34- add_compile_options (-frtti -fexceptions)
35- add_compile_options (-O3)
28+ add_compile_options (-frtti -fPIE -fPIC -fexceptions -fdeclspec -fvisibility=hidden -Wno-extra-qualification -O3)
3629
3730# get git info
3831execute_process (COMMAND git config user.name OUTPUT_VARIABLE GIT_USER)
@@ -50,102 +43,105 @@ message(STATUS "GIT_BRANCH: ${GIT_BRANCH}")
5043message (STATUS "GIT_COMMIT: 0x${GIT_COMMIT} " )
5144message (STATUS "GIT_MODIFIED: ${GIT_MODIFIED} " )
5245
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} )
46+
47+ # Check for file presence and read current contents
48+ set (GIT_INFO_H_PATH "${CMAKE_CURRENT_SOURCE_DIR} /include/git_info.h" )
49+ if (EXISTS "${GIT_INFO_H_PATH} " )
50+ file (READ "${GIT_INFO_H_PATH} " GIT_INFO_H_CURRENT)
51+ else ()
52+ set (GIT_INFO_H_CURRENT "" )
53+ endif ()
54+
55+ # Define new git info content
56+ set (GIT_INFO_H "#pragma once
57+ #define GIT_USER \" ${GIT_USER} \"
58+ #define GIT_BRANCH \" ${GIT_BRANCH} \"
59+ #define GIT_COMMIT 0x${GIT_COMMIT}
60+ #define GIT_MODIFIED ${GIT_MODIFIED}
61+ " )
62+
63+ # Write git info to file if the contents have changed
64+ if (NOT "${GIT_INFO_H} " STREQUAL "${GIT_INFO_H_CURRENT} " )
65+ file (WRITE "${GIT_INFO_H_PATH} " "${GIT_INFO_H} " )
66+ endif ()
67+
5868
5969# compile definitions used
6070add_compile_definitions (VERSION =\"${MOD_VERSION} \")
6171add_compile_definitions (MOD_ID=\"${MOD_ID} \")
72+ add_compile_definitions (UNITY_2021)
73+ add_compile_definitions (CORDL_RUNTIME_FIELD_NULL_CHECKS)
74+ add_compile_definitions (__USE_LARGEFILE64)
75+
76+ # compile options used
77+ add_compile_definitions (CP_SDK_BMBF)
78+
79+ string (LENGTH "${CMAKE_CURRENT_LIST_DIR} /" FOLDER_LENGTH)
80+ add_compile_definitions ("PAPER_ROOT_FOLDER_LENGTH=${FOLDER_LENGTH} " )
6281
6382# recursively get all src files
64- RECURSE_FILES(h_file_lista ${INCLUDE_DIR} /*.hpp)
65- RECURSE_FILES(h_file_listb ${SHARED_DIR} /*.hpp)
66- RECURSE_FILES(hpp_file_lista ${INCLUDE_DIR} /*.hpp)
67- RECURSE_FILES(hpp_file_listb ${SHARED_DIR} /*.hpp)
68- RECURSE_FILES(cpp_file_list ${SOURCE_DIR} /*.cpp)
69- 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)
85+
86+ recurse_files(inline_hook_c ${EXTERN_DIR} /includes/beatsaber-hook/shared/inline-hook/*.c)
87+ recurse_files(inline_hook_cpp ${EXTERN_DIR} /includes/beatsaber-hook/shared/inline-hook/*.cpp)
7088
7189# add all src files to compile
7290add_library (
73- ${COMPILE_ID}
74- SHARED
75- ${h_file_lista}
76- ${h_file_listb}
77- ${hpp_file_lista}
78- ${hpp_file_listb}
79- ${cpp_file_list}
80- ${c_file_list}
91+ ${COMPILE_ID} SHARED ${cpp_file_list} ${c_file_list} ${inline_hook_c} ${inline_hook_cpp}
8192)
8293
83- # Add any assets
84- #add_assets(assets_${COMPILE_ID} STATIC ${CMAKE_CURRENT_LIST_DIR}/assets ${INCLUDE_DIR}/assets.hpp)
85-
86- # get the vcpkg dir from env variables
87- if (EXISTS $ENV{VCPKG_ROOT} )
88- set (VCPKG_ROOT $ENV{VCPKG_ROOT} )
89- else ()
90- MESSAGE (ERROR "Please define the environment variable VCPKG_ROOT with the root to your vcpkg install!" )
91- endif ()
92-
93- target_include_directories (${COMPILE_ID} PRIVATE .)
94-
9594# add src dir as include dir
9695target_include_directories (${COMPILE_ID} PRIVATE ${SOURCE_DIR} )
9796# add include dir as include dir
9897target_include_directories (${COMPILE_ID} PRIVATE ${INCLUDE_DIR} )
9998# add shared dir as include dir
10099target_include_directories (${COMPILE_ID} PUBLIC ${SHARED_DIR} )
101- # codegen includes
102- target_include_directories (${COMPILE_ID} PRIVATE ${EXTERN_DIR} /includes/${CODEGEN_ID} /include )
103100# chatplex-sdk-bs includes
104101target_include_directories (${COMPILE_ID} PRIVATE ${EXTERN_DIR} /includes/chatplex-sdk-bs/shared)
105102
106- target_link_libraries (${COMPILE_ID} PRIVATE -llog)
107- #target_link_libraries(${COMPILE_ID} PRIVATE assets_${COMPILE_ID})
103+ target_link_libraries (${COMPILE_ID} PRIVATE -llog -lz)
108104
109105# add extern stuff like libs and other includes
110106include (extern.cmake)
111107
112108add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
113- COMMAND ${CMAKE_STRIP} -d --strip-all
114- "lib${COMPILE_ID} .so" -o "stripped_lib${COMPILE_ID} .so"
115- COMMENT "Strip debug symbols done on final binary." )
109+ COMMAND ${CMAKE_STRIP} -g -S -d --strip-all
110+ "lib${COMPILE_ID} .so" -o "stripped_lib${COMPILE_ID} .so"
111+ COMMENT "Strip debug symbols done on final binary." )
116112
117113add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
118114 COMMAND ${CMAKE_COMMAND} -E make_directory debug
119115 COMMENT "Make directory for debug symbols"
120116 )
121117
122118add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
123- COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID} .so debug/lib${COMPILE_ID} .so
124- COMMENT "Rename the lib to debug_ since it has debug symbols"
125- )
119+ COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID} .so debug/lib${COMPILE_ID} .so
120+ COMMENT "Rename the lib to debug_ since it has debug symbols"
121+ )
126122
127- # strip debug symbols from the .so and all dependencies
128123add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
129- COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID} .so lib${COMPILE_ID} .so
130- COMMENT "Rename the stripped lib to regular"
131- )
132- foreach (so_file ${so_list} )
133- cmake_path(GET so_file FILENAME file)
124+ COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID} .so lib${COMPILE_ID} .so
125+ COMMENT "Rename the stripped lib to regular"
126+ )
134127
135- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
136- COMMAND ${CMAKE_COMMAND} -E copy ${so_file} debug/${file}
137- COMMENT "Copy so files for ndk stack"
138- )
128+ foreach (so_file ${so_list} )
129+ cmake_path(GET so_file FILENAME file)
130+
131+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
132+ COMMAND ${CMAKE_COMMAND} -E copy ${so_file} debug/${file}
133+ COMMENT "Copy so files for ndk stack"
134+ )
139135
140- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
141- COMMAND ${CMAKE_STRIP} -g -S -d --strip-all ${so_file} -o ${file}
142- COMMENT "Strip debug symbols from the dependencies" )
143- endforeach ()
136+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
137+ COMMAND ${CMAKE_STRIP} -g -S -d --strip-all ${so_file} -o ${file}
138+ COMMENT "Strip debug symbols from the dependencies" )
139+ endforeach ()
144140
145- foreach (a_file ${a_list} )
146- cmake_path(GET a_file FILENAME file)
141+ foreach (a_file ${a_list} )
142+ cmake_path(GET a_file FILENAME file)
147143
148- add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
149- COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file}
150- COMMENT "Copy a files for ndk stack" )
151- endforeach ()
144+ add_custom_command (TARGET ${COMPILE_ID} POST_BUILD
145+ COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file}
146+ COMMENT "Copy a files for ndk stack" )
147+ endforeach ()
0 commit comments