Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ extern/
extern.cmake
qpm_defines.cmake
build/
build_desktop/

build-linux/
36 changes: 20 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# include some defines automatically made by qpm
include(qpm_defines.cmake)
include(qpm_defines_fixed.cmake)

cmake_minimum_required(VERSION 3.22)
project(${COMPILE_ID})
Expand All @@ -24,6 +24,7 @@ FetchContent_MakeAvailable(googletest)
# c++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED 20)
set(CMAKE_CXX_EXTENSIONS OFF)

# define that stores the actual source directory
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
Expand Down Expand Up @@ -69,7 +70,7 @@ target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR})
# add shared dir as include dir
target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR})

target_link_libraries(${COMPILE_ID} PRIVATE -llog GSL)
target_link_libraries(${COMPILE_ID} PRIVATE GSL)

include(extern.cmake)
MESSAGE(STATUS "extern added!")
Expand All @@ -89,18 +90,21 @@ add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMENT "Rename the stripped lib to regular"
)

enable_testing()

add_compile_options(-Wall -Wextra -Werror -Wpedantic)
add_executable(
test
test/main.cpp
)
target_include_directories(test PUBLIC ${SHARED_DIR})
target_link_libraries(
test
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(test)
if (DEFINED TEST_BUILD)
enable_testing()

add_compile_options(-Wall -Wextra -Werror -Wpedantic)
add_executable(
test
test/main.cpp
)
target_include_directories(test PUBLIC ${SHARED_DIR})
target_link_libraries(
test
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(test)
endif()
27 changes: 27 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": 3,
"configurePresets": [
{
"name": "Android",
"generator": "Ninja",
"binaryDir": "./build"
},
{
"name": "desktop",
"generator": "Ninja",
"binaryDir": "./build_desktop"
}
],
"buildPresets": [
{
"name": "Android",
"configurePreset": "Android",
"inheritConfigureEnvironment": true
},
{
"name": "desktop",
"configurePreset": "desktop",
"inheritConfigureEnvironment": true
}
]
}
71 changes: 33 additions & 38 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
Param(
[Parameter(Mandatory=$false)]
[Switch] $clean,

function Clean-Build-Folder {
if (Test-Path -Path "build") {
remove-item build -R
new-item -Path build -ItemType Directory
}
else {
new-item -Path build -ItemType Directory
}
}

$NDKPath = Get-Content $PSScriptRoot/ndkpath.txt

# Clean-Build-Folder
# build tests

& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DTEST_BUILD=1 -B build
& cmake --build ./build
[Parameter(Mandatory=$false)]
[Switch] $help,

$ExitCode = $LastExitCode
[Parameter(Mandatory=$false)]
[Switch] $test
)

if ($help -eq $true) {
Write-Output "`"Build`" - Copiles your mod into a `".so`" or a `".a`" library"
Write-Output "`n-- Arguments --`n"

if (-not ($ExitCode -eq 0)) {
$msg = "ExitCode: " + $ExitCode
Write-Output $msg
exit $ExitCode
Write-Output "-clean `t`t Deletes the `"build`" folder, so that the entire library is rebuilt"
Write-Output "-test `t`t Creates a test build"
Write-Output "-help `t`t Prints this message"
exit
}

# clean folder
Clean-Build-Folder
# build mod

& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -B build
& cmake --build ./build

$ExitCode = $LastExitCode
# if user specified clean, remove all build files
if ($clean.IsPresent)
{
if (Test-Path -Path "build")
{
remove-item build -R
}
}

# Post build, we actually want to transform the compile_commands.json file such that it has no \\ characters and ONLY has / characters
# (Get-Content -Path build/compile_commands.json) |
# ForEach-Object {$_ -Replace '\\\\', '/'} | Set-Content -Path build/compile_commands.json

# To build tests, we just compile with our local clang++ into an executable
# Kind of wacky but will work on linux
# Requires libcapstone-dev installed, and GSL/gtest headers fetched from cmake
# clang++ test/main.cpp src/trampoline.cpp src/trampoline-allocator.cpp -o build/test -std=c++20 -I/usr/include/ -Ishared -Ibuild/_deps/googletest-src/googletest/include -Ibuild/_deps/gsl-src/include -lcapstone -Iextern/includes/fmt/fmt/include -L/usr/lib/x86_64-linux-gnu -DFMT_HEADER_ONLY -Wall -Wextra -Werror -g
if (($clean.IsPresent) -or (-not (Test-Path -Path "build")))
{
$out = new-item -Path build -ItemType Directory
}

exit $ExitCode
if ($test.IsPresent) {
& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DTEST_BUILD=1 -B build --preset Android -DQPM_ANDROID=
} else {
& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -B build --preset Android -DQPM_ANDROID=
}
& cmake --build ./build
42 changes: 42 additions & 0 deletions build_desktop.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Param(
[Parameter(Mandatory=$false)]
[Switch] $clean,

[Parameter(Mandatory=$false)]
[Switch] $help,

[Parameter(Mandatory=$false)]
[Switch] $test
)

if ($help -eq $true) {
Write-Output "`"Build`" - Copiles your mod into a `".so`" or a `".a`" library"
Write-Output "`n-- Arguments --`n"

Write-Output "-clean `t`t Deletes the `"build`" folder, so that the entire library is rebuilt"
Write-Output "-test `t`t Creates a test build"
Write-Output "-help `t`t Prints this message"
exit
}

# if user specified clean, remove all build files
if ($clean.IsPresent)
{
if (Test-Path -Path "build")
{
remove-item build -R
}
}


if (($clean.IsPresent) -or (-not (Test-Path -Path "build")))
{
$out = new-item -Path build -ItemType Directory
}

if ($test.IsPresent) {
& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DTEST_BUILD=1 -B build_desktop --preset desktop
} else {
& cmake -G "Ninja" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -B build_desktop --preset desktop
}
& cmake --build ./build_desktop
60 changes: 60 additions & 0 deletions qpm_defines_fixed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Modified qpm_defines.cmake to allow cross compiling and desktop compiling
# Version defines, pretty useful
set(MOD_VERSION "0.1.0")
# take the mod name and just remove spaces, that will be MOD_ID, if you don't like it change it after the include of this file
set(MOD_ID "flamingo")

# derived from override .so name or just id_version
set(COMPILE_ID "flamingo")
# derived from whichever codegen package is installed, will default to just codegen
set(CODEGEN_ID "codegen")

# given from qpm, automatically updated from qpm.json
set(EXTERN_DIR_NAME "extern")
set(SHARED_DIR_NAME "shared")

# if no target given, use Debug
if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

# defines used in ninja / cmake ndk builds

if (DEFINED QPM_ANDROID)
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()
message(Using NDK ${CMAKE_ANDROID_NDK})
string(REPLACE "\\" "/" CMAKE_ANDROID_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)
endif()

# define used for external data, mostly just the qpm dependencies
set(EXTERN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${EXTERN_DIR_NAME})
set(SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${SHARED_DIR_NAME})
# get files by filter recursively
MACRO(RECURSE_FILES return_list filter)
FILE(GLOB_RECURSE new_list ${filter})
SET(file_list "")
FOREACH(file_path ${new_list})
SET(file_list ${file_list} ${file_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES file_list)
SET(${return_list} ${file_list})
ENDMACRO()
1 change: 1 addition & 0 deletions shared/hook-installer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <unordered_map>
#include <vector>
#include <list>
#include <optional>
#include "hook-data.hpp"
#include "trampoline-allocator.hpp"

Expand Down
Loading