diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..526a376
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,127 @@
+# Checkout config tool: https://zed0.co.uk/clang-format-configurator/
+# Or http://cf.monofraps.net/
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+# https://github.com/01org/parameter-framework/blob/master/.clang-format
+
+# Tested on: clang-format version 6.0.1
+
+
+# Common settings
+BasedOnStyle: WebKit
+TabWidth: 4
+IndentWidth: 4
+UseTab: Always
+ColumnLimit: 100
+
+# Other languages JavaScript, Proto
+
+---
+Language: Cpp
+
+# http://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code
+# int formatted_code;
+# // clang-format off
+# void unformatted_code ;
+# // clang-format on
+# void formatted_code_again;
+
+DisableFormat: false
+Standard: Cpp11
+
+AccessModifierOffset: -4
+AlignAfterOpenBracket: true
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: false
+BinPackParameters: false
+
+# Configure each individual brace in BraceWrapping
+BreakBeforeBraces: Custom
+# Control of individual brace wrapping cases
+BraceWrapping: {
+ AfterClass: 'true'
+ AfterControlStatement: 'true'
+ AfterEnum : 'true'
+ AfterFunction : 'true'
+ AfterNamespace : 'true'
+ AfterStruct : 'true'
+ AfterUnion : 'true'
+ BeforeCatch : 'true'
+ BeforeElse : 'true'
+ IndentBraces : 'false'
+ AfterExternBlock : 'true'
+ SplitEmptyFunction : 'false'
+ SplitEmptyRecord : 'false'
+ SplitEmptyNamespace : 'true'
+}
+
+BreakAfterJavaFieldAnnotations: true
+BreakBeforeInheritanceComma: false
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BreakStringLiterals: true
+
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+ExperimentalAutoDetectBinPacking: false
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IndentCaseLabels: false
+FixNamespaceComments: true
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+JavaScriptQuotes: Double
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: Never
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceAfterTemplateKeyword: true
+
+SortUsingDeclarations: true
+SortIncludes: true
+
+# Comments are for developers, they should arrange them
+ReflowComments: false
+
+IncludeBlocks: Preserve
+IndentPPDirectives: AfterHash
+---
diff --git a/.gitmodules b/.gitmodules
index bb0e98b..17626a0 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
-[submodule "test/Catch"]
- path = test/Catch
- url = https://github.com/philsquared/Catch.git
[submodule "performance/benchmark"]
path = performance/benchmark
url = https://github.com/google/benchmark.git
diff --git a/.travis.yml b/.travis.yml
index 8f2c5d8..8f0629c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,37 +1,54 @@
-os: linux
-dist: trusty
-sudo: require
language: cpp
+sudo: false
-addons:
- apt:
- sources:
- - llvm-toolchain-precise-3.9
- - ubuntu-toolchain-r-test
- packages:
- - clang-3.9
- - gcc-6
- - g++-6
+common_sources: &all_sources
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-trusty
+ - llvm-toolchain-trusty-3.9
+ - llvm-toolchain-trusty-4.0
+ - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-trusty-6.0
matrix:
- include:
- - compiler: gcc
- env: COMPILER=g++-6
+ exclude: # On OSX g++ is a symlink to clang++ by default
+ - os: osx
+ compiler: gcc
- - compiler: clang
- env: COMPILER=clang++-3.9
+ include:
+ - os: linux
+ compiler: gcc
+ addons:
+ apt:
+ sources: *all_sources
+ packages: ['gcc-7', 'g++-7', 'cmake']
+ env: COMPILER='g++-7'
+
+ - os: linux
+ compiler: clang
+ addons:
+ apt:
+ sources: *all_sources
+ packages: ['clang-6.0', 'libstdc++-6-dev', 'cmake']
+ env: COMPILER='clang++-6.0'
+
+ - os: osx
+ osx_image: xcode9.4
+ compiler: clang
+ env: COMPILER='clang++'
before_install:
- - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq update; fi
-
-before_script:
- - if [ "$COMPILER" = "g++-6" ]; then export CXX="g++-6" CC="gcc-6"; fi
- - if [ "$COMPILER" = "clang++-3.9" ]; then export CXX="clang++-3.9" CC="clang-3.9"; fi
+ # Install catch 2 dependency
+ - wget https://github.com/catchorg/Catch2/archive/v2.2.3.zip
+ - unzip v2.2.3.zip && cd Catch2-2.2.3 && mkdir -p build/ && cd build/
+ - cmake -DCMAKE_BUILD_TYPE=Release .. -DCMAKE_INSTALL_PREFIX=~/.local/ && cmake --build . --target install
+ - cd ../..
script:
- - mkdir build-debug && cd build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=YES .. && cmake --build .
- - ./test/EventBusTest # Run tests
- - cd .. # exit from build-debug
- - mkdir build-release && cd build-release && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=YES .. && cmake --build .
- - ./test/EventBusTest # Run tests
+ #Build & Install library
+ - (mkdir -p lib/build-debug/ && cd lib/build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/.local/ .. && cmake --build . --target install)
+ - (mkdir -p lib/build-release/ && cd lib/build-release && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/.local/ .. && cmake --build . --target install)
+ # Run tests
+ - (mkdir -p test/build-debug/ && cd test/build-debug && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/.local/ .. && cmake --build . && ctest -V .)
+ - (mkdir -p test/build-release/ && cd test/build-release && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/.local/ .. && cmake --build . && ctest -V .)
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dea4d7c..f93f0a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,66 +1,20 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.2 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
-OPTION(PERFORMANCE "Enable/Disable performance subdirectory" OFF)
+# Layout of project is inspired by: https://youtu.be/6sWec7b0JIc?t=20m50s
+# This top level CMakeLists should be used for development
-# BUILD_SHARED_LIBS can controll build type!
-PROJECT(EventBus
- VERSION 2.2.0
- LANGUAGES CXX
- )
+project(EventBusDev)
-ADD_LIBRARY(EventBus
- src/eventbus/EventCollector.cpp include/eventbus/EventCollector.h
- include/eventbus/EventBus.h
- )
-ADD_LIBRARY(Dexode::EventBus ALIAS EventBus)
+add_subdirectory(lib/)
-TARGET_INCLUDE_DIRECTORIES(EventBus PUBLIC
- $
- $
- PRIVATE src/
- )
+enable_testing()
+add_subdirectory(test/)
+add_subdirectory(sample/)
+add_subdirectory(performance/)
-TARGET_COMPILE_OPTIONS(EventBus PRIVATE
+target_compile_options(EventBus PUBLIC
-Wall -pedantic
-Wnon-virtual-dtor
-Werror
-Wno-error=deprecated-declarations
)
-
-IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- TARGET_COMPILE_OPTIONS(EventBus PRIVATE
- -Wno-error=unknown-argument
- -Wno-error=unused-command-line-argument
- )
-ENDIF()
-
-SET_TARGET_PROPERTIES(EventBus PROPERTIES
- CXX_STANDARD 14
- )
-
-IF(NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
- TARGET_COMPILE_FEATURES(EventBus
- PUBLIC cxx_auto_type
- )
-ENDIF()
-
-INSTALL(TARGETS EventBus EXPORT EventBusConfig
- ARCHIVE DESTINATION lib/
- LIBRARY DESTINATION lib/
- RUNTIME DESTINATION bin/
- INCLUDES DESTINATION include/
- )
-INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h*")
-INSTALL(EXPORT EventBusConfig
- DESTINATION cmake/
- NAMESPACE Dexode::
- )
-EXPORT(TARGETS EventBus FILE EventBusConfig.cmake)
-
-IF(BUILD_TESTING)
- ADD_SUBDIRECTORY(test/)
-ENDIF()
-
-IF(PERFORMANCE)
- ADD_SUBDIRECTORY(performance/)
-ENDIF()
diff --git a/README.md b/README.md
index 6771850..85dcd08 100644
--- a/README.md
+++ b/README.md
@@ -180,8 +180,12 @@ TARGET_LINK_LIBRARIES(MyExecutable PUBLIC Dexode::EventBus)
Also if you want you can install library and add it at any way you want.
Eg.
```commandline
-mkdir Release && cd Release
-cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install ..
+mkdir -p lib/build/
+cd lib/build
+cmake -DCMAKE_BUILD_TYPE=Relase -DCMAKE_INSTALL_PREFIX=~/.local/ ..
+
+cmake --build . --target install
+# OR
make && make install
```
@@ -205,6 +209,7 @@ checkNotifyFor10kListenersWhenNoOneListens_CCNotificationCenter 127388 ns
- Thread safe EventBus ?
- Verbose messages for easy debugging ?
- Generating graph flow ?
+- Add nice documentation [like in POCO](https://pocoproject.org/slides/090-NotificationsEvents.pdf)
- ...
# Issues ?
@@ -217,6 +222,11 @@ Please report here issue / question / whatever in 99% I will answer ;)
- [swietlana](https://github.com/swietlana) for english correction and support ;)
- [ruslo](https://github.com/ruslo) for this great example: https://github.com/forexample/package-example
+## For modern cmake refer
+
+ - https://github.com/forexample/package-example
+ - https://www.youtube.com/watch?v=6sWec7b0JIc
+
# License
EventBus source code can be used according to the **Apache License, Version 2.0**.
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 0000000..7131941
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1,104 @@
+cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
+
+# BUILD_SHARED_LIBS can controll build type!
+project(EventBus
+ VERSION 2.2.0
+ LANGUAGES CXX
+ )
+
+# Dependencies
+# No dependencies for EventBus yay!
+
+# Introduce variables:
+# * CMAKE_INSTALL_LIBDIR
+# * CMAKE_INSTALL_BINDIR
+# * CMAKE_INSTALL_INCLUDEDIR
+include(GNUInstallDirs)
+
+# Layout. This works for all platforms:
+# * /lib*/cmake/
+# * /lib*/
+# * /include/
+set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+
+# Library definition
+add_library(EventBus
+ src/EventCollector.cpp include/eventbus/EventCollector.h
+ include/eventbus/EventBus.h
+ )
+add_library(Dexode::EventBus ALIAS EventBus)
+
+target_compile_features(EventBus PUBLIC cxx_std_14)
+
+target_include_directories(EventBus PUBLIC
+ $
+ $
+ PRIVATE lib/src/
+ )
+
+# Add definitions for targets
+# Values:
+# * Debug: -DEVENTBUS_DEBUG=1
+# * Release: -DEVENTBUS_DEBUG=0
+# * other: -DEVENTBUS_DEBUG=0
+target_compile_definitions(EventBus PUBLIC "EVENTBUS_DEBUG=$")
+
+
+# Configuration
+set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
+set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
+set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+set(namespace "Dexode::")
+
+# Targets:
+# * /lib/libEventBus.a
+# * header location after install: /include/eventbus/EventBus.h
+# * headers can be included by C++ code `#include `
+install(TARGETS EventBus
+ EXPORT "${TARGETS_EXPORT_NAME}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+ )
+
+# Export headers
+install(DIRECTORY include/eventbus
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+ )
+
+# Include module with fuction 'write_basic_package_version_file'
+include(CMakePackageConfigHelpers)
+
+# Configure 'ConfigVersion.cmake'
+# Use:
+# * PROJECT_VERSION
+write_basic_package_version_file(
+ "${version_config}" COMPATIBILITY SameMajorVersion
+)
+
+# Configure 'Config.cmake'
+# Use variables:
+# * TARGETS_EXPORT_NAME
+# * PROJECT_NAME
+configure_package_config_file(
+ "cmake/Config.cmake.in"
+ "${project_config}"
+ INSTALL_DESTINATION "${config_install_dir}"
+)
+
+# Config
+# * /lib/cmake/EventBusventBusConfig.cmake
+# * /lib/cmake/EventBus/EventBusConfigVersion.cmake
+install(
+ FILES "${project_config}" "${version_config}"
+ DESTINATION "${config_install_dir}"
+)
+
+# Config
+# * /lib/cmake/EventBus/EventBusTargets.cmake
+install(EXPORT "${TARGETS_EXPORT_NAME}"
+ DESTINATION "${config_install_dir}"
+ NAMESPACE "${namespace}"
+ )
diff --git a/lib/cmake/Config.cmake.in b/lib/cmake/Config.cmake.in
new file mode 100644
index 0000000..b06af21
--- /dev/null
+++ b/lib/cmake/Config.cmake.in
@@ -0,0 +1,4 @@
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
+check_required_components("@PROJECT_NAME@")
diff --git a/include/eventbus/EventBus.h b/lib/include/eventbus/EventBus.h
similarity index 64%
rename from include/eventbus/EventBus.h
rename to lib/include/eventbus/EventBus.h
index df4a8f7..d4ffc7e 100644
--- a/include/eventbus/EventBus.h
+++ b/lib/include/eventbus/EventBus.h
@@ -5,15 +5,28 @@
#include
#include