Reorganize project layout

Inspired by: https://www.youtube.com/watch?v=6sWec7b0JIc
This commit is contained in:
Dawid Drozd 2018-07-24 12:47:10 +02:00
parent 40d1d64878
commit 685562c632
11 changed files with 108 additions and 116 deletions

View File

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/>
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()

38
lib/CMakeLists.txt Normal file
View 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)

View File

@ -54,6 +54,7 @@ public:
using Vector = VectorImpl<Event>;
assert(callback && "callback should be valid");//Check for valid object
std::unique_ptr<VectorInterface> vector2;
std::unique_ptr<VectorInterface>& vector = _callbacks[getTypeId<Event>()];
if (vector == nullptr)
@ -63,6 +64,7 @@ public:
assert(dynamic_cast<Vector*>(vector.get()));
Vector* vectorImpl = static_cast<Vector*>(vector.get());
vectorImpl->add(token, callback);
std::unique_ptr<VectorInterface> vector3;
}
/**

View File

@ -49,6 +49,7 @@ EventCollector::~EventCollector()
EventCollector& EventCollector::operator=(const EventCollector& other)
{
std::unique_ptr<int> vector3;
if (this == &other)
{
return *this;

View File

@ -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
# 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
#INCLUDE(cocos2d-x-compare/Cocos2dxCompare.cmake)
ADD_EXECUTABLE(EventBusPerformance
eventbus/EventBusPerformance.cpp
add_executable(EventBusPerformance
src/EventBusPerformance.cpp
${CCNOTIFICATION_CENTER_SRC}
)
TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC
target_compile_options(EventBusPerformance PUBLIC
-Wall -pedantic
-Wno-unused-private-field
-Wnon-virtual-dtor
@ -19,27 +25,18 @@ TARGET_COMPILE_OPTIONS(EventBusPerformance PUBLIC
-Werror
)
SET(EVENTBUS_DEBUG_FLAGS
set(EVENTBUS_DEBUG_FLAGS
-O0 -fno-inline
-DDEBUG
-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:RELEASE>:${EVENTBUS_RELEASE_FLAGS}>")
target_compile_options(EventBusPerformance PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
SET_TARGET_PROPERTIES(EventBusPerformance PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
)
TARGET_INCLUDE_DIRECTORIES(EventBusPerformance PUBLIC
./
target_include_directories(EventBusPerformance PUBLIC
src/
${CCNOTIFICATION_CENTER_INCLUDE}
)
TARGET_LINK_LIBRARIES(EventBusPerformance PUBLIC Dexode::EventBus benchmark)
target_link_libraries(EventBusPerformance PUBLIC Dexode::EventBus benchmark)

View File

@ -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
)
TARGET_COMPILE_OPTIONS(Sample PUBLIC
-Wall -pedantic
-Wno-unused-private-field
-Wnon-virtual-dtor
-Wno-gnu
-Werror
)
if(NOT TARGET Dexode::EventBus)
find_package(EventBus CONFIG REQUIRED)
endif()
SET_TARGET_PROPERTIES(Sample PROPERTIES
CXX_STANDARD 14
)
ADD_SUBDIRECTORY(../ EventBus/)
TARGET_LINK_LIBRARIES(Sample PRIVATE Dexode::EventBus)
target_link_libraries(Sample PRIVATE Dexode::EventBus)

View File

@ -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
# Thanks for CATCH!
ADD_EXECUTABLE(EventBusTest
eventbus/EventCollectorTest.cpp
eventbus/NotifierTest.cpp
project(EventBusTest)
# 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
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
)
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC
target_compile_options(EventBusTest PUBLIC
-Wall -pedantic
-Wno-unused-private-field
-Wnon-virtual-dtor
-Wno-gnu
-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
-DDEBUG
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
#-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
)
SET(EVENTBUS_RELEASE_FLAGS
-DNDEBUG
)
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
TARGET_COMPILE_OPTIONS(EventBusTest PUBLIC "$<$<CONFIG:RELEASE>:${EVENTBUS_RELEASE_FLAGS}>")
target_compile_options(EventBusTest PUBLIC "$<$<CONFIG:DEBUG>:${EVENTBUS_DEBUG_FLAGS}>")
TARGET_INCLUDE_DIRECTORIES(EventBusTest PUBLIC Catch/single_include/)
TARGET_LINK_LIBRARIES(EventBusTest PUBLIC Dexode::EventBus)
target_link_libraries(EventBusTest PUBLIC Dexode::EventBus Catch2::Catch)
add_test(NAME EventBus.UnitTests COMMAND EventBusTest)