1
0
mirror of synced 2024-11-24 15:50:16 +01:00

build: Added support patches for FreeBSD (#1584)

This pull request fixes build on FreeBSD. The changes are conditioned
with `#if defined(__FreeBSD__)` preprocessor macro and they should not
affect build for other operating systems.

---------

Co-authored-by: Nik <werwolv98@gmail.com>
Co-authored-by: iTrooz <hey@itrooz.fr>
This commit is contained in:
Nobutaka Mantani 2024-03-22 05:31:17 +09:00 committed by GitHub
parent 61b9c0970b
commit 05ffcab911
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 7 deletions

View File

@ -70,6 +70,9 @@ macro(detectOS)
add_compile_definitions(OS_WEB) add_compile_definitions(OS_WEB)
elseif (UNIX AND NOT APPLE) elseif (UNIX AND NOT APPLE)
add_compile_definitions(OS_LINUX) add_compile_definitions(OS_LINUX)
if (BSD AND BSD STREQUAL "FreeBSD")
add_compile_definitions(OS_FREEBSD)
endif()
include(GNUInstallDirs) include(GNUInstallDirs)
if(IMHEX_PLUGINS_IN_SHARE) if(IMHEX_PLUGINS_IN_SHARE)

View File

@ -663,7 +663,11 @@ namespace hex {
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
return "Windows"; return "Windows";
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
return "Linux"; #if defined(OS_FREEBSD)
return "FreeBSD";
#else
return "Linux";
#endif
#elif defined(OS_MACOS) #elif defined(OS_MACOS)
return "macOS"; return "macOS";
#elif defined(OS_WEB) #elif defined(OS_WEB)

View File

@ -13,7 +13,11 @@
#include <shellapi.h> #include <shellapi.h>
#elif defined(OS_LINUX) || defined(OS_WEB) #elif defined(OS_LINUX) || defined(OS_WEB)
#include <xdg.hpp> #include <xdg.hpp>
# if defined(OS_FREEBSD)
#include <sys/syslimits.h>
# else
#include <limits.h> #include <limits.h>
# endif
#endif #endif
#if defined(OS_WEB) #if defined(OS_WEB)

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#if defined(OS_WINDOWS) || defined (OS_LINUX) #if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD))
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/api/localization_manager.hpp> #include <hex/api/localization_manager.hpp>

View File

@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Provider::add<MemoryFileProvider>(false); ContentRegistry::Provider::add<MemoryFileProvider>(false);
ContentRegistry::Provider::add<ViewProvider>(false); ContentRegistry::Provider::add<ViewProvider>(false);
#if defined(OS_WINDOWS) ||defined (OS_LINUX) #if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD))
ContentRegistry::Provider::add<ProcessMemoryProvider>(); ContentRegistry::Provider::add<ProcessMemoryProvider>();
#endif #endif

View File

@ -28,7 +28,9 @@
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <linux/fs.h> #if !defined(OS_FREEBSD)
#include <linux/fs.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
@ -41,8 +43,11 @@
#include <sys/disk.h> #include <sys/disk.h>
#endif #endif
#if defined(OS_LINUX) #if defined(OS_LINUX) && !defined(OS_FREEBSD)
#define lseek lseek64 #define lseek lseek64
#elif defined(OS_FREEBSD)
#include <sys/disk.h>
#define DEFAULT_SECTOR_SIZE 512
#endif #endif
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
@ -83,6 +88,12 @@ namespace hex::plugin::builtin {
return -1; return -1;
return 0; return 0;
} }
#elif defined(OS_FREEBSD) && defined(DIOCGSECTORSIZE)
int blkdev_get_sector_size(int fd, int *sector_size) {
if (ioctl(fd, DIOCGSECTORSIZE, sector_size) < 0)
return -1;
return 0;
}
#else #else
int blkdev_get_sector_size(int fd, int *sector_size) { int blkdev_get_sector_size(int fd, int *sector_size) {
(void)fd; (void)fd;
@ -97,6 +108,12 @@ namespace hex::plugin::builtin {
return -1; return -1;
return 0; return 0;
} }
#elif defined(OS_FREEBSD) && defined(DIOCGMEDIASIZE)
int blkdev_get_size(int fd, u64 *bytes) {
if (ioctl(fd, DIOCGMEDIASIZE, bytes) < 0)
return -1;
return 0;
}
#else #else
int blkdev_get_size(int fd, u64 *bytes) { int blkdev_get_size(int fd, u64 *bytes) {
struct stat st; struct stat st;

View File

@ -1,4 +1,4 @@
#if defined(OS_WINDOWS) || defined (OS_LINUX) #if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD))
#include <content/providers/process_memory_provider.hpp> #include <content/providers/process_memory_provider.hpp>