prepare linux build, fix some memory leaks

This commit is contained in:
Ondřej Novák 2025-04-20 18:16:29 +02:00
parent 0fa5c48519
commit e7db30ca27
13 changed files with 133 additions and 94 deletions

View file

@ -35,23 +35,27 @@ if(WIN32)
windows/skeldal.rc
)
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_WINDOWS)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api64.lib)
set(STEAMDLL ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api64.dll)
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_WINDOWS_64)
if(STEAM_ENABLED)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api64.lib)
set(STEAMDLL ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api64.dll)
else()
# 32-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/win32/steam_api.lib)
set(STEAMDLL ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api.dll)
endif()
else()
# 32-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/win32/steam_api.lib)
set(STEAMDLL ${STEAMWORKS_SDK_DIR}redistributable_bin/win64/steam_api.dll)
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_WINDOWS_32)
set(STEAMLIB "")
set(STEAMDLL "")
endif()
target_link_libraries(skeldal ${all_libs} ${STEAMLIB})
add_custom_command(TARGET skeldal POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${STEAMDLL} $<TARGET_FILE_DIR:skeldal>
)
if(STEAMDLL)
add_custom_command(TARGET skeldal POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${STEAMDLL} $<TARGET_FILE_DIR:skeldal>)
endif()
message(STATUS "Building for Windows")
@ -65,14 +69,14 @@ elseif(UNIX AND NOT APPLE)
linux/app_start.cpp
)
target_compile_definitions(skeldal_bin PRIVATE PLATFORM_LINUX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/linux64/libsteam_api.so)
target_compile_definitions(skeldal_bin PRIVATE PLATFORM_LINUX_64)
else()
# 32-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/linux32/libsteam_api.so)
target_compile_definitions(skeldal_bin PRIVATE PLATFORM_LINUX_32)
if(STEAM_ENABLED)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/linux64/libsteam_api.so)
else()
# 32-bit
set(STEAMLIB ${STEAMWORKS_SDK_DIR}/redistributable_bin/linux32/libsteam_api.so)
endif()
endif()
add_custom_command(
TARGET skeldal_bin POST_BUILD

View file

@ -1,9 +1,10 @@
#include "achievements.h"
#include <steam/steam_api.h>
#include "error.h"
#include <string.h>
#include <sstream>
#include "achievements.h"
#include "error.h"
#include "platform.h"
#ifdef STEAM_ENABLED
#include <steam/steam_api.h>
extern "C" {
#include <libs/event.h>
@ -25,7 +26,7 @@ void steam_init()
steam_initialized = 1;
steam_available = SteamAPI_Init();
if (steam_available) {
send_message(E_ADD, E_IDLE, &run_steam_callbacks);
send_message(E_ADD, E_IDLE, &run_steam_callbacks);
SteamUserStats()->RequestUserStats(SteamUser()->GetSteamID());
} else {
steam_available = 0;
@ -57,7 +58,7 @@ int8_t set_achievement(const char *id)
} else {
return -1;
}
}
int8_t clear_achievement(const char *id)
@ -81,7 +82,7 @@ int8_t clear_achievement(const char *id)
return 0;
} else {
return -1;
}
}
}
}
@ -104,3 +105,11 @@ char *get_steam_status()
char *out = strdup(str.c_str());
return out;
}
#else
void steam_init() {}
void steam_shutdown() {}
int8_t set_achievement(const char *id) {return -1;}
int8_t clear_achievement(const char *id) {return -1;}
char is_steam_available() {return 0;}
char *get_steam_status() {return NULL;}
#endif

View file

@ -34,3 +34,7 @@ void send_log_impl(const char *format, ...) {
#endif
}
void throw_exception(const char *text) {
throw std::runtime_error(std::string("Invoked crash:") + text);
}

View file

@ -8,6 +8,7 @@ extern "C" {
void send_log_impl(const char *format, ...);
void display_error(const char *format, ...);
void throw_exception(const char *text);
#ifdef __cplusplus

View file

@ -1,14 +1,14 @@
#!/bin/bash
temp_file=$(mktemp /tmp/skeldal.XXXXXX.log)
CURDIR=`dirname "$0"`
`dirname $0`/skeldal_bin $* > "$temp_file" 2>&1
LD_LIBRARY_PATH=$CURDIR:$LD_LIBRARY_PATH "$CURDIR/skeldal_bin" $* > "$temp_file" 2>&1
exit_code=$?
if [ $exit_code -ne 0 ]; then
error_message=$(cat "$temp_file")
if command -v zenity > /dev/null; then
zenity --warning --no-markup --title="Skeldal ERROR" --text="$error_message"
elif command -v kdialog > /dev/null; then
@ -18,9 +18,11 @@ if [ $exit_code -ne 0 ]; then
elif command -v xdg-open > /dev/null; then
xdg-open "$temp_file"
sleep 5;
else
else
cat "$temp_file"
fi
fi
rm $temp_file
exit $exit_code
exit $exit_code

View file

@ -11,7 +11,6 @@
#include <stdexcept>
#include <sstream>
#include <algorithm>
#include <steam/steam_api.h>
#include <stdbool.h>
#include <thread>
#include <mutex>