Skip to content

Commit

Permalink
Merge pull request #1 from noctera/experimental
Browse files Browse the repository at this point in the history
Refactor: CMake files
  • Loading branch information
noctera authored May 8, 2022
2 parents 0a057c1 + 5e00785 commit 7168e31
Show file tree
Hide file tree
Showing 25 changed files with 2,533 additions and 237 deletions.
72 changes: 15 additions & 57 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,58 +1,16 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 500
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 2
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Auto
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: true
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
SpaceBeforeParens: ControlStatements
BasedOnStyle: Google
AccessModifierOffset: '-2'
AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlwaysBreakTemplateDeclarations: 'No'
BreakBeforeBraces: Attach
ColumnLimit: '100'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
IndentWidth: '2'
NamespaceIndentation: All
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'true'
...
57 changes: 57 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
format:
tab_size: 2
line_width: 100
dangle_parens: true

parse:
additional_commands:
cpmaddpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMAddPackage
kwargs: &cpmaddpackagekwargs
NAME: 1
FORCE: 1
VERSION: 1
GIT_TAG: 1
DOWNLOAD_ONLY: 1
GITHUB_REPOSITORY: 1
GITLAB_REPOSITORY: 1
GIT_REPOSITORY: 1
SVN_REPOSITORY: 1
SVN_REVISION: 1
SOURCE_DIR: 1
DOWNLOAD_COMMAND: 1
FIND_PACKAGE_ARGUMENTS: 1
NO_CACHE: 1
GIT_SHALLOW: 1
URL: 1
URL_HASH: 1
URL_MD5: 1
DOWNLOAD_NAME: 1
DOWNLOAD_NO_EXTRACT: 1
HTTP_USERNAME: 1
HTTP_PASSWORD: 1
OPTIONS: +
cpmfindpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMFindPackage
kwargs: *cpmaddpackagekwargs
packageproject:
pargs:
nargs: '*'
flags: []
spelling: packageProject
kwargs:
NAME: 1
VERSION: 1
NAMESPACE: 1
INCLUDE_DIR: 1
INCLUDE_DESTINATION: 1
BINARY_DIR: 1
COMPATIBILITY: 1
VERSION_HEADER: 1
DEPENDENCIES: +
81 changes: 54 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,66 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(AlgoCpp
LANGUAGES CXX
VERSION 0.0.1
project(
AlgoCpp
LANGUAGES CXX
VERSION 0.0.1
)

find_package( OpenCV REQUIRED )
include(CTest)
# ---- Include guards ----

SET(ALGOCPP_BUILD_EXAMPLES ON CACHE BOOL "Enables example building" FORCE)
SET(ALGOCPP_BUILD_TESTS ON CACHE BOOL "Enables tests building" FORCE)
SET(ALGOCPP_BUILD_BENCHMARK OFF CACHE BOOL "Enables benchmark building" FORCE)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()

add_library(${PROJECT_NAME} INTERFACE)
# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info

target_include_directories(
${PROJECT_NAME}
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
include(cmake/CPM.cmake)

target_compile_features(
${PROJECT_NAME}
INTERFACE
cxx_std_17
)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")

if (ALGOCPP_BUILD_EXAMPLES)
set(ExamplesDir "${CMAKE_CURRENT_SOURCE_DIR}/examples/")
add_subdirectory(${ExamplesDir})
endif()
# ---- Add source files ----

if (ALGOCPP_BUILD_TESTS)
set(TestsDir "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
add_subdirectory(${TestsDir})
endif()
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
# automatically. Keep that in mind when changing files, or explicitly mention them here.
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")

# ---- Create library ----

# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} INTERFACE ${headers} ${sources})

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")

# Link dependencies
target_include_directories(
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.

# the location where the project's version header will be placed should match the project's regular
# header paths
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
)
Loading

0 comments on commit 7168e31

Please sign in to comment.