1
0
mirror of https://github.com/wqking/eventpp.git synced 2024-12-26 15:52:40 +08:00
eventpp/CMakeLists.txt

85 lines
2.1 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.2)
2022-03-11 17:17:49 +08:00
project(eventpp VERSION 0.1.2)
2022-01-17 18:44:58 +01:00
add_library(eventpp INTERFACE)
set(CMAKE_CXX_STANDARD 11)
2022-01-17 18:44:58 +01:00
target_include_directories(
eventpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2022-01-17 18:44:58 +01:00
)
2022-01-17 19:59:36 +01:00
add_library(eventpp::eventpp ALIAS eventpp)
2022-05-27 16:36:31 +02:00
# Checks if eventpp is the main project or if it is
# being built as a subproject (using add_subdirectory/FetchContent).
set(MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()
2022-01-17 18:44:58 +01:00
# Installation
# ------------
include(GNUInstallDirs)
if (POLICY CMP0077)
2022-05-27 16:36:31 +02:00
# Allow CMake 3.13+ to override options when using add_subdirectory/FetchContent.
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
2022-05-27 16:36:31 +02:00
option(EVENTPP_INSTALL "Enable installation" ${MAIN_PROJECT})
2022-01-17 18:44:58 +01:00
if (EVENTPP_INSTALL)
# Install the library
install(
TARGETS eventpp
EXPORT eventppTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
2022-01-17 18:44:58 +01:00
# Install the headers
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
2022-01-17 18:44:58 +01:00
# (Generate and) install the target import file
install(
EXPORT eventppTargets
NAMESPACE eventpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eventpp
)
2022-01-17 18:44:58 +01:00
# Generate the package version file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/eventppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
2022-01-17 18:44:58 +01:00
# Generate the package configuration file, that allows other
# CMake projects to find the library with find_package()
configure_package_config_file(
cmake/eventppConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/eventppConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eventpp
)
2022-01-17 18:44:58 +01:00
# Install the package version and configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/eventppConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/eventppConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eventpp
)
2022-01-17 18:44:58 +01:00
# Install readme and license
install(
FILES
readme.md
license
DESTINATION ${CMAKE_INSTALL_DATADIR}/eventpp
)
endif()