From 412bc653aac9851116b48b138ae145f8c95da506 Mon Sep 17 00:00:00 2001 From: Dawid Drozd Date: Sat, 14 Sep 2019 15:10:08 +0200 Subject: [PATCH] Add new way of installing public headers --- lib/CMakeLists.txt | 14 ++++++++++++-- lib/cmake/InstallHelp.cmake | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/cmake/InstallHelp.cmake diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1635d74..5e074a2 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,6 +19,8 @@ set(CMAKE_CXX_STANDARD 17) # * CMAKE_INSTALL_BINDIR # * CMAKE_INSTALL_INCLUDEDIR include(GNUInstallDirs) +include(cmake/InstallHelp.cmake) + # Layout. This works for all platforms: # * /lib*/cmake/ @@ -43,7 +45,6 @@ add_library(EventBus src/dexode/eventbus/strategy/Protected.cpp include/dexode/eventbus/strategy/Protected.hpp src/dexode/eventbus/strategy/Transaction.cpp include/dexode/eventbus/strategy/Transaction.hpp ) - add_library(Dexode::EventBus ALIAS EventBus) target_compile_features(EventBus PUBLIC cxx_std_14) @@ -54,6 +55,13 @@ target_include_directories(EventBus PUBLIC PRIVATE lib/src/ ) +set(EventBus_PUBLIC_HEADERS + include/dexode/EventBus.hpp + include/dexode/eventbus/Listener.hpp + include/dexode/eventbus/Subscriber.hpp + include/dexode/eventbus/strategy/Protected.hpp + include/dexode/eventbus/strategy/Transaction.hpp + ) # Add definitions for targets # Values: # * Debug: -DEVENTBUS_DEBUG=1 @@ -121,8 +129,10 @@ install(EXPORT "${TARGETS_EXPORT_NAME}" NAMESPACE "${namespace}" ) +install_public_headers_with_directory(EventBus_PUBLIC_HEADERS "include/") + # Cpack configuration if(NOT CPACK_GENERATOR STREQUAL "") - include("cmake/EventBus_CPack.cmake") + include(cmake/EventBus_CPack.cmake) enable_cpack(${CPACK_GENERATOR}) endif() diff --git a/lib/cmake/InstallHelp.cmake b/lib/cmake/InstallHelp.cmake new file mode 100644 index 0000000..447f357 --- /dev/null +++ b/lib/cmake/InstallHelp.cmake @@ -0,0 +1,14 @@ +# +# Installs files with preserving paths. +# +# Example usage: +# install_public_headers_with_directory(MyHeadersList "src/") +# +macro(install_public_headers_with_directory HEADER_LIST IGNORE_PREFIX) + foreach(HEADER ${${HEADER_LIST}}) + get_filename_component(DIR ${HEADER} DIRECTORY) + string(REPLACE ${IGNORE_PREFIX} "" DIR ${DIR}) + install(FILES ${HEADER} DESTINATION include/${DIR}) + endforeach(HEADER) + +endmacro(install_public_headers_with_directory)