forked from qcoro/qcoro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
117 lines (90 loc) · 3.66 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cmake_minimum_required(VERSION 3.14)
set(qcoro_VERSION 0.1)
project(qcoro LANGUAGES CXX VERSION ${qcoro_VERSION})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
include(CTest)
include(FeatureSummary)
include(HasCompatibleStlAbi)
#-----------------------------------------------------------#
# Options
#-----------------------------------------------------------#
option(QCORO_BUILD_EXAMPLES "Build examples" ON)
add_feature_info(Examples QCORO_BUILD_EXAMPLES "Build examples")
option(QCORO_ENABLE_ASAN "Build with AddressSanitizer" OFF)
add_feature_info(Asan QCORO_ENABLE_ASAN "Build with AddressSanitizer")
#-----------------------------------------------------------#
# Compiler Settings
#-----------------------------------------------------------#
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic")
if (QCORO_ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
include(QCoroMacros.cmake)
qcoro_enable_coroutines()
#-----------------------------------------------------------#
# Dependencies
#-----------------------------------------------------------#
find_package(Threads REQUIRED)
set(REQUIRED_QT_COMPONENTS Core DBus Network Widgets Concurrent)
if (BUILD_TESTING)
list(APPEND REQUIRED_QT_COMPONENTS Test)
endif()
if (NOT USE_QT_VERSION)
# FIXME: find_package(QT NAMES Qt6 Qt5 ...) seems to prefer Qt5 on my system
find_package(Qt6 COMPONENTS ${REQUIRED_QT_COMPONENTS})
if (NOT Qt6_FOUND)
find_package(Qt5 COMPONENTS ${REQUIRED_QT_COMPONENTS} REQUIRED)
find_package(Qt5Core COMPONENTS Private REQUIRED)
set(QT_VERSION_MAJOR 5)
else()
find_package(Qt6Core COMPONENTS Private REQUIRED)
set(QT_VERSION_MAJOR 6)
endif()
else()
find_package(Qt${USE_QT_VERSION} COMPONENTS ${REQUIRED_QT_COMPONENTS} REQUIRED)
find_package(Qt${USE_QT_VERSION}Core COMPONENTS Private)
set(QT_VERSION_MAJOR ${USE_QT_VERSION})
endif()
has_compatible_stl_abi(QT_HAS_COMPAT_ABI)
if (NOT QT_HAS_COMPAT_ABI)
message(WARNING "Qt is built with an incompatible STL, some features will be disabled!")
endif()
#-----------------------------------------------------------#
# Sources
#-----------------------------------------------------------#
add_subdirectory(qcoro)
if (QCORO_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
#-----------------------------------------------------------#
# Installation
#-----------------------------------------------------------#
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/QCoroConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/QCoroConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QCoro
PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/QCoroConfigVersion.cmake"
VERSION ${qcoro_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/QCoroConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/QCoroConfigVersion.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/QCoroMacros.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QCoro
COMPONENT Devel)
install(EXPORT QCoroTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/QCoro"
FILE QCoroTargets.cmake
NAMESPACE QCoro::)
#-----------------------------------------------------------#
# Summary
#-----------------------------------------------------------#
feature_summary(FATAL_ON_MISSING_REQUIRED_PACKAGES WHAT ALL)