summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-06-15 12:47:33 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-06-15 12:47:33 +0800
commitf93f73cdd3c7473e358b18c6f6add5f4d34ba5d6 (patch)
tree437e021a9f934462fb84d5507d53193d1b6f1dec
init
-rw-r--r--.clang-format51
-rw-r--r--.clang-tidy101
-rwxr-xr-x.gitignore3
-rw-r--r--CMakeLists.txt67
-rw-r--r--Makefile27
-rw-r--r--libsock.pc.in11
6 files changed, 260 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..c1bd334
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,51 @@
+---
+Language: Cpp
+BasedOnStyle: LLVM
+
+PointerAlignment: Right
+RemoveBracesLLVM: true
+AlignAfterOpenBracket: BlockIndent
+AlignEscapedNewlines: Right
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AlignConsecutiveAssignments: true
+AlignConsecutiveBitFields: true
+AlignConsecutiveDeclarations: true
+AlignConsecutiveMacros: true
+# AlignConsecutiveShortCaseStatements: # need clang-format 17(not avaliable yet)
+ # Enabled: true
+# AlignConsecutiveTableGenBreakingDAGArgColons: true # need clang-format 19(not avaliable yet)
+# AlignConsecutiveTableGenCondOperatorColons: true # need clang-format 19(not avaliable yet)
+# AlignConsecutiveTableGenDefinitionColons: true # need clang-format 19(not avaliable yet)
+BinPackParameters: false
+Standard: Auto
+UseTab: Always
+IndentWidth: 4
+TabWidth: 4
+ColumnLimit: 0
+# AccessModifierOffset: -4
+BreakConstructorInitializers: BeforeComma
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+PackConstructorInitializers: Never
+
+BraceWrapping: {
+ AfterCaseLabel: false,
+ AfterClass: false,
+ AfterControlStatement: Never,
+ AfterEnum: false,
+ AfterFunction: false,
+ AfterNamespace: false,
+ AfterObjCDeclaration: false,
+ AfterStruct: false,
+ AfterUnion: false,
+ AfterExternBlock: false,
+ BeforeCatch: false,
+ BeforeElse: false,
+ BeforeLambdaBody: false,
+ BeforeWhile: false,
+ IndentBraces: false,
+ SplitEmptyFunction: true,
+ SplitEmptyRecord: true,
+}
+BreakBeforeBraces: Custom
+# InsertBraces: false
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..87a3deb
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,101 @@
+WarningsAsErrors: '*'
+HeaderFilterRegex: '.*\.hpp'
+FormatStyle: file
+Checks: >
+ -*,
+ bugprone-*,
+ -bugprone-easily-swappable-parameters,
+ -bugprone-forward-declararion-namespace,
+ -bugprone-forward-declararion-namespace,
+ -bugprone-macro-parentheses,
+ -bugprone-narrowing-conversions,
+ -bugprone-branch-clone,
+ -bugprone-assignment-in-if-condition,
+ concurrency-*,
+ -concurrency-mt-unsafe,
+ cppcoreguidelines-*,
+ -cppcoreguidelines-owning-memory,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -cppcoreguidelines-pro-bounds-constant-array-index,
+ -cppcoreguidelines-avoid-const-or-ref-data-members,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -cppcoreguidelines-avoid-goto,
+ -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
+ -cppcoreguidelines-avoid-do-while,
+ -cppcoreguidelines-avoid-non-const-global-variables,
+ -cppcoreguidelines-special-member-functions,
+ -cppcoreguidelines-explicit-virtual-functions,
+ -cppcoreguidelines-avoid-c-arrays,
+ -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+ -cppcoreguidelines-narrowing-conversions,
+ -cppcoreguidelines-pro-type-union-access,
+ -cppcoreguidelines-pro-type-member-init,
+ -cppcoreguidelines-macro-usage,
+ -cppcoreguidelines-macro-to-enum,
+ -cppcoreguidelines-init-variables,
+ -cppcoreguidelines-pro-type-cstyle-cast,
+ -cppcoreguidelines-pro-type-vararg,
+ -cppcoreguidelines-pro-type-reinterpret-cast,
+ google-global-names-in-headers,
+ -google-readability-casting,
+ google-runtime-operator,
+ misc-*,
+ -misc-unused-parameters,
+ -misc-no-recursion,
+ -misc-non-private-member-variables-in-classes,
+ -misc-include-cleaner,
+ -misc-use-anonymous-namespace,
+ -misc-const-correctness,
+ modernize-*,
+ -modernize-return-braced-init-list,
+ -modernize-use-trailing-return-type,
+ -modernize-use-using,
+ -modernize-use-override,
+ -modernize-avoid-c-arrays,
+ -modernize-macro-to-enum,
+ -modernize-loop-convert,
+ -modernize-use-nodiscard,
+ -modernize-pass-by-value,
+ -modernize-use-auto,
+ performance-*,
+ -performance-avoid-endl,
+ -performance-unnecessary-value-param,
+ portability-std-allocator-const,
+ readability-*,
+ -readability-function-cognitive-complexity,
+ -readability-function-size,
+ -readability-identifier-length,
+ -readability-magic-numbers,
+ -readability-uppercase-literal-suffix,
+ -readability-braces-around-statements,
+ -readability-redundant-access-specifiers,
+ -readability-else-after-return,
+ -readability-container-data-pointer,
+ -readability-implicit-bool-conversion,
+ -readability-avoid-nested-conditional-operator,
+ -readability-redundant-member-init,
+ -readability-redundant-string-init,
+ -readability-avoid-const-params-in-decls,
+ -readability-named-parameter,
+ -readability-convert-member-functions-to-static,
+ -readability-qualified-auto,
+ -readability-make-member-function-const,
+ -readability-isolate-declaration,
+ -readability-inconsistent-declaration-parameter-name,
+ -clang-diagnostic-error,
+
+CheckOptions:
+ performance-for-range-copy.WarnOnAllAutoCopies: true
+ performance-inefficient-string-concatenation.StrictMode: true
+ readability-braces-around-statements.ShortStatementLines: 0
+ readability-identifier-naming.ClassCase: CamelCase
+ readability-identifier-naming.ClassIgnoredRegexp: I.*
+ readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
+ readability-identifier-naming.EnumCase: CamelCase
+ readability-identifier-naming.EnumPrefix: e
+ readability-identifier-naming.EnumConstantCase: UPPER_CASE
+ readability-identifier-naming.FunctionCase: camelBack
+ readability-identifier-naming.NamespaceCase: CamelCase
+ readability-identifier-naming.NamespacePrefix:
+ readability-identifier-naming.StructPrefix: S
+ readability-identifier-naming.StructCase: CamelCase
diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..09f29ce
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+.cache
+build
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..727108f
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,67 @@
+cmake_minimum_required(VERSION 3.19)
+
+project(
+ libsock
+ VERSION 1.0.0
+ DESCRIPTION "Minimal C++ socket library")
+
+add_compile_definitions(LIBSOCK_VERSION="${PROJECT_VERSION}")
+
+include(CTest)
+include(GNUInstallDirs)
+
+set(PREFIX ${CMAKE_INSTALL_PREFIX})
+set(INCLUDE ${CMAKE_INSTALL_FULL_INCLUDEDIR})
+set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
+
+configure_file(libsock.pc.in libsock.pc @ONLY)
+
+set(CMAKE_CXX_STANDARD 23)
+add_compile_options(
+ -Wall
+ -Wextra
+ -Wpedantic
+ -Wno-unused-parameter
+ -Wno-unused-value
+ -Wno-missing-field-initializers
+ -Wno-narrowing
+ -Wno-pointer-arith)
+set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
+
+if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
+ message(STATUS "Configuring libsock in Debug")
+ add_compile_definitions(LIBSOCK_DEBUG)
+else()
+ add_compile_options(-O3)
+ message(STATUS "Configuring libsock in Release")
+endif()
+
+file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp" "include/*.hpp")
+file(GLOB_RECURSE PUBLIC_HEADERS CONFIGURE_DEPENDS "include/*.hpp")
+
+find_package(PkgConfig REQUIRED)
+
+add_library(libsock SHARED ${SRCFILES})
+target_include_directories(
+ libsock
+ PUBLIC "./include"
+ PRIVATE "./src")
+set_target_properties(libsock PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1)
+
+# tests add_custom_target(tests)
+#
+# add_executable(libsock_socket "tests/socket.cpp")
+# target_link_libraries(libsock_socket PRIVATE libsock) add_test( NAME "Socket"
+# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND libsock_socket "socket")
+# add_dependencies(tests libsock_socket)
+#
+# add_executable(libsock_connection "tests/connection.cpp")
+# target_link_libraries(libsock_connection PRIVATE libsock) add_test( NAME
+# "Connection" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND
+# libsock_connection "connection") add_dependencies(tests libsock_connection)
+#
+# Installation
+install(TARGETS libsock)
+install(DIRECTORY "include/libsock" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(FILES ${CMAKE_BINARY_DIR}/libsock.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b8a8022
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,27 @@
+PREFIX ?= /usr/local
+
+stub:
+ @echo "Use 'make release' or 'make debug' to build the project."
+
+release:
+ cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} -S . -B ./build
+ cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
+
+debug:
+ cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} -S . -B ./build
+ cmake --build ./build --config Debug --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
+
+clean:
+ rm -rf build
+
+all:
+ $(MAKE) clean
+ $(MAKE) release
+
+install:
+ cmake --install ./build
+
+uninstall:
+ xargs rm < ./build/install_manifest.txt
+
+.PHONY: stub release debug clean all install uninstall format
diff --git a/libsock.pc.in b/libsock.pc.in
new file mode 100644
index 0000000..b19f90c
--- /dev/null
+++ b/libsock.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=@INCLUDE@
+
+Name: libsock
+Description: @CMAKE_PROJECT_DESCRIPTION@
+Version: @CMAKE_PROJECT_VERSION@
+Libs: -L${libdir} -lsock
+Cflags: -I${includedir}
+