Skip to content

Commit 9230d97

Browse files
initial draft
Signed-off-by: Christian Parpart <[email protected]>
0 parents  commit 9230d97

File tree

12 files changed

+918
-0
lines changed

12 files changed

+918
-0
lines changed

.clang-format

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
AccessModifierOffset: '-2'
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveMacros: 'true'
6+
AlignConsecutiveDeclarations: 'false'
7+
AlignEscapedNewlines: Left
8+
AlignOperands: 'true'
9+
AlignTrailingComments: 'true'
10+
AllowAllArgumentsOnNextLine: 'true'
11+
AllowAllConstructorInitializersOnNextLine: 'true'
12+
AllowAllParametersOfDeclarationOnNextLine: 'true'
13+
AllowShortBlocksOnASingleLine: 'false'
14+
AllowShortCaseLabelsOnASingleLine: 'false'
15+
AllowShortFunctionsOnASingleLine: Empty
16+
AllowShortIfStatementsOnASingleLine: Never
17+
AllowShortLambdasOnASingleLine: Inline
18+
AllowShortLoopsOnASingleLine: 'false'
19+
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakBeforeMultilineStrings: 'false'
21+
AlwaysBreakTemplateDeclarations: 'Yes'
22+
BinPackArguments: 'false'
23+
BinPackParameters: 'false'
24+
BreakBeforeBinaryOperators: NonAssignment
25+
BreakBeforeBraces: Custom
26+
BreakBeforeTernaryOperators: 'true'
27+
BreakConstructorInitializers: AfterColon
28+
BreakInheritanceList: AfterColon
29+
BreakStringLiterals: 'true'
30+
ColumnLimit: '120'
31+
CompactNamespaces: 'false'
32+
PackConstructorInitializers: Never
33+
ConstructorInitializerIndentWidth: '4'
34+
ContinuationIndentWidth: '4'
35+
Cpp11BracedListStyle: 'false'
36+
DerivePointerAlignment: 'false'
37+
FixNamespaceComments: 'true'
38+
IncludeBlocks: Regroup
39+
IndentCaseLabels: true
40+
IndentPPDirectives: BeforeHash
41+
IndentWidth: '4'
42+
IndentWrappedFunctionNames: 'false'
43+
Language: Cpp
44+
MaxEmptyLinesToKeep: '1'
45+
NamespaceIndentation: Inner
46+
PenaltyBreakAssignment: '0'
47+
PointerAlignment: Left
48+
ReflowComments: 'true'
49+
SortIncludes: 'true'
50+
SortUsingDeclarations: 'true'
51+
SpaceAfterCStyleCast: 'true'
52+
SpaceAfterLogicalNot: 'false'
53+
SpaceAfterTemplateKeyword: 'true'
54+
SpaceBeforeAssignmentOperators: 'true'
55+
SpaceBeforeCpp11BracedList: 'true'
56+
SpaceBeforeCtorInitializerColon: 'false'
57+
SpaceBeforeInheritanceColon: 'false'
58+
SpaceBeforeParens: ControlStatements
59+
SpaceBeforeRangeBasedForLoopColon: 'false'
60+
SpaceInEmptyParentheses: 'false'
61+
SpacesInAngles: 'false'
62+
SpacesInCStyleCastParentheses: 'false'
63+
SpacesInContainerLiterals: 'false'
64+
SpacesInParentheses: 'false'
65+
SpacesInSquareBrackets: 'false'
66+
Standard: Cpp11
67+
TabWidth: '4'
68+
UseTab: Never
69+
IncludeCategories:
70+
- Regex: '^".*"'
71+
Priority: 0
72+
- Regex: '^<(reflection-cpp)/'
73+
Priority: 10
74+
- Regex: '^<gsl/'
75+
Priority: 48
76+
- Regex: '^<catch2/'
77+
Priority: 70
78+
- Regex: '^<sys/'
79+
Priority: 80
80+
- Regex: '^<[[:alnum:]_]+>'
81+
Priority: 81
82+
- Regex: '<[[:alnum:]_]+\.h>'
83+
Priority: 82
84+
- Regex: '.*'
85+
Priority: 99

.clang-tidy

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
Checks: >-
3+
-*,
4+
bugprone-*,
5+
-bugprone-branch-clone,
6+
-bugprone-easily-swappable-parameters,
7+
-bugprone-exception-escape,
8+
-bugprone-implicit-widening-of-multiplication-result,
9+
-bugprone-reserved-identifier,
10+
-bugprone-suspicious-include,
11+
-bugprone-unchecked-optional-access,
12+
clang-analyzer-core.*,
13+
clang-analyzer-cplusplus.*,
14+
clang-analyzer-deadcode.*,
15+
clang-analyzer-nullability.*,
16+
clang-analyzer-optin.cplusplus.*,
17+
-clang-analyzer-optin.cplusplus.UninitializedObject,
18+
clang-analyzer-optin.performance.*,
19+
clang-analyzer-optin.portability.*,
20+
clang-analyzer-security.*,
21+
clang-analyzer-unix.*,
22+
clang-diagnostic-*,
23+
cppcoreguidelines-*,
24+
cppcoreguidelines-*,
25+
-cppcoreguidelines-avoid-c-arrays,
26+
-cppcoreguidelines-avoid-const-or-ref-data-members,
27+
-cppcoreguidelines-avoid-do-while,
28+
-cppcoreguidelines-avoid-magic-numbers,
29+
-cppcoreguidelines-avoid-non-const-global-variables,
30+
-cppcoreguidelines-macro-usage,
31+
-cppcoreguidelines-no-malloc,
32+
-cppcoreguidelines-non-private-member-variables-in-classes,
33+
-cppcoreguidelines-owning-memory,
34+
-cppcoreguidelines-prefer-member-initializer,
35+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
36+
-cppcoreguidelines-pro-bounds-constant-array-index,
37+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
38+
-cppcoreguidelines-pro-type-const-cast,
39+
-cppcoreguidelines-pro-type-cstyle-cast,
40+
-cppcoreguidelines-pro-type-reinterpret-cast,
41+
-cppcoreguidelines-pro-type-static-cast-downcast,
42+
-cppcoreguidelines-pro-type-union-access,
43+
-cppcoreguidelines-pro-type-vararg,
44+
-cppcoreguidelines-special-member-functions,
45+
modernize-*,
46+
-modernize-avoid-bind,
47+
-modernize-avoid-c-arrays,
48+
-modernize-return-braced-init-list,
49+
-modernize-use-bool-literals,
50+
-modernize-use-trailing-return-type,
51+
performance-*,
52+
-performance-no-int-to-ptr,
53+
readability-*,
54+
-readability-avoid-unconditional-preprocessor-if,
55+
-readability-braces-around-statements,
56+
-readability-container-contains,
57+
-readability-else-after-return,
58+
-readability-function-cognitive-complexity,
59+
-readability-identifier-length,
60+
-readability-implicit-bool-conversion,
61+
-readability-magic-numbers,
62+
-readability-named-parameter,
63+
-readability-redundant-access-specifiers,
64+
-readability-simplify-boolean-expr,
65+
-readability-uppercase-literal-suffix,
66+
-readability-use-anyofallof,
67+
misc-const-correctness,
68+
WarningsAsErrors: >-
69+
modernize-use-nullptr,
70+
UseColor: true
71+
HeaderFilterRegex: 'src/'
72+
FormatStyle: none
73+
CheckOptions:
74+
- key: bugprone-easily-swappable-parameters.MinimumLength
75+
value: '3'
76+
- key: cert-dcl16-c.NewSuffixes
77+
value: 'L;LL;LU;LLU'
78+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
79+
value: '0'
80+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
81+
value: '1'
82+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
83+
value: '1'
84+
- key: google-readability-braces-around-statements.ShortStatementLines
85+
value: '1'
86+
- key: google-readability-function-size.StatementThreshold
87+
value: '800'
88+
- key: google-readability-namespace-comments.ShortNamespaceLines
89+
value: '10'
90+
- key: google-readability-namespace-comments.SpacesBeforeComments
91+
value: '2'
92+
- key: modernize-loop-convert.MaxCopySize
93+
value: '16'
94+
- key: modernize-loop-convert.MinConfidence
95+
value: reasonable
96+
- key: modernize-loop-convert.NamingStyle
97+
value: CamelCase
98+
- key: modernize-pass-by-value.IncludeStyle
99+
value: llvm
100+
- key: modernize-replace-auto-ptr.IncludeStyle
101+
value: llvm
102+
- key: modernize-use-nullptr.NullMacros
103+
value: 'NULL'
104+
- key: modernize-use-default-member-init.UseAssignment
105+
value: '1'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
compile_commands.json
2+
.cache/
3+
out/

CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(reflection-cpp VERSION 1.4.2 LANGUAGES CXX)
3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4+
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
7+
include(GNUInstallDirs)
8+
include(ThirdParties)
9+
include(ClangTidy)
10+
include(PedanticCompiler)
11+
12+
set(boxed_cpp_HEADERS
13+
${PROJECT_SOURCE_DIR}/include/reflection-cpp/boxed.hpp
14+
)
15+
add_library(reflection-cpp INTERFACE)
16+
add_library(reflection-cpp::reflection-cpp ALIAS reflection-cpp)
17+
18+
target_compile_features(reflection-cpp INTERFACE cxx_std_20)
19+
target_include_directories(reflection-cpp INTERFACE
20+
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
21+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
22+
)
23+
24+
# Generate the version, config and target files
25+
include(CMakePackageConfigHelpers)
26+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/reflection-cpp-config-version.cmake
27+
VERSION ${PROJECT_VERSION}
28+
COMPATIBILITY SameMajorVersion
29+
)
30+
configure_package_config_file(reflection-cpp-config.cmake.in
31+
${CMAKE_CURRENT_BINARY_DIR}/reflection-cpp-config.cmake
32+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflection-cpp
33+
)
34+
35+
install(FILES ${boxed_cpp_HEADERS}
36+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/reflection-cpp
37+
)
38+
install(TARGETS reflection-cpp
39+
EXPORT reflection-cpp-targets
40+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
41+
)
42+
43+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/reflection-cpp-config.cmake
44+
${CMAKE_CURRENT_BINARY_DIR}/reflection-cpp-config-version.cmake
45+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflection-cpp
46+
)
47+
install(EXPORT reflection-cpp-targets
48+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflection-cpp
49+
NAMESPACE reflection-cpp::
50+
)
51+
52+
# ---------------------------------------------------------------------------
53+
# unit tests
54+
55+
option(BOXED_TESTING "Enables building of unittests for reflection-cpp [default: ON]" ON)
56+
if(BOXED_TESTING)
57+
find_package(Catch2 3.4.0 QUIET)
58+
if(NOT Catch2_FOUND)
59+
ThirdPartiesAdd_Catch2()
60+
endif()
61+
enable_testing()
62+
add_executable(test-reflection-cpp
63+
test-reflection-cpp.cpp
64+
)
65+
target_compile_features(test-reflection-cpp INTERFACE cxx_std_20)
66+
target_link_libraries(test-reflection-cpp reflection-cpp Catch2::Catch2WithMain)
67+
add_test(test-reflection-cpp ./test-reflection-cpp)
68+
endif()
69+
message(STATUS "[reflection-cpp] Compile unit tests: ${BOXED_TESTING}")

CMakePresets.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "common",
6+
"hidden": true,
7+
"binaryDir": "${sourceDir}/out/build/${presetName}",
8+
"installDir": "${sourceDir}/out/install/${presetName}",
9+
"generator": "Ninja",
10+
"cacheVariables": {
11+
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
12+
"CMAKE_VERBOSE_MAKEFILE": "OFF"
13+
}
14+
},
15+
{
16+
"name": "windows-common",
17+
"hidden": true,
18+
"inherits": ["common"],
19+
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
20+
"condition": {
21+
"type": "equals",
22+
"lhs": "${hostSystemName}",
23+
"rhs": "Windows"
24+
},
25+
"cacheVariables": {
26+
"CMAKE_SYSTEM_VERSION": "10.0"
27+
}
28+
},
29+
{
30+
"name": "windows-cl-common",
31+
"hidden": true,
32+
"inherits": ["windows-common"],
33+
"generator": "Visual Studio 17 2022",
34+
"cacheVariables": {
35+
"CMAKE_CXX_COMPILER": "cl"
36+
}
37+
},
38+
{ "name": "windows-cl-debug", "inherits": ["windows-cl-common"], "displayName": "Windows - MSVC CL - Debug" },
39+
{ "name": "windows-cl-release", "inherits": ["windows-cl-common"], "displayName": "Windows - MSVC CL - Release" },
40+
{
41+
"name": "windows-clangcl-common",
42+
"hidden": true,
43+
"inherits": ["windows-common"],
44+
"cacheVariables": {
45+
"CMAKE_CXX_COMPILER": "clang-cl",
46+
"CMAKE_C_COMPILER": "clang-cl"
47+
}
48+
},
49+
{ "name": "windows-clangcl-debug", "inherits": ["windows-clangcl-common"], "displayName": "Windows - MSVC ClangCL - Debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } },
50+
{ "name": "windows-clangcl-release","inherits": ["windows-clangcl-common"], "displayName": "Windows - MSVC ClangCL - Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } },
51+
{ "name": "linux-common", "hidden": true, "inherits": ["common"], "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Linux" } },
52+
{ "name": "macos-common", "hidden": true, "inherits": ["common"], "condition": { "lhs": "${hostSystemName}", "type": "equals", "rhs": "Darwin" } },
53+
{ "name": "debug", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } },
54+
{ "name": "release", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" } },
55+
{ "name": "pedantic", "hidden": true, "cacheVariables": { "PEDANTIC_COMPILER": "ON", "PEDANTIC_COMPILER_WERROR": "ON" } },
56+
{ "name": "linux-common-release", "hidden": true, "inherits": "release", "cacheVariables": { "CMAKE_INSTALL_PREFIX": "/usr/local" } },
57+
{ "name": "linux-clang", "hidden": true, "inherits": "linux-common", "cacheVariables": { "CMAKE_CXX_COMPILER": "clang++" } },
58+
{ "name": "linux-gcc", "hidden": true, "inherits": "linux-common", "cacheVariables": { "CMAKE_CXX_COMPILER": "g++" } },
59+
{ "name": "linux-clang-release", "displayName": "Linux (Clang) Release", "inherits": ["linux-clang", "linux-common-release"] },
60+
{ "name": "linux-clang-debug", "displayName": "Linux (Clang) Debug", "inherits": ["linux-clang", "debug"] },
61+
{ "name": "linux-gcc-release", "displayName": "Linux (GCC) Release", "inherits": ["linux-gcc", "linux-common-release"] },
62+
{ "name": "linux-gcc-debug", "displayName": "Linux (GCC) Debug", "inherits": ["linux-gcc", "debug", "pedantic"] },
63+
{ "name": "macos-release", "displayName": "MacOS Release", "inherits": ["macos-common", "release"] },
64+
{ "name": "macos-debug", "displayName": "MacOS Debug", "inherits": ["macos-common", "debug"] }
65+
],
66+
"buildPresets": [
67+
{ "name": "windows-cl-debug", "displayName": "Windows - MSVC CL - Debug", "configurePreset": "windows-cl-debug", "configuration": "Debug" },
68+
{ "name": "windows-cl-release", "displayName": "Windows - MSVC CL - Release", "configurePreset": "windows-cl-release", "configuration": "Release" },
69+
{ "name": "windows-clangcl-debug", "displayName": "Windows - MSVC ClangCL - Debug", "configurePreset": "windows-clangcl-debug", "configuration": "Debug" },
70+
{ "name": "windows-clangcl-release", "displayName": "Windows - MSVC ClangCL - Release", "configurePreset": "windows-clangcl-release", "configuration": "Release" },
71+
{ "name": "linux-clang-debug", "displayName": "Linux - Clang - Debug", "configurePreset": "linux-clang-debug" },
72+
{ "name": "linux-clang-release", "displayName": "Linux - Clang - RelWithDebInfo", "configurePreset": "linux-clang-release" },
73+
{ "name": "linux-gcc-debug", "displayName": "Linux - GCC - Debug", "configurePreset": "linux-gcc-debug" },
74+
{ "name": "linux-gcc-release", "displayName": "Linux - GCC - RelWithDebInfo", "configurePreset": "linux-gcc-release" },
75+
{ "name": "macos-debug", "displayName": "MacOS - Debug", "configurePreset": "macos-debug" },
76+
{ "name": "macos-release", "displayName": "MacOS - RelWithDebInfo", "configurePreset": "macos-release" }
77+
],
78+
"testPresets": [
79+
{ "name": "windows-cl-debug", "configurePreset": "windows-cl-debug", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
80+
{ "name": "windows-cl-release", "configurePreset": "windows-cl-release", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
81+
{ "name": "windows-clangcl-debug", "configurePreset": "windows-clangcl-debug", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
82+
{ "name": "windows-clangcl-release", "configurePreset": "windows-clangcl-release", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
83+
{ "name": "linux-gcc-debug", "configurePreset": "linux-gcc-debug", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
84+
{ "name": "linux-gcc-release", "configurePreset": "linux-gcc-release", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
85+
{ "name": "linux-clang-debug", "configurePreset": "linux-clang-debug", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } },
86+
{ "name": "linux-clang-release", "configurePreset": "linux-clang-release", "output": {"outputOnFailure": true}, "execution": { "noTestsAction": "error", "stopOnFailure": true } }
87+
]
88+
}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Reflection C++
2+
3+
This is a C++ static reflection library.
4+
5+
## Goals
6+
7+
- Trivial to integrate into existing codebases (no code generation, no macros, no build system changes)
8+
- Minimal to zero runtime overhead
9+
- Works with C++20 and later
10+
- Prepared to integrate C++26 reflections when they are available

cmake/ClangTidy.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
option(ENABLE_TIDY "Enable clang-tidy [default: OFF]" OFF)
3+
if(ENABLE_TIDY)
4+
find_program(CLANG_TIDY_EXE
5+
NAMES clang-tidy-9 clang-tidy-8 clang-tidy-7 clang-tidy
6+
DOC "Path to clang-tidy executable")
7+
if(NOT CLANG_TIDY_EXE)
8+
message(STATUS "[clang-tidy] Not found.")
9+
else()
10+
message(STATUS "[clang-tidy] found: ${CLANG_TIDY_EXE}")
11+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
12+
endif()
13+
else()
14+
message(STATUS "[clang-tidy] Disabled.")
15+
endif()

0 commit comments

Comments
 (0)