mirror of
https://github.com/gelldur/EventBus.git
synced 2025-01-14 17:30:08 +08:00
Reorganize project layout
Inspired by: https://www.youtube.com/watch?v=6sWec7b0JIc
This commit is contained in:
parent
40d1d64878
commit
685562c632
@ -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(EventBusDev)
|
||||||
PROJECT(EventBus
|
|
||||||
VERSION 2.2.0
|
|
||||||
LANGUAGES CXX
|
|
||||||
)
|
|
||||||
|
|
||||||
ADD_LIBRARY(EventBus
|
add_subdirectory(lib/)
|
||||||
src/eventbus/EventCollector.cpp include/eventbus/EventCollector.h
|
|
||||||
include/eventbus/EventBus.h
|
|
||||||
)
|
|
||||||
ADD_LIBRARY(Dexode::EventBus ALIAS EventBus)
|
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(EventBus PUBLIC
|
enable_testing()
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
|
add_subdirectory(test/)
|
||||||
$<INSTALL_INTERFACE:include/>
|
add_subdirectory(sample/)
|
||||||
PRIVATE src/
|
add_subdirectory(performance/)
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBus PRIVATE
|
target_compile_options(EventBus PUBLIC
|
||||||
-Wall -pedantic
|
-Wall -pedantic
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
-Werror
|
-Werror
|
||||||
-Wno-error=deprecated-declarations
|
-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()
|
|
||||||
|
38
lib/CMakeLists.txt
Normal file
38
lib/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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!
|
||||||
|
|
||||||
|
# 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
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
|
||||||
|
$<INSTALL_INTERFACE:include/>
|
||||||
|
PRIVATE lib/src/
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS EventBus EXPORT EventBusConfig
|
||||||
|
ARCHIVE DESTINATION lib/
|
||||||
|
LIBRARY DESTINATION lib/
|
||||||
|
RUNTIME DESTINATION bin/
|
||||||
|
INCLUDES DESTINATION lib/include/
|
||||||
|
)
|
||||||
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION lib/include/ FILES_MATCHING PATTERN "*.h*")
|
||||||
|
install(EXPORT EventBusConfig
|
||||||
|
DESTINATION cmake/
|
||||||
|
NAMESPACE Dexode::
|
||||||
|
)
|
||||||
|
export(TARGETS EventBus FILE EventBusConfig.cmake)
|
@ -54,6 +54,7 @@ public:
|
|||||||
using Vector = VectorImpl<Event>;
|
using Vector = VectorImpl<Event>;
|
||||||
|
|
||||||
assert(callback && "callback should be valid");//Check for valid object
|
assert(callback && "callback should be valid");//Check for valid object
|
||||||
|
std::unique_ptr<VectorInterface> vector2;
|
||||||
|
|
||||||
std::unique_ptr<VectorInterface>& vector = _callbacks[getTypeId<Event>()];
|
std::unique_ptr<VectorInterface>& vector = _callbacks[getTypeId<Event>()];
|
||||||
if (vector == nullptr)
|
if (vector == nullptr)
|
||||||
@ -63,6 +64,7 @@ public:
|
|||||||
assert(dynamic_cast<Vector*>(vector.get()));
|
assert(dynamic_cast<Vector*>(vector.get()));
|
||||||
Vector* vectorImpl = static_cast<Vector*>(vector.get());
|
Vector* vectorImpl = static_cast<Vector*>(vector.get());
|
||||||
vectorImpl->add(token, callback);
|
vectorImpl->add(token, callback);
|
||||||
|
std::unique_ptr<VectorInterface> vector3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -49,6 +49,7 @@ EventCollector::~EventCollector()
|
|||||||
|
|
||||||
EventCollector& EventCollector::operator=(const EventCollector& other)
|
EventCollector& EventCollector::operator=(const EventCollector& other)
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<int> vector3;
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
@ -1,17 +1,23 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
|
||||||
|
|
||||||
# http://www.levelofindirection.com/journal/2010/12/28/unit-testing-in-c-and-objective-c-just-got-easier.html
|
# http://www.levelofindirection.com/journal/2010/12/28/unit-testing-in-c-and-objective-c-just-got-easier.html
|
||||||
# Thanks for CATCH!
|
# Thanks for CATCH!
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(benchmark/)
|
add_subdirectory(benchmark/)
|
||||||
|
|
||||||
|
if(NOT TARGET Dexode::EventBus)
|
||||||
|
find_package(EventBus CONFIG REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
# If you want to compare with CCNotificationCenter read about it in README and uncomment line below
|
# If you want to compare with CCNotificationCenter read about it in README and uncomment line below
|
||||||
#INCLUDE(cocos2d-x-compare/Cocos2dxCompare.cmake)
|
#INCLUDE(cocos2d-x-compare/Cocos2dxCompare.cmake)
|
||||||
|
|
||||||
ADD_EXECUTABLE(EventBusPerformance
|
add_executable(EventBusPerformance
|
||||||
eventbus/EventBusPerformance.cpp
|
src/EventBusPerformance.cpp
|
||||||
${CCNOTIFICATION_CENTER_SRC}
|
${CCNOTIFICATION_CENTER_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC
|
target_compile_options(EventBusPerformance PUBLIC
|
||||||
-Wall -pedantic
|
-Wall -pedantic
|
||||||
-Wno-unused-private-field
|
-Wno-unused-private-field
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
@ -19,27 +25,18 @@ TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC
|
|||||||
-Werror
|
-Werror
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(EVENTBUS_DEBUG_FLAGS
|
set(EVENTBUS_DEBUG_FLAGS
|
||||||
-O0 -fno-inline
|
-O0 -fno-inline
|
||||||
-DDEBUG
|
-DDEBUG
|
||||||
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(EVENTBUS_RELEASE_FLAGS
|
|
||||||
-DNDEBUG
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
|
target_compile_options(EventBusPerformance PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
|
||||||
TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC "$<$<CONFIG:RELEASE>:${EVENTBUS_RELEASE_FLAGS}>")
|
|
||||||
|
|
||||||
SET_TARGET_PROPERTIES(EventBusPerformance PROPERTIES
|
target_include_directories(EventBusPerformance PUBLIC
|
||||||
CXX_STANDARD 14
|
src/
|
||||||
CXX_STANDARD_REQUIRED YES
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(EventBusPerformance PUBLIC
|
|
||||||
./
|
|
||||||
${CCNOTIFICATION_CENTER_INCLUDE}
|
${CCNOTIFICATION_CENTER_INCLUDE}
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(EventBusPerformance PUBLIC Dexode::EventBus benchmark)
|
target_link_libraries(EventBusPerformance PUBLIC Dexode::EventBus benchmark)
|
||||||
|
@ -1,23 +1,13 @@
|
|||||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.2 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
|
||||||
|
|
||||||
PROJECT(Sample LANGUAGES CXX)
|
project(Sample LANGUAGES CXX)
|
||||||
|
|
||||||
ADD_EXECUTABLE(Sample
|
add_executable(Sample
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(Sample PUBLIC
|
if(NOT TARGET Dexode::EventBus)
|
||||||
-Wall -pedantic
|
find_package(EventBus CONFIG REQUIRED)
|
||||||
-Wno-unused-private-field
|
endif()
|
||||||
-Wnon-virtual-dtor
|
|
||||||
-Wno-gnu
|
|
||||||
-Werror
|
|
||||||
)
|
|
||||||
|
|
||||||
SET_TARGET_PROPERTIES(Sample PROPERTIES
|
target_link_libraries(Sample PRIVATE Dexode::EventBus)
|
||||||
CXX_STANDARD 14
|
|
||||||
)
|
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(../ EventBus/)
|
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(Sample PRIVATE Dexode::EventBus)
|
|
||||||
|
@ -1,42 +1,52 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
|
||||||
|
|
||||||
# http://www.levelofindirection.com/journal/2010/12/28/unit-testing-in-c-and-objective-c-just-got-easier.html
|
# http://www.levelofindirection.com/journal/2010/12/28/unit-testing-in-c-and-objective-c-just-got-easier.html
|
||||||
# Thanks for CATCH!
|
# Thanks for CATCH!
|
||||||
|
|
||||||
ADD_EXECUTABLE(EventBusTest
|
project(EventBusTest)
|
||||||
eventbus/EventCollectorTest.cpp
|
|
||||||
eventbus/NotifierTest.cpp
|
# Dependencies
|
||||||
|
enable_testing()
|
||||||
|
if(NOT TARGET Dexode::EventBus)
|
||||||
|
find_package(EventBus CONFIG REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Catch2 REQUIRED)
|
||||||
|
|
||||||
|
# Target definition
|
||||||
|
add_executable(EventBusTest
|
||||||
|
src/EventCollectorTest.cpp
|
||||||
|
src/NotifierTest.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET_TARGET_PROPERTIES(EventBusTest PROPERTIES
|
target_compile_options(EventBusTest PUBLIC
|
||||||
CXX_STANDARD 14
|
|
||||||
CXX_STANDARD_REQUIRED YES
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC
|
|
||||||
-Wall -pedantic
|
-Wall -pedantic
|
||||||
|
-Wno-unused-private-field
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
|
-Wno-gnu
|
||||||
-Werror
|
-Werror
|
||||||
-Wno-error=deprecated-declarations
|
|
||||||
)
|
)
|
||||||
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusTest PRIVATE
|
|
||||||
-Wno-error=unknown-argument
|
|
||||||
)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
SET(EVENTBUS_DEBUG_FLAGS
|
# Don't do such thing:
|
||||||
|
# if(CMAKE_BUILD_TYPE STREQUAL DEBUG)
|
||||||
|
# ....
|
||||||
|
# else()
|
||||||
|
# ...
|
||||||
|
# endif()
|
||||||
|
#
|
||||||
|
# Instead do this way: (It will work for Visual Studio)
|
||||||
|
# target_compile_definitions(foo PRIVATE "VERBOSITY=$<IF:$<BOOL:${VERBOSE}>,30,10>")
|
||||||
|
|
||||||
|
|
||||||
|
set(EVENTBUS_DEBUG_FLAGS
|
||||||
-O0 -fno-inline
|
-O0 -fno-inline
|
||||||
-DDEBUG
|
-DDEBUG
|
||||||
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
#-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(EVENTBUS_RELEASE_FLAGS
|
target_compile_options(EventBusTest PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
|
||||||
-DNDEBUG
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
|
|
||||||
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC "$<$<CONFIG:RELEASE>:${EVENTBUS_RELEASE_FLAGS}>")
|
|
||||||
|
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(EventBusTest PUBLIC Catch/single_include/)
|
target_link_libraries(EventBusTest PUBLIC Dexode::EventBus Catch2::Catch)
|
||||||
TARGET_LINK_LIBRARIES(EventBusTest PUBLIC Dexode::EventBus)
|
|
||||||
|
|
||||||
|
add_test(NAME EventBus.UnitTests COMMAND EventBusTest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user