Commit e2dc0ad2 authored by Jostein Bratlie's avatar Jostein Bratlie
Browse files

Initial commit of the DTE-3603 Template Source Base

parents
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
#CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
#IncludeCategories:
# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
# Priority: 2
# - Regex: '^(<|"(gtest|isl|json)/)'
# Priority: 3
# - Regex: '.*'
# Priority: 1
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 5
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 2
UseTab: Never
...
########################
## Globaly ignored files
*~
*.save
*.bak
*.backup
*.o
*.lib
*.a
*.obj
*.so
*.layout
*.user
*.suo
*.ncb
*.swp
*.moc
*.user*
*.cbp
*.autosave
########
## CMake
CMakeCache.txt
cmake_install.cmake
CMakeFiles/
build/
BUILD/
########
## QMake
*.pro
*.pri
moc_*
#######
## KDev
.kdev4/
*.kdev4
##########################################
# Ignored Ct Creator spesifics directories
qtc-gdbmacros
# mimimum required version 3.15: policy CMP0092
# mimimum required version 3.12: target_compile_features C++ 20
# mimimum required version 3.8: target_compile_features C++ 17
cmake_minimum_required(VERSION 3.15)
# policy CMP0092 MSVC COMPILE FLAGS -- no warings by default
cmake_policy(SET CMP0092 NEW)
# Project name
project(dte3603_source_base_dev_2021_REFERENCE VERSION 0.1 LANGUAGES CXX)
# Ease of setup protection on Wintendo OSes
if(MSVC AND NOT VCPKG_TOOLCHAIN)
message(FATAL_ERROR
"Enable VCPKG toolchain on MSVC platform\n"
" Star over; CMAKE_TOOLCHAIN_FILE definition missing!\n"
" i.e.: cmake -DCMAKE_TOOLCHAIN_FILE=<path_to>\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake <path_to>\\source\\"
)
endif()
## Global compiler spesific compile options
SET(CLANG_COMPILE_OPTIONS
# REQUIRED ON
-Weverything -pedantic -Werror
-Wno-c++98-compat -Wno-c++98-compat-pedantic
# REQUIRED ON
# Turn off warning for undocumented code fragments
-Wno-documentation
)
SET(GCC_COMPILE_OPTIONS
# REQUIRED ON
-pedantic -Wall -Werror
# REQUIRED ON
)
SET(MSVC_COMPILE_OPTIONS
# REQUIRED ON
/WX /W4 /permissive-
# REQUIRED ON
)
# Find boost
find_package(Boost 1.72 REQUIRED COMPONENTS graph)
target_compile_options( Boost::graph
INTERFACE $<$<CXX_COMPILER_ID:Clang>: -w >
INTERFACE $<$<CXX_COMPILER_ID:GNU>: -w >
# INTERFACE $<$<CXX_COMPILER_ID:MSVC>: /w > # Turn on if MSVC complains
)
target_compile_definitions(Boost::graph
INTERFACE $<$<CXX_COMPILER_ID:GNU>: BOOST_ALLOW_DEPRECATED_HEADERS > # Boost post c++17 compile bug
)
# Include shared predfined inline helper sources
add_subdirectory(predef_shared)
# Include internal library subfolders
add_subdirectory(day1_2_sort)
add_subdirectory(day3_string_match)
add_subdirectory(day4_graph_traversal)
add_subdirectory(day5_graph_path_finding)
###########################################
# Qt creator dummy target
option(DUMMY_TARGET "Dummy target..." TRUE)
if(DUMMY_TARGET)
add_custom_target(${PROJECT_NAME}_DUMMY)
endif(DUMMY_TARGET)
macro(SETUP_UNITTEST_ENV)
# Enable testing
enable_testing()
# Configure threads
find_package(Threads REQUIRED)
# Configure GTest
find_package(GTest REQUIRED)
if(GTest_FOUND)
# Turn off static analysis for benchmark tool (no compilation warnings)
target_compile_options( GTest::GTest
INTERFACE $<$<CXX_COMPILER_ID:Clang>: -w >
INTERFACE $<$<CXX_COMPILER_ID:GNU>: -w >
# INTERFACE $<$<CXX_COMPILER_ID:MSVC>: /w > # Turn on if MSVC complains
)
target_compile_options( GTest::Main
INTERFACE $<$<CXX_COMPILER_ID:Clang>: -w >
INTERFACE $<$<CXX_COMPILER_ID:GNU>: -w >
# INTERFACE $<$<CXX_COMPILER_ID:MSVC>: /w > # Turn on if MSVC complains
)
# GTEST compile options
set( GTEST_CLANG_COMPILE_OPTIONS
# option
)
set( GTEST_GCC_COMPILE_OPTIONS
# option
)
set( GTEST_MSVC_COMPILE_OPTIONS
# option
)
endif(GTest_FOUND)
endmacro(SETUP_UNITTEST_ENV)
function(ADD_UNITTESTS UNITTEST_LIB_TOTEST UNITTEST_DIR UNITTESTS_INN)
# Add tests
# -- ARGN :: additional LIB dependencies
foreach(TEST ${${UNITTESTS_INN}})
set( TESTNAME unittest_${TEST} )
add_executable( ${TESTNAME} )
target_sources( ${TESTNAME}
PRIVATE ${UNITTEST_DIR}/${TEST}.cpp ${SRCS} )
target_link_libraries( ${TESTNAME}
PRIVATE
${UNITTEST_LIB_TOTEST}
${ARGN}
GTest::GTest GTest::Main
Threads::Threads )
# C++ standard feature set
target_compile_features( ${TESTNAME}
PUBLIC $<$<CXX_COMPILER_ID:Clang>:cxx_std_20>
PUBLIC $<$<CXX_COMPILER_ID:GNU>:cxx_std_20>
PUBLIC $<$<CXX_COMPILER_ID:MSVC>:cxx_std_20>
)
# Compile definitions
target_compile_definitions( ${TESTNAME}
PUBLIC $<$<CXX_COMPILER_ID:MSVC>: _USE_MATH_DEFINES>
)
# Comple options
target_compile_options( ${TESTNAME}
PUBLIC $<$<CXX_COMPILER_ID:Clang>: ${CLANG_COMPILE_OPTIONS} ${GTEST_CLANG_COMPILE_OPTIONS}>
PUBLIC $<$<CXX_COMPILER_ID:GNU>: ${GCC_COMPILE_OPTIONS} ${GTEST_GCC_COMPILE_OPTIONS}>
PUBLIC $<$<CXX_COMPILER_ID:MSVC>: ${MSVC_COMPILE_OPTIONS} ${GTEST_MSVC_COMPILE_OPTIONS}>
)
# Turn off platform-spesific extensions
set_target_properties(${TESTNAME} PROPERTIES CXX_EXTENSIONS OFF)
gtest_discover_tests( ${TESTNAME} "" AUTO )
endforeach(TEST)
endfunction(ADD_UNITTESTS)
macro(SETUP_BENCHMARK_ENV)
# Enable testing
enable_testing()
# Configure threads
find_package(Threads REQUIRED)
# Configure benchmark
find_package(benchmark REQUIRED)
if(benchmark_FOUND)
# Turn off static analysis for benchmark tool (no compilation warnings)
target_compile_options( benchmark::benchmark
INTERFACE $<$<CXX_COMPILER_ID:Clang>: -w >
INTERFACE $<$<CXX_COMPILER_ID:GNU>: -w >
# INTERFACE $<$<CXX_COMPILER_ID:MSVC>: /w > # Turn on if MSVC complains
)
# benchmark compile options
set( BENCHMARK_CLANG_COMPILE_OPTIONS
# option
)
set( BENCHMARK_GCC_COMPILE_OPTIONS
# option
)
set( BENCHMARK_MSVC_COMPILE_OPTIONS
# option
)
endif(benchmark_FOUND)
endmacro(SETUP_BENCHMARK_ENV)
function(ADD_BENCHMARKS BENCHMARKS_LIB_TOTEST BENCHMARKS_DIR BENCHMARKS_INN)
# Add tests
# -- ARGN :: additional LIB dependencies
foreach(BENCHMARK ${${BENCHMARKS_INN}})
set(BNAME benchmark_${BENCHMARK})
add_executable( ${BNAME} )
target_sources( ${BNAME} PRIVATE ${BENCHMARKS_DIR}/${BENCHMARK}.cpp )
target_link_libraries( ${BNAME}
PRIVATE
${BENCHMARKS_LIB_TOTEST}
${ARGN}
benchmark::benchmark
Threads::Threads )
# Turn on c++20 compile features -- minimum CMake Version 3.8 required
target_compile_features( ${BNAME}
PUBLIC $<$<CXX_COMPILER_ID:Clang>:cxx_std_20>
PUBLIC $<$<CXX_COMPILER_ID:GNU>:cxx_std_20>
PUBLIC $<$<CXX_COMPILER_ID:MSVC>:cxx_std_20>
)
# Compile definitions
target_compile_definitions( ${BNAME}
PUBLIC $<$<CXX_COMPILER_ID:MSVC>: _USE_MATH_DEFINES>
)
# Comple options
target_compile_options( ${BNAME}
PUBLIC $<$<CXX_COMPILER_ID:Clang>: ${CLANG_COMPILE_OPTIONS} ${BENCHMARK_CLANG_COMPILE_OPTIONS}>
PUBLIC $<$<CXX_COMPILER_ID:GNU>: ${GCC_COMPILE_OPTIONS} ${BENCHMARK_GCC_COMPILE_OPTIONS}>
PUBLIC $<$<CXX_COMPILER_ID:MSVC>: ${MSVC_COMPILE_OPTIONS} ${BENCHMARK_MSVC_COMPILE_OPTIONS}>
)
# Turn off platform-spesific extensions
set_target_properties(${BNAME} PROPERTIES CXX_EXTENSIONS OFF)
add_test( NAME ${BNAME} COMMAND ${BNAME} )
endforeach(BENCHMARK ${BENCHMARKS})
endfunction(ADD_BENCHMARKS)
project(day1_2_sort)
# Add library target
add_library(${PROJECT_NAME} INTERFACE )
# Headers
target_include_directories( ${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> )
# Make ${PROJECT_NAME} available as a direct linkable target
add_library(dte3603::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# Unit tests
option(BUILD_UNITTESTS_DAY1_2 "Build unittests Day 1 & 2" OFF)
if(BUILD_UNITTESTS_DAY1_2)
add_subdirectory(testing)
endif(BUILD_UNITTESTS_DAY1_2)
# Benchmarking
option(BUILD_BENCHMARKS_DAY1_2 "Build benchmarks Day 1 & 2" OFF)
if(BUILD_BENCHMARKS_DAY1_2)
add_subdirectory(benchmarking)
endif(BUILD_BENCHMARKS_DAY1_2)
include(../../cmake/testing_utils.cmake)
SETUP_BENCHMARK_ENV()
if(benchmark_FOUND)
set( BENCHMARKS_DIR benchmarks )
set( BENCHMARKS
predefined_sort_bechmarks
)
ADD_BENCHMARKS(dte3603::${PROJECT_NAME} ${BENCHMARKS_DIR} BENCHMARKS
dte3603::predef_shared)
endif(benchmark_FOUND)
// Unit test utils
#include <predef_shared/benchmark_fixtures/sort_bench_fixtures.h>
// Day 2 sort library
#include <day1_2_sort/counting_sort.h>
#include <day1_2_sort/binary_sort.h>
#include <day1_2_sort/radix_sort.h>
#include <day1_2_sort/custom_aa_sort.h>
// google benchmark
#include <benchmark/benchmark.h>
// stl
#include <memory>
#include <algorithm>
// Qualify predefined fixtures
using namespace dte3603::predef::benchmarking::sort::fixtures;
namespace alg = dte3603::sort::algorithms;
// Define benchmark fixtures for sorting of a sorted collection
BENCHMARK_DEFINE_F(SortedIntColF, stlSort)
(benchmark::State& st)
{
for (auto const& _ : st) std::sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(SortedIntColF, countingSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::counting_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(SortedIntColF, binarySort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::binary_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(SortedIntColF, radixSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::radix_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(SortedIntColF, AndAlxSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::custom_aa_sort(m_data.begin(), m_data.end());
}
// Define benchmark fixtures for sorting of a reverse sorted collection
BENCHMARK_DEFINE_F(ReverseIntColF, stlSort)
(benchmark::State& st)
{
for (auto const& _ : st) std::sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(ReverseIntColF, countingSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::counting_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(ReverseIntColF, binarySort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::binary_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(ReverseIntColF, radixSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::radix_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(ReverseIntColF, AndAlxSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::custom_aa_sort(m_data.begin(), m_data.end());
}
// Define benchmark fixtures for sorting of a organpipe sorted collection
BENCHMARK_DEFINE_F(OrganpipeIntColF, stlSort)
(benchmark::State& st)
{
for (auto const& _ : st) std::sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(OrganpipeIntColF, countingSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::counting_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(OrganpipeIntColF, binarySort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::binary_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(OrganpipeIntColF, radixSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::radix_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(OrganpipeIntColF, AndAlxSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::custom_aa_sort(m_data.begin(), m_data.end());
}
// Define benchmark fixtures for sorting of a sorted and rotated (by one index)
// collection
BENCHMARK_DEFINE_F(RotatedIntColF, stlSort)
(benchmark::State& st)
{
for (auto const& _ : st) std::sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(RotatedIntColF, countingSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::counting_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(RotatedIntColF, binarySort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::binary_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(RotatedIntColF, radixSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::radix_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(RotatedIntColF, AndAlxSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::custom_aa_sort(m_data.begin(), m_data.end());
}
// Define benchmark fixtures for sorting of a sorted and random collection of 0s
// and 1s
BENCHMARK_DEFINE_F(Random01IntColF, stlSort)
(benchmark::State& st)
{
for (auto const& _ : st) std::sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(Random01IntColF, countingSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::counting_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(Random01IntColF, binarySort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::binary_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(Random01IntColF, radixSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::radix_sort(m_data.begin(), m_data.end());
}
BENCHMARK_DEFINE_F(Random01IntColF, AndAlxSort)
(benchmark::State& st)
{
for (auto const& _ : st) alg::custom_aa_sort(m_data.begin(), m_data.end());
}
// Register Benchmark : benchmark sorting of a sorted collection using different
// algorithms
BENCHMARK_REGISTER_F(SortedIntColF, stlSort)
->RangeMultiplier(10)
->Range(1e4, 1e6);
BENCHMARK_REGISTER_F(SortedIntColF, countingSort)
->RangeMultiplier(10)
->Range(1e4, 1e6);
BENCHMARK_REGISTER_F(SortedIntColF, binarySort)
->RangeMultiplier(10)
->Range(1e4, 1e6);
BENCHMARK_REGISTER_F(SortedIntColF, radixSort)
->RangeMultiplier(10)
->Range(1e4, 1e6);
BENCHMARK_REGISTER_F(SortedIntColF, AndAlxSort)
->RangeMultiplier(10)
->Range(1e4, 1e6);