forked from wqking/eventpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
85 lines (72 loc) · 2.13 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 3.2)
project(eventpp VERSION 0.1.2)
add_library(eventpp INTERFACE)
set(CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)
target_include_directories(
eventpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_library(eventpp::eventpp ALIAS eventpp)
# 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()
# Installation
# ------------
if (POLICY CMP0077)
# Allow CMake 3.13+ to override options when using add_subdirectory/FetchContent.
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
option(EVENTPP_INSTALL "Enable installation" ${MAIN_PROJECT})
if (EVENTPP_INSTALL)
# Install the library
install(
TARGETS eventpp
EXPORT eventppTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Install the headers
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# (Generate and) install the target import file
install(
EXPORT eventppTargets
NAMESPACE eventpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eventpp
)
# Generate the package version file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/eventppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# 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
)
# 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
)
# Install readme and license
install(
FILES
readme.md
license
DESTINATION ${CMAKE_INSTALL_DATADIR}/eventpp
)
endif()