Initial commit

This commit is contained in:
MechSlayer 2025-09-05 04:01:27 +02:00
commit d1a39262d8
6 changed files with 390 additions and 0 deletions

View file

@ -0,0 +1,72 @@
# Module
set(MODULE_NAME "DrangPlatform")
function(collect_platform_sources output_var source_dir)
# Get all source files recursively
file(GLOB_RECURSE all_sources
"${source_dir}/*.c"
"${source_dir}/*.cpp"
"${source_dir}/*.cc"
"${source_dir}/*.cxx"
"${source_dir}/*.h"
"${source_dir}/*.hpp"
)
# Define platform directories to exclude based on current platform
set(exclude_patterns)
if(WIN32)
list(APPEND exclude_patterns "linux/" "macos/" "unix/")
elseif(UNIX AND NOT APPLE)
list(APPEND exclude_patterns "win32/" "windows/" "macos/")
elseif(APPLE)
list(APPEND exclude_patterns "win32/" "windows/" "linux/")
endif()
# Filter out sources from excluded platform directories
set(filtered_sources)
foreach(source ${all_sources})
set(exclude_file FALSE)
# Check if source is in any excluded platform directory
foreach(pattern ${exclude_patterns})
string(FIND "${source}" "/${pattern}" found_pos)
if(found_pos GREATER -1)
set(exclude_file TRUE)
break()
endif()
endforeach()
# Add to filtered list if not excluded
if(NOT exclude_file)
list(APPEND filtered_sources "${source}")
endif()
endforeach()
# Return the filtered list
set(${output_var} ${filtered_sources} PARENT_SCOPE)
endfunction()
collect_platform_sources(MODULE_PRIVATE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source")
collect_platform_sources(MODULE_PUBLIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Include")
set(MODULE_FILES ${MODULE_PRIVATE_FILES} ${MODULE_PUBLIC_FILES})
if(${BUILD_SHARED_LIBS})
add_library(${MODULE_NAME} SHARED ${MODULE_FILES})
target_compile_definitions(${MODULE_NAME} PRIVATE DRANG_PLATFORM_EXPORT=1)
else()
add_library(${MODULE_NAME} STATIC ${MODULE_FILES})
target_compile_definitions(${MODULE_NAME} PRIVATE DRANG_PLATFORM_STATIC=1)
endif()
if(UNIX)
target_compile_definitions(${MODULE_NAME} PRIVATE _GNU_SOURCE=1)
endif()
set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C)
target_include_directories(${MODULE_NAME}
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include ${CMAKE_CURRENT_SOURCE_DIR}/Source)
target_link_libraries(${MODULE_NAME} PRIVATE mimalloc-static)

View file

@ -0,0 +1,51 @@
#pragma once
#if !DRANG_PLATFORM_STATIC
# if DRANG_PLATFORM_EXPORT
# ifdef _WIN32
# define DRANG_API __declspec(dllexport)
# elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default")))
# else
# error \
"Unknown platform, please implement shared library export macros"
# endif
# else
# ifdef _WIN32
# define DRANG_API __declspec(dllimport)
# elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default")))
# else
# error \
"Unknown platform, please implement shared library import macros"
# endif
# endif
#else
# define DRANG_API
#endif
#ifdef __cplusplus
# define DRANG_BEGIN_DECLS extern "C" {
# define DRANG_END_DECLS }
#else
# define DRANG_BEGIN_DECLS
# define DRANG_END_DECLS
#endif
#if defined(__GNUC__) || defined(__clang__)
#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) __attribute__((format(printf, fmt_idx, arg_idx)))
#define DRANG_VPRINTF_ATTR(fmt_idx) __attribute__((format(printf, fmt_idx, 0)))
#define DRANG_ALLOC_SIZE_COUNT_ATTR(count, idx) __attribute__((alloc_size(idx, count)))
#define DRANG_ALLOC_SIZE_ATTR(idx) __attribute__((alloc_size(idx)))
#define DRANG_ALLOC_ALIGN_ATTR(idx) __attribute__((alloc_align(idx)))
#define DRANG_MALLOC_ATTR __attribute__((malloc))
#else
#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx)
#define DRANG_VPRINTF_ATTR(fmt_idx)
#define DRANG_ALLOC_SIZE_COUNT_ATTR(idx, count)
#define DRANG_ALLOC_SIZE_ATTR(idx)
#define DRANG_ALLOC_ALIGN_ATTR(idx)
#define DRANG_MALLOC_ATTR
#endif