diff --git a/README.md b/README.md index f0d327b..85dcd08 100644 --- a/README.md +++ b/README.md @@ -222,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 index f7e7808..7131941 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -9,6 +9,18 @@ project(EventBus # 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 @@ -24,26 +36,69 @@ target_include_directories(EventBus PUBLIC PRIVATE lib/src/ ) -install(TARGETS EventBus EXPORT EventBusTargets - ARCHIVE DESTINATION lib/ - LIBRARY DESTINATION lib/ - RUNTIME DESTINATION bin/ - INCLUDES DESTINATION include/ +# 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}" ) -install(EXPORT EventBusTargets - DESTINATION lib/cmake/EventBus - FILE EventBusTargets.cmake - NAMESPACE Dexode:: - ) - -# Copy public headers +# Export headers install(DIRECTORY include/eventbus - DESTINATION include/ + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) +# Include module with fuction 'write_basic_package_version_file' include(CMakePackageConfigHelpers) -write_basic_package_version_file(EventBusConfigVersion.cmake COMPATIBILITY SameMajorVersion) -install(FILES EventBusConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/EventBusConfigVersion.cmake - DESTINATION lib/cmake/EventBus) +# 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/EventBusConfig.cmake b/lib/EventBusConfig.cmake deleted file mode 100644 index bd2938e..0000000 --- a/lib/EventBusConfig.cmake +++ /dev/null @@ -1,6 +0,0 @@ -include(CMakeFindDependencyMacro) - -# We don't have dependencies -# find_dependency(Foo 1.0) - -include("${CMAKE_CURRENT_LIST_DIR}/EventBusTargets.cmake") 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@")