-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
215 lines (181 loc) · 6.7 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
cmake_minimum_required(VERSION 3.13)
project(lbu)
set(LIBLBU_VERSION_MAJOR 0)
set(LIBLBU_VERSION_MINOR 1)
set(LIBLBU_VERSION_PATCH 20)
set(LIBLBU_VERSION "${LIBLBU_VERSION_MAJOR}.${LIBLBU_VERSION_MINOR}.${LIBLBU_VERSION_PATCH}")
option(LBU_BUILD_STATIC "Build lbu as a static library" OFF)
option(LBU_BUILD_ALSA "Build lbu alsa library" ON)
option(LBU_BUILD_TESTS "Build lbu tests" ON)
include(GNUInstallDirs)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(LIB_STATIC_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
CACHE STRING "Path to lbu cmake files")
set(INCLUDE_IMPORT_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(INCLUDE_INSTALL_DIR ${INCLUDE_IMPORT_DIR}/${PROJECT_NAME})
set(LBU_WARNING_FLAGS "-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-type-limits")
if(CMAKE_COMPILER_IS_GNUCXX)
set(LBU_WARNING_FLAGS "${LBU_WARNING_FLAGS} -Wnoexcept -Wstrict-null-sentinel -Wlogical-op")
endif()
separate_arguments(LBU_WARNING_FLAGS)
function(lbu_set_common_properties TARGET)
target_compile_options(${TARGET} PRIVATE ${LBU_WARNING_FLAGS})
set_property(TARGET ${TARGET} PROPERTY C_VISIBILITY_PRESET hidden)
set_property(TARGET ${TARGET} PROPERTY CXX_VISIBILITY_PRESET hidden)
set_property(TARGET ${TARGET} PROPERTY VISIBILITY_INLINES_HIDDEN ON)
target_link_options(${TARGET} PRIVATE "LINKER:-z,defs")
endfunction()
# --- TARGETS
## Core
set(lbu_core_src
core/abstract_stream.cpp
core/array_ref.cpp
core/ascii.cpp
core/byte_buffer_stream.cpp
core/byte_buffer.cpp
core/core.cpp
core/dynamic_memory.cpp
core/endian.cpp
core/eventfd.cpp
core/fd.cpp
core/fd_stream.cpp
core/file.cpp
core/io.cpp
core/math.cpp
core/memory.cpp
core/pipe.cpp
core/poll.cpp
core/ring_spsc.cpp
core/ring_spsc_stream.cpp
core/unexpected.cpp
)
set(lbu_core_hdr
core/lbu/abstract_stream.h
core/lbu/array_ref.h
core/lbu/ascii.h
core/lbu/byte_buffer_stream.h
core/lbu/byte_buffer.h
core/lbu/dynamic_memory.h
core/lbu/endian.h
core/lbu/eventfd.h
core/lbu/fd.h
core/lbu/fd_stream.h
core/lbu/file.h
core/lbu/io.h
core/lbu/math.h
core/lbu/memory.h
core/lbu/pipe.h
core/lbu/poll.h
core/lbu/ring_spsc.h
core/lbu/ring_spsc_stream.h
core/lbu/unexpected.h
)
if(LBU_BUILD_STATIC)
add_library(lbu_core STATIC ${lbu_core_src})
else()
add_library(lbu_core SHARED ${lbu_core_src})
set_target_properties(lbu_core PROPERTIES
SOVERSION ${LIBLBU_VERSION_MAJOR}
VERSION ${LIBLBU_VERSION})
endif()
add_library(lbu::core ALIAS lbu_core)
add_custom_target(lbu_core_header SOURCES ${lbu_core_hdr})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/core/lbu_global.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/lbu/lbu_global.h
)
set_property(TARGET lbu_core
PROPERTY PUBLIC_HEADER
${lbu_core_hdr}
${CMAKE_CURRENT_BINARY_DIR}/include/lbu/lbu_global.h)
target_compile_features(lbu_core PUBLIC cxx_std_17)
lbu_set_common_properties(lbu_core)
target_include_directories(lbu_core PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/core>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_IMPORT_DIR}>)
install(TARGETS lbu_core EXPORT lbuTargets
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
COMPONENT lbu_Runtime
NAMELINK_COMPONENT lbu_Development
ARCHIVE DESTINATION ${LIB_STATIC_INSTALL_DIR}
COMPONENT lbu_Development
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}
COMPONENT lbu_Development
)
## Alsa
set(lbu_alsa_src
alsa/alsa.cpp
)
set(lbu_alsa_hdr
alsa/lbu/alsa/alsa.h
)
if(LBU_BUILD_ALSA)
find_package(PkgConfig REQUIRED)
if(LBU_BUILD_STATIC)
add_library(lbu_alsa STATIC ${lbu_alsa_src})
else()
add_library(lbu_alsa SHARED ${lbu_alsa_src})
set_target_properties(lbu_alsa PROPERTIES
SOVERSION ${LIBLBU_VERSION_MAJOR}
VERSION ${LIBLBU_VERSION})
endif()
add_library(lbu::alsa ALIAS lbu_alsa)
add_custom_target(lbu_alsa_header SOURCES ${lbu_alsa_hdr})
set_property(TARGET lbu_alsa
PROPERTY PUBLIC_HEADER
${lbu_alsa_hdr})
pkg_check_modules(alsa REQUIRED IMPORTED_TARGET alsa)
target_link_libraries(lbu_alsa PUBLIC lbu::core PkgConfig::alsa)
lbu_set_common_properties(lbu_alsa)
target_include_directories(lbu_alsa PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/alsa>
$<INSTALL_INTERFACE:${INCLUDE_IMPORT_DIR}>)
install(TARGETS lbu_alsa EXPORT lbuTargets
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
COMPONENT lbu_Runtime
NAMELINK_COMPONENT lbu_Development
ARCHIVE DESTINATION ${LIB_STATIC_INSTALL_DIR}
COMPONENT lbu_Development
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/alsa
COMPONENT lbu_Development
)
endif()
# --- TESTS
if(LBU_BUILD_TESTS)
find_package(Qt5 COMPONENTS Core Test REQUIRED)
enable_testing()
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(bench_stream tests/bench/bench_stream.cpp)
target_link_libraries(bench_stream lbu_core Qt5::Core Qt5::Test)
target_compile_definitions(bench_stream PRIVATE BENCH_RING_ADDITIONAL)
add_executable(test_byte_buffer tests/auto/test_byte_buffer.cpp)
target_link_libraries(test_byte_buffer lbu_core Qt5::Core Qt5::Test)
add_test(NAME test_byte_buffer COMMAND test_byte_buffer)
endif()
# --- CMAKE INSTALL
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/lbu-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/lbu-config.cmake
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/lbu-config-version.cmake
VERSION ${LIBLBU_VERSION}
COMPATIBILITY ExactVersion # TODO change to SameMajorVersion once stable
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/lbu-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/lbu-config-version.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT lbu_Development
)
install(
EXPORT lbuTargets
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
FILE lbuTargets.cmake
COMPONENT lbu_Development
)