-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·342 lines (266 loc) · 12.2 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#
# Copyright 2014-2022 Real Logic Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_policy(VERSION 3.14)
include(FetchContent)
file(STRINGS version.txt AERON_VERSION_TXT LIMIT_COUNT 1 REGEX "^[0-9]+(\\.[0-9]+)+")
string(REGEX REPLACE "^([0-9]+(\\.[0-9]+)+).*$" "\\1" AERON_VERSION_FROM_FILE "${AERON_VERSION_TXT}")
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory)"
"and run CMake from there. You may need to remove CMakeCache.txt.")
endif ()
# if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
# set(STANDALONE_BUILD TRUE)
# endif ()
set(STANDALONE_BUILD TRUE)
option(BUILD_AERON_DRIVER "Build Aeron driver" ON)
option(BUILD_AERON_ARCHIVE_API "Build Aeron Archive API" OFF)
option(C_WARNINGS_AS_ERRORS "Enable warnings as errors for C" OFF)
option(CXX_WARNINGS_AS_ERRORS "Enable warnings as errors for C++" OFF)
option(SANITISE_BUILD "Enable sanitise options" ON)
option(COVERAGE_BUILD "Enable code coverage" OFF)
option(AERON_TESTS "Enable tests" OFF)
option(AERON_SYSTEM_TESTS "Enable system tests" OFF)
option(AERON_SLOW_SYSTEM_TESTS "Enable slow system tests" OFF)
option(AERON_BUILD_SAMPLES "Enable building the sample projects" ${STANDALONE_BUILD})
option(LINK_SAMPLES_CLIENT_SHARED "Enable shared linking for sample projects" OFF)
option(AERON_BUILD_DOCUMENTATION "Build Aeron documentation" ${STANDALONE_BUILD})
option(AERON_INSTALL_TARGETS "Enable installation step" ${STANDALONE_BUILD})
if (UNIX)
option(AERON_ENABLE_NONSTANDARD_OPTIMIZATIONS "Enable Ofast for release builds" ${STANDALONE_BUILD})
endif ()
unset(STANDALONE_BUILD)
include(ExternalProject)
# CMAKE_OSX_ARCHITECTURES can be set to arm64 or x86_64 (or both) to make a specific architecture version. Requires
# CMake 3.21. Must be set before project(), etc.
#set(CMAKE_OSX_ARCHITECTURES x86_64)
project("aeron" VERSION "${AERON_VERSION_FROM_FILE}")
if (AERON_TESTS)
enable_testing()
include(CTest)
endif ()
# default built type is Release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
endif (NOT CMAKE_BUILD_TYPE)
##########################################################
# Platform flags, etc.
find_package(Threads)
##########################################################
# Doxygen for generating doc
if (AERON_BUILD_DOCUMENTATION)
find_package(Doxygen)
endif ()
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif ()
if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif ()
if (NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif ()
if (NOT DEFINED CMAKE_C_EXTENSIONS)
set(CMAKE_C_EXTENSIONS OFF)
endif ()
add_definitions(-DAERON_VERSION_TXT="${AERON_VERSION_TXT}")
add_definitions(-DAERON_VERSION_MAJOR=${aeron_VERSION_MAJOR})
add_definitions(-DAERON_VERSION_MINOR=${aeron_VERSION_MINOR})
add_definitions(-DAERON_VERSION_PATCH=${aeron_VERSION_PATCH})
# all UNIX-based platform compiler flags
if (UNIX)
add_compile_options(-Wall -Wpedantic -Wextra -Wno-unused-parameter)
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "11.0")
add_compile_options(-Wno-error=maybe-uninitialized)
endif ()
if (C_WARNINGS_AS_ERRORS)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Werror>)
endif (C_WARNINGS_AS_ERRORS)
if (CXX_WARNINGS_AS_ERRORS)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror>)
endif (CXX_WARNINGS_AS_ERRORS)
if (SANITISE_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -DAERON_SANITIZE_ENABLED")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -DAERON_SANITIZE_ENABLED")
endif (SANITISE_BUILD)
if (COVERAGE_BUILD)
add_compile_options(-fno-inline --coverage)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif (COVERAGE_BUILD)
if (AERON_ENABLE_NONSTANDARD_OPTIMIZATIONS)
add_compile_options($<$<CONFIG:Release>:-Ofast>)
add_compile_options(-mcpu=neoverse-512tvb -Os)
endif ()
endif ()
# platform specific flags
if (APPLE)
add_compile_options(-Wsign-compare)
add_definitions(-DDarwin)
add_compile_options(-Wno-deprecated-register)
elseif (CYGWIN)
add_definitions(-DWIN32)
if (AERON_TESTS)
add_definitions(-DGTEST_HAS_PTHREAD)
endif ()
set(CMAKE_CXX_EXTENSIONS ON)
elseif (MSVC)
add_definitions(-DWIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(-DNOMINMAX)
if (${MSVC_VERSION} GREATER_EQUAL 1915)
# Acknowledge that we understand MSVC resolved a byte alignment issue in this compiler
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /Od /Zi /MP /wd4251")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /MP /wd4251")
set(CMAKE_C_FLAGS_DEBUG "/MTd")
set(CMAKE_C_FLAGS_RELEASE "/MT")
unset(CMAKE_C_STANDARD) # To avoid `/std:c11` in the compiler options
if (C_WARNINGS_AS_ERRORS)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/WX>)
endif (C_WARNINGS_AS_ERRORS)
if (CXX_WARNINGS_AS_ERRORS)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/WX>)
endif (CXX_WARNINGS_AS_ERRORS)
if (SANITISE_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address /Zi /D AERON_SANITIZE_ENABLED")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /Zi /D AERON_SANITIZE_ENABLED")
endif (SANITISE_BUILD)
endif ()
##########################################################
# Project variables, etc.
if (NOT DEFINED GRADLE_WRAPPER)
if (MSVC)
set(GRADLE_WRAPPER "gradlew.bat" CACHE INTERNAL "Location of the Gradle wrapper script")
else ()
set(GRADLE_WRAPPER "./gradlew" CACHE INTERNAL "Location of the Gradle wrapper script")
endif ()
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/binaries")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
if (AERON_BUILD_SAMPLES)
set(AERON_SAMPLES_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-samples/src/main/cpp")
set(AERON_C_SAMPLES_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-samples/src/main/c")
endif ()
set(AERON_CLIENT_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/main/cpp")
set(AERON_CLIENT_WRAPPER_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/main/cpp_wrapper")
set(AERON_C_CLIENT_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/main/c")
set(AERON_DRIVER_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-driver/src/main/c")
set(AERON_ARCHIVE_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-archive/src/main/cpp")
if (AERON_TESTS)
set(AERON_CLIENT_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/test/cpp")
set(AERON_DRIVER_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-driver/src/test/c")
set(AERON_C_CLIENT_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/test/c")
set(AERON_CLIENT_WRAPPER_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/test/cpp_wrapper")
set(AERON_ARCHIVE_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-archive/src/test/cpp")
# set(AERON_SYSTEM_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-system-tests")
endif ()
if (AERON_BUILD_SAMPLES)
# hdr_histogram
include_directories(${HDRHISTOGRAM_SOURCE_DIR}/include)
endif ()
##########################################################
add_definitions(-D_FILE_OFFSET_BITS=64)
##########################################################
# gmock usage
# if (AERON_TESTS)
# set(INSTALL_GMOCK OFF CACHE INTERNAL "Install Googletest's GMock?")
# set(INSTALL_GTEST OFF CACHE INTERNAL "Install Googletest's GTest?" )
# FetchContent_Declare(
# gmock
# URL ${CMAKE_CURRENT_SOURCE_DIR}/cppbuild/googletest-release-1.11.0.zip
# URL_MD5 52943a59cefce0ae0491d4d2412c120b)
# FetchContent_MakeAvailable(gmock)
# endif ()
##########################################################
# HdrHistogram usage - use MD5 as means to identify snapshot
if (AERON_BUILD_SAMPLES)
set(HDR_LOG_REQUIRED "OFF" CACHE INTERNAL "Set log required option")
set(HDR_HISTOGRAM_BUILD_PROGRAMS "OFF" CACHE INTERNAL "Set build programs option")
FetchContent_Declare(
hdr_histogram
URL ${CMAKE_CURRENT_SOURCE_DIR}/cppbuild/HdrHistogram_c-0.11.4.zip
URL_MD5 4d8f8ed3fe69422cf6b44fdabd98d462
)
FetchContent_GetProperties(hdr_histogram)
if(NOT hdr_histogram_POPULATED)
FetchContent_Populate(hdr_histogram)
add_subdirectory(${hdr_histogram_SOURCE_DIR} ${hdr_histogram_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
# FetchContent_MakeAvailable(hdr_histogram)
endif ()
add_subdirectory(${AERON_C_CLIENT_SOURCE_PATH})
add_subdirectory(${AERON_CLIENT_SOURCE_PATH})
add_subdirectory(${AERON_CLIENT_WRAPPER_SOURCE_PATH})
if (AERON_TESTS)
add_subdirectory(${AERON_CLIENT_TEST_PATH})
add_subdirectory(${AERON_C_CLIENT_TEST_PATH})
add_subdirectory(${AERON_CLIENT_WRAPPER_TEST_PATH})
endif ()
if (AERON_BUILD_SAMPLES)
add_subdirectory(${AERON_SAMPLES_PATH})
add_subdirectory(${AERON_C_SAMPLES_PATH})
endif ()
if (BUILD_AERON_DRIVER)
add_subdirectory(${AERON_DRIVER_SOURCE_PATH})
if (AERON_TESTS)
add_subdirectory(${AERON_DRIVER_TEST_PATH})
# add_subdirectory(${AERON_SYSTEM_TEST_PATH})
endif ()
endif (BUILD_AERON_DRIVER)
if (BUILD_AERON_ARCHIVE_API)
set(ARCHIVE_CODEC_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(ARCHIVE_CODEC_SCHEMA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/aeron-archive/src/main/resources/archive")
set(ARCHIVE_CODEC_WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(${AERON_ARCHIVE_SOURCE_PATH})
set(AERON_ALL_JAR "${CMAKE_CURRENT_SOURCE_DIR}/aeron-all/build/libs/aeron-all-${AERON_VERSION_TXT}.jar")
file(GLOB_RECURSE AERON_ALL_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}}/aeron-archive/src/main/java/*.java")
add_custom_command(OUTPUT ${AERON_ALL_JAR}
COMMAND ${CMAKE_COMMAND} -E env JAVA_HOME=$ENV{JAVA_HOME} BUILD_JAVA_HOME=$ENV{BUILD_JAVA_HOME} BUILD_JAVA_VERSION=$ENV{BUILD_JAVA_VERSION} ${GRADLE_WRAPPER} :aeron-all:clean :aeron-all:assemble --no-daemon -x javadoc --console=plain -q
DEPENDS ${AERON_ALL_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating aeron-all jar")
add_custom_target(aeron-all-jar
DEPENDS ${AERON_ALL_JAR})
if (AERON_TESTS)
add_subdirectory(${AERON_ARCHIVE_TEST_PATH})
endif ()
endif (BUILD_AERON_ARCHIVE_API)
##########################################################
# doc target
if (AERON_BUILD_DOCUMENTATION AND DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cppbuild/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(
doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
if (AERON_INSTALL_TARGETS)
# install the doc if it has been built
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc DESTINATION share OPTIONAL)
endif ()
endif ()
##########################################################
# package target
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${aeron_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${aeron_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${aeron_VERSION_PATCH}")
set(CPACK_GENERATOR "TGZ;STGZ")
include(CPack)