Skip to content

Commit d98d4e9

Browse files
committed
add initial project structure
mostly copied from https://github.com/lefticus/cpp_starter_project and adapted to my needs and taste
1 parent 5e1e35c commit d98d4e9

16 files changed

+533
-0
lines changed

.clang-format

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: DontAlign
3+
AlignConsecutiveAssignments: None
4+
AlignConsecutiveDeclarations: None
5+
AlignEscapedNewlines: Left
6+
AlignOperands: AlignAfterOperator
7+
AlignTrailingComments: true
8+
AllowAllParametersOfDeclarationOnNextLine: false
9+
AllowShortBlocksOnASingleLine: Empty
10+
AllowShortCaseLabelsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: Inline
12+
AllowShortIfStatementsOnASingleLine: true
13+
AllowShortLoopsOnASingleLine: true
14+
AlwaysBreakAfterDefinitionReturnType: None
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: Yes
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterCaseLabel: false
22+
AfterClass: true
23+
AfterControlStatement: Never
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterObjCDeclaration: false
28+
AfterStruct: true
29+
AfterUnion: false
30+
AfterExternBlock: true
31+
BeforeCatch: false
32+
BeforeElse: false
33+
BeforeLambdaBody: false
34+
BeforeWhile: false
35+
IndentBraces: false
36+
SplitEmptyFunction: false
37+
SplitEmptyNamespace: true
38+
SplitEmptyRecord: true
39+
BreakAfterJavaFieldAnnotations: true
40+
BreakBeforeBinaryOperators: NonAssignment
41+
BreakBeforeBraces: Attach
42+
BreakBeforeTernaryOperators: true
43+
BreakConstructorInitializers: BeforeComma
44+
BreakStringLiterals: true
45+
ColumnLimit: 0
46+
CommentPragmas: '^ IWYU pragma:'
47+
CompactNamespaces: false
48+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
49+
ConstructorInitializerIndentWidth: 2
50+
ContinuationIndentWidth: 2
51+
Cpp11BracedListStyle: false
52+
DerivePointerAlignment: false
53+
DisableFormat: false
54+
ExperimentalAutoDetectBinPacking: true
55+
FixNamespaceComments: true
56+
ForEachMacros:
57+
- foreach
58+
- Q_FOREACH
59+
- BOOST_FOREACH
60+
IncludeCategories:
61+
- Priority: 2
62+
Regex: ^"(llvm|llvm-c|clang|clang-c)/
63+
- Priority: 3
64+
Regex: ^(<|"(catch2|gmock|isl|json)/)
65+
- Priority: 1
66+
Regex: .*
67+
IncludeIsMainRegex: (Test)?$
68+
IndentCaseLabels: false
69+
IndentWidth: 2
70+
IndentWrappedFunctionNames: true
71+
JavaScriptQuotes: Leave
72+
JavaScriptWrapImports: true
73+
KeepEmptyLinesAtTheStartOfBlocks: false
74+
Language: Cpp
75+
MacroBlockBegin: ''
76+
MacroBlockEnd: ''
77+
MaxEmptyLinesToKeep: 2
78+
NamespaceIndentation: None
79+
ObjCBlockIndentWidth: 4
80+
ObjCSpaceAfterProperty: true
81+
ObjCSpaceBeforeProtocolList: false
82+
PointerAlignment: Right
83+
ReflowComments: true
84+
SortIncludes: CaseInsensitive
85+
SortUsingDeclarations: true
86+
SpaceAfterCStyleCast: false
87+
SpaceAfterTemplateKeyword: true
88+
SpaceBeforeAssignmentOperators: true
89+
SpaceBeforeParens: ControlStatements
90+
SpaceInEmptyParentheses: false
91+
SpacesBeforeTrailingComments: 1
92+
SpacesInAngles: Never
93+
SpacesInCStyleCastParentheses: false
94+
SpacesInContainerLiterals: true
95+
SpacesInParentheses: false
96+
SpacesInSquareBrackets: false
97+
Standard: c++20
98+
TabWidth: 8
99+
UseTab: Never
100+

.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
FormatStyle: none

CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
project(fix CXX)
4+
include(cmake/StandardProjectSettings.cmake)
5+
include(cmake/PreventInSourceBuilds.cmake)
6+
7+
# enable cache system
8+
include(cmake/Cache.cmake)
9+
10+
# enable doxygen
11+
include(cmake/Doxygen.cmake)
12+
enable_doxygen()
13+
14+
15+
# standard compiler warnings
16+
include(cmake/CompilerWarnings.cmake)
17+
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
18+
add_library(project_warnings INTERFACE)
19+
set_project_warnings(project_warnings)
20+
21+
22+
# Link this 'library' to set the c++ standard / compile-time options requested
23+
add_library(project_options INTERFACE)
24+
target_compile_features(project_options INTERFACE cxx_std_20)
25+
26+
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
27+
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
28+
if (ENABLE_BUILD_WITH_TIME_TRACE)
29+
target_compile_options(project_options INTERFACE -ftime-trace)
30+
endif ()
31+
endif ()
32+
33+
# sanitizer options if supported by compiler
34+
include(cmake/Sanitizers.cmake)
35+
enable_sanitizers(project_options)
36+
37+
# allow for static analysis options
38+
include(cmake/StaticAnalyzers.cmake)
39+
40+
option(ENABLE_TESTING "Enable Test Builds" ON)
41+
42+
# Set up some extra Conan dependencies based on our needs before loading Conan
43+
set(CONAN_EXTRA_REQUIRES "")
44+
set(CONAN_EXTRA_OPTIONS "")
45+
46+
include(cmake/Conan.cmake)
47+
run_conan()
48+
49+
add_subdirectory(src)
50+
51+
if (ENABLE_TESTING)
52+
enable_testing()
53+
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
54+
add_subdirectory(test)
55+
endif ()
56+
57+

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

cmake/Cache.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
option(ENABLE_CACHE "Enable cache if available" ON)
2+
if(NOT ENABLE_CACHE)
3+
return()
4+
endif()
5+
6+
set(CACHE_OPTION
7+
"ccache"
8+
CACHE STRING "Compiler cache to be used")
9+
set(CACHE_OPTION_VALUES "ccache" "sccache")
10+
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
11+
list(
12+
FIND
13+
CACHE_OPTION_VALUES
14+
${CACHE_OPTION}
15+
CACHE_OPTION_INDEX)
16+
17+
if(${CACHE_OPTION_INDEX} EQUAL -1)
18+
message(
19+
STATUS
20+
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}")
21+
endif()
22+
23+
find_program(CACHE_BINARY ${CACHE_OPTION})
24+
if(CACHE_BINARY)
25+
message(STATUS "${CACHE_OPTION} found and enabled")
26+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY})
27+
else()
28+
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
29+
endif()

cmake/CompilerWarnings.cmake

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# from here:
2+
#
3+
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
4+
5+
function(set_project_warnings project_name)
6+
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
7+
8+
set(MSVC_WARNINGS
9+
/W4 # Baseline reasonable warnings
10+
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
11+
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
12+
/w14263 # 'function': member function does not override any base class virtual member function
13+
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
14+
# be destructed correctly
15+
/w14287 # 'operator': unsigned/negative constant mismatch
16+
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
17+
# the for-loop scope
18+
/w14296 # 'operator': expression is always 'boolean_value'
19+
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
20+
/w14545 # expression before comma evaluates to a function which is missing an argument list
21+
/w14546 # function call before comma missing argument list
22+
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
23+
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
24+
/w14555 # expression has no effect; expected expression with side- effect
25+
/w14619 # pragma warning: there is no warning number 'number'
26+
/w14640 # Enable warning on thread un-safe static member initialization
27+
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
28+
/w14905 # wide string literal cast to 'LPSTR'
29+
/w14906 # string literal cast to 'LPWSTR'
30+
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
31+
/permissive- # standards conformance mode for MSVC compiler.
32+
)
33+
34+
set(CLANG_WARNINGS
35+
-Wall
36+
-Wextra # reasonable and standard
37+
-Wshadow # warn the user if a variable declaration shadows one from a parent context
38+
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
39+
# catch hard to track down memory errors
40+
-Wold-style-cast # warn for c-style casts
41+
-Wcast-align # warn for potential performance problem casts
42+
-Wunused # warn on anything being unused
43+
-Woverloaded-virtual # warn if you overload (not override) a virtual function
44+
-Wpedantic # warn if non-standard C++ is used
45+
-Wconversion # warn on type conversions that may lose data
46+
-Wsign-conversion # warn on sign conversions
47+
-Wnull-dereference # warn if a null dereference is detected
48+
-Wdouble-promotion # warn if float is implicit promoted to double
49+
-Wformat=2 # warn on security issues around functions that format output (ie printf)
50+
)
51+
52+
if (WARNINGS_AS_ERRORS)
53+
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
54+
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
55+
endif ()
56+
57+
set(GCC_WARNINGS
58+
${CLANG_WARNINGS}
59+
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
60+
-Wduplicated-cond # warn if if / else chain has duplicated conditions
61+
-Wduplicated-branches # warn if if / else branches have duplicated code
62+
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
63+
-Wuseless-cast # warn if you perform a cast to the same type
64+
)
65+
66+
if (MSVC)
67+
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
68+
elseif (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
69+
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
70+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
71+
set(PROJECT_WARNINGS ${GCC_WARNINGS})
72+
else ()
73+
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
74+
endif ()
75+
76+
target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})
77+
78+
endfunction()

cmake/Conan.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
macro(run_conan)
2+
# Download automatically, you can also just copy the conan.cmake file
3+
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
4+
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
5+
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
6+
endif ()
7+
8+
include(${CMAKE_BINARY_DIR}/conan.cmake)
9+
10+
conan_add_remote(
11+
NAME
12+
bincrafters
13+
URL
14+
https://api.bintray.com/conan/bincrafters/public-conan)
15+
16+
conan_cmake_run(
17+
REQUIRES
18+
${CONAN_EXTRA_REQUIRES}
19+
catch2/2.13.6
20+
fmt/8.0.1
21+
OPTIONS
22+
${CONAN_EXTRA_OPTIONS}
23+
BASIC_SETUP
24+
CMAKE_TARGETS # individual targets to link to
25+
BUILD
26+
missing)
27+
endmacro()

cmake/Doxygen.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function(enable_doxygen)
2+
option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" OFF)
3+
if (ENABLE_DOXYGEN)
4+
set(DOXYGEN_CALLER_GRAPH YES)
5+
set(DOXYGEN_CALL_GRAPH YES)
6+
set(DOXYGEN_EXTRACT_ALL YES)
7+
find_package(Doxygen REQUIRED dot)
8+
doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR})
9+
10+
endif ()
11+
endfunction()

cmake/PreventInSourceBuilds.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# This function will prevent in-source builds
3+
function(AssureOutOfSourceBuilds)
4+
# make sure the user doesn't play dirty with symlinks
5+
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
6+
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
7+
8+
# disallow in-source builds
9+
if ("${srcdir}" STREQUAL "${bindir}")
10+
message("######################################################")
11+
message("Warning: in-source builds are disabled")
12+
message("Please create a separate build directory and run cmake from there")
13+
message("######################################################")
14+
message(FATAL_ERROR "Quitting configuration")
15+
endif ()
16+
endfunction()
17+
18+
assureoutofsourcebuilds()

0 commit comments

Comments
 (0)