mirror of
https://github.com/gelldur/EventBus.git
synced 2024-12-27 12:21:02 +08:00
018a536147
I don't like to keep separate folders for public & private stuff. In my opinion this is "old" approach. I like when header and module file are next to each other. My choice. Installation will handle splitting public & private headers.
141 lines
3.9 KiB
CMake
141 lines
3.9 KiB
CMake
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
|
|
|
|
# Use ';' to specify multiple e.g. ZIP;TGZ;DEB
|
|
set(CPACK_GENERATOR "" CACHE STRING "Set packages CPack should build e.g. ZIP;TGZ;DEB")
|
|
|
|
# BUILD_SHARED_LIBS can controll build type!
|
|
project(EventBus
|
|
VERSION 3.0.0
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
# Why C++ 17 needed:
|
|
# - std::shared_mutex used
|
|
# - nested namespaces e.g. my::name::space
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Dependencies
|
|
# No dependencies for EventBus yay!
|
|
|
|
# Introduce variables:
|
|
# * CMAKE_INSTALL_LIBDIR
|
|
# * CMAKE_INSTALL_BINDIR
|
|
# * CMAKE_INSTALL_INCLUDEDIR
|
|
include(GNUInstallDirs)
|
|
include(cmake/InstallHelp.cmake)
|
|
|
|
|
|
# Layout. This works for all platforms:
|
|
# * <prefix>/lib*/cmake/<PROJECT-NAME>
|
|
# * <prefix>/lib*/
|
|
# * <prefix>/include/
|
|
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
|
|
|
# Library definition
|
|
add_library(EventBus
|
|
include/eventbus/EventBus.h
|
|
include/eventbus/EventCollector.h
|
|
include/eventbus/internal/AsyncCallbackVector.h
|
|
include/eventbus/internal/CallbackVector.h
|
|
include/eventbus/internal/TransactionCallbackVector.h
|
|
include/eventbus/TokenHolder.h
|
|
src/eventbus/AsyncEventBus.cpp include/eventbus/AsyncEventBus.h
|
|
|
|
# New version of EventBus 3.0
|
|
src/dexode/EventBus.hpp
|
|
src/dexode/eventbus/Listener.hpp
|
|
src/dexode/eventbus/strategy/Protected.cpp src/dexode/eventbus/strategy/Protected.hpp
|
|
src/dexode/eventbus/strategy/Transaction.hpp
|
|
)
|
|
add_library(Dexode::EventBus ALIAS EventBus)
|
|
|
|
target_compile_features(EventBus PUBLIC cxx_std_17)
|
|
|
|
target_include_directories(EventBus PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>
|
|
$<INSTALL_INTERFACE:include/>
|
|
)
|
|
|
|
set(EventBus_PUBLIC_HEADERS
|
|
src/dexode/EventBus.hpp
|
|
src/dexode/eventbus/Listener.hpp
|
|
src/dexode/eventbus/strategy/Protected.hpp
|
|
src/dexode/eventbus/strategy/Transaction.hpp
|
|
)
|
|
# Add definitions for targets
|
|
# Values:
|
|
# * Debug: -DEVENTBUS_DEBUG=1
|
|
# * Release: -DEVENTBUS_DEBUG=0
|
|
# * other: -DEVENTBUS_DEBUG=0
|
|
target_compile_definitions(EventBus PUBLIC "EVENTBUS_DEBUG=$<CONFIG: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:
|
|
# * <prefix>/lib/libEventBus.a
|
|
# * header location after install: <prefix>/include/eventbus/EventBus.h
|
|
# * headers can be included by C++ code `#include <eventbus/EventBus.h>`
|
|
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 '<PROJECT-NAME>ConfigVersion.cmake'
|
|
# Use:
|
|
# * PROJECT_VERSION
|
|
write_basic_package_version_file(
|
|
"${version_config}" COMPATIBILITY SameMajorVersion
|
|
)
|
|
|
|
# Configure '<PROJECT-NAME>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
|
|
# * <prefix>/lib/cmake/EventBusventBusConfig.cmake
|
|
# * <prefix>/lib/cmake/EventBus/EventBusConfigVersion.cmake
|
|
install(
|
|
FILES "${project_config}" "${version_config}"
|
|
DESTINATION "${config_install_dir}"
|
|
)
|
|
|
|
# Config
|
|
# * <prefix>/lib/cmake/EventBus/EventBusTargets.cmake
|
|
install(EXPORT "${TARGETS_EXPORT_NAME}"
|
|
DESTINATION "${config_install_dir}"
|
|
NAMESPACE "${namespace}"
|
|
)
|
|
|
|
install_public_headers_with_directory(EventBus_PUBLIC_HEADERS "include/")
|
|
|
|
# Cpack configuration
|
|
if(NOT CPACK_GENERATOR STREQUAL "")
|
|
include(cmake/EventBus_CPack.cmake)
|
|
enable_cpack(${CPACK_GENERATOR})
|
|
endif()
|