Cmake Refactor

This commit is contained in:
TheBrokenRail 2022-07-02 18:14:23 -04:00
parent e506dbb1bb
commit ea4c5c77a1
24 changed files with 138 additions and 289 deletions

4
.gitmodules vendored
View File

@ -2,10 +2,10 @@
path = dependencies/libpng/src path = dependencies/libpng/src
url = https://github.com/glennrp/libpng.git url = https://github.com/glennrp/libpng.git
[submodule "dependencies/zlib/src"] [submodule "dependencies/zlib/src"]
path = dependencies/zlib/src path = dependencies/libpng/zlib/src
url = https://github.com/madler/zlib.git url = https://github.com/madler/zlib.git
[submodule "dependencies/glfw/src"] [submodule "dependencies/glfw/src"]
path = dependencies/glfw/src path = media-layer/core/dependencies/glfw/src
url = https://github.com/glfw/glfw.git url = https://github.com/glfw/glfw.git
[submodule "dependencies/zenity/src"] [submodule "dependencies/zenity/src"]
path = dependencies/zenity/src path = dependencies/zenity/src

View File

@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.16.0)
# Specify Options # Specify Options
option(MCPI_IS_MIXED_BUILD "Whether The Architecture-Independent And ARM Code Are Different Architecture" FALSE) 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(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 "both" "arm" "native") 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_OPEN_SOURCE_ONLY "Only Install Open-Source Code (Will Result In Broken Install)" FALSE)
option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE) option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE)
# Server/Headless Builds # Server/Headless Builds
@ -46,10 +46,6 @@ elseif(MCPI_BUILD_MODE STREQUAL "native")
set(USE_ARM32_TOOLCHAIN FALSE) set(USE_ARM32_TOOLCHAIN FALSE)
set(BUILD_ARM_COMPONENTS FALSE) set(BUILD_ARM_COMPONENTS FALSE)
set(BUILD_NATIVE_COMPONENTS TRUE) 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() else()
message(FATAL_ERROR "Invalid Mode") message(FATAL_ERROR "Invalid Mode")
endif() endif()
@ -67,12 +63,19 @@ endif()
# Specify Installation Paths # Specify Installation Paths
set(MCPI_INSTALL_DIR "lib/${MCPI_VARIANT_NAME}") 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_BIN_DIR "${MCPI_INSTALL_DIR}/bin")
set(MCPI_SDK_DIR "${MCPI_INSTALL_DIR}/sdk") set(MCPI_SDK_DIR "${MCPI_INSTALL_DIR}/sdk")
set(MCPI_SDK_LIB_DIR "${MCPI_SDK_DIR}/lib") set(MCPI_SDK_LIB_DIR "${MCPI_SDK_DIR}/lib")
set(MCPI_SDK_INCLUDE_DIR "${MCPI_SDK_DIR}/include") 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 # Build Mode
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")

View File

@ -1,17 +1,11 @@
project(dependencies) project(dependencies)
# ZLib (Needed By libpng)
add_subdirectory(zlib)
# LibPNG # LibPNG
add_subdirectory(libpng) add_subdirectory(libpng)
# Minecraft: Pi Edition # Minecraft: Pi Edition
if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY) if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY)
add_subdirectory(minecraft-pi) add_subdirectory(minecraft-pi)
endif() endif()
# GLFW
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
add_subdirectory(glfw)
endif()
# Zenity (Minimal Build) # Zenity (Minimal Build)
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE) if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
add_subdirectory(zenity) add_subdirectory(zenity)

View File

@ -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)

View File

@ -1,5 +1,8 @@
project(libpng) project(libpng)
# ZLib (Needed By libpng)
add_subdirectory(zlib)
# Silence Warnings # Silence Warnings
add_compile_options(-w) add_compile_options(-w)
@ -7,18 +10,9 @@ add_compile_options(-w)
# Options # Options
set(PNG_TESTS FALSE CACHE BOOL "" FORCE) set(PNG_TESTS FALSE CACHE BOOL "" FORCE)
if(BUILD_NATIVE_COMPONENTS) set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE)
set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE) set(PNG_STATIC FALSE CACHE BOOL "" FORCE)
else() set(PNG_SHARED TRUE CACHE BOOL "" FORCE)
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()
# Download # Download
set(ZLIB_LIBRARY zlibstatic) set(ZLIB_LIBRARY zlibstatic)
@ -29,28 +23,16 @@ set(CMAKE_POLICY_DEFAULT_CMP0022 NEW) # Fix Error
set(M_LIBRARY m) # No Full Paths! set(M_LIBRARY m) # No Full Paths!
add_subdirectory(src EXCLUDE_FROM_ALL) add_subdirectory(src EXCLUDE_FROM_ALL)
set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior 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 # Setup Target
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning
target_include_directories(png12 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>") set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
endif() target_include_directories(png12 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
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()
# Ensure Build # Ensure Build
if(TARGET png12) add_custom_target(png12-build ALL DEPENDS 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()
# Install # Install
if(TARGET png12) install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}") if(BUILD_ARM_COMPONENTS)
# SDK
install(TARGETS png12 zlibstatic EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") install(TARGETS png12 zlibstatic EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
endif() endif()

View File

@ -8,6 +8,8 @@ else()
target_sources(launcher PRIVATE src/client/launcher.cpp) target_sources(launcher PRIVATE src/client/launcher.cpp)
endif() endif()
target_link_libraries(launcher reborn-util) target_link_libraries(launcher reborn-util)
# RPath
set_target_properties(launcher PROPERTIES INSTALL_RPATH "$ORIGIN/lib/native")
# Install # Install
install(TARGETS launcher DESTINATION "${MCPI_INSTALL_DIR}") install(TARGETS launcher DESTINATION "${MCPI_INSTALL_DIR}")

View File

@ -15,13 +15,6 @@
#include "crash-report.h" #include "crash-report.h"
// Set Environmental Variable // 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) { static void trim(char **value) {
// Remove Trailing Colon // Remove Trailing Colon
int length = strlen(*value); int length = strlen(*value);
@ -45,19 +38,6 @@ void set_and_print_env(const char *name, char *value) {
// Set The Value // Set The Value
setenv(name, value, 1); 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 // Get Environmental Variable
static char *get_env_safe(const char *name) { 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); int result = access(name, R_OK);
if (result == 0) { if (result == 0) {
// Add To LD_PRELOAD // 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) { } else if (result == -1 && errno != 0) {
// Fail // Fail
INFO("Unable To Acesss: %s: %s", name, strerror(errno)); INFO("Unable To Acesss: %s: %s", name, strerror(errno));
@ -169,12 +149,14 @@ void pre_bootstrap(int argc, char *argv[]) {
#endif #endif
// Debug Zenity // Debug Zenity
#ifndef MCPI_HEADLESS_MODE
{ {
const char *is_debug = getenv("MCPI_DEBUG"); const char *is_debug = getenv("MCPI_DEBUG");
if (is_debug != NULL && strlen(is_debug) > 0) { if (is_debug != NULL && strlen(is_debug) > 0) {
set_and_print_env("ZENITY_DEBUG", "1"); set_and_print_env("ZENITY_DEBUG", "1");
} }
} }
#endif
// AppImage // AppImage
#ifdef MCPI_IS_APPIMAGE_BUILD #ifdef MCPI_IS_APPIMAGE_BUILD
@ -348,22 +330,17 @@ void bootstrap(int argc, char *argv[]) {
// Free Resolved Path // Free Resolved Path
free(resolved_path); free(resolved_path);
// Configure LD_LIBRARY_PATH // Configure Library Search Path
char *library_path = NULL;
{ {
// Log // Log
DEBUG("Setting Linker Search Paths..."); DEBUG("Setting Linker Search Paths...");
// Preserve // Prepare
PRESERVE_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
char *new_ld_path = NULL; char *new_ld_path = NULL;
// Add Library Directory // Add Native Library Directory
safe_asprintf(&new_ld_path, "%s/lib", binary_directory); safe_asprintf(&new_ld_path, "%s/lib/native", 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 LD_LIBRARY_PATH // 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); 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); free(new_ld_path);
} }
// Configure LD_PRELOAD // Configure MCPI's Preloaded Objects
char *preload = NULL;
{ {
// Log // Log
DEBUG("Locating Mods..."); DEBUG("Locating Mods...");
// Preserve
PRESERVE_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
char *new_ld_preload = NULL;
// ~/.minecraft-pi/mods // ~/.minecraft-pi/mods
{ {
// Get Mods Folder // Get Mods Folder
char *mods_folder = NULL; char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME")); safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME"));
// Load Mods From ./mods // Load Mods From ./mods
load(&new_ld_preload, mods_folder); load(&preload, mods_folder);
// Free Mods Folder // Free Mods Folder
free(mods_folder); free(mods_folder);
} }
@ -404,7 +392,7 @@ void bootstrap(int argc, char *argv[]) {
char *mods_folder = NULL; char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s/mods/", binary_directory); safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
// Load Mods From ./mods // Load Mods From ./mods
load(&new_ld_preload, mods_folder); load(&preload, mods_folder);
// Free Mods Folder // Free 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"); char *value = get_env_safe("LD_PRELOAD");
if (strlen(value) > 0) { 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 // Free Binary Directory
@ -430,26 +414,28 @@ void bootstrap(int argc, char *argv[]) {
// Arguments // Arguments
int argv_start = 1; // argv = &new_args[argv_start] 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 // Copy Existing Arguments
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
new_args[i + argv_start] = argv[i]; new_args[i + real_argv_start] = argv[i];
} }
// NULL-Terminator // NULL-Terminator
new_args[argv_start + argc] = NULL; new_args[real_argv_start + argc] = NULL;
// Set Executable Argument // 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 // Non-ARM Systems Need QEMU
#ifndef __ARM_ARCH #ifndef __ARM_ARCH
argv_start--; argv_start--;
new_args[argv_start] = QEMU_BINARY; 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 #endif
// Run // Run

View File

@ -73,6 +73,7 @@ static void duplicate_mcpi_executable(const char *original_path, char *new_path)
"--remove-needed", "libX11.so.6", \ "--remove-needed", "libX11.so.6", \
"--remove-needed", "libEGL.so", \ "--remove-needed", "libEGL.so", \
"--replace-needed", "libGLESv2.so", "libGLESv1_CM.so.1", \ "--replace-needed", "libGLESv2.so", "libGLESv1_CM.so.1", \
"--replace-needed", "libSDL-1.2.so.0", "libmedia-layer-core.so", \
new_path, \ new_path, \
NULL \ NULL \
}; \ }; \

View File

@ -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) configure_file(include/libreborn/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/libreborn/config.h" ESCAPE_QUOTES @ONLY)
# Util # 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( target_include_directories(
reborn-util reborn-util
PUBLIC PUBLIC
@ -13,6 +13,14 @@ target_include_directories(
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<INSTALL_INTERFACE:${MCPI_SDK_INCLUDE_DIR}/libreborn>" "$<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 # Patch
if(BUILD_ARM_COMPONENTS) if(BUILD_ARM_COMPONENTS)
@ -23,7 +31,4 @@ if(BUILD_ARM_COMPONENTS)
install(TARGETS reborn-patch DESTINATION "${MCPI_LIB_DIR}") install(TARGETS reborn-patch DESTINATION "${MCPI_LIB_DIR}")
# SDK # SDK
install(TARGETS reborn-patch EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") 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() endif()

View File

@ -32,17 +32,6 @@
\ \
__attribute__((__used__)) return_type name args __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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -4,6 +4,12 @@
// Safe execvpe() // Safe execvpe()
__attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]) { __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); int ret = execvpe(argv[0], (char *const *) argv, (char *const *) envp);
if (ret == -1) { if (ret == -1) {
ERR("Unable To Execute Program: %s: %s", argv[0], strerror(errno)); ERR("Unable To Execute Program: %s: %s", argv[0], strerror(errno));

View File

@ -1,9 +1,5 @@
project(media-layer) 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 Headers
add_library(media-layer-headers INTERFACE) add_library(media-layer-headers INTERFACE)
target_include_directories( target_include_directories(
@ -21,13 +17,15 @@ endif()
# Add GLESv1_CM Stubs Or Compatibility Layer # Add GLESv1_CM Stubs Or Compatibility Layer
add_subdirectory(gles) add_subdirectory(gles)
# Add Extras
add_subdirectory(extras)
# Add Core # 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 # Add Proxy
if(MCPI_USE_MEDIA_LAYER_PROXY) if(MCPI_USE_MEDIA_LAYER_PROXY)
add_subdirectory(proxy) add_subdirectory(proxy)
endif() endif()
# Add Extras
add_subdirectory(extras)

View File

@ -1,41 +1,25 @@
project(media-layer-core) project(media-layer-core)
# Dependencies
add_subdirectory(dependencies)
# Configuration # 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) if(NOT MCPI_HEADLESS_MODE)
list(APPEND CORE_SRC src/audio/api.cpp src/audio/engine.c src/audio/file.cpp) list(APPEND CORE_SRC src/audio/api.cpp src/audio/engine.c src/audio/file.cpp)
endif() endif()
# Build # Build
if(MCPI_USE_MEDIA_LAYER_PROXY AND BUILD_NATIVE_COMPONENTS) add_library(media-layer-core SHARED ${CORE_SRC}) # Dependencies Are Setup Later
# Build Media Layer Core Natively And Use Proxy # Install
add_library(media-layer-core-real OBJECT ${CORE_SRC}) # Dependencies Are Setup Later install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}")
endif() install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
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()
# Configure Media Layer Core If Built # Link
if(TARGET media-layer-core-real) target_link_libraries(media-layer-core PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC pthread PUBLIC dl)
# Link if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(media-layer-core-real PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC pthread PUBLIC dl)
if(NOT MCPI_HEADLESS_MODE)
# OpenAL # OpenAL
find_library(OPENAL_LIBRARY NAMES openal REQUIRED) find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
# Link # Link
target_link_libraries(media-layer-core-real PRIVATE png12_static PRIVATE "${OPENAL_LIBRARY}" PRIVATE m PUBLIC GLESv1_CM PRIVATE glfw) target_link_libraries(media-layer-core PRIVATE png12 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")
endif() endif()

View File

@ -1,11 +1,5 @@
project(media-layer-extras) project(media-layer-extras)
if(BUILD_ARM_COMPONENTS) # Build
# Add Source To Media Core add_library(media-layer-extras OBJECT src/SDL.c)
if(TARGET media-layer-core-real) target_link_libraries(media-layer-extras media-layer-headers reborn-util)
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()

View File

@ -1,39 +1,32 @@
project(media-layer-stubs) project(media-layer-stubs)
# Stubs Only Needed For ARM # 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 # 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) 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) 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() else()
set(GLES_SRC src/passthrough.c) set(GLES_SRC src/passthrough.c)
endif() 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) target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m)
# Install # Install
if(GLES1_LINK_MODE STREQUAL "SHARED")
install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}") install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
endif() elseif(BUILD_ARM_COMPONENTS)
else()
# Add GLESv1_CM Stubs For Linking # Add GLESv1_CM Stubs For Linking
add_library(GLESv1_CM SHARED src/stubs.c) add_library(GLESv1_CM SHARED src/stubs.c)
# Install Fake GLESv1_CM Stubs In Server Mode # 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}") install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
endif() endif()
endif() endif()
# SDK
if(BUILD_ARM_COMPONENTS)
install(TARGETS GLESv1_CM EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
endif()
# Common # Common
target_link_libraries(GLESv1_CM PUBLIC media-layer-headers) if(TARGET GLESv1_CM)
set_target_properties(GLESv1_CM PROPERTIES SOVERSION "1") 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()

View File

@ -7,23 +7,18 @@ set(MEDIA_LAYER_PROXY_SRC src/common/common.c src/media-layer-core.c src/GLESv1_
if(BUILD_NATIVE_COMPONENTS) if(BUILD_NATIVE_COMPONENTS)
# Build Media Layer Proxy Client # Build Media Layer Proxy Client
add_executable(media-layer-proxy-client src/client/client.cpp ${MEDIA_LAYER_PROXY_SRC}) 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) target_compile_definitions(media-layer-proxy-client PRIVATE -DMEDIA_LAYER_PROXY_CLIENT)
# Install # Install
install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_BIN_DIR}") install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_BIN_DIR}")
endif() elseif(BUILD_ARM_COMPONENTS)
if(BUILD_ARM_COMPONENTS)
# Build Media Layer Proxy Server # Build Media Layer Proxy Server
add_library(media-layer-proxy-server SHARED src/server/server.cpp ${MEDIA_LAYER_PROXY_SRC}) add_library(media-layer-core SHARED src/server/server.cpp ${MEDIA_LAYER_PROXY_SRC} $<TARGET_OBJECTS:media-layer-extras>)
target_link_libraries(media-layer-proxy-server media-layer-headers reborn-util) target_link_libraries(media-layer-core media-layer-headers reborn-util)
target_compile_definitions(media-layer-proxy-server PRIVATE -DMEDIA_LAYER_PROXY_SERVER) target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_PROXY_SERVER)
set_target_properties(media-layer-proxy-server PROPERTIES OUTPUT_NAME "media-layer-core") # 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 # Symlink GLESv1_CM To Media Layer Proxy Server
install_symlink("libmedia-layer-core.so" "${MCPI_LIB_DIR}/libGLESv1_CM.so.1") 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() endif()

View File

@ -65,10 +65,6 @@ static void start_media_layer_proxy_client(int read, int write) {
} else if (ret == 0) { } else if (ret == 0) {
// Child Process // Child Process
// Prepare Environment
RESET_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
RESET_ENVIRONMENTAL_VARIABLE("LD_PRELOAD");
// Prepare Arguments // Prepare Arguments
char *read_str = NULL; char *read_str = NULL;
safe_asprintf(&read_str, "%i", read); safe_asprintf(&read_str, "%i", read);

View File

@ -14,16 +14,6 @@
#include "chat-internal.h" #include "chat-internal.h"
#include <mods/chat/chat.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 // Count Chat Windows
static pthread_mutex_t chat_counter_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t chat_counter_lock = PTHREAD_MUTEX_INITIALIZER;
static volatile unsigned int chat_counter = 0; static volatile unsigned int chat_counter = 0;
@ -44,7 +34,7 @@ static void *chat_thread(__attribute__((unused)) void *nop) {
"--text", "Enter Chat Message:", "--text", "Enter Chat Message:",
NULL NULL
}; };
char *output = run_command_proper(command, &return_code); char *output = run_command(command, &return_code);
// Handle Message // Handle Message
if (output != NULL) { if (output != NULL) {
// Check Return Code // Check Return Code

View File

@ -17,10 +17,6 @@
// Run Command // Run Command
static char *run_command_proper(const char *command[], bool allow_empty) { 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 // Run
int return_code; int return_code;
char *output = run_command(command, &return_code); char *output = run_command(command, &return_code);

View File

@ -31,35 +31,10 @@ build() {
cd ../../ 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 # Variables
MODE="$1" MODE="$1"
ARCH="$2" ARCH="$2"
shift 2 shift 2
# Build # Build
if [ "${ARCH}" = "armhf" ]; then build "${MODE}" "${ARCH}"
armhf_build "${MODE}"
else
build "${MODE}" "${ARCH}"
fi

View File

@ -19,48 +19,34 @@ setup() {
mkdir -p "build/${MODE}-${ARCH}" mkdir -p "build/${MODE}-${ARCH}"
cd "build/${MODE}-${ARCH}" cd "build/${MODE}-${ARCH}"
# Prepare # Server Build
local server_mode='OFF' local server_mode='OFF'
if [ "${MODE}" = "server" ]; then if [ "${MODE}" = "server" ]; then
server_mode='ON' server_mode='ON'
fi fi
# Mixed Build
local mixed_build='ON'
if [ "${ARCH}" = "armhf" ]; then
mixed_build='OFF'
fi
# Build ARM Components # Build ARM Components
mkdir arm mkdir arm
cd 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 ../ cd ../
# Build Native Components # Build Native Components
mkdir native mkdir native
cd 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 ../ cd ../
# Exit # Exit
cd ../../ 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 # Variables
MODE="$1" MODE="$1"
ARCH="$2" ARCH="$2"
@ -73,8 +59,4 @@ if [ "${MODE}" != "client" ] && [ "${MODE}" != "server" ]; then
fi fi
# Setup # Setup
if [ "${ARCH}" = "armhf" ]; then setup "$@"
armhf_setup "$@"
else
setup "$@"
fi