Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
5 files changed
+52
-125
No files matched your search
+43
-84
@@ -1,98 +1,57 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(VoidLoaderCore LANGUAGES CXX)
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(VoidLoader LANGUAGES CXX)
|
||||
|
||||
# ============================================================
|
||||
# Project settings
|
||||
# ============================================================
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Options
|
||||
# ----------------------------------------------------------
|
||||
option(BUILD_LINUX "Build shared lib for Linux" ON)
|
||||
option(BUILD_WINDOWS "Cross-compile shared lib for Windows" ON)
|
||||
set(VERSION "1.0.1")
|
||||
# ============================================================
|
||||
# Source / includes
|
||||
# ============================================================
|
||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
include_directories(include)
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Locate JDK and JNI
|
||||
# ----------------------------------------------------------
|
||||
# ============================================================
|
||||
# Find JDK / JNI / JVMTI
|
||||
# ============================================================
|
||||
find_package(Java REQUIRED)
|
||||
find_package(JNI REQUIRED)
|
||||
message(STATUS "JNI include dirs: ${JNI_INCLUDE_DIRS}")
|
||||
message(STATUS "JNI libs: ${JNI_LIBRARIES}")
|
||||
|
||||
if (JNI_FOUND)
|
||||
message(STATUS "✅ JNI include dirs: ${JNI_INCLUDE_DIRS}")
|
||||
include_directories(${JNI_INCLUDE_DIRS})
|
||||
# For JVMTI: also include JAVA_HOME/include/<os>
|
||||
if (DEFINED ENV{JAVA_HOME})
|
||||
message(STATUS "JAVA_HOME: $ENV{JAVA_HOME}")
|
||||
include_directories($ENV{JAVA_HOME}/include)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
include_directories($ENV{JAVA_HOME}/include/win32)
|
||||
else()
|
||||
include_directories($ENV{JAVA_HOME}/include/linux)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ============================================================
|
||||
# Platform flags
|
||||
# ============================================================
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX)
|
||||
else()
|
||||
message(FATAL_ERROR "❌ Could not locate JNI (ensure JAVA_HOME or JDK installed)")
|
||||
add_compile_options(-fPIC)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Toolchain autodetection
|
||||
# ----------------------------------------------------------
|
||||
find_program(GCC_PATH g++)
|
||||
find_program(MINGW_PATH x86_64-w64-mingw32-g++)
|
||||
# ============================================================
|
||||
# Build shared library
|
||||
# ============================================================
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCES})
|
||||
|
||||
message(STATUS "🔍 Toolchains detected:")
|
||||
message(STATUS " Linux → ${GCC_PATH}")
|
||||
message(STATUS " Win64 → ${MINGW_PATH}")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${JNI_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${JNI_LIBRARIES})
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Source structure
|
||||
# ----------------------------------------------------------
|
||||
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||
include_directories("include")
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Linux target
|
||||
# ----------------------------------------------------------
|
||||
if (BUILD_LINUX AND GCC_PATH)
|
||||
add_library(VoidLoader_Linux SHARED ${SOURCES})
|
||||
set_target_properties(VoidLoader_Linux PROPERTIES
|
||||
OUTPUT_NAME "VoidLoader"
|
||||
SUFFIX ".so"
|
||||
VERSION ${VERSION}
|
||||
)
|
||||
target_compile_options(VoidLoader_Linux PRIVATE -O2 -Wall -fPIC)
|
||||
target_include_directories(VoidLoader_Linux PRIVATE ${JNI_INCLUDE_DIRS})
|
||||
target_link_libraries(VoidLoader_Linux PRIVATE ${JNI_LIBRARIES})
|
||||
|
||||
# Post-build: bundle dependencies
|
||||
add_custom_command(TARGET VoidLoader_Linux POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -DINPUT_LIB=$<TARGET_FILE:VoidLoader_Linux>
|
||||
-DOUT_DIR=$<TARGET_FILE_DIR:VoidLoader_Linux>
|
||||
-P ${CMAKE_SOURCE_DIR}/cmake/bundle_linux.cmake
|
||||
)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Windows target
|
||||
# ----------------------------------------------------------
|
||||
if (BUILD_WINDOWS AND MINGW_PATH)
|
||||
add_library(VoidLoader_Windows SHARED ${SOURCES})
|
||||
set_target_properties(VoidLoader_Windows PROPERTIES
|
||||
OUTPUT_NAME "VoidLoader"
|
||||
SUFFIX ".dll"
|
||||
VERSION ${VERSION}
|
||||
)
|
||||
target_compile_options(VoidLoader_Windows PRIVATE
|
||||
-O2 -Wall -static-libstdc++ -static-libgcc
|
||||
)
|
||||
target_include_directories(VoidLoader_Windows PRIVATE ${JNI_INCLUDE_DIRS})
|
||||
|
||||
add_custom_command(TARGET VoidLoader_Windows POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -DINPUT_LIB=$<TARGET_FILE:VoidLoader_Windows>
|
||||
-DOUT_DIR=$<TARGET_FILE_DIR:VoidLoader_Windows>
|
||||
-P ${CMAKE_SOURCE_DIR}/cmake/bundle_windows.cmake
|
||||
)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Combined target
|
||||
# ----------------------------------------------------------
|
||||
add_custom_target(buildAll
|
||||
DEPENDS
|
||||
$<$<BOOL:${BUILD_LINUX}>:VoidLoader_Linux>
|
||||
$<$<BOOL:${BUILD_WINDOWS}>:VoidLoader_Windows>
|
||||
# Output name: YourAgent.dll / libYourAgent.so
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME "VoidLoader"
|
||||
)
|
||||
|
||||
message(STATUS "✅ Configured VoidLoader JNI agent build")
|
||||
|
||||
Vendored
+5
-2
@@ -4,8 +4,11 @@ pipeline {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'rm -rf build'
|
||||
sh 'cmake -B build -S . -DBUILD_WINDOWS=ON -DBUILD_LINUX=ON'
|
||||
sh 'cmake --build build --target buildAll'
|
||||
sh 'mkdir build && mkdir build/linux && mkdir build/windows'
|
||||
sh 'cmake -B build/linux -DCMAKE_BUILD_TYPE=Release'
|
||||
sh 'cmake --build build/linux'
|
||||
sh 'cmake -B build/windows -DCMAKE_TOOLCHAIN_FILE=mingw.cmake -DCMAKE_BUILD_TYPE=Release'
|
||||
sh 'cmake --build build/windows'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# Copy non-system dependencies using ldd
|
||||
execute_process(
|
||||
COMMAND ldd ${INPUT_LIB}
|
||||
OUTPUT_VARIABLE LDD_OUT
|
||||
)
|
||||
string(REGEX MATCHALL "\t[^ ]+ => (/[^ ]+)" MATCHES "${LDD_OUT}")
|
||||
|
||||
foreach(M ${MATCHES})
|
||||
string(REGEX REPLACE ".*=> " "" M_PATH ${M})
|
||||
if (NOT "${M_PATH}" MATCHES "^/usr/lib" AND NOT "${M_PATH}" MATCHES "^/lib")
|
||||
message(STATUS "📦 Copying ${M_PATH}")
|
||||
file(COPY ${M_PATH} DESTINATION ${OUT_DIR})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Copy referenced DLLs using objdump
|
||||
execute_process(
|
||||
COMMAND objdump -p ${INPUT_LIB}
|
||||
OUTPUT_VARIABLE OBJDUMP_OUT
|
||||
)
|
||||
string(REGEX MATCHALL "DLL Name: ([A-Za-z0-9_\\.-]+)" DLLS "${OBJDUMP_OUT}")
|
||||
|
||||
set(MINGW_ROOTS
|
||||
"/usr/x86_64-w64-mingw32/bin"
|
||||
"/usr/lib/gcc/x86_64-w64-mingw32/"
|
||||
)
|
||||
|
||||
foreach(DLL ${DLLS})
|
||||
string(REGEX REPLACE "DLL Name: " "" DLL_NAME ${DLL})
|
||||
foreach(ROOT ${MINGW_ROOTS})
|
||||
file(GLOB CAND "${ROOT}/${DLL_NAME}")
|
||||
if (CAND)
|
||||
message(STATUS "📦 Copying ${CAND}")
|
||||
file(COPY ${CAND} DESTINATION ${OUT_DIR})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
Reference in new issue
Block a user