Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add cmake support #35

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3495840
Explicitly default/delete copy and move constructors for signal and o…
captaincrutches Nov 19, 2021
5847018
Add noexcept
captaincrutches Nov 19, 2021
7a6b322
Implemented copy and move for Spin_Mutex so all policies are now copy…
captaincrutches Nov 20, 2021
170350a
Move connections when moving an observer
captaincrutches Dec 30, 2021
a8f5dea
Fix TS_Policy tests by not trying to lock when we already have a lock…
captaincrutches Feb 7, 2022
f402654
Uncomment Test_Signal_Move and update test readme
captaincrutches Feb 7, 2022
7b84712
Since we're already clearing other's signals in move_connections_from…
captaincrutches Feb 7, 2022
82eaaf8
Make Spin_Mutex final
captaincrutches Feb 9, 2022
d6df597
Merge pull request #33 from captaincrutches/cc-move-constructors
NoAvailableAlias Feb 10, 2022
c9ac38f
Added try_lock and scoped_lock to policies.
NoAvailableAlias Feb 10, 2022
73811dc
Add cmake build support
ClausKlein Mar 3, 2022
65338e7
convert all tests to catch2
ClausKlein Mar 3, 2022
703c3de
prevent compiler and clang-tidy warnings
ClausKlein Mar 3, 2022
6eb86c0
add github action for CI
ClausKlein Mar 3, 2022
3a01476
disable developer mode for CI
ClausKlein Mar 3, 2022
668dc61
fix type in filename
ClausKlein Mar 3, 2022
1d2b66d
prevent gcc warning about extra ';'
ClausKlein Mar 3, 2022
69e2fbc
use g++-10 on linux
ClausKlein Mar 3, 2022
50404d0
linux needs to link -lphreads
ClausKlein Mar 3, 2022
549cc06
add clang-tidy config file
ClausKlein Mar 4, 2022
f07cba7
add example
ClausKlein Mar 6, 2022
1bf8efb
Merge branch 'feature/add-cmake-support' of github.com:ClausKlein/nan…
ClausKlein Mar 6, 2022
08ff2a2
prevent or ignore clang-tidy warnings
ClausKlein Mar 6, 2022
8afae28
change typdef to using ...
ClausKlein Mar 6, 2022
7f77bb7
without chrono for now
ClausKlein Mar 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# clang v12
#
Checks:
'-*,
-llvm-*,
-llvm-header-guard,
boost-*,
bugprone-*,
-bugprone-suspicious-include,
cert-*,
-cert-msc32-c,
-cert-msc51-cpp,
clang-analyzer-*,
-cppcoreguidelines-*,
concurrency-*,
-hicpp-*,
misc-*,
modernize-*,
-modernize-use-equals-default,
-modernize-use-trailing-return-type,
-modernize-use-nodiscard,
performance-*,
portability-*,
-readability-*,
-readability-identifier-naming,
'

HeaderFilterRegex: '.*'
WarningsAsErrors: 'clang*'
FormatStyle: file
UseColor: false
User: klein_cl

CheckOptions:
- { 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' }
- { key: readability-identifier-naming.NamespaceCase, value: CamelCase }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.MemberCase, value: camelBack }
- { key: readability-identifier-naming.MemberHungarianPrefix , value: On }
- { key: readability-identifier-naming.MemberPrefix, value: m_ }
# - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.StructCase, value: camel_Snake_Back }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
# - { key: readability-identifier-naming.VariablePrefix, value: '_' }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.EnumPrefix, value: 'E' }
- { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
- { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
# - { key: readability-identifier-naming.GlobalVariablePrefix, value: 'g' }
- { key: readability-identifier-naming.ConstexprFunctionCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprMethodCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableCase, value: camelBack }
...
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
name: Continuous Integration

on: [push, pull_request]

env:
CTEST_OUTPUT_ON_FAILURE: 1
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules

jobs:
test:
strategy:
fail-fast: false

matrix:
# XXX type: [static, shared]

os: [macos, ubuntu, windows]

include:
- {type: static, build: NO}
- {type: shared, build: YES}

runs-on: ${{ matrix.os }}-latest

steps:
- uses: actions/checkout@v1

- uses: actions/cache@v2
with:
path: "**/cpm_modules"
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}


- name: Install llvm-12 Ubuntu Host
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get install \
gcc-10 llvm-12 clang-12 libclang-12-dev clang-tidy-12 ||
echo IGNORED
CXX=g++-10 cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D ENABLE_DEVELOPER_MODE=NO # XXX -D BUILD_SHARED_LIBS=${{ matrix.build }}

- name: Configure
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D ENABLE_DEVELOPER_MODE=NO # XXX -D BUILD_SHARED_LIBS=${{ matrix.build }}

- name: Build
run: cmake --build build --config Release -j 4

- name: Test
working-directory: build
run: ctest -C Release --output-on-failure

# - name: Install
# run: cmake --install build --config Release --prefix stage

# - name: BuildWithInstalledVersion
# shell: bash
# run: |
# cmake -S examples -B build/test -D CMAKE_PREFIX_PATH=$PWD/stage -D CMAKE_EXPORT_COMPILE_COMMANDS=1
# cmake --build build/test --config Release -j 4

# - name: TestWithInstalledVersion
# working-directory: build/test
# run: ctest -C Release --output-on-failure

- name: Run clang-tidy on MacOS Host
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
export PATH=/usr/local/opt/llvm/bin/:${PATH}
perl -i.bak -pe 's#-I($CPM_SOURCE_CACHE)#-isystem $1#g' build/compile_commands.json
run-clang-tidy -p build

- name: Run clang-tidy on Ubuntu Host
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
perl -i.bak -pe 's#-I($CPM_SOURCE_CACHE)#-isystem $1#g' build/compile_commands.json
run-clang-tidy-12 -p build
124 changes: 124 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
cmake_minimum_required(VERSION 3.16...3.22)

# Not ideal to use this global variable, but necessary to make sure
# that tooling and projects use the same version
set(CMAKE_CXX_STANDARD 20)

# strongly encouraged to enable this globally to avoid conflicts between
# -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for example
# when compiling with PCH enabled
set(CMAKE_CXX_EXTENSIONS OFF)

# Note: by default ENABLE_DEVELOPER_MODE is True
# This means that all analysis (sanitizers, static analysis)
# is enabled and all warnings are treated as errors
# if you want to switch this behavior, change TRUE to FALSE
set(ENABLE_DEVELOPER_MODE TRUE CACHE BOOL "Enable 'developer mode'")

# Change this to false if you want to disable warnings_as_errors in developer mode
set(OPT_WARNINGS_AS_ERRORS_DEVELOPER_DEFAULT TRUE)

# ---- Add dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info
include(cmake/CPM.cmake)

# Add project_options v0.18.0, but my version! CK
# https://github.com/cpp-best-practices/project_options
CPMAddPackage("gh:ClausKlein/cmakelib#865af7a1339c03cc8b3cab0d3dcd01ec789f456c")
list(APPEND CMAKE_MODULE_PATH ${ProjectOptions_SRC_DIR})

# uncomment to enable vcpkg:
# # Setup vcpkg - should be called before defining project()
# run_vcpkg()

# Set the project name and language
project(
NanoSignalSlot
VERSION 0.0.1
# DESCRIPTION "Based on Starter Project With Best Practices for C++"
# HOMEPAGE_URL "https://github.com/cpp-best-practices/cpp_boilerplate_project"
LANGUAGES CXX)

get_property(BUILDING_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(BUILDING_MULTI_CONFIG)
if(NOT CMAKE_BUILD_TYPE)
# Make sure that all supported configuration types have their
# associated conan packages available. You can reduce this
# list to only the configuration types you use, but only if one
# is not forced-set on the command line for VS
message(TRACE "Setting up multi-config build types")
set(CMAKE_CONFIGURATION_TYPES
Debug
Release
RelWithDebInfo
MinSizeRel
CACHE STRING "Enabled build types" FORCE)
else()
message(TRACE "User chose a specific build type, so we are using that")
set(CMAKE_CONFIGURATION_TYPES
${CMAKE_BUILD_TYPE}
CACHE STRING "Enabled build types" FORCE)
endif()
endif()

include(DynamicProjectOptions)

# defaulted_project_options sets recommended defaults and provides user and developer
# modes and full GUI support for choosing options at configure time

# for more flexibility, look into project_options() macro

# Any default can be overridden
# set(<feature_name>_DEFAULT <value>) - set default for both user and developer modes
# set(<feature_name>_DEVELOPER_DEFAULT <value>) - set default for developer mode
# set(<feature_name>_USER_DEFAULT <value>) - set default for user mode

# Initialize project_options variable related to this project
# This overwrites `project_options` and sets `project_warnings`
# uncomment the options to enable them:
dynamic_project_options(
# Note: PCH is disabled by default in developer mode because these headers become
# globally included and they can mask other errors
PCH_HEADERS
<iostream>
<vector>
<string> # This is a list of headers to pre-compile, here are some common ones
# CONAN_OPTIONS # Extra options to pass to conan
# MSVC_WARNINGS # Override the defaults for the MSVC warnings
# CLANG_WARNINGS # Override the defaults for the CLANG warnings
# GCC_WARNINGS # Override the defaults for the GCC warnings
)

target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})

# configure files based on CMake configuration options
#TODO add_subdirectory(configured_files)
#TODO target_include_directories(project_options INTERFACE "${CMAKE_BINARY_DIR}")
target_include_directories(project_options INTERFACE include)

# Adding the examples:
add_subdirectory(examples)

# Adding the tests:
option(ENABLE_TESTING "Enable the tests" ON)
if(ENABLE_TESTING)
enable_testing()
message("Building Tests.")
add_subdirectory(tests)
endif()

# option(ENABLE_FUZZING "Enable the fuzz tests" OFF)
# if(ENABLE_FUZZING)
# message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
# add_subdirectory(fuzz_test)
# endif()

# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
if(MSVC)
get_all_targets(all_targets)
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
endif()

# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT test)
21 changes: 21 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(CPM_DOWNLOAD_VERSION 0.35.0)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})
11 changes: 11 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
find_package(Threads REQUIRED)

add_executable(
doc_view
doc_view.cpp
)

target_link_libraries(
doc_view PRIVATE project_warnings project_options Threads::Threads
)

Loading