forked from srsran/srsRAN_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
434 lines (376 loc) · 16.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#
# Copyright 2021-2024 Software Radio Systems Limited
#
# This file is part of srsRAN
#
# srsRAN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# srsRAN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# A copy of the GNU Affero General Public License can be found in
# the LICENSE file in the top-level directory of this distribution
# and at http://www.gnu.org/licenses/.
#
########################################################################
# Prevent in-tree builds
########################################################################
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree build. This is bad practice.")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 3.14)
project(srsran)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
include(version) # sets version information
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message(STATUS "Build type not specified: defaulting to Release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
# Generate CMake to include build information
configure_file(
${PROJECT_SOURCE_DIR}/cmake/modules/build_info.cmake.in
${CMAKE_BINARY_DIR}/build_info.cmake
)
########################################################################
# Options
########################################################################
option(STOP_ON_WARNING "Interrupt application on warning" OFF)
option(ENABLE_WERROR "Stop compilation on errors" ON)
option(ENABLE_TSAN "Enable clang thread sanitizer" OFF)
option(ENABLE_ASAN "Enable clang address sanitizer" OFF)
option(ENABLE_GCOV "Enable code coverage" OFF)
option(ENABLE_UHD "Enable UHD" ON)
option(ENABLE_ZEROMQ "Enable ZeroMQ" OFF)
option(ENABLE_FFTW "Enable FFTW" ON)
option(ENABLE_DPDK "Enable DPDK" OFF)
option(ENABLE_LIBNUMA "Enable LibNUMA" OFF)
option(ENABLE_EXPORT "Enable PIC and export libraries" OFF)
option(ENABLE_TRX_DRIVER "Enable Amarisoft TRX driver library" OFF)
option(AUTO_DETECT_ISA "Enable automatic ISA detection" ON)
option(BUILD_TESTS "Compile tests" ON)
option(ENABLE_GPROF "Enable gprof" OFF)
option(USE_PHY_TESTVECTORS "Enable testvector PHY tests" OFF)
option(FORCE_DEBUG_INFO "Add debug information to Release build" OFF)
# Set assertion level options and default value.
set(ASSERT_LEVEL "AUTO" CACHE STRING "Assertion paranoia level")
set_property(CACHE ASSERT_LEVEL PROPERTY STRINGS AUTO MINIMAL NORMAL PARANOID)
# Set maximum time to wait for a clean exit.
set(EXIT_TIMEOUT "AUTO" CACHE STRING "Timer to wait for a clean exit")
if (ENABLE_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
# Disable gcc's maybe uninitialized analysis as it raises false positives
if (CMAKE_COMPILER_IS_GNUCXX)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
if (HAS_MAYBE_UNINITIALIZED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
endif()
check_cxx_compiler_flag("-Wstringop-overflow" HAS_STRINGOP_OVERFLOW)
if (HAS_STRINGOP_OVERFLOW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=stringop-overflow")
endif()
if (ASSERT_LEVEL STREQUAL "MINIMAL")
check_cxx_compiler_flag("-Warray-bounds" HAS_ARRAY_BOUNDS)
if (HAS_ARRAY_BOUNDS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds")
endif()
endif()
endif()
endif ()
if (ENABLE_ASAN AND ENABLE_TSAN)
message(FATAL_ERROR "ASAN and TSAN cannot be enabled at the same time.")
endif ()
# Hardware acceleration for both PUSCH and PDSCH is enabled by default when using DPDK.
if (ENABLE_DPDK)
# Make sure that library export is disabed, as it is not compatible with hardware acceleration.
if (NOT ENABLE_EXPORT)
SET(ENABLE_PDSCH_HWACC ON CACHE BOOL "Enable PDSCH hardware-acceleration")
message(STATUS "Hardware-acceleration enabled for PDSCH.")
SET(ENABLE_PUSCH_HWACC ON CACHE BOOL "Enable PUSCH hardware-acceleration")
message(STATUS "Hardware-acceleration enabled for PUSCH.")
endif ()
else (ENABLE_DPDK)
unset(ENABLE_PDSCH_HWACC CACHE)
unset(ENABLE_PUSCH_HWACC CACHE)
endif (ENABLE_DPDK)
########################################################################
# ENABLE_EXPORT
########################################################################
# ENABLE_EXPORT tells cmake to make some libaries available for other
# software to link to. If ON, the code must be compiled in PIC mode.
# We also add a dummy target that will depend on all the exported
# libraries to simplify their compilation.
if (ENABLE_EXPORT)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_custom_target(srsran_exported_libs)
endif (ENABLE_EXPORT)
# Simple macro that tags libraries to be exported and adds them to the
# dependencies of the dummy target.
macro(ADD_TO_EXPORTED_LIBS)
if(ENABLE_EXPORT)
# Tag libraries.
install(TARGETS ${ARGV} EXPORT srsran_export)
# Make libraries dependencies of the srsran_exported_libs dummy
# target, which can be called to compile all exported libraries
# at once.
add_dependencies(srsran_exported_libs ${ARGV})
endif(ENABLE_EXPORT)
endmacro(ADD_TO_EXPORTED_LIBS)
########################################################################
# Install Dirs
########################################################################
set(DATA_DIR share/${CMAKE_PROJECT_NAME})
########################################################################
# Compiler specific setup
########################################################################
macro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(${flag} ${have})
if (${have})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif (${have})
endmacro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE)
# Make sure no instance of abstract class is left without a destructor
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-Wnon-virtual-dtor HAVE_NON_VIRTUAL_DTOR)
# Make sure all overridden methods are marked as override
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-Wsuggest-override HAVE_SUGGEST_OVERRIDE)
# Avoid shadow variables which can be caused due to C code ported into C++
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-Wshadow HAVE_SHADOW)
# Set compiler flags for different build types.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0 -DDEBUG_MODE -DBUILD_TYPE_DEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb -DBUILD_TYPE_RELWITHDEBINFO")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-trapping-math -fno-math-errno -DBUILD_TYPE_RELEASE")
if(ENABLE_GPROF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif(ENABLE_GPROF)
if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if (HAVE_SSE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast -funroll-loops")
endif (HAVE_SSE)
endif (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if (ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
# Note: When using ASAN, we need to ensure the use of RPATH instead of RUNPATH via "-Wl,--disable-new-dtags"
# While RPATH is default, some systems (e.g. Ubuntu 18.04 and 20.04) use RUNPATH by default, which is non-transitive.
# Since ASAN intercepts dlopen(), by which it replaces the dynamic string token "$ORIGIN" to its own location,
# the RF plugins won't be found when using ASAN + RUNPATH in the top-level executable.
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE("-Wl,--disable-new-dtags" HAVE_RPATH_FORCE)
endif (ENABLE_ASAN)
if (ENABLE_TSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
add_definitions(-DENABLE_TSAN)
endif (ENABLE_TSAN)
if (FORCE_DEBUG_INFO)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif (FORCE_DEBUG_INFO)
if (ENABLE_GCOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif (ENABLE_GCOV)
if(NOT ASSERT_LEVEL STREQUAL "MINIMAL")
# asserts are enabled.
add_definitions(-DASSERTS_ENABLED)
if((ASSERT_LEVEL STREQUAL "PARANOID") OR
((ASSERT_LEVEL STREQUAL "AUTO") AND (${CMAKE_BUILD_TYPE} STREQUAL "Debug")))
add_definitions(-DPARANOID_ASSERTS_ENABLED)
message(STATUS "Assertion level set to PARANOID")
else()
message(STATUS "Assertion level set to NORMAL")
endif()
endif()
if(NOT EXIT_TIMEOUT STREQUAL "AUTO")
message(STATUS "Manually set exit timeout. timeout=${EXIT_TIMEOUT}s")
add_compile_definitions(TERM_TIMEOUT_S=${EXIT_TIMEOUT})
endif()
########################################################################
# Find dependencies
########################################################################
# Backward-cpp
find_package(Backward)
if(Backward_FOUND)
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
message(STATUS "Building with backward-cpp support")
else (BACKWARD_HAS_EXTERNAL_LIBRARIES)
message(STATUS "Backward-cpp found, but external libraries are missing.")
endif()
endif()
# Crypto
find_package(MbedTLS REQUIRED)
if (MBEDTLS_FOUND)
set(SEC_INCLUDE_DIRS "${MBEDTLS_INCLUDE_DIRS}")
if(BUILD_STATIC)
set(SEC_LIBRARIES "${MBEDTLS_STATIC_LIBRARIES}")
else(BUILD_STATIC)
set(SEC_LIBRARIES "${MBEDTLS_LIBRARIES}")
endif(BUILD_STATIC)
else(MBEDTLS_FOUND)
message(FATAL_ERROR "mbedTLS is required to build ${CMAKE_PROJECT_NAME}")
endif (MBEDTLS_FOUND)
# FFTW
if (ENABLE_FFTW)
find_package(FFTW3F)
endif (ENABLE_FFTW)
# Google Tests
if (BUILD_TESTS)
find_package(GTest REQUIRED)
# Alias gtest_discover_tests increase discovery the timeout.
function(gtest_discover_tests)
_gtest_discover_tests(${ARGV} DISCOVERY_TIMEOUT 15)
endfunction()
endif (BUILD_TESTS)
# Threads
find_package(Threads REQUIRED)
# UHD
if (ENABLE_UHD)
find_package(UHD)
if (UHD_FOUND)
include_directories(${UHD_INCLUDE_DIRS})
link_directories(${UHD_LIBRARY_DIRS})
endif (UHD_FOUND)
else (ENABLE_UHD)
unset(UHD_FOUND CACHE)
endif (ENABLE_UHD)
# Yaml-cpp
find_package(YAMLCPP)
if (YAMLCPP_FOUND)
include_directories(${YAMLCPP_INCLUDE_DIR})
link_directories(${YAMLCPP_LIBRARY})
else (YAMLCPP_FOUND)
message(FATAL_ERROR "yaml-cpp is required to build ${CMAKE_PROJECT_NAME}")
endif (YAMLCPP_FOUND)
# ZeroMQ
if (ENABLE_ZEROMQ)
find_package(ZeroMQ)
if (ZEROMQ_FOUND)
include_directories(${ZEROMQ_INCLUDE_DIRS})
link_directories(${ZEROMQ_LIBRARY_DIRS})
endif (ZEROMQ_FOUND)
else (ENABLE_ZEROMQ)
unset(ZEROMQ_FOUND CACHE)
endif (ENABLE_ZEROMQ)
if (ENABLE_LIBNUMA)
find_package(NUMA)
if (NUMA_FOUND)
include_directories(${NUMA_INCLUDE_DIRS})
add_definitions(-DNUMA_SUPPORT)
endif (NUMA_FOUND)
endif (ENABLE_LIBNUMA)
# DPDK
if (ENABLE_DPDK)
set(DPDK_MIN_VERSION "22.11")
find_package(DPDK ${DPDK_MIN_VERSION})
if (DPDK_FOUND)
include_directories(SYSTEM ${DPDK_INCLUDE_DIRS})
endif (DPDK_FOUND)
else (ENABLE_DPDK)
unset(DPDK_FOUND CACHE)
endif (ENABLE_DPDK)
########################################################################
# Instruction Set Architecture setup
########################################################################
if (AUTO_DETECT_ISA)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(GCC_ARCH armv8-a CACHE STRING "GCC compile for specific architecture.")
message(STATUS "Detected aarch64 processor")
set(HAVE_NEON True CACHE BOOL "NEON Instruction set is supported")
else (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(GCC_ARCH native CACHE STRING "GCC compile for specific architecture.")
endif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
find_package(SSE)
# Add default architecture if enabled and available.
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE("-march=${GCC_ARCH}" HAVE_MARCH)
if (HAVE_AVX2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
endif (HAVE_AVX2)
if (HAVE_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
endif (HAVE_AVX)
if (HAVE_SSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif (HAVE_SSE)
if (HAVE_FMA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
endif (HAVE_FMA)
if (HAVE_AVX512)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mavx512cd -mavx512bw -mavx512dq")
endif (HAVE_AVX512)
else (AUTO_DETECT_ISA)
unset(HAVE_SSE CACHE)
unset(HAVE_AVX CACHE)
unset(HAVE_AVX2 CACHE)
unset(HAVE_FMA CACHE)
unset(HAVE_AVX512 CACHE)
endif (AUTO_DETECT_ISA)
########################################################################
# Compiler launcher setup
########################################################################
# Enable ccache if not already enabled
find_program(CCACHE_EXECUTABLE ccache)
mark_as_advanced(CCACHE_EXECUTABLE)
if (CCACHE_EXECUTABLE)
foreach (LANG C CXX)
if (NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/ccache$")
message(STATUS "Enabling ccache for ${LANG}")
set(CMAKE_${LANG}_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "")
endif ()
endforeach ()
endif ()
include(CTest)
execute_process(COMMAND sed -i "s|MemoryCheckCommandOptions: |MemoryCheckCommandOptions: --verbose --trace-children=yes --time-stamp=yes --leak-check=full --show-leak-kinds=all --show-reachable=yes --exit-on-first-error=yes --error-exitcode=22 --suppressions=${CMAKE_SOURCE_DIR}/.memcheck-suppressions|" DartConfiguration.tcl
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
include_directories(include)
include_directories(external/fmt/include)
include_directories(external)
########################################################################
# Add headers to cmake project (useful for IDEs)
########################################################################
# List of directories that contain header files
set(ALL_HEADER_DIRS
apps
lib
include
tests/unittests
)
set(ALL_HEADER_FILES "")
foreach(TMP_DIR ${ALL_HEADER_DIRS})
file(GLOB_RECURSE TMP_HEADERS "${TMP_DIR}/*.h")
list(APPEND ALL_HEADER_FILES ${TMP_HEADERS})
endforeach()
add_custom_target(all_srsran_headers SOURCES ${ALL_HEADER_FILES})
########################################################################
# Add the subdirectories
########################################################################
add_subdirectory(apps)
add_subdirectory(configs)
add_subdirectory(docs)
add_subdirectory(external)
add_subdirectory(lib)
add_subdirectory(utils)
if (BUILD_TESTS)
add_subdirectory(tests/test_doubles)
add_subdirectory(tests/unittests)
add_subdirectory(tests/integrationtests)
add_subdirectory(tests/benchmarks)
endif (BUILD_TESTS)
########################################################################
# Export (selected) libraries
########################################################################
if(ENABLE_EXPORT)
export(EXPORT srsran_export NAMESPACE srsran:: FILE "${CMAKE_BINARY_DIR}/srsran.cmake")
else(ENABLE_EXPORT)
# Remove any previous export file (if it exists), since it will become outdated.
file(REMOVE "${CMAKE_BINARY_DIR}/srsran.cmake")
endif(ENABLE_EXPORT)
message(STATUS "Building srsRAN version ${SRSRAN_VERSION_STRING}")