Skip to content

Commit

Permalink
add example to test the concept
Browse files Browse the repository at this point in the history
make it works
  • Loading branch information
ClausKlein committed Sep 25, 2021
1 parent 38c96c9 commit 95a34f6
Show file tree
Hide file tree
Showing 6 changed files with 661 additions and 14 deletions.
41 changes: 41 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
Checks:
'-*,
cert-*,-cert-err58-cpp,
clang-diagnostic-*,
clang-analyzer-*,
hicpp-*,-hicpp-avoid-c-arrays,-hicpp-no-array-decay,hicpp-explicit-*,-hicpp-use-equals-default,-hicpp-signed-bitwise,-hicpp-special-member-functions,-hicpp-use-equals-delete,
misc-*,-misc-non-private-member-variables-in-classes,
modernize-*,modernize-use-*,modernize-avoid-c-arrays,-modernize-use-trailing-return-type,
performance-*,
portability-*,
readablity-*,
'
WarningsAsErrors: 'clang-analyzer-*'
HeaderFilterRegex: '.*\.hpp$'
AnalyzeTemporaryDtors: false
FormatStyle: file
User: klein_cl
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

155 changes: 155 additions & 0 deletions .cmake-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
_help_parse: Options affecting listfile parsing
parse:
_help_additional_commands:
- Specify structure for custom cmake functions
additional_commands:
catch_discover_tests:
pargs:
nargs: '*'
flags: []
kwargs:
OUTPUT_DIR: 1
OUTPUT_PREFIX: 1
OUTPUT_SUFFIX: 1
REPORTER: 1
TEST_PREFIX: 1
conan_add_remote:
pargs:
nargs: '*'
flags: []
kwargs:
INDEX: 1
NAME: 1
URL: 1
conan_cmake_install:
pargs:
nargs: '*'
flags: []
kwargs:
BUILD: +
INSTALL_FOLDER: 1
LOCKFILE: 1
LOCKFILE_NODE_ID: 1
LOCKFILE_OUT: 1
PATH_OR_REFERENCE: 1
REFERENCE: 1
REMOTE: 1
ENV: +
ENV_BUILD: +
ENV_HOST: +
GENERATOR: +
OPTIONS: +
OPTIONS_BUILD: +
OPTIONS_HOST: +
PROFILE: +
PROFILE_BUILD: +
PROFILE_HOST: +
SETTINGS: +
SETTINGS_BUILD: +
SETTINGS_HOST: +
cpmaddpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMAddPackage
kwargs: &id001
DOWNLOAD_COMMAND: 1
DOWNLOAD_NAME: 1
DOWNLOAD_NO_EXTRACT: 1
DOWNLOAD_ONLY: 1
FIND_PACKAGE_ARGUMENTS: 1
FORCE: 1
GITHUB_REPOSITORY: 1
GITLAB_REPOSITORY: 1
GIT_REPOSITORY: 1
GIT_SHALLOW: 1
GIT_TAG: 1
HTTP_PASSWORD: 1
HTTP_USERNAME: 1
NAME: 1
NO_CACHE: 1
SOURCE_DIR: 1
SVN_REPOSITORY: 1
SVN_REVISION: 1
URL: 1
URL_HASH: 1
URL_MD5: 1
VERSION: 1
OPTIONS: +
cpmfindpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMFindPackage
kwargs: *id001
cpmdeclarepackage:
pargs:
nargs: '*'
flags: []
spelling: CPMDeclarePackage
kwargs: *id001
packageproject:
pargs:
nargs: '*'
flags: []
spelling: packageProject
kwargs:
BINARY_DIR: 1
COMPATIBILITY: 1
DISABLE_VERSION_SUFFIX: 1
EXPORT_HEADER: 1
INCLUDE_DESTINATION: 1
INCLUDE_DIR: 1
NAME: 1
NAMESPACE: 1
VERSION: 1
VERSION_HEADER: 1
DEPENDENCIES: +
cpmusepackagelock:
pargs: 1
spelling: CPMUsePackageLock
cpmregisterpackage:
pargs: 1
spelling: CPMRegisterPackage
cpmgetpackageversion:
pargs: 2
spelling: CPMGetPackageVersion
_help_format: Options affecting formatting.
format:
_help_line_width:
- How wide to allow formatted cmake files
line_width: 120
_help_tab_size:
- How many spaces to tab for indent
tab_size: 2
_help_max_pargs_hwrap:
- If a positional argument group contains more than this many
- arguments, then force it to a vertical layout.
max_pargs_hwrap: 3
_help_separate_ctrl_name_with_space:
- If true, separate flow control names from their parentheses
- with a space
separate_ctrl_name_with_space: false
_help_separate_fn_name_with_space:
- If true, separate function names from parentheses with a
- space
separate_fn_name_with_space: false
_help_dangle_parens:
- If a statement is wrapped to more than one line, than dangle
- the closing parenthesis on its own line.
dangle_parens: false
_help_line_ending:
- What style line endings to use in the output.
line_ending: unix
_help_markup: Options affecting comment reflow and formatting.
markup:
_help_bullet_char:
- What character to use for bulleted lists
bullet_char: '*'
_help_enum_char:
- What character to use as punctuation after numerals in an
- enumerated list
enum_char: .
_help_enable_markup:
- enable comment markup parsing and reflow
enable_markup: false
12 changes: 7 additions & 5 deletions src/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ function(set_project_warnings project_name WARNINGS_AS_ERRORS MSVC_WARNINGS CLAN
)
endif()

if(${WARNINGS_AS_ERRORS})
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()

if (NOT ${GCC_WARNINGS})
set(GCC_WARNINGS
${CLANG_WARNINGS}
Expand All @@ -68,6 +63,13 @@ function(set_project_warnings project_name WARNINGS_AS_ERRORS MSVC_WARNINGS CLAN
)
endif()

message(WARNING "${WARNINGS_AS_ERRORS}")
if(WARNINGS_AS_ERRORS STREQUAL TRUE)
list(APPEND CLANG_WARNINGS -Werror)
list(APPEND GCC_WARNINGS -Werror)
list(APPEND MSVC_WARNINGS /WX)
endif()

if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
Expand Down
18 changes: 9 additions & 9 deletions src/Index.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.16)

include(CMakeParseArguments) # to support cmake 3.4 and older
include(CMakeParseArguments)

set(CMAKELIB_SRC_DIR ${CMAKE_CURRENT_LIST_DIR})

include("${CMAKELIB_SRC_DIR}/PreventInSourceBuilds.cmake")

#
# Params:
# - WARNINGS_AS_ERRORS: Treat compiler warnings as errors
# - ENABLE_CPPCHECK: Enable static analysis with cppcheck
# - ENABLE_CLANG_TIDY: Enable static analysis with clang-tidy
# - ENABLE_INCLUDE_WHAT_YOU_USE: Enable static analysis with include-what-you-use
# - ENABLE_COVERAGE: Enable coverage reporting for gcc/clang
# - Enable_CACHE: Enable cache if available
# - ENABLE_CACHE: Enable cache if available
# - ENABLE_PCH: Enable Precompiled Headers
# - ENABLE_CONAN: Use Conan for dependency management
# - ENABLE_DOXYGEN: Enable doxygen doc builds of source
Expand Down Expand Up @@ -58,8 +60,6 @@ macro(cmakelib)
enable_ipo()
endif()

include("${CMAKELIB_SRC_DIR}/PreventInSourceBuilds.cmake")

# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)

Expand All @@ -72,7 +72,7 @@ macro(cmakelib)
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)

if (${cmakelib_Enable_CACHE})
if (${cmakelib_ENABLE_CACHE})
# enable cache system
include("${CMAKELIB_SRC_DIR}/Cache.cmake")
enable_cache()
Expand All @@ -87,15 +87,15 @@ macro(cmakelib)
# standard compiler warnings
include("${CMAKELIB_SRC_DIR}/CompilerWarnings.cmake")
set_project_warnings(
"project_warnings"
project_warnings
WARNINGS_AS_ERRORS=${cmakelib_WARNINGS_AS_ERRORS}
MSVC_WARNINGS=${cmakelib_MSVC_WARNINGS}
CLANG_WARNINGS=${cmakelib_CLANG_WARNINGS}
GCC_WARNINGS=${cmakelib_GCC_WARNINGS})

include("${CMAKELIB_SRC_DIR}/Tests.cmake")
if(${cmakelib_ENABLE_COVERAGE})
enable_coverage()
enable_coverage(${PROJECT_NAME})
endif()

# sanitizer options if supported by compiler
Expand Down Expand Up @@ -149,7 +149,7 @@ macro(cmakelib)

if(${cmakelib_ENABLE_UNITY})
# Add for any project you want to apply unity builds for
set_target_properties(main PROPERTIES UNITY_BUILD ON)
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ON)
endif()

endmacro()
46 changes: 46 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.16...3.21)

project(escape VERSION 0.1.0 LANGUAGES CXX)

# Add cmakelib
# include(FetchContent)
# FetchContent_Declare(cmakelib URL https://github.com/aminya/cmakelib/archive/refs/heads/main.zip)
# FetchContent_MakeAvailable(cmakelib)
# include(${cmakelib_SOURCE_DIR}/Index.cmake)
include(../Index.cmake)

add_library(escape INTERFACE)

# Initialize cmakelib
# uncomment the options to enable them
cmakelib(
ENABLE_CACHE
# ENABLE_CONAN
# WARNINGS_AS_ERRORS
# ENABLE_CPPCHECK
ENABLE_CLANG_TIDY
# ENABLE_INCLUDE_WHAT_YOU_USE
ENABLE_COVERAGE
# ENABLE_PCH
# ENABLE_DOXYGEN
# ENABLE_IPO
# ENABLE_USER_LINKER
ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
# ENABLE_SANITIZER_ADDRESS
# ENABLE_SANITIZER_LEAK
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
)

# project_options is defined inside cmakelib
target_compile_features(project_options INTERFACE cxx_std_17)
target_link_libraries(escape INTERFACE project_options project_warnings)

# add src, tests, etc here:
add_executable(test_escape escape.cpp)
target_link_libraries(test_escape PRIVATE escape)

enable_testing()
add_test(NAME test_escape COMMAND test_escape)
Loading

0 comments on commit 95a34f6

Please sign in to comment.