Cmake Refactor
This commit is contained in:
parent
e506dbb1bb
commit
ea4c5c77a1
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -2,10 +2,10 @@
|
||||
path = dependencies/libpng/src
|
||||
url = https://github.com/glennrp/libpng.git
|
||||
[submodule "dependencies/zlib/src"]
|
||||
path = dependencies/zlib/src
|
||||
path = dependencies/libpng/zlib/src
|
||||
url = https://github.com/madler/zlib.git
|
||||
[submodule "dependencies/glfw/src"]
|
||||
path = dependencies/glfw/src
|
||||
path = media-layer/core/dependencies/glfw/src
|
||||
url = https://github.com/glfw/glfw.git
|
||||
[submodule "dependencies/zenity/src"]
|
||||
path = dependencies/zenity/src
|
||||
|
@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.16.0)
|
||||
|
||||
# Specify Options
|
||||
option(MCPI_IS_MIXED_BUILD "Whether The Architecture-Independent And ARM Code Are Different Architecture" FALSE)
|
||||
set(MCPI_BUILD_MODE "both" CACHE STRING "\"arm\" = Build Only Code That Must Be ARM; \"native\" = Build Architecture-Independent Code; \"both\" = Build All Code As ARM")
|
||||
set_property(CACHE MCPI_BUILD_MODE PROPERTY STRINGS "both" "arm" "native")
|
||||
set(MCPI_BUILD_MODE "native" CACHE STRING "\"arm\" = Build Only Code That Must Be ARM; \"native\" = Build Architecture-Independent Code")
|
||||
set_property(CACHE MCPI_BUILD_MODE PROPERTY STRINGS "arm" "native")
|
||||
option(MCPI_OPEN_SOURCE_ONLY "Only Install Open-Source Code (Will Result In Broken Install)" FALSE)
|
||||
option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE)
|
||||
# Server/Headless Builds
|
||||
@ -46,10 +46,6 @@ elseif(MCPI_BUILD_MODE STREQUAL "native")
|
||||
set(USE_ARM32_TOOLCHAIN FALSE)
|
||||
set(BUILD_ARM_COMPONENTS FALSE)
|
||||
set(BUILD_NATIVE_COMPONENTS TRUE)
|
||||
elseif(MCPI_BUILD_MODE STREQUAL "both")
|
||||
set(USE_ARM32_TOOLCHAIN TRUE)
|
||||
set(BUILD_ARM_COMPONENTS TRUE)
|
||||
set(BUILD_NATIVE_COMPONENTS TRUE)
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid Mode")
|
||||
endif()
|
||||
@ -67,12 +63,19 @@ endif()
|
||||
|
||||
# Specify Installation Paths
|
||||
set(MCPI_INSTALL_DIR "lib/${MCPI_VARIANT_NAME}")
|
||||
set(MCPI_LIB_DIR "${MCPI_INSTALL_DIR}/lib")
|
||||
set(MCPI_BIN_DIR "${MCPI_INSTALL_DIR}/bin")
|
||||
set(MCPI_SDK_DIR "${MCPI_INSTALL_DIR}/sdk")
|
||||
set(MCPI_SDK_LIB_DIR "${MCPI_SDK_DIR}/lib")
|
||||
set(MCPI_SDK_INCLUDE_DIR "${MCPI_SDK_DIR}/include")
|
||||
|
||||
# Library Directory
|
||||
set(MCPI_LIB_DIR "${MCPI_INSTALL_DIR}/lib")
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
string(APPEND MCPI_LIB_DIR "/arm")
|
||||
elseif(BUILD_NATIVE_COMPONENTS)
|
||||
string(APPEND MCPI_LIB_DIR "/native")
|
||||
endif()
|
||||
|
||||
# Build Mode
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
|
6
dependencies/CMakeLists.txt
vendored
6
dependencies/CMakeLists.txt
vendored
@ -1,17 +1,11 @@
|
||||
project(dependencies)
|
||||
|
||||
# ZLib (Needed By libpng)
|
||||
add_subdirectory(zlib)
|
||||
# LibPNG
|
||||
add_subdirectory(libpng)
|
||||
# Minecraft: Pi Edition
|
||||
if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY)
|
||||
add_subdirectory(minecraft-pi)
|
||||
endif()
|
||||
# GLFW
|
||||
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
|
||||
add_subdirectory(glfw)
|
||||
endif()
|
||||
# Zenity (Minimal Build)
|
||||
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
|
||||
add_subdirectory(zenity)
|
||||
|
22
dependencies/glfw/CMakeLists.txt
vendored
22
dependencies/glfw/CMakeLists.txt
vendored
@ -1,22 +0,0 @@
|
||||
project(glfw)
|
||||
|
||||
# Silence Warnings
|
||||
add_compile_options(-w)
|
||||
|
||||
## GLFW
|
||||
|
||||
# Download
|
||||
set(BUILD_SHARED_LIBS FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_TESTS FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_DOCS FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_INSTALL FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_WIN32 FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_COCOA FALSE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_X11 TRUE CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_WAYLAND TRUE CACHE BOOL "" FORCE)
|
||||
set(GLFW_LIBRARY_TYPE "STATIC" CACHE BOOL "" FORCE)
|
||||
add_subdirectory(src EXCLUDE_FROM_ALL)
|
||||
|
||||
# Ensure Build
|
||||
add_custom_target(glfw-build ALL DEPENDS glfw)
|
46
dependencies/libpng/CMakeLists.txt
vendored
46
dependencies/libpng/CMakeLists.txt
vendored
@ -1,5 +1,8 @@
|
||||
project(libpng)
|
||||
|
||||
# ZLib (Needed By libpng)
|
||||
add_subdirectory(zlib)
|
||||
|
||||
# Silence Warnings
|
||||
add_compile_options(-w)
|
||||
|
||||
@ -7,18 +10,9 @@ add_compile_options(-w)
|
||||
|
||||
# Options
|
||||
set(PNG_TESTS FALSE CACHE BOOL "" FORCE)
|
||||
if(BUILD_NATIVE_COMPONENTS)
|
||||
set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE)
|
||||
else()
|
||||
set(PNG_NO_STDIO TRUE CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
set(PNG_STATIC FALSE CACHE BOOL "" FORCE)
|
||||
set(PNG_SHARED TRUE CACHE BOOL "" FORCE)
|
||||
else()
|
||||
set(PNG_STATIC TRUE CACHE BOOL "" FORCE)
|
||||
set(PNG_SHARED FALSE CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE)
|
||||
set(PNG_STATIC FALSE CACHE BOOL "" FORCE)
|
||||
set(PNG_SHARED TRUE CACHE BOOL "" FORCE)
|
||||
|
||||
# Download
|
||||
set(ZLIB_LIBRARY zlibstatic)
|
||||
@ -29,28 +23,16 @@ set(CMAKE_POLICY_DEFAULT_CMP0022 NEW) # Fix Error
|
||||
set(M_LIBRARY m) # No Full Paths!
|
||||
add_subdirectory(src EXCLUDE_FROM_ALL)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior
|
||||
if(TARGET png12)
|
||||
set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning
|
||||
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
|
||||
target_include_directories(png12 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
||||
endif()
|
||||
if(TARGET png12_static)
|
||||
target_link_libraries(png12_static "${ZLIB_LIBRARY}" m)
|
||||
target_include_directories(png12_static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
||||
else()
|
||||
add_library(png12_static ALIAS png12)
|
||||
endif()
|
||||
|
||||
# Setup Target
|
||||
set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning
|
||||
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
|
||||
target_include_directories(png12 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
||||
|
||||
# Ensure Build
|
||||
if(TARGET png12)
|
||||
add_custom_target(png12-build ALL DEPENDS png12)
|
||||
endif()
|
||||
if(TARGET png12_static)
|
||||
add_custom_target(png12_static-build ALL DEPENDS png12_static)
|
||||
endif()
|
||||
add_custom_target(png12-build ALL DEPENDS png12)
|
||||
# Install
|
||||
if(TARGET png12)
|
||||
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")
|
||||
# SDK
|
||||
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
install(TARGETS png12 zlibstatic EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
endif()
|
||||
|
@ -8,6 +8,8 @@ else()
|
||||
target_sources(launcher PRIVATE src/client/launcher.cpp)
|
||||
endif()
|
||||
target_link_libraries(launcher reborn-util)
|
||||
# RPath
|
||||
set_target_properties(launcher PROPERTIES INSTALL_RPATH "$ORIGIN/lib/native")
|
||||
|
||||
# Install
|
||||
install(TARGETS launcher DESTINATION "${MCPI_INSTALL_DIR}")
|
||||
|
@ -15,13 +15,6 @@
|
||||
#include "crash-report.h"
|
||||
|
||||
// Set Environmental Variable
|
||||
#define PRESERVE_ENVIRONMENTAL_VARIABLE(name) \
|
||||
{ \
|
||||
char *original_env_value = getenv(name); \
|
||||
if (original_env_value != NULL) { \
|
||||
setenv("ORIGINAL_" name, original_env_value, 1); \
|
||||
} \
|
||||
}
|
||||
static void trim(char **value) {
|
||||
// Remove Trailing Colon
|
||||
int length = strlen(*value);
|
||||
@ -45,19 +38,6 @@ void set_and_print_env(const char *name, char *value) {
|
||||
// Set The Value
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
#ifndef __ARM_ARCH
|
||||
#define PASS_ENVIRONMENTAL_VARIABLE_TO_QEMU(name) \
|
||||
{ \
|
||||
char *old_value = getenv("QEMU_SET_ENV"); \
|
||||
char *new_value = NULL; \
|
||||
/* Pass Variable */ \
|
||||
safe_asprintf(&new_value, "%s%s%s=%s", old_value == NULL ? "" : old_value, old_value == NULL ? "" : ",", name, getenv(name)); \
|
||||
setenv("QEMU_SET_ENV", new_value, 1); \
|
||||
free(new_value); \
|
||||
/* Reset Variable */ \
|
||||
RESET_ENVIRONMENTAL_VARIABLE(name); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get Environmental Variable
|
||||
static char *get_env_safe(const char *name) {
|
||||
@ -102,7 +82,7 @@ static void load(char **ld_preload, char *folder) {
|
||||
int result = access(name, R_OK);
|
||||
if (result == 0) {
|
||||
// Add To LD_PRELOAD
|
||||
string_append(ld_preload, ":%s", name);
|
||||
string_append(ld_preload, "%s%s", *ld_preload == NULL ? "" : ":", name);
|
||||
} else if (result == -1 && errno != 0) {
|
||||
// Fail
|
||||
INFO("Unable To Acesss: %s: %s", name, strerror(errno));
|
||||
@ -169,12 +149,14 @@ void pre_bootstrap(int argc, char *argv[]) {
|
||||
#endif
|
||||
|
||||
// Debug Zenity
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
{
|
||||
const char *is_debug = getenv("MCPI_DEBUG");
|
||||
if (is_debug != NULL && strlen(is_debug) > 0) {
|
||||
set_and_print_env("ZENITY_DEBUG", "1");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// AppImage
|
||||
#ifdef MCPI_IS_APPIMAGE_BUILD
|
||||
@ -348,22 +330,17 @@ void bootstrap(int argc, char *argv[]) {
|
||||
// Free Resolved Path
|
||||
free(resolved_path);
|
||||
|
||||
// Configure LD_LIBRARY_PATH
|
||||
// Configure Library Search Path
|
||||
char *library_path = NULL;
|
||||
{
|
||||
// Log
|
||||
DEBUG("Setting Linker Search Paths...");
|
||||
|
||||
// Preserve
|
||||
PRESERVE_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
|
||||
// Prepare
|
||||
char *new_ld_path = NULL;
|
||||
|
||||
// Add Library Directory
|
||||
safe_asprintf(&new_ld_path, "%s/lib", binary_directory);
|
||||
|
||||
// Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System)
|
||||
#ifdef MCPI_BUNDLE_ARMHF_SYSROOT
|
||||
string_append(&new_ld_path, ":%s/sysroot/lib:%s/sysroot/lib/arm-linux-gnueabihf:%s/sysroot/usr/lib:%s/sysroot/usr/lib/arm-linux-gnueabihf", binary_directory, binary_directory, binary_directory, binary_directory);
|
||||
#endif
|
||||
// Add Native Library Directory
|
||||
safe_asprintf(&new_ld_path, "%s/lib/native", binary_directory);
|
||||
|
||||
// Add LD_LIBRARY_PATH
|
||||
{
|
||||
@ -373,27 +350,38 @@ void bootstrap(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set And Free
|
||||
// Set LD_LIBRARY_PATH (Used For Everything Except MCPI)
|
||||
set_and_print_env("LD_LIBRARY_PATH", new_ld_path);
|
||||
|
||||
// Add ARM Library Directory
|
||||
// (This Overrides LD_LIBRARY_PATH Using ld.so's --library-path Option)
|
||||
safe_asprintf(&library_path, "%s/lib/arm", binary_directory);
|
||||
|
||||
// Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System)
|
||||
#ifdef MCPI_BUNDLE_ARMHF_SYSROOT
|
||||
string_append(&library_path, ":%s/sysroot/lib:%s/sysroot/lib/arm-linux-gnueabihf:%s/sysroot/usr/lib:%s/sysroot/usr/lib/arm-linux-gnueabihf", binary_directory, binary_directory, binary_directory, binary_directory);
|
||||
#endif
|
||||
|
||||
// Add Remaining LD_LIBRARY_PATH
|
||||
string_append(&library_path, ":%s", new_ld_path);
|
||||
|
||||
// Free LD_LIBRARY_PATH
|
||||
free(new_ld_path);
|
||||
}
|
||||
|
||||
// Configure LD_PRELOAD
|
||||
// Configure MCPI's Preloaded Objects
|
||||
char *preload = NULL;
|
||||
{
|
||||
// Log
|
||||
DEBUG("Locating Mods...");
|
||||
|
||||
// Preserve
|
||||
PRESERVE_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
|
||||
char *new_ld_preload = NULL;
|
||||
|
||||
// ~/.minecraft-pi/mods
|
||||
{
|
||||
// Get Mods Folder
|
||||
char *mods_folder = NULL;
|
||||
safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME"));
|
||||
// Load Mods From ./mods
|
||||
load(&new_ld_preload, mods_folder);
|
||||
load(&preload, mods_folder);
|
||||
// Free Mods Folder
|
||||
free(mods_folder);
|
||||
}
|
||||
@ -404,7 +392,7 @@ void bootstrap(int argc, char *argv[]) {
|
||||
char *mods_folder = NULL;
|
||||
safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
|
||||
// Load Mods From ./mods
|
||||
load(&new_ld_preload, mods_folder);
|
||||
load(&preload, mods_folder);
|
||||
// Free Mods Folder
|
||||
free(mods_folder);
|
||||
}
|
||||
@ -413,13 +401,9 @@ void bootstrap(int argc, char *argv[]) {
|
||||
{
|
||||
char *value = get_env_safe("LD_PRELOAD");
|
||||
if (strlen(value) > 0) {
|
||||
string_append(&new_ld_preload, ":%s", value);
|
||||
string_append(&preload, ":%s", value);
|
||||
}
|
||||
}
|
||||
|
||||
// Set LD_PRELOAD
|
||||
set_and_print_env("LD_PRELOAD", new_ld_preload);
|
||||
free(new_ld_preload);
|
||||
}
|
||||
|
||||
// Free Binary Directory
|
||||
@ -430,26 +414,28 @@ void bootstrap(int argc, char *argv[]) {
|
||||
|
||||
// Arguments
|
||||
int argv_start = 1; // argv = &new_args[argv_start]
|
||||
const char *new_args[argv_start /* 1 Potential Prefix Argument (QEMU) */ + argc + 1 /* NULL-Terminator */]; //
|
||||
int real_argv_start = argv_start + 5; // ld.so Arguments
|
||||
const char *new_args[real_argv_start /* 1 Potential Prefix Argument (QEMU) */ + argc + 1 /* NULL-Terminator */]; //
|
||||
|
||||
// Copy Existing Arguments
|
||||
for (int i = 1; i < argc; i++) {
|
||||
new_args[i + argv_start] = argv[i];
|
||||
new_args[i + real_argv_start] = argv[i];
|
||||
}
|
||||
// NULL-Terminator
|
||||
new_args[argv_start + argc] = NULL;
|
||||
new_args[real_argv_start + argc] = NULL;
|
||||
|
||||
// Set Executable Argument
|
||||
new_args[argv_start] = new_mcpi_exe_path;
|
||||
new_args[argv_start] = patch_get_interpreter(new_mcpi_exe_path);
|
||||
new_args[argv_start + 1] = "--preload";
|
||||
new_args[argv_start + 2] = preload;
|
||||
new_args[argv_start + 3] = "--library-path";
|
||||
new_args[argv_start + 4] = library_path;
|
||||
new_args[real_argv_start] = new_mcpi_exe_path;
|
||||
|
||||
// Non-ARM Systems Need QEMU
|
||||
#ifndef __ARM_ARCH
|
||||
argv_start--;
|
||||
new_args[argv_start] = QEMU_BINARY;
|
||||
|
||||
// Prevent QEMU From Being Modded
|
||||
PASS_ENVIRONMENTAL_VARIABLE_TO_QEMU("LD_LIBRARY_PATH");
|
||||
PASS_ENVIRONMENTAL_VARIABLE_TO_QEMU("LD_PRELOAD");
|
||||
#endif
|
||||
|
||||
// Run
|
||||
|
@ -73,6 +73,7 @@ static void duplicate_mcpi_executable(const char *original_path, char *new_path)
|
||||
"--remove-needed", "libX11.so.6", \
|
||||
"--remove-needed", "libEGL.so", \
|
||||
"--replace-needed", "libGLESv2.so", "libGLESv1_CM.so.1", \
|
||||
"--replace-needed", "libSDL-1.2.so.0", "libmedia-layer-core.so", \
|
||||
new_path, \
|
||||
NULL \
|
||||
}; \
|
||||
|
@ -5,7 +5,7 @@ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/libreborn")
|
||||
configure_file(include/libreborn/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/libreborn/config.h" ESCAPE_QUOTES @ONLY)
|
||||
|
||||
# Util
|
||||
add_library(reborn-util STATIC src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c)
|
||||
add_library(reborn-util SHARED src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c)
|
||||
target_include_directories(
|
||||
reborn-util
|
||||
PUBLIC
|
||||
@ -13,6 +13,14 @@ target_include_directories(
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${MCPI_SDK_INCLUDE_DIR}/libreborn>"
|
||||
)
|
||||
# Install
|
||||
install(TARGETS reborn-util DESTINATION "${MCPI_LIB_DIR}")
|
||||
# SDK
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
install(TARGETS reborn-util EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
install(DIRECTORY "include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/libreborn")
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/libreborn")
|
||||
endif()
|
||||
|
||||
# Patch
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
@ -23,7 +31,4 @@ if(BUILD_ARM_COMPONENTS)
|
||||
install(TARGETS reborn-patch DESTINATION "${MCPI_LIB_DIR}")
|
||||
# SDK
|
||||
install(TARGETS reborn-patch EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
install(TARGETS reborn-util EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
install(DIRECTORY "include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/libreborn")
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/libreborn")
|
||||
endif()
|
||||
|
@ -32,17 +32,6 @@
|
||||
\
|
||||
__attribute__((__used__)) return_type name args
|
||||
|
||||
// Macro To Reset Environmental Variables To Pre-MCPI State
|
||||
#define RESET_ENVIRONMENTAL_VARIABLE(name) \
|
||||
{ \
|
||||
char *original_env_value = getenv("ORIGINAL_" name); \
|
||||
if (original_env_value != NULL) { \
|
||||
setenv(name, original_env_value, 1); \
|
||||
} else { \
|
||||
unsetenv(name); \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -4,6 +4,12 @@
|
||||
|
||||
// Safe execvpe()
|
||||
__attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]) {
|
||||
// Log
|
||||
DEBUG("Running Command:");
|
||||
for (int i = 0; argv[i] != NULL; i++) {
|
||||
DEBUG(" %s", argv[i]);
|
||||
}
|
||||
// Run
|
||||
int ret = execvpe(argv[0], (char *const *) argv, (char *const *) envp);
|
||||
if (ret == -1) {
|
||||
ERR("Unable To Execute Program: %s: %s", argv[0], strerror(errno));
|
||||
|
@ -1,9 +1,5 @@
|
||||
project(media-layer)
|
||||
|
||||
# Target Notes:
|
||||
# media-layer-core-real: Fully Built Media Layer Core
|
||||
# media-layer-core: Alias Target That Points To The Library MCPI Should Link To
|
||||
|
||||
# Add Headers
|
||||
add_library(media-layer-headers INTERFACE)
|
||||
target_include_directories(
|
||||
@ -21,13 +17,15 @@ endif()
|
||||
# Add GLESv1_CM Stubs Or Compatibility Layer
|
||||
add_subdirectory(gles)
|
||||
|
||||
# Add Extras
|
||||
add_subdirectory(extras)
|
||||
|
||||
# Add Core
|
||||
add_subdirectory(core)
|
||||
if((BUILD_NATIVE_COMPONENTS AND MCPI_USE_MEDIA_LAYER_PROXY) OR (BUILD_ARM_COMPONENTS AND NOT MCPI_USE_MEDIA_LAYER_PROXY))
|
||||
add_subdirectory(core)
|
||||
endif()
|
||||
|
||||
# Add Proxy
|
||||
if(MCPI_USE_MEDIA_LAYER_PROXY)
|
||||
add_subdirectory(proxy)
|
||||
endif()
|
||||
|
||||
# Add Extras
|
||||
add_subdirectory(extras)
|
||||
|
@ -1,41 +1,25 @@
|
||||
project(media-layer-core)
|
||||
|
||||
# Dependencies
|
||||
add_subdirectory(dependencies)
|
||||
|
||||
# Configuration
|
||||
set(CORE_SRC src/base.cpp src/media.c src/screenshot.c) # SDL Re-Implementation Using GLFW
|
||||
set(CORE_SRC src/base.cpp src/media.c src/screenshot.c $<TARGET_OBJECTS:media-layer-extras>) # SDL Re-Implementation Using GLFW
|
||||
if(NOT MCPI_HEADLESS_MODE)
|
||||
list(APPEND CORE_SRC src/audio/api.cpp src/audio/engine.c src/audio/file.cpp)
|
||||
endif()
|
||||
|
||||
# Build
|
||||
if(MCPI_USE_MEDIA_LAYER_PROXY AND BUILD_NATIVE_COMPONENTS)
|
||||
# Build Media Layer Core Natively And Use Proxy
|
||||
add_library(media-layer-core-real OBJECT ${CORE_SRC}) # Dependencies Are Setup Later
|
||||
endif()
|
||||
if(NOT MCPI_USE_MEDIA_LAYER_PROXY AND BUILD_ARM_COMPONENTS)
|
||||
# Directly Link Media Layer Core To MCPI
|
||||
add_library(media-layer-core-real SHARED ${CORE_SRC}) # Dependencies Are Setup Later
|
||||
set_target_properties(media-layer-core-real PROPERTIES OUTPUT_NAME "media-layer-core")
|
||||
# Install
|
||||
install(TARGETS media-layer-core-real DESTINATION "${MCPI_LIB_DIR}")
|
||||
install(TARGETS media-layer-core-real EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
# Create Alias Target For Linking
|
||||
add_library(media-layer-core ALIAS media-layer-core-real)
|
||||
set_target_properties(media-layer-core-real PROPERTIES EXPORT_NAME media-layer-core)
|
||||
endif()
|
||||
add_library(media-layer-core SHARED ${CORE_SRC}) # Dependencies Are Setup Later
|
||||
# Install
|
||||
install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}")
|
||||
install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
|
||||
# Configure Media Layer Core If Built
|
||||
if(TARGET media-layer-core-real)
|
||||
# Link
|
||||
target_link_libraries(media-layer-core PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC pthread PUBLIC dl)
|
||||
if(NOT MCPI_HEADLESS_MODE)
|
||||
# OpenAL
|
||||
find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
|
||||
# Link
|
||||
target_link_libraries(media-layer-core-real PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC pthread PUBLIC dl)
|
||||
if(NOT MCPI_HEADLESS_MODE)
|
||||
# OpenAL
|
||||
find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
|
||||
# Link
|
||||
target_link_libraries(media-layer-core-real PRIVATE png12_static PRIVATE "${OPENAL_LIBRARY}" PRIVATE m PUBLIC GLESv1_CM PRIVATE glfw)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add Symlinks So MCPI Can Locate Libraries
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
install_symlink("libmedia-layer-core.so" "${MCPI_LIB_DIR}/libSDL-1.2.so.0")
|
||||
target_link_libraries(media-layer-core PRIVATE png12 PRIVATE "${OPENAL_LIBRARY}" PRIVATE m PUBLIC GLESv1_CM PRIVATE glfw)
|
||||
endif()
|
||||
|
@ -1,11 +1,5 @@
|
||||
project(media-layer-extras)
|
||||
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
# Add Source To Media Core
|
||||
if(TARGET media-layer-core-real)
|
||||
set(TARGET media-layer-core-real)
|
||||
elseif(TARGET media-layer-proxy-server)
|
||||
set(TARGET media-layer-proxy-server)
|
||||
endif()
|
||||
target_sources("${TARGET}" PRIVATE src/SDL.c)
|
||||
endif()
|
||||
# Build
|
||||
add_library(media-layer-extras OBJECT src/SDL.c)
|
||||
target_link_libraries(media-layer-extras media-layer-headers reborn-util)
|
||||
|
@ -1,39 +1,32 @@
|
||||
project(media-layer-stubs)
|
||||
|
||||
# Stubs Only Needed For ARM
|
||||
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
|
||||
if(NOT MCPI_HEADLESS_MODE AND ((BUILD_NATIVE_COMPONENTS AND MCPI_USE_MEDIA_LAYER_PROXY) OR (BUILD_ARM_COMPONENTS AND NOT MCPI_USE_MEDIA_LAYER_PROXY)))
|
||||
# GLESv1_CM Compatibility Layer
|
||||
set(GLES1_LINK_MODE "SHARED")
|
||||
if(MCPI_USE_MEDIA_LAYER_PROXY)
|
||||
# Link To Media Layer Proxy Client Statically
|
||||
# (This is so it doesn't interfere with the Media Layer Proxy Server's libGLESv1_CM.so.1 symlink.)
|
||||
set(GLES1_LINK_MODE "OBJECT")
|
||||
endif()
|
||||
if(MCPI_USE_GLES1_COMPATIBILITY_LAYER)
|
||||
set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c src/compatibility-layer/buffer.cpp)
|
||||
else()
|
||||
set(GLES_SRC src/passthrough.c)
|
||||
endif()
|
||||
add_library(GLESv1_CM "${GLES1_LINK_MODE}" ${GLES_SRC})
|
||||
add_library(GLESv1_CM SHARED ${GLES_SRC})
|
||||
target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m)
|
||||
# Install
|
||||
if(GLES1_LINK_MODE STREQUAL "SHARED")
|
||||
install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
|
||||
endif()
|
||||
else()
|
||||
install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
|
||||
elseif(BUILD_ARM_COMPONENTS)
|
||||
# Add GLESv1_CM Stubs For Linking
|
||||
add_library(GLESv1_CM SHARED src/stubs.c)
|
||||
# Install Fake GLESv1_CM Stubs In Server Mode
|
||||
if(BUILD_ARM_COMPONENTS AND MCPI_HEADLESS_MODE)
|
||||
if(MCPI_HEADLESS_MODE)
|
||||
install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# SDK
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
install(TARGETS GLESv1_CM EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
endif()
|
||||
|
||||
# Common
|
||||
target_link_libraries(GLESv1_CM PUBLIC media-layer-headers)
|
||||
set_target_properties(GLESv1_CM PROPERTIES SOVERSION "1")
|
||||
if(TARGET GLESv1_CM)
|
||||
target_link_libraries(GLESv1_CM PUBLIC media-layer-headers)
|
||||
set_target_properties(GLESv1_CM PROPERTIES SOVERSION "1")
|
||||
# SDK
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
install(TARGETS GLESv1_CM EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
@ -7,23 +7,18 @@ set(MEDIA_LAYER_PROXY_SRC src/common/common.c src/media-layer-core.c src/GLESv1_
|
||||
if(BUILD_NATIVE_COMPONENTS)
|
||||
# Build Media Layer Proxy Client
|
||||
add_executable(media-layer-proxy-client src/client/client.cpp ${MEDIA_LAYER_PROXY_SRC})
|
||||
target_link_libraries(media-layer-proxy-client media-layer-headers reborn-util media-layer-core-real GLESv1_CM)
|
||||
target_link_libraries(media-layer-proxy-client media-layer-headers reborn-util media-layer-core GLESv1_CM)
|
||||
target_compile_definitions(media-layer-proxy-client PRIVATE -DMEDIA_LAYER_PROXY_CLIENT)
|
||||
# Install
|
||||
install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_BIN_DIR}")
|
||||
endif()
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
elseif(BUILD_ARM_COMPONENTS)
|
||||
# Build Media Layer Proxy Server
|
||||
add_library(media-layer-proxy-server SHARED src/server/server.cpp ${MEDIA_LAYER_PROXY_SRC})
|
||||
target_link_libraries(media-layer-proxy-server media-layer-headers reborn-util)
|
||||
target_compile_definitions(media-layer-proxy-server PRIVATE -DMEDIA_LAYER_PROXY_SERVER)
|
||||
set_target_properties(media-layer-proxy-server PROPERTIES OUTPUT_NAME "media-layer-core")
|
||||
add_library(media-layer-core SHARED src/server/server.cpp ${MEDIA_LAYER_PROXY_SRC} $<TARGET_OBJECTS:media-layer-extras>)
|
||||
target_link_libraries(media-layer-core media-layer-headers reborn-util)
|
||||
target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_PROXY_SERVER)
|
||||
# Install
|
||||
install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}")
|
||||
install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
# Symlink GLESv1_CM To Media Layer Proxy Server
|
||||
install_symlink("libmedia-layer-core.so" "${MCPI_LIB_DIR}/libGLESv1_CM.so.1")
|
||||
# Install
|
||||
install(TARGETS media-layer-proxy-server DESTINATION "${MCPI_LIB_DIR}")
|
||||
install(TARGETS media-layer-proxy-server EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
||||
# Create Alias Target For Linking
|
||||
add_library(media-layer-core ALIAS media-layer-proxy-server)
|
||||
set_target_properties(media-layer-proxy-server PROPERTIES EXPORT_NAME media-layer-core)
|
||||
endif()
|
||||
|
@ -65,10 +65,6 @@ static void start_media_layer_proxy_client(int read, int write) {
|
||||
} else if (ret == 0) {
|
||||
// Child Process
|
||||
|
||||
// Prepare Environment
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
|
||||
|
||||
// Prepare Arguments
|
||||
char *read_str = NULL;
|
||||
safe_asprintf(&read_str, "%i", read);
|
||||
|
@ -14,16 +14,6 @@
|
||||
#include "chat-internal.h"
|
||||
#include <mods/chat/chat.h>
|
||||
|
||||
// Run Command
|
||||
static char *run_command_proper(const char *command[], int *return_code) {
|
||||
// Prepare Environment
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
|
||||
|
||||
// Run
|
||||
return run_command(command, return_code);
|
||||
}
|
||||
|
||||
// Count Chat Windows
|
||||
static pthread_mutex_t chat_counter_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static volatile unsigned int chat_counter = 0;
|
||||
@ -44,7 +34,7 @@ static void *chat_thread(__attribute__((unused)) void *nop) {
|
||||
"--text", "Enter Chat Message:",
|
||||
NULL
|
||||
};
|
||||
char *output = run_command_proper(command, &return_code);
|
||||
char *output = run_command(command, &return_code);
|
||||
// Handle Message
|
||||
if (output != NULL) {
|
||||
// Check Return Code
|
||||
|
@ -17,10 +17,6 @@
|
||||
|
||||
// Run Command
|
||||
static char *run_command_proper(const char *command[], bool allow_empty) {
|
||||
// Prepare Environment
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
|
||||
RESET_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
|
||||
|
||||
// Run
|
||||
int return_code;
|
||||
char *output = run_command(command, &return_code);
|
||||
|
@ -31,35 +31,10 @@ build() {
|
||||
cd ../../
|
||||
}
|
||||
|
||||
# Build For ARM
|
||||
armhf_build() {
|
||||
# Use Build Dir
|
||||
if [ ! -f "build/${MODE}-armhf/build.ninja" ]; then
|
||||
./scripts/setup.sh "${MODE}" armhf
|
||||
fi
|
||||
cd "build/${MODE}-armhf"
|
||||
|
||||
# Create Prefix
|
||||
local prefix="$(cd ../../; pwd)/out/${MODE}-armhf"
|
||||
rm -rf "${prefix}"
|
||||
mkdir -p "${prefix}"
|
||||
|
||||
# Build All Components
|
||||
cmake --build .
|
||||
DESTDIR="${prefix}" cmake --install .
|
||||
|
||||
# Exit
|
||||
cd ../../
|
||||
}
|
||||
|
||||
# Variables
|
||||
MODE="$1"
|
||||
ARCH="$2"
|
||||
shift 2
|
||||
|
||||
# Build
|
||||
if [ "${ARCH}" = "armhf" ]; then
|
||||
armhf_build "${MODE}"
|
||||
else
|
||||
build "${MODE}" "${ARCH}"
|
||||
fi
|
||||
build "${MODE}" "${ARCH}"
|
||||
|
@ -19,48 +19,34 @@ setup() {
|
||||
mkdir -p "build/${MODE}-${ARCH}"
|
||||
cd "build/${MODE}-${ARCH}"
|
||||
|
||||
# Prepare
|
||||
# Server Build
|
||||
local server_mode='OFF'
|
||||
if [ "${MODE}" = "server" ]; then
|
||||
server_mode='ON'
|
||||
fi
|
||||
|
||||
# Mixed Build
|
||||
local mixed_build='ON'
|
||||
if [ "${ARCH}" = "armhf" ]; then
|
||||
mixed_build='OFF'
|
||||
fi
|
||||
|
||||
# Build ARM Components
|
||||
mkdir arm
|
||||
cd arm
|
||||
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm -DMCPI_IS_MIXED_BUILD=ON -DMCPI_SERVER_MODE="${server_mode}" "$@" ../../..
|
||||
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm -DMCPI_IS_MIXED_BUILD="${mixed_build}" -DMCPI_SERVER_MODE="${server_mode}" "$@" ../../..
|
||||
cd ../
|
||||
|
||||
# Build Native Components
|
||||
mkdir native
|
||||
cd native
|
||||
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native -DMCPI_IS_MIXED_BUILD=ON -DMCPI_SERVER_MODE="${server_mode}" "$@" ../../..
|
||||
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native -DMCPI_IS_MIXED_BUILD="${mixed_build}" -DMCPI_SERVER_MODE="${server_mode}" "$@" ../../..
|
||||
cd ../
|
||||
|
||||
# Exit
|
||||
cd ../../
|
||||
}
|
||||
|
||||
# Setup For ARM
|
||||
armhf_setup() {
|
||||
# Create Build Dir
|
||||
rm -rf "build/${MODE}-armhf"
|
||||
mkdir -p "build/${MODE}-armhf"
|
||||
cd "build/${MODE}-armhf"
|
||||
|
||||
# Prepare
|
||||
local server_mode='OFF'
|
||||
if [ "${MODE}" = "server" ]; then
|
||||
server_mode='ON'
|
||||
fi
|
||||
|
||||
# Build All Components
|
||||
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=both -DMCPI_SERVER_MODE="${server_mode}" "$@" ../..
|
||||
|
||||
# Exit
|
||||
cd ../../
|
||||
}
|
||||
|
||||
# Variables
|
||||
MODE="$1"
|
||||
ARCH="$2"
|
||||
@ -73,8 +59,4 @@ if [ "${MODE}" != "client" ] && [ "${MODE}" != "server" ]; then
|
||||
fi
|
||||
|
||||
# Setup
|
||||
if [ "${ARCH}" = "armhf" ]; then
|
||||
armhf_setup "$@"
|
||||
else
|
||||
setup "$@"
|
||||
fi
|
||||
setup "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user