From 14e71b09ef5aa4d0609a0fa1ff3b5d07d7f4a6f9 Mon Sep 17 00:00:00 2001 From: hayzamjs Date: Thu, 6 Nov 2025 00:59:18 +0530 Subject: [PATCH] feat(platform): add FreeBSD platform support --- CMakeLists.txt | 8 ++++---- cmake/ksutil.cmake | 24 ++++++++++++++++++++++++ src/include/libks/ks_platform.h | 6 +++++- src/include/libks/ks_types.h | 4 ++++ src/ks_json_check.c | 6 ++++++ src/ks_thread.c | 2 ++ 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0facfe4..5e030162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,6 @@ option(WITH_PACKAGING "Enable packaging" ON) # Must include cotire before anything else for auto pch setup #include(cmake/cotire.cmake) -# Load our common utility api and setup the platfomrm and build -include(cmake/ksutil.cmake) -ksutil_setup_platform() - # Find stuff we need for packaging on UNIX if(KS_PLAT_LIN AND WITH_PACKAGING) find_package(Git) @@ -46,6 +42,10 @@ endif() project(LibKS2 VERSION 2.0.8 LANGUAGES C CXX) message("LibKS2 Version ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") +# Load our common utility api and setup the platfomrm and build +include(cmake/ksutil.cmake) +ksutil_setup_platform() + # Set package version set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) diff --git a/cmake/ksutil.cmake b/cmake/ksutil.cmake index a82c6398..516fd092 100644 --- a/cmake/ksutil.cmake +++ b/cmake/ksutil.cmake @@ -130,6 +130,30 @@ macro(ksutil_setup_platform) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + message("Platform is FreeBSD") + set(KS_PLAT_FBSD 1 CACHE INTERNAL "Platform definition" FORCE) + set(CMAKE_POSITION_INDEPENDENT_CODE YES) + + add_compile_options("$<$:-O2>") + add_compile_options("$<$:-g>") + + add_compile_options("$<$:-O0>") + add_compile_options("$<$:-g>") + add_compile_options("$<$:-DKS_BUILD_DEBUG=1>") + + add_compile_options("$<$:-O0>") + add_compile_options("$<$:-g>") + add_compile_options("$<$:-fsanitize=address>") + add_compile_options("$<$:-DKS_BUILD_DEBUG=1>") + + add_definitions("-DKS_PLAT_BSD=1") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") + + if (NOT CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE INTERNAL "Prefix prepended to install directories" FORCE) + set(CMAKE_PREFIX_PATH "/usr/local" CACHE INTERNAL "Prefix search path" FORCE) + endif() else() message("Platform is linux") set(KS_PLAT_LIN 1 CACHE INTERNAL "Platform definition" FORCE) diff --git a/src/include/libks/ks_platform.h b/src/include/libks/ks_platform.h index dfb8ede8..4d0c8da7 100644 --- a/src/include/libks/ks_platform.h +++ b/src/include/libks/ks_platform.h @@ -25,7 +25,7 @@ KS_BEGIN_EXTERN_C -#if !defined(KS_PLAT_LIN) && !defined(KS_PLAT_WIN) && !defined(KS_PLAT_MAC) +#if !defined(KS_PLAT_LIN) && !defined(KS_PLAT_WIN) && !defined(KS_PLAT_MAC) && !defined(KS_PLAT_FBSD) #ifdef __linux__ #define KS_PLAT_LIN #else @@ -34,6 +34,10 @@ KS_BEGIN_EXTERN_C #else #ifdef __APPLE__ #define KS_PLAT_MAC +#else +#ifdef __FreeBSD__ +#define KS_PLAT_FBSD +#endif #endif #endif #endif diff --git a/src/include/libks/ks_types.h b/src/include/libks/ks_types.h index 3480262b..f4952cb4 100644 --- a/src/include/libks/ks_types.h +++ b/src/include/libks/ks_types.h @@ -161,7 +161,11 @@ KS_BEGIN_EXTERN_C #include typedef UUID ks_uuid_t; #else + #ifdef KS_PLAT_FBSD + #include + #else #include + #endif /* Use a structure rather then uuids char array, that way * we can return it by value*/ diff --git a/src/ks_json_check.c b/src/ks_json_check.c index 3861b0a8..e3b200f0 100644 --- a/src/ks_json_check.c +++ b/src/ks_json_check.c @@ -23,11 +23,17 @@ * */ #include "libks/ks.h" + #ifndef KS_PLAT_WIN +#ifdef KS_PLAT_FBSD +#include +#else #include #endif +#endif #include "cJSON/cJSON.h" + /* todo move util functions to ks_utils.c */ /*! diff --git a/src/ks_thread.c b/src/ks_thread.c index d4c1e707..d040a8e4 100644 --- a/src/ks_thread.c +++ b/src/ks_thread.c @@ -76,6 +76,8 @@ KS_DECLARE(ks_pid_t) ks_thread_self_id(void) return GetCurrentThreadId(); #elif defined(KS_PLAT_LIN) return syscall(SYS_gettid); +#elif defined(KS_PLAT_FBSD) + return pthread_getthreadid_np(); #elif defined(KS_PLAT_MAC) uint64_t tid; int r = pthread_threadid_np(NULL, &tid);