VoidLoader/VoidLoaderCore/pipeline/head There was a failure building this commit
Signed-off-by: Faumaray <faumaray@gmail.com>
99 lines
3.5 KiB
CMake
99 lines
3.5 KiB
CMake
cmake_minimum_required(VERSION 3.22)
|
|
project(VoidLoaderCore LANGUAGES CXX)
|
|
|
|
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")
|
|
|
|
# ----------------------------------------------------------
|
|
# Locate JDK and JNI
|
|
# ----------------------------------------------------------
|
|
find_package(JNI REQUIRED)
|
|
|
|
if (JNI_FOUND)
|
|
message(STATUS "✅ JNI include dirs: ${JNI_INCLUDE_DIRS}")
|
|
include_directories(${JNI_INCLUDE_DIRS})
|
|
else()
|
|
message(FATAL_ERROR "❌ Could not locate JNI (ensure JAVA_HOME or JDK installed)")
|
|
endif()
|
|
|
|
# ----------------------------------------------------------
|
|
# Toolchain autodetection
|
|
# ----------------------------------------------------------
|
|
find_program(GCC_PATH g++)
|
|
find_program(MINGW_PATH x86_64-w64-mingw32-g++)
|
|
|
|
message(STATUS "🔍 Toolchains detected:")
|
|
message(STATUS " Linux → ${GCC_PATH}")
|
|
message(STATUS " Win64 → ${MINGW_PATH}")
|
|
|
|
# ----------------------------------------------------------
|
|
# 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>
|
|
)
|
|
|
|
message(STATUS "✅ Configured VoidLoader JNI agent build")
|
|
|