Skip to content

Commit

Permalink
add FreeBSD build target
Browse files Browse the repository at this point in the history
Signed-off-by: Lucca Jiménez Könings <[email protected]>
  • Loading branch information
jimkoen committed Jan 19, 2024
1 parent 9915c83 commit 924efe4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ We only allow building unmodified (original) source code for public use. `master

## Supported Operating Systems

The code itself supports (latest stable) Linux and Windows. In terms of actual build support, for now we usually only distribute Windows binaries and Linux. For any other distro or OS, you just have to find the same libraries listed in [Runtime Dependencies](#runtime-dependencies) further down the page, and it should build fine.
The code itself supports (latest stable) Linux, Windows andcurrently supported production releases of FreeBSD. In terms of actual build support, for now we usually only distribute Windows binaries and Linux. For any other distro or OS, you just have to find the same libraries listed in [Runtime Dependencies](#runtime-dependencies) further down the page, and it should build fine.

Recommended compilers: MSVC, GCC, CLANG.

Expand Down Expand Up @@ -72,6 +72,14 @@ You can build on **Windows, Linux** or other platforms by following these steps:

When you make changes to the code, you only have to run step 4 again.

It's a similar situation on FreeBSD, although build dependencies can be universally installed from ports via pkg:
```
pkg install git cmake-core zip bash devel/ninja devel/pkgconf lua53
```
Then follow the linux build instructions beginning from step 3. **Note**: Running the initial cmake command will compile vcpkg from source, as vcpkg has no native FreeBSD port - this may take some time.

**Note**: On systems with a single logical CPU core, `make` may fail to build the server when using the `--parallel` option when calling CMake.

### Runtime Dependencies

These are needed to *run* the server.
Expand Down
9 changes: 8 additions & 1 deletion include/Compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
#include <termios.h>
#include <unistd.h>
char _getch();
#endif // unix
#endif // linux

#ifdef BEAMMP_FREEBSD
#include <errno.h>
#include <termios.h>
#include <unistd.h>
char _getch();
#endif // freebsd

// ======================= APPLE ========================

Expand Down
6 changes: 4 additions & 2 deletions include/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
// one of BEAMMP_{WINDOWS,LINUX,APPLE} will be set at the end of this

// clang-format off
#if !defined(BEAMMP_WINDOWS) && !defined(BEAMMP_UNIX) && !defined(BEAMMP_APPLE)
#if !defined(BEAMMP_WINDOWS) && !defined(BEAMMP_UNIX) && !defined(BEAMMP_APPLE) && !defined(BEAMMP_FREEBSD)
#if defined(_WIN32) || defined(__CYGWIN__)
#define BEAMMP_WINDOWS
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__unix__) || defined(__unix) || defined(unix)
#elif defined(__linux__) || defined(__linux) || defined(linux)
#define BEAMMP_LINUX
#elif defined(__FreeBSD__)
#define BEAMMP_FREEBSD
#elif defined(__APPLE__) || defined(__MACH__)
#define BEAMMP_APPLE
#else
Expand Down
9 changes: 8 additions & 1 deletion src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ void RegisterThread(const std::string& str) {
#elif defined(BEAMMP_APPLE)
ThreadId = std::to_string(getpid()); // todo: research if 'getpid()' is a valid, posix compliant alternative to 'gettid()'
#elif defined(BEAMMP_LINUX)
ThreadId = std::to_string(gettid());
ThreadId = std::to_string(gettid()); //todo: 'gettid()' may not produce the inted behavior, as tid's can be the same as pid's when the calling process only has one thread (according to this StackOverflow answer: https://stackoverflow.com/a/8787888). gettid is also a linux specific call (not in posix standard). consider to refactor this in a posix compliant way (maybe 'pthread_self()'?).
#elif defined(BEAMMP_FREEBSD)
ThreadId = std::to_string(getpid());
#endif
if (Application::Settings.DebugModeEnabled) {
std::ofstream ThreadFile(".Threads.log", std::ios::app);
Expand All @@ -289,6 +291,11 @@ TEST_CASE("RegisterThread") {
CHECK(threadNameMap.at(std::this_thread::get_id()) == "MyThread");
}

#ifdef BEAMMP_FREEBSD
#undef major
#undef minor
#endif

Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
: major(major)
, minor(minor)
Expand Down

0 comments on commit 924efe4

Please sign in to comment.