cleanup
This commit is contained in:
parent
e3ffcb02c2
commit
16ac661643
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# Build the LCPU addon for the reccomended environment
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
|
||||||
|
cmake -Wno-dev -S native -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
|
ninja -C build
|
||||||
|
|
||||||
|
[[ ! -d ''../../lua/bin' ]] && {
|
||||||
|
mkdir -p ../../lua/bin
|
||||||
|
}
|
||||||
|
|
||||||
|
cp -v build/projects/lcpu/*.dll ../../lua/bin
|
|
@ -1,10 +1,3 @@
|
||||||
-- skeleton load file to get gmod to recognize this as an addon
|
-- skeleton load file to get gmod to recognize this as an addon
|
||||||
-- this will contain files later on in life.
|
-- this will contain files later on in life.
|
||||||
|
AddCSLuaFile()
|
||||||
print("hello world?")
|
|
||||||
|
|
||||||
-- detect if wiremod is installed
|
|
||||||
if not istable(WireLib) then
|
|
||||||
print("[LCPU] we need wiremod..")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,31 +1,4 @@
|
||||||
|
include(./gmod_headers.cmake)
|
||||||
|
|
||||||
add_library(gmod_headers INTERFACE)
|
|
||||||
target_include_directories(gmod_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gmod_headers/include)
|
|
||||||
|
|
||||||
# Originally from facepunch cmake build system, modified to be slightly less painful
|
|
||||||
function(set_gmod_suffix_prefix library)
|
|
||||||
set_target_properties(${library} PROPERTIES PREFIX "gmsv_")
|
|
||||||
if(APPLE)
|
|
||||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_osx.dll")
|
|
||||||
else()
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_osx64.dll")
|
|
||||||
endif()
|
|
||||||
elseif(UNIX)
|
|
||||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_linux.dll")
|
|
||||||
else()
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_linux64.dll")
|
|
||||||
endif()
|
|
||||||
elseif(WIN32)
|
|
||||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_win32.dll")
|
|
||||||
else()
|
|
||||||
set_target_properties(${library} PROPERTIES SUFFIX "_win64.dll")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
add_library(lcpu_native SHARED
|
add_library(lcpu_native SHARED
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
add_library(gmod_headers INTERFACE)
|
||||||
|
target_include_directories(gmod_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gmod_headers/include)
|
||||||
|
|
||||||
|
# Originally from facepunch cmake build system, modified to be slightly less painful
|
||||||
|
function(set_gmod_suffix_prefix library)
|
||||||
|
set_target_properties(${library} PROPERTIES PREFIX "gmsv_")
|
||||||
|
if(APPLE)
|
||||||
|
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_osx.dll")
|
||||||
|
else()
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_osx64.dll")
|
||||||
|
endif()
|
||||||
|
elseif(UNIX)
|
||||||
|
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_linux.dll")
|
||||||
|
else()
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_linux64.dll")
|
||||||
|
endif()
|
||||||
|
elseif(WIN32)
|
||||||
|
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_win32.dll")
|
||||||
|
else()
|
||||||
|
set_target_properties(${library} PROPERTIES SUFFIX "_win64.dll")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
|
@ -1,10 +1,13 @@
|
||||||
#include "SourceSink.hpp"
|
#include "SourceSink.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <lucore/Assert.hpp>
|
||||||
#include <lucore/Library.hpp>
|
#include <lucore/Library.hpp>
|
||||||
#include <lucore/Types.hpp>
|
#include <lucore/Types.hpp>
|
||||||
|
|
||||||
// The old non-beta branch of GMod on Linux has multiple tier0 libraries for client and server.
|
// The old non-beta branch of GMod on Linux has multiple tier0 libraries for client and server.
|
||||||
// This compatibility define allows to support that case (for now).
|
// This compatibility define allows to support that case (for now). Once this define is removed,
|
||||||
|
// the old codepath can be totally removed.
|
||||||
#define LCPU_SUPPORT_OLD_GMOD
|
#define LCPU_SUPPORT_OLD_GMOD
|
||||||
|
|
||||||
namespace tier0 {
|
namespace tier0 {
|
||||||
|
@ -14,6 +17,44 @@ namespace tier0 {
|
||||||
using Msg_t = void (*)(const char*, ...);
|
using Msg_t = void (*)(const char*, ...);
|
||||||
Msg_t Msg {};
|
Msg_t Msg {};
|
||||||
|
|
||||||
|
bool OpenLibrary() {
|
||||||
|
#ifdef LCPU_SUPPORT_OLD_GMOD
|
||||||
|
constexpr static std::string_view tier0_libraries[] {
|
||||||
|
#ifdef __linux__
|
||||||
|
"tier0_srv",
|
||||||
|
#endif
|
||||||
|
"tier0"
|
||||||
|
};
|
||||||
|
|
||||||
|
for(auto lib : tier0_libraries) {
|
||||||
|
if(lucore::Library::Loaded(lib)) {
|
||||||
|
// Found the correct tier0 library to open; use that.
|
||||||
|
tier0::library = lucore::Library::OpenExisting(lib);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// The x86-64 branch of GMod, including the 32-bit binaries in the branch,
|
||||||
|
// have a single tier0 library, which makes the codepath much simpler.
|
||||||
|
// Hopefully I can switch to this path at some point.
|
||||||
|
tier0::library = lucore::Library::OpenExisting("tier0");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(tier0::library == nullptr)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GrabSymbols() {
|
||||||
|
#define GRAB_SYMBOL(name, T) \
|
||||||
|
name = library->Symbol<T>(#name); \
|
||||||
|
if(name == nullptr) \
|
||||||
|
return false;
|
||||||
|
GRAB_SYMBOL(Msg, Msg_t);
|
||||||
|
#undef GRAB_SYMBOL
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tier0
|
} // namespace tier0
|
||||||
|
|
||||||
namespace lcpu {
|
namespace lcpu {
|
||||||
|
@ -24,29 +65,17 @@ namespace lcpu {
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceSink::SourceSink() {
|
SourceSink::SourceSink() {
|
||||||
#ifdef LCPU_SUPPORT_OLD_GMOD
|
if(!tier0::OpenLibrary()) {
|
||||||
constexpr static std::string_view tier0_libraries[] {
|
std::printf("Tier0 could not be opened\n");
|
||||||
#ifdef __linux__
|
std::quick_exit(10);
|
||||||
"tier0_srv"
|
|
||||||
#endif
|
|
||||||
"tier0"
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto lib : tier0_libraries) {
|
|
||||||
if(lucore::Library::Loaded(lib)) {
|
|
||||||
// Found the correct tier0 library to open; use that.
|
|
||||||
tier0::library = lucore::Library::Open(lib);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// The x86-64 branch of GMod, including the 32-bit binaries in the branch,
|
|
||||||
// have a single tier0 library, which makes the codepath much simpler.
|
|
||||||
tier0::library = lucore::Library::Open("tier0");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GRAB_SYMBOL(name, T) tier0::name = tier0::library->Symbol<T>(#name);
|
// TODO: A bit nicer of an error message?
|
||||||
GRAB_SYMBOL(Msg, tier0::Msg_t);
|
// Explain *what* to do if you see this message.
|
||||||
|
if(!tier0::GrabSymbols()) {
|
||||||
|
std::printf("Tier0 symbols could not be grabbed\n");
|
||||||
|
std::quick_exit(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceSink::~SourceSink() {
|
SourceSink::~SourceSink() {
|
||||||
|
|
|
@ -4,10 +4,16 @@
|
||||||
|
|
||||||
#include <lucore/Assert.hpp>
|
#include <lucore/Assert.hpp>
|
||||||
|
|
||||||
|
LUA_FUNCTION(lcpu_native_test) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
GMOD_MODULE_OPEN() {
|
GMOD_MODULE_OPEN() {
|
||||||
lucore::Logger::The().AttachSink(lcpu::SourceSink::The());
|
lucore::Logger::The().AttachSink(lcpu::SourceSink::The());
|
||||||
|
|
||||||
lucore::LogInfo("LCPU Native Module loading");
|
lucore::LogInfo("LCPU Native Module loading");
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace lucore {
|
namespace lucore {
|
||||||
|
@ -5,8 +7,8 @@ namespace lucore {
|
||||||
struct Library {
|
struct Library {
|
||||||
using Handle = void*;
|
using Handle = void*;
|
||||||
|
|
||||||
/// Create a new library instance.
|
/// Open an already loaded library
|
||||||
static Library* Open(std::string_view dllname);
|
static Library* OpenExisting(std::string_view dllname);
|
||||||
|
|
||||||
/// Query if [dllname] is loaded in the process.
|
/// Query if [dllname] is loaded in the process.
|
||||||
static bool Loaded(std::string_view dllname);
|
static bool Loaded(std::string_view dllname);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! Logging utilities for Lucore
|
//! Logging utilities for Lucore
|
||||||
//! Using Standard C++ <format>
|
//! Using Standard C++ <format>
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <lucore/Logger.hpp>
|
#include <lucore/Logger.hpp>
|
||||||
|
|
||||||
namespace lucore {
|
namespace lucore {
|
||||||
|
|
|
@ -16,8 +16,11 @@ namespace lucore {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Library* Library::Open(std::string_view dllname) {
|
Library* Library::OpenExisting(std::string_view dllname) {
|
||||||
return new Library(detail::OsOpenLibrary(FormatLibraryName(dllname).c_str()));
|
auto name = FormatLibraryName(dllname);
|
||||||
|
if(!detail::OsLibraryLoaded(name.c_str()))
|
||||||
|
return nullptr;
|
||||||
|
return new Library(detail::OsOpenLibrary(name.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Library::Loaded(std::string_view dllname) {
|
bool Library::Loaded(std::string_view dllname) {
|
||||||
|
|
Loading…
Reference in New Issue