Skip to content

Commit

Permalink
Compile things more manually to not link against bs hook directly
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBrumbler committed Jan 29, 2024
1 parent 59e226b commit 7b54c4b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 35 deletions.
41 changes: 24 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# include some defines automatically made by qpm
include(qpm_defines.cmake)

cmake_minimum_required(VERSION 3.22)
project(${COMPILE_ID})

include(${CMAKE_CURRENT_LIST_DIR}/cmake/quest.cmake)

project(${PACKAGE_ID} VERSION ${PACKAGE_VERSION})

# c++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED 20)

# Enable link time optimization
# In my experience, this can be highly unstable but it nets a huge size optimization and likely performance
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)

# 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)
# compile definitions used
add_compile_definitions(VERSION=\"${MOD_VERSION}\")
add_compile_definitions(MOD_ID=\"${MOD_ID}\")
add_compile_definitions(VERSION=\"${PACKAGE_VERSION}\")
add_compile_definitions(MOD_ID=\"${PACKAGE_ID}\")
add_compile_definitions(FMT_HEADER_ONLY)

# recursively get all src files
RECURSE_FILES(cpp_file_list ${SOURCE_DIR}/*.cpp)
RECURSE_FILES(c_file_list ${SOURCE_DIR}/*.c)
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(
Expand All @@ -50,15 +50,22 @@ target_include_directories(${COMPILE_ID} PRIVATE ${SOURCE_DIR})
target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR})
# add shared dir as include dir
target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR})
# codegen includes
target_include_directories(${COMPILE_ID} PRIVATE ${EXTERN_DIR}/includes/${CODEGEN_ID}/include)

# gzip library
target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR}/gzip-hpp/include)

target_link_libraries(${COMPILE_ID} PRIVATE -llog -lz "${VCPKG_ROOT}/installed/arm64-android/lib/libprotobuf.a")
# add extern stuff like libs and other includes
include(extern.cmake)
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
"${VCPKG_ROOT}/installed/arm64-android/lib/libprotobuf.a"
${EXTERN_DIR}/libs/libcurl.a
${EXTERN_DIR}/libs/libpaperlog.so
)

add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_STRIP} -g -S -d --strip-all
Expand Down
47 changes: 47 additions & 0 deletions cmake/quest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
if (NOT DEFINED CMAKE_ANDROID_NDK)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/ndkpath.txt")
file (STRINGS "ndkpath.txt" CMAKE_ANDROID_NDK)
else()
if(EXISTS $ENV{ANDROID_NDK_HOME})
set(CMAKE_ANDROID_NDK $ENV{ANDROID_NDK_HOME})
elseif(EXISTS $ENV{ANDROID_NDK_LATEST_HOME})
set(CMAKE_ANDROID_NDK $ENV{ANDROID_NDK_LATEST_HOME})
endif()
endif()
endif()
if (NOT DEFINED CMAKE_ANDROID_NDK)
message(Big time error buddy, no NDK)
endif()

string(REPLACE "\\" "/" CMAKE_ANDROID_NDK ${CMAKE_ANDROID_NDK})
message(STATUS "Using NDK ${CMAKE_ANDROID_NDK}")

set(ANDROID_PLATFORM 24)
set(ANDROID_ABI arm64-v8a)
set(ANDROID_STL c++_static)
set(ANDROID_USE_LEGACY_TOOLCHAIN_FILE OFF)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake)

# read in information about the mod from qpm.json
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/qpm.json PACKAGE_JSON)

string(JSON PACKAGE_INFO GET ${PACKAGE_JSON} info)

string(JSON PACKAGE_NAME GET ${PACKAGE_INFO} name)
string(JSON PACKAGE_ID GET ${PACKAGE_INFO} id)
string(JSON PACKAGE_VERSION GET ${PACKAGE_INFO} version)

message(STATUS "PACKAGE NAME: ${PACKAGE_NAME}")
message(STATUS "PACKAGE VERSION: ${PACKAGE_VERSION}")

string(JSON EXTERN_DIR_NAME GET ${PACKAGE_JSON} dependenciesDir)
string(JSON SHARED_DIR_NAME GET ${PACKAGE_JSON} sharedDir)

set(EXTERN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${EXTERN_DIR_NAME})
set(SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${SHARED_DIR_NAME})

macro(find_qpm_package NAME)
set(${NAME}_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/cmake")
find_package(${NAME} REQUIRED)
endmacro()
2 changes: 1 addition & 1 deletion qpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/RedBrumbler/SongDetails",
"additionalData": {
"overrideSoName": "libsongdetails.so",
"cmake": true
"cmake": false
}
},
"dependencies": [
Expand Down
39 changes: 22 additions & 17 deletions qpm.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/RedBrumbler/SongDetails",
"additionalData": {
"overrideSoName": "libsongdetails.so",
"cmake": true
"cmake": false
}
},
"workspace": {
Expand Down Expand Up @@ -60,17 +60,22 @@
{
"dependency": {
"id": "paper",
"versionRange": "=3.3.1",
"versionRange": "=3.6.0",
"additionalData": {
"soLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.3.1/libpaperlog.so",
"debugSoLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.3.1/debug_libpaperlog.so",
"soLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.0/libpaperlog.so",
"debugSoLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.0/debug_libpaperlog.so",
"overrideSoName": "libpaperlog.so",
"modLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.3.1/paperlog.qmod",
"branchName": "version/v3_3_1",
"modLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.0/paperlog.qmod",
"branchName": "version/v3_6_0",
"compileOptions": {
"systemIncludes": [
"shared/utfcpp"
]
},
"cmake": false
}
},
"version": "3.3.1"
"version": "3.6.0"
},
{
"dependency": {
Expand Down Expand Up @@ -108,6 +113,16 @@
},
"version": "5.0.7"
},
{
"dependency": {
"id": "scotland2",
"versionRange": "=0.1.3",
"additionalData": {
"overrideSoName": "libsl2.so"
}
},
"version": "0.1.3"
},
{
"dependency": {
"id": "fmt",
Expand All @@ -126,16 +141,6 @@
}
},
"version": "10.0.0"
},
{
"dependency": {
"id": "scotland2",
"versionRange": "=0.1.3",
"additionalData": {
"overrideSoName": "libsl2.so"
}
},
"version": "0.1.3"
}
]
}

0 comments on commit 7b54c4b

Please sign in to comment.