Initial commit
This commit is contained in:
commit
d1a39262d8
6 changed files with 390 additions and 0 deletions
105
.clang-format
Normal file
105
.clang-format
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
BasedOnStyle: LLVM
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- forever
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeCategories:
|
||||
- Regex: '^<Q.*'
|
||||
Priority: 200
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
AllowShortCaseExpressionOnASingleLine: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
IndentPPDirectives: AfterHash
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: true
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ""
|
||||
MacroBlockEnd: ""
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 88
|
||||
PenaltyBreakBeforeFirstCallParameter: 2000
|
||||
PenaltyBreakComment: 500
|
||||
PenaltyBreakFirstLessLess: 400
|
||||
PenaltyBreakString: 600
|
||||
PenaltyExcessCharacter: 50
|
||||
PenaltyReturnTypeOnItsOwnLine: 300
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: CaseSensitive
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: c++20
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Build folders
|
||||
build-*/
|
||||
|
||||
# Ide specific
|
||||
.idea/
|
||||
.vs/
|
||||
.vscode/
|
||||
.qtcreator/
|
||||
|
||||
# Qt creator
|
||||
CMakeLists.txt.user
|
||||
|
||||
# CMake
|
||||
CMakeUserPresets.json
|
||||
31
CMakeLists.txt
Normal file
31
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(DrangPlatform VERSION 1.0.0)
|
||||
|
||||
|
||||
|
||||
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
set(OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
|
||||
|
||||
if(WIN32)
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
mimalloc
|
||||
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
|
||||
GIT_TAG v3.1.5
|
||||
)
|
||||
set(MI_OVERRIDE OFF CACHE BOOL "" FORCE)
|
||||
set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE)
|
||||
set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(mimalloc)
|
||||
|
||||
|
||||
add_subdirectory(Source/DrangPlatform)
|
||||
117
CMakePresets.json
Normal file
117
CMakePresets.json
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "windows-base",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "clang-cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "clang-cl.exe",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": true
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux-base",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": true
|
||||
},
|
||||
"condition": {
|
||||
"type": "notEquals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "win64-debug",
|
||||
"displayName": "x64 Debug",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "win64-debug-shared",
|
||||
"displayName": "x64 Debug Shared",
|
||||
"inherits": "win64-debug",
|
||||
"cacheVariables": {
|
||||
"BUILD_SHARED_LIBS": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "win64-release",
|
||||
"displayName": "x64 Release",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "win64-release-shared",
|
||||
"displayName": "x64 Release Shared",
|
||||
"inherits": "win64-release",
|
||||
"cacheVariables": {
|
||||
"BUILD_SHARED_LIBS": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux64-debug",
|
||||
"displayName": "x64 Debug",
|
||||
"inherits": "linux-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux64-debug-shared",
|
||||
"displayName": "x64 Debug Shared",
|
||||
"inherits": "linux64-debug",
|
||||
"cacheVariables": {
|
||||
"BUILD_SHARED_LIBS": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux64-release",
|
||||
"displayName": "x64 Release",
|
||||
"inherits": "linux-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux64-release-shared",
|
||||
"displayName": "x64 Release Shared",
|
||||
"inherits": "linux64-release",
|
||||
"cacheVariables": {
|
||||
"BUILD_SHARED_LIBS": "ON"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
72
Source/DrangPlatform/CMakeLists.txt
Normal file
72
Source/DrangPlatform/CMakeLists.txt
Normal 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)
|
||||
51
Source/DrangPlatform/Include/drang/platform.h
Normal file
51
Source/DrangPlatform/Include/drang/platform.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue